Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 4:3bd0dc0c2b2e, committed 2013-08-25
- Comitter:
- clemente
- Date:
- Sun Aug 25 22:13:55 2013 +0000
- Parent:
- 3:2cee0b9ac1ff
- Commit message:
- First release.
Changed in this revision
| KL25Z_RTC.cpp | Show annotated file Show diff for this revision Revisions of this file |
| KL25Z_RTC.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/KL25Z_RTC.cpp Fri Jun 21 02:22:00 2013 +0000
+++ b/KL25Z_RTC.cpp Sun Aug 25 22:13:55 2013 +0000
@@ -19,15 +19,32 @@
#include "KL25Z_RTC.h"
#include "rtc_api.h"
-unsigned int _alarm;
+unsigned int _alarm=0; // Value at which tha alarm is set.
+volatile unsigned int _secIRQ_Done;
+volatile unsigned int _alrmIRQ_Done;
-void (*user2_fptr)(void); // Pointers to user function called after
-void (*user1_fptr)(void); // IRQ assertion.
+void (*RTC_usr2_fptr)(void); // Pointers to user function called after
+void (*RTC_usr1_fptr)(void); // IRQ assertion.
KL25Z_RTC::KL25Z_RTC( unsigned int alarm)
{
- _alarm = alarm;
+ if ( alarm != 0)
+ _alarm = alarm;
+}
+
+KL25Z_RTC::~KL25Z_RTC()
+{
+ NVIC_DisableIRQ( RTC_Seconds_IRQn);
+ RTC_usr1_fptr = NULL;
+ RTC->IER &= ~RTC_IER_TSIE_MASK;
+
+ NVIC_DisableIRQ( RTC_IRQn);
+ RTC_usr2_fptr = NULL;
+ RTC->IER &= ~RTC_IER_TAIE_MASK;
+
+ // Disable the clock to the RTC module.
+ SIM->SCGC6 &= ~SIM_SCGC6_RTC_MASK;
}
unsigned int KL25Z_RTC::RTC_GetAlarm( void)
@@ -64,16 +81,22 @@
if ( sec_ptr != NULL) {
NVIC_EnableIRQ( RTC_Seconds_IRQn);
NVIC_SetVector( RTC_Seconds_IRQn, (uint32_t)&_RTC_Seconds_IRQHandler);
- user1_fptr = sec_ptr;
+ RTC_usr1_fptr = sec_ptr;
RTC->IER |= RTC_IER_TSIE_MASK;
+ } else {
+ NVIC_DisableIRQ( RTC_Seconds_IRQn);
+ RTC->IER &= ~RTC_IER_TSIE_MASK;
}
if ( alrm_ptr != NULL) {
RTC->TAR = RTC->TSR + _alarm;
NVIC_EnableIRQ( RTC_IRQn);
NVIC_SetVector( RTC_IRQn, (uint32_t)&_RTC_IRQHandler);
- user2_fptr = alrm_ptr;
+ RTC_usr2_fptr = alrm_ptr;
RTC->IER |= RTC_IER_TAIE_MASK;
+ } else {
+ NVIC_DisableIRQ( RTC_IRQn);
+ RTC->IER &= ~RTC_IER_TAIE_MASK;
}
}
@@ -83,22 +106,47 @@
return RTC->TSR;
}
-void KL25Z_RTC::_RTC_IRQHandler(void) {
- // error_led = 1;
+void KL25Z_RTC::_RTC_IRQHandler(void)
+{
+ //
if ( RTC->SR & 0x04) {
// printf("RTC_Alarm\r\n");
RTC->TAR = RTC->TSR + _alarm;
+ // Run the user supplied function
+ if ( RTC_usr2_fptr != NULL)
+ RTC_usr2_fptr();
+ //
+ _alrmIRQ_Done=1;
}
- // Run the user supplied function
- user2_fptr();
}
-
-void KL25Z_RTC::_RTC_Seconds_IRQHandler(void) {
+void KL25Z_RTC::_RTC_Seconds_IRQHandler(void)
+{
//
+ _secIRQ_Done=1;
+
// printf("RTC_Seconds_IRQHandler [%0d].\r\n", RTC->TSR);
// Run the user supplied function
- user1_fptr();
+ if ( RTC_usr1_fptr != NULL)
+ RTC_usr1_fptr();
}
+unsigned int KL25Z_RTC::RTC_isIRQSecondDone( void)
+{
+ if ( _secIRQ_Done) {
+ _secIRQ_Done=0;
+ return 1;
+ } else
+ return 0;
+}
+
+unsigned int KL25Z_RTC::RTC_isIRQAlarmDone( void)
+{
+ if ( _alrmIRQ_Done) {
+ _alrmIRQ_Done=0;
+ return 1;
+ } else
+ return 0;
+}
+
--- a/KL25Z_RTC.h Fri Jun 21 02:22:00 2013 +0000
+++ b/KL25Z_RTC.h Sun Aug 25 22:13:55 2013 +0000
@@ -66,7 +66,14 @@
*/
KL25Z_RTC( unsigned int alarm);
- /** Start the RTC module
+ /** Desctructor
+ */
+ ~KL25Z_RTC();
+
+ /** Start the RTC module, using IRQ but without registering user defined callback functions.
+ * Access to the elapsed time is possible using the "Read" methid.
+ * The IRQ transaction is visible through "RTC_isIRQxxxxDone" methods.
+ *
* @param none
* @return none
*/
@@ -95,6 +102,24 @@
* @return the second elapsed
*/
unsigned int RTC_Read( void);
+
+ /** Return the status of the IRQ for seconds elapsed.
+ * Use this function for a polling like method, using the IRQ internally the module but without callbacks define.
+ * The flag is reset after the read.
+ *
+ * @param none
+ * @return 1 if the IRQ is done.
+ */
+ unsigned int RTC_isIRQSecondDone( void);
+
+ /** Return the status of the IRQ for the alarm.
+ * Use this function for a polling like method, using the IRQ internally the module but without callbacks define.
+ * The flag is reset after the read.
+ *
+ * @param none
+ * @return 1 if the IRQ is done.
+ */
+ unsigned int RTC_isIRQAlarmDone( void);
private: