40 #include "dev/uart0.h"
41 #include "dev/watchdog.h"
43 #include "lib/random.h"
46 #include "dev/button-sensor.h"
47 #include "dev/adxl345.h"
48 #include "sys/clock.h"
50 #include "dev/reset-sensor.h"
51 #if NETSTACK_CONF_WITH_IPV6
57 #include "sys/node-id.h"
62 #include "dev/battery-sensor.h"
63 #include "dev/button-sensor.h"
64 #include "dev/sht11/sht11-sensor.h"
68 extern unsigned char node_mac[8];
70 #if DCOSYNCH_CONF_ENABLED
71 static struct timer mgt_timer;
74 #ifndef NETSTACK_CONF_WITH_IPV4
75 #define NETSTACK_CONF_WITH_IPV4 0
78 #if NETSTACK_CONF_WITH_IPV4
81 #include "net/uip-fw-drv.h"
86 {
UIP_FW_NETIF(172, 16, 0, 0, 255, 255, 0, 0, uip_over_mesh_send) };
90 #define UIP_OVER_MESH_CHANNEL 8
91 #if NETSTACK_CONF_WITH_IPV4
92 static uint8_t is_gateway;
95 #ifdef EXPERIMENT_SETUP
96 #include "experiment-setup.h"
102 #define PRINTF(...) printf(__VA_ARGS__)
107 void init_platform(
void);
112 force_float_inclusion()
114 extern int __fixsfsi;
115 extern int __floatsisf;
119 return __fixsfsi + __floatsisf + __mulsf3 + __subsf3;
131 force_inclusion(
int d1,
int d2)
133 snprintf(
NULL, 0,
"%d", d1 % d2);
143 memset(&addr, 0,
sizeof(linkaddr_t));
144 #if NETSTACK_CONF_WITH_IPV6
145 memcpy(addr.u8, node_mac,
sizeof(addr.u8));
148 for(i = 0; i <
sizeof(linkaddr_t); ++i) {
149 addr.u8[i] = node_mac[7 - i];
152 addr.u8[0] = node_id & 0xff;
153 addr.u8[1] = node_id >> 8;
165 print_processes(
struct process *
const processes[])
169 while(*processes !=
NULL) {
176 #if NETSTACK_CONF_WITH_IPV4
182 printf(
"%d.%d: making myself the IP network gateway.\n\n",
184 printf(
"IPv4 address of the gateway: %d.%d.%d.%d\n\n",
187 uip_over_mesh_make_announced_gateway();
194 main(
int argc,
char **argv)
207 #if NETSTACK_CONF_WITH_IPV4
222 if(!(node_mac[0] | node_mac[1] | node_mac[2] | node_mac[3] |
223 node_mac[4] | node_mac[5] | node_mac[6] | node_mac[7])) {
227 PRINTF(
"Node id is not set, using Z1 product ID\n");
240 node_mac[6] = node_id >> 8;
241 node_mac[7] = node_id & 0xff;
246 #warning "***** CHANGING DEFAULT MAC *****"
256 node_mac[6] = MACID >> 8;
257 node_mac[7] = MACID & 0xff;
260 #ifdef IEEE_802154_MAC_ADDRESS
263 uint8_t ieee[] = IEEE_802154_MAC_ADDRESS;
264 memcpy(node_mac, ieee,
sizeof(
uip_lladdr.addr));
265 node_mac[7] = node_id & 0xff;
282 #ifndef FESHIE_NO_ACC
284 #endif // FESHIE_NO_ACC
291 memset(longaddr, 0,
sizeof(longaddr));
297 cc2420_set_pan_addr(IEEE802154_PANID, shortaddr, longaddr);
303 PRINTF(
"Ref ID: %u\n", SERIALNUM);
305 PRINTF(CONTIKI_VERSION_STRING
" started. ");
308 PRINTF(
"Node id is set to %u.\n", node_id);
310 PRINTF(
"Node id not set\n");
313 #if NETSTACK_CONF_WITH_IPV6
324 NETSTACK_NETWORK.init();
335 printf(
"Tentative link-local IPv6 address ");
339 lladdr = uip_ds6_get_link_local(-1);
340 for(i = 0; i < 7; ++i) {
341 printf(
"%02x%02x:", lladdr->ipaddr.u8[i * 2],
342 lladdr->ipaddr.u8[i * 2 + 1]);
344 printf(
"%02x%02x\n", lladdr->ipaddr.u8[14], lladdr->ipaddr.u8[15]);
347 if(!UIP_CONF_IPV6_RPL) {
353 printf(
"Tentative global IPv6 address ");
354 for(i = 0; i < 7; ++i) {
356 ipaddr.u8[i * 2], ipaddr.u8[i * 2 + 1]);
359 ipaddr.u8[7 * 2], ipaddr.u8[7 * 2 + 1]);
366 NETSTACK_NETWORK.init();
368 printf(
"%s %s, channel check rate %lu Hz, radio channel %u\n",
369 NETSTACK_MAC.name, NETSTACK_RDC.name,
370 CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1 :
371 NETSTACK_RDC.channel_check_interval()),
372 CC2420_CONF_CHANNEL);
375 #if !NETSTACK_CONF_WITH_IPV4 && !NETSTACK_CONF_WITH_IPV6
380 leds_off(LEDS_GREEN);
382 #if TIMESYNCH_CONF_ENABLED
387 #if NETSTACK_CONF_WITH_IPV4
395 uip_ipaddr_t hostaddr,
netmask;
406 uip_over_mesh_set_net(&hostaddr, &netmask);
408 uip_over_mesh_set_gateway_netif(&slipif);
410 uip_over_mesh_init(UIP_OVER_MESH_CHANNEL);
411 printf(
"uIP started with IP address %d.%d.%d.%d\n",
417 ENERGEST_ON(ENERGEST_TYPE_CPU);
420 reset_sensor.configure(SENSORS_ACTIVE,1);
421 printf(
"Reset Count %d \n",reset_sensor.value(0));
423 print_processes(autostart_processes);
424 autostart_start(autostart_processes);
429 #if DCOSYNCH_CONF_ENABLED
450 static unsigned long irq_energest = 0;
452 #if DCOSYNCH_CONF_ENABLED
461 ENERGEST_OFF(ENERGEST_TYPE_CPU);
462 ENERGEST_ON(ENERGEST_TYPE_LPM);
466 energest_type_set(ENERGEST_TYPE_IRQ, irq_energest);
468 _BIS_SR(GIE | SCG0 | SCG1 | CPUOFF);
478 irq_energest = energest_type_time(ENERGEST_TYPE_IRQ);
481 ENERGEST_OFF(ENERGEST_TYPE_LPM);
482 ENERGEST_ON(ENERGEST_TYPE_CPU);
498 log_message(
char *m1,
char *m2)
500 printf(
"%s%s\n", m1, m2);
void uip_log(char *msg)
Print out a uIP log message.
#define uip_sethostaddr(addr)
Set the IP address of this host.
static uip_ipaddr_t ipaddr
Pointer to prefix information option in uip_buf.
void uart0_init(unsigned long ubr)
Initalize the RS232 port.
void timer_reset(struct timer *t)
Reset the timer with the same interval.
#define uip_ipaddr(addr, addr0, addr1, addr2, addr3)
Construct an IP address from four bytes.
void timesynch_set_authority_level(int level)
Set the authority level of the current time.
static uip_ds6_addr_t * addr
Pointer to a router list entry.
uint8_t slip_send(void)
Send an IP packet from the uIP buffer with SLIP.
Header file for IPv6-related data structures.
void timer_set(struct timer *t, clock_time_t interval)
Set a timer.
uip_ipaddr_t ipaddr
The IP address of this interface.
void watchdog_stop(void)
Stops the WDT such that it won't timeout and cause MCU reset.
Header file for tunnelling uIP over Rime mesh
void clock_init(void)
Initialize the clock library.
#define uip_ipaddr_copy(dest, src)
Copy an IP address from one place to another.
int process_run(void)
Run the system once - call poll handlers and process one event.
Unicast address structure.
void slip_arch_init(unsigned long ubr)
Initalize the RS232 port and the SLIP driver.
void slip_set_input_callback(void(*c)(void))
Set a function to be called when there is activity on the SLIP interface; used for detecting if a nod...
SENSORS & button_sensor
Copyright (c) 2014, Analog Devices, Inc.
uip_ipaddr_t netmask
The netmask of the interface.
Header file for the Rime stack
#define uip_setnetmask(addr)
Set the netmask.
#define NULL
The null pointer.
#define uip_ipaddr_to_quad(a)
Convert an IP address to four bytes separated by commas.
Coffee architecture-dependent header for the Zolertia Z1 platform.
802.15.4 frame creation and parsing functions
uIP packet forwarding header file.
void linkaddr_set_node_addr(linkaddr_t *t)
Set the address of the current node.
#define UIP_FW_NETIF(ip1, ip2, ip3, ip4, nm1, nm2, nm3, nm4, outputfunc)
Instantiating macro for a uIP network interface.
void watchdog_periodic(void)
Writes the WDT clear sequence.
#define ADDR_TENTATIVE
Possible states for the an address (RFC 4862)
#define CLOCK_SECOND
A second, measured in system clock time.
#define uip_ip6addr(addr, addr0, addr1, addr2, addr3, addr4, addr5, addr6, addr7)
Construct an IPv6 address from eight 16-bit words.
Header file for the uIP TCP/IP stack.
void clock_delay(unsigned int delay)
Obsolete delay function but we implement it here since some code still uses it.
void process_start(struct process *p, process_data_t data)
Start a process.
Header for the Coffee file system.
uip_ds6_addr_t * uip_ds6_addr_add(uip_ipaddr_t *ipaddr, unsigned long vlifetime, uint8_t type)
Add a unicast address to the interface.
Header file for module for automatically starting and exiting a list of processes.
void clock_wait(clock_time_t t)
Wait for a given number of ticks.
void timesynch_init(void)
Initialize the timesynch module.
void rtimer_init(void)
Initialize the real-time scheduler.
Generic serial I/O process header filer.
CCIF uip_lladdr_t uip_lladdr
Host L2 address.
void uip_init(void)
uIP initialization function.
int process_nevents(void)
Number of events waiting to be processed.
void process_init(void)
Initialize the process module.
void ctimer_init(void)
Initialize the callback timer library.
void linkaddr_copy(linkaddr_t *dest, const linkaddr_t *src)
Copy a Rime address.
linkaddr_t linkaddr_node_addr
The Rime address of the node.
int serial_line_input_byte(unsigned char c)
Get one byte of input from the serial driver.
void watchdog_start(void)
Starts the WDT in watchdog mode if enabled by user configuration, maximum interval.
void clock_delay_usec(uint16_t usec)
Delay a given number of microseconds.
Include file for the Contiki low-layer network stack (NETSTACK)
void uip_ds6_set_addr_iid(uip_ipaddr_t *ipaddr, uip_lladdr_t *lladdr)
set the last 64 bits of an IP address based on the MAC address
void uip_fw_default(struct uip_fw_netif *netif)
Register a default network interface.
int timer_expired(struct timer *t)
Check if a timer has expired.
Representation of a uIP network interface.