Versão sem FFT e aquisição por DMA. 256 amostras.

Dependencies:   EthernetInterface NTPClient mbed-rtos mbed

Committer:
rebonatto
Date:
Tue Jan 05 11:45:44 2016 +0000
Revision:
0:e57bc370d339
Vers?o est?vel sem calculo de FFT. Aquisi??o por DMA. Usa 256 amostras.

Who changed what in which revision?

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