RTC. Test updated.

git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3408 35acf78f-673a-0410-8e92-d51de3d6d3f4
master
barthess 2011-09-25 10:32:39 +00:00
parent fa0a7f52db
commit 0af85bab42
2 changed files with 24 additions and 14 deletions

View File

@ -76,7 +76,7 @@ void rtcInit(void){
*/ */
void rtcSetCallback(RTCDriver *rtcp, rtccb_t overflowcb, void rtcSetCallback(RTCDriver *rtcp, rtccb_t overflowcb,
rtccb_t secondcb, rtccb_t alarmcb){ rtccb_t secondcb, rtccb_t alarmcb){
chDbgCheck((rtcp != NULL), "rtcStart"); chDbgCheck((rtcp != NULL), "rtcSetCallback");
rtc_lld_set_callback(rtcp, overflowcb, secondcb, alarmcb); rtc_lld_set_callback(rtcp, overflowcb, secondcb, alarmcb);
} }
#endif /* RTC_SUPPORTS_CALLBACKS */ #endif /* RTC_SUPPORTS_CALLBACKS */

View File

@ -21,30 +21,36 @@
#include "ch.h" #include "ch.h"
#include "hal.h" #include "hal.h"
//#define TEST_DEEPSLEEP_ENABLE
#ifdef TEST_DEEPSLEEP_ENABLE RTCDateTime timespec;
RTCDateTime alarmspec;
#define TEST_ALARM_WAKEUP FALSE
#if TEST_ALARM_WAKEUP
/* sleep indicator thread */
static WORKING_AREA(blinkWA, 128); static WORKING_AREA(blinkWA, 128);
static msg_t blink_thd(void *arg){ static msg_t blink_thd(void *arg){
(void)arg; (void)arg;
while (TRUE) { while (TRUE) {
chThdSleepMilliseconds(500); chThdSleepMilliseconds(100);
palTogglePad(IOPORT3, GPIOC_LED); palTogglePad(IOPORT3, GPIOC_LED);
} }
return 0; return 0;
} }
int main(void) { int main(void) {
halInit(); halInit();
chSysInit(); chSysInit();
chThdCreateStatic(blinkWA, sizeof(blinkWA), NORMALPRIO, blink_thd, NULL); chThdCreateStatic(blinkWA, sizeof(blinkWA), NORMALPRIO, blink_thd, NULL);
/* set alarm in near future */ /* set alarm in near future */
rtcSetAlarm(rtcGetSec() + 60); rtcGetTime(&timespec);
alarmspec.tv_sec = timespec.tv_sec + 60;
rtcSetAlarm(&alarmspec);
while (TRUE){ while (TRUE){
chThdSleepSeconds(10); chThdSleepSeconds(10);
@ -60,12 +66,11 @@ int main(void) {
#else /* TEST_DEEPSLEEP_ENABLE */ #else /* TEST_ALARM_WAKEUP */
static void my_overflowcb(RTCDriver *rtcp){ static void my_overflowcb(RTCDriver *rtcp){
(void)rtcp; (void)rtcp;
palTogglePad(IOPORT3, GPIOC_LED); palTogglePad(IOPORT3, GPIOC_LED);
rtcSetAlarm(rtcGetSec() + 10);
} }
static void my_secondcb(RTCDriver *rtcp){ static void my_secondcb(RTCDriver *rtcp){
@ -76,7 +81,9 @@ static void my_secondcb(RTCDriver *rtcp){
static void my_alarmcb(RTCDriver *rtcp){ static void my_alarmcb(RTCDriver *rtcp){
(void)rtcp; (void)rtcp;
palTogglePad(IOPORT3, GPIOC_LED); palTogglePad(IOPORT3, GPIOC_LED);
rtcSetAlarm(rtcGetSec() + 10); rtcGetTime(&timespec);
alarmspec.tv_sec = timespec.tv_sec + 10;
rtcSetAlarm(&alarmspec);
} }
@ -84,11 +91,14 @@ int main(void) {
halInit(); halInit();
chSysInit(); chSysInit();
rtcSetAlarm(rtcGetSec() + 10); rtcGetTime(&timespec);
rtcSetCallback(&RTCD, NULL, my_secondcb, my_alarmcb); alarmspec.tv_sec = timespec.tv_sec + 10;
rtcSetAlarm(&alarmspec);
rtcSetCallback(&RTCD, my_overflowcb, my_secondcb, my_alarmcb);
while (TRUE){ while (TRUE){
chThdSleepMilliseconds(500); chThdSleepMilliseconds(500);
} }
return 0; return 0;
} }
#endif /* TEST_DEEPSLEEP_ENABLE */ #endif /* TEST_ALARM_WAKEUP */