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 wdt_interrupt_test.c
frank26080115 0:bf7b9fba3924 3 * @purpose This example describes how to use Watch-dog timer application
frank26080115 0:bf7b9fba3924 4 * in interrupt mode
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_wdt.h"
frank26080115 0:bf7b9fba3924 21 #include "lpc17xx_libcfg.h"
frank26080115 0:bf7b9fba3924 22 #include "lpc17xx_pinsel.h"
frank26080115 0:bf7b9fba3924 23 #include "debug_frmwrk.h"
frank26080115 0:bf7b9fba3924 24 #include "lpc17xx_gpio.h"
frank26080115 0:bf7b9fba3924 25
frank26080115 0:bf7b9fba3924 26 /* Example group ----------------------------------------------------------- */
frank26080115 0:bf7b9fba3924 27 /** @defgroup WDT_INTERRUPT INTERRUPT
frank26080115 0:bf7b9fba3924 28 * @ingroup WDT_Examples
frank26080115 0:bf7b9fba3924 29 * @{
frank26080115 0:bf7b9fba3924 30 */
frank26080115 0:bf7b9fba3924 31
frank26080115 0:bf7b9fba3924 32 /************************** PRIVATE DEFINITIONS *************************/
frank26080115 0:bf7b9fba3924 33 #define MCB_LPC_1768
frank26080115 0:bf7b9fba3924 34 //#define IAR_LPC_1768
frank26080115 0:bf7b9fba3924 35
frank26080115 0:bf7b9fba3924 36 //Watchodog time out in 5 seconds
frank26080115 0:bf7b9fba3924 37 #define WDT_TIMEOUT 5000000
frank26080115 0:bf7b9fba3924 38
frank26080115 0:bf7b9fba3924 39
frank26080115 0:bf7b9fba3924 40 /************************** PRIVATE VARIABLES *************************/
frank26080115 0:bf7b9fba3924 41 uint8_t menu1[] =
frank26080115 0:bf7b9fba3924 42 "********************************************************************************\n\r"
frank26080115 0:bf7b9fba3924 43 "Hello NXP Semiconductors \n\r"
frank26080115 0:bf7b9fba3924 44 " Watch dog timer interrupt (test or debug mode) demo \n\r"
frank26080115 0:bf7b9fba3924 45 "\t - MCU: LPC17xx \n\r"
frank26080115 0:bf7b9fba3924 46 "\t - Core: Cortex M3 \n\r"
frank26080115 0:bf7b9fba3924 47 "\t - Communicate via: UART0 - 115200 bps \n\r"
frank26080115 0:bf7b9fba3924 48 " Use WDT with Internal RC OSC, interrupt mode (test only), timeout = 1 seconds \n\r"
frank26080115 0:bf7b9fba3924 49 " To generate an interrupt, after interrupt WDT interrupt is disabled immediately! \n\r"
frank26080115 0:bf7b9fba3924 50 "********************************************************************************\n\r";
frank26080115 0:bf7b9fba3924 51 uint8_t info1[] = "BEFORE WDT interrupt!\n\r";
frank26080115 0:bf7b9fba3924 52 uint8_t info2[] = "AFTER WDT interrupt\n\r";
frank26080115 0:bf7b9fba3924 53
frank26080115 0:bf7b9fba3924 54 __IO Bool wdt_flag = FALSE;
frank26080115 0:bf7b9fba3924 55 __IO Bool LED_toggle = FALSE;
frank26080115 0:bf7b9fba3924 56
frank26080115 0:bf7b9fba3924 57 /************************** PRIVATE FUNCTION *************************/
frank26080115 0:bf7b9fba3924 58 void WDT_IRQHandler(void);
frank26080115 0:bf7b9fba3924 59
frank26080115 0:bf7b9fba3924 60 void print_menu(void);
frank26080115 0:bf7b9fba3924 61 void LED_Init (void);
frank26080115 0:bf7b9fba3924 62
frank26080115 0:bf7b9fba3924 63 /*----------------- INTERRUPT SERVICE ROUTINES --------------------------*/
frank26080115 0:bf7b9fba3924 64 /*********************************************************************//**
frank26080115 0:bf7b9fba3924 65 * @brief WDT interrupt handler sub-routine
frank26080115 0:bf7b9fba3924 66 * @param[in] None
frank26080115 0:bf7b9fba3924 67 * @return None
frank26080115 0:bf7b9fba3924 68 **********************************************************************/
frank26080115 0:bf7b9fba3924 69 void WDT_IRQHandler(void)
frank26080115 0:bf7b9fba3924 70 {
frank26080115 0:bf7b9fba3924 71 // Disable WDT interrupt
frank26080115 0:bf7b9fba3924 72 NVIC_DisableIRQ(WDT_IRQn);
frank26080115 0:bf7b9fba3924 73 // Set WDT flag according
frank26080115 0:bf7b9fba3924 74 if (wdt_flag == TRUE)
frank26080115 0:bf7b9fba3924 75 wdt_flag = FALSE;
frank26080115 0:bf7b9fba3924 76 else
frank26080115 0:bf7b9fba3924 77 wdt_flag = TRUE;
frank26080115 0:bf7b9fba3924 78 // Clear TimeOut flag
frank26080115 0:bf7b9fba3924 79 WDT_ClrTimeOutFlag();
frank26080115 0:bf7b9fba3924 80 }
frank26080115 0:bf7b9fba3924 81
frank26080115 0:bf7b9fba3924 82 /*-------------------------PRIVATE FUNCTIONS------------------------------*/
frank26080115 0:bf7b9fba3924 83 /*********************************************************************//**
frank26080115 0:bf7b9fba3924 84 * @brief Print menu
frank26080115 0:bf7b9fba3924 85 * @param[in] None
frank26080115 0:bf7b9fba3924 86 * @return None
frank26080115 0:bf7b9fba3924 87 **********************************************************************/
frank26080115 0:bf7b9fba3924 88 void print_menu(void)
frank26080115 0:bf7b9fba3924 89 {
frank26080115 0:bf7b9fba3924 90 _DBG(menu1);
frank26080115 0:bf7b9fba3924 91 }
frank26080115 0:bf7b9fba3924 92
frank26080115 0:bf7b9fba3924 93 /*********************************************************************//**
frank26080115 0:bf7b9fba3924 94 * @brief Initialize LEDs
frank26080115 0:bf7b9fba3924 95 * @param[in] None
frank26080115 0:bf7b9fba3924 96 * @return None
frank26080115 0:bf7b9fba3924 97 **********************************************************************/
frank26080115 0:bf7b9fba3924 98 void LED_Init (void)
frank26080115 0:bf7b9fba3924 99 {
frank26080115 0:bf7b9fba3924 100 #ifdef MCB_LPC_1768 /* Using LED2.2 for testing */
frank26080115 0:bf7b9fba3924 101 //turn on LED2.2
frank26080115 0:bf7b9fba3924 102 FIO_SetDir(2,(1<<2),1);
frank26080115 0:bf7b9fba3924 103 FIO_SetValue(2,(1<<2));
frank26080115 0:bf7b9fba3924 104 #elif defined(IAR_LPC_1768) /* Using LED1 (P1.25 for testing */
frank26080115 0:bf7b9fba3924 105 FIO_SetDir(1,(1<<25),1);
frank26080115 0:bf7b9fba3924 106 FIO_ClearValue(1,(1<<25));
frank26080115 0:bf7b9fba3924 107 #endif
frank26080115 0:bf7b9fba3924 108 }
frank26080115 0:bf7b9fba3924 109
frank26080115 0:bf7b9fba3924 110 /*-------------------------MAIN FUNCTION------------------------------*/
frank26080115 0:bf7b9fba3924 111 /*********************************************************************//**
frank26080115 0:bf7b9fba3924 112 * @brief c_entry: Main WDT program body
frank26080115 0:bf7b9fba3924 113 * @param[in] None
frank26080115 0:bf7b9fba3924 114 * @return int
frank26080115 0:bf7b9fba3924 115 **********************************************************************/
frank26080115 0:bf7b9fba3924 116 int c_entry(void)
frank26080115 0:bf7b9fba3924 117 {
frank26080115 0:bf7b9fba3924 118 uint32_t delay;
frank26080115 0:bf7b9fba3924 119 // Init LED port
frank26080115 0:bf7b9fba3924 120 LED_Init();
frank26080115 0:bf7b9fba3924 121
frank26080115 0:bf7b9fba3924 122 /* Initialize debug via UART0
frank26080115 0:bf7b9fba3924 123 * – 115200bps
frank26080115 0:bf7b9fba3924 124 * – 8 data bit
frank26080115 0:bf7b9fba3924 125 * – No parity
frank26080115 0:bf7b9fba3924 126 * – 1 stop bit
frank26080115 0:bf7b9fba3924 127 * – No flow control
frank26080115 0:bf7b9fba3924 128 */
frank26080115 0:bf7b9fba3924 129 debug_frmwrk_init();
frank26080115 0:bf7b9fba3924 130
frank26080115 0:bf7b9fba3924 131 // print welcome screen
frank26080115 0:bf7b9fba3924 132 print_menu();
frank26080115 0:bf7b9fba3924 133
frank26080115 0:bf7b9fba3924 134 /* Install interrupt for WDT interrupt */
frank26080115 0:bf7b9fba3924 135 NVIC_SetPriority(WDT_IRQn, 0x10);
frank26080115 0:bf7b9fba3924 136 // Set Watchdog use internal RC, just generate interrupt only in 5ms if Watchdog is not feed
frank26080115 0:bf7b9fba3924 137
frank26080115 0:bf7b9fba3924 138 // Init WDT, IRC OSC, interrupt mode, timeout = 5000000 us = 5s
frank26080115 0:bf7b9fba3924 139 WDT_Init(WDT_CLKSRC_IRC, WDT_MODE_INT_ONLY);
frank26080115 0:bf7b9fba3924 140
frank26080115 0:bf7b9fba3924 141 /* Enable the Watch dog interrupt*/
frank26080115 0:bf7b9fba3924 142 NVIC_EnableIRQ(WDT_IRQn);
frank26080115 0:bf7b9fba3924 143
frank26080115 0:bf7b9fba3924 144 while (1)
frank26080115 0:bf7b9fba3924 145 {
frank26080115 0:bf7b9fba3924 146 if (wdt_flag == FALSE){ //before WDT interrupt
frank26080115 0:bf7b9fba3924 147 _DBG_(info1);
frank26080115 0:bf7b9fba3924 148 _DBG_("Press '1' to enable Watchdog timer...");
frank26080115 0:bf7b9fba3924 149 while(_DG !='1');
frank26080115 0:bf7b9fba3924 150 // Start watchdog with timeout given
frank26080115 0:bf7b9fba3924 151 WDT_Start(WDT_TIMEOUT);
frank26080115 0:bf7b9fba3924 152 while(wdt_flag == FALSE)
frank26080115 0:bf7b9fba3924 153 {
frank26080115 0:bf7b9fba3924 154 _DBD32(WDT_GetCurrentCount()); _DBG_("");
frank26080115 0:bf7b9fba3924 155 }
frank26080115 0:bf7b9fba3924 156 } else { // after WDT interrupt
frank26080115 0:bf7b9fba3924 157 _DBG_(info2);
frank26080115 0:bf7b9fba3924 158 _DBG_("LED is blinking...");
frank26080115 0:bf7b9fba3924 159 while(wdt_flag == TRUE)
frank26080115 0:bf7b9fba3924 160 {
frank26080115 0:bf7b9fba3924 161 if (LED_toggle == FALSE)
frank26080115 0:bf7b9fba3924 162 {
frank26080115 0:bf7b9fba3924 163 #ifdef MCB_LPC_1768
frank26080115 0:bf7b9fba3924 164 //turn on LED
frank26080115 0:bf7b9fba3924 165 GPIO_SetValue(2,(1<<2));
frank26080115 0:bf7b9fba3924 166 #elif defined(IAR_LPC_1768)
frank26080115 0:bf7b9fba3924 167 GPIO_ClearValue(1,(1<<25));
frank26080115 0:bf7b9fba3924 168 #endif
frank26080115 0:bf7b9fba3924 169 LED_toggle = TRUE;
frank26080115 0:bf7b9fba3924 170 }
frank26080115 0:bf7b9fba3924 171 else
frank26080115 0:bf7b9fba3924 172 {
frank26080115 0:bf7b9fba3924 173 #ifdef MCB_LPC_1768
frank26080115 0:bf7b9fba3924 174 //turn off LED
frank26080115 0:bf7b9fba3924 175 GPIO_ClearValue(2,(1<<2));
frank26080115 0:bf7b9fba3924 176 #elif defined(IAR_LPC_1768)
frank26080115 0:bf7b9fba3924 177 GPIO_SetValue(1,(1<<25));
frank26080115 0:bf7b9fba3924 178 #endif
frank26080115 0:bf7b9fba3924 179 LED_toggle = FALSE;
frank26080115 0:bf7b9fba3924 180 }
frank26080115 0:bf7b9fba3924 181 //delay
frank26080115 0:bf7b9fba3924 182 for(delay = 0; delay<1000000; delay ++);
frank26080115 0:bf7b9fba3924 183 }
frank26080115 0:bf7b9fba3924 184 }
frank26080115 0:bf7b9fba3924 185 }
frank26080115 0:bf7b9fba3924 186 return 1;
frank26080115 0:bf7b9fba3924 187 }
frank26080115 0:bf7b9fba3924 188
frank26080115 0:bf7b9fba3924 189 /* Support required entry point for other toolchain */
frank26080115 0:bf7b9fba3924 190 int main (void)
frank26080115 0:bf7b9fba3924 191 {
frank26080115 0:bf7b9fba3924 192 return c_entry();
frank26080115 0:bf7b9fba3924 193 }
frank26080115 0:bf7b9fba3924 194 #ifdef DEBUG
frank26080115 0:bf7b9fba3924 195 /*******************************************************************************
frank26080115 0:bf7b9fba3924 196 * @brief Reports the name of the source file and the source line number
frank26080115 0:bf7b9fba3924 197 * where the CHECK_PARAM error has occurred.
frank26080115 0:bf7b9fba3924 198 * @param[in] file Pointer to the source file name
frank26080115 0:bf7b9fba3924 199 * @param[in] line assert_param error line source number
frank26080115 0:bf7b9fba3924 200 * @return None
frank26080115 0:bf7b9fba3924 201 *******************************************************************************/
frank26080115 0:bf7b9fba3924 202 void check_failed(uint8_t *file, uint32_t line)
frank26080115 0:bf7b9fba3924 203 {
frank26080115 0:bf7b9fba3924 204 /* User can add his own implementation to report the file name and line number,
frank26080115 0:bf7b9fba3924 205 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
frank26080115 0:bf7b9fba3924 206
frank26080115 0:bf7b9fba3924 207 /* Infinite loop */
frank26080115 0:bf7b9fba3924 208 while(1);
frank26080115 0:bf7b9fba3924 209 }
frank26080115 0:bf7b9fba3924 210 #endif
frank26080115 0:bf7b9fba3924 211
frank26080115 0:bf7b9fba3924 212 /*
frank26080115 0:bf7b9fba3924 213 * @}
frank26080115 0:bf7b9fba3924 214 */