Merge pull request #1859 from alignan/pull/remote-rtcc-update
Zoul: RTCC with trigger selection and second-based time increase
This commit is contained in:
commit
95ed9a9a91
4 changed files with 158 additions and 24 deletions
|
@ -59,9 +59,14 @@
|
|||
#define DATE "Unknown"
|
||||
#endif
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define LOOP_PERIOD 60L
|
||||
#define LOOP_INTERVAL (CLOCK_SECOND * LOOP_PERIOD)
|
||||
#define TEST_ALARM_SECOND 30
|
||||
#define LOOP_PERIOD 60L
|
||||
#define LOOP_INTERVAL (CLOCK_SECOND * LOOP_PERIOD)
|
||||
#define TEST_ALARM_SECOND 15
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Enable to match a given second number every minute, else it will trigger an
|
||||
* interrupt every TEST_ALARM_SECOND
|
||||
*/
|
||||
#define TEST_ALARM_MATCH_MIN 0
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS(test_remote_rtcc_process, "Test RTC driver process");
|
||||
AUTOSTART_PROCESSES(&test_remote_rtcc_process);
|
||||
|
@ -72,11 +77,34 @@ static simple_td_map *simple_td = (simple_td_map *)rtc_buffer;
|
|||
static struct etimer et;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
configure_new_alarm(void)
|
||||
{
|
||||
if(rtcc_date_increment_seconds(simple_td, TEST_ALARM_SECOND) == AB08_ERROR) {
|
||||
printf("Fail: could not increment the next alarm date\n");
|
||||
return;
|
||||
}
|
||||
|
||||
/* We use the RTCC_REPEAT_DAY as we want the RTCC to match the given date */
|
||||
if(rtcc_set_alarm_time_date(simple_td, RTCC_ALARM_ON, RTCC_REPEAT_DAY,
|
||||
RTCC_TRIGGER_INT1) == AB08_ERROR) {
|
||||
printf("Fail: couldn't set the alarm\n");
|
||||
return;
|
||||
}
|
||||
|
||||
printf("Alarm set to match: ");
|
||||
rtcc_print(RTCC_PRINT_ALARM_DEC);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
rtcc_interrupt_callback(uint8_t value)
|
||||
{
|
||||
printf("A RTCC interrupt just happened! time/date: ");
|
||||
rtcc_print(RTCC_PRINT_DATE_DEC);
|
||||
leds_toggle(LEDS_PURPLE);
|
||||
leds_toggle(LEDS_ALL);
|
||||
|
||||
#if !TEST_ALARM_MATCH_MIN
|
||||
configure_new_alarm();
|
||||
#endif
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(test_remote_rtcc_process, ev, data)
|
||||
|
@ -149,9 +177,10 @@ PROCESS_THREAD(test_remote_rtcc_process, ev, data)
|
|||
printf("Configured time: ");
|
||||
rtcc_print(RTCC_PRINT_DATE_DEC);
|
||||
|
||||
/* Configure the RTCC to trigger an alarm every TEST_ALARM_SECOND tick */
|
||||
printf("Setting an alarm to tick every minute matching %u seconds\n",
|
||||
TEST_ALARM_SECOND);
|
||||
#if TEST_ALARM_MATCH_MIN
|
||||
/* Configure the RTCC to trigger an alarm every TEST_ALARM_SECOND match */
|
||||
printf("Setting an alarm to tick every %u seconds match\n", TEST_ALARM_SECOND);
|
||||
|
||||
simple_td->seconds = TEST_ALARM_SECOND;
|
||||
|
||||
/* Notice the arguments, we want to trigger the alarm every time the clock
|
||||
|
@ -159,14 +188,18 @@ PROCESS_THREAD(test_remote_rtcc_process, ev, data)
|
|||
* minute. In case we would want to trigger the alarm on a specific time,
|
||||
* then we would want to set a daily repeat interval
|
||||
*/
|
||||
if(rtcc_set_alarm_time_date(simple_td, RTCC_ALARM_ON,
|
||||
RTCC_REPEAT_MINUTE) == AB08_ERROR) {
|
||||
if(rtcc_set_alarm_time_date(simple_td, RTCC_ALARM_ON, RTCC_REPEAT_MINUTE,
|
||||
RTCC_TRIGGER_INT1) == AB08_ERROR) {
|
||||
printf("Fail: couldn't set the alarm\n");
|
||||
PROCESS_EXIT();
|
||||
}
|
||||
|
||||
printf("Alarm set to match: ");
|
||||
rtcc_print(RTCC_PRINT_ALARM_DEC);
|
||||
#else
|
||||
/* Configure the RTCC to trigger an alarm every TEST_ALARM_SECOND tick */
|
||||
printf("Setting an alarm to tick every %u seconds\n", TEST_ALARM_SECOND);
|
||||
|
||||
configure_new_alarm();
|
||||
#endif
|
||||
|
||||
PROCESS_END();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue