reflow-oven-control-sw/stm-firmware/include/stm-periph/dma-ring-buffer.h

41 lines
1.6 KiB
C

#ifndef __DMA_RING_BUFFER_H__
#define __DMA_RING_BUFFER_H__
#include <stdbool.h>
#include <stm32/stm32f4xx.h>
#include <stddef.h>
struct dma_ring_buffer_to_mem {
void *data_ptr;
size_t buffer_count;
DMA_Stream_TypeDef *dma;
size_t get_idx;
uint8_t base_dma_id;
size_t element_size;
};
struct dma_ring_buffer_to_periph {
void *src_buffer;
size_t buffer_count;
DMA_Stream_TypeDef *dma;
volatile size_t dma_get_idx_current;
volatile size_t dma_get_idx_future;
volatile size_t sw_put_idx;
uint8_t dma_base_id;
size_t element_size;
};
int dma_ring_buffer_periph_to_mem_initialize(struct dma_ring_buffer_to_mem *dma_buffer, uint8_t base_dma_id, DMA_Stream_TypeDef *dma_stream, size_t buffer_element_count, size_t element_size, void *data_buffer, void *src_reg, uint8_t dma_trigger_channel);
int dma_ring_buffer_periph_to_mem_get_data(struct dma_ring_buffer_to_mem *buff, const void **data_buff, size_t *len);
void dma_ring_buffer_periph_to_mem_stop(struct dma_ring_buffer_to_mem *buff);
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);
int dma_ring_buffer_mem_to_periph_insert_data(struct dma_ring_buffer_to_periph *buff, const void *data_to_insert, size_t count);
void dma_ring_buffer_mem_to_periph_int_callback(struct dma_ring_buffer_to_periph *buff);
void dma_ring_buffer_mem_to_periph_stop(struct dma_ring_buffer_to_periph *buff);
#endif /* __DMA_RING_BUFFER_H__ */