bool result; int result_i; void dma_callback_test(void * args) { *((uint8_t *)args) = 0; } msp430x_dma_req_t test_1_req = { instring, /* source address */ outstring, /* destination address */ 9, /* number of words */ MSP430X_DMA_SRCINCR | MSP430X_DMA_DSTINCR, /* address mode - dual increment */ MSP430X_DMA_SRCWORD | MSP430X_DMA_DSTWORD, /* word transfer */ MSP430X_DMA_BLOCK, /* block (and blocking) transfer */ DMA_TRIGGER_MNEM(DMAREQ), /* software-requested trigger */ { NULL, /* no callback */ NULL /* no arguments */ } }; msp430x_dma_req_t test_2_req = { instring, /* source address */ outstring, /* destination address */ 18, /* number of bytes */ MSP430X_DMA_SRCINCR | MSP430X_DMA_DSTINCR, /* address mode - dual increment */ MSP430X_DMA_SRCBYTE | MSP430X_DMA_DSTBYTE, /* byte transfer */ MSP430X_DMA_BLOCK, /* block (and blocking) transfer */ DMA_TRIGGER_MNEM(DMAREQ), /* software-requested trigger */ {
/** * @brief Requests a DMA transfer operation from the DMA engine. * @note The DMA engine uses unclaimed DMA channels to provide DMA services * for one-off or infrequent uses. If all channels are busy, and * semaphores are enabled, the calling thread will sleep until a * channel is available or the request times out. If semaphores are * disabled, the calling thread will busy-wait instead of sleeping. */ bool dmaRequest(msp430x_dma_req_t * request, systime_t timeout) { /* Check if a DMA channel is available */ #if CH_CFG_USE_SEMAPHORES msg_t semresult = chSemWaitTimeout(&dma_lock, timeout); if (semresult != MSG_OK) return true; #endif #if !(CH_CFG_USE_SEMAPHORES) systime_t start = chVTGetSystemTimeX(); do { #endif /* Grab the correct DMA channel to use */ int i = 0; for (i = 0; i < MSP430X_DMA_CHANNELS; i++) { if (!(dma_channels[i].ctl & DMAEN)) { break; } } #if !(CH_CFG_USE_SEMAPHORES) while (chVTTimeElapsedSinceX(start) < timeout) ; #endif #if !(CH_CFG_USE_SEMAPHORES) if (i == MSP430X_DMA_CHANNELS) { return true; } #endif /* Make the request */ init_request(request, i); return false; } /** * @brief Acquires exclusive control of a DMA channel. * @pre The channel must not be already acquired or an error is returned. * @note If the channel is in use by the DMA engine, blocks until acquired. * @post This channel must be interacted with using only the functions * defined in this module. * * @param[out] channel The channel handle. Must be pre-allocated. * @param[in] index The index of the channel (< MSP430X_DMA_CHANNELS). * @return The operation status. * @retval false no error, channel acquired. * @retval true error, channel already acquired. */ bool dmaAcquire(msp430x_dma_ch_t * channel, uint8_t index) { /* Acquire the channel in an idle mode */ /* Is the channel already acquired? */ osalDbgAssert(index < MSP430X_DMA_CHANNELS, "invalid channel index"); if (dma_channels[index].ctl & DMADT_4) { return true; } /* Increment the DMA counter */ #if CH_CFG_USE_SEMAPHORES msg_t semresult = chSemWait(&dma_lock); if (semresult != MSG_OK) return true; #endif while (dma_channels[index].ctl & DMAEN) ; dma_trigger_set(index, DMA_TRIGGER_MNEM(DMAREQ)); dma_channels[index].sz = 0; dma_channels[index].ctl = DMAEN | DMAABORT | DMADT_4; channel->registers = dma_channels + index; channel->index = index; channel->cb = callbacks + index; return false; }