trying to make telnetserver repo public

Fork of MODDMA by Andy K

Committer:
AjK
Date:
Sat Feb 05 08:53:26 2011 +0000
Revision:
8:cb4d323ce6fd
Parent:
0:c409efd8df78
Child:
11:19009be5a0e7
1.5 See ChangeLog.c

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AjK 8:cb4d323ce6fd 1 /*
AjK 8:cb4d323ce6fd 2 Copyright (c) 2010 Andy Kirkham
AjK 8:cb4d323ce6fd 3
AjK 8:cb4d323ce6fd 4 Permission is hereby granted, free of charge, to any person obtaining a copy
AjK 8:cb4d323ce6fd 5 of this software and associated documentation files (the "Software"), to deal
AjK 8:cb4d323ce6fd 6 in the Software without restriction, including without limitation the rights
AjK 8:cb4d323ce6fd 7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
AjK 8:cb4d323ce6fd 8 copies of the Software, and to permit persons to whom the Software is
AjK 8:cb4d323ce6fd 9 furnished to do so, subject to the following conditions:
AjK 8:cb4d323ce6fd 10
AjK 8:cb4d323ce6fd 11 The above copyright notice and this permission notice shall be included in
AjK 8:cb4d323ce6fd 12 all copies or substantial portions of the Software.
AjK 8:cb4d323ce6fd 13
AjK 8:cb4d323ce6fd 14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
AjK 8:cb4d323ce6fd 15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
AjK 8:cb4d323ce6fd 16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AjK 8:cb4d323ce6fd 17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
AjK 8:cb4d323ce6fd 18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
AjK 8:cb4d323ce6fd 19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
AjK 8:cb4d323ce6fd 20 THE SOFTWARE.
AjK 8:cb4d323ce6fd 21 */
AjK 8:cb4d323ce6fd 22
AjK 8:cb4d323ce6fd 23 #include "MODDMA.h"
AjK 8:cb4d323ce6fd 24
AjK 8:cb4d323ce6fd 25 namespace AjK {
AjK 8:cb4d323ce6fd 26
AjK 8:cb4d323ce6fd 27 uint32_t
AjK 8:cb4d323ce6fd 28 MODDMA::Setup(MODDMA_Config *config)
AjK 8:cb4d323ce6fd 29 {
AjK 8:cb4d323ce6fd 30 LPC_GPDMACH_TypeDef *pChannel = (LPC_GPDMACH_TypeDef *)Channel_p( config->channelNum() );
AjK 8:cb4d323ce6fd 31
AjK 8:cb4d323ce6fd 32 if (LPC_GPDMA->DMACEnbldChns & EnbldChns_Ch( config->channelNum() )) {
AjK 8:cb4d323ce6fd 33 return 0;
AjK 8:cb4d323ce6fd 34 }
AjK 8:cb4d323ce6fd 35
AjK 8:cb4d323ce6fd 36 setups[config->channelNum() & 0x7] = config;
AjK 8:cb4d323ce6fd 37
AjK 8:cb4d323ce6fd 38 // Reset the Interrupt status
AjK 8:cb4d323ce6fd 39 LPC_GPDMA->DMACIntTCClear = IntTCClear_Ch( config->channelNum() );
AjK 8:cb4d323ce6fd 40 LPC_GPDMA->DMACIntErrClr = IntErrClr_Ch ( config->channelNum() );
AjK 8:cb4d323ce6fd 41
AjK 8:cb4d323ce6fd 42 // Clear DMA configure
AjK 8:cb4d323ce6fd 43 pChannel->DMACCControl = 0x00;
AjK 8:cb4d323ce6fd 44 pChannel->DMACCConfig = 0x00;
AjK 8:cb4d323ce6fd 45
AjK 8:cb4d323ce6fd 46 // Assign Linker List Item value
AjK 8:cb4d323ce6fd 47 pChannel->DMACCLLI = config->dmaLLI();
AjK 8:cb4d323ce6fd 48
AjK 8:cb4d323ce6fd 49 // Set value to Channel Control Registers
AjK 8:cb4d323ce6fd 50 switch (config->transferType()) {
AjK 8:cb4d323ce6fd 51
AjK 8:cb4d323ce6fd 52 // Memory to memory
AjK 8:cb4d323ce6fd 53 case m2m:
AjK 8:cb4d323ce6fd 54 // Assign physical source and destination address
AjK 8:cb4d323ce6fd 55 pChannel->DMACCSrcAddr = config->srcMemAddr();
AjK 8:cb4d323ce6fd 56 pChannel->DMACCDestAddr = config->dstMemAddr();
AjK 8:cb4d323ce6fd 57 pChannel->DMACCControl
AjK 8:cb4d323ce6fd 58 = CxControl_TransferSize(config->transferSize())
AjK 8:cb4d323ce6fd 59 | CxControl_SBSize(_32)
AjK 8:cb4d323ce6fd 60 | CxControl_DBSize(_32)
AjK 8:cb4d323ce6fd 61 | CxControl_SWidth(config->transferWidth())
AjK 8:cb4d323ce6fd 62 | CxControl_DWidth(config->transferWidth())
AjK 8:cb4d323ce6fd 63 | CxControl_SI()
AjK 8:cb4d323ce6fd 64 | CxControl_DI()
AjK 8:cb4d323ce6fd 65 | CxControl_I();
AjK 8:cb4d323ce6fd 66 break;
AjK 8:cb4d323ce6fd 67
AjK 8:cb4d323ce6fd 68 // Memory to peripheral
AjK 8:cb4d323ce6fd 69 case m2p:
AjK 8:cb4d323ce6fd 70 // Assign physical source
AjK 8:cb4d323ce6fd 71 pChannel->DMACCSrcAddr = config->srcMemAddr();
AjK 8:cb4d323ce6fd 72 // Assign peripheral destination address
AjK 8:cb4d323ce6fd 73 pChannel->DMACCDestAddr = (uint32_t)LUTPerAddr(config->dstConn());
AjK 8:cb4d323ce6fd 74 pChannel->DMACCControl
AjK 8:cb4d323ce6fd 75 = CxControl_TransferSize((uint32_t)config->transferSize())
AjK 8:cb4d323ce6fd 76 | CxControl_SBSize((uint32_t)LUTPerBurst(config->dstConn()))
AjK 8:cb4d323ce6fd 77 | CxControl_DBSize((uint32_t)LUTPerBurst(config->dstConn()))
AjK 8:cb4d323ce6fd 78 | CxControl_SWidth((uint32_t)LUTPerWid(config->dstConn()))
AjK 8:cb4d323ce6fd 79 | CxControl_DWidth((uint32_t)LUTPerWid(config->dstConn()))
AjK 8:cb4d323ce6fd 80 | CxControl_SI()
AjK 8:cb4d323ce6fd 81 | CxControl_I();
AjK 8:cb4d323ce6fd 82 break;
AjK 8:cb4d323ce6fd 83
AjK 8:cb4d323ce6fd 84 // Peripheral to memory
AjK 8:cb4d323ce6fd 85 case p2m:
AjK 8:cb4d323ce6fd 86 // Assign peripheral source address
AjK 8:cb4d323ce6fd 87 pChannel->DMACCSrcAddr = (uint32_t)LUTPerAddr(config->srcConn());
AjK 8:cb4d323ce6fd 88 // Assign memory destination address
AjK 8:cb4d323ce6fd 89 pChannel->DMACCDestAddr = config->dstMemAddr();
AjK 8:cb4d323ce6fd 90 pChannel->DMACCControl
AjK 8:cb4d323ce6fd 91 = CxControl_TransferSize((uint32_t)config->transferSize())
AjK 8:cb4d323ce6fd 92 | CxControl_SBSize((uint32_t)LUTPerBurst(config->srcConn()))
AjK 8:cb4d323ce6fd 93 | CxControl_DBSize((uint32_t)LUTPerBurst(config->srcConn()))
AjK 8:cb4d323ce6fd 94 | CxControl_SWidth((uint32_t)LUTPerWid(config->srcConn()))
AjK 8:cb4d323ce6fd 95 | CxControl_DWidth((uint32_t)LUTPerWid(config->srcConn()))
AjK 8:cb4d323ce6fd 96 | CxControl_DI()
AjK 8:cb4d323ce6fd 97 | CxControl_I();
AjK 8:cb4d323ce6fd 98 break;
AjK 8:cb4d323ce6fd 99
AjK 8:cb4d323ce6fd 100 // Peripheral to peripheral
AjK 8:cb4d323ce6fd 101 case p2p:
AjK 8:cb4d323ce6fd 102 // Assign peripheral source address
AjK 8:cb4d323ce6fd 103 pChannel->DMACCSrcAddr = (uint32_t)LUTPerAddr(config->srcConn());
AjK 8:cb4d323ce6fd 104 // Assign peripheral destination address
AjK 8:cb4d323ce6fd 105 pChannel->DMACCDestAddr = (uint32_t)LUTPerAddr(config->dstConn());
AjK 8:cb4d323ce6fd 106 pChannel->DMACCControl
AjK 8:cb4d323ce6fd 107 = CxControl_TransferSize((uint32_t)config->transferSize())
AjK 8:cb4d323ce6fd 108 | CxControl_SBSize((uint32_t)LUTPerBurst(config->srcConn()))
AjK 8:cb4d323ce6fd 109 | CxControl_DBSize((uint32_t)LUTPerBurst(config->dstConn()))
AjK 8:cb4d323ce6fd 110 | CxControl_SWidth((uint32_t)LUTPerWid(config->srcConn()))
AjK 8:cb4d323ce6fd 111 | CxControl_DWidth((uint32_t)LUTPerWid(config->dstConn()))
AjK 8:cb4d323ce6fd 112 | CxControl_I();
AjK 8:cb4d323ce6fd 113 break;
AjK 8:cb4d323ce6fd 114
AjK 8:cb4d323ce6fd 115 // Do not support any more transfer type, return ERROR
AjK 8:cb4d323ce6fd 116 default:
AjK 8:cb4d323ce6fd 117 return 0;
AjK 8:cb4d323ce6fd 118 }
AjK 8:cb4d323ce6fd 119
AjK 8:cb4d323ce6fd 120 // Re-Configure DMA Request Select for source peripheral
AjK 8:cb4d323ce6fd 121 if (config->srcConn() > 15) {
AjK 8:cb4d323ce6fd 122 LPC_SC->RESERVED9 |= (1 << (config->srcConn() - 16));
AjK 8:cb4d323ce6fd 123 }
AjK 8:cb4d323ce6fd 124 else {
AjK 8:cb4d323ce6fd 125 LPC_SC->RESERVED9 &= ~(1 << (config->srcConn() - 8));
AjK 8:cb4d323ce6fd 126 }
AjK 8:cb4d323ce6fd 127
AjK 8:cb4d323ce6fd 128 // Re-Configure DMA Request Select for Destination peripheral
AjK 8:cb4d323ce6fd 129 if (config->dstConn() > 15) {
AjK 8:cb4d323ce6fd 130 LPC_SC->RESERVED9 |= (1 << (config->dstConn() - 16));
AjK 8:cb4d323ce6fd 131 }
AjK 8:cb4d323ce6fd 132 else {
AjK 8:cb4d323ce6fd 133 LPC_SC->RESERVED9 &= ~(1 << (config->dstConn() - 8));
AjK 8:cb4d323ce6fd 134 }
AjK 8:cb4d323ce6fd 135
AjK 8:cb4d323ce6fd 136 // Enable DMA channels, little endian
AjK 8:cb4d323ce6fd 137 LPC_GPDMA->DMACConfig = _E;
AjK 8:cb4d323ce6fd 138 while (!(LPC_GPDMA->DMACConfig & _E));
AjK 8:cb4d323ce6fd 139
AjK 8:cb4d323ce6fd 140 // Calculate absolute value for Connection number
AjK 8:cb4d323ce6fd 141 uint32_t tmp1 = config->srcConn(); tmp1 = ((tmp1 > 15) ? (tmp1 - 8) : tmp1);
AjK 8:cb4d323ce6fd 142 uint32_t tmp2 = config->dstConn(); tmp2 = ((tmp2 > 15) ? (tmp2 - 8) : tmp2);
AjK 8:cb4d323ce6fd 143
AjK 8:cb4d323ce6fd 144 // Configure DMA Channel, enable Error Counter and Terminate counter
AjK 8:cb4d323ce6fd 145 pChannel->DMACCConfig
AjK 8:cb4d323ce6fd 146 = CxConfig_IE()
AjK 8:cb4d323ce6fd 147 | CxConfig_ITC()
AjK 8:cb4d323ce6fd 148 | CxConfig_TransferType((uint32_t)config->transferType())
AjK 8:cb4d323ce6fd 149 | CxConfig_SrcPeripheral(tmp1)
AjK 8:cb4d323ce6fd 150 | CxConfig_DestPeripheral(tmp2);
AjK 8:cb4d323ce6fd 151
AjK 8:cb4d323ce6fd 152 return pChannel->DMACCControl;
AjK 8:cb4d323ce6fd 153 }
AjK 8:cb4d323ce6fd 154
AjK 8:cb4d323ce6fd 155 }; // namespace AjK ends
AjK 8:cb4d323ce6fd 156