stm32f1xx_HBL/srv/dma_cbuf.h
Steins7 ccf36ac400 Simplify dma buffers and adjust usart
The dma buffer should be services that are used on top of peripherals. As such,
the usart driver should'nt directly use them, this is up to the user. The
multi-buffer has also been simplified since I was not satisfied with the
previous implementation
2024-04-03 22:03:15 +02:00

57 lines
1.8 KiB
C

/** @file dma_cbuf.h
* Module handling Direct Memory Access controller's circular system
*
* The module provides a convenient tool to receive data from a peripheral in a
* buffered, low-latency, low-cpu usage, non-blocking way
*/
#ifndef _DMA_CBUF_H_
#define _DMA_CBUF_H_
//--includes--------------------------------------------------------------------
#include "../drv/dma.h"
//--type definitions------------------------------------------------------------
/**
* Struct used by the circular buffer system. This system allows bufferized
* reads to a peripheral with no latency, minimal cpu usage and customisable
* buffer sizes
*/
struct DmaCircBuffer {
volatile void* buffer; //the buffer to use as a circular buffer
const struct DmaParam* param;
enum DmaConfig priority; //DMA config, must correspond to peripheral
uint16_t size; //the size of the buffer
uint16_t begin; //pointer to the current begin of the buffer
bool dma_looped; //whether the DMA looped or not (buffer overflow)
};
//--functions-------------------------------------------------------------------
/**
* Configure a DMA circular buffer for a single DMA channel. A standard buffer
* is used a base to construct a circular buffer, supplied in data by DMA
* tranfers from a peripheral. The DMA's priority is given as parameters.
* The peripheral's specific configuration must be handled separately.
*
* Once this function is called, the system will start running right away and
* will stay running until manually stopped
*/
void dma_cbuf_configure(volatile struct DmaCircBuffer* buffer,
const struct DmaParam* param, enum DmaConfig priority,
volatile void* raw_buffer, uint16_t buffer_size);
uint32_t dma_cbuf_read_byte(volatile struct DmaCircBuffer* buffer,
uint8_t* byte);
#endif //_DMA_CBUF_H_