trying to make telnetserver repo public

Fork of MODDMA by Andy K

Committer:
AjK
Date:
Tue Nov 23 14:50:39 2010 +0000
Revision:
0:c409efd8df78
Child:
8:cb4d323ce6fd
0.1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AjK 0:c409efd8df78 1 /*
AjK 0:c409efd8df78 2 Copyright (c) 2010 Andy Kirkham
AjK 0:c409efd8df78 3
AjK 0:c409efd8df78 4 Permission is hereby granted, free of charge, to any person obtaining a copy
AjK 0:c409efd8df78 5 of this software and associated documentation files (the "Software"), to deal
AjK 0:c409efd8df78 6 in the Software without restriction, including without limitation the rights
AjK 0:c409efd8df78 7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
AjK 0:c409efd8df78 8 copies of the Software, and to permit persons to whom the Software is
AjK 0:c409efd8df78 9 furnished to do so, subject to the following conditions:
AjK 0:c409efd8df78 10
AjK 0:c409efd8df78 11 The above copyright notice and this permission notice shall be included in
AjK 0:c409efd8df78 12 all copies or substantial portions of the Software.
AjK 0:c409efd8df78 13
AjK 0:c409efd8df78 14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
AjK 0:c409efd8df78 15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
AjK 0:c409efd8df78 16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AjK 0:c409efd8df78 17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
AjK 0:c409efd8df78 18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
AjK 0:c409efd8df78 19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
AjK 0:c409efd8df78 20 THE SOFTWARE.
AjK 0:c409efd8df78 21 */
AjK 0:c409efd8df78 22
AjK 0:c409efd8df78 23 #include "MODDMA.h"
AjK 0:c409efd8df78 24
AjK 0:c409efd8df78 25 namespace AjK {
AjK 0:c409efd8df78 26
AjK 0:c409efd8df78 27 extern uint32_t oldDMAHandler;
AjK 0:c409efd8df78 28 extern "C" void MODDMA_IRQHandler(void);
AjK 0:c409efd8df78 29 extern class MODDMA *moddma_p;
AjK 0:c409efd8df78 30
AjK 0:c409efd8df78 31 void
AjK 0:c409efd8df78 32 MODDMA::init(bool isConstructorCalling, int Channels, int Tc, int Err)
AjK 0:c409efd8df78 33 {
AjK 0:c409efd8df78 34 if (isConstructorCalling) {
AjK 0:c409efd8df78 35 if (LPC_SC->PCONP & (1UL << 29)) {
AjK 0:c409efd8df78 36 if (LPC_GPDMA->DMACConfig & 1) {
AjK 0:c409efd8df78 37 error("Only one instance of MODDMA can exist.");
AjK 0:c409efd8df78 38 }
AjK 0:c409efd8df78 39 }
AjK 0:c409efd8df78 40 LPC_SC->PCONP |= (1UL << 29);
AjK 0:c409efd8df78 41 LPC_GPDMA->DMACConfig = 1;
AjK 0:c409efd8df78 42 moddma_p = this;
AjK 0:c409efd8df78 43 for (int i = 0; i < 8; i++) {
AjK 0:c409efd8df78 44 setups[i] = (MODDMA_Config *)NULL;
AjK 0:c409efd8df78 45 }
AjK 0:c409efd8df78 46 }
AjK 0:c409efd8df78 47
AjK 0:c409efd8df78 48 // Reset channel configuration register(s)
AjK 0:c409efd8df78 49 if (Channels & 0x01) LPC_GPDMACH0->DMACCConfig = 0;
AjK 0:c409efd8df78 50 if (Channels & 0x02) LPC_GPDMACH1->DMACCConfig = 0;
AjK 0:c409efd8df78 51 if (Channels & 0x04) LPC_GPDMACH2->DMACCConfig = 0;
AjK 0:c409efd8df78 52 if (Channels & 0x08) LPC_GPDMACH3->DMACCConfig = 0;
AjK 0:c409efd8df78 53 if (Channels & 0x10) LPC_GPDMACH4->DMACCConfig = 0;
AjK 0:c409efd8df78 54 if (Channels & 0x20) LPC_GPDMACH5->DMACCConfig = 0;
AjK 0:c409efd8df78 55 if (Channels & 0x40) LPC_GPDMACH6->DMACCConfig = 0;
AjK 0:c409efd8df78 56 if (Channels & 0x80) LPC_GPDMACH7->DMACCConfig = 0;
AjK 0:c409efd8df78 57
AjK 0:c409efd8df78 58 /* Clear DMA interrupt and error flag */
AjK 0:c409efd8df78 59 LPC_GPDMA->DMACIntTCClear = Tc;
AjK 0:c409efd8df78 60 LPC_GPDMA->DMACIntErrClr = Err;
AjK 0:c409efd8df78 61
AjK 0:c409efd8df78 62 if (isConstructorCalling) {
AjK 0:c409efd8df78 63 oldDMAHandler = NVIC_GetVector(DMA_IRQn);
AjK 0:c409efd8df78 64 NVIC_SetVector(DMA_IRQn, (uint32_t)MODDMA_IRQHandler);
AjK 0:c409efd8df78 65 NVIC_EnableIRQ(DMA_IRQn);
AjK 0:c409efd8df78 66 }
AjK 0:c409efd8df78 67 }
AjK 0:c409efd8df78 68
AjK 0:c409efd8df78 69 }; // namespace AjK ends