47 #include "dev/watchdog.h" 48 #include <AppHardwareApi.h> 49 #include <BbcAndPhyRegs.h> 51 #include "dev/uart0.h" 52 #include "dev/uart-driver.h" 62 #include "lib/random.h" 65 #include "rtimer-arch.h" 67 #if NETSTACK_CONF_WITH_IPV6 74 #if SENSOR_BOARD_DR1175 75 #include "light-sensor.h" 76 #include "ht-sensor.h" 77 SENSORS(&light_sensor, &ht_sensor);
78 #elif SENSOR_BOARD_DR1199 79 #include "button-sensor.h" 80 #include "pot-sensor.h" 83 #include "dev/button-sensor.h" 89 unsigned char node_mac[8];
93 extern uint32_t heap_location;
95 #ifdef EXPERIMENT_SETUP 96 #include "experiment-setup.h" 100 #define ENERGEST_TYPE_EXTRA_LPM ENERGEST_TYPE_LPM 102 extern int main(
void);
104 #if DCOSYNCH_CONF_ENABLED 105 static unsigned long last_dco_calibration_time;
107 static uint64_t sleep_start;
108 static uint32_t sleep_start_ticks;
112 #define LOG_MODULE "JN516x" 113 #define LOG_LEVEL LOG_LEVEL_MAIN 121 vMMAC_GetMacAddress(&psExtAddress.sExt);
122 node_mac[7] = psExtAddress.sExt.u32L;
123 node_mac[6] = psExtAddress.sExt.u32L >> (uint32_t)8;
124 node_mac[5] = psExtAddress.sExt.u32L >> (uint32_t)16;
125 node_mac[4] = psExtAddress.sExt.u32L >> (uint32_t)24;
126 node_mac[3] = psExtAddress.sExt.u32H;
127 node_mac[2] = psExtAddress.sExt.u32H >> (uint32_t)8;
128 node_mac[1] = psExtAddress.sExt.u32H >> (uint32_t)16;
129 node_mac[0] = psExtAddress.sExt.u32H >> (uint32_t)24;
136 memset(&addr, 0, LINKADDR_SIZE);
138 #if NETSTACK_CONF_WITH_IPV6 139 memcpy(addr.u8, node_mac,
sizeof(addr.u8));
142 for(i = 0; i < LINKADDR_SIZE; ++i) {
143 addr.u8[i] = node_mac[LINKADDR_SIZE - 1 - i];
155 vAHI_Init32KhzXtal();
158 return bAHI_Set32KhzClockMode(E_AHI_XTAL);
165 vAHI_SetStackOverflow(TRUE, ((uint32_t *)&heap_location)[0]);
170 vAHI_StartRandomNumberGenerator(E_AHI_RND_SINGLE_SHOT, E_AHI_INTS_DISABLED);
176 #if JN516X_EXTERNAL_CRYSTAL_OSCILLATOR 195 if(bAHI_WatchdogResetEvent()) {
196 LOG_INFO(
"Init: Watchdog timer has reset device!\r\n");
204 #ifndef UIP_FALLBACK_INTERFACE 209 #if TIMESYNCH_CONF_ENABLED 224 clock_time_t time_to_etimer;
225 rtimer_clock_t ticks_to_rtimer;
227 #if DCOSYNCH_CONF_ENABLED 232 if(
clock_seconds() - last_dco_calibration_time > DCOSYNCH_PERIOD) {
235 eAHI_AttemptCalibration();
237 vREG_PhyWrite(REG_PHY_IS, REG_PHY_INT_VCO_CAL_MASK);
244 uart_driver_flush(E_AHI_UART_0, TRUE, FALSE);
247 time_to_etimer = clock_arch_time_to_etimer();
248 ticks_to_rtimer = rtimer_arch_time_to_rtimer();
250 #if JN516X_SLEEP_ENABLED 252 rtimer_clock_t max_sleep_time = ticks_to_rtimer;
253 if(max_sleep_time >= JN516X_MIN_SLEEP_TIME) {
256 max_sleep_time = MIN(ticks_to_etimer, ticks_to_rtimer);
259 if(max_sleep_time >= JN516X_MIN_SLEEP_TIME) {
260 max_sleep_time -= JN516X_SLEEP_GUARD_TIME;
262 max_sleep_time = MIN(max_sleep_time, JN516X_MAX_SLEEP_TIME);
264 #if !RTIMER_USE_32KHZ 266 max_sleep_time = (uint64_t)max_sleep_time * JN516X_XOSC_SECOND /
RTIMER_SECOND;
268 vAHI_WakeTimerEnable(WAKEUP_TIMER, TRUE);
270 WAIT_FOR_EDGE(sleep_start);
271 sleep_start_ticks = u32AHI_TickTimerRead();
273 vAHI_WakeTimerStartLarge(WAKEUP_TIMER, max_sleep_time);
274 ENERGEST_SWITCH(ENERGEST_TYPE_CPU, ENERGEST_TYPE_EXTRA_LPM);
275 vAHI_Sleep(E_AHI_SLEEP_OSCON_RAMON);
280 clock_arch_schedule_interrupt(time_to_etimer, ticks_to_rtimer);
281 ENERGEST_SWITCH(ENERGEST_TYPE_CPU, ENERGEST_TYPE_LPM);
284 ENERGEST_SWITCH(ENERGEST_TYPE_LPM, ENERGEST_TYPE_CPU);
321 uint32_t sleep_ticks;
323 rtimer_clock_t sleep_ticks_rtimer;
325 clock_arch_calibrate();
328 NETSTACK_RADIO.init();
332 WAIT_FOR_EDGE(sleep_end);
333 sleep_ticks = (uint32_t)(sleep_start - sleep_end) + 1;
336 sleep_ticks_rtimer = sleep_ticks;
339 static uint32_t remainder;
340 uint64_t t = (uint64_t)sleep_ticks *
RTIMER_SECOND + remainder;
341 sleep_ticks_rtimer = (uint32_t)(t / JN516X_XOSC_SECOND);
342 remainder = t - sleep_ticks_rtimer * JN516X_XOSC_SECOND;
347 rtimer_arch_reinit(sleep_start_ticks, sleep_ticks_rtimer);
349 ENERGEST_SWITCH(ENERGEST_TYPE_EXTRA_LPM, ENERGEST_TYPE_CPU);
356 clock_arch_schedule_interrupt(clock_arch_time_to_etimer(), rtimer_arch_time_to_rtimer());
358 #if DCOSYNCH_CONF_ENABLED SENSORS & button_sensor
Exports global symbols for the sensor API.
static uip_ds6_addr_t * addr
Pointer to a nbr cache entry.
Header file for the energy estimation mechanism
void platform_main_loop()
The platform's main loop, if provided.
void platform_init_stage_two()
Stage 2 of platform driver initialisation.
void platform_idle()
The platform's idle/sleep function.
void leds_init(void)
Initialise the LED HAL.
Node-id (simple 16-bit identifiers) handling.
unsigned long clock_seconds(void)
Get the current value of the platform seconds.
void leds_on(unsigned char leds)
Turn on multiple LEDs.
#define LEDS_ALL
The OR mask representation of all device LEDs.
#define RTIMER_SECOND
Number of rtimer ticks for 1 second.
void leds_off(unsigned char leds)
Turn off multiple LEDs.
Header file for IPv6-related data structures.
linkaddr_t linkaddr_node_addr
The link-layer address of the node.
int serial_line_input_byte(unsigned char c)
Get one byte of input from the serial driver.
#define CLOCK_SECOND
A second, measured in system clock time.
void uart0_init(unsigned long ubr)
Initalize the RS232 port.
void watchdog_start(void)
Starts the WDT in watchdog mode if enabled by user configuration, maximum interval.
MICROMAC_RADIO driver header file
void platform_init_stage_three()
Final stage of platform driver initialisation.
void random_init(unsigned short seed)
Seed the cc2538 random number generator.
void watchdog_init(void)
Initialisation function for the WDT.
Generic serial I/O process header filer.
Include file for the Contiki low-layer network stack (NETSTACK)
void watchdog_periodic(void)
Writes the WDT clear sequence.
Header file for the logging system
Header file for the LED HAL.
void rtimer_init(void)
Initialize the real-time scheduler.
int process_run(void)
Run the system once - call poll handlers and process one event.
void clock_init(void)
Arch-specific implementation of clock_init for the cc2538.
void platform_init_stage_one(void)
Basic (Stage 1) platform driver initialisation.
void linkaddr_set_node_addr(linkaddr_t *t)
Set the address of the current node.
void watchdog_stop(void)
Stops the WDT such that it won't timeout and cause MCU reset.