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 #if NETSTACK_CONF_WITH_IPV6
56 #include "sys/node-id.h"
61 #include "dev/battery-sensor.h"
62 #include "dev/button-sensor.h"
63 #include "dev/sht11/sht11-sensor.h"
67 extern unsigned char node_mac[8];
69 #if DCOSYNCH_CONF_ENABLED
70 static struct timer mgt_timer;
73 #ifndef NETSTACK_CONF_WITH_IPV4
74 #define NETSTACK_CONF_WITH_IPV4 0
77 #if NETSTACK_CONF_WITH_IPV4
80 #include "net/ipv4/uip-fw-drv.h"
85 {
UIP_FW_NETIF(172, 16, 0, 0, 255, 255, 0, 0, uip_over_mesh_send) };
89 #define UIP_OVER_MESH_CHANNEL 8
90 #if NETSTACK_CONF_WITH_IPV4
91 static uint8_t is_gateway;
94 #ifdef EXPERIMENT_SETUP
95 #include "experiment-setup.h"
101 #define PRINTF(...) printf(__VA_ARGS__)
106 void init_platform(
void);
111 force_float_inclusion()
113 extern int __fixsfsi;
114 extern int __floatsisf;
118 return __fixsfsi + __floatsisf + __mulsf3 + __subsf3;
130 force_inclusion(
int d1,
int d2)
132 snprintf(
NULL, 0,
"%d", d1 % d2);
142 memset(&addr, 0,
sizeof(linkaddr_t));
143 #if NETSTACK_CONF_WITH_IPV6
144 memcpy(addr.u8, node_mac,
sizeof(addr.u8));
147 for(i = 0; i <
sizeof(linkaddr_t); ++i) {
148 addr.u8[i] = node_mac[7 - i];
151 addr.u8[0] = node_id & 0xff;
152 addr.u8[1] = node_id >> 8;
156 printf(
"Rime started with address ");
157 for(i = 0; i <
sizeof(addr.u8) - 1; i++) {
158 printf(
"%d.", addr.u8[i]);
160 printf(
"%d\n", addr.u8[i]);
164 print_processes(
struct process *
const processes[])
168 while(*processes !=
NULL) {
169 printf(
" '%s'", (*processes)->name);
175 #if NETSTACK_CONF_WITH_IPV4
181 printf(
"%d.%d: making myself the IP network gateway.\n\n",
183 printf(
"IPv4 address of the gateway: %d.%d.%d.%d\n\n",
186 uip_over_mesh_make_announced_gateway();
193 main(
int argc,
char **argv)
206 #if NETSTACK_CONF_WITH_IPV4
221 if(!(node_mac[0] | node_mac[1] | node_mac[2] | node_mac[3] |
222 node_mac[4] | node_mac[5] | node_mac[6] | node_mac[7])) {
226 PRINTF(
"Node id is not set, using Z1 product ID\n");
239 node_mac[6] = node_id >> 8;
240 node_mac[7] = node_id & 0xff;
245 #warning "***** CHANGING DEFAULT MAC *****"
255 node_mac[6] = MACID >> 8;
256 node_mac[7] = MACID & 0xff;
259 #ifdef IEEE_802154_MAC_ADDRESS
262 uint8_t ieee[] = IEEE_802154_MAC_ADDRESS;
263 memcpy(node_mac, ieee,
sizeof(
uip_lladdr.addr));
264 node_mac[7] = node_id & 0xff;
290 memset(longaddr, 0,
sizeof(longaddr));
292 printf(
"MAC %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
293 longaddr[0], longaddr[1], longaddr[2], longaddr[3],
294 longaddr[4], longaddr[5], longaddr[6], longaddr[7]);
296 cc2420_set_pan_addr(IEEE802154_PANID, shortaddr, longaddr);
302 PRINTF(
"Ref ID: %u\n", SERIALNUM);
304 PRINTF(CONTIKI_VERSION_STRING
" started. ");
307 PRINTF(
"Node id is set to %u.\n", node_id);
309 PRINTF(
"Node id not set\n");
312 #if NETSTACK_CONF_WITH_IPV6
323 NETSTACK_NETWORK.init();
325 printf(
"%s %s, channel check rate %lu Hz, radio channel %u\n",
326 NETSTACK_MAC.name, NETSTACK_RDC.name,
327 CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1 :
328 NETSTACK_RDC.channel_check_interval()),
329 CC2420_CONF_CHANNEL);
333 printf(
"Tentative link-local IPv6 address ");
337 lladdr = uip_ds6_get_link_local(-1);
338 for(i = 0; i < 7; ++i) {
339 printf(
"%02x%02x:", lladdr->ipaddr.u8[i * 2],
340 lladdr->ipaddr.u8[i * 2 + 1]);
342 printf(
"%02x%02x\n", lladdr->ipaddr.u8[14], lladdr->ipaddr.u8[15]);
345 if(!UIP_CONF_IPV6_RPL) {
348 uip_ip6addr(&ipaddr, UIP_DS6_DEFAULT_PREFIX, 0, 0, 0, 0, 0, 0, 0);
351 printf(
"Tentative global IPv6 address ");
352 for(i = 0; i < 7; ++i) {
354 ipaddr.u8[i * 2], ipaddr.u8[i * 2 + 1]);
357 ipaddr.u8[7 * 2], ipaddr.u8[7 * 2 + 1]);
364 NETSTACK_NETWORK.init();
366 printf(
"%s %s, channel check rate %lu Hz, radio channel %u\n",
367 NETSTACK_MAC.name, NETSTACK_RDC.name,
368 CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1 :
369 NETSTACK_RDC.channel_check_interval()),
370 CC2420_CONF_CHANNEL);
373 #if !NETSTACK_CONF_WITH_IPV4 && !NETSTACK_CONF_WITH_IPV6
378 leds_off(LEDS_GREEN);
380 #if TIMESYNCH_CONF_ENABLED
385 #if NETSTACK_CONF_WITH_IPV4
393 uip_ipaddr_t hostaddr,
netmask;
404 uip_over_mesh_set_net(&hostaddr, &netmask);
406 uip_over_mesh_set_gateway_netif(&slipif);
408 uip_over_mesh_init(UIP_OVER_MESH_CHANNEL);
409 printf(
"uIP started with IP address %d.%d.%d.%d\n",
415 ENERGEST_ON(ENERGEST_TYPE_CPU);
417 print_processes(autostart_processes);
418 autostart_start(autostart_processes);
423 #if DCOSYNCH_CONF_ENABLED
444 static unsigned long irq_energest = 0;
446 #if DCOSYNCH_CONF_ENABLED
455 ENERGEST_SWITCH(ENERGEST_TYPE_CPU, ENERGEST_TYPE_LPM);
459 energest_type_set(ENERGEST_TYPE_IRQ, irq_energest);
461 _BIS_SR(GIE | SCG0 | SCG1 | CPUOFF);
471 irq_energest = energest_type_time(ENERGEST_TYPE_IRQ);
474 ENERGEST_SWITCH(ENERGEST_TYPE_LPM, ENERGEST_TYPE_CPU);
483 log_message(
char *m1,
char *m2)
485 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 random_init(unsigned short seed)
Seed the cc2538 random number generator.
Coffee architecture-dependent header for the Zolertia Z1 platform.
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.
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 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.
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.