mirror of
https://github.com/oliverschmidt/contiki.git
synced 2024-12-22 10:30:13 +00:00
zoul: remote: Factor out duplicate RTC init
Signed-off-by: Benoît Thébaudeau <benoit@wsystem.com>
This commit is contained in:
parent
2866ae0555
commit
12ea1bd492
@ -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 = ../../../..
|
||||
|
@ -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_ */
|
||||
|
||||
/**
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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 = ../../../..
|
||||
|
@ -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_ */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
|
@ -55,10 +55,6 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#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));
|
||||
|
@ -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)
|
||||
|
@ -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_ */
|
||||
|
||||
|
@ -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 <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#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();
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user