These are the examples provided for [[/users/frank26080115/libraries/LPC1700CMSIS_Lib/]] Note, the entire "program" is not compilable!

Committer:
frank26080115
Date:
Sun Mar 20 05:38:56 2011 +0000
Revision:
0:bf7b9fba3924

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
frank26080115 0:bf7b9fba3924 1 /***********************************************************************//**
frank26080115 0:bf7b9fba3924 2 * @file gpdma_m2m_test.c
frank26080115 0:bf7b9fba3924 3 * @purpose This example used to test GPDMA Ram-to-Ram mode
frank26080115 0:bf7b9fba3924 4 * @version 2.0
frank26080115 0:bf7b9fba3924 5 * @date 21. May. 2010
frank26080115 0:bf7b9fba3924 6 * @author NXP MCU SW Application Team
frank26080115 0:bf7b9fba3924 7 *---------------------------------------------------------------------
frank26080115 0:bf7b9fba3924 8 * Software that is described herein is for illustrative purposes only
frank26080115 0:bf7b9fba3924 9 * which provides customers with programming information regarding the
frank26080115 0:bf7b9fba3924 10 * products. This software is supplied "AS IS" without any warranties.
frank26080115 0:bf7b9fba3924 11 * NXP Semiconductors assumes no responsibility or liability for the
frank26080115 0:bf7b9fba3924 12 * use of the software, conveys no license or title under any patent,
frank26080115 0:bf7b9fba3924 13 * copyright, or mask work right to the product. NXP Semiconductors
frank26080115 0:bf7b9fba3924 14 * reserves the right to make changes in the software without
frank26080115 0:bf7b9fba3924 15 * notification. NXP Semiconductors also make no representation or
frank26080115 0:bf7b9fba3924 16 * warranty that such application will be suitable for the specified
frank26080115 0:bf7b9fba3924 17 * use without further testing or modification.
frank26080115 0:bf7b9fba3924 18 **********************************************************************/
frank26080115 0:bf7b9fba3924 19 #include "lpc17xx_gpdma.h"
frank26080115 0:bf7b9fba3924 20 #include "lpc17xx_libcfg.h"
frank26080115 0:bf7b9fba3924 21 #include "lpc17xx_pinsel.h"
frank26080115 0:bf7b9fba3924 22 #include "debug_frmwrk.h"
frank26080115 0:bf7b9fba3924 23
frank26080115 0:bf7b9fba3924 24 /* Example group ----------------------------------------------------------- */
frank26080115 0:bf7b9fba3924 25 /** @defgroup GPDMA_Ram_2_Ram_Test Ram_2_Ram_Test
frank26080115 0:bf7b9fba3924 26 * @ingroup GPDMA_Examples
frank26080115 0:bf7b9fba3924 27 * @{
frank26080115 0:bf7b9fba3924 28 */
frank26080115 0:bf7b9fba3924 29
frank26080115 0:bf7b9fba3924 30 /************************** PRIVATE MACROS *************************/
frank26080115 0:bf7b9fba3924 31 /** DMA transfer size */
frank26080115 0:bf7b9fba3924 32 #define DMA_SIZE 0x100UL
frank26080115 0:bf7b9fba3924 33 /** DMA Source Address is AHBRAM1_BASE that used for USB RAM purpose, but
frank26080115 0:bf7b9fba3924 34 * it is not used in this example, so this memory section can be used for general purpose
frank26080115 0:bf7b9fba3924 35 * memory
frank26080115 0:bf7b9fba3924 36 */
frank26080115 0:bf7b9fba3924 37 #define DMA_SRC LPC_AHBRAM1_BASE
frank26080115 0:bf7b9fba3924 38 /** DMA Source Address is (AHBRAM1_BASE + DMA_SIZE) that used for USB RAM purpose, but
frank26080115 0:bf7b9fba3924 39 * it is not used in this example, so this memory section can be used for general purpose
frank26080115 0:bf7b9fba3924 40 * memory
frank26080115 0:bf7b9fba3924 41 */
frank26080115 0:bf7b9fba3924 42 #define DMA_DST (DMA_SRC+DMA_SIZE)
frank26080115 0:bf7b9fba3924 43
frank26080115 0:bf7b9fba3924 44
frank26080115 0:bf7b9fba3924 45 /************************** PRIVATE VARIABLES *************************/
frank26080115 0:bf7b9fba3924 46 uint8_t menu1[] =
frank26080115 0:bf7b9fba3924 47 "********************************************************************************\n\r"
frank26080115 0:bf7b9fba3924 48 "Hello NXP Semiconductors \n\r"
frank26080115 0:bf7b9fba3924 49 "GPDMA demo \n\r"
frank26080115 0:bf7b9fba3924 50 "\t - MCU: LPC17xx \n\r"
frank26080115 0:bf7b9fba3924 51 "\t - Core: ARM Cortex-M3 \n\r"
frank26080115 0:bf7b9fba3924 52 "\t - Communicate via: UART0 - 115200bps \n\r"
frank26080115 0:bf7b9fba3924 53 " This example will transfer 2 blocks of data from memory boundary \n\r"
frank26080115 0:bf7b9fba3924 54 " to the other memory boundary on RAM using GPDMA module with interrupt \n\r"
frank26080115 0:bf7b9fba3924 55 "********************************************************************************\n\r";
frank26080115 0:bf7b9fba3924 56 uint8_t menu2[] = "Demo terminated! \n\r";
frank26080115 0:bf7b9fba3924 57 uint8_t err_menu[] = "Buffer Check fail!";
frank26080115 0:bf7b9fba3924 58 uint8_t compl_menu[] = "Buffer Check success!";
frank26080115 0:bf7b9fba3924 59
frank26080115 0:bf7b9fba3924 60 // Terminal Counter flag for Channel 0
frank26080115 0:bf7b9fba3924 61 __IO uint32_t Channel0_TC;
frank26080115 0:bf7b9fba3924 62
frank26080115 0:bf7b9fba3924 63 // Error Counter flag for Channel 0
frank26080115 0:bf7b9fba3924 64 __IO uint32_t Channel0_Err;
frank26080115 0:bf7b9fba3924 65
frank26080115 0:bf7b9fba3924 66
frank26080115 0:bf7b9fba3924 67 /************************** PRIVATE FUNCTIONS *************************/
frank26080115 0:bf7b9fba3924 68 void DMA_IRQHandler (void);
frank26080115 0:bf7b9fba3924 69
frank26080115 0:bf7b9fba3924 70 void print_menu(void);
frank26080115 0:bf7b9fba3924 71 void Buffer_Init(void);
frank26080115 0:bf7b9fba3924 72 void Error_Loop(void);
frank26080115 0:bf7b9fba3924 73
frank26080115 0:bf7b9fba3924 74 /*----------------- INTERRUPT SERVICE ROUTINES --------------------------*/
frank26080115 0:bf7b9fba3924 75 /*********************************************************************//**
frank26080115 0:bf7b9fba3924 76 * @brief GPDMA interrupt handler sub-routine
frank26080115 0:bf7b9fba3924 77 * @param[in] None
frank26080115 0:bf7b9fba3924 78 * @return None
frank26080115 0:bf7b9fba3924 79 **********************************************************************/
frank26080115 0:bf7b9fba3924 80 void DMA_IRQHandler (void)
frank26080115 0:bf7b9fba3924 81 {
frank26080115 0:bf7b9fba3924 82 // check GPDMA interrupt on channel 0
frank26080115 0:bf7b9fba3924 83 if (GPDMA_IntGetStatus(GPDMA_STAT_INT, 0)){ //check interrupt status on channel 0
frank26080115 0:bf7b9fba3924 84 // Check counter terminal status
frank26080115 0:bf7b9fba3924 85 if(GPDMA_IntGetStatus(GPDMA_STAT_INTTC, 0)){
frank26080115 0:bf7b9fba3924 86 // Clear terminate counter Interrupt pending
frank26080115 0:bf7b9fba3924 87 GPDMA_ClearIntPending (GPDMA_STATCLR_INTTC, 0);
frank26080115 0:bf7b9fba3924 88 Channel0_TC++;
frank26080115 0:bf7b9fba3924 89 }
frank26080115 0:bf7b9fba3924 90 if (GPDMA_IntGetStatus(GPDMA_STAT_INTERR, 0)){
frank26080115 0:bf7b9fba3924 91 // Clear error counter Interrupt pending
frank26080115 0:bf7b9fba3924 92 GPDMA_ClearIntPending (GPDMA_STATCLR_INTERR, 0);
frank26080115 0:bf7b9fba3924 93 Channel0_Err++;
frank26080115 0:bf7b9fba3924 94 }
frank26080115 0:bf7b9fba3924 95 }
frank26080115 0:bf7b9fba3924 96 }
frank26080115 0:bf7b9fba3924 97
frank26080115 0:bf7b9fba3924 98 /*-------------------------PRIVATE FUNCTIONS-----------------------------*/
frank26080115 0:bf7b9fba3924 99 /*********************************************************************//**
frank26080115 0:bf7b9fba3924 100 * @brief Print Welcome menu
frank26080115 0:bf7b9fba3924 101 * @param[in] none
frank26080115 0:bf7b9fba3924 102 * @return None
frank26080115 0:bf7b9fba3924 103 **********************************************************************/
frank26080115 0:bf7b9fba3924 104 void print_menu(void)
frank26080115 0:bf7b9fba3924 105 {
frank26080115 0:bf7b9fba3924 106 _DBG(menu1);
frank26080115 0:bf7b9fba3924 107 }
frank26080115 0:bf7b9fba3924 108
frank26080115 0:bf7b9fba3924 109 /*********************************************************************//**
frank26080115 0:bf7b9fba3924 110 * @brief Initialize buffer
frank26080115 0:bf7b9fba3924 111 * @param[in] none
frank26080115 0:bf7b9fba3924 112 * @return None
frank26080115 0:bf7b9fba3924 113 **********************************************************************/
frank26080115 0:bf7b9fba3924 114 void Buffer_Init(void)
frank26080115 0:bf7b9fba3924 115 {
frank26080115 0:bf7b9fba3924 116 uint8_t i;
frank26080115 0:bf7b9fba3924 117 uint32_t *src_addr = (uint32_t *)DMA_SRC;
frank26080115 0:bf7b9fba3924 118 uint32_t *dest_addr = (uint32_t *)DMA_DST;
frank26080115 0:bf7b9fba3924 119
frank26080115 0:bf7b9fba3924 120 for ( i = 0; i < DMA_SIZE/4; i++ )
frank26080115 0:bf7b9fba3924 121 {
frank26080115 0:bf7b9fba3924 122 *src_addr++ = i;
frank26080115 0:bf7b9fba3924 123 *dest_addr++ = 0;
frank26080115 0:bf7b9fba3924 124 }
frank26080115 0:bf7b9fba3924 125 }
frank26080115 0:bf7b9fba3924 126
frank26080115 0:bf7b9fba3924 127
frank26080115 0:bf7b9fba3924 128 /*********************************************************************//**
frank26080115 0:bf7b9fba3924 129 * @brief Verify buffer
frank26080115 0:bf7b9fba3924 130 * @param[in] none
frank26080115 0:bf7b9fba3924 131 * @return None
frank26080115 0:bf7b9fba3924 132 **********************************************************************/
frank26080115 0:bf7b9fba3924 133 void Buffer_Verify(void)
frank26080115 0:bf7b9fba3924 134 {
frank26080115 0:bf7b9fba3924 135 uint8_t i;
frank26080115 0:bf7b9fba3924 136 uint32_t *src_addr = (uint32_t *)DMA_SRC;
frank26080115 0:bf7b9fba3924 137 uint32_t *dest_addr = (uint32_t *)DMA_DST;
frank26080115 0:bf7b9fba3924 138
frank26080115 0:bf7b9fba3924 139 for ( i = 0; i < DMA_SIZE/4; i++ )
frank26080115 0:bf7b9fba3924 140 {
frank26080115 0:bf7b9fba3924 141 if ( *src_addr++ != *dest_addr++ )
frank26080115 0:bf7b9fba3924 142 {
frank26080115 0:bf7b9fba3924 143 /* Call Error Loop */
frank26080115 0:bf7b9fba3924 144 Error_Loop();
frank26080115 0:bf7b9fba3924 145 }
frank26080115 0:bf7b9fba3924 146 }
frank26080115 0:bf7b9fba3924 147 }
frank26080115 0:bf7b9fba3924 148
frank26080115 0:bf7b9fba3924 149
frank26080115 0:bf7b9fba3924 150 /*********************************************************************//**
frank26080115 0:bf7b9fba3924 151 * @brief Error Loop (called by Buffer_Verify() if any error)
frank26080115 0:bf7b9fba3924 152 * @param[in] none
frank26080115 0:bf7b9fba3924 153 * @return None
frank26080115 0:bf7b9fba3924 154 **********************************************************************/
frank26080115 0:bf7b9fba3924 155 void Error_Loop(void)
frank26080115 0:bf7b9fba3924 156 {
frank26080115 0:bf7b9fba3924 157 _DBG(err_menu);
frank26080115 0:bf7b9fba3924 158
frank26080115 0:bf7b9fba3924 159 /* Loop forever */
frank26080115 0:bf7b9fba3924 160 while (1);
frank26080115 0:bf7b9fba3924 161 }
frank26080115 0:bf7b9fba3924 162
frank26080115 0:bf7b9fba3924 163
frank26080115 0:bf7b9fba3924 164 /*-------------------------MAIN FUNCTION--------------------------------*/
frank26080115 0:bf7b9fba3924 165 /*********************************************************************//**
frank26080115 0:bf7b9fba3924 166 * @brief c_entry: Main program body
frank26080115 0:bf7b9fba3924 167 * @param[in] None
frank26080115 0:bf7b9fba3924 168 * @return int
frank26080115 0:bf7b9fba3924 169 **********************************************************************/
frank26080115 0:bf7b9fba3924 170 int c_entry(void)
frank26080115 0:bf7b9fba3924 171 {
frank26080115 0:bf7b9fba3924 172 GPDMA_Channel_CFG_Type GPDMACfg;
frank26080115 0:bf7b9fba3924 173
frank26080115 0:bf7b9fba3924 174 /* Initialize debug via UART0
frank26080115 0:bf7b9fba3924 175 * – 115200bps
frank26080115 0:bf7b9fba3924 176 * – 8 data bit
frank26080115 0:bf7b9fba3924 177 * – No parity
frank26080115 0:bf7b9fba3924 178 * – 1 stop bit
frank26080115 0:bf7b9fba3924 179 * – No flow control
frank26080115 0:bf7b9fba3924 180 */
frank26080115 0:bf7b9fba3924 181 debug_frmwrk_init();
frank26080115 0:bf7b9fba3924 182
frank26080115 0:bf7b9fba3924 183 // print welcome screen
frank26080115 0:bf7b9fba3924 184 print_menu();
frank26080115 0:bf7b9fba3924 185
frank26080115 0:bf7b9fba3924 186 /* GPDMA block section -------------------------------------------- */
frank26080115 0:bf7b9fba3924 187 /* Initialize buffer */
frank26080115 0:bf7b9fba3924 188 _DBG_("Initialize Buffer...");
frank26080115 0:bf7b9fba3924 189 Buffer_Init();
frank26080115 0:bf7b9fba3924 190
frank26080115 0:bf7b9fba3924 191 /* Disable GPDMA interrupt */
frank26080115 0:bf7b9fba3924 192 NVIC_DisableIRQ(DMA_IRQn);
frank26080115 0:bf7b9fba3924 193 /* preemption = 1, sub-priority = 1 */
frank26080115 0:bf7b9fba3924 194 NVIC_SetPriority(DMA_IRQn, ((0x01<<3)|0x01));
frank26080115 0:bf7b9fba3924 195
frank26080115 0:bf7b9fba3924 196 /* Initialize GPDMA controller */
frank26080115 0:bf7b9fba3924 197 GPDMA_Init();
frank26080115 0:bf7b9fba3924 198
frank26080115 0:bf7b9fba3924 199 // Setup GPDMA channel --------------------------------
frank26080115 0:bf7b9fba3924 200 // channel 0
frank26080115 0:bf7b9fba3924 201 GPDMACfg.ChannelNum = 0;
frank26080115 0:bf7b9fba3924 202 // Source memory
frank26080115 0:bf7b9fba3924 203 GPDMACfg.SrcMemAddr = DMA_SRC;
frank26080115 0:bf7b9fba3924 204 // Destination memory
frank26080115 0:bf7b9fba3924 205 GPDMACfg.DstMemAddr = DMA_DST;
frank26080115 0:bf7b9fba3924 206 // Transfer size
frank26080115 0:bf7b9fba3924 207 GPDMACfg.TransferSize = DMA_SIZE;
frank26080115 0:bf7b9fba3924 208 // Transfer width
frank26080115 0:bf7b9fba3924 209 GPDMACfg.TransferWidth = GPDMA_WIDTH_WORD;
frank26080115 0:bf7b9fba3924 210 // Transfer type
frank26080115 0:bf7b9fba3924 211 GPDMACfg.TransferType = GPDMA_TRANSFERTYPE_M2M;
frank26080115 0:bf7b9fba3924 212 // Source connection - unused
frank26080115 0:bf7b9fba3924 213 GPDMACfg.SrcConn = 0;
frank26080115 0:bf7b9fba3924 214 // Destination connection - unused
frank26080115 0:bf7b9fba3924 215 GPDMACfg.DstConn = 0;
frank26080115 0:bf7b9fba3924 216 // Linker List Item - unused
frank26080115 0:bf7b9fba3924 217 GPDMACfg.DMALLI = 0;
frank26080115 0:bf7b9fba3924 218 // Setup channel with given parameter
frank26080115 0:bf7b9fba3924 219 GPDMA_Setup(&GPDMACfg);
frank26080115 0:bf7b9fba3924 220
frank26080115 0:bf7b9fba3924 221 /* Reset terminal counter */
frank26080115 0:bf7b9fba3924 222 Channel0_TC = 0;
frank26080115 0:bf7b9fba3924 223 /* Reset Error counter */
frank26080115 0:bf7b9fba3924 224 Channel0_Err = 0;
frank26080115 0:bf7b9fba3924 225
frank26080115 0:bf7b9fba3924 226 _DBG_("Start transfer...");
frank26080115 0:bf7b9fba3924 227
frank26080115 0:bf7b9fba3924 228 // Enable GPDMA channel 0
frank26080115 0:bf7b9fba3924 229 GPDMA_ChannelCmd(0, ENABLE);
frank26080115 0:bf7b9fba3924 230
frank26080115 0:bf7b9fba3924 231 /* Enable GPDMA interrupt */
frank26080115 0:bf7b9fba3924 232 NVIC_EnableIRQ(DMA_IRQn);
frank26080115 0:bf7b9fba3924 233
frank26080115 0:bf7b9fba3924 234 /* Wait for GPDMA processing complete */
frank26080115 0:bf7b9fba3924 235 while ((Channel0_TC == 0) && (Channel0_Err == 0));
frank26080115 0:bf7b9fba3924 236
frank26080115 0:bf7b9fba3924 237 /* Verify buffer */
frank26080115 0:bf7b9fba3924 238 Buffer_Verify();
frank26080115 0:bf7b9fba3924 239
frank26080115 0:bf7b9fba3924 240 _DBG(compl_menu);
frank26080115 0:bf7b9fba3924 241
frank26080115 0:bf7b9fba3924 242 /* Loop forever */
frank26080115 0:bf7b9fba3924 243 while(1);
frank26080115 0:bf7b9fba3924 244 return 1;
frank26080115 0:bf7b9fba3924 245 }
frank26080115 0:bf7b9fba3924 246
frank26080115 0:bf7b9fba3924 247 /* With ARM and GHS toolsets, the entry point is main() - this will
frank26080115 0:bf7b9fba3924 248 allow the linker to generate wrapper code to setup stacks, allocate
frank26080115 0:bf7b9fba3924 249 heap area, and initialize and copy code and data segments. For GNU
frank26080115 0:bf7b9fba3924 250 toolsets, the entry point is through __start() in the crt0_gnu.asm
frank26080115 0:bf7b9fba3924 251 file, and that startup code will setup stacks and data */
frank26080115 0:bf7b9fba3924 252 int main(void)
frank26080115 0:bf7b9fba3924 253 {
frank26080115 0:bf7b9fba3924 254 return c_entry();
frank26080115 0:bf7b9fba3924 255 }
frank26080115 0:bf7b9fba3924 256
frank26080115 0:bf7b9fba3924 257
frank26080115 0:bf7b9fba3924 258 #ifdef DEBUG
frank26080115 0:bf7b9fba3924 259 /*******************************************************************************
frank26080115 0:bf7b9fba3924 260 * @brief Reports the name of the source file and the source line number
frank26080115 0:bf7b9fba3924 261 * where the CHECK_PARAM error has occurred.
frank26080115 0:bf7b9fba3924 262 * @param[in] file Pointer to the source file name
frank26080115 0:bf7b9fba3924 263 * @param[in] line assert_param error line source number
frank26080115 0:bf7b9fba3924 264 * @return None
frank26080115 0:bf7b9fba3924 265 *******************************************************************************/
frank26080115 0:bf7b9fba3924 266 void check_failed(uint8_t *file, uint32_t line)
frank26080115 0:bf7b9fba3924 267 {
frank26080115 0:bf7b9fba3924 268 /* User can add his own implementation to report the file name and line number,
frank26080115 0:bf7b9fba3924 269 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
frank26080115 0:bf7b9fba3924 270
frank26080115 0:bf7b9fba3924 271 /* Infinite loop */
frank26080115 0:bf7b9fba3924 272 while(1);
frank26080115 0:bf7b9fba3924 273 }
frank26080115 0:bf7b9fba3924 274 #endif
frank26080115 0:bf7b9fba3924 275 /*
frank26080115 0:bf7b9fba3924 276 * @}
frank26080115 0:bf7b9fba3924 277 */