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