Document DMA ring buffer
This commit is contained in:
@@ -105,6 +105,8 @@ void dma_ring_buffer_periph_to_mem_stop(struct dma_ring_buffer_to_mem *buff)
|
||||
buff->dma->FCR = 0;
|
||||
|
||||
dma_ring_buffer_switch_clock_enable(buff->base_dma_id, false);
|
||||
|
||||
memset(buff, 0, sizeof(struct dma_ring_buffer_to_mem));
|
||||
}
|
||||
|
||||
int dma_ring_buffer_mem_to_periph_initialize(struct dma_ring_buffer_to_periph *dma_buffer, uint8_t base_dma_id, DMA_Stream_TypeDef *dma_stream, size_t buffer_element_count, size_t element_size, void *data_buffer, uint8_t dma_trigger_channel, void *dest_reg)
|
||||
@@ -206,18 +208,30 @@ int dma_ring_buffer_mem_to_periph_insert_data(struct dma_ring_buffer_to_periph *
|
||||
/* Fillup buffer (max is buffer end, wrap around afterwards) */
|
||||
insert_ptr = (char *)data_to_insert;
|
||||
dest_ptr = &((char *)buff->src_buffer)[buff->sw_put_idx * buff->element_size];
|
||||
|
||||
/* Check if data completely fits into memory starting from put index */
|
||||
if (buff->buffer_count - buff->sw_put_idx >= count) {
|
||||
/* Copy data and move put index */
|
||||
memcpy(dest_ptr, insert_ptr, buff->element_size * count);
|
||||
buff->sw_put_idx += count;
|
||||
|
||||
/* If buffer is used up to last element, set put index to beginning */
|
||||
if(buff->sw_put_idx >= buff->buffer_count)
|
||||
buff->sw_put_idx = 0;
|
||||
} else {
|
||||
/* Fill up to end of buffer and fill rest after wrap around */
|
||||
first_round_count = buff->element_size * (buff->buffer_count - buff->sw_put_idx);
|
||||
memcpy(dest_ptr, insert_ptr, first_round_count);
|
||||
insert_ptr += first_round_count;
|
||||
memcpy(buff->src_buffer, insert_ptr, count - first_round_count);
|
||||
|
||||
/* Move put index */
|
||||
buff->sw_put_idx = count - first_round_count;
|
||||
}
|
||||
|
||||
/* Queue the DMA transfer. If DMA is already enabled, this has no effect
|
||||
* DMA is triggerd from interrupt in this case
|
||||
*/
|
||||
queue_or_start_dma_transfer(buff);
|
||||
|
||||
return_retval:
|
||||
@@ -226,15 +240,19 @@ return_retval:
|
||||
|
||||
void dma_ring_buffer_mem_to_periph_int_callback(struct dma_ring_buffer_to_periph *buff)
|
||||
{
|
||||
/* update current get index */
|
||||
/* update current get index because DMA is finished */
|
||||
buff->dma_get_idx_current = buff->dma_get_idx_future;
|
||||
|
||||
/* Start new DMA transfer if not all data is trasnferred yet */
|
||||
queue_or_start_dma_transfer(buff);
|
||||
}
|
||||
|
||||
void dma_ring_buffer_mem_to_periph_stop(struct dma_ring_buffer_to_periph *buff)
|
||||
{
|
||||
/* Stop DMA and clock */
|
||||
buff->dma->CR = 0;
|
||||
dma_ring_buffer_switch_clock_enable(buff->dma_base_id, false);
|
||||
|
||||
/* Reset the structure */
|
||||
memset(buff, 0, sizeof(struct dma_ring_buffer_to_periph));
|
||||
}
|
||||
|
Reference in New Issue
Block a user