These are the examples provided for [[/users/frank26080115/libraries/LPC1700CMSIS_Lib/]] Note, the entire "program" is not compilable!
DAC/DMA/dac_dma.c@0:bf7b9fba3924, 2011-03-20 (annotated)
- Committer:
- frank26080115
- Date:
- Sun Mar 20 05:38:56 2011 +0000
- Revision:
- 0:bf7b9fba3924
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
frank26080115 | 0:bf7b9fba3924 | 1 | /***********************************************************************//** |
frank26080115 | 0:bf7b9fba3924 | 2 | * @file dac_dma.c |
frank26080115 | 0:bf7b9fba3924 | 3 | * @purpose This example describes how to use DAC conversion and |
frank26080115 | 0:bf7b9fba3924 | 4 | * using DMA to transfer data |
frank26080115 | 0:bf7b9fba3924 | 5 | * @version 2.0 |
frank26080115 | 0:bf7b9fba3924 | 6 | * @date 21. May. 2010 |
frank26080115 | 0:bf7b9fba3924 | 7 | * @author NXP MCU SW Application Team |
frank26080115 | 0:bf7b9fba3924 | 8 | *--------------------------------------------------------------------- |
frank26080115 | 0:bf7b9fba3924 | 9 | * Software that is described herein is for illustrative purposes only |
frank26080115 | 0:bf7b9fba3924 | 10 | * which provides customers with programming information regarding the |
frank26080115 | 0:bf7b9fba3924 | 11 | * products. This software is supplied "AS IS" without any warranties. |
frank26080115 | 0:bf7b9fba3924 | 12 | * NXP Semiconductors assumes no responsibility or liability for the |
frank26080115 | 0:bf7b9fba3924 | 13 | * use of the software, conveys no license or title under any patent, |
frank26080115 | 0:bf7b9fba3924 | 14 | * copyright, or mask work right to the product. NXP Semiconductors |
frank26080115 | 0:bf7b9fba3924 | 15 | * reserves the right to make changes in the software without |
frank26080115 | 0:bf7b9fba3924 | 16 | * notification. NXP Semiconductors also make no representation or |
frank26080115 | 0:bf7b9fba3924 | 17 | * warranty that such application will be suitable for the specified |
frank26080115 | 0:bf7b9fba3924 | 18 | * use without further testing or modification. |
frank26080115 | 0:bf7b9fba3924 | 19 | **********************************************************************/ |
frank26080115 | 0:bf7b9fba3924 | 20 | #include "lpc17xx_dac.h" |
frank26080115 | 0:bf7b9fba3924 | 21 | #include "lpc17xx_libcfg.h" |
frank26080115 | 0:bf7b9fba3924 | 22 | #include "lpc17xx_pinsel.h" |
frank26080115 | 0:bf7b9fba3924 | 23 | #include "lpc17xx_gpdma.h" |
frank26080115 | 0:bf7b9fba3924 | 24 | |
frank26080115 | 0:bf7b9fba3924 | 25 | /* Example group ----------------------------------------------------------- */ |
frank26080115 | 0:bf7b9fba3924 | 26 | /** @defgroup DAC_DMA DMA |
frank26080115 | 0:bf7b9fba3924 | 27 | * @ingroup DAC_Examples |
frank26080115 | 0:bf7b9fba3924 | 28 | * @{ |
frank26080115 | 0:bf7b9fba3924 | 29 | */ |
frank26080115 | 0:bf7b9fba3924 | 30 | |
frank26080115 | 0:bf7b9fba3924 | 31 | /************************** PRIVATE MACROS *************************/ |
frank26080115 | 0:bf7b9fba3924 | 32 | /** DMA size of transfer */ |
frank26080115 | 0:bf7b9fba3924 | 33 | #define DMA_SIZE 1 |
frank26080115 | 0:bf7b9fba3924 | 34 | |
frank26080115 | 0:bf7b9fba3924 | 35 | /************************** PRIVATE VARIABLES *************************/ |
frank26080115 | 0:bf7b9fba3924 | 36 | // Terminal Counter flag for Channel 0 |
frank26080115 | 0:bf7b9fba3924 | 37 | __IO uint32_t Channel0_TC; |
frank26080115 | 0:bf7b9fba3924 | 38 | |
frank26080115 | 0:bf7b9fba3924 | 39 | // Error Counter flag for Channel 0 |
frank26080115 | 0:bf7b9fba3924 | 40 | __IO uint32_t Channel0_Err; |
frank26080115 | 0:bf7b9fba3924 | 41 | |
frank26080115 | 0:bf7b9fba3924 | 42 | GPDMA_Channel_CFG_Type GPDMACfg; |
frank26080115 | 0:bf7b9fba3924 | 43 | |
frank26080115 | 0:bf7b9fba3924 | 44 | /************************** PRIVATE FUNCTION *************************/ |
frank26080115 | 0:bf7b9fba3924 | 45 | void DMA_IRQHandler (void); |
frank26080115 | 0:bf7b9fba3924 | 46 | |
frank26080115 | 0:bf7b9fba3924 | 47 | |
frank26080115 | 0:bf7b9fba3924 | 48 | /*----------------- INTERRUPT SERVICE ROUTINES --------------------------*/ |
frank26080115 | 0:bf7b9fba3924 | 49 | /*********************************************************************//** |
frank26080115 | 0:bf7b9fba3924 | 50 | * @brief GPDMA interrupt handler sub-routine |
frank26080115 | 0:bf7b9fba3924 | 51 | * @param[in] None |
frank26080115 | 0:bf7b9fba3924 | 52 | * @return None |
frank26080115 | 0:bf7b9fba3924 | 53 | **********************************************************************/ |
frank26080115 | 0:bf7b9fba3924 | 54 | void DMA_IRQHandler (void) |
frank26080115 | 0:bf7b9fba3924 | 55 | { |
frank26080115 | 0:bf7b9fba3924 | 56 | // check GPDMA interrupt on channel 0 |
frank26080115 | 0:bf7b9fba3924 | 57 | if (GPDMA_IntGetStatus(GPDMA_STAT_INT, 0)){ |
frank26080115 | 0:bf7b9fba3924 | 58 | // Check counter terminal status |
frank26080115 | 0:bf7b9fba3924 | 59 | if(GPDMA_IntGetStatus(GPDMA_STAT_INTTC, 0)){ |
frank26080115 | 0:bf7b9fba3924 | 60 | GPDMA_ClearIntPending (GPDMA_STATCLR_INTTC, 0); |
frank26080115 | 0:bf7b9fba3924 | 61 | Channel0_TC++; |
frank26080115 | 0:bf7b9fba3924 | 62 | } |
frank26080115 | 0:bf7b9fba3924 | 63 | // Check error terminal status |
frank26080115 | 0:bf7b9fba3924 | 64 | if (GPDMA_IntGetStatus(GPDMA_STAT_INTERR, 0)){ |
frank26080115 | 0:bf7b9fba3924 | 65 | GPDMA_ClearIntPending (GPDMA_STATCLR_INTERR, 0); |
frank26080115 | 0:bf7b9fba3924 | 66 | Channel0_Err++; |
frank26080115 | 0:bf7b9fba3924 | 67 | } |
frank26080115 | 0:bf7b9fba3924 | 68 | } |
frank26080115 | 0:bf7b9fba3924 | 69 | } |
frank26080115 | 0:bf7b9fba3924 | 70 | |
frank26080115 | 0:bf7b9fba3924 | 71 | |
frank26080115 | 0:bf7b9fba3924 | 72 | /*-------------------------MAIN FUNCTION------------------------------*/ |
frank26080115 | 0:bf7b9fba3924 | 73 | /*********************************************************************//** |
frank26080115 | 0:bf7b9fba3924 | 74 | * @brief c_entry: Main DAC program body |
frank26080115 | 0:bf7b9fba3924 | 75 | * @param[in] None |
frank26080115 | 0:bf7b9fba3924 | 76 | * @return int |
frank26080115 | 0:bf7b9fba3924 | 77 | **********************************************************************/ |
frank26080115 | 0:bf7b9fba3924 | 78 | int c_entry(void) |
frank26080115 | 0:bf7b9fba3924 | 79 | { |
frank26080115 | 0:bf7b9fba3924 | 80 | PINSEL_CFG_Type PinCfg; |
frank26080115 | 0:bf7b9fba3924 | 81 | DAC_CONVERTER_CFG_Type DAC_ConverterConfigStruct; |
frank26080115 | 0:bf7b9fba3924 | 82 | uint32_t dac_value =0; |
frank26080115 | 0:bf7b9fba3924 | 83 | uint32_t i; |
frank26080115 | 0:bf7b9fba3924 | 84 | /* |
frank26080115 | 0:bf7b9fba3924 | 85 | * Init DAC pin connect |
frank26080115 | 0:bf7b9fba3924 | 86 | * AOUT on P0.26 |
frank26080115 | 0:bf7b9fba3924 | 87 | */ |
frank26080115 | 0:bf7b9fba3924 | 88 | PinCfg.Funcnum = 2; |
frank26080115 | 0:bf7b9fba3924 | 89 | PinCfg.OpenDrain = 0; |
frank26080115 | 0:bf7b9fba3924 | 90 | PinCfg.Pinmode = 0; |
frank26080115 | 0:bf7b9fba3924 | 91 | PinCfg.Pinnum = 26; |
frank26080115 | 0:bf7b9fba3924 | 92 | PinCfg.Portnum = 0; |
frank26080115 | 0:bf7b9fba3924 | 93 | PINSEL_ConfigPin(&PinCfg); |
frank26080115 | 0:bf7b9fba3924 | 94 | |
frank26080115 | 0:bf7b9fba3924 | 95 | /* GPDMA block section -------------------------------------------- */ |
frank26080115 | 0:bf7b9fba3924 | 96 | |
frank26080115 | 0:bf7b9fba3924 | 97 | /* Disable GPDMA interrupt */ |
frank26080115 | 0:bf7b9fba3924 | 98 | NVIC_DisableIRQ(DMA_IRQn); |
frank26080115 | 0:bf7b9fba3924 | 99 | |
frank26080115 | 0:bf7b9fba3924 | 100 | /* preemption = 1, sub-priority = 1 */ |
frank26080115 | 0:bf7b9fba3924 | 101 | NVIC_SetPriority(DMA_IRQn, ((0x01<<3)|0x01)); |
frank26080115 | 0:bf7b9fba3924 | 102 | |
frank26080115 | 0:bf7b9fba3924 | 103 | DAC_ConverterConfigStruct.CNT_ENA =SET; |
frank26080115 | 0:bf7b9fba3924 | 104 | DAC_ConverterConfigStruct.DMA_ENA = SET; |
frank26080115 | 0:bf7b9fba3924 | 105 | DAC_Init(LPC_DAC); |
frank26080115 | 0:bf7b9fba3924 | 106 | /* set time out for DAC*/ |
frank26080115 | 0:bf7b9fba3924 | 107 | DAC_SetDMATimeOut(LPC_DAC,0xFFFF); |
frank26080115 | 0:bf7b9fba3924 | 108 | DAC_ConfigDAConverterControl(LPC_DAC, &DAC_ConverterConfigStruct); |
frank26080115 | 0:bf7b9fba3924 | 109 | |
frank26080115 | 0:bf7b9fba3924 | 110 | /* Initialize GPDMA controller */ |
frank26080115 | 0:bf7b9fba3924 | 111 | GPDMA_Init(); |
frank26080115 | 0:bf7b9fba3924 | 112 | |
frank26080115 | 0:bf7b9fba3924 | 113 | // Setup GPDMA channel -------------------------------- |
frank26080115 | 0:bf7b9fba3924 | 114 | // channel 0 |
frank26080115 | 0:bf7b9fba3924 | 115 | GPDMACfg.ChannelNum = 0; |
frank26080115 | 0:bf7b9fba3924 | 116 | // Source memory |
frank26080115 | 0:bf7b9fba3924 | 117 | GPDMACfg.SrcMemAddr = (uint32_t)(&dac_value); |
frank26080115 | 0:bf7b9fba3924 | 118 | // Destination memory - unused |
frank26080115 | 0:bf7b9fba3924 | 119 | GPDMACfg.DstMemAddr = 0; |
frank26080115 | 0:bf7b9fba3924 | 120 | // Transfer size |
frank26080115 | 0:bf7b9fba3924 | 121 | GPDMACfg.TransferSize = DMA_SIZE; |
frank26080115 | 0:bf7b9fba3924 | 122 | // Transfer width - unused |
frank26080115 | 0:bf7b9fba3924 | 123 | GPDMACfg.TransferWidth = 0; |
frank26080115 | 0:bf7b9fba3924 | 124 | // Transfer type |
frank26080115 | 0:bf7b9fba3924 | 125 | GPDMACfg.TransferType = GPDMA_TRANSFERTYPE_M2P; |
frank26080115 | 0:bf7b9fba3924 | 126 | // Source connection - unused |
frank26080115 | 0:bf7b9fba3924 | 127 | GPDMACfg.SrcConn = 0; |
frank26080115 | 0:bf7b9fba3924 | 128 | // Destination connection |
frank26080115 | 0:bf7b9fba3924 | 129 | GPDMACfg.DstConn = GPDMA_CONN_DAC; |
frank26080115 | 0:bf7b9fba3924 | 130 | // Linker List Item - unused |
frank26080115 | 0:bf7b9fba3924 | 131 | GPDMACfg.DMALLI = 0; |
frank26080115 | 0:bf7b9fba3924 | 132 | // Setup channel with given parameter |
frank26080115 | 0:bf7b9fba3924 | 133 | GPDMA_Setup(&GPDMACfg); |
frank26080115 | 0:bf7b9fba3924 | 134 | |
frank26080115 | 0:bf7b9fba3924 | 135 | /* Reset terminal counter */ |
frank26080115 | 0:bf7b9fba3924 | 136 | Channel0_TC = 0; |
frank26080115 | 0:bf7b9fba3924 | 137 | /* Reset Error counter */ |
frank26080115 | 0:bf7b9fba3924 | 138 | Channel0_Err = 0; |
frank26080115 | 0:bf7b9fba3924 | 139 | |
frank26080115 | 0:bf7b9fba3924 | 140 | /* Enable GPDMA interrupt */ |
frank26080115 | 0:bf7b9fba3924 | 141 | NVIC_EnableIRQ(DMA_IRQn); |
frank26080115 | 0:bf7b9fba3924 | 142 | |
frank26080115 | 0:bf7b9fba3924 | 143 | /* Wait for GPDMA processing complete */ |
frank26080115 | 0:bf7b9fba3924 | 144 | while (1) { |
frank26080115 | 0:bf7b9fba3924 | 145 | |
frank26080115 | 0:bf7b9fba3924 | 146 | // Enable GPDMA channel 0 |
frank26080115 | 0:bf7b9fba3924 | 147 | GPDMA_ChannelCmd(0, ENABLE); |
frank26080115 | 0:bf7b9fba3924 | 148 | |
frank26080115 | 0:bf7b9fba3924 | 149 | while ((Channel0_TC == 0) ); |
frank26080115 | 0:bf7b9fba3924 | 150 | |
frank26080115 | 0:bf7b9fba3924 | 151 | // Disable GPDMA channel 0 |
frank26080115 | 0:bf7b9fba3924 | 152 | GPDMA_ChannelCmd(0, DISABLE); |
frank26080115 | 0:bf7b9fba3924 | 153 | |
frank26080115 | 0:bf7b9fba3924 | 154 | dac_value ++; |
frank26080115 | 0:bf7b9fba3924 | 155 | if (dac_value == 0x3FF) dac_value =0; |
frank26080115 | 0:bf7b9fba3924 | 156 | //delay |
frank26080115 | 0:bf7b9fba3924 | 157 | for(i=0;i<100000;i++); |
frank26080115 | 0:bf7b9fba3924 | 158 | |
frank26080115 | 0:bf7b9fba3924 | 159 | /* Reset terminal counter */ |
frank26080115 | 0:bf7b9fba3924 | 160 | Channel0_TC = 0; |
frank26080115 | 0:bf7b9fba3924 | 161 | |
frank26080115 | 0:bf7b9fba3924 | 162 | // Re-setup channel |
frank26080115 | 0:bf7b9fba3924 | 163 | GPDMA_Setup(&GPDMACfg); |
frank26080115 | 0:bf7b9fba3924 | 164 | } |
frank26080115 | 0:bf7b9fba3924 | 165 | |
frank26080115 | 0:bf7b9fba3924 | 166 | return 1; |
frank26080115 | 0:bf7b9fba3924 | 167 | } |
frank26080115 | 0:bf7b9fba3924 | 168 | /* With ARM and GHS toolsets, the entry point is main() - this will |
frank26080115 | 0:bf7b9fba3924 | 169 | allow the linker to generate wrapper code to setup stacks, allocate |
frank26080115 | 0:bf7b9fba3924 | 170 | heap area, and initialize and copy code and data segments. For GNU |
frank26080115 | 0:bf7b9fba3924 | 171 | toolsets, the entry point is through __start() in the crt0_gnu.asm |
frank26080115 | 0:bf7b9fba3924 | 172 | file, and that startup code will setup stacks and data */ |
frank26080115 | 0:bf7b9fba3924 | 173 | int main(void) |
frank26080115 | 0:bf7b9fba3924 | 174 | { |
frank26080115 | 0:bf7b9fba3924 | 175 | return c_entry(); |
frank26080115 | 0:bf7b9fba3924 | 176 | } |
frank26080115 | 0:bf7b9fba3924 | 177 | |
frank26080115 | 0:bf7b9fba3924 | 178 | #ifdef DEBUG |
frank26080115 | 0:bf7b9fba3924 | 179 | /******************************************************************************* |
frank26080115 | 0:bf7b9fba3924 | 180 | * @brief Reports the name of the source file and the source line number |
frank26080115 | 0:bf7b9fba3924 | 181 | * where the CHECK_PARAM error has occurred. |
frank26080115 | 0:bf7b9fba3924 | 182 | * @param[in] file Pointer to the source file name |
frank26080115 | 0:bf7b9fba3924 | 183 | * @param[in] line assert_param error line source number |
frank26080115 | 0:bf7b9fba3924 | 184 | * @return None |
frank26080115 | 0:bf7b9fba3924 | 185 | *******************************************************************************/ |
frank26080115 | 0:bf7b9fba3924 | 186 | void check_failed(uint8_t *file, uint32_t line) |
frank26080115 | 0:bf7b9fba3924 | 187 | { |
frank26080115 | 0:bf7b9fba3924 | 188 | /* User can add his own implementation to report the file name and line number, |
frank26080115 | 0:bf7b9fba3924 | 189 | ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ |
frank26080115 | 0:bf7b9fba3924 | 190 | |
frank26080115 | 0:bf7b9fba3924 | 191 | /* Infinite loop */ |
frank26080115 | 0:bf7b9fba3924 | 192 | while(1); |
frank26080115 | 0:bf7b9fba3924 | 193 | } |
frank26080115 | 0:bf7b9fba3924 | 194 | #endif |
frank26080115 | 0:bf7b9fba3924 | 195 | |
frank26080115 | 0:bf7b9fba3924 | 196 | /* |
frank26080115 | 0:bf7b9fba3924 | 197 | * @} |
frank26080115 | 0:bf7b9fba3924 | 198 | */ |