Test
MODDMA.h@8:cb4d323ce6fd, 2011-02-05 (annotated)
- Committer:
- AjK
- Date:
- Sat Feb 05 08:53:26 2011 +0000
- Revision:
- 8:cb4d323ce6fd
- Parent:
- 7:347110c7aefc
- Child:
- 12:1dfee7208043
1.5 See ChangeLog.c
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 | @file MODDMA.h |
AjK | 8:cb4d323ce6fd | 23 | @purpose Adds DMA controller and multiple transfer configurations |
AjK | 8:cb4d323ce6fd | 24 | @version see ChangeLog.c |
AjK | 8:cb4d323ce6fd | 25 | @date Nov 2010 |
AjK | 8:cb4d323ce6fd | 26 | @author Andy Kirkham |
AjK | 8:cb4d323ce6fd | 27 | */ |
AjK | 8:cb4d323ce6fd | 28 | |
AjK | 8:cb4d323ce6fd | 29 | #ifndef MODDMA_H |
AjK | 8:cb4d323ce6fd | 30 | #define MODDMA_H |
AjK | 8:cb4d323ce6fd | 31 | |
AjK | 8:cb4d323ce6fd | 32 | /** @defgroup API The MODDMA API */ |
AjK | 8:cb4d323ce6fd | 33 | /** @defgroup MISC Misc MODSERIAL functions */ |
AjK | 8:cb4d323ce6fd | 34 | /** @defgroup INTERNALS MODSERIAL Internals */ |
AjK | 8:cb4d323ce6fd | 35 | |
AjK | 8:cb4d323ce6fd | 36 | #include "mbed.h" |
AjK | 8:cb4d323ce6fd | 37 | #include "iomacros.h" |
AjK | 8:cb4d323ce6fd | 38 | |
AjK | 8:cb4d323ce6fd | 39 | namespace AjK { |
AjK | 8:cb4d323ce6fd | 40 | |
AjK | 8:cb4d323ce6fd | 41 | /** |
AjK | 8:cb4d323ce6fd | 42 | * @brief The MODDMA configuration system |
AjK | 8:cb4d323ce6fd | 43 | * @author Andy Kirkham |
AjK | 8:cb4d323ce6fd | 44 | * @see http://mbed.org/cookbook/MODDMA_Config |
AjK | 8:cb4d323ce6fd | 45 | * @see MODDMA |
AjK | 8:cb4d323ce6fd | 46 | * @see API |
AjK | 8:cb4d323ce6fd | 47 | * |
AjK | 8:cb4d323ce6fd | 48 | * <b>MODDMA_Config</b> defines a configuration that can be passed to the MODDMA controller |
AjK | 8:cb4d323ce6fd | 49 | * instance to perform a GPDMA data transfer. |
AjK | 8:cb4d323ce6fd | 50 | */ |
AjK | 8:cb4d323ce6fd | 51 | class MODDMA_Config { |
AjK | 8:cb4d323ce6fd | 52 | protected: |
AjK | 8:cb4d323ce6fd | 53 | |
AjK | 8:cb4d323ce6fd | 54 | // ***************************************** |
AjK | 8:cb4d323ce6fd | 55 | // From GPDMA by NXP MCU SW Application Team |
AjK | 8:cb4d323ce6fd | 56 | // ***************************************** |
AjK | 8:cb4d323ce6fd | 57 | |
AjK | 8:cb4d323ce6fd | 58 | uint32_t ChannelNum; //!< DMA channel number, should be in range from 0 to 7. |
AjK | 8:cb4d323ce6fd | 59 | uint32_t TransferSize; //!< Length/Size of transfer |
AjK | 8:cb4d323ce6fd | 60 | uint32_t TransferWidth; //!< Transfer width - used for TransferType is GPDMA_TRANSFERTYPE_m2m only |
AjK | 8:cb4d323ce6fd | 61 | uint32_t SrcMemAddr; //!< Physical Src Addr, used in case TransferType is chosen as MODDMA::GPDMA_TRANSFERTYPE::m2m or MODDMA::GPDMA_TRANSFERTYPE::m2p |
AjK | 8:cb4d323ce6fd | 62 | uint32_t DstMemAddr; //!< Physical Destination Address, used in case TransferType is chosen as MODDMA::GPDMA_TRANSFERTYPE::m2m or MODDMA::GPDMA_TRANSFERTYPE::p2m |
AjK | 8:cb4d323ce6fd | 63 | uint32_t TransferType; //!< Transfer Type |
AjK | 8:cb4d323ce6fd | 64 | uint32_t SrcConn; //!< Peripheral Source Connection type, used in case TransferType is chosen as |
AjK | 8:cb4d323ce6fd | 65 | uint32_t DstConn; //!< Peripheral Destination Connection type, used in case TransferType is chosen as |
AjK | 8:cb4d323ce6fd | 66 | uint32_t DMALLI; //!< Linker List Item structure data address if there's no Linker List, set as '0' |
AjK | 8:cb4d323ce6fd | 67 | |
AjK | 8:cb4d323ce6fd | 68 | // Mbed specifics. |
AjK | 8:cb4d323ce6fd | 69 | |
AjK | 8:cb4d323ce6fd | 70 | public: |
AjK | 8:cb4d323ce6fd | 71 | |
AjK | 8:cb4d323ce6fd | 72 | MODDMA_Config() { |
AjK | 8:cb4d323ce6fd | 73 | isrIntTCStat = new FunctionPointer; |
AjK | 8:cb4d323ce6fd | 74 | isrIntErrStat = new FunctionPointer; |
AjK | 8:cb4d323ce6fd | 75 | ChannelNum = 0xFFFF; |
AjK | 8:cb4d323ce6fd | 76 | TransferSize = 0; |
AjK | 8:cb4d323ce6fd | 77 | TransferWidth = 0; |
AjK | 8:cb4d323ce6fd | 78 | SrcMemAddr = 0; |
AjK | 8:cb4d323ce6fd | 79 | DstMemAddr = 0; |
AjK | 8:cb4d323ce6fd | 80 | TransferType = 0; |
AjK | 8:cb4d323ce6fd | 81 | SrcConn = 0; |
AjK | 8:cb4d323ce6fd | 82 | DstConn = 0; |
AjK | 8:cb4d323ce6fd | 83 | DMALLI = 0; |
AjK | 8:cb4d323ce6fd | 84 | } |
AjK | 8:cb4d323ce6fd | 85 | |
AjK | 8:cb4d323ce6fd | 86 | ~MODDMA_Config() { |
AjK | 8:cb4d323ce6fd | 87 | delete(isrIntTCStat); |
AjK | 8:cb4d323ce6fd | 88 | delete(isrIntErrStat); |
AjK | 8:cb4d323ce6fd | 89 | } |
AjK | 8:cb4d323ce6fd | 90 | |
AjK | 8:cb4d323ce6fd | 91 | class MODDMA_Config * channelNum(uint32_t n) { ChannelNum = n & 0x7; return this; } |
AjK | 8:cb4d323ce6fd | 92 | class MODDMA_Config * transferSize(uint32_t n) { TransferSize = n; return this; } |
AjK | 8:cb4d323ce6fd | 93 | class MODDMA_Config * transferWidth(uint32_t n) { TransferWidth = n; return this; } |
AjK | 8:cb4d323ce6fd | 94 | class MODDMA_Config * srcMemAddr(uint32_t n) { SrcMemAddr = n; return this; } |
AjK | 8:cb4d323ce6fd | 95 | class MODDMA_Config * dstMemAddr(uint32_t n) { DstMemAddr = n; return this; } |
AjK | 8:cb4d323ce6fd | 96 | class MODDMA_Config * transferType(uint32_t n) { TransferType = n; return this; } |
AjK | 8:cb4d323ce6fd | 97 | class MODDMA_Config * srcConn(uint32_t n) { SrcConn = n; return this; } |
AjK | 8:cb4d323ce6fd | 98 | class MODDMA_Config * dstConn(uint32_t n) { DstConn = n; return this; } |
AjK | 8:cb4d323ce6fd | 99 | class MODDMA_Config * dmaLLI(uint32_t n) { DMALLI = n; return this; } |
AjK | 8:cb4d323ce6fd | 100 | |
AjK | 8:cb4d323ce6fd | 101 | uint32_t channelNum(void) { return ChannelNum; } |
AjK | 8:cb4d323ce6fd | 102 | uint32_t transferSize(void) { return TransferSize; } |
AjK | 8:cb4d323ce6fd | 103 | uint32_t transferWidth(void) { return TransferWidth; } |
AjK | 8:cb4d323ce6fd | 104 | uint32_t srcMemAddr(void) { return SrcMemAddr; } |
AjK | 8:cb4d323ce6fd | 105 | uint32_t dstMemAddr(void) { return DstMemAddr; } |
AjK | 8:cb4d323ce6fd | 106 | uint32_t transferType(void) { return TransferType; } |
AjK | 8:cb4d323ce6fd | 107 | uint32_t srcConn(void) { return SrcConn; } |
AjK | 8:cb4d323ce6fd | 108 | uint32_t dstConn(void) { return DstConn; } |
AjK | 8:cb4d323ce6fd | 109 | uint32_t dmaLLI(void) { return DMALLI; } |
AjK | 8:cb4d323ce6fd | 110 | |
AjK | 8:cb4d323ce6fd | 111 | /** |
AjK | 8:cb4d323ce6fd | 112 | * Attach a callback to the TC IRQ configuration. |
AjK | 8:cb4d323ce6fd | 113 | * |
AjK | 8:cb4d323ce6fd | 114 | * @param fptr A function pointer to call |
AjK | 8:cb4d323ce6fd | 115 | * @return this |
AjK | 8:cb4d323ce6fd | 116 | */ |
AjK | 8:cb4d323ce6fd | 117 | class MODDMA_Config * attach_tc(void (*fptr)(void)) { |
AjK | 8:cb4d323ce6fd | 118 | isrIntTCStat->attach(fptr); |
AjK | 8:cb4d323ce6fd | 119 | return this; |
AjK | 8:cb4d323ce6fd | 120 | } |
AjK | 8:cb4d323ce6fd | 121 | |
AjK | 8:cb4d323ce6fd | 122 | /** |
AjK | 8:cb4d323ce6fd | 123 | * Attach a callback to the ERR IRQ configuration. |
AjK | 8:cb4d323ce6fd | 124 | * |
AjK | 8:cb4d323ce6fd | 125 | * @param fptr A function pointer to call |
AjK | 8:cb4d323ce6fd | 126 | * @return this |
AjK | 8:cb4d323ce6fd | 127 | */ |
AjK | 8:cb4d323ce6fd | 128 | class MODDMA_Config * attach_err(void (*fptr)(void)) { |
AjK | 8:cb4d323ce6fd | 129 | isrIntErrStat->attach(fptr); |
AjK | 8:cb4d323ce6fd | 130 | return this; |
AjK | 8:cb4d323ce6fd | 131 | } |
AjK | 8:cb4d323ce6fd | 132 | |
AjK | 8:cb4d323ce6fd | 133 | /** |
AjK | 8:cb4d323ce6fd | 134 | * Attach a callback to the TC IRQ configuration. |
AjK | 8:cb4d323ce6fd | 135 | * |
AjK | 8:cb4d323ce6fd | 136 | * @param tptr A template pointer to the calling object |
AjK | 8:cb4d323ce6fd | 137 | * @param mptr A method pointer within the object to call. |
AjK | 8:cb4d323ce6fd | 138 | * @return this |
AjK | 8:cb4d323ce6fd | 139 | */ |
AjK | 8:cb4d323ce6fd | 140 | template<typename T> |
AjK | 8:cb4d323ce6fd | 141 | class MODDMA_Config * attach_tc(T* tptr, void (T::*mptr)(void)) { |
AjK | 8:cb4d323ce6fd | 142 | if((mptr != NULL) && (tptr != NULL)) { |
AjK | 8:cb4d323ce6fd | 143 | isrIntTCStat->attach(tptr, mptr); |
AjK | 8:cb4d323ce6fd | 144 | } |
AjK | 8:cb4d323ce6fd | 145 | return this; |
AjK | 8:cb4d323ce6fd | 146 | } |
AjK | 8:cb4d323ce6fd | 147 | |
AjK | 8:cb4d323ce6fd | 148 | /** |
AjK | 8:cb4d323ce6fd | 149 | * Attach a callback to the ERR IRQ configuration. |
AjK | 8:cb4d323ce6fd | 150 | * |
AjK | 8:cb4d323ce6fd | 151 | * @param tptr A template pointer to the calling object |
AjK | 8:cb4d323ce6fd | 152 | * @param mptr A method pointer within the object to call. |
AjK | 8:cb4d323ce6fd | 153 | * @return this |
AjK | 8:cb4d323ce6fd | 154 | */ |
AjK | 8:cb4d323ce6fd | 155 | template<typename T> |
AjK | 8:cb4d323ce6fd | 156 | class MODDMA_Config * attach_err(T* tptr, void (T::*mptr)(void)) { |
AjK | 8:cb4d323ce6fd | 157 | if((mptr != NULL) && (tptr != NULL)) { |
AjK | 8:cb4d323ce6fd | 158 | isrIntErrStat->attach(tptr, mptr); |
AjK | 8:cb4d323ce6fd | 159 | } |
AjK | 8:cb4d323ce6fd | 160 | return this; |
AjK | 8:cb4d323ce6fd | 161 | } |
AjK | 8:cb4d323ce6fd | 162 | FunctionPointer *isrIntTCStat; |
AjK | 8:cb4d323ce6fd | 163 | FunctionPointer *isrIntErrStat; |
AjK | 8:cb4d323ce6fd | 164 | }; |
AjK | 8:cb4d323ce6fd | 165 | |
AjK | 8:cb4d323ce6fd | 166 | /** |
AjK | 8:cb4d323ce6fd | 167 | * @brief The MODDMA configuration system (linked list items) |
AjK | 8:cb4d323ce6fd | 168 | * @author Andy Kirkham |
AjK | 8:cb4d323ce6fd | 169 | * @see http://mbed.org/cookbook/MODDMA_Config |
AjK | 8:cb4d323ce6fd | 170 | * @see MODDMA |
AjK | 8:cb4d323ce6fd | 171 | * @see MODDMA_Config |
AjK | 8:cb4d323ce6fd | 172 | * @see API |
AjK | 8:cb4d323ce6fd | 173 | */ |
AjK | 8:cb4d323ce6fd | 174 | class MODDMA_LLI { |
AjK | 8:cb4d323ce6fd | 175 | public: |
AjK | 8:cb4d323ce6fd | 176 | class MODDMA_LLI *srcAddr(uint32_t n) { SrcAddr = n; return this; } |
AjK | 8:cb4d323ce6fd | 177 | class MODDMA_LLI *dstAddr(uint32_t n) { DstAddr = n; return this; } |
AjK | 8:cb4d323ce6fd | 178 | class MODDMA_LLI *nextLLI(uint32_t n) { NextLLI = n; return this; } |
AjK | 8:cb4d323ce6fd | 179 | class MODDMA_LLI *control(uint32_t n) { Control = n; return this; } |
AjK | 8:cb4d323ce6fd | 180 | uint32_t srcAddr(void) { return SrcAddr; } |
AjK | 8:cb4d323ce6fd | 181 | uint32_t dstAddr(void) { return DstAddr; } |
AjK | 8:cb4d323ce6fd | 182 | uint32_t nextLLI(void) { return NextLLI; } |
AjK | 8:cb4d323ce6fd | 183 | uint32_t control(void) { return Control; } |
AjK | 8:cb4d323ce6fd | 184 | |
AjK | 8:cb4d323ce6fd | 185 | uint32_t SrcAddr; //!< Source Address |
AjK | 8:cb4d323ce6fd | 186 | uint32_t DstAddr; //!< Destination address |
AjK | 8:cb4d323ce6fd | 187 | uint32_t NextLLI; //!< Next LLI address, otherwise set to '0' |
AjK | 8:cb4d323ce6fd | 188 | uint32_t Control; //!< GPDMA Control of this LLI |
AjK | 8:cb4d323ce6fd | 189 | }; |
AjK | 8:cb4d323ce6fd | 190 | |
AjK | 8:cb4d323ce6fd | 191 | |
AjK | 8:cb4d323ce6fd | 192 | |
AjK | 8:cb4d323ce6fd | 193 | /** |
AjK | 8:cb4d323ce6fd | 194 | * @brief MODDMA GPDMA Controller |
AjK | 8:cb4d323ce6fd | 195 | * @author Andy Kirkham |
AjK | 8:cb4d323ce6fd | 196 | * @see http://mbed.org/cookbook/MODDMA |
AjK | 8:cb4d323ce6fd | 197 | * @see example1.cpp |
AjK | 8:cb4d323ce6fd | 198 | * @see API |
AjK | 8:cb4d323ce6fd | 199 | * |
AjK | 8:cb4d323ce6fd | 200 | * <b>MODDMA</b> defines a GPDMA controller and multiple DMA configurations that allow for DMA |
AjK | 8:cb4d323ce6fd | 201 | * transfers from memory to memory, memory to peripheral or peripheral to memory. |
AjK | 8:cb4d323ce6fd | 202 | * |
AjK | 8:cb4d323ce6fd | 203 | * At the heart of the library is the MODDMA class that defines a single instance controller that |
AjK | 8:cb4d323ce6fd | 204 | * manages all the GPDMA hardware registers and interrupts. The controller can accept multiple |
AjK | 8:cb4d323ce6fd | 205 | * configurations that define the channel transfers. Each configuration specifies the source and |
AjK | 8:cb4d323ce6fd | 206 | * destination information and other associated parts to maintain the transfer process. |
AjK | 8:cb4d323ce6fd | 207 | * |
AjK | 8:cb4d323ce6fd | 208 | * Standard example: |
AjK | 8:cb4d323ce6fd | 209 | * @code |
AjK | 8:cb4d323ce6fd | 210 | * #include "mbed.h" |
AjK | 8:cb4d323ce6fd | 211 | * #include "MODDMA.h" |
AjK | 8:cb4d323ce6fd | 212 | * |
AjK | 8:cb4d323ce6fd | 213 | * DigitalOut led1(LED1); |
AjK | 8:cb4d323ce6fd | 214 | * Serial pc(USBTX, USBRX); // tx, rx |
AjK | 8:cb4d323ce6fd | 215 | * MODDMA dma; |
AjK | 8:cb4d323ce6fd | 216 | * |
AjK | 8:cb4d323ce6fd | 217 | * int main() { |
AjK | 8:cb4d323ce6fd | 218 | * |
AjK | 8:cb4d323ce6fd | 219 | * // Create a string buffer to send directly to a Uart/Serial |
AjK | 8:cb4d323ce6fd | 220 | * char s[] = "***DMA*** ABCDEFGHIJKLMNOPQRSTUVWXYZ ***DMA***"; |
AjK | 8:cb4d323ce6fd | 221 | * |
AjK | 8:cb4d323ce6fd | 222 | * // Create a transfer configuarion |
AjK | 8:cb4d323ce6fd | 223 | * MODDMA_Config *config = new MODDMA_Config; |
AjK | 8:cb4d323ce6fd | 224 | * |
AjK | 8:cb4d323ce6fd | 225 | * // Provide a "minimal" setup for demo purposes. |
AjK | 8:cb4d323ce6fd | 226 | * config |
AjK | 8:cb4d323ce6fd | 227 | * ->channelNum ( MODDMA::Channel_0 ) // The DMA channel to use. |
AjK | 8:cb4d323ce6fd | 228 | * ->srcMemAddr ( (uint32_t) &s ) // A pointer to the buffer to send. |
AjK | 8:cb4d323ce6fd | 229 | * ->transferSize ( sizeof(s) ) // The size of that buffer. |
AjK | 8:cb4d323ce6fd | 230 | * ->transferType ( MODDMA::m2p ) // Source is memory, destination is peripheral |
AjK | 8:cb4d323ce6fd | 231 | * ->dstConn ( MODDMA::UART0_Tx ) // Specifically, peripheral is Uart0 TX (USBTX, USBRX) |
AjK | 8:cb4d323ce6fd | 232 | * ; // config end. |
AjK | 8:cb4d323ce6fd | 233 | * |
AjK | 8:cb4d323ce6fd | 234 | * // Pass the configuration to the MODDMA controller. |
AjK | 8:cb4d323ce6fd | 235 | * dma.Setup( config ); |
AjK | 8:cb4d323ce6fd | 236 | * |
AjK | 8:cb4d323ce6fd | 237 | * // Enable the channel and begin transfer. |
AjK | 8:cb4d323ce6fd | 238 | * dma.Enable( config->channelNum() ); |
AjK | 8:cb4d323ce6fd | 239 | * |
AjK | 8:cb4d323ce6fd | 240 | * while(1) { |
AjK | 8:cb4d323ce6fd | 241 | * led1 = !led1; |
AjK | 8:cb4d323ce6fd | 242 | * wait(0.25); |
AjK | 8:cb4d323ce6fd | 243 | * } |
AjK | 8:cb4d323ce6fd | 244 | * } |
AjK | 8:cb4d323ce6fd | 245 | * @endcode |
AjK | 8:cb4d323ce6fd | 246 | */ |
AjK | 8:cb4d323ce6fd | 247 | class MODDMA |
AjK | 8:cb4d323ce6fd | 248 | { |
AjK | 8:cb4d323ce6fd | 249 | public: |
AjK | 8:cb4d323ce6fd | 250 | |
AjK | 8:cb4d323ce6fd | 251 | //! Channel definitions. |
AjK | 8:cb4d323ce6fd | 252 | enum CHANNELS { |
AjK | 8:cb4d323ce6fd | 253 | Channel_0 = 0 /*!< Channel 0 */ |
AjK | 8:cb4d323ce6fd | 254 | , Channel_1 /*!< Channel 1 */ |
AjK | 8:cb4d323ce6fd | 255 | , Channel_2 /*!< Channel 2 */ |
AjK | 8:cb4d323ce6fd | 256 | , Channel_3 /*!< Channel 3 */ |
AjK | 8:cb4d323ce6fd | 257 | , Channel_4 /*!< Channel 4 */ |
AjK | 8:cb4d323ce6fd | 258 | , Channel_5 /*!< Channel 5 */ |
AjK | 8:cb4d323ce6fd | 259 | , Channel_6 /*!< Channel 6 */ |
AjK | 8:cb4d323ce6fd | 260 | , Channel_7 /*!< Channel 7 */ |
AjK | 8:cb4d323ce6fd | 261 | }; |
AjK | 8:cb4d323ce6fd | 262 | |
AjK | 8:cb4d323ce6fd | 263 | //! Interrupt callback types. |
AjK | 8:cb4d323ce6fd | 264 | enum IrqType_t { |
AjK | 8:cb4d323ce6fd | 265 | TcIrq = 0 /*!< Terminal Count interrupt */ |
AjK | 8:cb4d323ce6fd | 266 | , ErrIrq /*!< Error interrupt */ |
AjK | 8:cb4d323ce6fd | 267 | }; |
AjK | 8:cb4d323ce6fd | 268 | |
AjK | 8:cb4d323ce6fd | 269 | //! Return status codes. |
AjK | 8:cb4d323ce6fd | 270 | enum Status { |
AjK | 8:cb4d323ce6fd | 271 | Ok = 0 /*!< Ok, suceeded */ |
AjK | 8:cb4d323ce6fd | 272 | , Error = -1 /*!< General error */ |
AjK | 8:cb4d323ce6fd | 273 | , ErrChInUse = -2 /*!< Specific error, channel in use */ |
AjK | 8:cb4d323ce6fd | 274 | }; |
AjK | 8:cb4d323ce6fd | 275 | |
AjK | 8:cb4d323ce6fd | 276 | //! DMA Connection number definitions |
AjK | 8:cb4d323ce6fd | 277 | enum GPDMA_CONNECTION { |
AjK | 8:cb4d323ce6fd | 278 | SSP0_Tx = 0UL /*!< SSP0 Tx */ |
AjK | 8:cb4d323ce6fd | 279 | , SSP0_Rx = 1UL /*!< SSP0 Rx */ |
AjK | 8:cb4d323ce6fd | 280 | , SSP1_Tx = 2UL /*!< SSP1 Tx */ |
AjK | 8:cb4d323ce6fd | 281 | , SSP1_Rx = 3UL /*!< SSP1 Rx */ |
AjK | 8:cb4d323ce6fd | 282 | , ADC = 4UL /*!< ADC */ |
AjK | 8:cb4d323ce6fd | 283 | , I2S_Channel_0 = 5UL /*!< I2S channel 0 */ |
AjK | 8:cb4d323ce6fd | 284 | , I2S_Channel_1 = 6UL /*!< I2S channel 1 */ |
AjK | 8:cb4d323ce6fd | 285 | , DAC = 7UL /*!< DAC */ |
AjK | 8:cb4d323ce6fd | 286 | , UART0_Tx = 8UL /*!< UART0 Tx */ |
AjK | 8:cb4d323ce6fd | 287 | , UART0_Rx = 9UL /*!< UART0 Rx */ |
AjK | 8:cb4d323ce6fd | 288 | , UART1_Tx = 10UL /*!< UART1 Tx */ |
AjK | 8:cb4d323ce6fd | 289 | , UART1_Rx = 11UL /*!< UART1 Rx */ |
AjK | 8:cb4d323ce6fd | 290 | , UART2_Tx = 12UL /*!< UART2 Tx */ |
AjK | 8:cb4d323ce6fd | 291 | , UART2_Rx = 13UL /*!< UART2 Rx */ |
AjK | 8:cb4d323ce6fd | 292 | , UART3_Tx = 14UL /*!< UART3 Tx */ |
AjK | 8:cb4d323ce6fd | 293 | , UART3_Rx = 15UL /*!< UART3 Rx */ |
AjK | 8:cb4d323ce6fd | 294 | , MAT0_0 = 16UL /*!< MAT0.0 */ |
AjK | 8:cb4d323ce6fd | 295 | , MAT0_1 = 17UL /*!< MAT0.1 */ |
AjK | 8:cb4d323ce6fd | 296 | , MAT1_0 = 18UL /*!< MAT1.0 */ |
AjK | 8:cb4d323ce6fd | 297 | , MAT1_1 = 19UL /*!< MAT1.1 */ |
AjK | 8:cb4d323ce6fd | 298 | , MAT2_0 = 20UL /**< MAT2.0 */ |
AjK | 8:cb4d323ce6fd | 299 | , MAT2_1 = 21UL /*!< MAT2.1 */ |
AjK | 8:cb4d323ce6fd | 300 | , MAT3_0 = 22UL /*!< MAT3.0 */ |
AjK | 8:cb4d323ce6fd | 301 | , MAT3_1 = 23UL /*!< MAT3.1 */ |
AjK | 8:cb4d323ce6fd | 302 | }; |
AjK | 8:cb4d323ce6fd | 303 | |
AjK | 8:cb4d323ce6fd | 304 | //! GPDMA Transfer type definitions |
AjK | 8:cb4d323ce6fd | 305 | enum GPDMA_TRANSFERTYPE { |
AjK | 8:cb4d323ce6fd | 306 | m2m = 0UL /*!< Memory to memory - DMA control */ |
AjK | 8:cb4d323ce6fd | 307 | , m2p = 1UL /*!< Memory to peripheral - DMA control */ |
AjK | 8:cb4d323ce6fd | 308 | , p2m = 2UL /*!< Peripheral to memory - DMA control */ |
AjK | 8:cb4d323ce6fd | 309 | , p2p = 3UL /*!< Src peripheral to dest peripheral - DMA control */ |
AjK | 8:cb4d323ce6fd | 310 | }; |
AjK | 8:cb4d323ce6fd | 311 | |
AjK | 8:cb4d323ce6fd | 312 | //! Burst size in Source and Destination definitions */ |
AjK | 8:cb4d323ce6fd | 313 | enum GPDMA_BSIZE { |
AjK | 8:cb4d323ce6fd | 314 | _1 = 0UL /*!< Burst size = 1 */ |
AjK | 8:cb4d323ce6fd | 315 | , _4 = 1UL /*!< Burst size = 4 */ |
AjK | 8:cb4d323ce6fd | 316 | , _8 = 2UL /*!< Burst size = 8 */ |
AjK | 8:cb4d323ce6fd | 317 | , _16 = 3UL /*!< Burst size = 16 */ |
AjK | 8:cb4d323ce6fd | 318 | , _32 = 4UL /*!< Burst size = 32 */ |
AjK | 8:cb4d323ce6fd | 319 | , _64 = 5UL /*!< Burst size = 64 */ |
AjK | 8:cb4d323ce6fd | 320 | , _128 = 6UL /*!< Burst size = 128 */ |
AjK | 8:cb4d323ce6fd | 321 | , _256 = 7UL /*!< Burst size = 256 */ |
AjK | 8:cb4d323ce6fd | 322 | }; |
AjK | 8:cb4d323ce6fd | 323 | |
AjK | 8:cb4d323ce6fd | 324 | //! Width in Src transfer width and Dest transfer width definitions */ |
AjK | 8:cb4d323ce6fd | 325 | enum GPDMA_WIDTH { |
AjK | 8:cb4d323ce6fd | 326 | byte = 0UL /*!< Width = 1 byte */ |
AjK | 8:cb4d323ce6fd | 327 | , halfword = 1UL /*!< Width = 2 bytes */ |
AjK | 8:cb4d323ce6fd | 328 | , word = 2UL /*!< Width = 4 bytes */ |
AjK | 8:cb4d323ce6fd | 329 | }; |
AjK | 8:cb4d323ce6fd | 330 | |
AjK | 8:cb4d323ce6fd | 331 | //! DMA Request Select Mode definitions. */ |
AjK | 8:cb4d323ce6fd | 332 | enum GPDMA_REQSEL { |
AjK | 8:cb4d323ce6fd | 333 | uart = 0UL /*!< UART TX/RX is selected */ |
AjK | 8:cb4d323ce6fd | 334 | , timer = 1UL /*!< Timer match is selected */ |
AjK | 8:cb4d323ce6fd | 335 | }; |
AjK | 8:cb4d323ce6fd | 336 | |
AjK | 8:cb4d323ce6fd | 337 | //! GPDMA Control register bits. |
AjK | 8:cb4d323ce6fd | 338 | enum Config { |
AjK | 8:cb4d323ce6fd | 339 | _E = 1 /*!< DMA Controller enable */ |
AjK | 8:cb4d323ce6fd | 340 | , _M = 2 /*!< AHB Master endianness configuration */ |
AjK | 8:cb4d323ce6fd | 341 | }; |
AjK | 8:cb4d323ce6fd | 342 | |
AjK | 8:cb4d323ce6fd | 343 | //! GPDMA Channel config register bits. |
AjK | 8:cb4d323ce6fd | 344 | enum CConfig { |
AjK | 8:cb4d323ce6fd | 345 | _CE = (1UL << 0) /*!< Channel enable */ |
AjK | 8:cb4d323ce6fd | 346 | , _IE = (1UL << 14) /*!< Interrupt error mask */ |
AjK | 8:cb4d323ce6fd | 347 | , _ITC = (1UL << 15) /*!< Terminal count interrupt mask */ |
AjK | 8:cb4d323ce6fd | 348 | , _L = (1UL << 16) /*!< Lock */ |
AjK | 8:cb4d323ce6fd | 349 | , _A = (1UL << 17) /*!< Active */ |
AjK | 8:cb4d323ce6fd | 350 | , _H = (1UL << 18) /*!< Halt */ |
AjK | 8:cb4d323ce6fd | 351 | }; |
AjK | 8:cb4d323ce6fd | 352 | |
AjK | 8:cb4d323ce6fd | 353 | /** |
AjK | 8:cb4d323ce6fd | 354 | * The MODDMA constructor is used to initialise the DMA controller object. |
AjK | 8:cb4d323ce6fd | 355 | */ |
AjK | 8:cb4d323ce6fd | 356 | MODDMA() { init(true); } |
AjK | 8:cb4d323ce6fd | 357 | |
AjK | 8:cb4d323ce6fd | 358 | /** |
AjK | 8:cb4d323ce6fd | 359 | * The MODDMA destructor. |
AjK | 8:cb4d323ce6fd | 360 | */ |
AjK | 8:cb4d323ce6fd | 361 | ~MODDMA() {} |
AjK | 8:cb4d323ce6fd | 362 | |
AjK | 8:cb4d323ce6fd | 363 | /** |
AjK | 8:cb4d323ce6fd | 364 | * Used to setup the DMA controller to prepare for a data transfer. |
AjK | 8:cb4d323ce6fd | 365 | * |
AjK | 8:cb4d323ce6fd | 366 | * @ingroup API |
AjK | 8:cb4d323ce6fd | 367 | * @param isConstructorCalling Set true when called from teh constructor |
AjK | 8:cb4d323ce6fd | 368 | * @param |
AjK | 8:cb4d323ce6fd | 369 | */ |
AjK | 8:cb4d323ce6fd | 370 | void init(bool isConstructorCalling, int Channels = 0xFF, int Tc = 0xFF, int Err = 0xFF); |
AjK | 8:cb4d323ce6fd | 371 | |
AjK | 8:cb4d323ce6fd | 372 | /** |
AjK | 8:cb4d323ce6fd | 373 | * Used to setup the DMA controller to prepare for a data transfer. |
AjK | 8:cb4d323ce6fd | 374 | * |
AjK | 8:cb4d323ce6fd | 375 | * @ingroup API |
AjK | 8:cb4d323ce6fd | 376 | * @param c A pointer to an instance of MODDMA_Config to setup. |
AjK | 8:cb4d323ce6fd | 377 | */ |
AjK | 8:cb4d323ce6fd | 378 | uint32_t Setup(MODDMA_Config *c); |
AjK | 8:cb4d323ce6fd | 379 | |
AjK | 8:cb4d323ce6fd | 380 | /** |
AjK | 8:cb4d323ce6fd | 381 | * Enable and begin data transfer. |
AjK | 8:cb4d323ce6fd | 382 | * |
AjK | 8:cb4d323ce6fd | 383 | * @ingroup API |
AjK | 8:cb4d323ce6fd | 384 | * @param ChannelNumber Type CHANNELS, the channel number to enable |
AjK | 8:cb4d323ce6fd | 385 | */ |
AjK | 8:cb4d323ce6fd | 386 | void Enable(CHANNELS ChannelNumber); |
AjK | 8:cb4d323ce6fd | 387 | |
AjK | 8:cb4d323ce6fd | 388 | /** |
AjK | 8:cb4d323ce6fd | 389 | * Enable and begin data transfer (overloaded function) |
AjK | 8:cb4d323ce6fd | 390 | * |
AjK | 8:cb4d323ce6fd | 391 | * @ingroup API |
AjK | 8:cb4d323ce6fd | 392 | * @param ChannelNumber Type uin32_t, the channel number to enable |
AjK | 8:cb4d323ce6fd | 393 | */ |
AjK | 8:cb4d323ce6fd | 394 | void Enable(uint32_t ChannelNumber) { Enable((CHANNELS)(ChannelNumber & 0x7)); } |
AjK | 8:cb4d323ce6fd | 395 | |
AjK | 8:cb4d323ce6fd | 396 | /** |
AjK | 8:cb4d323ce6fd | 397 | * Enable and begin data transfer (overloaded function) |
AjK | 8:cb4d323ce6fd | 398 | * |
AjK | 8:cb4d323ce6fd | 399 | * @ingroup API |
AjK | 8:cb4d323ce6fd | 400 | * @param config A pointer to teh configuration |
AjK | 8:cb4d323ce6fd | 401 | */ |
AjK | 8:cb4d323ce6fd | 402 | void Enable(MODDMA_Config *config) { Enable( config->channelNum() ); } |
AjK | 8:cb4d323ce6fd | 403 | |
AjK | 8:cb4d323ce6fd | 404 | |
AjK | 8:cb4d323ce6fd | 405 | /** |
AjK | 8:cb4d323ce6fd | 406 | * Disable a channel and end data transfer. |
AjK | 8:cb4d323ce6fd | 407 | * |
AjK | 8:cb4d323ce6fd | 408 | * @ingroup API |
AjK | 8:cb4d323ce6fd | 409 | * @param ChannelNumber Type CHANNELS, the channel number to enable |
AjK | 8:cb4d323ce6fd | 410 | */ |
AjK | 8:cb4d323ce6fd | 411 | void Disable(CHANNELS ChannelNumber); |
AjK | 8:cb4d323ce6fd | 412 | |
AjK | 8:cb4d323ce6fd | 413 | /** |
AjK | 8:cb4d323ce6fd | 414 | * Disable a channel and end data transfer (overloaded function) |
AjK | 8:cb4d323ce6fd | 415 | * |
AjK | 8:cb4d323ce6fd | 416 | * @ingroup API |
AjK | 8:cb4d323ce6fd | 417 | * @param ChannelNumber Type uin32_t, the channel number to disable |
AjK | 8:cb4d323ce6fd | 418 | */ |
AjK | 8:cb4d323ce6fd | 419 | void Disable(uint32_t ChannelNumber) { Disable((CHANNELS)(ChannelNumber & 0x7)); } |
AjK | 8:cb4d323ce6fd | 420 | |
AjK | 8:cb4d323ce6fd | 421 | /** |
AjK | 8:cb4d323ce6fd | 422 | * Is the specified channel enabled? |
AjK | 8:cb4d323ce6fd | 423 | * |
AjK | 8:cb4d323ce6fd | 424 | * @ingroup API |
AjK | 8:cb4d323ce6fd | 425 | * @param ChannelNumber Type CHANNELS, the channel number to test |
AjK | 8:cb4d323ce6fd | 426 | * @return bool true if enabled, false otherwise. |
AjK | 8:cb4d323ce6fd | 427 | */ |
AjK | 8:cb4d323ce6fd | 428 | bool Enabled(CHANNELS ChannelNumber); |
AjK | 8:cb4d323ce6fd | 429 | |
AjK | 8:cb4d323ce6fd | 430 | /** |
AjK | 8:cb4d323ce6fd | 431 | * Is the specified channel enabled? (overloaded function) |
AjK | 8:cb4d323ce6fd | 432 | * |
AjK | 8:cb4d323ce6fd | 433 | * @ingroup API |
AjK | 8:cb4d323ce6fd | 434 | * @param ChannelNumber Type uin32_t, the channel number to test |
AjK | 8:cb4d323ce6fd | 435 | * @return bool true if enabled, false otherwise. |
AjK | 8:cb4d323ce6fd | 436 | */ |
AjK | 8:cb4d323ce6fd | 437 | bool Enabled(uint32_t ChannelNumber) { return Enabled((CHANNELS)(ChannelNumber & 0x7)); } |
AjK | 8:cb4d323ce6fd | 438 | |
AjK | 8:cb4d323ce6fd | 439 | __INLINE uint32_t IntStat(uint32_t n) { return (1UL << n) & 0xFF; } |
AjK | 8:cb4d323ce6fd | 440 | __INLINE uint32_t IntTCStat_Ch(uint32_t n) { return (1UL << n) & 0xFF; } |
AjK | 8:cb4d323ce6fd | 441 | __INLINE uint32_t IntTCClear_Ch(uint32_t n) { return (1UL << n) & 0xFF; } |
AjK | 8:cb4d323ce6fd | 442 | __INLINE uint32_t IntErrStat_Ch(uint32_t n) { return (1UL << n) & 0xFF; } |
AjK | 8:cb4d323ce6fd | 443 | __INLINE uint32_t IntErrClr_Ch(uint32_t n) { return (1UL << n) & 0xFF; } |
AjK | 8:cb4d323ce6fd | 444 | __INLINE uint32_t RawIntErrStat_Ch(uint32_t n) { return (1UL << n) & 0xFF; } |
AjK | 8:cb4d323ce6fd | 445 | __INLINE uint32_t EnbldChns_Ch(uint32_t n) { return (1UL << n) & 0xFF; } |
AjK | 8:cb4d323ce6fd | 446 | __INLINE uint32_t SoftBReq_Src(uint32_t n) { return (1UL << n) & 0xFFFF; } |
AjK | 8:cb4d323ce6fd | 447 | __INLINE uint32_t SoftSReq_Src(uint32_t n) { return (1UL << n) & 0xFFFF; } |
AjK | 8:cb4d323ce6fd | 448 | __INLINE uint32_t SoftLBReq_Src(uint32_t n) { return (1UL << n) & 0xFFFF; } |
AjK | 8:cb4d323ce6fd | 449 | __INLINE uint32_t SoftLSReq_Src(uint32_t n) { return (1UL << n) & 0xFFFF; } |
AjK | 8:cb4d323ce6fd | 450 | __INLINE uint32_t Sync_Src(uint32_t n) { return (1UL << n) & 0xFFFF; } |
AjK | 8:cb4d323ce6fd | 451 | __INLINE uint32_t ReqSel_Input(uint32_t n) { return (1UL << (n - 8)) & 0xFF; } |
AjK | 8:cb4d323ce6fd | 452 | |
AjK | 8:cb4d323ce6fd | 453 | |
AjK | 8:cb4d323ce6fd | 454 | __INLINE uint32_t CxControl_TransferSize(uint32_t n) { return (n & 0xFFF) << 0; } |
AjK | 8:cb4d323ce6fd | 455 | __INLINE uint32_t CxControl_SBSize(uint32_t n) { return (n & 0x7) << 12; } |
AjK | 8:cb4d323ce6fd | 456 | __INLINE uint32_t CxControl_DBSize(uint32_t n) { return (n & 0x7) << 15; } |
AjK | 8:cb4d323ce6fd | 457 | __INLINE uint32_t CxControl_SWidth(uint32_t n) { return (n & 0x7) << 18; } |
AjK | 8:cb4d323ce6fd | 458 | __INLINE uint32_t CxControl_DWidth(uint32_t n) { return (n & 0x7) << 21; } |
AjK | 8:cb4d323ce6fd | 459 | __INLINE uint32_t CxControl_SI() { return (1UL << 26); } |
AjK | 8:cb4d323ce6fd | 460 | __INLINE uint32_t CxControl_DI() { return (1UL << 27); } |
AjK | 8:cb4d323ce6fd | 461 | __INLINE uint32_t CxControl_Prot1() { return (1UL << 28); } |
AjK | 8:cb4d323ce6fd | 462 | __INLINE uint32_t CxControl_Prot2() { return (1UL << 29); } |
AjK | 8:cb4d323ce6fd | 463 | __INLINE uint32_t CxControl_Prot3() { return (1UL << 30); } |
AjK | 8:cb4d323ce6fd | 464 | __INLINE uint32_t CxControl_I() { return (1UL << 31); } |
AjK | 8:cb4d323ce6fd | 465 | __INLINE uint32_t CxControl_E() { return (1UL << 0); } |
AjK | 8:cb4d323ce6fd | 466 | __INLINE uint32_t CxConfig_SrcPeripheral(uint32_t n) { return (n & 0x1F) << 1; } |
AjK | 8:cb4d323ce6fd | 467 | __INLINE uint32_t CxConfig_DestPeripheral(uint32_t n) { return (n & 0x1F) << 6; } |
AjK | 8:cb4d323ce6fd | 468 | __INLINE uint32_t CxConfig_TransferType(uint32_t n) { return (n & 0x7) << 11; } |
AjK | 8:cb4d323ce6fd | 469 | __INLINE uint32_t CxConfig_IE() { return (1UL << 14); } |
AjK | 8:cb4d323ce6fd | 470 | __INLINE uint32_t CxConfig_ITC() { return (1UL << 15); } |
AjK | 8:cb4d323ce6fd | 471 | __INLINE uint32_t CxConfig_L() { return (1UL << 16); } |
AjK | 8:cb4d323ce6fd | 472 | __INLINE uint32_t CxConfig_A() { return (1UL << 17); } |
AjK | 8:cb4d323ce6fd | 473 | __INLINE uint32_t CxConfig_H() { return (1UL << 18); } |
AjK | 8:cb4d323ce6fd | 474 | |
AjK | 8:cb4d323ce6fd | 475 | /** |
AjK | 8:cb4d323ce6fd | 476 | * A store for up to 8 (8 channels) of configurations. |
AjK | 8:cb4d323ce6fd | 477 | * @see MODDMA_Config |
AjK | 8:cb4d323ce6fd | 478 | */ |
AjK | 8:cb4d323ce6fd | 479 | MODDMA_Config *setups[8]; |
AjK | 8:cb4d323ce6fd | 480 | |
AjK | 8:cb4d323ce6fd | 481 | /** |
AjK | 8:cb4d323ce6fd | 482 | * Get a pointer to the current configuration the ISR is servicing. |
AjK | 8:cb4d323ce6fd | 483 | * |
AjK | 8:cb4d323ce6fd | 484 | * @ingroup API |
AjK | 8:cb4d323ce6fd | 485 | * @return MODDMA_Config * A pointer to the setup the ISR is currently servicing. |
AjK | 8:cb4d323ce6fd | 486 | */ |
AjK | 8:cb4d323ce6fd | 487 | MODDMA_Config *getConfig(void) { return setups[IrqProcessingChannel]; } |
AjK | 8:cb4d323ce6fd | 488 | |
AjK | 8:cb4d323ce6fd | 489 | /** |
AjK | 8:cb4d323ce6fd | 490 | * Set which channel the ISR is currently servicing. |
AjK | 8:cb4d323ce6fd | 491 | * |
AjK | 8:cb4d323ce6fd | 492 | * *** USED INTERNALLY. DO NOT CALL FROM USER PROGRAMS *** |
AjK | 8:cb4d323ce6fd | 493 | * |
AjK | 8:cb4d323ce6fd | 494 | * Must be public so the extern "C" ISR can use it. |
AjK | 8:cb4d323ce6fd | 495 | */ |
AjK | 8:cb4d323ce6fd | 496 | void setIrqProcessingChannel(CHANNELS n) { IrqProcessingChannel = n; } |
AjK | 8:cb4d323ce6fd | 497 | |
AjK | 8:cb4d323ce6fd | 498 | /** |
AjK | 8:cb4d323ce6fd | 499 | * Gets which channel the ISR is currently servicing. |
AjK | 8:cb4d323ce6fd | 500 | * |
AjK | 8:cb4d323ce6fd | 501 | * @ingroup API |
AjK | 8:cb4d323ce6fd | 502 | * @return CHANNELS The current channel the ISR is servicing. |
AjK | 8:cb4d323ce6fd | 503 | */ |
AjK | 8:cb4d323ce6fd | 504 | CHANNELS irqProcessingChannel(void) { return IrqProcessingChannel; } |
AjK | 8:cb4d323ce6fd | 505 | |
AjK | 8:cb4d323ce6fd | 506 | /** |
AjK | 8:cb4d323ce6fd | 507 | * Sets which type of IRQ the ISR is making a callback for. |
AjK | 8:cb4d323ce6fd | 508 | * |
AjK | 8:cb4d323ce6fd | 509 | * *** USED INTERNALLY. DO NOT CALL FROM USER PROGRAMS *** |
AjK | 8:cb4d323ce6fd | 510 | * |
AjK | 8:cb4d323ce6fd | 511 | * Must be public so the extern "C" ISR can use it. |
AjK | 8:cb4d323ce6fd | 512 | */ |
AjK | 8:cb4d323ce6fd | 513 | void setIrqType(IrqType_t n) { IrqType = n; } |
AjK | 8:cb4d323ce6fd | 514 | |
AjK | 8:cb4d323ce6fd | 515 | /** |
AjK | 8:cb4d323ce6fd | 516 | * Get which type of IRQ the ISR is calling you about, |
AjK | 8:cb4d323ce6fd | 517 | * terminal count or error. |
AjK | 8:cb4d323ce6fd | 518 | */ |
AjK | 8:cb4d323ce6fd | 519 | IrqType_t irqType(void) { return IrqType; } |
AjK | 8:cb4d323ce6fd | 520 | |
AjK | 8:cb4d323ce6fd | 521 | /** |
AjK | 8:cb4d323ce6fd | 522 | * Clear the interrupt after handling. |
AjK | 8:cb4d323ce6fd | 523 | * |
AjK | 8:cb4d323ce6fd | 524 | * @param CHANNELS The channel the IQR occured on. |
AjK | 8:cb4d323ce6fd | 525 | */ |
AjK | 8:cb4d323ce6fd | 526 | void clearTcIrq(CHANNELS n) { LPC_GPDMA->DMACIntTCClear = (uint32_t)(1UL << n); } |
AjK | 8:cb4d323ce6fd | 527 | |
AjK | 8:cb4d323ce6fd | 528 | /** |
AjK | 8:cb4d323ce6fd | 529 | * Clear the interrupt the ISR is currently handing.. |
AjK | 8:cb4d323ce6fd | 530 | */ |
AjK | 8:cb4d323ce6fd | 531 | void clearTcIrq(void) { clearTcIrq( IrqProcessingChannel ); } |
AjK | 8:cb4d323ce6fd | 532 | |
AjK | 8:cb4d323ce6fd | 533 | /** |
AjK | 8:cb4d323ce6fd | 534 | * Clear the error interrupt after handling. |
AjK | 8:cb4d323ce6fd | 535 | * |
AjK | 8:cb4d323ce6fd | 536 | * @ingroup API |
AjK | 8:cb4d323ce6fd | 537 | * @param CHANNELS The channel the IQR occured on. |
AjK | 8:cb4d323ce6fd | 538 | */ |
AjK | 8:cb4d323ce6fd | 539 | void clearErrIrq(CHANNELS n) { LPC_GPDMA->DMACIntTCClear = (uint32_t)(1UL << n); } |
AjK | 8:cb4d323ce6fd | 540 | |
AjK | 8:cb4d323ce6fd | 541 | /** |
AjK | 8:cb4d323ce6fd | 542 | * Clear the error interrupt the ISR is currently handing. |
AjK | 8:cb4d323ce6fd | 543 | * @ingroup API |
AjK | 8:cb4d323ce6fd | 544 | */ |
AjK | 8:cb4d323ce6fd | 545 | void clearErrIrq(void) { clearErrIrq( IrqProcessingChannel ); } |
AjK | 8:cb4d323ce6fd | 546 | |
AjK | 8:cb4d323ce6fd | 547 | /** |
AjK | 8:cb4d323ce6fd | 548 | * Is the supplied channel currently active? |
AjK | 8:cb4d323ce6fd | 549 | * |
AjK | 8:cb4d323ce6fd | 550 | * @ingroup API |
AjK | 8:cb4d323ce6fd | 551 | * @param CHANNELS The channel to inquire about. |
AjK | 8:cb4d323ce6fd | 552 | * @return bool true if active, false otherwise. |
AjK | 8:cb4d323ce6fd | 553 | */ |
AjK | 8:cb4d323ce6fd | 554 | bool isActive(CHANNELS ChannelNumber); |
AjK | 8:cb4d323ce6fd | 555 | |
AjK | 8:cb4d323ce6fd | 556 | /** |
AjK | 8:cb4d323ce6fd | 557 | * Halt the supplied channel. |
AjK | 8:cb4d323ce6fd | 558 | * |
AjK | 8:cb4d323ce6fd | 559 | * @ingroup API |
AjK | 8:cb4d323ce6fd | 560 | * @param CHANNELS The channel to halt. |
AjK | 8:cb4d323ce6fd | 561 | */ |
AjK | 8:cb4d323ce6fd | 562 | void haltChannel(CHANNELS ChannelNumber); |
AjK | 8:cb4d323ce6fd | 563 | |
AjK | 8:cb4d323ce6fd | 564 | /** |
AjK | 8:cb4d323ce6fd | 565 | * get a channels control register. |
AjK | 8:cb4d323ce6fd | 566 | * |
AjK | 8:cb4d323ce6fd | 567 | * @ingroup API |
AjK | 8:cb4d323ce6fd | 568 | * @param CHANNELS The channel to get the control register for. |
AjK | 8:cb4d323ce6fd | 569 | */ |
AjK | 8:cb4d323ce6fd | 570 | uint32_t getControl(CHANNELS ChannelNumber); |
AjK | 8:cb4d323ce6fd | 571 | |
AjK | 8:cb4d323ce6fd | 572 | /** |
AjK | 8:cb4d323ce6fd | 573 | * Wait for channel transfer to complete and then halt. |
AjK | 8:cb4d323ce6fd | 574 | * |
AjK | 8:cb4d323ce6fd | 575 | * @ingroup API |
AjK | 8:cb4d323ce6fd | 576 | * @param CHANNELS The channel to wait for then halt. |
AjK | 8:cb4d323ce6fd | 577 | */ |
AjK | 8:cb4d323ce6fd | 578 | void haltAndWaitChannelComplete(CHANNELS n) { haltChannel(n); while (isActive(n)); } |
AjK | 8:cb4d323ce6fd | 579 | |
AjK | 8:cb4d323ce6fd | 580 | /** |
AjK | 8:cb4d323ce6fd | 581 | * Attach a callback to the TC IRQ controller. |
AjK | 8:cb4d323ce6fd | 582 | * |
AjK | 8:cb4d323ce6fd | 583 | * @ingroup API |
AjK | 8:cb4d323ce6fd | 584 | * @param fptr A function pointer to call |
AjK | 8:cb4d323ce6fd | 585 | * @return this |
AjK | 8:cb4d323ce6fd | 586 | */ |
AjK | 8:cb4d323ce6fd | 587 | void attach_tc(void (*fptr)(void)) { |
AjK | 8:cb4d323ce6fd | 588 | isrIntTCStat.attach(fptr); |
AjK | 8:cb4d323ce6fd | 589 | } |
AjK | 8:cb4d323ce6fd | 590 | |
AjK | 8:cb4d323ce6fd | 591 | /** |
AjK | 8:cb4d323ce6fd | 592 | * Attach a callback to the TC IRQ controller. |
AjK | 8:cb4d323ce6fd | 593 | * |
AjK | 8:cb4d323ce6fd | 594 | * @ingroup API |
AjK | 8:cb4d323ce6fd | 595 | * @param tptr A template pointer to the calling object |
AjK | 8:cb4d323ce6fd | 596 | * @param mptr A method pointer within the object to call. |
AjK | 8:cb4d323ce6fd | 597 | * @return this |
AjK | 8:cb4d323ce6fd | 598 | */ |
AjK | 8:cb4d323ce6fd | 599 | template<typename T> |
AjK | 8:cb4d323ce6fd | 600 | void attach_tc(T* tptr, void (T::*mptr)(void)) { |
AjK | 8:cb4d323ce6fd | 601 | if((mptr != NULL) && (tptr != NULL)) { |
AjK | 8:cb4d323ce6fd | 602 | isrIntTCStat.attach(tptr, mptr); |
AjK | 8:cb4d323ce6fd | 603 | } |
AjK | 8:cb4d323ce6fd | 604 | } |
AjK | 8:cb4d323ce6fd | 605 | |
AjK | 8:cb4d323ce6fd | 606 | /** |
AjK | 8:cb4d323ce6fd | 607 | * The MODDMA controllers terminal count interrupt callback. |
AjK | 8:cb4d323ce6fd | 608 | */ |
AjK | 8:cb4d323ce6fd | 609 | FunctionPointer isrIntTCStat; |
AjK | 8:cb4d323ce6fd | 610 | |
AjK | 8:cb4d323ce6fd | 611 | /** |
AjK | 8:cb4d323ce6fd | 612 | * Attach a callback to the ERR IRQ controller. |
AjK | 8:cb4d323ce6fd | 613 | * |
AjK | 8:cb4d323ce6fd | 614 | * @ingroup API |
AjK | 8:cb4d323ce6fd | 615 | * @param fptr A function pointer to call |
AjK | 8:cb4d323ce6fd | 616 | * @return this |
AjK | 8:cb4d323ce6fd | 617 | */ |
AjK | 8:cb4d323ce6fd | 618 | void attach_err(void (*fptr)(void)) { |
AjK | 8:cb4d323ce6fd | 619 | isrIntErrStat.attach(fptr); |
AjK | 8:cb4d323ce6fd | 620 | } |
AjK | 8:cb4d323ce6fd | 621 | |
AjK | 8:cb4d323ce6fd | 622 | /** |
AjK | 8:cb4d323ce6fd | 623 | * Attach a callback to the ERR IRQ controller. |
AjK | 8:cb4d323ce6fd | 624 | * |
AjK | 8:cb4d323ce6fd | 625 | * @ingroup API |
AjK | 8:cb4d323ce6fd | 626 | * @param tptr A template pointer to the calling object |
AjK | 8:cb4d323ce6fd | 627 | * @param mptr A method pointer within the object to call. |
AjK | 8:cb4d323ce6fd | 628 | * @return this |
AjK | 8:cb4d323ce6fd | 629 | */ |
AjK | 8:cb4d323ce6fd | 630 | template<typename T> |
AjK | 8:cb4d323ce6fd | 631 | void attach_err(T* tptr, void (T::*mptr)(void)) { |
AjK | 8:cb4d323ce6fd | 632 | if((mptr != NULL) && (tptr != NULL)) { |
AjK | 8:cb4d323ce6fd | 633 | isrIntErrStat.attach(tptr, mptr); |
AjK | 8:cb4d323ce6fd | 634 | } |
AjK | 8:cb4d323ce6fd | 635 | } |
AjK | 8:cb4d323ce6fd | 636 | |
AjK | 8:cb4d323ce6fd | 637 | /** |
AjK | 8:cb4d323ce6fd | 638 | * Get the Linked List index regsiter for the requested channel. |
AjK | 8:cb4d323ce6fd | 639 | * |
AjK | 8:cb4d323ce6fd | 640 | * @param channelNum The channel number. |
AjK | 8:cb4d323ce6fd | 641 | * @return uint32_t The value of the DMACCLLI register |
AjK | 8:cb4d323ce6fd | 642 | */ |
AjK | 8:cb4d323ce6fd | 643 | uint32_t lli(CHANNELS ChannelNumber, MODDMA_LLI *set = 0) { |
AjK | 8:cb4d323ce6fd | 644 | LPC_GPDMACH_TypeDef *pChannel = (LPC_GPDMACH_TypeDef *)Channel_p( ChannelNumber & 0x7 ); |
AjK | 8:cb4d323ce6fd | 645 | if (set) pChannel->DMACCLLI = (uint32_t)set; |
AjK | 8:cb4d323ce6fd | 646 | return pChannel->DMACCLLI; |
AjK | 8:cb4d323ce6fd | 647 | } |
AjK | 8:cb4d323ce6fd | 648 | |
AjK | 8:cb4d323ce6fd | 649 | /** |
AjK | 8:cb4d323ce6fd | 650 | * The MODDMA controllers error interrupt callback. |
AjK | 8:cb4d323ce6fd | 651 | */ |
AjK | 8:cb4d323ce6fd | 652 | FunctionPointer isrIntErrStat; |
AjK | 8:cb4d323ce6fd | 653 | |
AjK | 8:cb4d323ce6fd | 654 | protected: |
AjK | 8:cb4d323ce6fd | 655 | |
AjK | 8:cb4d323ce6fd | 656 | // Data LUTs. |
AjK | 8:cb4d323ce6fd | 657 | uint32_t LUTPerAddr(int n); |
AjK | 8:cb4d323ce6fd | 658 | uint8_t LUTPerBurst(int n); |
AjK | 8:cb4d323ce6fd | 659 | uint8_t LUTPerWid(int n); |
AjK | 8:cb4d323ce6fd | 660 | uint32_t Channel_p(int channel); |
AjK | 8:cb4d323ce6fd | 661 | |
AjK | 8:cb4d323ce6fd | 662 | CHANNELS IrqProcessingChannel; |
AjK | 8:cb4d323ce6fd | 663 | |
AjK | 8:cb4d323ce6fd | 664 | IrqType_t IrqType; |
AjK | 8:cb4d323ce6fd | 665 | }; |
AjK | 8:cb4d323ce6fd | 666 | |
AjK | 8:cb4d323ce6fd | 667 | }; // namespace AjK ends. |
AjK | 8:cb4d323ce6fd | 668 | |
AjK | 8:cb4d323ce6fd | 669 | using namespace AjK; |
AjK | 8:cb4d323ce6fd | 670 | |
AjK | 8:cb4d323ce6fd | 671 | #endif |