diff --git a/examples/zolertia/zoul/rev-b/Makefile b/examples/zolertia/zoul/rev-b/Makefile index ddb6bda4b..882591218 100644 --- a/examples/zolertia/zoul/rev-b/Makefile +++ b/examples/zolertia/zoul/rev-b/Makefile @@ -4,9 +4,6 @@ CONTIKI_PROJECT = test-power-mgmt BOARD ?= remote-revb -# Works in Linux and probably on OSX too (RTCC example) -CFLAGS = -DDATE="\"`date +"%02u %02d %02m %02y %02H %02M %02S"`\"" - all: $(CONTIKI_PROJECT) CONTIKI = ../../../.. diff --git a/examples/zolertia/zoul/rev-b/project-conf.h b/examples/zolertia/zoul/rev-b/project-conf.h index 39e389032..e1082168d 100644 --- a/examples/zolertia/zoul/rev-b/project-conf.h +++ b/examples/zolertia/zoul/rev-b/project-conf.h @@ -46,6 +46,9 @@ #define BROADCAST_CHANNEL 129 #define NETSTACK_CONF_RDC nullrdc_driver +#define RTC_CONF_INIT 1 +#define RTC_CONF_SET_FROM_SYS 1 + #endif /* PROJECT_CONF_H_ */ /** diff --git a/examples/zolertia/zoul/rev-b/test-power-mgmt.c b/examples/zolertia/zoul/rev-b/test-power-mgmt.c index fb83c1e6f..0bb364aba 100644 --- a/examples/zolertia/zoul/rev-b/test-power-mgmt.c +++ b/examples/zolertia/zoul/rev-b/test-power-mgmt.c @@ -59,10 +59,6 @@ static struct etimer et; /* RE-Mote revision B, low-power PIC version */ #define PM_EXPECTED_VERSION 0x20 /*---------------------------------------------------------------------------*/ -#ifndef DATE -#define DATE "Unknown" -#endif -/*---------------------------------------------------------------------------*/ #define TEST_LEDS_FAIL leds_off(LEDS_ALL); \ leds_on(LEDS_RED); \ PROCESS_EXIT(); @@ -80,7 +76,6 @@ PROCESS_THREAD(test_remote_pm, ev, data) static uint8_t aux; static uint16_t voltage; static uint32_t cycles; - static char *next; PROCESS_BEGIN(); @@ -162,38 +157,13 @@ PROCESS_THREAD(test_remote_pm, ev, data) /* Configure the RTCC to schedule a "hard" restart of the shutdown mode, * waking up from a RTCC interrupt to the low-power PIC */ - printf("PM: System date: %s\n", DATE); - if(strcmp("Unknown", DATE) == 0) { - printf("PM: could not retrieve date from system\n"); + printf("PM\n"); + + if(rtcc_get_time_date(simple_td) == AB08_ERROR) { + printf("PM: Couldn't read time and date\n"); TEST_LEDS_FAIL; } - /* Configure RTC and return structure with all parameters */ - rtcc_init(); - - /* Configure the RTC with the current values */ - simple_td->weekdays = (uint8_t)strtol(DATE, &next, 10); - simple_td->day = (uint8_t)strtol(next, &next, 10); - simple_td->months = (uint8_t)strtol(next, &next, 10); - simple_td->years = (uint8_t)strtol(next, &next, 10); - simple_td->hours = (uint8_t)strtol(next, &next, 10); - simple_td->minutes = (uint8_t)strtol(next, &next, 10); - simple_td->seconds = (uint8_t)strtol(next, NULL, 10); - - simple_td->miliseconds = 0; - simple_td->mode = RTCC_24H_MODE; - simple_td->century = RTCC_CENTURY_20XX; - - if(rtcc_set_time_date(simple_td) == AB08_ERROR) { - printf("PM: Time and date configuration failed\n"); - TEST_LEDS_FAIL; - } else { - if(rtcc_get_time_date(simple_td) == AB08_ERROR) { - printf("PM: Couldn't read time and date\n"); - TEST_LEDS_FAIL; - } - } - printf("PM: Configured time: "); rtcc_print(RTCC_PRINT_DATE_DEC); diff --git a/examples/zolertia/zoul/rtcc/Makefile b/examples/zolertia/zoul/rtcc/Makefile index 25dee77cb..91b0aecf1 100644 --- a/examples/zolertia/zoul/rtcc/Makefile +++ b/examples/zolertia/zoul/rtcc/Makefile @@ -3,9 +3,6 @@ CONTIKI_PROJECT = test-rtcc TARGET = zoul -# Works in Linux and probably on OSX too (RTCC example) -CFLAGS = -DDATE="\"`date +"%02u %02d %02m %02y %02H %02M %02S"`\"" - all: $(CONTIKI_PROJECT) CONTIKI = ../../../.. diff --git a/examples/zolertia/zoul/rtcc/project-conf.h b/examples/zolertia/zoul/rtcc/project-conf.h index 66bf67bc0..897cd7b8b 100644 --- a/examples/zolertia/zoul/rtcc/project-conf.h +++ b/examples/zolertia/zoul/rtcc/project-conf.h @@ -47,6 +47,9 @@ #define NETSTACK_CONF_RDC nullrdc_driver +#define RTC_CONF_INIT 1 +#define RTC_CONF_SET_FROM_SYS 1 + #endif /* PROJECT_CONF_H_ */ /*---------------------------------------------------------------------------*/ /** diff --git a/examples/zolertia/zoul/rtcc/test-rtcc.c b/examples/zolertia/zoul/rtcc/test-rtcc.c index b2c7ce937..36ca2b324 100644 --- a/examples/zolertia/zoul/rtcc/test-rtcc.c +++ b/examples/zolertia/zoul/rtcc/test-rtcc.c @@ -55,10 +55,6 @@ #include #include /*---------------------------------------------------------------------------*/ -#ifndef DATE -#define DATE "Unknown" -#endif -/*---------------------------------------------------------------------------*/ #define LOOP_PERIOD 60L #define LOOP_INTERVAL (CLOCK_SECOND * LOOP_PERIOD) #define TEST_ALARM_SECOND 15 @@ -109,58 +105,13 @@ rtcc_interrupt_callback(uint8_t value) /*---------------------------------------------------------------------------*/ PROCESS_THREAD(test_remote_rtcc_process, ev, data) { - static char *next; - PROCESS_BEGIN(); - /* Alternatively for test only, undefine DATE and define on your own as - * #define DATE "07 06 12 15 16 00 00" - * Also note that if you restart the node at a given time, it will use the - * already defined DATE, so if you want to update the device date/time you - * need to reflash the node - */ - - /* Get the system date in the following format: wd dd mm yy hh mm ss */ - printf("RE-Mote RTC test, system date: %s\n", DATE); - - /* Sanity check */ - if(strcmp("Unknown", DATE) == 0) { - printf("Fail: could not retrieve date from system\n"); - PROCESS_EXIT(); - } - - /* Configure RTC and return structure with all parameters */ - rtcc_init(); + printf("RE-Mote RTC test\n"); /* Map interrupt callback handler */ RTCC_REGISTER_INT1(rtcc_interrupt_callback); - /* Configure the RTC with the current values */ - simple_td->weekdays = (uint8_t)strtol(DATE, &next, 10); - simple_td->day = (uint8_t)strtol(next, &next, 10); - simple_td->months = (uint8_t)strtol(next, &next, 10); - simple_td->years = (uint8_t)strtol(next, &next, 10); - simple_td->hours = (uint8_t)strtol(next, &next, 10); - simple_td->minutes = (uint8_t)strtol(next, &next, 10); - simple_td->seconds = (uint8_t)strtol(next, NULL, 10); - - /* Don't care about the milliseconds... */ - simple_td->miliseconds = 0; - - /* This example relies on 24h mode */ - simple_td->mode = RTCC_24H_MODE; - - /* And to simplify the configuration, it relies it will be executed in the - * present century - */ - simple_td->century = RTCC_CENTURY_20XX; - - /* Set the time and date */ - if(rtcc_set_time_date(simple_td) == AB08_ERROR) { - printf("Fail: Time and date not configured\n"); - PROCESS_EXIT(); - } - /* Wait a bit */ etimer_set(&et, (CLOCK_SECOND * 2)); PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); diff --git a/platform/zoul/Makefile.zoul b/platform/zoul/Makefile.zoul index cff7f11cf..635ec8c13 100644 --- a/platform/zoul/Makefile.zoul +++ b/platform/zoul/Makefile.zoul @@ -18,6 +18,9 @@ endif PYTHON = python BSL_FLAGS += -e -w -v +# Works in Linux and probably on OSX too (RTCC example) +CFLAGS += -DDATE="\"`date +"%02u %02d %02m %02y %02H %02M %02S"`\"" + ### Configure the build for the board and pull in board-specific sources CONTIKI_TARGET_DIRS += . dev CONTIKI_TARGET_DIRS += . $(BOARD) diff --git a/platform/zoul/contiki-conf.h b/platform/zoul/contiki-conf.h index 2288e1bc9..2051dfc71 100644 --- a/platform/zoul/contiki-conf.h +++ b/platform/zoul/contiki-conf.h @@ -577,6 +577,27 @@ typedef uint32_t rtimer_clock_t; #endif /** @} */ /*---------------------------------------------------------------------------*/ +/** + * \name RTC + * + * @{ + */ +#ifdef PLATFORM_HAS_RTC + +#ifndef RTC_CONF_INIT +#define RTC_CONF_INIT 0 /**< Whether to initialize the RTC */ +#endif + +#ifndef RTC_CONF_SET_FROM_SYS +#define RTC_CONF_SET_FROM_SYS 0 /**< Whether to set the RTC from the build system */ +#endif + +#else +#undef RTC_CONF_INIT +#define RTC_CONF_INIT 0 +#endif +/** @} */ +/*---------------------------------------------------------------------------*/ #endif /* CONTIKI_CONF_H_ */ diff --git a/platform/zoul/contiki-main.c b/platform/zoul/contiki-main.c index c8aa8f347..9a56a3243 100644 --- a/platform/zoul/contiki-main.c +++ b/platform/zoul/contiki-main.c @@ -57,6 +57,7 @@ #include "dev/cc2538-rf.h" #include "dev/udma.h" #include "dev/crypto.h" +#include "dev/rtcc.h" #include "usb/usb-serial.h" #include "lib/random.h" #include "net/netstack.h" @@ -72,6 +73,7 @@ #include #include +#include #include /*---------------------------------------------------------------------------*/ #if STARTUP_CONF_VERBOSE @@ -109,6 +111,62 @@ fade(unsigned char l) } /*---------------------------------------------------------------------------*/ static void +rtc_init(void) +{ +#if RTC_CONF_INIT +#if RTC_CONF_SET_FROM_SYS + char *next; + simple_td_map td; +#endif + + /* Configure RTC and return structure with all parameters */ + rtcc_init(); + +#if RTC_CONF_SET_FROM_SYS +#ifndef DATE +#error Could not retrieve date from system +#endif + + /* Alternatively, for test only, undefine DATE and define it on your own as: + * #define DATE "07 06 12 15 16 00 00" + * Also note that if you restart the node at a given time, it will use the + * already defined DATE, so if you want to update the device date/time you + * need to reflash the node. + */ + + /* Get the system date in the following format: wd dd mm yy hh mm ss */ + PRINTF("Setting RTC from system date: %s\n", DATE); + + /* Configure the RTC with the current values */ + td.weekdays = (uint8_t)strtol(DATE, &next, 10); + td.day = (uint8_t)strtol(next, &next, 10); + td.months = (uint8_t)strtol(next, &next, 10); + td.years = (uint8_t)strtol(next, &next, 10); + td.hours = (uint8_t)strtol(next, &next, 10); + td.minutes = (uint8_t)strtol(next, &next, 10); + td.seconds = (uint8_t)strtol(next, NULL, 10); + + /* Don't care about the milliseconds... */ + td.miliseconds = 0; + + /* This example relies on 24h mode */ + td.mode = RTCC_24H_MODE; + + /* + * And to simplify the configuration, it relies on the fact that it will be + * executed in the present century + */ + td.century = RTCC_CENTURY_20XX; + + /* Set the time and date */ + if(rtcc_set_time_date(&td) == AB08_ERROR) { + PRINTF("Failed to set time and date\n"); + } +#endif +#endif +} +/*---------------------------------------------------------------------------*/ +static void set_rf_params(void) { uint16_t short_addr; @@ -204,6 +262,8 @@ main(void) crypto_disable(); #endif + rtc_init(); + netstack_init(); set_rf_params(); diff --git a/platform/zoul/remote-reva/board.h b/platform/zoul/remote-reva/board.h index 43842e38e..efb516c31 100644 --- a/platform/zoul/remote-reva/board.h +++ b/platform/zoul/remote-reva/board.h @@ -455,6 +455,7 @@ * requiring to put the PIC into deep-sleep and waking up at a certain time. * @{ */ +#define PLATFORM_HAS_RTC 1 #define RTC_SDA_PORT I2C_SDA_PORT #define RTC_SDA_PIN I2C_SDA_PIN #define RTC_SCL_PORT I2C_SCL_PORT diff --git a/platform/zoul/remote-revb/board.h b/platform/zoul/remote-revb/board.h index 89bb60c22..fb50f13dc 100644 --- a/platform/zoul/remote-revb/board.h +++ b/platform/zoul/remote-revb/board.h @@ -482,6 +482,7 @@ * * @{ */ +#define PLATFORM_HAS_RTC 1 #define RTC_SDA_PORT I2C_SDA_PORT #define RTC_SDA_PIN I2C_SDA_PIN #define RTC_SCL_PORT I2C_SCL_PORT