These are the examples provided for [[/users/frank26080115/libraries/LPC1700CMSIS_Lib/]] Note, the entire "program" is not compilable!
RTC/Calibration/rtc_calib.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 rtc_calib.c |
frank26080115 | 0:bf7b9fba3924 | 3 | * @purpose This example describes how to calibrate real time clock. |
frank26080115 | 0:bf7b9fba3924 | 4 | * @version 2.0 |
frank26080115 | 0:bf7b9fba3924 | 5 | * @date 18. June. 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.h" |
frank26080115 | 0:bf7b9fba3924 | 20 | #include "lpc17xx_clkpwr.h" |
frank26080115 | 0:bf7b9fba3924 | 21 | #include "lpc17xx_libcfg.h" |
frank26080115 | 0:bf7b9fba3924 | 22 | #include "debug_frmwrk.h" |
frank26080115 | 0:bf7b9fba3924 | 23 | #include "lpc17xx_rtc.h" |
frank26080115 | 0:bf7b9fba3924 | 24 | |
frank26080115 | 0:bf7b9fba3924 | 25 | /* Example group ----------------------------------------------------------- */ |
frank26080115 | 0:bf7b9fba3924 | 26 | /** @defgroup RTC_Calibration Calibration |
frank26080115 | 0:bf7b9fba3924 | 27 | * @ingroup RTC_Examples |
frank26080115 | 0:bf7b9fba3924 | 28 | * @{ |
frank26080115 | 0:bf7b9fba3924 | 29 | */ |
frank26080115 | 0:bf7b9fba3924 | 30 | |
frank26080115 | 0:bf7b9fba3924 | 31 | |
frank26080115 | 0:bf7b9fba3924 | 32 | /************************** PRIVATE VARIABLES *************************/ |
frank26080115 | 0:bf7b9fba3924 | 33 | uint8_t menu[]= |
frank26080115 | 0:bf7b9fba3924 | 34 | "********************************************************************************\n\r" |
frank26080115 | 0:bf7b9fba3924 | 35 | "Hello NXP Semiconductors \n\r" |
frank26080115 | 0:bf7b9fba3924 | 36 | "RTC Calibration demo \n\r" |
frank26080115 | 0:bf7b9fba3924 | 37 | "\t - MCU: LPC17xx \n\r" |
frank26080115 | 0:bf7b9fba3924 | 38 | "\t - Core: ARM CORTEX-M3 \n\r" |
frank26080115 | 0:bf7b9fba3924 | 39 | "\t - Communicate via: UART0 - 115200 bps \n\r" |
frank26080115 | 0:bf7b9fba3924 | 40 | "This example describes how to calibrate RTC \n\r" |
frank26080115 | 0:bf7b9fba3924 | 41 | "********************************************************************************\n\r"; |
frank26080115 | 0:bf7b9fba3924 | 42 | |
frank26080115 | 0:bf7b9fba3924 | 43 | /************************** PRIVATE FUNCTIONS *************************/ |
frank26080115 | 0:bf7b9fba3924 | 44 | void print_menu(void); |
frank26080115 | 0:bf7b9fba3924 | 45 | void RTC_IRQHandle(void); |
frank26080115 | 0:bf7b9fba3924 | 46 | |
frank26080115 | 0:bf7b9fba3924 | 47 | /*----------------- INTERRUPT SERVICE ROUTINES --------------------------*/ |
frank26080115 | 0:bf7b9fba3924 | 48 | /*********************************************************************//** |
frank26080115 | 0:bf7b9fba3924 | 49 | * @brief RTC interrupt handler sub-routine |
frank26080115 | 0:bf7b9fba3924 | 50 | * @param[in] None |
frank26080115 | 0:bf7b9fba3924 | 51 | * @return None |
frank26080115 | 0:bf7b9fba3924 | 52 | **********************************************************************/ |
frank26080115 | 0:bf7b9fba3924 | 53 | void RTC_IRQHandler(void) |
frank26080115 | 0:bf7b9fba3924 | 54 | { |
frank26080115 | 0:bf7b9fba3924 | 55 | uint32_t secval; |
frank26080115 | 0:bf7b9fba3924 | 56 | |
frank26080115 | 0:bf7b9fba3924 | 57 | /* This is increment counter interrupt*/ |
frank26080115 | 0:bf7b9fba3924 | 58 | if (RTC_GetIntPending(LPC_RTC, RTC_INT_COUNTER_INCREASE)) |
frank26080115 | 0:bf7b9fba3924 | 59 | { |
frank26080115 | 0:bf7b9fba3924 | 60 | secval = RTC_GetTime (LPC_RTC, RTC_TIMETYPE_SECOND); |
frank26080115 | 0:bf7b9fba3924 | 61 | |
frank26080115 | 0:bf7b9fba3924 | 62 | /* Send debug information */ |
frank26080115 | 0:bf7b9fba3924 | 63 | _DBG ("Second: "); _DBD(secval); |
frank26080115 | 0:bf7b9fba3924 | 64 | _DBG_(""); |
frank26080115 | 0:bf7b9fba3924 | 65 | |
frank26080115 | 0:bf7b9fba3924 | 66 | // Clear pending interrupt |
frank26080115 | 0:bf7b9fba3924 | 67 | RTC_ClearIntPending(LPC_RTC, RTC_INT_COUNTER_INCREASE); |
frank26080115 | 0:bf7b9fba3924 | 68 | } |
frank26080115 | 0:bf7b9fba3924 | 69 | } |
frank26080115 | 0:bf7b9fba3924 | 70 | |
frank26080115 | 0:bf7b9fba3924 | 71 | /*-------------------------PRIVATE FUNCTIONS------------------------------*/ |
frank26080115 | 0:bf7b9fba3924 | 72 | /*********************************************************************//** |
frank26080115 | 0:bf7b9fba3924 | 73 | * @brief Print Welcome menu |
frank26080115 | 0:bf7b9fba3924 | 74 | * @param[in] none |
frank26080115 | 0:bf7b9fba3924 | 75 | * @return None |
frank26080115 | 0:bf7b9fba3924 | 76 | **********************************************************************/ |
frank26080115 | 0:bf7b9fba3924 | 77 | void print_menu(void) |
frank26080115 | 0:bf7b9fba3924 | 78 | { |
frank26080115 | 0:bf7b9fba3924 | 79 | _DBG(menu); |
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 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 | |
frank26080115 | 0:bf7b9fba3924 | 99 | // print welcome screen |
frank26080115 | 0:bf7b9fba3924 | 100 | print_menu(); |
frank26080115 | 0:bf7b9fba3924 | 101 | |
frank26080115 | 0:bf7b9fba3924 | 102 | /* In this example: |
frank26080115 | 0:bf7b9fba3924 | 103 | * Suppose that the RTC need periodically adjust after each 5 second. |
frank26080115 | 0:bf7b9fba3924 | 104 | * And the time counter need by incrementing the counter by 2 instead of 1 |
frank26080115 | 0:bf7b9fba3924 | 105 | * We will observe timer counter after calibration via serial display |
frank26080115 | 0:bf7b9fba3924 | 106 | */ |
frank26080115 | 0:bf7b9fba3924 | 107 | // Init RTC module |
frank26080115 | 0:bf7b9fba3924 | 108 | RTC_Init(LPC_RTC); |
frank26080115 | 0:bf7b9fba3924 | 109 | |
frank26080115 | 0:bf7b9fba3924 | 110 | /* Enable rtc (starts increase the tick counter and second counter register) */ |
frank26080115 | 0:bf7b9fba3924 | 111 | RTC_ResetClockTickCounter(LPC_RTC); |
frank26080115 | 0:bf7b9fba3924 | 112 | RTC_Cmd(LPC_RTC, ENABLE); |
frank26080115 | 0:bf7b9fba3924 | 113 | |
frank26080115 | 0:bf7b9fba3924 | 114 | //Set current time = 0 |
frank26080115 | 0:bf7b9fba3924 | 115 | RTC_SetTime (LPC_RTC, RTC_TIMETYPE_SECOND, 0); |
frank26080115 | 0:bf7b9fba3924 | 116 | |
frank26080115 | 0:bf7b9fba3924 | 117 | /* Setting Timer calibration |
frank26080115 | 0:bf7b9fba3924 | 118 | * Calibration value = 5s; |
frank26080115 | 0:bf7b9fba3924 | 119 | * Direction = Forward calibration |
frank26080115 | 0:bf7b9fba3924 | 120 | * So after each 5s, calibration logic can periodically adjust the time counter by |
frank26080115 | 0:bf7b9fba3924 | 121 | * incrementing the counter by 2 instead of 1 |
frank26080115 | 0:bf7b9fba3924 | 122 | */ |
frank26080115 | 0:bf7b9fba3924 | 123 | RTC_CalibConfig(LPC_RTC, 5, RTC_CALIB_DIR_FORWARD); |
frank26080115 | 0:bf7b9fba3924 | 124 | RTC_CalibCounterCmd(LPC_RTC, ENABLE); |
frank26080115 | 0:bf7b9fba3924 | 125 | |
frank26080115 | 0:bf7b9fba3924 | 126 | /* Set the CIIR for second counter interrupt*/ |
frank26080115 | 0:bf7b9fba3924 | 127 | RTC_CntIncrIntConfig (LPC_RTC, RTC_TIMETYPE_SECOND, ENABLE); |
frank26080115 | 0:bf7b9fba3924 | 128 | |
frank26080115 | 0:bf7b9fba3924 | 129 | /* Enable RTC interrupt */ |
frank26080115 | 0:bf7b9fba3924 | 130 | NVIC_EnableIRQ(RTC_IRQn); |
frank26080115 | 0:bf7b9fba3924 | 131 | |
frank26080115 | 0:bf7b9fba3924 | 132 | /* Loop forever */ |
frank26080115 | 0:bf7b9fba3924 | 133 | while(1); |
frank26080115 | 0:bf7b9fba3924 | 134 | return 1; |
frank26080115 | 0:bf7b9fba3924 | 135 | } |
frank26080115 | 0:bf7b9fba3924 | 136 | |
frank26080115 | 0:bf7b9fba3924 | 137 | |
frank26080115 | 0:bf7b9fba3924 | 138 | /* With ARM and GHS toolsets, the entry point is main() - this will |
frank26080115 | 0:bf7b9fba3924 | 139 | allow the linker to generate wrapper code to setup stacks, allocate |
frank26080115 | 0:bf7b9fba3924 | 140 | heap area, and initialize and copy code and data segments. For GNU |
frank26080115 | 0:bf7b9fba3924 | 141 | toolsets, the entry point is through __start() in the crt0_gnu.asm |
frank26080115 | 0:bf7b9fba3924 | 142 | file, and that startup code will setup stacks and data */ |
frank26080115 | 0:bf7b9fba3924 | 143 | int main(void) |
frank26080115 | 0:bf7b9fba3924 | 144 | { |
frank26080115 | 0:bf7b9fba3924 | 145 | return c_entry(); |
frank26080115 | 0:bf7b9fba3924 | 146 | } |
frank26080115 | 0:bf7b9fba3924 | 147 | |
frank26080115 | 0:bf7b9fba3924 | 148 | #ifdef DEBUG |
frank26080115 | 0:bf7b9fba3924 | 149 | /******************************************************************************* |
frank26080115 | 0:bf7b9fba3924 | 150 | * @brief Reports the name of the source file and the source line number |
frank26080115 | 0:bf7b9fba3924 | 151 | * where the CHECK_PARAM error has occurred. |
frank26080115 | 0:bf7b9fba3924 | 152 | * @param[in] file Pointer to the source file name |
frank26080115 | 0:bf7b9fba3924 | 153 | * @param[in] line assert_param error line source number |
frank26080115 | 0:bf7b9fba3924 | 154 | * @return None |
frank26080115 | 0:bf7b9fba3924 | 155 | *******************************************************************************/ |
frank26080115 | 0:bf7b9fba3924 | 156 | void check_failed(uint8_t *file, uint32_t line) |
frank26080115 | 0:bf7b9fba3924 | 157 | { |
frank26080115 | 0:bf7b9fba3924 | 158 | /* User can add his own implementation to report the file name and line number, |
frank26080115 | 0:bf7b9fba3924 | 159 | ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ |
frank26080115 | 0:bf7b9fba3924 | 160 | |
frank26080115 | 0:bf7b9fba3924 | 161 | /* Infinite loop */ |
frank26080115 | 0:bf7b9fba3924 | 162 | while(1); |
frank26080115 | 0:bf7b9fba3924 | 163 | } |
frank26080115 | 0:bf7b9fba3924 | 164 | #endif |
frank26080115 | 0:bf7b9fba3924 | 165 | |
frank26080115 | 0:bf7b9fba3924 | 166 | /* |
frank26080115 | 0:bf7b9fba3924 | 167 | * @} |
frank26080115 | 0:bf7b9fba3924 | 168 | */ |