/*---------------------------------------------------------------------------*/ void contiki_init() { /* Initialize random generator (moved to moteid.c) */ /* Start process handler */ process_init(); /* Start Contiki processes */ process_start(&etimer_process, NULL); process_start(&sensors_process, NULL); ctimer_init(); /* Print startup information */ printf(CONTIKI_VERSION_STRING " started. "); if(node_id > 0) { printf("Node id is set to %u.\n", node_id); } else { printf("Node id is not set.\n"); } set_rime_addr(); { uint8_t longaddr[8]; uint16_t shortaddr; shortaddr = (linkaddr_node_addr.u8[0] << 8) + linkaddr_node_addr.u8[1]; memset(longaddr, 0, sizeof(longaddr)); linkaddr_copy((linkaddr_t *)&longaddr, &linkaddr_node_addr); printf("MAC %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ", longaddr[0], longaddr[1], longaddr[2], longaddr[3], longaddr[4], longaddr[5], longaddr[6], longaddr[7]); } queuebuf_init(); /* Initialize communication stack */ netstack_init(); printf("%s/%s/%s, channel check rate %lu Hz\n", NETSTACK_NETWORK.name, NETSTACK_MAC.name, NETSTACK_RDC.name, CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1: NETSTACK_RDC.channel_check_interval())); #if WITH_UIP /* IPv4 CONFIGURATION */ { uip_ipaddr_t hostaddr, netmask; process_start(&tcpip_process, NULL); process_start(&uip_fw_process, NULL); process_start(&slip_process, NULL); slip_set_input_callback(set_gateway); uip_init(); uip_fw_init(); uip_ipaddr(&hostaddr, 172,16,linkaddr_node_addr.u8[0],linkaddr_node_addr.u8[1]); uip_ipaddr(&netmask, 255,255,0,0); uip_ipaddr_copy(&meshif.ipaddr, &hostaddr); uip_sethostaddr(&hostaddr); uip_setnetmask(&netmask); uip_over_mesh_set_net(&hostaddr, &netmask); uip_over_mesh_set_gateway_netif(&slipif); uip_fw_default(&meshif); uip_over_mesh_init(UIP_OVER_MESH_CHANNEL); rs232_set_input(slip_input_byte); printf("IPv4 address: %d.%d.%d.%d\n", uip_ipaddr_to_quad(&hostaddr)); } #endif /* WITH_UIP */ #if WITH_UIP6 /* IPv6 CONFIGURATION */ { int i; uint8_t addr[sizeof(uip_lladdr.addr)]; for(i = 0; i < sizeof(uip_lladdr.addr); i += 2) { addr[i + 1] = node_id & 0xff; addr[i + 0] = node_id >> 8; } linkaddr_copy(addr, &linkaddr_node_addr); memcpy(&uip_lladdr.addr, addr, sizeof(uip_lladdr.addr)); process_start(&tcpip_process, NULL); printf("Tentative link-local IPv6 address "); { uip_ds6_addr_t *lladdr; int i; lladdr = uip_ds6_get_link_local(-1); for(i = 0; i < 7; ++i) { printf("%02x%02x:", lladdr->ipaddr.u8[i * 2], lladdr->ipaddr.u8[i * 2 + 1]); } printf("%02x%02x\n", lladdr->ipaddr.u8[14], lladdr->ipaddr.u8[15]); } if(1) { uip_ipaddr_t ipaddr; int i; uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0); uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr); uip_ds6_addr_add(&ipaddr, 0, ADDR_TENTATIVE); printf("Tentative global IPv6 address "); for(i = 0; i < 7; ++i) { printf("%02x%02x:", ipaddr.u8[i * 2], ipaddr.u8[i * 2 + 1]); } printf("%02x%02x\n", ipaddr.u8[7 * 2], ipaddr.u8[7 * 2 + 1]); } } #endif /* WITH_UIP6 */ /* Initialize eeprom */ eeprom_init(); /* Start serial process */ serial_line_init(); /* Start autostart processes (defined in Contiki application) */ print_processes(autostart_processes); autostart_start(autostart_processes); }
/*------Done in a subroutine to keep main routine stack usage small--------*/ void initialize(void) { //calibrate_rc_osc_32k(); //CO: Had to comment this out #ifdef RAVEN_LCD_INTERFACE /* First rs232 port for Raven 3290 port */ rs232_init(RS232_PORT_0, USART_BAUD_38400,USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8); /* Set input handler for 3290 port */ rs232_set_input(0,raven_lcd_serial_input); #endif /* Second rs232 port for debugging */ rs232_init(RS232_PORT_1, USART_BAUD_57600,USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8); /* Redirect stdout to second port */ rs232_redirect_stdout(RS232_PORT_1); clock_init(); printf_P(PSTR("\n*******Booting %s*******\n"),CONTIKI_VERSION_STRING); /* Initialize process subsystem */ process_init(); #ifdef RF230BB { /* Start radio and radio receive process */ rf230_init(); sicslowpan_init(sicslowmac_init(&rf230_driver)); // ctimer_init(); // sicslowpan_init(lpp_init(&rf230_driver)); // rime_init(sicslowmac_driver.init(&rf230_driver)); // rime_init(lpp_init(&rf230_driver)); /* Set addresses BEFORE starting tcpip process */ rimeaddr_t addr; memset(&addr, 0, sizeof(rimeaddr_t)); AVR_ENTER_CRITICAL_REGION(); eeprom_read_block ((void *)&addr.u8, &mac_address, 8); AVR_LEAVE_CRITICAL_REGION(); memcpy(&uip_lladdr.addr, &addr.u8, 8); rf230_set_pan_addr(IEEE802154_PANID, 0, (uint8_t *)&addr.u8); rf230_set_channel(24); rimeaddr_set_node_addr(&addr); PRINTF("MAC address %x:%x:%x:%x:%x:%x:%x:%x\n",addr.u8[0],addr.u8[1],addr.u8[2],addr.u8[3],addr.u8[4],addr.u8[5],addr.u8[6],addr.u8[7]); // uip_ip6addr(&ipprefix, 0xaaaa, 0, 0, 0, 0, 0, 0, 0); // uip_netif_addr_add(&ipprefix, UIP_DEFAULT_PREFIX_LEN, 0, AUTOCONF); // uip_nd6_prefix_add(&ipprefix, UIP_DEFAULT_PREFIX_LEN, 0); // PRINTF("Prefix %x::/%u\n",ipprefix.u16[0],UIP_DEFAULT_PREFIX_LEN); #if UIP_CONF_ROUTER rime_init(rime_udp_init(NULL)); uip_router_register(&rimeroute); #endif PRINTF("Driver: %s, Channel: %u\n", sicslowmac_driver.name, rf230_get_channel()); } #endif /*RF230BB*/ /* Register initial processes */ procinit_init(); /* Autostart processes */ autostart_start(autostart_processes); //Give ourselves a prefix // init_net(); /*---If using coffee file system create initial web content if necessary---*/ #if COFFEE_FILES int fa = cfs_open( "/index.html", CFS_READ); if (fa<0) { //Make some default web content printf_P(PSTR("No index.html file found, creating upload.html!\n")); printf_P(PSTR("Formatting FLASH file system for coffee...")); cfs_coffee_format(); printf_P(PSTR("Done!\n")); fa = cfs_open( "/index.html", CFS_WRITE); int r = cfs_write(fa, &"It works!", 9); if (r<0) printf_P(PSTR("Can''t create /index.html!\n")); cfs_close(fa); // fa = cfs_open("upload.html"), CFW_WRITE); // <html><body><form action="upload.html" enctype="multipart/form-data" method="post"><input name="userfile" type="file" size="50" /><input value="Upload" type="submit" /></form></body></html> } #endif /*--------------------------Announce the configuration---------------------*/ #if WEBSERVER char buf[80]; unsigned int size; eeprom_read_block (buf,server_name, sizeof(server_name)); buf[sizeof(server_name)]=0; printf_P(PSTR("%s"),buf); eeprom_read_block (buf,domain_name, sizeof(domain_name)); buf[sizeof(domain_name)]=0; size=httpd_fs_get_size(); #ifndef COFFEE_FILES printf_P(PSTR(".%s online with fixed %u byte web content\n"),buf,size); #elif COFFEE_FILES==1 printf_P(PSTR(".%s online with static %u byte EEPROM file system\n"),buf,size); #elif COFFEE_FILES==2 printf_P(PSTR(".%s online with dynamic %u KB EEPROM file system\n"),buf,size>>10); #elif COFFEE_FILES==3 printf_P(PSTR(".%s online with static %u byte program memory file system\n"),buf,size); #elif COFFEE_FILES==4 printf_P(PSTR(".%s online with dynamic %u KB program memory file system\n"),buf,size>>10); #endif #else printf_P(PSTR("Online\n")); #endif /* WEBSERVER */ }
/*---------------------------------------------------------------------------*/ void contiki_init() { /* Initialize random generator (moved to moteid.c) */ /* Start process handler */ process_init(); /* Start Contiki processes */ procinit_init(); /* Print startup information */ printf(CONTIKI_VERSION_STRING " started. "); if(node_id > 0) { printf("Node id is set to %u.\n", node_id); } else { printf("Node id is not set.\n"); } /* RIME CONFIGURATION */ { int i; rimeaddr_t rimeaddr; /* Init Rime */ ctimer_init(); rimeaddr.u8[0] = node_id & 0xff; rimeaddr.u8[1] = node_id >> 8; rimeaddr_set_node_addr(&rimeaddr); printf("Rime address: "); for(i = 0; i < sizeof(rimeaddr_node_addr.u8) - 1; i++) { printf("%d.", rimeaddr_node_addr.u8[i]); } printf("%d\n", rimeaddr_node_addr.u8[i]); } queuebuf_init(); /* Initialize communication stack */ netstack_init(); printf("MAC %s RDC %s NETWORK %s\n", NETSTACK_MAC.name, NETSTACK_RDC.name, NETSTACK_NETWORK.name); #if WITH_UIP /* IPv4 CONFIGURATION */ { uip_ipaddr_t hostaddr, netmask; process_start(&tcpip_process, NULL); process_start(&uip_fw_process, NULL); process_start(&slip_process, NULL); slip_set_input_callback(set_gateway); uip_init(); uip_fw_init(); uip_ipaddr(&hostaddr, 172,16,rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1]); uip_ipaddr(&netmask, 255,255,0,0); uip_ipaddr_copy(&meshif.ipaddr, &hostaddr); uip_sethostaddr(&hostaddr); uip_setnetmask(&netmask); uip_over_mesh_set_net(&hostaddr, &netmask); uip_over_mesh_set_gateway_netif(&slipif); uip_fw_default(&meshif); uip_over_mesh_init(UIP_OVER_MESH_CHANNEL); rs232_set_input(slip_input_byte); printf("IPv4 address: %d.%d.%d.%d\n", uip_ipaddr_to_quad(&hostaddr)); } #endif /* WITH_UIP */ #if WITH_UIP6 /* IPv6 CONFIGURATION */ { int i; uint8_t addr[sizeof(uip_lladdr.addr)]; for (i=0; i < sizeof(uip_lladdr.addr); i++) { addr[i] = node_id & 0xff; } memcpy(&uip_lladdr.addr, addr, sizeof(uip_lladdr.addr)); process_start(&tcpip_process, NULL); printf("Tentative link-local IPv6 address "); { int i, a; for(a = 0; a < UIP_DS6_ADDR_NB; a++) { if (uip_ds6_if.addr_list[a].isused) { for(i = 0; i < 7; ++i) { printf("%02x%02x:", uip_ds6_if.addr_list[a].ipaddr.u8[i * 2], uip_ds6_if.addr_list[a].ipaddr.u8[i * 2 + 1]); } printf("%02x%02x\n", uip_ds6_if.addr_list[a].ipaddr.u8[14], uip_ds6_if.addr_list[a].ipaddr.u8[15]); } } } if(1) { uip_ipaddr_t ipaddr; int i; uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0); uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr); uip_ds6_addr_add(&ipaddr, 0, ADDR_TENTATIVE); printf("Tentative global IPv6 address "); for(i = 0; i < 7; ++i) { printf("%02x%02x:", ipaddr.u8[i * 2], ipaddr.u8[i * 2 + 1]); } printf("%02x%02x\n", ipaddr.u8[7 * 2], ipaddr.u8[7 * 2 + 1]); } } #endif /* WITH_UIP6 */ /* Start serial process */ serial_line_init(); /* Start autostart processes (defined in Contiki application) */ print_processes(autostart_processes); autostart_start(autostart_processes); }
/*---------------------------------------------------------------------------*/ void contiki_init(void) { int i; uint8_t addr[sizeof(uip_lladdr.addr)]; uip_ipaddr_t ipaddr; uip_ds6_addr_t *lladdr; uip_ip4addr_t ipv4addr, netmask; /* Start process handler */ process_init(); /* Start Contiki processes */ process_start(&etimer_process, NULL); process_start(&sensors_process, NULL); ctimer_init(); /* Print startup information */ printf(CONTIKI_VERSION_STRING " started. "); if(node_id > 0) { printf("Node id is set to %u.\n", node_id); } else { printf("Node id is not set.\n"); } set_mac_addr(); queuebuf_init(); /* Initialize communication stack */ netstack_init(); printf("%s/%s/%s, channel check rate %lu Hz\n", NETSTACK_NETWORK.name, NETSTACK_MAC.name, NETSTACK_RDC.name, CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1: NETSTACK_RDC.channel_check_interval())); /* IPv6 CONFIGURATION */ for(i = 0; i < sizeof(uip_lladdr.addr); i += 2) { addr[i + 1] = node_id & 0xff; addr[i + 0] = node_id >> 8; } linkaddr_copy(addr, &linkaddr_node_addr); memcpy(&uip_lladdr.addr, addr, sizeof(uip_lladdr.addr)); process_start(&tcpip_process, NULL); printf("Tentative link-local IPv6 address "); lladdr = uip_ds6_get_link_local(-1); for(i = 0; i < 7; ++i) { printf("%02x%02x:", lladdr->ipaddr.u8[i * 2], lladdr->ipaddr.u8[i * 2 + 1]); } printf("%02x%02x\n", lladdr->ipaddr.u8[14], lladdr->ipaddr.u8[15]); uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0); uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr); uip_ds6_addr_add(&ipaddr, 0, ADDR_TENTATIVE); printf("Tentative global IPv6 address "); for(i = 0; i < 7; ++i) { printf("%02x%02x:", ipaddr.u8[i * 2], ipaddr.u8[i * 2 + 1]); } printf("%02x%02x\n", ipaddr.u8[7 * 2], ipaddr.u8[7 * 2 + 1]); /* Start serial process */ serial_line_init(); /* Start autostart processes (defined in Contiki application) */ print_processes(autostart_processes); autostart_start(autostart_processes); /* Start the SLIP */ printf("Initiating SLIP with IP address is 172.16.0.2.\n"); uip_ipaddr(&ipv4addr, 172, 16, 0, 2); uip_ipaddr(&netmask, 255, 255, 255, 0); ip64_set_ipv4_address(&ipv4addr, &netmask); rs232_set_input(slip_input_byte); log_set_putchar_with_slip(1); uip_ip4addr_t ip4addr; uip_ip6addr_t ip6addr; uip_ipaddr(&ip4addr, 8,8,8,8); ip64_addr_4to6(&ip4addr, &ip6addr); uip_nameserver_update((uip_ipaddr_t *)&ip6addr, UIP_NAMESERVER_INFINITE_LIFETIME); }
/** * Initalize the RS232 port and the SLIP driver. * */ void slip_arch_init(unsigned long ubr) { rs232_set_input(slip_input_byte); }
/*------Done in a subroutine to keep main routine stack usage small--------*/ void initialize(void) { watchdog_init(); watchdog_start(); #ifdef RAVEN_LCD_INTERFACE /* First rs232 port for Raven 3290 port */ rs232_init(RS232_PORT_0, USART_BAUD_38400,USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8); /* Set input handler for 3290 port */ rs232_set_input(0,raven_lcd_serial_input); #endif /* Second rs232 port for debugging */ rs232_init(RS232_PORT_1, USART_BAUD_57600,USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8); /* Redirect stdout to second port */ rs232_redirect_stdout(RS232_PORT_1); clock_init(); #if STACKMONITOR /* Simple stack pointer highwater monitor. Checks for magic numbers in the main * loop. In conjuction with TESTRTIMER, never-used stack will be printed * every STACKMONITOR seconds. */ { extern uint16_t __bss_end; uint16_t p=(uint16_t)&__bss_end; do { *(uint16_t *)p = 0x4242; p+=10; } while (p<SP-10); //don't overwrite our own stack } #endif #define CONF_CALIBRATE_OSCCAL 0 #if CONF_CALIBRATE_OSCCAL { extern uint8_t osccal_calibrated; uint8_t i; PRINTF("\nBefore calibration OSCCAL=%x\n",OSCCAL); for (i=0;i<10;i++) { calibrate_rc_osc_32k(); PRINTF("Calibrated=%x\n",osccal_calibrated); //#include <util/delay_basic.h> //#define delay_us( us ) ( _delay_loop_2(1+(us*F_CPU)/4000000UL) ) // delay_us(50000); } clock_init(); } #endif #if ANNOUNCE_BOOT PRINTF("\n*******Booting %s*******\n",CONTIKI_VERSION_STRING); #endif /* rtimers needed for radio cycling */ rtimer_init(); /* Initialize process subsystem */ process_init(); /* etimers must be started before ctimer_init */ process_start(&etimer_process, NULL); #if RF230BB ctimer_init(); /* Start radio and radio receive process */ NETSTACK_RADIO.init(); /* Set addresses BEFORE starting tcpip process */ rimeaddr_t addr; memset(&addr, 0, sizeof(rimeaddr_t)); get_mac_from_eeprom(addr.u8); #if UIP_CONF_IPV6 memcpy(&uip_lladdr.addr, &addr.u8, 8); #endif rf230_set_pan_addr( get_panid_from_eeprom(), get_panaddr_from_eeprom(), (uint8_t *)&addr.u8 ); rf230_set_channel(get_channel_from_eeprom()); rimeaddr_set_node_addr(&addr); PRINTFD("MAC address %x:%x:%x:%x:%x:%x:%x:%x\n",addr.u8[0],addr.u8[1],addr.u8[2],addr.u8[3],addr.u8[4],addr.u8[5],addr.u8[6],addr.u8[7]); /* Initialize stack protocols */ queuebuf_init(); NETSTACK_RDC.init(); NETSTACK_MAC.init(); NETSTACK_NETWORK.init(); #if ANNOUNCE_BOOT PRINTF("%s %s, channel %u",NETSTACK_MAC.name, NETSTACK_RDC.name,rf230_get_channel()); if (NETSTACK_RDC.channel_check_interval) {//function pointer is zero for sicslowmac unsigned short tmp; tmp=CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval == 0 ? 1:\ NETSTACK_RDC.channel_check_interval()); if (tmp<65535) printf_P(PSTR(", check rate %u Hz"),tmp); } PRINTF("\n"); #if UIP_CONF_IPV6_RPL PRINTF("RPL Enabled\n"); #endif #if UIP_CONF_ROUTER PRINTF("Routing Enabled\n"); #endif #endif /* ANNOUNCE_BOOT */ // rime_init(rime_udp_init(NULL)); // uip_router_register(&rimeroute); process_start(&tcpip_process, NULL); #else /* Original RF230 combined mac/radio driver */ /* mac process must be started before tcpip process! */ process_start(&mac_process, NULL); process_start(&tcpip_process, NULL); #endif /*RF230BB*/ #ifdef RAVEN_LCD_INTERFACE process_start(&raven_lcd_process, NULL); #endif /* Autostart other processes */ autostart_start(autostart_processes); //Give ourselves a prefix // init_net(); /*---If using coffee file system create initial web content if necessary---*/ #if COFFEE_FILES int fa = cfs_open( "/index.html", CFS_READ); if (fa<0) { //Make some default web content PRINTF("No index.html file found, creating upload.html!\n"); PRINTF("Formatting FLASH file system for coffee..."); cfs_coffee_format(); PRINTF("Done!\n"); fa = cfs_open( "/index.html", CFS_WRITE); int r = cfs_write(fa, &"It works!", 9); if (r<0) PRINTF("Can''t create /index.html!\n"); cfs_close(fa); // fa = cfs_open("upload.html"), CFW_WRITE); // <html><body><form action="upload.html" enctype="multipart/form-data" method="post"><input name="userfile" type="file" size="50" /><input value="Upload" type="submit" /></form></body></html> } #endif /* COFFEE_FILES */ /* Add addresses for testing */ #if 0 { uip_ip6addr_t ipaddr; uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0); uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF); // uip_ds6_prefix_add(&ipaddr,64,0); } #endif /*--------------------------Announce the configuration---------------------*/ #if ANNOUNCE_BOOT #if AVR_WEBSERVER uint8_t i; char buf[80]; unsigned int size; for (i=0;i<UIP_DS6_ADDR_NB;i++) { if (uip_ds6_if.addr_list[i].isused) { httpd_cgi_sprint_ip6(uip_ds6_if.addr_list[i].ipaddr,buf); PRINTF("IPv6 Address: %s\n",buf); } } eeprom_read_block (buf,server_name, sizeof(server_name)); buf[sizeof(server_name)]=0; PRINTF("%s",buf); eeprom_read_block (buf,domain_name, sizeof(domain_name)); buf[sizeof(domain_name)]=0; size=httpd_fs_get_size(); #ifndef COFFEE_FILES PRINTF(".%s online with fixed %u byte web content\n",buf,size); #elif COFFEE_FILES==1 PRINTF(".%s online with static %u byte EEPROM file system\n",buf,size); #elif COFFEE_FILES==2 PRINTF(".%s online with dynamic %u KB EEPROM file system\n",buf,size>>10); #elif COFFEE_FILES==3 PRINTF(".%s online with static %u byte program memory file system\n",buf,size); #elif COFFEE_FILES==4 PRINTF(".%s online with dynamic %u KB program memory file system\n",buf,size>>10); #endif /* COFFEE_FILES */ #else PRINTF("Online\n"); #endif /* AVR_WEBSERVER */ #endif /* ANNOUNCE_BOOT */ }
/*------Done in a subroutine to keep main routine stack usage small--------*/ void initialize(void) { #if WITH_SLIP //Slip border router on uart0 rs232_init(RS232_PORT_0, USART_BAUD_38400,USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8); #else /* First rs232 port for debugging */ rs232_init(RS232_PORT_0, USART_BAUD_57600,USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8); /* Redirect stdout to first port */ rs232_redirect_stdout(RS232_PORT_0); /* Get input from first port */ rs232_set_input(RS232_PORT_0, serial_line_input_byte); #endif clock_init(); if(MCUSR & (1<<PORF )) PRINTA("Power-on reset.\n"); if(MCUSR & (1<<EXTRF)) PRINTA("External reset!\n"); if(MCUSR & (1<<BORF )) PRINTA("Brownout reset!\n"); if(MCUSR & (1<<WDRF )) PRINTA("Watchdog reset!\n"); if(MCUSR & (1<<JTRF )) PRINTA("JTAG reset!\n"); #if ANNOUNCE_BOOT PRINTA("\n*******Booting %s*******\n",CONTIKI_VERSION_STRING); #endif /* Initialize process subsystem */ process_init(); /* etimers must be started before ctimer_init */ process_start(&etimer_process, NULL); /* Initilaize serial line for input */ serial_line_init(); /* Initialize board LEDs */ leds_init(); /* When used for testing, we should start with them off */ leds_off(LEDS_GREEN|LEDS_YELLOW); ctimer_init(); /* Start radio and radio receive process */ NETSTACK_RADIO.init(); /* Set addresses BEFORE starting tcpip process */ rimeaddr_t addr; memset(&addr, 0, sizeof(rimeaddr_t)); get_mac_from_eeprom(addr.u8); memcpy(&uip_lladdr.addr, &addr.u8, 8); // Is this required with IPv6, I wonder? #if 1 rf230_set_pan_addr( IEEE802154_PANID, 0, (uint8_t *)&addr.u8 ); rf230_set_channel(26); rimeaddr_set_node_addr(&addr); #endif PRINTF("MAC address %x:%x:%x:%x:%x:%x:%x:%x\n",addr.u8[0],addr.u8[1],addr.u8[2],addr.u8[3],addr.u8[4],addr.u8[5],addr.u8[6],addr.u8[7]); /* Initialize stack protocols */ queuebuf_init(); NETSTACK_RDC.init(); NETSTACK_MAC.init(); NETSTACK_NETWORK.init(); #if ANNOUNCE_BOOT PRINTA("%s %s, channel %u",NETSTACK_MAC.name, NETSTACK_RDC.name,rf230_get_channel()); if (NETSTACK_RDC.channel_check_interval) //function pointer is zero for sicslowmac { unsigned short tmp; tmp=CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval == 0 ? 1:\ NETSTACK_RDC.channel_check_interval()); if (tmp<65535) PRINTA(", check rate %u Hz",tmp); } PRINTA("\n"); #endif #if UIP_CONF_ROUTER //#warning Zigduino has not been tested with UIP_CONF_ROUTER #if ANNOUNCE_BOOT PRINTA("Routing Enabled\n"); #endif #endif /* Sensors process means all processes will get an event posted whenever sensors change. Not always desired, so may want to put this on a compile switch. */ process_start(&sensors_process, NULL); SENSORS_ACTIVATE(button_sensor); process_start(&tcpip_process, NULL); //Give ourselves a prefix // init_net(); /* Add easy addresses for testing */ uip_ip6addr_t ipaddr; uip_ip6addr(&ipaddr, 0xfe80, 0, 0, 0, 0, 0, 0, addr.u8[7]); uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF); #if UIP_CONF_ROUTER uip_ds6_prefix_add(&ipaddr,64,0,0,0,0); #else uip_ds6_prefix_add(&ipaddr,64,0); #endif /* Create a route through the border router for site-local addresses, fec0::/64. */ uip_ds6_route_t *rep; uip_ip6addr_t next_hop; uip_ip6addr(&ipaddr, 0xfec0, 0, 0, 0, 0, 0, 0, 0); uip_ip6addr(&next_hop, 0xaaaa, 0, 0, 0, 0, 0, 0, 1); if((rep = uip_ds6_route_add(&ipaddr, 64, &next_hop, 0)) == NULL) { printf("*** Failed to add a route to fec0::/64\n"); } printf("Autostart other processes\n"); /* Autostart other processes */ autostart_start(autostart_processes); /*--------------------------Announce the configuration---------------------*/ #if ANNOUNCE_BOOT extern uip_ds6_netif_t uip_ds6_if; uint8_t i; PRINTA("\nIP addresses [%u max]\n",UIP_DS6_ADDR_NB); for (i=0; i<UIP_DS6_ADDR_NB; i++) { if (uip_ds6_if.addr_list[i].isused) { uip_debug_ipaddr_print(&uip_ds6_if.addr_list[i].ipaddr); PRINTA("\n"); } } #endif /* ANNOUNCE_BOOT */ }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(check_sensor_status, ev, data) { uip_ipaddr_t addr; static struct etimer periodic_timer; int i=0; char globalStatus=0; PROCESS_BEGIN(); for(i=0;i<20;i++){ sensorsList[i].type = SENSOR_NONE; sensorsList[i].status = STATUS_OK; sensorsList[i].lastTime = 0; sensorsList[i].failedTimeouts = 0; } sensorsList[0].type = SENSOR_PIR; sensorsList[1].type = SENSOR_CHOCK; sensorsList[2].type = SENSOR_PIR; sensorsList[3].type = SENSOR_RFID; DDRB = 0x00; PORTB = 0x00; //sensorsList[0].type = SENSOR_PIR; //sensorsList[1].type = SENSOR_PIR; //sensorsList[2].type = SENSOR_CHOCK; //rs232_init(RS232_PORT_0, USART_BAUD_19200, USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8); //rs232_redirect_stdout(RS232_PORT_0); //rs232_send(RS232_PORT_n, char c); // OR FOR STRINGS rs232_print(char *); rs232_set_input(RS232_PORT_0, uart0_callback); uart0_setLineCallback(baseReadyUART); rs232_init(RS232_PORT_1, USART_BAUD_9600, USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8); rs232_set_input(RS232_PORT_1, uart1_callback); uart1_setLineCallback(lineReadyUART1); simple_udp_register(&broadcast_connection, UDP_PORT, NULL, UDP_PORT, receiver); etimer_set(&periodic_timer, CHECK_INTERVAL); while(1) { PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&periodic_timer)); etimer_reset(&periodic_timer); for(i=0;i<20;i++){ if(sensorsList[i].type != 0){ sensorsList[i].lastTime++; if(sensorsList[i].lastTime == 11){ /* SECONDS / 2 => *0->11* 6 seconds without infos */ sensorsList[i].failedTimeouts++; sensorsList[i].lastTime = 0; uip_create_linklocal_allnodes_mcast(&addr); sprintf(string6LOWPAN,"{\"cmd\":\"s\",\"id\":\"%d\"}",i); simple_udp_sendto(&broadcast_connection, string6LOWPAN, strlen(string6LOWPAN), &addr); if(sensorsList[i].failedTimeouts == 3){ sensorsList[i].failedTimeouts = 0; sensorsList[i].status = STATUS_TIMEOUT; printf("{\"cmd\":\"g\",\"id\":\"%d\",\"st\":\"%d\",\"ty\":\"%d\"}\n", i, sensorsList[i].status, sensorsList[i].type); } } } } } PROCESS_END(); }
uart1_set_input(int (*input)(unsigned char c)) { rs232_set_input(RS232_PORT_1, input); }