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"
51 #include "net/ipv6/uip-ds6.h"
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;
80 #include "net/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
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;
126 force_inclusion(
int d1,
int d2)
128 snprintf(
NULL, 0,
"%d", d1 % d2);
138 memset(&addr, 0,
sizeof(linkaddr_t));
140 memcpy(addr.u8, node_mac,
sizeof(addr.u8));
143 for(i = 0; i <
sizeof(linkaddr_t); ++i) {
144 addr.u8[i] = node_mac[7 - i];
147 addr.u8[0] = node_id & 0xff;
148 addr.u8[1] = node_id >> 8;
152 printf(
"Rime started with address ");
153 for(i = 0; i <
sizeof(addr.u8) - 1; i++) {
154 printf(
"%d.", addr.u8[i]);
156 printf(
"%d\n", addr.u8[i]);
160 print_processes(
struct process *
const processes[])
164 while(*processes !=
NULL) {
165 printf(
" '%s'", (*processes)->name);
177 printf(
"%d.%d: making myself the IP network gateway.\n\n",
179 printf(
"IPv4 address of the gateway: %d.%d.%d.%d\n\n",
182 uip_over_mesh_make_announced_gateway();
189 main(
int argc,
char **argv)
201 uart0_init(BAUD2UBR(115200));
217 if(!(node_mac[0] | node_mac[1] | node_mac[2] | node_mac[3] |
218 node_mac[4] | node_mac[5] | node_mac[6] | node_mac[7])) {
228 node_mac[6] = node_id >> 8;
229 node_mac[7] = node_id & 0xff;
234 #warning "***** CHANGING DEFAULT MAC *****"
244 node_mac[6] = MACID >> 8;
245 node_mac[7] = MACID & 0xff;
248 #ifdef IEEE_802154_MAC_ADDRESS
251 uint8_t ieee[] = IEEE_802154_MAC_ADDRESS;
252 memcpy(node_mac, ieee,
sizeof(
uip_lladdr.addr));
253 node_mac[7] = node_id & 0xff;
278 memset(longaddr, 0,
sizeof(longaddr));
280 printf(
"MAC %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
281 longaddr[0], longaddr[1], longaddr[2], longaddr[3],
282 longaddr[4], longaddr[5], longaddr[6], longaddr[7]);
284 cc2420_set_pan_addr(IEEE802154_PANID, shortaddr, longaddr);
289 PRINTF(CONTIKI_VERSION_STRING
" started. ");
292 PRINTF(
"Node id is set to %u.\n", node_id);
294 PRINTF(
"Node id is not set.\n");
309 NETSTACK_NETWORK.init();
311 printf(
"%s %s, channel check rate %lu Hz, radio channel %u\n",
312 NETSTACK_MAC.name, NETSTACK_RDC.name,
313 CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1:
314 NETSTACK_RDC.channel_check_interval()),
315 CC2420_CONF_CHANNEL);
319 printf(
"Tentative link-local IPv6 address ");
323 lladdr = uip_ds6_get_link_local(-1);
324 for(i = 0; i < 7; ++i) {
325 printf(
"%02x%02x:", lladdr->ipaddr.u8[i * 2],
326 lladdr->ipaddr.u8[i * 2 + 1]);
328 printf(
"%02x%02x\n", lladdr->ipaddr.u8[14], lladdr->ipaddr.u8[15]);
331 if(!UIP_CONF_IPV6_RPL) {
336 uip_ds6_addr_add(&ipaddr, 0, ADDR_TENTATIVE);
337 printf(
"Tentative global IPv6 address ");
338 for(i = 0; i < 7; ++i) {
340 ipaddr.u8[i * 2], ipaddr.u8[i * 2 + 1]);
343 ipaddr.u8[7 * 2], ipaddr.u8[7 * 2 + 1]);
350 NETSTACK_NETWORK.init();
352 printf(
"%s %s, channel check rate %lu Hz, radio channel %u\n",
353 NETSTACK_MAC.name, NETSTACK_RDC.name,
354 CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0? 1:
355 NETSTACK_RDC.channel_check_interval()),
356 CC2420_CONF_CHANNEL);
359 #if !WITH_UIP && !WITH_UIP6
360 uart0_set_input(serial_line_input_byte);
366 #if TIMESYNCH_CONF_ENABLED
376 slip_set_input_callback(set_gateway);
379 uip_ipaddr_t hostaddr,
netmask;
390 uip_over_mesh_set_net(&hostaddr, &netmask);
392 uip_over_mesh_set_gateway_netif(&slipif);
394 uip_over_mesh_init(UIP_OVER_MESH_CHANNEL);
395 printf(
"uIP started with IP address %d.%d.%d.%d\n",
401 ENERGEST_ON(ENERGEST_TYPE_CPU);
403 print_processes(autostart_processes);
404 autostart_start(autostart_processes);
409 #if DCOSYNCH_CONF_ENABLED
430 static unsigned long irq_energest = 0;
432 #if DCOSYNCH_CONF_ENABLED
441 ENERGEST_OFF(ENERGEST_TYPE_CPU);
442 ENERGEST_ON(ENERGEST_TYPE_LPM);
446 energest_type_set(ENERGEST_TYPE_IRQ, irq_energest);
448 _BIS_SR(GIE | SCG0 | SCG1 | CPUOFF);
458 irq_energest = energest_type_time(ENERGEST_TYPE_IRQ);
461 ENERGEST_OFF(ENERGEST_TYPE_LPM);
462 ENERGEST_ON(ENERGEST_TYPE_CPU);
471 log_message(
char *m1,
char *m2)
473 printf(
"%s%s\n", m1, m2);