These are the examples provided for [[/users/frank26080115/libraries/LPC1700CMSIS_Lib/]] Note, the entire "program" is not compilable!
RIT/Interrupt/rit_interrupt.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 rit_interrupt.c |
frank26080115 | 0:bf7b9fba3924 | 3 | * @purpose This example used RIT to generate interrupt each 1s |
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_rit.h" |
frank26080115 | 0:bf7b9fba3924 | 20 | #include "lpc17xx_libcfg.h" |
frank26080115 | 0:bf7b9fba3924 | 21 | #include "debug_frmwrk.h" |
frank26080115 | 0:bf7b9fba3924 | 22 | #include "lpc17xx_gpio.h" |
frank26080115 | 0:bf7b9fba3924 | 23 | |
frank26080115 | 0:bf7b9fba3924 | 24 | /* Example group ----------------------------------------------------------- */ |
frank26080115 | 0:bf7b9fba3924 | 25 | /** @defgroup RIT_Interrupt Interrupt |
frank26080115 | 0:bf7b9fba3924 | 26 | * @ingroup RIT_Examples |
frank26080115 | 0:bf7b9fba3924 | 27 | * @{ |
frank26080115 | 0:bf7b9fba3924 | 28 | */ |
frank26080115 | 0:bf7b9fba3924 | 29 | |
frank26080115 | 0:bf7b9fba3924 | 30 | /************************** PRIVATE DEFINITIONS ***********************/ |
frank26080115 | 0:bf7b9fba3924 | 31 | #define MCB_LPC_1768 |
frank26080115 | 0:bf7b9fba3924 | 32 | //#define IAR_LPC_1768 |
frank26080115 | 0:bf7b9fba3924 | 33 | |
frank26080115 | 0:bf7b9fba3924 | 34 | #define TIME_INTERVAL 1000 |
frank26080115 | 0:bf7b9fba3924 | 35 | |
frank26080115 | 0:bf7b9fba3924 | 36 | /************************** PRIVATE VARIABLE ***********************/ |
frank26080115 | 0:bf7b9fba3924 | 37 | uint8_t menu[]= |
frank26080115 | 0:bf7b9fba3924 | 38 | "********************************************************************************\n\r" |
frank26080115 | 0:bf7b9fba3924 | 39 | "Hello NXP Semiconductors \n\r" |
frank26080115 | 0:bf7b9fba3924 | 40 | " RIT demo \n\r" |
frank26080115 | 0:bf7b9fba3924 | 41 | "\t - MCU: LPC17xx \n\r" |
frank26080115 | 0:bf7b9fba3924 | 42 | "\t - Core: ARM CORTEX-M3 \n\r" |
frank26080115 | 0:bf7b9fba3924 | 43 | "\t - Communicate via: UART0 - 115200 bps \n\r" |
frank26080115 | 0:bf7b9fba3924 | 44 | " Use RIT as a timer to generate interrupt to turn on/off LED each 1s \n\r" |
frank26080115 | 0:bf7b9fba3924 | 45 | "********************************************************************************\n\r"; |
frank26080115 | 0:bf7b9fba3924 | 46 | FunctionalState LEDStatus = ENABLE; |
frank26080115 | 0:bf7b9fba3924 | 47 | |
frank26080115 | 0:bf7b9fba3924 | 48 | /************************** PRIVATE FUNCTION *************************/ |
frank26080115 | 0:bf7b9fba3924 | 49 | void RIT_IRQHandler(void); |
frank26080115 | 0:bf7b9fba3924 | 50 | |
frank26080115 | 0:bf7b9fba3924 | 51 | /*----------------- INTERRUPT SERVICE ROUTINES --------------------------*/ |
frank26080115 | 0:bf7b9fba3924 | 52 | /*********************************************************************//** |
frank26080115 | 0:bf7b9fba3924 | 53 | * @brief RIT interrupt handler sub-routine |
frank26080115 | 0:bf7b9fba3924 | 54 | * @param[in] None |
frank26080115 | 0:bf7b9fba3924 | 55 | * @return None |
frank26080115 | 0:bf7b9fba3924 | 56 | **********************************************************************/ |
frank26080115 | 0:bf7b9fba3924 | 57 | void RIT_IRQHandler(void) |
frank26080115 | 0:bf7b9fba3924 | 58 | { |
frank26080115 | 0:bf7b9fba3924 | 59 | RIT_GetIntStatus(LPC_RIT); //call this to clear interrupt flag |
frank26080115 | 0:bf7b9fba3924 | 60 | if(LEDStatus == ENABLE) |
frank26080115 | 0:bf7b9fba3924 | 61 | { |
frank26080115 | 0:bf7b9fba3924 | 62 | LEDStatus = DISABLE; |
frank26080115 | 0:bf7b9fba3924 | 63 | #ifdef MCB_LPC_1768 |
frank26080115 | 0:bf7b9fba3924 | 64 | //turn off LED |
frank26080115 | 0:bf7b9fba3924 | 65 | GPIO_ClearValue(2,(1<<2)); |
frank26080115 | 0:bf7b9fba3924 | 66 | #elif defined(IAR_LPC_1768) |
frank26080115 | 0:bf7b9fba3924 | 67 | GPIO_SetValue(1,(1<<25)); |
frank26080115 | 0:bf7b9fba3924 | 68 | #endif |
frank26080115 | 0:bf7b9fba3924 | 69 | } |
frank26080115 | 0:bf7b9fba3924 | 70 | else |
frank26080115 | 0:bf7b9fba3924 | 71 | { |
frank26080115 | 0:bf7b9fba3924 | 72 | LEDStatus = ENABLE; |
frank26080115 | 0:bf7b9fba3924 | 73 | #ifdef MCB_LPC_1768 |
frank26080115 | 0:bf7b9fba3924 | 74 | //turn off LED |
frank26080115 | 0:bf7b9fba3924 | 75 | GPIO_SetValue(2,(1<<2)); |
frank26080115 | 0:bf7b9fba3924 | 76 | #elif defined(IAR_LPC_1768) |
frank26080115 | 0:bf7b9fba3924 | 77 | GPIO_ClearValue(1,(1<<25)); |
frank26080115 | 0:bf7b9fba3924 | 78 | #endif |
frank26080115 | 0:bf7b9fba3924 | 79 | } |
frank26080115 | 0:bf7b9fba3924 | 80 | } |
frank26080115 | 0:bf7b9fba3924 | 81 | |
frank26080115 | 0:bf7b9fba3924 | 82 | /*-------------------------MAIN FUNCTION------------------------------*/ |
frank26080115 | 0:bf7b9fba3924 | 83 | /*********************************************************************//** |
frank26080115 | 0:bf7b9fba3924 | 84 | * @brief c_entry: Main RIT program body |
frank26080115 | 0:bf7b9fba3924 | 85 | * @param[in] None |
frank26080115 | 0:bf7b9fba3924 | 86 | * @return int |
frank26080115 | 0:bf7b9fba3924 | 87 | **********************************************************************/ |
frank26080115 | 0:bf7b9fba3924 | 88 | int c_entry (void) { |
frank26080115 | 0:bf7b9fba3924 | 89 | |
frank26080115 | 0:bf7b9fba3924 | 90 | /* Initialize debug via UART0 |
frank26080115 | 0:bf7b9fba3924 | 91 | * 115200bps |
frank26080115 | 0:bf7b9fba3924 | 92 | * 8 data bit |
frank26080115 | 0:bf7b9fba3924 | 93 | * No parity |
frank26080115 | 0:bf7b9fba3924 | 94 | * 1 stop bit |
frank26080115 | 0:bf7b9fba3924 | 95 | * No flow control |
frank26080115 | 0:bf7b9fba3924 | 96 | */ |
frank26080115 | 0:bf7b9fba3924 | 97 | debug_frmwrk_init(); |
frank26080115 | 0:bf7b9fba3924 | 98 | _DBG(menu); |
frank26080115 | 0:bf7b9fba3924 | 99 | |
frank26080115 | 0:bf7b9fba3924 | 100 | RIT_Init(LPC_RIT); |
frank26080115 | 0:bf7b9fba3924 | 101 | /* Configure time_interval for RIT |
frank26080115 | 0:bf7b9fba3924 | 102 | * In this case: time_interval = 1000 ms = 1s |
frank26080115 | 0:bf7b9fba3924 | 103 | * So, RIT will generate interrupt each 1s |
frank26080115 | 0:bf7b9fba3924 | 104 | */ |
frank26080115 | 0:bf7b9fba3924 | 105 | RIT_TimerConfig(LPC_RIT,TIME_INTERVAL); |
frank26080115 | 0:bf7b9fba3924 | 106 | |
frank26080115 | 0:bf7b9fba3924 | 107 | _DBG("The time interval is: "); |
frank26080115 | 0:bf7b9fba3924 | 108 | _DBD32(TIME_INTERVAL); _DBG_(" millisecond.."); |
frank26080115 | 0:bf7b9fba3924 | 109 | |
frank26080115 | 0:bf7b9fba3924 | 110 | #ifdef MCB_LPC_1768 /* Using LED2.2 for testing */ |
frank26080115 | 0:bf7b9fba3924 | 111 | //turn on LED2.2 |
frank26080115 | 0:bf7b9fba3924 | 112 | FIO_SetDir(2,(1<<2),1); |
frank26080115 | 0:bf7b9fba3924 | 113 | FIO_SetValue(2,(1<<2)); |
frank26080115 | 0:bf7b9fba3924 | 114 | #elif defined(IAR_LPC_1768) /* Using LED1 (P1.25 for testing */ |
frank26080115 | 0:bf7b9fba3924 | 115 | FIO_SetDir(1,(1<<25),1); |
frank26080115 | 0:bf7b9fba3924 | 116 | FIO_ClearValue(1,(1<<25)); |
frank26080115 | 0:bf7b9fba3924 | 117 | #endif |
frank26080115 | 0:bf7b9fba3924 | 118 | NVIC_EnableIRQ(RIT_IRQn); |
frank26080115 | 0:bf7b9fba3924 | 119 | |
frank26080115 | 0:bf7b9fba3924 | 120 | while(1); |
frank26080115 | 0:bf7b9fba3924 | 121 | return 1; |
frank26080115 | 0:bf7b9fba3924 | 122 | } |
frank26080115 | 0:bf7b9fba3924 | 123 | |
frank26080115 | 0:bf7b9fba3924 | 124 | /* With ARM and GHS toolsets, the entry point is main() - this will |
frank26080115 | 0:bf7b9fba3924 | 125 | allow the linker to generate wrapper code to setup stacks, allocate |
frank26080115 | 0:bf7b9fba3924 | 126 | heap area, and initialize and copy code and data segments. For GNU |
frank26080115 | 0:bf7b9fba3924 | 127 | toolsets, the entry point is through __start() in the crt0_gnu.asm |
frank26080115 | 0:bf7b9fba3924 | 128 | file, and that startup code will setup stacks and data */ |
frank26080115 | 0:bf7b9fba3924 | 129 | int main(void) |
frank26080115 | 0:bf7b9fba3924 | 130 | { |
frank26080115 | 0:bf7b9fba3924 | 131 | return c_entry(); |
frank26080115 | 0:bf7b9fba3924 | 132 | } |
frank26080115 | 0:bf7b9fba3924 | 133 | |
frank26080115 | 0:bf7b9fba3924 | 134 | #ifdef DEBUG |
frank26080115 | 0:bf7b9fba3924 | 135 | /******************************************************************************* |
frank26080115 | 0:bf7b9fba3924 | 136 | * @brief Reports the name of the source file and the source line number |
frank26080115 | 0:bf7b9fba3924 | 137 | * where the CHECK_PARAM error has occurred. |
frank26080115 | 0:bf7b9fba3924 | 138 | * @param[in] file Pointer to the source file name |
frank26080115 | 0:bf7b9fba3924 | 139 | * @param[in] line assert_param error line source number |
frank26080115 | 0:bf7b9fba3924 | 140 | * @return None |
frank26080115 | 0:bf7b9fba3924 | 141 | *******************************************************************************/ |
frank26080115 | 0:bf7b9fba3924 | 142 | void check_failed(uint8_t *file, uint32_t line) |
frank26080115 | 0:bf7b9fba3924 | 143 | { |
frank26080115 | 0:bf7b9fba3924 | 144 | /* User can add his own implementation to report the file name and line number, |
frank26080115 | 0:bf7b9fba3924 | 145 | ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ |
frank26080115 | 0:bf7b9fba3924 | 146 | |
frank26080115 | 0:bf7b9fba3924 | 147 | /* Infinite loop */ |
frank26080115 | 0:bf7b9fba3924 | 148 | while(1); |
frank26080115 | 0:bf7b9fba3924 | 149 | } |
frank26080115 | 0:bf7b9fba3924 | 150 | #endif |
frank26080115 | 0:bf7b9fba3924 | 151 | |
frank26080115 | 0:bf7b9fba3924 | 152 | /* |
frank26080115 | 0:bf7b9fba3924 | 153 | * @} |
frank26080115 | 0:bf7b9fba3924 | 154 | */ |