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