47 #include "dev/button-sensor.h"
48 #include "lib/random.h"
51 #include "lib/include/mc1322x.h"
66 #include "default_lowlevel.h"
67 #include "contiki-maca.h"
68 #include "contiki-uart.h"
72 #define PERIODICPRINTS 0
77 #define STACKMONITOR 600
84 void rtimercycle(
void) {rtimerflag=1;}
91 #define PRINTF(...) printf(__VA_ARGS__)
92 #define PRINT6ADDR(addr) PRINTF(" %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x ", ((u8_t *)addr)[0], ((u8_t *)addr)[1], ((u8_t *)addr)[2], ((u8_t *)addr)[3], ((u8_t *)addr)[4], ((u8_t *)addr)[5], ((u8_t *)addr)[6], ((u8_t *)addr)[7], ((u8_t *)addr)[8], ((u8_t *)addr)[9], ((u8_t *)addr)[10], ((u8_t *)addr)[11], ((u8_t *)addr)[12], ((u8_t *)addr)[13], ((u8_t *)addr)[14], ((u8_t *)addr)[15])
93 #define PRINTLLADDR(lladdr) PRINTF(" %02x:%02x:%02x:%02x:%02x:%02x ",(lladdr)->addr[0], (lladdr)->addr[1], (lladdr)->addr[2], (lladdr)->addr[3],(lladdr)->addr[4], (lladdr)->addr[5])
96 #define PRINT6ADDR(addr)
97 #define PRINTLLADDR(addr)
101 #define RIMEADDR_NVM 0x1E000
104 #ifndef RIMEADDR_NBYTES
105 #define RIMEADDR_NBYTES 8
110 #ifndef UIP_ROUTER_MODULE
111 #ifdef UIP_CONF_ROUTER_MODULE
112 #define UIP_ROUTER_MODULE UIP_CONF_ROUTER_MODULE
114 #define UIP_ROUTER_MODULE rimeroute
118 extern const struct uip_router UIP_ROUTER_MODULE;
122 #if DCOSYNCH_CONF_ENABLED
123 static struct timer mgt_timer;
133 #include "net/uip-fw-drv.h"
136 {
UIP_FW_NETIF(192,168,1,2, 255,255,255,255, slip_send)};
138 {
UIP_FW_NETIF(172,16,0,0, 255,255,0,0, uip_over_mesh_send)};
142 #define UIP_OVER_MESH_CHANNEL 8
144 static uint8_t is_gateway;
151 #define RF_CHANNEL 26
160 printf(
"%d.%d: making myself the IP network gateway.\n\n",
162 printf(
"IPv4 address of the gateway: %d.%d.%d.%d\n\n",
165 uip_over_mesh_make_announced_gateway();
172 print_processes(
struct process *
const processes[])
176 while(*processes !=
NULL) {
177 printf(
" '%s'", (*processes)->name);
184 SENSORS(&button_sensor);
202 uart_init(BRINC, BRMOD, SAMP);
208 set_channel(RF_CHANNEL - 11);
220 *CRM_RTC_TIMEOUT = 32768 * 10;
222 *CRM_RTC_TIMEOUT = cal_rtc_secs * 10;
227 cop_timeout_ms(WDT_TIMEOUT);
229 CRM->COP_CNTLbits.COP_EN = 1;
239 #if RIMEADDR_SIZE == 1
240 const rimeaddr_t addr_ff = { { 0xff } };
242 #if RIMEADDR_SIZE == 2
243 const rimeaddr_t addr_ff = { { 0xff, 0xff } };
245 #if RIMEADDR_SIZE == 8
246 const rimeaddr_t addr_ff = { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } };
251 void iab_to_eui64(rimeaddr_t *eui64, uint32_t oui, uint16_t iab, uint32_t ext) {
258 eui64->u8[3] = (iab >> 4) & 0xff;
259 eui64->u8[4] = (iab << 4) & 0xf0;
263 eui64->u8[4] |= (ext >> 24) & 0xf;
264 eui64->u8[5] = (ext >> 16) & 0xff;
265 eui64->u8[6] = (ext >> 8) & 0xff;
266 eui64->u8[7] = ext & 0xff;
269 void oui_to_eui64(rimeaddr_t *eui64, uint32_t oui, uint64_t ext) {
271 eui64->u8[0] = (oui >> 16) & 0xff;
272 eui64->u8[1] = (oui >> 8) & 0xff;
273 eui64->u8[2] = oui & 0xff;
276 eui64->u8[3] = (ext >> 32) & 0xff;
277 eui64->u8[4] = (ext >> 24) & 0xff;
278 eui64->u8[5] = (ext >> 16) & 0xff;
279 eui64->u8[6] = (ext >> 8) & 0xff;
280 eui64->u8[7] = ext & 0xff;
284 set_rimeaddr(rimeaddr_t *addr)
288 volatile uint8_t buf[RIMEADDR_NBYTES];
292 err = nvm_detect(gNvmInternalInterface_c, &type);
294 err = nvm_read(gNvmInternalInterface_c, type, (uint8_t *)buf, RIMEADDR_NVM, RIMEADDR_NBYTES);
298 for(i=0; i<RIMEADDR_CONF_SIZE; i++) {
299 addr->u8[i] = buf[i];
302 if (memcmp(addr, &addr_ff, RIMEADDR_CONF_SIZE)==0) {
307 PRINTF(
"address in flash blank, setting to defined IAB and extension.\n\r");
308 iab_to_eui64(&eui64, OUI, IAB, EXT_ID);
310 PRINTF(
"address in flash blank, setting to defined IAB with a random extension.\n\r");
311 iab_to_eui64(&eui64, OUI, IAB, *MACA_RANDOM);
317 PRINTF(
"address in flash blank, setting to defined OUI and extension.\n\r");
318 oui_to_eui64(&eui64, OUI, EXT_ID);
320 PRINTF(
"address in flash blank, setting to defined OUI with a random extension.\n\r");
321 oui_to_eui64(&eui64, OUI, ((*MACA_RANDOM << 32) | *MACA_RANDOM));
327 #ifdef FLASH_BLANK_ADDR
328 PRINTF(
"flashing blank address\n\r");
329 err = nvm_write(gNvmInternalInterface_c, type, &(eui64.u8), RIMEADDR_NVM, RIMEADDR_NBYTES);
332 PRINTF(
"loading rime address from flash.\n\r");
354 extern uint32_t __und_stack_top__, __sys_stack_top__;
355 uint32_t p=(uint32_t)&__und_stack_top__;
357 *(uint32_t *)p = 0x42424242;
359 }
while (p<(uint32_t)&__sys_stack_top__-100);
369 extern uint32_t __heap_start__, __heap_end__;
370 uint32_t p=(uint32_t)&__heap_end__-4;
372 *(uint32_t *)p = 0x42424242;
374 }
while (p>=(uint32_t)&__heap_start__);
385 GPIO->FUNC_SEL.GPIO_44 = 2;
386 GPIO->PAD_DIR.GPIO_44 = 1;
397 printf(
"Rime started with address ");
398 for(i = 0; i <
sizeof(addr.u8) - 1; i++) {
399 printf(
"%02X:", addr.u8[i]);
401 printf(
"%02X\n", addr.u8[i]);
414 NETSTACK_NETWORK.init();
416 printf(
"%s %s, channel check rate %lu Hz, radio channel %u\n",
417 NETSTACK_MAC.name, NETSTACK_RDC.name,
418 CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1:
419 NETSTACK_RDC.channel_check_interval()),
424 printf(
"Tentative link-local IPv6 address ");
427 for(a = 0; a < UIP_DS6_ADDR_NB; a++) {
428 if (uip_ds6_if.addr_list[a].isused) {
429 for(i = 0; i < 7; ++i) {
431 uip_ds6_if.addr_list[a].ipaddr.u8[i * 2],
432 uip_ds6_if.addr_list[a].ipaddr.u8[i * 2 + 1]);
435 uip_ds6_if.addr_list[a].ipaddr.u8[14],
436 uip_ds6_if.addr_list[a].ipaddr.u8[15]);
447 printf(
"Tentative global IPv6 address ");
448 for(i = 0; i < 7; ++i) {
450 ipaddr.u8[i * 2], ipaddr.u8[i * 2 + 1]);
453 ipaddr.u8[7 * 2], ipaddr.u8[7 * 2 + 1]);
461 NETSTACK_NETWORK.init();
463 printf(
"%s %s, channel check rate %lu Hz, radio channel %u\n",
464 NETSTACK_MAC.name, NETSTACK_RDC.name,
465 CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0? 1:
466 NETSTACK_RDC.channel_check_interval()),
470 *MACA_MACPANID = 0xcdab;
471 *MACA_MAC16ADDR = 0xffff;
483 PRINTF(
"setting panid 0x%04x\n\r", *MACA_MACPANID);
484 PRINTF(
"setting short mac 0x%04x\n\r", *MACA_MAC16ADDR);
485 PRINTF(
"setting long mac 0x%08x_%08x\n\r", *MACA_MAC64HI, *MACA_MAC64LO);
488 set_prm_mode(AUTOACK);
495 #if TIMESYNCH_CONF_ENABLED
505 slip_set_input_callback(set_gateway);
519 uip_over_mesh_set_net(&hostaddr, &netmask);
521 uip_over_mesh_set_gateway_netif(&slipif);
523 uip_over_mesh_init(UIP_OVER_MESH_CHANNEL);
524 printf(
"uIP started with IP address %d.%d.%d.%d\n",
531 print_processes(autostart_processes);
532 autostart_start(autostart_processes);
542 if(uart1_input_handler !=
NULL) {
543 if(uart1_can_get()) {
544 uart1_input_handler(uart1_getc());
560 if (clocktime!=clock_seconds()) {
561 clocktime=clock_seconds();
565 if ((clocktime%STAMPS)==0) {
570 extern volatile unsigned long radioontime;
571 printf(
"\r%u(%u)s ",clocktime,radioontime);
573 printf(
"%us\n",clocktime);
582 #if PINGS && UIP_CONF_IPV6
583 extern void raven_ping6(
void);
584 if ((clocktime%PINGS)==1) {
590 #if ROUTES && UIP_CONF_IPV6
591 if ((clocktime%ROUTES)==2) {
598 printf(
"\nAddresses [%u max]\n",UIP_DS6_ADDR_NB);
599 for (i=0;i<UIP_DS6_ADDR_NB;i++) {
600 if (uip_ds6_if.addr_list[i].isused) {
601 uip_debug_ipaddr_print(&uip_ds6_if.addr_list[i].ipaddr);
605 printf(
"\nNeighbors [%u max]\n",UIP_DS6_NBR_NB);
606 for(i = 0,j=1; i < UIP_DS6_NBR_NB; i++) {
607 if(uip_ds6_nbr_cache[i].isused) {
608 uip_debug_ipaddr_print(&uip_ds6_nbr_cache[i].
ipaddr);
613 if (j) printf(
" <none>");
614 printf(
"\nRoutes [%u max]\n",UIP_DS6_ROUTE_NB);
615 for(i = 0,j=1; i < UIP_DS6_ROUTE_NB; i++) {
616 if(uip_ds6_routing_table[i].isused) {
617 uip_debug_ipaddr_print(&uip_ds6_routing_table[i].
ipaddr);
618 printf(
"/%u (via ", uip_ds6_routing_table[i].length);
619 uip_debug_ipaddr_print(&uip_ds6_routing_table[i].nexthop);
621 printf(
") %lus\n", uip_ds6_routing_table[i].state.lifetime);
628 if (j) printf(
" <none>");
629 printf(
"\n---------\n");
634 if ((clocktime%STACKMONITOR)==3) {
635 extern uint32_t __und_stack_top__, __sys_stack_top__;
636 uint32_t p=(uint32_t)&__und_stack_top__;
638 if (*(uint32_t *)p != 0x42424242) {
639 printf(
"Never-Used stack > %d bytes\n",p-(uint32_t)&__und_stack_top__);
643 }
while (p<(uint32_t)&__sys_stack_top__-100);
647 if ((clocktime%HEAPMONITOR)==4) {
648 extern uint32_t __heap_start__, __heap_end__;
649 uint32_t p=(uint32_t)&__heap_end__-4;
651 if (*(uint32_t *)p != 0x42424242) {
655 }
while (p>=(uint32_t)&__heap_start__);
656 printf(
"Never-used heap >= %d bytes\n",(uint32_t)&__heap_end__-p-4);
660 printf(
"********Got pointer %x\n",ptr);
675 log_message(
char *m1,
char *m2)
677 printf(
"%s%s\n", m1, m2);