MODDMA GPDMA Controller New features: transfer pins to memory buffer under periodic timer control and send double buffers to DAC

Dependents:   FirstTest WaveSim IO-dma-memmem DACDMAfuncgenlib ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers INIT.cpp Source File

INIT.cpp

00001 /*
00002     Copyright (c) 2010 Andy Kirkham
00003  
00004     Permission is hereby granted, free of charge, to any person obtaining a copy
00005     of this software and associated documentation files (the "Software"), to deal
00006     in the Software without restriction, including without limitation the rights
00007     to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00008     copies of the Software, and to permit persons to whom the Software is
00009     furnished to do so, subject to the following conditions:
00010  
00011     The above copyright notice and this permission notice shall be included in
00012     all copies or substantial portions of the Software.
00013  
00014     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00015     IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00016     FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00017     AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00018     LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00019     OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00020     THE SOFTWARE.
00021 */
00022 
00023 #include "MODDMA.h"
00024 
00025 namespace AjK {
00026 
00027 extern uint32_t oldDMAHandler;
00028 extern "C" void MODDMA_IRQHandler(void);
00029 extern class MODDMA *moddma_p;
00030 
00031 void
00032 MODDMA::init(bool isConstructorCalling, int Channels, int Tc, int Err)
00033 {
00034     if (isConstructorCalling) {    
00035         if (LPC_SC->PCONP & (1UL << 29)) {
00036             if (LPC_GPDMA->DMACConfig & 1) {
00037                 error("Only one instance of MODDMA can exist.");
00038             }
00039         }
00040         LPC_SC->PCONP |= (1UL << 29);
00041         LPC_GPDMA->DMACConfig = 1;
00042         moddma_p = this;
00043         for (int i = 0; i < 8; i++) {
00044             setups[i] = (MODDMA_Config *)NULL;
00045         }        
00046     }
00047     
00048     // Reset channel configuration register(s)
00049     if (Channels & 0x01) LPC_GPDMACH0->DMACCConfig = 0;
00050     if (Channels & 0x02) LPC_GPDMACH1->DMACCConfig = 0;
00051     if (Channels & 0x04) LPC_GPDMACH2->DMACCConfig = 0;
00052     if (Channels & 0x08) LPC_GPDMACH3->DMACCConfig = 0;
00053     if (Channels & 0x10) LPC_GPDMACH4->DMACCConfig = 0;
00054     if (Channels & 0x20) LPC_GPDMACH5->DMACCConfig = 0;
00055     if (Channels & 0x40) LPC_GPDMACH6->DMACCConfig = 0;
00056     if (Channels & 0x80) LPC_GPDMACH7->DMACCConfig = 0;
00057 
00058     /* Clear DMA interrupt and error flag */
00059     LPC_GPDMA->DMACIntTCClear = Tc;
00060     LPC_GPDMA->DMACIntErrClr  = Err;
00061     
00062     if (isConstructorCalling) {    
00063         oldDMAHandler = NVIC_GetVector(DMA_IRQn);
00064         NVIC_SetVector(DMA_IRQn, (uint32_t)MODDMA_IRQHandler);
00065         NVIC_EnableIRQ(DMA_IRQn);
00066     }
00067 }
00068 
00069 }; // namespace AjK ends