![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
First Version
Dependencies: EthernetInterface mbed-rtos mbed
Drivers/dma.c@0:9df41090ba33, 2015-07-21 (annotated)
- Committer:
- rebonatto
- Date:
- Tue Jul 21 21:29:49 2015 +0000
- Revision:
- 0:9df41090ba33
First Version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rebonatto | 0:9df41090ba33 | 1 | /* |
rebonatto | 0:9df41090ba33 | 2 | * dma.c |
rebonatto | 0:9df41090ba33 | 3 | * |
rebonatto | 0:9df41090ba33 | 4 | * Created on: 03/07/2011 |
rebonatto | 0:9df41090ba33 | 5 | * Author: francisco |
rebonatto | 0:9df41090ba33 | 6 | */ |
rebonatto | 0:9df41090ba33 | 7 | #include <LPC17xx.h> |
rebonatto | 0:9df41090ba33 | 8 | #include "dma.h" |
rebonatto | 0:9df41090ba33 | 9 | |
rebonatto | 0:9df41090ba33 | 10 | #define LPC_GPDMACH ((LPC_GPDMACH_TypeDef **) LPC_GPDMACH0_BASE ) |
rebonatto | 0:9df41090ba33 | 11 | |
rebonatto | 0:9df41090ba33 | 12 | void init_dma() |
rebonatto | 0:9df41090ba33 | 13 | { |
rebonatto | 0:9df41090ba33 | 14 | LPC_SC->PCONP |= 1<<29; //Power GPDMA module |
rebonatto | 0:9df41090ba33 | 15 | |
rebonatto | 0:9df41090ba33 | 16 | LPC_GPDMA->DMACConfig = 1; //Enable GPDMA |
rebonatto | 0:9df41090ba33 | 17 | |
rebonatto | 0:9df41090ba33 | 18 | //Clear any previous interrupts |
rebonatto | 0:9df41090ba33 | 19 | LPC_GPDMA->DMACIntTCClear = 0xFF; |
rebonatto | 0:9df41090ba33 | 20 | LPC_GPDMA->DMACIntErrClr = 0xFF; |
rebonatto | 0:9df41090ba33 | 21 | |
rebonatto | 0:9df41090ba33 | 22 | NVIC_SetPriority(DMA_IRQn,(1<<__NVIC_PRIO_BITS) - 1); |
rebonatto | 0:9df41090ba33 | 23 | NVIC_EnableIRQ(DMA_IRQn); |
rebonatto | 0:9df41090ba33 | 24 | } |
rebonatto | 0:9df41090ba33 | 25 | |
rebonatto | 0:9df41090ba33 | 26 | void setup_channel(dmaLinkedListNode* pList,int ch,int src,int dst) |
rebonatto | 0:9df41090ba33 | 27 | { |
rebonatto | 0:9df41090ba33 | 28 | //Initialize the channel with previously configured LL; |
rebonatto | 0:9df41090ba33 | 29 | LPC_GPDMACH0->DMACCSrcAddr = pList->sourceAddr; |
rebonatto | 0:9df41090ba33 | 30 | LPC_GPDMACH0->DMACCDestAddr = pList->destAddr; |
rebonatto | 0:9df41090ba33 | 31 | LPC_GPDMACH0->DMACCControl = pList->dmaControl; |
rebonatto | 0:9df41090ba33 | 32 | LPC_GPDMACH0->DMACCLLI = (unsigned long int) pList & 0xFFFFFFFC; //Lower bits must be 0 |
rebonatto | 0:9df41090ba33 | 33 | |
rebonatto | 0:9df41090ba33 | 34 | int transfer_type; |
rebonatto | 0:9df41090ba33 | 35 | if(src == DMA_MEMORY && dst != DMA_MEMORY) |
rebonatto | 0:9df41090ba33 | 36 | { |
rebonatto | 0:9df41090ba33 | 37 | transfer_type = DMA_MEMORY_TO_PERIPHERAL; |
rebonatto | 0:9df41090ba33 | 38 | src = 0; |
rebonatto | 0:9df41090ba33 | 39 | } |
rebonatto | 0:9df41090ba33 | 40 | else if(src != DMA_MEMORY && dst == DMA_MEMORY) |
rebonatto | 0:9df41090ba33 | 41 | { |
rebonatto | 0:9df41090ba33 | 42 | transfer_type = DMA_PERIPHERAL_TO_MEMORY; |
rebonatto | 0:9df41090ba33 | 43 | dst = 0; |
rebonatto | 0:9df41090ba33 | 44 | } |
rebonatto | 0:9df41090ba33 | 45 | else if(src == DMA_MEMORY && dst == DMA_MEMORY) |
rebonatto | 0:9df41090ba33 | 46 | { |
rebonatto | 0:9df41090ba33 | 47 | transfer_type = DMA_MEMORY_TO_MEMORY; |
rebonatto | 0:9df41090ba33 | 48 | src=dst = 0; |
rebonatto | 0:9df41090ba33 | 49 | } |
rebonatto | 0:9df41090ba33 | 50 | else if(src != DMA_MEMORY && dst != DMA_MEMORY) |
rebonatto | 0:9df41090ba33 | 51 | transfer_type = DMA_PERIPHERAL_TO_PERIPHERAL; |
rebonatto | 0:9df41090ba33 | 52 | |
rebonatto | 0:9df41090ba33 | 53 | //Set up all relevant bits |
rebonatto | 0:9df41090ba33 | 54 | LPC_GPDMACH0->DMACCConfig = (src<<1) | (dst<<5) | (transfer_type<<11) | (1<<15); |
rebonatto | 0:9df41090ba33 | 55 | |
rebonatto | 0:9df41090ba33 | 56 | //Finally, enable the channel - |
rebonatto | 0:9df41090ba33 | 57 | LPC_GPDMACH0->DMACCConfig |= 1<<0; |
rebonatto | 0:9df41090ba33 | 58 | } |
rebonatto | 0:9df41090ba33 | 59 | |
rebonatto | 0:9df41090ba33 | 60 | void stop_channel() |
rebonatto | 0:9df41090ba33 | 61 | { |
rebonatto | 0:9df41090ba33 | 62 | LPC_GPDMACH0->DMACCConfig &= ~(1<<0); |
rebonatto | 0:9df41090ba33 | 63 | } |