42 #if !defined(STM32_DMA_USE_WAIT) || defined(__DOXYGEN__)
43 #define STM32_DMA_USE_WAIT TRUE
50 #if !defined(STM32_DMA_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__)
51 #define STM32_DMA_USE_MUTUAL_EXCLUSION FALSE
54 #if !defined(STM32_DMA_SUPPORTS_CSELR) || defined(__DOXYGEN__)
55 #define STM32_DMA_SUPPORTS_CSELR FALSE
58 #if !defined(STM32_DMA_SUPPORTS_DMAMUX) || defined(__DOXYGEN__)
59 #define STM32_DMA_SUPPORTS_DMAMUX FALSE
62 #if !defined(STM32_DMA_DUMMY_MEMORY_AREA_ADDRESS) || defined(__DOXYGEN__)
63 #define STM32_DMA_DUMMY_MEMORY_AREA_ADDRESS 0x80000000
66 #if !defined(__DCACHE_PRESENT)
67 #define __DCACHE_PRESENT FALSE
110 #if STM32_DMA_USE_DOUBLE_BUFFER
111 DMA_CONTINUOUS_DOUBLE_BUFFER
138 typedef void * (*dmanextcallback_t)(
DMADriver *dmap,
const size_t n);
155 #if (STM32_DMA_USE_WAIT == TRUE) || defined(__DOXYGEN__)
168 #define _dma_reset_i(dmap) \
169 osalThreadResumeI(&(dmap)->thread, MSG_RESET)
178 #define _dma_reset_s(dmap) \
179 osalThreadResumeS(&(dmap)->thread, MSG_RESET)
188 #define _dma_wakeup_isr(dmap) { \
189 osalSysLockFromISR(); \
190 osalThreadResumeI(&(dmap)->thread, MSG_OK); \
191 osalSysUnlockFromISR(); \
201 #define _dma_timeout_isr(dmap) { \
202 osalSysLockFromISR(); \
203 osalThreadResumeI(&(dmap)->thread, MSG_TIMEOUT); \
204 osalSysUnlockFromISR(); \
207 #define _dma_reset_i(dmap)
208 #define _dma_reset_s(dmap)
209 #define _dma_wakeup_isr(dmap)
210 #define _dma_timeout_isr(dmap)
280 #if STM32_DMA_SUPPORTS_DMAMUX
283 #if STM32_DMA_SUPPORTS_CSELR
320 #if STM32_DMA_USE_DOUBLE_BUFFER
332 #if STM32_DMA_USE_ASYNC_TIMOUT
371 bool dcache_memory_in_use;
372 bool activate_dcache_sync;
375 #if STM32_DMA_ADVANCED
376 #define STM32_DMA_FIFO_SIZE 16
396 bool periph_inc_size_4;
401 bool transfert_end_ctrl_by_periph;
403 #if STM32_DMA_DRIVER_USER_DATA_FIELD
423 #if STM32_DMA_USE_WAIT || defined(__DOXYGEN__)
427 thread_reference_t thread;
429 #if STM32_DMA_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__)
435 #if STM32_DMA_USE_ASYNC_TIMOUT
462 volatile void * periphp;
465 #if STM32_DMA_ADVANCED
477 #if STM32_DMA_USE_DOUBLE_BUFFER
481 #if CH_DBG_SYSTEM_STATE_CHECK
482 volatile size_t nbTransferError;
483 volatile size_t nbDirectModeError;
484 volatile size_t nbFifoError;
485 volatile size_t nbFifoFull;
486 volatile size_t nbFifoEmpty;
498 #if STM32_DMA_SUPPORTS_DMAMUX == 0
510 #if STM32_DMA_USE_WAIT == TRUE
519 #if STM32_DMA_USE_MUTUAL_EXCLUSION == TRUE
529 #ifndef DMA_request_TypeDef
532 DMA_Stream_TypeDef *registers);
537 #if STM32_DMA_USE_DOUBLE_BUFFER
554 static inline void dmaClearNextErrors(
DMADriver *dmap) {dmap->next_cb_errors = 0U;}
568 #if STM32_DMA_USE_ASYNC_TIMOUT
569 void dma_lld_serve_timeout_interrupt(
void *arg);
574 #if STM32_DMA_USE_ASYNC_TIMOUT
575 typedef enum {FROM_TIMOUT_CODE, FROM_HALF_CODE, FROM_FULL_CODE, FROM_NON_CIRCULAR_CODE} CbCallContext;
576 static inline void async_timout_enabled_call_end_cb(
DMADriver *dmap,
const CbCallContext context)
578 uint8_t *
const baseAddr = dmap->currPtr;
579 const size_t fullSize = dmap->
size;
580 const size_t halfSize = fullSize / 2;
588 case (FROM_HALF_CODE) :
589 if (midPtr > baseAddr) {
591 dmap->currPtr = midPtr;
595 case (FROM_FULL_CODE) :
596 case (FROM_NON_CIRCULAR_CODE) :
598 dmap->currPtr = basePtr;
601 case (FROM_TIMOUT_CODE) : {
602 const size_t dmaCNT = dmaStreamGetTransactionSize(dmap->
dmastream);
603 const size_t index = (baseAddr - basePtr) / dmap->
config->
msize;
608 if (fullSize >= (dmaCNT + index)) {
609 rem = (fullSize - dmaCNT - index);
610 dmap->currPtr = baseAddr + (rem * dmap->
config->
msize);
624 #if STM32_DMA_USE_ASYNC_TIMOUT
625 if (dmap->
config->timeout != TIME_INFINITE) {
627 chVTSetI(&dmap->vt, dmap->
config->timeout,
628 &dma_lld_serve_timeout_interrupt, (
void *) dmap);
629 chSysUnlockFromISR();
631 async_timout_enabled_call_end_cb(dmap, FROM_HALF_CODE);
642 #if STM32_DMA_USE_ASYNC_TIMOUT
643 if (dmap->
config->timeout != TIME_INFINITE) {
645 chVTSetI(&dmap->vt, dmap->
config->timeout,
646 &dma_lld_serve_timeout_interrupt, (
void *) dmap);
647 chSysUnlockFromISR();
649 async_timout_enabled_call_end_cb(dmap, FROM_FULL_CODE);
653 if (dmap->
size > 1) {
655 const size_t half_index = dmap->
size / 2;
658 dmap->
config->
end_cb(dmap, (
void *) byte_array_p, half_index);
668 #if STM32_DMA_USE_ASYNC_TIMOUT
669 if (dmap->
config->timeout != TIME_INFINITE) {
671 chVTResetI(&dmap->vt);
672 chSysUnlockFromISR();
679 #if STM32_DMA_USE_ASYNC_TIMOUT
680 async_timout_enabled_call_end_cb(dmap, FROM_NON_CIRCULAR_CODE);
692 #if STM32_DMA_USE_DOUBLE_BUFFER
695 void*
const rawNextBuff = dmap->
config->next_cb(dmap, dmap->
size);
696 if (rawNextBuff == NULL)
697 dmap->next_cb_errors++;
710 #if CH_DBG_SYSTEM_STATE_CHECK == TRUE
712 dmap->nbTransferError++;
714 dmap->nbDirectModeError++;
722 dmap->lastError = err;
739 #ifndef DMA_request_TypeDef
741 void *mem0p,
const size_t size,
742 DMA_Stream_TypeDef *registers);
static pthread_mutex_t mutex
if(GpsFixValid() &&e_identification_started)
uint8_t msize
DMA memory data granurality in bytes (1,2,4)
void dmaObjectInit(DMADriver *dmap)
void(* dmaerrorcallback_t)(DMADriver *dmap, dmaerrormask_t err)
DMA error callback type.
dmaopmode_t
DMA transfert memory mode.
@ DMA_CONTINUOUS_HALF_BUFFER
Continuous mode to/from the same buffer.
@ DMA_ONESHOT
One transert then stop
dmadirection_t
DMA transfert direction.
@ DMA_DIR_M2P
MEMORY to PERIPHERAL
@ DMA_DIR_M2M
MEMORY to MEMORY
@ DMA_DIR_P2M
PERIPHERAL to MEMORY
size_t size
hold size of current transaction
bool dmaStartTransfert(DMADriver *dmap, volatile void *periphp, void *mem0p, const size_t size)
Starts a DMA transaction.
bool inc_peripheral_addr
Enable increment of peripheral address after each transfert.
bool dma_lld_start(DMADriver *dmap, bool allocate_stream)
Configures and activates the DMA peripheral.
#define STM32_DMA_DUMMY_MEMORY_AREA_ADDRESS
#define _dma_wakeup_isr(dmap)
Wakes up the waiting thread.
uint8_t irq_priority
DMA IRQ priority (2 .
void dmaStop(DMADriver *dmap)
Deactivates the DMA peripheral.
msg_t dmaTransfertTimeout(DMADriver *dmap, volatile void *periphp, void *mem0p, const size_t size, sysinterval_t timeout)
Performs a DMA transaction.
void dmaGetRegisters(DMADriver *dmap, volatile void *periphp, void *mem0p, const size_t size, DMA_Stream_TypeDef *registers)
copy the dma register to memory.
uint8_t dma_priority
DMA priority (1 .
void(* dmacallback_t)(DMADriver *dmap, void *buffer, const size_t n)
DMA notification callback type.
static dmastate_t dmaGetState(DMADriver *dmap)
bool dmaStartTransfertI(DMADriver *dmap, volatile void *periphp, void *mem0p, const size_t size)
Starts a DMA transaction.
const DMAConfig * config
Current configuration data.
static size_t dmaGetTransactionCounter(DMADriver *dmap)
void dma_lld_stop(DMADriver *dmap)
Deactivates the DMA peripheral.
static void _dma_isr_error_code(DMADriver *dmap, dmaerrormask_t err)
Common ISR code, error event.
#define _dma_timeout_isr(dmap)
Wakes up the waiting thread with a timeout message.
void dma_lld_get_registers(DMADriver *dmap, volatile void *periphp, void *mem0p, const size_t size, DMA_Stream_TypeDef *registers)
Copy the register of a ready stream.
dmaerrormask_t
Possible DMA failure causes.
@ DMA_ERR_FIFO_EMPTY
DMA FIFO underrun.
@ DMA_ERR_FIFO_FULL
DMA FIFO overrun.
@ DMA_ERR_TRANSFER_ERROR
DMA transfer failure.
@ DMA_ERR_DIRECTMODE_ERROR
DMA Direct Mode failure.
@ DMA_ERR_FIFO_ERROR
DMA FIFO error.
void * mem0p
memory address
dmaerrorcallback_t error_cb
Error callback or NULL.
uint32_t stream
stream associated with transaction
void * dma_lld_set_next_double_buffer(DMADriver *dmap, void *nextBuffer)
dmaopmode_t op_mode
one shot, or circular half buffer, or circular double buffers
void dmaStopTransfert(DMADriver *dmap)
Stops an ongoing transaction.
uint8_t controller
controller associated with stream
static msg_t dmaTransfert(DMADriver *dmap, volatile void *periphp, void *mem0p, const size_t size)
void dmaAcquireBus(DMADriver *dmap)
Gains exclusive access to the DMA peripheral.
static void _dma_isr_full_code(DMADriver *dmap)
Common ISR code, full buffer event.
void dmaReleaseBus(DMADriver *dmap)
Releases exclusive access to the DMA peripheral.
uint32_t dmamode
hold DMA CR register for the stream
dmastate_t
Driver state machine possible states.
@ DMA_ERROR
Transfert error.
@ DMA_UNINIT
Not initialized.
@ DMA_COMPLETE
Transfert complete.
void dma_lld_stop_transfert(DMADriver *dmap)
Stops an ongoing transaction.
dmacallback_t end_cb
Callback function associated to the stream or NULL.
void dmaStopTransfertI(DMADriver *dmap)
Stops an ongoing transaction.
static void _dma_isr_half_code(DMADriver *dmap)
Common ISR code, half buffer event.
bool dma_lld_start_transfert(DMADriver *dmap, volatile void *periphp, void *mem0p, const size_t size)
Starts a DMA transaction.
dmadirection_t direction
DMA transaction direction.
const stm32_dma_stream_t * dmastream
DMA stream associated with peripheral or memory.
volatile dmastate_t state
Driver state.
uint8_t psize
DMA peripheral data granurality in bytes (1,2,4)
bool dmaStart(DMADriver *dmap, const DMAConfig *cfg)
Configures and activates the DMA peripheral.
void *(* dmanextcallback_t)(DMADriver *dmap, const size_t n)
DMA next buffer query callback type.
bool dmaReloadConf(DMADriver *dmap, const DMAConfig *cfg)
Configures and activates the DMA peripheral.
bool inc_memory_addr
Enable increment of memory address after each transfert.
uint8_t dmaGetStreamIndex(DMADriver *dmap)
DMA stream configuration structure.
Structure representing a DMA driver.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.