47 #include "dev/button-sensor.h"
48 #include "lib/random.h"
65 #include "default_lowlevel.h"
66 #include "contiki-maca.h"
67 #include "contiki-uart.h"
72 #define PRINTF(...) printf(__VA_ARGS__)
73 #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])
74 #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])
77 #define PRINT6ADDR(addr)
78 #define PRINTLLADDR(addr)
82 #define RIMEADDR_NVM 0x1E000
85 #ifndef RIMEADDR_NBYTES
86 #define RIMEADDR_NBYTES 8
89 #define PLATFORM_DEBUG 1
91 #define PRINTF(...) printf(__VA_ARGS__)
99 #ifndef UIP_ROUTER_MODULE
100 #ifdef UIP_CONF_ROUTER_MODULE
101 #define UIP_ROUTER_MODULE UIP_CONF_ROUTER_MODULE
103 #define UIP_ROUTER_MODULE rimeroute
107 extern const struct uip_router UIP_ROUTER_MODULE;
111 #if DCOSYNCH_CONF_ENABLED
112 static struct timer mgt_timer;
122 #include "net/uip-fw-drv.h"
125 {
UIP_FW_NETIF(192,168,1,2, 255,255,255,255, slip_send)};
127 {
UIP_FW_NETIF(172,16,0,0, 255,255,0,0, uip_over_mesh_send)};
131 #define UIP_OVER_MESH_CHANNEL 8
133 static uint8_t is_gateway;
140 #define RF_CHANNEL 26
149 printf(
"%d.%d: making myself the IP network gateway.\n\n",
151 printf(
"IPv4 address of the gateway: %d.%d.%d.%d\n\n",
154 uip_over_mesh_make_announced_gateway();
161 print_processes(
struct process *
const processes[])
165 while(*processes !=
NULL) {
166 printf(
" '%s'", (*processes)->name);
173 SENSORS(&button_sensor);
179 set_bit(*GPIO_PAD_DIR0,8);
180 set_bit(*GPIO_PAD_DIR0,9);
181 set_bit(*GPIO_PAD_DIR0,10);
182 set_bit(*GPIO_PAD_DIR0,23);
183 set_bit(*GPIO_PAD_DIR0,24);
184 set_bit(*GPIO_PAD_DIR0,25);
199 uart_init(BRINC, BRMOD, SAMP);
205 set_channel(RF_CHANNEL - 11);
209 *GPIO_FUNC_SEL2 = (0x01 << ((44-16*2)*2));
210 gpio_pad_dir_set( 1ULL << 44 );
221 *CRM_RTC_TIMEOUT = 32768 * 10;
223 *CRM_RTC_TIMEOUT = cal_rtc_secs * 10;
233 #if RIMEADDR_SIZE == 1
234 const rimeaddr_t addr_ff = { { 0xff } };
236 #if RIMEADDR_SIZE == 2
237 const rimeaddr_t addr_ff = { { 0xff, 0xff } };
239 #if RIMEADDR_SIZE == 8
240 const rimeaddr_t addr_ff = { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } };
245 void iab_to_eui64(rimeaddr_t *eui64, uint32_t oui, uint16_t iab, uint32_t ext) {
256 eui64->u8[5] = (iab >> 4) & 0xff;
257 eui64->u8[6] = (iab & 0xf) << 4;
260 eui64->u8[6] |= ((ext >> 8) & 0xf);
261 eui64->u8[7] = ext & 0xff;
264 void oui_to_eui64(rimeaddr_t *eui64, uint32_t oui, uint32_t ext) {
266 eui64->u8[0] = (oui >> 16) & 0xff;
267 eui64->u8[1] = (oui >> 8) & 0xff;
268 eui64->u8[2] = oui & 0xff;
275 eui64->u8[5] = (ext >> 16) & 0xff;
276 eui64->u8[6] = (ext >> 8) & 0xff;
277 eui64->u8[7] = ext & 0xff;
281 set_rimeaddr(rimeaddr_t *addr)
285 volatile uint8_t buf[RIMEADDR_NBYTES];
289 err = nvm_detect(gNvmInternalInterface_c, &type);
291 err = nvm_read(gNvmInternalInterface_c, type, (uint8_t *)buf, RIMEADDR_NVM, RIMEADDR_NBYTES);
295 for(i=0; i<RIMEADDR_CONF_SIZE; i++) {
296 addr->u8[i] = buf[i];
299 if (memcmp(addr, &addr_ff, RIMEADDR_CONF_SIZE)==0) {
304 PRINTF(
"address in flash blank, setting to defined IAB and extension.\n\r");
305 iab_to_eui64(&eui64, OUI, IAB, EXT_ID);
307 PRINTF(
"address in flash blank, setting to defined IAB with a random extension.\n\r");
308 iab_to_eui64(&eui64, OUI, IAB, *MACA_RANDOM & 0xfff);
314 PRINTF(
"address in flash blank, setting to defined OUI and extension.\n\r");
315 oui_to_eui64(&eui64, OUI, EXT_ID);
317 PRINTF(
"address in flash blank, setting to defined OUI with a random extension.\n\r");
318 oui_to_eui64(&eui64, OUI, *MACA_RANDOM & 0xffffff);
324 #ifdef FLASH_BLANK_ADDR
325 PRINTF(
"flashing blank address\n\r");
326 err = nvm_write(gNvmInternalInterface_c, type, &(eui64.u8), RIMEADDR_NVM, RIMEADDR_NBYTES);
329 PRINTF(
"loading rime address from flash.\n\r");
357 printf(
"Rime started with address ");
358 for(i = 0; i <
sizeof(addr.u8) - 1; i++) {
359 printf(
"%02X:", addr.u8[i]);
361 printf(
"%02X\n", addr.u8[i]);
374 NETSTACK_NETWORK.init();
376 printf(
"%s %s, channel check rate %lu Hz, radio channel %u\n",
377 NETSTACK_MAC.name, NETSTACK_RDC.name,
378 CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1:
379 NETSTACK_RDC.channel_check_interval()),
384 printf(
"Tentative link-local IPv6 address ");
387 for(a = 0; a < UIP_DS6_ADDR_NB; a++) {
388 if (uip_ds6_if.addr_list[a].isused) {
389 for(i = 0; i < 7; ++i) {
391 uip_ds6_if.addr_list[a].ipaddr.u8[i * 2],
392 uip_ds6_if.addr_list[a].ipaddr.u8[i * 2 + 1]);
395 uip_ds6_if.addr_list[a].ipaddr.u8[14],
396 uip_ds6_if.addr_list[a].ipaddr.u8[15]);
407 printf(
"Tentative global IPv6 address ");
408 for(i = 0; i < 7; ++i) {
410 ipaddr.u8[i * 2], ipaddr.u8[i * 2 + 1]);
413 ipaddr.u8[7 * 2], ipaddr.u8[7 * 2 + 1]);
421 NETSTACK_NETWORK.init();
423 printf(
"%s %s, channel check rate %lu Hz, radio channel %u\n",
424 NETSTACK_MAC.name, NETSTACK_RDC.name,
425 CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0? 1:
426 NETSTACK_RDC.channel_check_interval()),
434 #if TIMESYNCH_CONF_ENABLED
444 slip_set_input_callback(set_gateway);
458 uip_over_mesh_set_net(&hostaddr, &netmask);
460 uip_over_mesh_set_gateway_netif(&slipif);
462 uip_over_mesh_init(UIP_OVER_MESH_CHANNEL);
463 printf(
"uIP started with IP address %d.%d.%d.%d\n",
470 print_processes(autostart_processes);
471 autostart_start(autostart_processes);
478 if(uart1_input_handler !=
NULL) {
479 if(uart1_can_get()) {
480 uart1_input_handler(uart1_getc());
493 log_message(
char *m1,
char *m2)
495 printf(
"%s%s\n", m1, m2);