Fork of Andy Kirkham's MODDMA GPDMA Controller for Mbed OS 6

Read MODDMA for more info.

Committer:
hudakz
Date:
Sat Dec 10 09:59:10 2022 +0000
Revision:
18:31f858967e93
Parent:
16:cb10aec6feb1
Fork of Andy Kirkham's MODDMA GPDMA Controller for Mbed OS 6

Who changed what in which revision?

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