initial commit of kl25z rtc code. local changes for debug
Fork of KL25Z_RTC by
KL25Z_RTC.cpp@2:56a50064749e, 2013-06-19 (annotated)
- Committer:
- clemente
- Date:
- Wed Jun 19 09:03:44 2013 +0000
- Revision:
- 2:56a50064749e
- Parent:
- 1:2e81444e49a9
- Child:
- 3:2cee0b9ac1ff
Not final release. But almost usable.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
clemente | 0:12422f7c30d3 | 1 | /* Copyright (c) 2010-2011 mbed.org, MIT License |
clemente | 0:12422f7c30d3 | 2 | * |
clemente | 0:12422f7c30d3 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
clemente | 0:12422f7c30d3 | 4 | * and associated documentation files (the "Software"), to deal in the Software without |
clemente | 0:12422f7c30d3 | 5 | * restriction, including without limitation the rights to use, copy, modify, merge, publish, |
clemente | 0:12422f7c30d3 | 6 | * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the |
clemente | 0:12422f7c30d3 | 7 | * Software is furnished to do so, subject to the following conditions: |
clemente | 0:12422f7c30d3 | 8 | * |
clemente | 0:12422f7c30d3 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
clemente | 0:12422f7c30d3 | 10 | * substantial portions of the Software. |
clemente | 0:12422f7c30d3 | 11 | * |
clemente | 0:12422f7c30d3 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
clemente | 0:12422f7c30d3 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
clemente | 0:12422f7c30d3 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
clemente | 0:12422f7c30d3 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
clemente | 0:12422f7c30d3 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
clemente | 0:12422f7c30d3 | 17 | */ |
clemente | 0:12422f7c30d3 | 18 | |
clemente | 0:12422f7c30d3 | 19 | #include "KL25Z_RTC.h" |
clemente | 0:12422f7c30d3 | 20 | #include "rtc_api.h" |
clemente | 0:12422f7c30d3 | 21 | |
clemente | 0:12422f7c30d3 | 22 | unsigned int _alarm; |
clemente | 0:12422f7c30d3 | 23 | |
clemente | 1:2e81444e49a9 | 24 | void (*user2_fptr)(void); // Pointers to user function called after |
clemente | 1:2e81444e49a9 | 25 | void (*user1_fptr)(void); // IRQ assertion. |
clemente | 1:2e81444e49a9 | 26 | |
clemente | 1:2e81444e49a9 | 27 | |
clemente | 0:12422f7c30d3 | 28 | KL25Z_RTC::KL25Z_RTC( unsigned int alarm) |
clemente | 0:12422f7c30d3 | 29 | { |
clemente | 0:12422f7c30d3 | 30 | _alarm = alarm; |
clemente | 0:12422f7c30d3 | 31 | } |
clemente | 0:12422f7c30d3 | 32 | |
clemente | 0:12422f7c30d3 | 33 | unsigned int KL25Z_RTC::RTC_GetAlarm( void) |
clemente | 0:12422f7c30d3 | 34 | { |
clemente | 0:12422f7c30d3 | 35 | return _alarm; |
clemente | 0:12422f7c30d3 | 36 | } |
clemente | 0:12422f7c30d3 | 37 | |
clemente | 2:56a50064749e | 38 | void KL25Z_RTC::RTC_SetAlarm( unsigned int alarm) |
clemente | 2:56a50064749e | 39 | { |
clemente | 2:56a50064749e | 40 | _alarm = alarm; |
clemente | 2:56a50064749e | 41 | } |
clemente | 2:56a50064749e | 42 | |
clemente | 0:12422f7c30d3 | 43 | void KL25Z_RTC::RTC_Start( void) |
clemente | 0:12422f7c30d3 | 44 | { |
clemente | 0:12422f7c30d3 | 45 | rtc_init(); |
clemente | 0:12422f7c30d3 | 46 | |
clemente | 0:12422f7c30d3 | 47 | NVIC_EnableIRQ( RTC_Seconds_IRQn); |
clemente | 0:12422f7c30d3 | 48 | NVIC_EnableIRQ( RTC_IRQn); |
clemente | 0:12422f7c30d3 | 49 | |
clemente | 0:12422f7c30d3 | 50 | NVIC_SetVector( RTC_Seconds_IRQn, (uint32_t)&_RTC_Seconds_IRQHandler); |
clemente | 0:12422f7c30d3 | 51 | NVIC_SetVector( RTC_IRQn, (uint32_t)&_RTC_IRQHandler); |
clemente | 0:12422f7c30d3 | 52 | |
clemente | 0:12422f7c30d3 | 53 | RTC->TAR = RTC->TSR + _alarm; |
clemente | 0:12422f7c30d3 | 54 | RTC->IER = RTC_IER_TSIE_MASK | RTC_IER_TAIE_MASK; |
clemente | 0:12422f7c30d3 | 55 | |
clemente | 0:12422f7c30d3 | 56 | } |
clemente | 0:12422f7c30d3 | 57 | |
clemente | 1:2e81444e49a9 | 58 | void KL25Z_RTC::RTC_Start( void(*sec_ptr)(void), void(*alrm_ptr)(void)) |
clemente | 1:2e81444e49a9 | 59 | { |
clemente | 1:2e81444e49a9 | 60 | rtc_init(); |
clemente | 1:2e81444e49a9 | 61 | |
clemente | 1:2e81444e49a9 | 62 | RTC->IER = 0; |
clemente | 1:2e81444e49a9 | 63 | |
clemente | 1:2e81444e49a9 | 64 | if ( sec_ptr != NULL) { |
clemente | 1:2e81444e49a9 | 65 | NVIC_EnableIRQ( RTC_Seconds_IRQn); |
clemente | 1:2e81444e49a9 | 66 | NVIC_SetVector( RTC_Seconds_IRQn, (uint32_t)&_RTC_Seconds_IRQHandler); |
clemente | 1:2e81444e49a9 | 67 | user1_fptr = sec_ptr; |
clemente | 1:2e81444e49a9 | 68 | RTC->IER |= RTC_IER_TSIE_MASK; |
clemente | 1:2e81444e49a9 | 69 | } |
clemente | 1:2e81444e49a9 | 70 | |
clemente | 1:2e81444e49a9 | 71 | if ( alrm_ptr != NULL) { |
clemente | 1:2e81444e49a9 | 72 | RTC->TAR = RTC->TSR + _alarm; |
clemente | 1:2e81444e49a9 | 73 | NVIC_EnableIRQ( RTC_IRQn); |
clemente | 1:2e81444e49a9 | 74 | NVIC_SetVector( RTC_IRQn, (uint32_t)&_RTC_IRQHandler); |
clemente | 1:2e81444e49a9 | 75 | user2_fptr = alrm_ptr; |
clemente | 1:2e81444e49a9 | 76 | RTC->IER |= RTC_IER_TAIE_MASK; |
clemente | 1:2e81444e49a9 | 77 | } |
clemente | 1:2e81444e49a9 | 78 | |
clemente | 1:2e81444e49a9 | 79 | } |
clemente | 1:2e81444e49a9 | 80 | |
clemente | 1:2e81444e49a9 | 81 | void KL25Z_RTC::RTC_Seconds_CallBack( void(*fptr)(void)) |
clemente | 1:2e81444e49a9 | 82 | { |
clemente | 1:2e81444e49a9 | 83 | } |
clemente | 1:2e81444e49a9 | 84 | |
clemente | 0:12422f7c30d3 | 85 | unsigned int KL25Z_RTC::RTC_Read( void) |
clemente | 0:12422f7c30d3 | 86 | { |
clemente | 0:12422f7c30d3 | 87 | return RTC->TSR; |
clemente | 0:12422f7c30d3 | 88 | } |
clemente | 0:12422f7c30d3 | 89 | |
clemente | 0:12422f7c30d3 | 90 | void KL25Z_RTC::_RTC_IRQHandler(void) { |
clemente | 0:12422f7c30d3 | 91 | // error_led = 1; |
clemente | 0:12422f7c30d3 | 92 | if ( RTC->SR & 0x04) { |
clemente | 0:12422f7c30d3 | 93 | printf("RTC_Alarm\r\n"); |
clemente | 0:12422f7c30d3 | 94 | RTC->TAR = RTC->TSR + _alarm; |
clemente | 0:12422f7c30d3 | 95 | } |
clemente | 1:2e81444e49a9 | 96 | // Run the user supplied function |
clemente | 1:2e81444e49a9 | 97 | user2_fptr(); |
clemente | 1:2e81444e49a9 | 98 | |
clemente | 0:12422f7c30d3 | 99 | } |
clemente | 0:12422f7c30d3 | 100 | |
clemente | 0:12422f7c30d3 | 101 | |
clemente | 0:12422f7c30d3 | 102 | void KL25Z_RTC::_RTC_Seconds_IRQHandler(void) { |
clemente | 0:12422f7c30d3 | 103 | // |
clemente | 0:12422f7c30d3 | 104 | printf("RTC_Seconds_IRQHandler [%0d].\r\n", rtc_read()); |
clemente | 1:2e81444e49a9 | 105 | // Run the user supplied function |
clemente | 1:2e81444e49a9 | 106 | user1_fptr(); |
clemente | 0:12422f7c30d3 | 107 | } |
clemente | 0:12422f7c30d3 | 108 |