GPDMA (Direct Memory Access) and LLI (Link List Item) test see: http://mbed.org/users/okini3939/notebook/dma_jp/
MODDMA/MODDMA.cpp@1:1a77fa863282, 2013-09-13 (annotated)
- Committer:
- okini3939
- Date:
- Fri Sep 13 15:19:09 2013 +0000
- Revision:
- 1:1a77fa863282
- Parent:
- 0:de79d4a48e63
fix more lli
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
okini3939 | 0:de79d4a48e63 | 1 | /* |
okini3939 | 0:de79d4a48e63 | 2 | Copyright (c) 2010 Andy Kirkham |
okini3939 | 0:de79d4a48e63 | 3 | |
okini3939 | 0:de79d4a48e63 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy |
okini3939 | 0:de79d4a48e63 | 5 | of this software and associated documentation files (the "Software"), to deal |
okini3939 | 0:de79d4a48e63 | 6 | in the Software without restriction, including without limitation the rights |
okini3939 | 0:de79d4a48e63 | 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
okini3939 | 0:de79d4a48e63 | 8 | copies of the Software, and to permit persons to whom the Software is |
okini3939 | 0:de79d4a48e63 | 9 | furnished to do so, subject to the following conditions: |
okini3939 | 0:de79d4a48e63 | 10 | |
okini3939 | 0:de79d4a48e63 | 11 | The above copyright notice and this permission notice shall be included in |
okini3939 | 0:de79d4a48e63 | 12 | all copies or substantial portions of the Software. |
okini3939 | 0:de79d4a48e63 | 13 | |
okini3939 | 0:de79d4a48e63 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
okini3939 | 0:de79d4a48e63 | 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
okini3939 | 0:de79d4a48e63 | 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
okini3939 | 0:de79d4a48e63 | 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
okini3939 | 0:de79d4a48e63 | 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
okini3939 | 0:de79d4a48e63 | 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
okini3939 | 0:de79d4a48e63 | 20 | THE SOFTWARE. |
okini3939 | 0:de79d4a48e63 | 21 | */ |
okini3939 | 0:de79d4a48e63 | 22 | #include "iomacros.h" |
okini3939 | 0:de79d4a48e63 | 23 | #include "MODDMA.h" |
okini3939 | 0:de79d4a48e63 | 24 | |
okini3939 | 0:de79d4a48e63 | 25 | namespace AjK { |
okini3939 | 0:de79d4a48e63 | 26 | |
okini3939 | 0:de79d4a48e63 | 27 | // Create a "hook" for our ISR to make callbacks. Set by init() |
okini3939 | 0:de79d4a48e63 | 28 | class MODDMA *moddma_p = (class MODDMA *)NULL; |
okini3939 | 0:de79d4a48e63 | 29 | |
okini3939 | 0:de79d4a48e63 | 30 | void |
okini3939 | 0:de79d4a48e63 | 31 | MODDMA::Enable(CHANNELS ChannelNumber) |
okini3939 | 0:de79d4a48e63 | 32 | { |
okini3939 | 0:de79d4a48e63 | 33 | LPC_GPDMACH_TypeDef *pChannel = (LPC_GPDMACH_TypeDef *)Channel_p( ChannelNumber ); |
okini3939 | 0:de79d4a48e63 | 34 | pChannel->DMACCConfig |= _E; |
okini3939 | 0:de79d4a48e63 | 35 | } |
okini3939 | 0:de79d4a48e63 | 36 | |
okini3939 | 0:de79d4a48e63 | 37 | bool |
okini3939 | 0:de79d4a48e63 | 38 | MODDMA::Enabled(CHANNELS ChannelNumber) |
okini3939 | 0:de79d4a48e63 | 39 | { |
okini3939 | 0:de79d4a48e63 | 40 | LPC_GPDMACH_TypeDef *pChannel = (LPC_GPDMACH_TypeDef *)Channel_p( ChannelNumber ); |
okini3939 | 0:de79d4a48e63 | 41 | return (bool)(pChannel->DMACCConfig & _E); |
okini3939 | 0:de79d4a48e63 | 42 | } |
okini3939 | 0:de79d4a48e63 | 43 | |
okini3939 | 0:de79d4a48e63 | 44 | void |
okini3939 | 0:de79d4a48e63 | 45 | MODDMA::Disable(CHANNELS ChannelNumber) |
okini3939 | 0:de79d4a48e63 | 46 | { |
okini3939 | 0:de79d4a48e63 | 47 | LPC_GPDMACH_TypeDef *pChannel = (LPC_GPDMACH_TypeDef *)Channel_p( ChannelNumber ); |
okini3939 | 0:de79d4a48e63 | 48 | pChannel->DMACCConfig &= ~(_E); |
okini3939 | 0:de79d4a48e63 | 49 | } |
okini3939 | 0:de79d4a48e63 | 50 | |
okini3939 | 0:de79d4a48e63 | 51 | bool |
okini3939 | 0:de79d4a48e63 | 52 | MODDMA::isActive(CHANNELS ChannelNumber) |
okini3939 | 0:de79d4a48e63 | 53 | { |
okini3939 | 0:de79d4a48e63 | 54 | LPC_GPDMACH_TypeDef *pChannel = (LPC_GPDMACH_TypeDef *)Channel_p( ChannelNumber ); |
okini3939 | 0:de79d4a48e63 | 55 | return (bool)( pChannel->DMACCConfig & CxConfig_A() ) ; |
okini3939 | 0:de79d4a48e63 | 56 | } |
okini3939 | 0:de79d4a48e63 | 57 | |
okini3939 | 0:de79d4a48e63 | 58 | void |
okini3939 | 0:de79d4a48e63 | 59 | MODDMA::haltChannel(CHANNELS ChannelNumber) |
okini3939 | 0:de79d4a48e63 | 60 | { |
okini3939 | 0:de79d4a48e63 | 61 | LPC_GPDMACH_TypeDef *pChannel = (LPC_GPDMACH_TypeDef *)Channel_p( ChannelNumber ); |
okini3939 | 0:de79d4a48e63 | 62 | pChannel->DMACCConfig |= CxConfig_H(); |
okini3939 | 0:de79d4a48e63 | 63 | } |
okini3939 | 0:de79d4a48e63 | 64 | |
okini3939 | 0:de79d4a48e63 | 65 | uint32_t |
okini3939 | 0:de79d4a48e63 | 66 | MODDMA::getControl(CHANNELS ChannelNumber) |
okini3939 | 0:de79d4a48e63 | 67 | { |
okini3939 | 0:de79d4a48e63 | 68 | LPC_GPDMACH_TypeDef *pChannel = (LPC_GPDMACH_TypeDef *)Channel_p( ChannelNumber ); |
okini3939 | 0:de79d4a48e63 | 69 | return pChannel->DMACCControl; |
okini3939 | 0:de79d4a48e63 | 70 | } |
okini3939 | 0:de79d4a48e63 | 71 | |
okini3939 | 0:de79d4a48e63 | 72 | uint32_t oldDMAHandler = 0; |
okini3939 | 0:de79d4a48e63 | 73 | typedef void (*MODDMA_FN)(void); |
okini3939 | 0:de79d4a48e63 | 74 | |
okini3939 | 0:de79d4a48e63 | 75 | extern "C" void MODDMA_IRQHandler(void) { |
okini3939 | 0:de79d4a48e63 | 76 | uint32_t channel_mask; |
okini3939 | 0:de79d4a48e63 | 77 | |
okini3939 | 0:de79d4a48e63 | 78 | if (moddma_p == (class MODDMA *)NULL) { |
okini3939 | 0:de79d4a48e63 | 79 | if (oldDMAHandler) { |
okini3939 | 0:de79d4a48e63 | 80 | ((MODDMA_FN)oldDMAHandler)(); |
okini3939 | 0:de79d4a48e63 | 81 | return; |
okini3939 | 0:de79d4a48e63 | 82 | } |
okini3939 | 0:de79d4a48e63 | 83 | else { |
okini3939 | 0:de79d4a48e63 | 84 | error("Interrupt without instance"); |
okini3939 | 0:de79d4a48e63 | 85 | } |
okini3939 | 0:de79d4a48e63 | 86 | } |
okini3939 | 0:de79d4a48e63 | 87 | |
okini3939 | 0:de79d4a48e63 | 88 | for (int channel_number = 0; channel_number < 8; channel_number++) { |
okini3939 | 0:de79d4a48e63 | 89 | channel_mask = (1UL << channel_number); |
okini3939 | 0:de79d4a48e63 | 90 | if (LPC_GPDMA->DMACIntStat & channel_mask) { |
okini3939 | 0:de79d4a48e63 | 91 | if (LPC_GPDMA->DMACIntTCStat & channel_mask) { |
okini3939 | 0:de79d4a48e63 | 92 | if (moddma_p->setups[channel_number] != (MODDMA_Config *)NULL) { |
okini3939 | 0:de79d4a48e63 | 93 | moddma_p->setIrqProcessingChannel((MODDMA::CHANNELS)channel_number); |
okini3939 | 0:de79d4a48e63 | 94 | moddma_p->setIrqType(MODDMA::TcIrq); |
okini3939 | 0:de79d4a48e63 | 95 | moddma_p->setups[channel_number]->isrIntTCStat->call(); |
okini3939 | 0:de79d4a48e63 | 96 | moddma_p->isrIntTCStat.call(); |
okini3939 | 0:de79d4a48e63 | 97 | // The user callback should clear the IRQ. But if they forget |
okini3939 | 0:de79d4a48e63 | 98 | // then the Mbed will lockup. So, check to see if the IRQ has |
okini3939 | 0:de79d4a48e63 | 99 | // been dismissed, if not, we will dismiss it here. |
okini3939 | 0:de79d4a48e63 | 100 | if (LPC_GPDMA->DMACIntTCStat & channel_mask) { |
okini3939 | 0:de79d4a48e63 | 101 | LPC_GPDMA->DMACIntTCClear = channel_mask; |
okini3939 | 0:de79d4a48e63 | 102 | } |
okini3939 | 0:de79d4a48e63 | 103 | // If the user has left the channel enabled, disable it. |
okini3939 | 0:de79d4a48e63 | 104 | // Note, we don't check Active here as it may block inside |
okini3939 | 0:de79d4a48e63 | 105 | // an ISR, we just shut it down immediately. If the user |
okini3939 | 0:de79d4a48e63 | 106 | // must wait for completion they should implement their |
okini3939 | 0:de79d4a48e63 | 107 | // own ISR. But only disable if the LLI linked list register |
okini3939 | 0:de79d4a48e63 | 108 | // is null otherwise we can crap out a series of transfers. |
okini3939 | 0:de79d4a48e63 | 109 | if (moddma_p->Enabled( (MODDMA::CHANNELS)channel_number )) { |
okini3939 | 0:de79d4a48e63 | 110 | if (moddma_p->lli( (MODDMA::CHANNELS)channel_number ) == 0 ) { |
okini3939 | 0:de79d4a48e63 | 111 | moddma_p->Disable( (MODDMA::CHANNELS)channel_number ); |
okini3939 | 0:de79d4a48e63 | 112 | } |
okini3939 | 0:de79d4a48e63 | 113 | } |
okini3939 | 0:de79d4a48e63 | 114 | } |
okini3939 | 0:de79d4a48e63 | 115 | } |
okini3939 | 0:de79d4a48e63 | 116 | |
okini3939 | 0:de79d4a48e63 | 117 | if (LPC_GPDMA->DMACIntErrStat & channel_mask) { |
okini3939 | 0:de79d4a48e63 | 118 | if (moddma_p->setups[channel_number] != (MODDMA_Config *)NULL) { |
okini3939 | 0:de79d4a48e63 | 119 | moddma_p->setIrqProcessingChannel((MODDMA::CHANNELS)channel_number); |
okini3939 | 0:de79d4a48e63 | 120 | moddma_p->setIrqType(MODDMA::ErrIrq); |
okini3939 | 0:de79d4a48e63 | 121 | moddma_p->setups[channel_number]->isrIntErrStat->call(); |
okini3939 | 0:de79d4a48e63 | 122 | moddma_p->isrIntErrStat.call(); |
okini3939 | 0:de79d4a48e63 | 123 | // The user callback should clear the IRQ. But if they forget |
okini3939 | 0:de79d4a48e63 | 124 | // then the Mbed will lockup. So, check to see if the IRQ has |
okini3939 | 0:de79d4a48e63 | 125 | // been dismissed, if not, we will dismiss it here. |
okini3939 | 0:de79d4a48e63 | 126 | if (LPC_GPDMA->DMACIntErrStat & channel_mask) { |
okini3939 | 0:de79d4a48e63 | 127 | LPC_GPDMA->DMACIntErrClr = channel_mask; |
okini3939 | 0:de79d4a48e63 | 128 | } |
okini3939 | 0:de79d4a48e63 | 129 | // If the user has left the channel enabled, disable it. |
okini3939 | 0:de79d4a48e63 | 130 | // Not, we don't check Active here as it may block inside |
okini3939 | 0:de79d4a48e63 | 131 | // an ISR, we just shut it down immediately. If the user |
okini3939 | 0:de79d4a48e63 | 132 | // must wait for completion they should implement their |
okini3939 | 0:de79d4a48e63 | 133 | // own ISR. But only disable if the LLI linked list register |
okini3939 | 0:de79d4a48e63 | 134 | // is null otherwise we can crap out a series of transfers. |
okini3939 | 0:de79d4a48e63 | 135 | if (moddma_p->Enabled( (MODDMA::CHANNELS)channel_number )) { |
okini3939 | 0:de79d4a48e63 | 136 | if (moddma_p->lli( (MODDMA::CHANNELS)channel_number ) == 0 ) { |
okini3939 | 0:de79d4a48e63 | 137 | moddma_p->Disable( (MODDMA::CHANNELS)channel_number ); |
okini3939 | 0:de79d4a48e63 | 138 | } |
okini3939 | 0:de79d4a48e63 | 139 | } |
okini3939 | 0:de79d4a48e63 | 140 | } |
okini3939 | 0:de79d4a48e63 | 141 | } |
okini3939 | 0:de79d4a48e63 | 142 | } |
okini3939 | 0:de79d4a48e63 | 143 | } |
okini3939 | 0:de79d4a48e63 | 144 | |
okini3939 | 0:de79d4a48e63 | 145 | /* IRQ should be handled by now, check to make sure. */ |
okini3939 | 0:de79d4a48e63 | 146 | if (LPC_GPDMA->DMACIntStat) { |
okini3939 | 0:de79d4a48e63 | 147 | ((MODDMA_FN)oldDMAHandler)(); |
okini3939 | 0:de79d4a48e63 | 148 | LPC_GPDMA->DMACIntTCClear = (uint32_t)0xFF; /* If not, clear anyway! */ |
okini3939 | 0:de79d4a48e63 | 149 | } |
okini3939 | 0:de79d4a48e63 | 150 | if (LPC_GPDMA->DMACIntErrStat) { |
okini3939 | 0:de79d4a48e63 | 151 | ((MODDMA_FN)oldDMAHandler)(); |
okini3939 | 0:de79d4a48e63 | 152 | LPC_GPDMA->DMACIntErrClr = (uint32_t)0xFF; /* If not, clear anyway! */ |
okini3939 | 0:de79d4a48e63 | 153 | } |
okini3939 | 0:de79d4a48e63 | 154 | } |
okini3939 | 0:de79d4a48e63 | 155 | |
okini3939 | 0:de79d4a48e63 | 156 | }; // namespace AjK ends |
okini3939 | 0:de79d4a48e63 | 157 |