|
Paparazzi UAS
v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
|
Go to the documentation of this file.
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
123 #if (STM32_DMA_USE_WAIT == TRUE) || defined(__DOXYGEN__)
136 #define _dma_reset_i(dmap) \
137 osalThreadResumeI(&(dmap)->thread, MSG_RESET)
146 #define _dma_reset_s(dmap) \
147 osalThreadResumeS(&(dmap)->thread, MSG_RESET)
156 #define _dma_wakeup_isr(dmap) { \
157 osalSysLockFromISR(); \
158 osalThreadResumeI(&(dmap)->thread, MSG_OK); \
159 osalSysUnlockFromISR(); \
169 #define _dma_timeout_isr(dmap) { \
170 osalSysLockFromISR(); \
171 osalThreadResumeI(&(dmap)->thread, MSG_TIMEOUT); \
172 osalSysUnlockFromISR(); \
175 #define _dma_reset_i(dmap)
176 #define _dma_reset_s(dmap)
177 #define _dma_wakeup_isr(dmap)
178 #define _dma_timeout_isr(dmap)
248 #if STM32_DMA_SUPPORTS_CSELR
257 #elif STM32_DMA_ADVANCED
288 #if STM32_DMA_USE_ASYNC_TIMOUT
326 bool dcache_memory_in_use;
328 #if STM32_DMA_ADVANCED
329 #define STM32_DMA_FIFO_SIZE 16 // hardware specification for dma V2
349 bool periph_inc_size_4;
354 bool transfert_end_ctrl_by_periph;
356 #ifdef STM32_DMA_DRIVER_USER_DATA_FIELD
376 #if STM32_DMA_USE_WAIT || defined(__DOXYGEN__)
380 thread_reference_t thread;
382 #if STM32_DMA_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__)
388 #if STM32_DMA_USE_ASYNC_TIMOUT
415 volatile void * periphp;
418 #if STM32_DMA_ADVANCED
430 #if CH_DBG_SYSTEM_STATE_CHECK
431 volatile size_t nbTransferError;
432 volatile size_t nbDirectModeError;
433 volatile size_t nbFifoError;
434 volatile size_t nbFifoFull;
435 volatile size_t nbFifoEmpty;
456 #if STM32_DMA_USE_WAIT == TRUE
465 #if STM32_DMA_USE_MUTUAL_EXCLUSION == TRUE
488 #if STM32_DMA_USE_ASYNC_TIMOUT
489 void dma_lld_serve_timeout_interrupt(
void *arg);
492 #if STM32_DMA_USE_ASYNC_TIMOUT
493 typedef enum {FROM_TIMOUT_CODE, FROM_HALF_CODE, FROM_FULL_CODE, FROM_NON_CIRCULAR_CODE} CbCallContext;
494 static inline void async_timout_enabled_call_end_cb(
DMADriver *dmap,
const CbCallContext context)
496 uint8_t *
const baseAddr = dmap->currPtr;
497 const size_t fullSize = dmap->
size;
498 const size_t halfSize = fullSize / 2;
506 case (FROM_HALF_CODE) :
507 if (midPtr > baseAddr) {
509 dmap->currPtr = midPtr;
513 case (FROM_FULL_CODE) :
514 case (FROM_NON_CIRCULAR_CODE) :
516 dmap->currPtr = basePtr;
519 case (FROM_TIMOUT_CODE) : {
520 const size_t dmaCNT = dmaStreamGetTransactionSize(dmap->
dmastream);
521 const size_t index = (baseAddr - basePtr) / dmap->
config->
msize;
526 if (fullSize >= (dmaCNT + index)) {
527 rem = (fullSize - dmaCNT - index);
528 dmap->currPtr = baseAddr + (rem * dmap->
config->
msize);
542 #if STM32_DMA_USE_ASYNC_TIMOUT
543 if (dmap->
config->timeout != TIME_INFINITE) {
545 chVTSetI(&dmap->vt, dmap->
config->timeout,
546 &dma_lld_serve_timeout_interrupt, (
void *) dmap);
547 chSysUnlockFromISR();
549 async_timout_enabled_call_end_cb(dmap, FROM_HALF_CODE);
560 #if STM32_DMA_USE_ASYNC_TIMOUT
561 if (dmap->
config->timeout != TIME_INFINITE) {
563 chVTSetI(&dmap->vt, dmap->
config->timeout,
564 &dma_lld_serve_timeout_interrupt, (
void *) dmap);
565 chSysUnlockFromISR();
567 async_timout_enabled_call_end_cb(dmap, FROM_FULL_CODE);
571 if (dmap->
size > 1) {
573 const size_t half_index = dmap->
size / 2;
576 dmap->
config->
end_cb(dmap, (
void *) byte_array_p, half_index);
585 #if STM32_DMA_USE_ASYNC_TIMOUT
586 if (dmap->
config->timeout != TIME_INFINITE) {
588 chVTResetI(&dmap->vt);
589 chSysUnlockFromISR();
596 #if STM32_DMA_USE_ASYNC_TIMOUT
597 async_timout_enabled_call_end_cb(dmap, FROM_NON_CIRCULAR_CODE);
612 #if CH_DBG_SYSTEM_STATE_CHECK == TRUE
614 dmap->nbTransferError++;
616 dmap->nbDirectModeError++;
624 dmap->lastError = err;
bool circular
Enables the circular buffer mode for the stream.
@ DMA_DIR_M2P
MEMORY to PERIPHERAL
size_t size
hold size of current transaction
void(* dmacallback_t)(DMADriver *dmap, void *buffer, const size_t n)
DMA notification callback type.
static msg_t dmaTransfert(DMADriver *dmap, volatile void *periphp, void *mem0p, const size_t size)
const stm32_dma_stream_t * dmastream
DMA stream associated with peripheral or memory.
uint8_t dma_priority
DMA priority (1 .
uint8_t irq_priority
DMA IRQ priority (2 .
bool dmaStartTransfertI(DMADriver *dmap, volatile void *periphp, void *mem0p, const size_t size)
Starts a DMA transaction.
bool dma_lld_start(DMADriver *dmap)
Configures and activates the DMA peripheral.
msg_t dmaTransfertTimeout(DMADriver *dmap, volatile void *periphp, void *mem0p, const size_t size, sysinterval_t timeout)
Performs a DMA transaction.
dmadirection_t
DMA transfert direction.
bool inc_peripheral_addr
Enable increment of peripheral address after each transfert.
static pthread_mutex_t mutex
#define _dma_timeout_isr(dmap)
Wakes up the waiting thread with a timeout message.
static void _dma_isr_full_code(DMADriver *dmap)
Common ISR code, full buffer event.
uint8_t msize
DMA memory data granurality in bytes (1,2,4)
@ DMA_ERR_FIFO_FULL
DMA FIFO overrun.
void dmaStop(DMADriver *dmap)
Deactivates the DMA peripheral.
void * mem0p
memory address
dmaerrormask_t
Possible DMA failure causes.
@ DMA_ERR_FIFO_EMPTY
DMA FIFO underrun.
void dmaStopTransfert(DMADriver *dmap)
Stops an ongoing transaction.
dmacallback_t end_cb
Callback function associated to the stream or NULL.
void(* dmaerrorcallback_t)(DMADriver *dmap, dmaerrormask_t err)
DMA error callback type.
void dmaStopTransfertI(DMADriver *dmap)
Stops an ongoing transaction.
@ DMA_DIR_P2M
PERIPHERAL to MEMORY
bool dma_lld_start_transfert(DMADriver *dmap, volatile void *periphp, void *mem0p, const size_t size)
Starts a DMA transaction.
void dmaAcquireBus(DMADriver *dmap)
Gains exclusive access to the DMA peripheral.
static void _dma_isr_error_code(DMADriver *dmap, dmaerrormask_t err)
Common ISR code, error event.
@ DMA_DIR_M2M
MEMORY to MEMORY
@ DMA_COMPLETE
Transfert complete.
@ DMA_ERR_FIFO_ERROR
DMA FIFO error.
@ DMA_ERR_DIRECTMODE_ERROR
DMA Direct Mode failure.
volatile dmastate_t state
Driver state.
if(GpsFixValid() &&e_identification_started)
dmastate_t
Driver state machine possible states.
void dma_lld_stop(DMADriver *dmap)
Deactivates the DMA peripheral.
bool inc_memory_addr
Enable increment of memory address after each transfert.
dmadirection_t direction
DMA transaction direction.
@ DMA_UNINIT
Not initialized.
Structure representing a DMA driver.
uint8_t psize
DMA peripheral data granurality in bytes (1,2,4)
uint32_t dmamode
hold DMA CR register for the stream
uint32_t stream
stream associated with transaction
@ DMA_ERROR
Transfert error.
DMA stream configuration structure.
uint8_t controller
controller associated with stream
bool dmaStart(DMADriver *dmap, const DMAConfig *cfg)
Configures and activates the DMA peripheral.
void dmaObjectInit(DMADriver *dmap)
void dmaReleaseBus(DMADriver *dmap)
Releases exclusive access to the DMA peripheral.
dmaerrorcallback_t error_cb
Error callback or NULL.
static dmastate_t dmaGetState(DMADriver *dmap)
const DMAConfig * config
Current configuration data.
#define _dma_wakeup_isr(dmap)
Wakes up the waiting thread.
bool dmaStartTransfert(DMADriver *dmap, volatile void *periphp, void *mem0p, const size_t size)
Starts a DMA transaction.
static void _dma_isr_half_code(DMADriver *dmap)
Common ISR code, half buffer event.
@ DMA_ERR_TRANSFER_ERROR
DMA transfer failure.
void dma_lld_stop_transfert(DMADriver *dmap)
Stops an ongoing transaction.