47#include "dev/watchdog.h"
48#include <AppHardwareApi.h>
49#include <BbcAndPhyRegs.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"
77SENSORS(&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"
89unsigned char node_mac[8];
93extern uint32_t heap_location;
95#ifdef EXPERIMENT_SETUP
96#include "experiment-setup.h"
100#define ENERGEST_TYPE_EXTRA_LPM ENERGEST_TYPE_LPM
102extern int main(
void);
104#if DCOSYNCH_CONF_ENABLED
105static unsigned long last_dco_calibration_time;
107static uint64_t sleep_start;
108static 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);
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
Header file for the energy estimation mechanism.
unsigned long clock_seconds(void)
Get the current value of the platform seconds.
void clock_init(void)
Arch-specific implementation of clock_init for the cc2538.
void random_init(unsigned short seed)
Seed the cc2538 random number generator.
void watchdog_start(void)
Starts the WDT in watchdog mode if enabled by user configuration, maximum interval.
void watchdog_periodic(void)
Writes the WDT clear sequence.
void watchdog_init(void)
Initialisation function for the WDT.
void platform_init_stage_three()
Final stage of platform driver initialisation.
void platform_init_stage_one(void)
Basic (Stage 1) platform driver initialisation.
void platform_idle()
The platform's idle/sleep function.
void platform_init_stage_two()
Stage 2 of platform driver initialisation.
void watchdog_stop(void)
Stops the WDT such that it won't timeout and cause MCU reset.
#define CLOCK_SECOND
A second, measured in system clock time.
#define LEDS_ALL
The OR mask representation of all device LEDs.
void leds_init(void)
Initialise the LED HAL.
void leds_on(unsigned char leds)
Turn on multiple LEDs.
void leds_off(unsigned char leds)
Turn off multiple LEDs.
linkaddr_t linkaddr_node_addr
The link-layer address of the node.
void linkaddr_set_node_addr(linkaddr_t *t)
Set the address of the current node.
void platform_main_loop()
The platform's main loop, if provided.
void uart0_init(unsigned long ubr)
Initalize the RS232 port.
int process_run(void)
Run the system once - call poll handlers and process one event.
void rtimer_init(void)
Initialize the real-time scheduler.
#define RTIMER_SECOND
Number of rtimer ticks for 1 second.
Header file for the LED HAL.
Header file for the logging system.
MICROMAC_RADIO driver header file.
Include file for the Contiki low-layer network stack (NETSTACK)
Node-id (simple 16-bit identifiers) handling.
Generic serial I/O process header filer.
int serial_line_input_byte(unsigned char c)
Get one byte of input from the serial driver.
Header file for IPv6-related data structures.
static uip_ds6_addr_t * addr
Pointer to a nbr cache entry.
SENSORS & button_sensor
Exports global symbols for the sensor API.