/*-----------------------------------------------------------------------------------*/ void sec_arp_init(void) { uint8_t sum, i; uint8_t temp_buf[KEY_SIZE*3]; /* Read security data from Flash mem */ xmem_pread(temp_buf, (KEY_SIZE*3), MAC_SECURITY_DATA); /* Check if we have a network key */ sum = 0; for(i=KEY_SIZE; i>0; i--) {sum |= temp_buf[i-1];} if(!(sum)) { /* Init slip connection */ slip_arch_init(BAUD2UBR(115200)); PRINTF("sec-arp: Start slip process\n"); process_start(&slip_process, NULL); slip_set_input_callback(slip_input_callback); /* Send hello packet */ create_hello(); } else { PRINTF("sec-arp: Key OK\n"); #if DEBUG PRINTF("sec-arp: buf "); for(i=0; i<(KEY_SIZE*3); i++) PRINTF("%02x ", temp_buf[i]); PRINTF("\n"); #endif /* Set security data */ set_security_data(temp_buf); } }
/*---------------------------------------------------------------------------*/ static void slip_init(void) { slip_arch_init(BAUD2UBR(115200)); process_start(&slip_process, NULL); slip_set_input_callback(slip_input_callback); PRINTF("slip init\n"); }
void slipnet_init(void) { tcpip_set_outputfunc(tip_output); slip_set_input_callback(slip_input_call); slip_arch_init(115200); process_start(&slip_process, NULL); }
/*---------------------------------------------------------------------------*/ static void init(void) { #ifndef BAUD2UBR #define BAUD2UBR(baud) baud #endif slip_arch_init(BAUD2UBR(115200)); process_start(&slip_process, NULL); slip_set_input_callback(slip_input_callback); packet_pos = 0; }
/*---------------------------------------------------------------------------*/ void init_usart(void) { /* First rs232 port for debugging */ rs232_init(RS232_PORT_0, USART_BAUD_115200, USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8); #if WITH_UIP || WITH_UIP6 slip_arch_init(USART_BAUD_115200); #else rs232_redirect_stdout(RS232_PORT_0); #endif /* WITH_UIP */ }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(uip6_bridge, ev, data) { PROCESS_BEGIN(); printf("Setting up SLIP\n"); mac_ethernetSetup(); slip_arch_init(BAUD2UBR(115200)); slip_set_input_callback(slip_activity); slip_set_tcpip_input_callback(slip_tcpip_input); process_start(&slip_process, NULL); PROCESS_END(); }
void init_lowlevel(void) { rs232_init(USART_PORT, USART_BAUD, USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8); #if WITH_UIP || WITH_UIP6 /* Initialise SPLIP on USART port */ slip_arch_init(SLIP_BAUD); #else /* Redirect stdout and stdin to USART port */ rs232_redirect_stdout(USART_PORT); rs232_set_input(USART_PORT, serial_line_input_byte); #endif }
/*---------------------------------------------------------------------------*/ int main(int argc, char **argv) { /* * Initalize hardware. */ msp430_cpu_init(); clock_init(); leds_init(); leds_on(LEDS_RED); clock_wait(100); uart0_init(BAUD2UBR(115200)); /* Must come before first printf */ #if WITH_UIP slip_arch_init(BAUD2UBR(115200)); #endif /* WITH_UIP */ xmem_init(); rtimer_init(); /* * Hardware initialization done! */ /* Restore node id if such has been stored in external mem */ node_id_restore(); /* If no MAC address was burned, we use the node ID. */ if(node_mac[0] | node_mac[1] | node_mac[2] | node_mac[3] | node_mac[4] | node_mac[5] | node_mac[6] | node_mac[7]) { node_mac[0] = 0xc1; /* Hardcoded for Z1 */ node_mac[1] = 0x0c; /* Hardcoded for Revision C */ node_mac[2] = 0x00; /* Hardcoded to arbitrary even number so that the 802.15.4 MAC address is compatible with an Ethernet MAC address - byte 0 (byte 2 in the DS ID) */ node_mac[3] = 0x00; /* Hardcoded */ node_mac[4] = 0x00; /* Hardcoded */ node_mac[5] = 0x00; /* Hardcoded */ node_mac[6] = node_id >> 8; node_mac[7] = node_id & 0xff; }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(uip6_bridge, ev, data) { PROCESS_BEGIN(); printf("Setting up SLIP\n"); { short i; for(i=0;i<5;i++){ leds_blink(); clock_wait(100); } } mac_ethernetSetup(); slip_arch_init(115200); slip_set_tcpip_input_callback(slip_tcpip_input); process_start(&slip_process, NULL); PROCESS_END(); }
/*--------------------------------------------------------------------------*/ int main(int argc, char **argv) { /* * Initalize hardware. */ msp430_cpu_init(); clock_init(); leds_init(); leds_on(LEDS_RED); uart1_init(BAUD2UBR(115200)); /* Must come before first printf */ leds_on(LEDS_GREEN); /* xmem_init(); */ rtimer_init(); lcd_init(); watchdog_init(); PRINTF(CONTIKI_VERSION_STRING "\n"); /* PRINTF("Compiled at %s, %s\n", __TIME__, __DATE__);*/ /* * Hardware initialization done! */ leds_on(LEDS_RED); /* Restore node id if such has been stored in external mem */ #ifdef NODEID node_id = NODEID; #ifdef BURN_NODEID node_id_burn(node_id); node_id_restore(); /* also configures node_mac[] */ #endif /* BURN_NODEID */ #else node_id_restore(); /* also configures node_mac[] */ #endif /* NODE_ID */ /* for setting "hardcoded" IEEE 802.15.4 MAC addresses */ #ifdef MAC_1 { uint8_t ieee[] = { MAC_1, MAC_2, MAC_3, MAC_4, MAC_5, MAC_6, MAC_7, MAC_8 }; memcpy(node_mac, ieee, sizeof(uip_lladdr.addr)); } #endif /* * Initialize Contiki and our processes. */ process_init(); process_start(&etimer_process, NULL); ctimer_init(); set_rime_addr(); random_init(node_id); NETSTACK_RADIO.init(); #if CC11xx_CC1101 || CC11xx_CC1120 printf("Starting up cc11xx radio at channel %d\n", RF_CHANNEL); cc11xx_channel_set(RF_CHANNEL); #endif /* CC11xx_CC1101 || CC11xx_CC1120 */ #if CONFIGURE_CC2420 || CONFIGURE_CC2520 { uint8_t longaddr[8]; uint16_t shortaddr; shortaddr = (rimeaddr_node_addr.u8[0] << 8) + rimeaddr_node_addr.u8[1]; memset(longaddr, 0, sizeof(longaddr)); rimeaddr_copy((rimeaddr_t *)&longaddr, &rimeaddr_node_addr); printf("MAC %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n", longaddr[0], longaddr[1], longaddr[2], longaddr[3], longaddr[4], longaddr[5], longaddr[6], longaddr[7]); #if CONFIGURE_CC2420 cc2420_set_pan_addr(IEEE802154_PANID, shortaddr, longaddr); #endif /* CONFIGURE_CC2420 */ #if CONFIGURE_CC2520 cc2520_set_pan_addr(IEEE802154_PANID, shortaddr, longaddr); #endif /* CONFIGURE_CC2520 */ } #if CONFIGURE_CC2420 cc2420_set_channel(RF_CHANNEL); #endif /* CONFIGURE_CC2420 */ #if CONFIGURE_CC2520 cc2520_set_channel(RF_CHANNEL); #endif /* CONFIGURE_CC2520 */ #endif /* CONFIGURE_CC2420 || CONFIGURE_CC2520 */ NETSTACK_RADIO.on(); leds_off(LEDS_ALL); if(node_id > 0) { PRINTF("Node id %u.\n", node_id); } else { PRINTF("Node id not set.\n"); } #if WITH_UIP6 memcpy(&uip_lladdr.addr, node_mac, sizeof(uip_lladdr.addr)); /* Setup nullmac-like MAC for 802.15.4 */ queuebuf_init(); netstack_init(); printf("%s/%s %lu %u\n", NETSTACK_RDC.name, NETSTACK_MAC.name, CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1: NETSTACK_RDC.channel_check_interval()), RF_CHANNEL); process_start(&tcpip_process, NULL); printf("IPv6 "); { 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, 0xfc00, 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]); } #else /* WITH_UIP6 */ netstack_init(); printf("%s %lu %u\n", NETSTACK_RDC.name, CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0? 1: NETSTACK_RDC.channel_check_interval()), RF_CHANNEL); #endif /* WITH_UIP6 */ #if !WITH_UIP6 uart1_set_input(serial_line_input_byte); serial_line_init(); #endif #ifdef NETSTACK_AES_H #ifndef NETSTACK_AES_KEY #error Please define NETSTACK_AES_KEY! #endif /* NETSTACK_AES_KEY */ { const uint8_t key[] = NETSTACK_AES_KEY; netstack_aes_set_key(key); } /*printf("AES encryption is enabled: '%s'\n", NETSTACK_AES_KEY);*/ printf("AES encryption is enabled\n"); #else /* NETSTACK_AES_H */ printf("Warning: AES encryption is disabled\n"); #endif /* NETSTACK_AES_H */ #if TIMESYNCH_CONF_ENABLED timesynch_init(); timesynch_set_authority_level(rimeaddr_node_addr.u8[0]); #endif /* TIMESYNCH_CONF_ENABLED */ #if CC11xx_CC1101 || CC11xx_CC1120 printf("cc11xx radio at channel %d\n", RF_CHANNEL); cc11xx_channel_set(RF_CHANNEL); #endif /* CC11xx_CC1101 || CC11xx_CC1120 */ #if CONFIGURE_CC2420 { uint8_t longaddr[8]; uint16_t shortaddr; shortaddr = (rimeaddr_node_addr.u8[0] << 8) + rimeaddr_node_addr.u8[1]; memset(longaddr, 0, sizeof(longaddr)); rimeaddr_copy((rimeaddr_t *)&longaddr, &rimeaddr_node_addr); printf("MAC %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n", longaddr[0], longaddr[1], longaddr[2], longaddr[3], longaddr[4], longaddr[5], longaddr[6], longaddr[7]); cc2420_set_pan_addr(IEEE802154_PANID, shortaddr, longaddr); } cc2420_set_channel(RF_CHANNEL); #endif /* CONFIGURE_CC2420 */ NETSTACK_RADIO.on(); /* process_start(&sensors_process, NULL); SENSORS_ACTIVATE(button_sensor);*/ energest_init(); ENERGEST_ON(ENERGEST_TYPE_CPU); simple_rpl_init(); watchdog_start(); print_processes(autostart_processes); autostart_start(autostart_processes); duty_cycle_scroller_start(CLOCK_SECOND * 2); #if IP64_CONF_UIP_FALLBACK_INTERFACE_SLIP && WITH_SLIP /* Start the SLIP */ printf("Initiating SLIP: my IP is 172.16.0.2...\n"); slip_arch_init(0); { uip_ip4addr_t ipv4addr, netmask; uip_ipaddr(&ipv4addr, 172, 16, 0, 2); uip_ipaddr(&netmask, 255, 255, 255, 0); ip64_set_ipv4_address(&ipv4addr, &netmask); } uart1_set_input(slip_input_byte); #endif /* IP64_CONF_UIP_FALLBACK_INTERFACE_SLIP */ /* * This is the scheduler loop. */ while(1) { int r; do { /* Reset watchdog. */ watchdog_periodic(); r = process_run(); } while(r > 0); /* * Idle processing. */ int s = splhigh(); /* Disable interrupts. */ /* uart1_active is for avoiding LPM3 when still sending or receiving */ if(process_nevents() != 0 || uart1_active()) { splx(s); /* Re-enable interrupts. */ } else { static unsigned long irq_energest = 0; /* Re-enable interrupts and go to sleep atomically. */ ENERGEST_OFF(ENERGEST_TYPE_CPU); ENERGEST_ON(ENERGEST_TYPE_LPM); /* We only want to measure the processing done in IRQs when we are asleep, so we discard the processing time done when we were awake. */ energest_type_set(ENERGEST_TYPE_IRQ, irq_energest); watchdog_stop(); _BIS_SR(GIE | SCG0 | SCG1 | CPUOFF); /* LPM3 sleep. This statement will block until the CPU is woken up by an interrupt that sets the wake up flag. */ /* We get the current processing time for interrupts that was done during the LPM and store it for next time around. */ dint(); irq_energest = energest_type_time(ENERGEST_TYPE_IRQ); eint(); watchdog_start(); ENERGEST_OFF(ENERGEST_TYPE_LPM); ENERGEST_ON(ENERGEST_TYPE_CPU); } } }
/*--------------------------------------------------------------------------*/ int main(int argc, char **argv) { /* * Initalize hardware. */ msp430_cpu_init(); clock_init(); leds_init(); leds_on(LEDS_RED); uart1_init(BAUD2UBR(115200)); /* Must come before first printf */ #if NETSTACK_CONF_WITH_IPV4 slip_arch_init(BAUD2UBR(115200)); #endif /* NETSTACK_CONF_WITH_IPV4 */ leds_on(LEDS_GREEN); /* xmem_init(); */ rtimer_init(); lcd_init(); PRINTF(CONTIKI_VERSION_STRING "\n"); /* * Hardware initialization done! */ leds_on(LEDS_RED); /* Restore node id if such has been stored in external mem */ // node_id_restore(); #ifdef NODEID node_id = NODEID; #ifdef BURN_NODEID flash_setup(); flash_clear(0x1800); flash_write(0x1800, node_id); flash_done(); #endif /* BURN_NODEID */ #endif /* NODE_ID */ if(node_id == 0) { node_id = *((unsigned short *)0x1800); } memset(node_mac, 0, sizeof(node_mac)); node_mac[6] = node_id >> 8; node_mac[7] = node_id & 0xff; /* for setting "hardcoded" IEEE 802.15.4 MAC addresses */ #ifdef MAC_1 { uint8_t ieee[] = { MAC_1, MAC_2, MAC_3, MAC_4, MAC_5, MAC_6, MAC_7, MAC_8 }; memcpy(node_mac, ieee, sizeof(uip_lladdr.addr)); } #endif /* * Initialize Contiki and our processes. */ process_init(); process_start(&etimer_process, NULL); ctimer_init(); set_rime_addr(); cc2420_init(); { 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\n", longaddr[0], longaddr[1], longaddr[2], longaddr[3], longaddr[4], longaddr[5], longaddr[6], longaddr[7]); cc2420_set_pan_addr(IEEE802154_PANID, shortaddr, longaddr); } leds_off(LEDS_ALL); if(node_id > 0) { PRINTF("Node id %u.\n", node_id); } else { PRINTF("Node id not set.\n"); } #if NETSTACK_CONF_WITH_IPV6 memcpy(&uip_lladdr.addr, node_mac, sizeof(uip_lladdr.addr)); /* Setup nullmac-like MAC for 802.15.4 */ queuebuf_init(); NETSTACK_RDC.init(); NETSTACK_MAC.init(); NETSTACK_NETWORK.init(); printf("%s %lu %u\n", NETSTACK_RDC.name, CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1: NETSTACK_RDC.channel_check_interval()), CC2420_CONF_CHANNEL); process_start(&tcpip_process, NULL); printf("IPv6 "); { 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(!UIP_CONF_IPV6_RPL) { uip_ipaddr_t ipaddr; int i; uip_ip6addr(&ipaddr, UIP_DS6_DEFAULT_PREFIX, 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]); } #else /* NETSTACK_CONF_WITH_IPV6 */ NETSTACK_RDC.init(); NETSTACK_MAC.init(); NETSTACK_NETWORK.init(); printf("%s %lu %u\n", NETSTACK_RDC.name, CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0? 1: NETSTACK_RDC.channel_check_interval()), CC2420_CONF_CHANNEL); #endif /* NETSTACK_CONF_WITH_IPV6 */ #if !NETSTACK_CONF_WITH_IPV6 uart1_set_input(serial_line_input_byte); serial_line_init(); #endif #if TIMESYNCH_CONF_ENABLED timesynch_init(); timesynch_set_authority_level(linkaddr_node_addr.u8[0]); #endif /* TIMESYNCH_CONF_ENABLED */ /* process_start(&sensors_process, NULL); SENSORS_ACTIVATE(button_sensor);*/ energest_init(); ENERGEST_ON(ENERGEST_TYPE_CPU); print_processes(autostart_processes); autostart_start(autostart_processes); duty_cycle_scroller_start(CLOCK_SECOND * 2); /* * This is the scheduler loop. */ watchdog_start(); watchdog_stop(); /* Stop the wdt... */ while(1) { int r; do { /* Reset watchdog. */ watchdog_periodic(); r = process_run(); } while(r > 0); /* * Idle processing. */ int s = splhigh(); /* Disable interrupts. */ /* uart1_active is for avoiding LPM3 when still sending or receiving */ if(process_nevents() != 0 || uart1_active()) { splx(s); /* Re-enable interrupts. */ } else { static unsigned long irq_energest = 0; /* Re-enable interrupts and go to sleep atomically. */ ENERGEST_SWITCH(ENERGEST_TYPE_CPU, ENERGEST_TYPE_LPM); /* We only want to measure the processing done in IRQs when we are asleep, so we discard the processing time done when we were awake. */ energest_type_set(ENERGEST_TYPE_IRQ, irq_energest); watchdog_stop(); _BIS_SR(GIE | SCG0 | SCG1 | CPUOFF); /* LPM3 sleep. This statement will block until the CPU is woken up by an interrupt that sets the wake up flag. */ /* We get the current processing time for interrupts that was done during the LPM and store it for next time around. */ dint(); irq_energest = energest_type_time(ENERGEST_TYPE_IRQ); eint(); watchdog_start(); ENERGEST_SWITCH(ENERGEST_TYPE_LPM, ENERGEST_TYPE_CPU); } } }
/*---------------------------------------------------------------------------*/ int main(int argc, char **argv) { /* * Initalize hardware. */ msp430_cpu_init(); clock_init(); leds_init(); leds_on(LEDS_RED); clock_wait(100); uart0_init(BAUD2UBR(UART0_BAUD_RATE)); /* Must come before first printf */ #if NETSTACK_CONF_WITH_IPV4 slip_arch_init(BAUD2UBR(UART0_BAUD_RATE)); #endif /* NETSTACK_CONF_WITH_IPV4 */ xmem_init(); rtimer_init(); /* * Hardware initialization done! */ /* Restore node id if such has been stored in external mem */ node_id_restore(); /* If no MAC address was burned, we use the node id or the Z1 product ID */ if(!(node_mac[0] | node_mac[1] | node_mac[2] | node_mac[3] | node_mac[4] | node_mac[5] | node_mac[6] | node_mac[7])) { #ifdef SERIALNUM if(!node_id) { PRINTF("Node id is not set, using Z1 product ID\n"); node_id = SERIALNUM; } #endif node_mac[0] = 0xc1; /* Hardcoded for Z1 */ node_mac[1] = 0x0c; /* Hardcoded for Revision C */ node_mac[2] = 0x00; /* Hardcoded to arbitrary even number so that the 802.15.4 MAC address is compatible with an Ethernet MAC address - byte 0 (byte 2 in the DS ID) */ node_mac[3] = 0x00; /* Hardcoded */ node_mac[4] = 0x00; /* Hardcoded */ node_mac[5] = 0x00; /* Hardcoded */ node_mac[6] = node_id >> 8; node_mac[7] = node_id & 0xff; } /* Overwrite node MAC if desired at compile time */ #ifdef MACID #warning "***** CHANGING DEFAULT MAC *****" node_mac[0] = 0xc1; /* Hardcoded for Z1 */ node_mac[1] = 0x0c; /* Hardcoded for Revision C */ node_mac[2] = 0x00; /* Hardcoded to arbitrary even number so that the 802.15.4 MAC address is compatible with an Ethernet MAC address - byte 0 (byte 2 in the DS ID) */ node_mac[3] = 0x00; /* Hardcoded */ node_mac[4] = 0x00; /* Hardcoded */ node_mac[5] = 0x00; /* Hardcoded */ node_mac[6] = MACID >> 8; node_mac[7] = MACID & 0xff; #endif #ifdef IEEE_802154_MAC_ADDRESS /* for setting "hardcoded" IEEE 802.15.4 MAC addresses */ { uint8_t ieee[] = IEEE_802154_MAC_ADDRESS; memcpy(node_mac, ieee, sizeof(uip_lladdr.addr)); node_mac[7] = node_id & 0xff; } #endif /* IEEE_802154_MAC_ADDRESS */ /* * Initialize Contiki and our processes. */ random_init(node_mac[6] + node_mac[7]); process_init(); process_start(&etimer_process, NULL); ctimer_init(); init_platform(); set_rime_addr(); cc2420_init(); SENSORS_ACTIVATE(adxl345); { 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]); cc2420_set_pan_addr(IEEE802154_PANID, shortaddr, longaddr); } leds_off(LEDS_ALL); #ifdef SERIALNUM PRINTF("Ref ID: %u\n", SERIALNUM); #endif PRINTF(CONTIKI_VERSION_STRING " started. "); if(node_id) { PRINTF("Node id is set to %u.\n", node_id); } else { PRINTF("Node id not set\n"); } #if NETSTACK_CONF_WITH_IPV6 memcpy(&uip_lladdr.addr, node_mac, sizeof(uip_lladdr.addr)); /* Setup nullmac-like MAC for 802.15.4 */ /* sicslowpan_init(sicslowmac_init(&cc2420_driver)); */ /* printf(" %s channel %u\n", sicslowmac_driver.name, CC2420_CONF_CHANNEL); */ /* Setup X-MAC for 802.15.4 */ queuebuf_init(); netstack_init(); // NETSTACK_RDC.init(); // NETSTACK_MAC.init(); // NETSTACK_LLSEC.init(); // NETSTACK_NETWORK.init(); printf("%s %s %s, channel check rate %lu Hz, radio channel %u\n", NETSTACK_LLSEC.name, NETSTACK_MAC.name, NETSTACK_RDC.name, CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1 : NETSTACK_RDC.channel_check_interval()), CC2420_CONF_CHANNEL); 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(!UIP_CONF_IPV6_RPL) { uip_ipaddr_t ipaddr; int i; uip_ip6addr(&ipaddr, UIP_DS6_DEFAULT_PREFIX, 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]); } #else /* NETSTACK_CONF_WITH_IPV6 */ netstack_init(); //NETSTACK_RDC.init(); //NETSTACK_MAC.init(); //NETSTACK_LLSEC.init(); //NETSTACK_NETWORK.init(); printf("%s %s %s, channel check rate %lu Hz, radio channel %u\n", NETSTACK_LLSEC.name, NETSTACK_MAC.name, NETSTACK_RDC.name, CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1 : NETSTACK_RDC.channel_check_interval()), CC2420_CONF_CHANNEL); #endif /* NETSTACK_CONF_WITH_IPV6 */ #if !NETSTACK_CONF_WITH_IPV4 && !NETSTACK_CONF_WITH_IPV6 uart0_set_input(serial_line_input_byte); serial_line_init(); #endif leds_off(LEDS_GREEN); #if TIMESYNCH_CONF_ENABLED timesynch_init(); timesynch_set_authority_level(linkaddr_node_addr.u8[0]); #endif /* TIMESYNCH_CONF_ENABLED */ #if NETSTACK_CONF_WITH_IPV4 process_start(&tcpip_process, NULL); process_start(&uip_fw_process, NULL); /* Start IP output */ process_start(&slip_process, NULL); slip_set_input_callback(set_gateway); { uip_ipaddr_t hostaddr, netmask; uip_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_fw_register(&slipif);*/ uip_over_mesh_set_gateway_netif(&slipif); uip_fw_default(&meshif); uip_over_mesh_init(UIP_OVER_MESH_CHANNEL); printf("uIP started with IP address %d.%d.%d.%d\n", uip_ipaddr_to_quad(&hostaddr)); } #endif /* NETSTACK_CONF_WITH_IPV4 */ energest_init(); ENERGEST_ON(ENERGEST_TYPE_CPU); print_processes(autostart_processes); autostart_start(autostart_processes); /* * This is the scheduler loop. */ #if DCOSYNCH_CONF_ENABLED timer_set(&mgt_timer, DCOSYNCH_PERIOD * CLOCK_SECOND); #endif watchdog_start(); /* watchdog_stop();*/ while(1) { int r; do { /* Reset watchdog. */ watchdog_periodic(); r = process_run(); } while(r > 0); /* * Idle processing. */ int s = splhigh(); /* Disable interrupts. */ /* uart0_active is for avoiding LPM3 when still sending or receiving */ if(process_nevents() != 0 || uart0_active()) { splx(s); /* Re-enable interrupts. */ } else { static unsigned long irq_energest = 0; #if DCOSYNCH_CONF_ENABLED /* before going down to sleep possibly do some management */ if(timer_expired(&mgt_timer)) { timer_reset(&mgt_timer); msp430_sync_dco(); } #endif /* Re-enable interrupts and go to sleep atomically. */ ENERGEST_SWITCH(ENERGEST_TYPE_CPU, ENERGEST_TYPE_LPM); /* We only want to measure the processing done in IRQs when we are asleep, so we discard the processing time done when we were awake. */ energest_type_set(ENERGEST_TYPE_IRQ, irq_energest); watchdog_stop(); _BIS_SR(GIE | SCG0 | SCG1 | CPUOFF); /* LPM3 sleep. This statement will block until the CPU is woken up by an interrupt that sets the wake up flag. */ /* We get the current processing time for interrupts that was done during the LPM and store it for next time around. */ dint(); irq_energest = energest_type_time(ENERGEST_TYPE_IRQ); eint(); watchdog_start(); ENERGEST_SWITCH(ENERGEST_TYPE_LPM, ENERGEST_TYPE_CPU); } } return 0; }
int main(void) { #if WITH_SD int r; #endif /* WITH_SD */ msp430_cpu_init(); watchdog_stop(); /* Platform-specific initialization. */ msb_ports_init(); adc_init(); clock_init(); rtimer_init(); sht11_init(); leds_init(); leds_on(LEDS_ALL); irq_init(); process_init(); /* serial interface */ rs232_set_input(serial_line_input_byte); rs232_init(); serial_line_init(); uart_lock(UART_MODE_RS232); uart_unlock(UART_MODE_RS232); #if WITH_UIP slip_arch_init(BAUD2UBR(115200)); #endif #if WITH_SD r = sd_initialize(); if(r < 0) { printf("Failed to initialize the SD driver: %s\n", sd_error_string(r)); } else { sd_offset_t capacity; printf("The SD driver was successfully initialized\n"); capacity = sd_get_capacity(); if(capacity < 0) { printf("Failed to get the SD card capacity: %s\n", sd_error_string(r)); } else { printf("SD card capacity: %u MB\n", (unsigned)(capacity / (1024UL * 1024))); } } #endif /* System services */ process_start(&etimer_process, NULL); ctimer_init(); node_id_restore(); init_net(); energest_init(); #if PROFILE_CONF_ON profile_init(); #endif /* PROFILE_CONF_ON */ leds_off(LEDS_ALL); printf(CONTIKI_VERSION_STRING " started. Node id %u, using %s.\n", node_id, rime_mac->name); autostart_start(autostart_processes); /* * This is the scheduler loop. */ ENERGEST_ON(ENERGEST_TYPE_CPU); while (1) { int r; #if PROFILE_CONF_ON profile_episode_start(); #endif /* PROFILE_CONF_ON */ do { /* Reset watchdog. */ watchdog_periodic(); r = process_run(); } while(r > 0); #if PROFILE_CONF_ON profile_episode_end(); #endif /* PROFILE_CONF_ON */ /* * Idle processing. */ int s = splhigh(); /* Disable interrupts. */ if (process_nevents() != 0) { splx(s); /* Re-enable interrupts. */ } else { static unsigned long irq_energest = 0; /* Re-enable interrupts and go to sleep atomically. */ ENERGEST_OFF(ENERGEST_TYPE_CPU); ENERGEST_ON(ENERGEST_TYPE_LPM); /* * We only want to measure the processing done in IRQs when we * are asleep, so we discard the processing time done when we * were awake. */ energest_type_set(ENERGEST_TYPE_IRQ, irq_energest); if (uart_edge) { _BIC_SR(LPM1_bits + GIE); } else { _BIS_SR(LPM1_bits + GIE); } /* * We get the current processing time for interrupts that was * done during the LPM and store it for next time around. */ dint(); irq_energest = energest_type_time(ENERGEST_TYPE_IRQ); eint(); ENERGEST_OFF(ENERGEST_TYPE_LPM); ENERGEST_ON(ENERGEST_TYPE_CPU); #if PROFILE_CONF_ON profile_clear_timestamps(); #endif /* PROFILE_CONF_ON */ } } return 0; }
int main(int argc, char **argv) { /* * Initalize hardware. */ msp430_cpu_init(); clock_init(); leds_init(); leds_toggle(LEDS_ALL); slip_arch_init(BAUD2UBR(115200)); /* Must come before first printf */ printf("Starting %s " "($Id: dhclient.c,v 1.1 2008/05/27 13:16:34 adamdunkels Exp $)\n", __FILE__); ds2411_init(); sensors_light_init(); cc2420_init(); xmem_init(); button_init(&button_process); leds_toggle(LEDS_ALL); /* * Hardware initialization done! */ printf("MAC %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x CHANNEL %d\n", ds2411_id[0], ds2411_id[1], ds2411_id[2], ds2411_id[3], ds2411_id[4], ds2411_id[5], ds2411_id[6], ds2411_id[7], RF_CHANNEL); srand(rand() + (ds2411_id[3]<<8) + (ds2411_id[4]<<6) + (ds2411_id[5]<<4) + (ds2411_id[6]<<2) + ds2411_id[7]); /* * Initialize Contiki and our processes. */ process_init(); process_start(&etimer_process, NULL); /* Configure IP stack. */ uip_init(); /* Start IP stack. */ process_start(&tcpip_process, NULL); process_start(&uip_fw_process, NULL); /* Start IP output */ process_start(&cc2420_process, NULL); cc2420_on(); process_start(&dhclient_process, NULL); process_start(&button_process, NULL); process_start(&tcp_loader_process, NULL); /* * This is the scheduler loop. */ printf("process_run()...\n"); while (1) { do { /* Reset watchdog. */ } while(process_run() > 0); /* * Idle processing. */ int s = splhigh(); /* Disable interrupts. */ if(process_nevents() != 0) { splx(s); /* Re-enable interrupts. */ } else { /* Re-enable interrupts and go to sleep atomically. */ _BIS_SR(GIE | SCG0 | CPUOFF); /* LPM1 sleep. */ } } return 0; }
/*---------------------------------------------------------------------------*/ int main() { static uint32_t idle_count = 0; /* * OpenLab Platform init * */ platform_init(); /* * Contiki core * */ clock_init(); process_init(); rtimer_init(); process_start(&etimer_process, NULL); ctimer_init(); /* * Sensors * * registered sensors: button * * TODO: add lsm303dlhc + l3g4200 + lps331 */ process_start(&sensors_process, NULL); /* * Network * */ netstack_init(); set_rime_addr(); #if UIP_CONF_IPV6 memcpy(&uip_lladdr.addr, &rimeaddr_node_addr, sizeof(uip_lladdr.addr)); process_start(&tcpip_process, NULL); #if VIZTOOL_CONF_ON process_start(&viztool_process, NULL); #endif #if (!UIP_CONF_IPV6_RPL) { uip_ipaddr_t ipaddr; uip_ip6addr(&ipaddr, 0x2001, 0x630, 0x301, 0x6453, 0, 0, 0, 0); uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr); uip_ds6_addr_add(&ipaddr, 0, ADDR_TENTATIVE); } #endif /* UIP_CONF_IPV6_RPL */ #endif /* UIP_CONF_IPV6 */ /* * init serial line */ serial_line_init(); uart_set_rx_handler(uart_print, char_rx, NULL); /* * eventually init slip device * wich may override serial line */ #if SLIP_ARCH_CONF_ENABLE #ifndef UIP_CONF_LLH_LEN #error "LLH_LEN is not defined" #elif UIP_CONF_LLH_LEN != 0 #error "LLH_LEN must be 0 to use slip interface" #endif slip_arch_init(SLIP_ARCH_CONF_BAUDRATE); #endif /* * Start */ print_processes(autostart_processes); autostart_start(autostart_processes); watchdog_start(); while(1) { int r; do { watchdog_periodic(); r = process_run(); } while(r > 0); idle_count++; } return 0; }
/*---------------------------------------------------------------------------*/ int main(int argc, char **argv) { /* * Initalize hardware. */ msp430_cpu_init(); clock_init(); leds_init(); leds_on(LEDS_RED); uart1_init(BAUD2UBR(115200)); /* Must come before first printf */ #if WITH_UIP slip_arch_init(BAUD2UBR(115200)); #endif /* WITH_UIP */ leds_on(LEDS_GREEN); ds2411_init(); /* XXX hack: Fix it so that the 802.15.4 MAC address is compatible with an Ethernet MAC address - byte 0 (byte 2 in the DS ID) cannot be odd. */ ds2411_id[2] &= 0xfe; leds_on(LEDS_BLUE); xmem_init(); leds_off(LEDS_RED); rtimer_init(); /* * Hardware initialization done! */ /* Restore node id if such has been stored in external mem */ node_id_restore(); random_init(ds2411_id[0] + node_id); leds_off(LEDS_BLUE); /* * Initialize Contiki and our processes. */ process_init(); process_start(&etimer_process, NULL); process_start(&sensors_process, NULL); /* * Initialize light and humidity/temp sensors. */ sensors_light_init(); battery_sensor.activate(); sht11_init(); ctimer_init(); cc2420_init(); cc2420_set_pan_addr(IEEE802154_PANID, 0 /*XXX*/, ds2411_id); cc2420_set_channel(RF_CHANNEL); 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(); printf("MAC %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x", ds2411_id[0], ds2411_id[1], ds2411_id[2], ds2411_id[3], ds2411_id[4], ds2411_id[5], ds2411_id[6], ds2411_id[7]); #if WITH_UIP6 memcpy(&uip_lladdr.addr, ds2411_id, sizeof(uip_lladdr.addr)); sicslowpan_init(sicslowmac_init(&cc2420_driver)); process_start(&tcpip_process, NULL); printf(" %s channel %u\n", sicslowmac_driver.name, RF_CHANNEL); #if UIP_CONF_ROUTER rime_init(rime_udp_init(NULL)); uip_router_register(&rimeroute); #endif /* UIP_CONF_ROUTER */ #else /* WITH_UIP6 */ rime_init(MAC_DRIVER.init(&cc2420_driver)); printf(" %s channel %u\n", rime_mac->name, RF_CHANNEL); #endif /* WITH_UIP6 */ #if !WITH_UIP && !WITH_UIP6 uart1_set_input(serial_line_input_byte); serial_line_init(); #endif #if PROFILE_CONF_ON profile_init(); #endif /* PROFILE_CONF_ON */ leds_off(LEDS_GREEN); #if WITH_FTSP ftsp_init(); #endif /* WITH_FTSP */ #if TIMESYNCH_CONF_ENABLED timesynch_init(); timesynch_set_authority_level(rimeaddr_node_addr.u8[0]); #endif /* TIMESYNCH_CONF_ENABLED */ #if WITH_UIP process_start(&tcpip_process, NULL); process_start(&uip_fw_process, NULL); /* Start IP output */ process_start(&slip_process, NULL); slip_set_input_callback(set_gateway); { uip_ipaddr_t hostaddr, netmask; uip_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_fw_register(&slipif);*/ uip_over_mesh_set_gateway_netif(&slipif); uip_fw_default(&meshif); uip_over_mesh_init(UIP_OVER_MESH_CHANNEL); printf("uIP started with IP address %d.%d.%d.%d\n", uip_ipaddr_to_quad(&hostaddr)); } #endif /* WITH_UIP */ button_sensor.activate(); energest_init(); ENERGEST_ON(ENERGEST_TYPE_CPU); print_processes(autostart_processes); autostart_start(autostart_processes); /* * This is the scheduler loop. */ #if DCOSYNCH_CONF_ENABLED timer_set(&mgt_timer, DCOSYNCH_PERIOD * CLOCK_SECOND); #endif watchdog_start(); /* watchdog_stop();*/ while(1) { int r; #if PROFILE_CONF_ON profile_episode_start(); #endif /* PROFILE_CONF_ON */ do { /* Reset watchdog. */ watchdog_periodic(); r = process_run(); } while(r > 0); #if PROFILE_CONF_ON profile_episode_end(); #endif /* PROFILE_CONF_ON */ /* * Idle processing. */ int s = splhigh(); /* Disable interrupts. */ /* uart1_active is for avoiding LPM3 when still sending or receiving */ if(process_nevents() != 0 || uart1_active()) { splx(s); /* Re-enable interrupts. */ } else { static unsigned long irq_energest = 0; #if DCOSYNCH_CONF_ENABLED /* before going down to sleep possibly do some management */ if (timer_expired(&mgt_timer)) { timer_reset(&mgt_timer); msp430_sync_dco(); } #endif /* Re-enable interrupts and go to sleep atomically. */ ENERGEST_OFF(ENERGEST_TYPE_CPU); ENERGEST_ON(ENERGEST_TYPE_LPM); /* We only want to measure the processing done in IRQs when we are asleep, so we discard the processing time done when we were awake. */ energest_type_set(ENERGEST_TYPE_IRQ, irq_energest); watchdog_stop(); _BIS_SR(GIE | SCG0 | SCG1 | CPUOFF); /* LPM3 sleep. This statement will block until the CPU is woken up by an interrupt that sets the wake up flag. */ /* We get the current processing time for interrupts that was done during the LPM and store it for next time around. */ dint(); irq_energest = energest_type_time(ENERGEST_TYPE_IRQ); eint(); watchdog_start(); ENERGEST_OFF(ENERGEST_TYPE_LPM); ENERGEST_ON(ENERGEST_TYPE_CPU); } } return 0; }
/*---------------------------------------------------------------------------*/ #if WITH_TINYOS_AUTO_IDS uint16_t TOS_NODE_ID = 0x1234; /* non-zero */ uint16_t TOS_LOCAL_ADDRESS = 0x1234; /* non-zero */ #endif /* WITH_TINYOS_AUTO_IDS */ int main(void) { /* Set stack overflow address for detecting overflow in runtime */ vAHI_SetStackOverflow(TRUE, ((uint32_t *)&heap_location)[0]); /* Initialize random with a seed from the SoC random generator. * This must be done before selecting the high-precision external oscillator. */ vAHI_StartRandomNumberGenerator(E_AHI_RND_SINGLE_SHOT, E_AHI_INTS_DISABLED); random_init(u16AHI_ReadRandomNumber()); clock_init(); rtimer_init(); #if JN516X_EXTERNAL_CRYSTAL_OSCILLATOR /* initialize the 32kHz crystal and wait for ready */ xosc_init(); /* need to reinitialize because the wait-for-ready process uses system timers */ clock_init(); rtimer_init(); #endif watchdog_init(); leds_init(); leds_on(LEDS_ALL); init_node_mac(); energest_init(); ENERGEST_ON(ENERGEST_TYPE_CPU); node_id_restore(); #if WITH_TINYOS_AUTO_IDS node_id = TOS_NODE_ID; #endif /* WITH_TINYOS_AUTO_IDS */ /* for setting "hardcoded" IEEE 802.15.4 MAC addresses */ #ifdef IEEE_802154_MAC_ADDRESS { uint8_t ieee[] = IEEE_802154_MAC_ADDRESS; memcpy(node_mac, ieee, sizeof(uip_lladdr.addr)); node_mac[7] = node_id & 0xff; } #endif process_init(); ctimer_init(); uart0_init(UART_BAUD_RATE); /* Must come before first PRINTF */ #if NETSTACK_CONF_WITH_IPV4 slip_arch_init(UART_BAUD_RATE); #endif /* NETSTACK_CONF_WITH_IPV4 */ /* check for reset source */ if(bAHI_WatchdogResetEvent()) { PRINTF("Init: Watchdog timer has reset device!\r\n"); } process_start(&etimer_process, NULL); set_linkaddr(); netstack_init(); #if NETSTACK_CONF_WITH_IPV6 #if UIP_CONF_IPV6_RPL PRINTF(CONTIKI_VERSION_STRING " started with IPV6, RPL\n"); #else PRINTF(CONTIKI_VERSION_STRING " started with IPV6\n"); #endif #elif NETSTACK_CONF_WITH_IPV4 PRINTF(CONTIKI_VERSION_STRING " started with IPV4\n"); #else PRINTF(CONTIKI_VERSION_STRING " started\n"); #endif if(node_id > 0) { PRINTF("Node id is set to %u.\n", node_id); } else { PRINTF("Node id is not set.\n"); } #if NETSTACK_CONF_WITH_IPV6 memcpy(&uip_lladdr.addr, node_mac, sizeof(uip_lladdr.addr)); queuebuf_init(); #endif /* NETSTACK_CONF_WITH_IPV6 */ PRINTF("%s %s %s\n", NETSTACK_LLSEC.name, NETSTACK_MAC.name, NETSTACK_RDC.name); #if !NETSTACK_CONF_WITH_IPV4 && !NETSTACK_CONF_WITH_IPV6 uart0_set_input(serial_line_input_byte); serial_line_init(); #endif #if TIMESYNCH_CONF_ENABLED timesynch_init(); timesynch_set_authority_level((linkaddr_node_addr.u8[0] << 4) + 16); #endif /* TIMESYNCH_CONF_ENABLED */ #if NETSTACK_CONF_WITH_IPV4 process_start(&tcpip_process, NULL); process_start(&uip_fw_process, NULL); /* Start IP output */ process_start(&slip_process, NULL); slip_set_input_callback(set_gateway); { uip_ipaddr_t hostaddr, netmask; uip_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_fw_register(&slipif);*/ uip_over_mesh_set_gateway_netif(&slipif); uip_fw_default(&meshif); uip_over_mesh_init(UIP_OVER_MESH_CHANNEL); PRINTF("uIP started with IP address %d.%d.%d.%d\n", uip_ipaddr_to_quad(&hostaddr)); } #endif /* NETSTACK_CONF_WITH_IPV4 */ watchdog_start(); NETSTACK_LLSEC.init(); #if NETSTACK_CONF_WITH_IPV6 start_uip6(); #endif /* NETSTACK_CONF_WITH_IPV6 */ /* need this to reliably generate the first rtimer callback and callbacks in other auto-start processes */ (void)u32AHI_Init(); start_autostart_processes(); leds_off(LEDS_ALL); main_loop(); return -1; }
/** * \brief Main function for nRF52dk platform. * \note This function doesn't return. */ int main(void) { board_init(); leds_init(); clock_init(); rtimer_init(); watchdog_init(); process_init(); // Seed value is ignored since hardware RNG is used. random_init(0); #ifdef UART0_ENABLED uart0_init(); #if SLIP_ARCH_CONF_ENABLE slip_arch_init(0); #else uart0_set_input(serial_line_input_byte); serial_line_init(); #endif #endif PRINTF("Starting " CONTIKI_VERSION_STRING "\n"); process_start(&etimer_process, NULL); ctimer_init(); #if ENERGEST_CONF_ON energest_init(); ENERGEST_ON(ENERGEST_TYPE_CPU); #endif #ifdef SOFTDEVICE_PRESENT ble_stack_init(); ble_advertising_init(DEVICE_NAME); #if NETSTACK_CONF_WITH_IPV6 netstack_init(); linkaddr_t linkaddr; ble_get_mac(linkaddr.u8); /* Set link layer address */ linkaddr_set_node_addr(&linkaddr); /* Set device link layer address in uip stack */ memcpy(&uip_lladdr.addr, &linkaddr, sizeof(uip_lladdr.addr)); process_start(&ble_iface_observer, NULL); process_start(&tcpip_process, NULL); #endif /* NETSTACK_CONF_WITH_IPV6 */ #endif /* SOFTDEVICE_PRESENT */ process_start(&sensors_process, NULL); autostart_start(autostart_processes); watchdog_start(); #ifdef SOFTDEVICE_PRESENT ble_advertising_start(); PRINTF("Advertising name [%s]\n", DEVICE_NAME); #endif while(1) { uint8_t r; do { r = process_run(); watchdog_periodic(); } while(r > 0); lpm_drop(); } }
/*---------------------------------------------------------------------------*/ int main(void) { /* Hardware initialization */ clock_init(); soc_init(); rtimer_init(); /* Init LEDs here */ leds_init(); leds_off(LEDS_ALL); fade(LEDS_GREEN); /* initialize process manager. */ process_init(); /* Init UART */ uart0_init(); #if DMA_ON dma_init(); #endif #if SLIP_ARCH_CONF_ENABLE slip_arch_init(0); #else uart0_set_input(serial_line_input_byte); serial_line_init(); #endif fade(LEDS_RED); PUTSTRING("##########################################\n"); putstring(CONTIKI_VERSION_STRING "\n"); putstring("TI SmartRF05 EB\n"); switch(CHIPID) { case 0xA5: putstring("cc2530"); break; case 0xB5: putstring("cc2531"); break; case 0x95: putstring("cc2533"); break; case 0x8D: putstring("cc2540"); break; } putstring("-F"); switch(CHIPINFO0 & 0x70) { case 0x40: putstring("256, "); break; case 0x30: putstring("128, "); break; case 0x20: putstring("64, "); break; case 0x10: putstring("32, "); break; } puthex(CHIPINFO1 + 1); putstring("KB SRAM\n"); PUTSTRING("\nSDCC Build:\n"); #if STARTUP_VERBOSE #ifdef HAVE_SDCC_BANKING PUTSTRING(" With Banking.\n"); #endif /* HAVE_SDCC_BANKING */ #ifdef SDCC_MODEL_LARGE PUTSTRING(" --model-large\n"); #endif /* SDCC_MODEL_LARGE */ #ifdef SDCC_MODEL_HUGE PUTSTRING(" --model-huge\n"); #endif /* SDCC_MODEL_HUGE */ #ifdef SDCC_STACK_AUTO PUTSTRING(" --stack-auto\n"); #endif /* SDCC_STACK_AUTO */ PUTCHAR('\n'); PUTSTRING(" Net: "); PUTSTRING(NETSTACK_NETWORK.name); PUTCHAR('\n'); PUTSTRING(" MAC: "); PUTSTRING(NETSTACK_MAC.name); PUTCHAR('\n'); PUTSTRING(" RDC: "); PUTSTRING(NETSTACK_RDC.name); PUTCHAR('\n'); PUTSTRING("##########################################\n"); #endif watchdog_init(); /* Initialise the H/W RNG engine. */ random_init(0); /* start services */ process_start(&etimer_process, NULL); ctimer_init(); /* initialize the netstack */ netstack_init(); set_rime_addr(); #if BUTTON_SENSOR_ON || ADC_SENSOR_ON process_start(&sensors_process, NULL); BUTTON_SENSOR_ACTIVATE(); ADC_SENSOR_ACTIVATE(); #endif #if UIP_CONF_IPV6 memcpy(&uip_lladdr.addr, &rimeaddr_node_addr, sizeof(uip_lladdr.addr)); queuebuf_init(); process_start(&tcpip_process, NULL); #endif /* UIP_CONF_IPV6 */ #if VIZTOOL_CONF_ON process_start(&viztool_process, NULL); #endif energest_init(); ENERGEST_ON(ENERGEST_TYPE_CPU); autostart_start(autostart_processes); watchdog_start(); fade(LEDS_YELLOW); while(1) { do { /* Reset watchdog and handle polls and events */ watchdog_periodic(); #if CLOCK_CONF_STACK_FRIENDLY if(sleep_flag) { if(etimer_pending() && (etimer_next_expiration_time() - clock_time() - 1) > MAX_TICKS) { etimer_request_poll(); } sleep_flag = 0; } #endif r = process_run(); } while(r > 0); len = NETSTACK_RADIO.pending_packet(); if(len) { packetbuf_clear(); len = NETSTACK_RADIO.read(packetbuf_dataptr(), PACKETBUF_SIZE); if(len > 0) { packetbuf_set_datalen(len); NETSTACK_RDC.input(); } } #if LPM_MODE #if (LPM_MODE==LPM_MODE_PM2) SLEEP &= ~OSC_PD; /* Make sure both HS OSCs are on */ while(!(SLEEP & HFRC_STB)); /* Wait for RCOSC to be stable */ CLKCON |= OSC; /* Switch to the RCOSC */ while(!(CLKCON & OSC)); /* Wait till it's happened */ SLEEP |= OSC_PD; /* Turn the other one off */ #endif /* LPM_MODE==LPM_MODE_PM2 */ /* * Set MCU IDLE or Drop to PM1. Any interrupt will take us out of LPM * Sleep Timer will wake us up in no more than 7.8ms (max idle interval) */ SLEEPCMD = (SLEEPCMD & 0xFC) | (LPM_MODE - 1); #if (LPM_MODE==LPM_MODE_PM2) /* * Wait 3 NOPs. Either an interrupt occurred and SLEEP.MODE was cleared or * no interrupt occurred and we can safely power down */ __asm nop nop nop __endasm; if(SLEEPCMD & SLEEP_MODE0) { #endif /* LPM_MODE==LPM_MODE_PM2 */ ENERGEST_OFF(ENERGEST_TYPE_CPU); ENERGEST_ON(ENERGEST_TYPE_LPM); /* We are only interested in IRQ energest while idle or in LPM */ ENERGEST_IRQ_RESTORE(irq_energest); /* Go IDLE or Enter PM1 */ PCON |= PCON_IDLE; /* First instruction upon exiting PM1 must be a NOP */ __asm nop __endasm; /* Remember energest IRQ for next pass */ ENERGEST_IRQ_SAVE(irq_energest); ENERGEST_ON(ENERGEST_TYPE_CPU); ENERGEST_OFF(ENERGEST_TYPE_LPM); #if (LPM_MODE==LPM_MODE_PM2) SLEEPCMD &= ~SLEEP_OSC_PD; /* Make sure both HS OSCs are on */ while(!(SLEEPCMD & SLEEP_XOSC_STB)); /* Wait for XOSC to be stable */ CLKCONCMD &= ~CLKCONCMD_OSC; /* Switch to the XOSC */ /* * On occasion the XOSC is reported stable when in reality it's not. * We need to wait for a safeguard of 64us or more before selecting it */ clock_delay(10); while(CLKCONCMD & CLKCONCMD_OSC); /* Wait till it's happened */ } #endif /* LPM_MODE==LPM_MODE_PM2 */ #endif /* LPM_MODE */ } }
/** * \brief Main routine for the cc2538dk platform */ int main(void) { nvic_init(); sys_ctrl_init(); clock_init(); dint(); /*Init Watchdog*/ watchdog_init();//Need to check the watchdog on 123gxl rtimer_init(); lpm_init(); gpio_init(); ioc_init(); leds_init(); fade(LEDS_YELLOW); button_sensor_init(); /* * Character I/O Initialisation. * When the UART receives a character it will call serial_line_input_byte to * notify the core. The same applies for the USB driver. * * If slip-arch is also linked in afterwards (e.g. if we are a border router) * it will overwrite one of the two peripheral input callbacks. Characters * received over the relevant peripheral will be handled by * slip_input_byte instead */ #if UART_CONF_ENABLE uart_init(0); uart_init(1); uart_set_input(SERIAL_LINE_CONF_UART, serial_line_input_byte); #endif #if USB_SERIAL_CONF_ENABLE usb_serial_init(); usb_serial_set_input(serial_line_input_byte); #endif serial_line_init(); /*Enable EA*/ eint(); INTERRUPTS_ENABLE(); fade(LEDS_GREEN); PRINTF("=================================\r\n"); PUTS(CONTIKI_VERSION_STRING); PRINTF("======================\r\n"); PRINTF("\r\n"); PUTS(BOARD_STRING); PRINTF("\r\n"); #ifdef NODEID node_id = NODEID; #ifdef BURN_NODEID node_id_burn(node_id); node_id_restore(); /* also configures node_mac[] */ #endif /* BURN_NODEID */ #else node_id_restore(); /* also configures node_mac[] */ #endif /* NODE_ID */ /* for setting "hardcoded" IEEE 802.15.4 MAC addresses */ #ifdef MAC_1 { uint8_t ieee[] = { MAC_1, MAC_2, MAC_3, MAC_4, MAC_5, MAC_6, MAC_7, MAC_8 }; memcpy(node_mac, ieee, sizeof(uip_lladdr.addr)); } #endif /* * Initialize Contiki and our processes. */ process_init(); process_start(&sensors_process, NULL); button_sensor_init(); process_start(&etimer_process, NULL); ctimer_init(); set_rime_addr(); printf("finish addr seting\r\n"); /* Initialise the H/W RNG engine. */ random_init(0); udma_init(); if(node_id > 0) { printf("Node id %u.\r\n", node_id); } else { printf("Node id not set.\r\n"); } #if WITH_UIP6 memcpy(&uip_lladdr.addr, node_mac, sizeof(uip_lladdr.addr)); /* Setup nullmac-like MAC for 802.15.4 */ queuebuf_init(); netstack_init(); PRINTF("CC2538 IEEE802154 PANID %d\r\n", IEEE802154_PANID); cc2538_rf_set_addr(IEEE802154_PANID); printf("%s/%s %lu %u\r\n", NETSTACK_RDC.name, NETSTACK_MAC.name, CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1: NETSTACK_RDC.channel_check_interval()), RF_CHANNEL); process_start(&tcpip_process, NULL); printf("IPv6 "); { 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\r\n", lladdr->ipaddr.u8[14], lladdr->ipaddr.u8[15]); } if(1) { uip_ipaddr_t ipaddr; int i; uip_ip6addr(&ipaddr, 0xfc00, 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\r\n", ipaddr.u8[7 * 2], ipaddr.u8[7 * 2 + 1]); } #else /* WITH_UIP6 */ netstack_init(); PRINTF("CC2538 IEEE802154 PANID %d\r\n", IEEE802154_PANID); cc2538_rf_set_addr(IEEE802154_PANID); printf("%s %lu %u\r\n", NETSTACK_RDC.name, CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0? 1: NETSTACK_RDC.channel_check_interval()), RF_CHANNEL); #endif /* WITH_UIP6 */ #if !WITH_UIP6 uart1_set_input(serial_line_input_byte); serial_line_init(); #endif #ifdef NETSTACK_AES_H #ifndef NETSTACK_AES_KEY #error Please define NETSTACK_AES_KEY! #endif /* NETSTACK_AES_KEY */ { const uint8_t key[] = NETSTACK_AES_KEY; netstack_aes_set_key(key); } /*printf("AES encryption is enabled: '%s'\n", NETSTACK_AES_KEY);*/ printf("AES encryption is enabled\r\n"); #else /* NETSTACK_AES_H */ printf("Warning: AES encryption is disabled\r\n"); #endif /* NETSTACK_AES_H */ #if TIMESYNCH_CONF_ENABLED timesynch_init(); timesynch_set_authority_level(rimeaddr_node_addr.u8[0]); #endif /* TIMESYNCH_CONF_ENABLED */ energest_init(); ENERGEST_ON(ENERGEST_TYPE_CPU); simple_rpl_init(); /*Watch dog configuration*/ watchdog_periodic(); watchdog_start(); autostart_start(autostart_processes); //duty_cycle_scroller_start(CLOCK_SECOND * 2); #if IP64_CONF_UIP_FALLBACK_INTERFACE_SLIP && WITH_SLIP /* Start the SLIP */ printf("Initiating SLIP: my IP is 172.16.0.2...\r\n"); slip_arch_init(0); { uip_ip4addr_t ipv4addr, netmask; uip_ipaddr(&ipv4addr, 172, 16, 0, 2); uip_ipaddr(&netmask, 255, 255, 255, 0); ip64_set_ipv4_address(&ipv4addr, &netmask); } uart1_set_input(slip_input_byte); #endif /* IP64_CONF_UIP_FALLBACK_INTERFACE_SLIP */ fade(LEDS_ORANGE); /* * This is the scheduler loop. */ while(1) { uint8_t r; do { /* Reset watchdog and handle polls and events */ // printf("reset watchdog\r\n"); watchdog_periodic(); r = process_run(); } while(r > 0); /* We have serviced all pending events. Enter a Low-Power mode. */ lpm_enter(); } }
int main(int argc, char **argv) { /* * Initalize hardware. */ msp430_cpu_init(); clock_init(); leds_init(); leds_toggle(LEDS_ALL); slip_arch_init(BAUD2UBR(115200)); /* Must come before first printf */ printf("Starting %s " "($Id: client.c,v 1.1 2008/05/27 13:16:34 adamdunkels Exp $)\n", __FILE__); ds2411_init(); sensors_light_init(); cc2420_init(); xmem_init(); button_init(&button_process); leds_toggle(LEDS_ALL); /* * Hardware initialization done! */ printf("MAC %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x CHANNEL %d\n", ds2411_id[0], ds2411_id[1], ds2411_id[2], ds2411_id[3], ds2411_id[4], ds2411_id[5], ds2411_id[6], ds2411_id[7], RF_CHANNEL); uip_ipaddr_copy(&uip_hostaddr, &cc2420if.ipaddr); uip_ipaddr_copy(&uip_netmask, &cc2420if.netmask); uip_ipaddr(&uip_draddr, 172,16,0,1); printf("IP %d.%d.%d.%d netmask %d.%d.%d.%d default router %d.%d.%d.%d\n", uip_ipaddr_to_quad(&uip_hostaddr), uip_ipaddr_to_quad(&uip_netmask), uip_ipaddr_to_quad(&uip_draddr)); cc2420_set_chan_pan_addr(RF_CHANNEL, panId, uip_hostaddr.u16[1], ds2411_id); /* * Initialize Contiki and our processes. */ process_init(); process_start(&etimer_process, NULL); /* Configure IP stack. */ uip_init(); uip_fw_default(&cc2420if); tcpip_set_forwarding(1); /* Start IP stack. */ process_start(&tcpip_process, NULL); process_start(&uip_fw_process, NULL); /* Start IP output */ process_start(&cc2420_process, NULL); cc2420_on(); process_start(&uaodv_process, NULL); process_start(&button_process, NULL); process_start(&tcp_loader_process, NULL); /* * This is the scheduler loop. */ printf("process_run()...\n"); while (1) { do { /* Reset watchdog. */ } while(process_run() > 0); /* * Idle processing. */ int s = splhigh(); /* Disable interrupts. */ if(process_nevents() != 0) { splx(s); /* Re-enable interrupts. */ } else { /* Re-enable interrupts and go to sleep atomically. */ _BIS_SR(GIE | SCG0 | CPUOFF); /* LPM1 sleep. */ } } return 0; }
/*---------------------------------------------------------------------------*/ int main(void) { /* Hardware initialization */ bus_init();//ʱÖÓ³õʼ»¯ rtimer_init();//¼ÆʱÆ÷³õʼ»¯ /* model-specific h/w init. */ io_port_init(); /* Init LEDs here */ leds_init();//LED³õʼ»¯ /*LEDS_GREEN indicate LEDs Init finished*/ fade(LEDS_GREEN); /* initialize process manager. */ process_init();//½ø³Ì¹ÜÀí³õʼ»¯ /* Init UART0 * Based on the EJOY MCU CC2430 Circuit Design * */ uart0_init();//UART0´®¿Ú³õʼ»¯ #if DMA_ON dma_init();//DMA³õʼ»¯ #endif #if SLIP_ARCH_CONF_ENABLE /* On cc2430, the argument is not used */ slip_arch_init(0);//SLIP³õʼ»¯ #else uart1_set_input(serial_line_input_byte); serial_line_init(); #endif PUTSTRING("##########################################\n"); putstring(CONTIKI_VERSION_STRING "\n"); // putstring(SENSINODE_MODEL " (CC24"); puthex(((CHIPID >> 3) | 0x20)); putstring("-" FLASH_SIZE ")\n"); #if STARTUP_VERBOSE #ifdef HAVE_SDCC_BANKING PUTSTRING(" With Banking.\n"); #endif /* HAVE_SDCC_BANKING */ #ifdef SDCC_MODEL_LARGE PUTSTRING(" --model-large\n"); #endif /* SDCC_MODEL_LARGE */ #ifdef SDCC_MODEL_HUGE PUTSTRING(" --model-huge\n"); #endif /* SDCC_MODEL_HUGE */ #ifdef SDCC_STACK_AUTO PUTSTRING(" --stack-auto\n"); #endif /* SDCC_STACK_AUTO */ PUTCHAR('\n'); PUTSTRING(" Net: "); PUTSTRING(NETSTACK_NETWORK.name); PUTCHAR('\n'); PUTSTRING(" MAC: "); PUTSTRING(NETSTACK_MAC.name); PUTCHAR('\n'); PUTSTRING(" RDC: "); PUTSTRING(NETSTACK_RDC.name); PUTCHAR('\n'); PUTSTRING("##########################################\n"); #endif watchdog_init();//¿´ÃŹ·³õʼ»¯ /* Initialise the cc2430 RNG engine. */ random_init(0);//Ëæ»úÊýÉú³ÉÆ÷³õʼ»¯ /* start services */ process_start(&etimer_process, NULL);// ctimer_init();//ctimer³õʼ»¯ /* initialize the netstack */ netstack_init();//ÍøÂçµ×²ãÕ»³õʼ»¯ set_rime_addr();//rimeµØÖ·ÉèÖà //there is no sensor for us maintenance #if BUTTON_SENSOR_ON || ADC_SENSOR_ON process_start(&sensors_process, NULL); sensinode_sensors_activate(); #endif //IPV6,YES! #if UIP_CONF_IPV6 memcpy(&uip_lladdr.addr, &rimeaddr_node_addr, sizeof(uip_lladdr.addr)); queuebuf_init(); process_start(&tcpip_process, NULL); //DISCO #if DISCO_ENABLED process_start(&disco_process, NULL); #endif /* DISCO_ENABLED */ //VIZTOOL #if VIZTOOL_CONF_ON process_start(&viztool_process, NULL); #endif #if (!UIP_CONF_IPV6_RPL) { uip_ipaddr_t ipaddr; uip_ip6addr(&ipaddr, 0x2001, 0x630, 0x301, 0x6453, 0, 0, 0, 0); uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr); uip_ds6_addr_add(&ipaddr, 0, ADDR_TENTATIVE); } #endif /* UIP_CONF_IPV6_RPL */ #endif /* UIP_CONF_IPV6 */ /* * Acknowledge the UART1 RX interrupt * now that we're sure we are ready to process it * * We don't need it. by MW */ // model_uart_intr_en(); energest_init(); ENERGEST_ON(ENERGEST_TYPE_CPU); fade(LEDS_RED); #if BATMON_CONF_ON process_start(&batmon_process, NULL); #endif autostart_start(autostart_processes); watchdog_start(); while(1) { do { /* Reset watchdog and handle polls and events */ watchdog_periodic(); /**/ #if !CLOCK_CONF_ACCURATE if(sleep_flag) { if(etimer_pending() && (etimer_next_expiration_time() - count - 1) > MAX_TICKS) { /*core/sys/etimer.c*/ etimer_request_poll(); } sleep_flag = 0; } #endif r = process_run(); } while(r > 0); #if SHORTCUTS_CONF_NETSTACK len = NETSTACK_RADIO.pending_packet(); if(len) { packetbuf_clear(); len = NETSTACK_RADIO.read(packetbuf_dataptr(), PACKETBUF_SIZE); if(len > 0) { packetbuf_set_datalen(len); NETSTACK_RDC.input(); } } #endif #if LPM_MODE #if (LPM_MODE==LPM_MODE_PM2) SLEEP &= ~OSC_PD; /* Make sure both HS OSCs are on */ while(!(SLEEP & HFRC_STB)); /* Wait for RCOSC to be stable */ CLKCON |= OSC; /* Switch to the RCOSC */ while(!(CLKCON & OSC)); /* Wait till it's happened */ SLEEP |= OSC_PD; /* Turn the other one off */ #endif /* LPM_MODE==LPM_MODE_PM2 */ /* * Set MCU IDLE or Drop to PM1. Any interrupt will take us out of LPM * Sleep Timer will wake us up in no more than 7.8ms (max idle interval) */ SLEEP = (SLEEP & 0xFC) | (LPM_MODE - 1); #if (LPM_MODE==LPM_MODE_PM2) /* * Wait 3 NOPs. Either an interrupt occurred and SLEEP.MODE was cleared or * no interrupt occurred and we can safely power down */ __asm nop nop nop __endasm; if (SLEEP & SLEEP_MODE0) { #endif /* LPM_MODE==LPM_MODE_PM2 */ ENERGEST_OFF(ENERGEST_TYPE_CPU); ENERGEST_ON(ENERGEST_TYPE_LPM); /* We are only interested in IRQ energest while idle or in LPM */ ENERGEST_IRQ_RESTORE(irq_energest); /* Go IDLE or Enter PM1 */ PCON |= IDLE; /* First instruction upon exiting PM1 must be a NOP */ __asm nop __endasm; /* Remember energest IRQ for next pass */ ENERGEST_IRQ_SAVE(irq_energest); ENERGEST_ON(ENERGEST_TYPE_CPU); ENERGEST_OFF(ENERGEST_TYPE_LPM); #if (LPM_MODE==LPM_MODE_PM2) SLEEP &= ~OSC_PD; /* Make sure both HS OSCs are on */ while(!(SLEEP & XOSC_STB)); /* Wait for XOSC to be stable */ CLKCON &= ~OSC; /* Switch to the XOSC */ /* * On occasion the XOSC is reported stable when in reality it's not. * We need to wait for a safeguard of 64us or more before selecting it */ clock_delay(10); while(CLKCON & OSC); /* Wait till it's happened */ } #endif /* LPM_MODE==LPM_MODE_PM2 */ #endif /* LPM_MODE */ } }
int main(int argc, char **argv) { /* * Initalize hardware. */ msp430_cpu_init(); clock_init(); leds_init(); leds_toggle(LEDS_ALL); slip_arch_init(BAUD2UBR(115200)); /* Must come before first printf */ printf("Starting %s " "($Id: gateway.c,v 1.2 2010/10/19 18:29:04 adamdunkels Exp $)\n", __FILE__); ds2411_init(); sensors_light_init(); cc2420_init(); xmem_init(); leds_toggle(LEDS_ALL); /* * Hardware initialization done! */ printf("MAC %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x CHANNEL %d\n", ds2411_id[0], ds2411_id[1], ds2411_id[2], ds2411_id[3], ds2411_id[4], ds2411_id[5], ds2411_id[6], ds2411_id[7], RF_CHANNEL); uip_ipaddr_copy(&uip_hostaddr, &cc2420if.ipaddr); uip_ipaddr_copy(&uip_netmask, &cc2420if.netmask); printf("IP %d.%d.%d.%d netmask %d.%d.%d.%d\n", uip_ipaddr_to_quad(&uip_hostaddr), uip_ipaddr_to_quad(&uip_netmask)); cc2420_set_chan_pan_addr(RF_CHANNEL, panId, uip_hostaddr.u16[1], ds2411_id); srand(rand() + (ds2411_id[3]<<8) + (ds2411_id[4]<<6) + (ds2411_id[5]<<4) + (ds2411_id[6]<<2) + ds2411_id[7]); /* * Initialize Contiki and our processes. */ process_init(); process_start(&etimer_process, NULL); /* Configure IP stack. */ uip_init(); uip_fw_default(&slipif); /* Point2point, no default router. */ uip_fw_register(&cc2420if); tcpip_set_forwarding(1); /* Start IP stack. */ process_start(&tcpip_process, NULL); process_start(&uip_fw_process, NULL); /* Start IP output */ process_start(&slip_process, NULL); process_start(&cc2420_process, NULL); cc2420_on(); process_start(&uaodv_process, NULL); process_start(&tcp_loader_process, NULL); /* * This is the scheduler loop. */ printf("process_run()...\n"); while (1) { do { /* Reset watchdog. */ } while(process_run() > 0); /* Idle! */ } return 0; }
/*---------------------------------------------------------------------------*/ #if WITH_TINYOS_AUTO_IDS uint16_t TOS_NODE_ID = 0x1234; /* non-zero */ uint16_t TOS_LOCAL_ADDRESS = 0x1234; /* non-zero */ #endif /* WITH_TINYOS_AUTO_IDS */ int main(int argc, char **argv) { /* * Initalize hardware. */ msp430_cpu_init(); clock_init(); leds_init(); leds_on(LEDS_RED); uart1_init(BAUD2UBR(115200)); /* Must come before first printf */ leds_on(LEDS_GREEN); ds2411_init(); /* XXX hack: Fix it so that the 802.15.4 MAC address is compatible with an Ethernet MAC address - byte 0 (byte 2 in the DS ID) cannot be odd. */ ds2411_id[2] &= 0xfe; leds_on(LEDS_BLUE); xmem_init(); leds_off(LEDS_RED); rtimer_init(); /* * Hardware initialization done! */ /* Initialize energest first (but after rtimer) */ energest_init(); ENERGEST_ON(ENERGEST_TYPE_CPU); #if WITH_TINYOS_AUTO_IDS node_id = TOS_NODE_ID; #else /* WITH_TINYOS_AUTO_IDS */ /* Restore node id if such has been stored in external mem */ node_id_restore(); #endif /* WITH_TINYOS_AUTO_IDS */ /* for setting "hardcoded" IEEE 802.15.4 MAC addresses */ #ifdef IEEE_802154_MAC_ADDRESS { uint8_t ieee[] = IEEE_802154_MAC_ADDRESS; memcpy(ds2411_id, ieee, sizeof(uip_lladdr.addr)); ds2411_id[7] = node_id & 0xff; } #endif random_init(ds2411_id[0] + node_id); leds_off(LEDS_BLUE); /* * Initialize Contiki and our processes. */ process_init(); process_start(&etimer_process, NULL); ctimer_init(); #if NETSTACK_CONF_WITH_IPV4 slip_arch_init(BAUD2UBR(115200)); #endif /* NETSTACK_CONF_WITH_IPV4 */ init_platform(); set_rime_addr(); cc2420_init(); { 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]); cc2420_set_pan_addr(IEEE802154_PANID, shortaddr, longaddr); } 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"); } /* PRINTF("MAC %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x", ds2411_id[0], ds2411_id[1], ds2411_id[2], ds2411_id[3], ds2411_id[4], ds2411_id[5], ds2411_id[6], ds2411_id[7]);*/ #if NETSTACK_CONF_WITH_IPV6 memcpy(&uip_lladdr.addr, ds2411_id, sizeof(uip_lladdr.addr)); /* Setup nullmac-like MAC for 802.15.4 */ /* sicslowpan_init(sicslowmac_init(&cc2420_driver)); */ /* PRINTF(" %s channel %u\n", sicslowmac_driver.name, CC2420_CONF_CCA_THRESH); */ /* Setup X-MAC for 802.15.4 */ queuebuf_init(); NETSTACK_RDC.init(); NETSTACK_MAC.init(); NETSTACK_LLSEC.init(); NETSTACK_NETWORK.init(); PRINTF("%s %s %s, channel check rate %lu Hz, radio channel %u, CCA threshold %i\n", NETSTACK_LLSEC.name, NETSTACK_MAC.name, NETSTACK_RDC.name, CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1: NETSTACK_RDC.channel_check_interval()), CC2420_CONF_CHANNEL, CC2420_CONF_CCA_THRESH); process_start(&tcpip_process, NULL); #if DEBUG 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]); } #endif /* DEBUG */ if(!UIP_CONF_IPV6_RPL) { uip_ipaddr_t ipaddr; int i; uip_ip6addr(&ipaddr, UIP_DS6_DEFAULT_PREFIX, 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]); } #else /* NETSTACK_CONF_WITH_IPV6 */ NETSTACK_RDC.init(); NETSTACK_MAC.init(); NETSTACK_LLSEC.init(); NETSTACK_NETWORK.init(); PRINTF("%s %s %s, channel check rate %lu Hz, radio channel %u\n", NETSTACK_LLSEC.name, NETSTACK_MAC.name, NETSTACK_RDC.name, CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0? 1: NETSTACK_RDC.channel_check_interval()), CC2420_CONF_CHANNEL); #endif /* NETSTACK_CONF_WITH_IPV6 */ #if !NETSTACK_CONF_WITH_IPV4 && !NETSTACK_CONF_WITH_IPV6 uart1_set_input(serial_line_input_byte); serial_line_init(); #endif leds_off(LEDS_GREEN); #if TIMESYNCH_CONF_ENABLED timesynch_init(); timesynch_set_authority_level((linkaddr_node_addr.u8[0] << 4) + 16); #endif /* TIMESYNCH_CONF_ENABLED */ #if NETSTACK_CONF_WITH_IPV4 process_start(&tcpip_process, NULL); process_start(&uip_fw_process, NULL); /* Start IP output */ process_start(&slip_process, NULL); slip_set_input_callback(set_gateway); { uip_ipaddr_t hostaddr, netmask; uip_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_fw_register(&slipif);*/ uip_over_mesh_set_gateway_netif(&slipif); uip_fw_default(&meshif); uip_over_mesh_init(UIP_OVER_MESH_CHANNEL); PRINTF("uIP started with IP address %d.%d.%d.%d\n", uip_ipaddr_to_quad(&hostaddr)); } #endif /* NETSTACK_CONF_WITH_IPV4 */ watchdog_start(); #if !PROCESS_CONF_NO_PROCESS_NAMES print_processes(autostart_processes); #endif /* !PROCESS_CONF_NO_PROCESS_NAMES */ autostart_start(autostart_processes); /* * This is the scheduler loop. */ #if DCOSYNCH_CONF_ENABLED timer_set(&mgt_timer, DCOSYNCH_PERIOD * CLOCK_SECOND); #endif /* watchdog_stop();*/ while(1) { int r; do { /* Reset watchdog. */ watchdog_periodic(); r = process_run(); } while(r > 0); /* * Idle processing. */ int s = splhigh(); /* Disable interrupts. */ /* uart1_active is for avoiding LPM3 when still sending or receiving */ if(process_nevents() != 0 || uart1_active()) { splx(s); /* Re-enable interrupts. */ } else { static unsigned long irq_energest = 0; #if DCOSYNCH_CONF_ENABLED /* before going down to sleep possibly do some management */ if(timer_expired(&mgt_timer)) { watchdog_periodic(); timer_reset(&mgt_timer); msp430_sync_dco(); #if CC2420_CONF_SFD_TIMESTAMPS cc2420_arch_sfd_init(); #endif /* CC2420_CONF_SFD_TIMESTAMPS */ } #endif /* Re-enable interrupts and go to sleep atomically. */ ENERGEST_SWITCH(ENERGEST_TYPE_CPU, ENERGEST_TYPE_LPM); /* We only want to measure the processing done in IRQs when we are asleep, so we discard the processing time done when we were awake. */ energest_type_set(ENERGEST_TYPE_IRQ, irq_energest); watchdog_stop(); /* check if the DCO needs to be on - if so - only LPM 1 */ if (msp430_dco_required) { _BIS_SR(GIE | CPUOFF); /* LPM1 sleep for DMA to work!. */ } else { _BIS_SR(GIE | SCG0 | SCG1 | CPUOFF); /* LPM3 sleep. This statement will block until the CPU is woken up by an interrupt that sets the wake up flag. */ } /* We get the current processing time for interrupts that was done during the LPM and store it for next time around. */ dint(); irq_energest = energest_type_time(ENERGEST_TYPE_IRQ); eint(); watchdog_start(); ENERGEST_SWITCH(ENERGEST_TYPE_LPM, ENERGEST_TYPE_CPU); } } return 0; }
/*---------------------------------------------------------------------------*/ int main(void) { clock_init(); // 初始化 睡眠定时器 必要 soc_init(); // 还函数中启动了全局中断 可修改 rtimer_init(); // rtimer为定时器1 必要 /* Init LEDs here */ leds_init(); // 初始化LED 可修改 leds_off(LEDS_ALL); // 关闭所有LED 非必要 fade(LEDS_GREEN); // 绿色闪烁一下 非必要 /* initialize process manager. */ process_init(); // 任务初始化 必要 /* Init UART */ uart0_init(); // 初始化串口0,先用于调试,可修改 #if DMA_ON dma_init(); // 非必要 #endif #if SLIP_ARCH_CONF_ENABLE slip_arch_init(0); #else uart0_set_input(serial_line_input_byte); serial_line_init(); #endif fade(LEDS_RED); // 红色LED闪烁一下 非必要 // 打印若干提示信息 非必要 可修改 putstring("**************************************\r\n"); putstring(CONTIKI_VERSION_STRING "\r\n"); // 打印若干信息 putstring("Platform CC2530 NB\r\n"); switch(CHIPID) { case 0xA5: putstring("CC2530"); break; case 0xB5: putstring("CC2531"); break; case 0x95: putstring("CC2533"); break; case 0x8D: putstring("CC2540"); break; } putstring("-F"); switch(CHIPINFO0 & 0x70) { case 0x40: putstring("256,"); break; case 0x30: putstring("128,"); break; case 0x20: putstring("64,"); break; case 0x10: putstring("32,"); break; } puthex(CHIPINFO1 + 1); putstring("KB SRAM\r\n"); #if STARTUP_VERBOSE PUTSTRING("Net: "); // NETWORK名称 PUTSTRING(NETSTACK_NETWORK.name); PUTCHAR('\r');PUTCHAR('\n'); PUTSTRING("MAC: "); // MAC名称 PUTSTRING(NETSTACK_MAC.name); PUTCHAR('\r');PUTCHAR('\n'); PUTSTRING("RDC: "); // RDC名称 PUTSTRING(NETSTACK_RDC.name); PUTCHAR('\r');PUTCHAR('\n'); PUTSTRING("**************************************\r\n"); #endif watchdog_init(); // 初始化看门狗 /* Initialise the H/W RNG engine. */ random_init(0); // /* start services */ process_start(&etimer_process, NULL); // 启动etimer任务 ctimer_init(); // ctimer初始化 /* initialize the netstack */ netstack_init(); // NET协议栈初始化 set_rime_addr(); // 设置RIME地址,相当于设置IP地址 #if BUTTON_SENSOR_ON || ADC_SENSOR_ON process_start(&sensors_process, NULL); BUTTON_SENSOR_ACTIVATE(); ADC_SENSOR_ACTIVATE(); #endif #if UIP_CONF_IPV6 // 非常重要,启动TCPIP查询任务 memcpy(&uip_lladdr.addr, &rimeaddr_node_addr, sizeof(uip_lladdr.addr)); queuebuf_init(); process_start(&tcpip_process, NULL); #endif /* UIP_CONF_IPV6 */ #if VIZTOOL_CONF_ON process_start(&viztool_process, NULL); #endif energest_init(); // 能量估计初始化,但是该功能未被打开 ENERGEST_ON(ENERGEST_TYPE_CPU); // 该功能未被打开 autostart_start(autostart_processes); // 启动被定义为自动启动的任务 watchdog_start(); // 看门狗初始化 fade(LEDS_YELLOW); // 黄色LED闪烁,完成所有初始化工作 while(1) { do { /* Reset watchdog and handle polls and events */ watchdog_periodic(); // 喂狗操作 r = process_run(); } while(r > 0); #if SHORTCUTS_CONF_NETSTACK // 循环查询无线输入数据包长度 tcpip_process len = NETSTACK_RADIO.pending_packet(); if(len) { packetbuf_clear(); len = NETSTACK_RADIO.read(packetbuf_dataptr(), PACKETBUF_SIZE); if(len > 0) { packetbuf_set_datalen(len); NETSTACK_RDC.input(); } } #endif #if LPM_MODE // 该宏被定义为0,没有休眠功能,以下代码均无效 #if (LPM_MODE==LPM_MODE_PM2) SLEEP &= ~OSC_PD; /* Make sure both HS OSCs are on */ while(!(SLEEP & HFRC_STB)); /* Wait for RCOSC to be stable */ CLKCON |= OSC; /* Switch to the RCOSC */ while(!(CLKCON & OSC)); /* Wait till it's happened */ SLEEP |= OSC_PD; /* Turn the other one off */ #endif /* LPM_MODE==LPM_MODE_PM2 */ /* * Set MCU IDLE or Drop to PM1. Any interrupt will take us out of LPM * Sleep Timer will wake us up in no more than 7.8ms (max idle interval) */ SLEEPCMD = (SLEEPCMD & 0xFC) | (LPM_MODE - 1); #if (LPM_MODE==LPM_MODE_PM2) /* * Wait 3 NOPs. Either an interrupt occurred and SLEEP.MODE was cleared or * no interrupt occurred and we can safely power down */ __asm nop nop nop __endasm; if(SLEEPCMD & SLEEP_MODE0) { #endif /* LPM_MODE==LPM_MODE_PM2 */ ENERGEST_OFF(ENERGEST_TYPE_CPU); ENERGEST_ON(ENERGEST_TYPE_LPM); /* We are only interested in IRQ energest while idle or in LPM */ ENERGEST_IRQ_RESTORE(irq_energest); /* Go IDLE or Enter PM1 */ PCON |= PCON_IDLE; /* First instruction upon exiting PM1 must be a NOP */ __asm nop __endasm; /* Remember energest IRQ for next pass */ ENERGEST_IRQ_SAVE(irq_energest); ENERGEST_ON(ENERGEST_TYPE_CPU); ENERGEST_OFF(ENERGEST_TYPE_LPM); #if (LPM_MODE==LPM_MODE_PM2) SLEEPCMD &= ~SLEEP_OSC_PD; /* Make sure both HS OSCs are on */ while(!(SLEEPCMD & SLEEP_XOSC_STB)); /* Wait for XOSC to be stable */ CLKCONCMD &= ~CLKCONCMD_OSC; /* Switch to the XOSC */ /* * On occasion the XOSC is reported stable when in reality it's not. * We need to wait for a safeguard of 64us or more before selecting it */ clock_delay(10); while(CLKCONCMD & CLKCONCMD_OSC); /* Wait till it's happened */ } #endif /* LPM_MODE==LPM_MODE_PM2 */ #endif /* LPM_MODE */ } }
/*---------------------------------------------------------------------------*/ int main(int argc, char **argv) { /* * Initalize hardware. */ msp430_cpu_init(); clock_init(); leds_init(); leds_toggle(LEDS_RED | LEDS_GREEN | LEDS_BLUE); #if WITH_UIP slip_arch_init(BAUD2UBR(115200)); /* Must come before first printf */ #else /* WITH_UIP */ uart1_init(BAUD2UBR(115200)); /* Must come before first printf */ #endif /* WITH_UIP */ printf("Starting %s " "($Id: contiki-sky-main.c,v 1.9 2009/11/20 10:45:07 nifi Exp $)\n", __FILE__); ds2411_init(); xmem_init(); leds_toggle(LEDS_RED | LEDS_GREEN | LEDS_BLUE); rtimer_init(); /* * Hardware initialization done! */ /* Restore node id if such has been stored in external mem */ // node_id_burn(3); node_id_restore(); printf("node_id : %hu\n", node_id); printf("MAC %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n", ds2411_id[0], ds2411_id[1], ds2411_id[2], ds2411_id[3], ds2411_id[4], ds2411_id[5], ds2411_id[6], ds2411_id[7]); #if WITH_UIP uip_init(); uip_sethostaddr(&slipif.ipaddr); uip_setnetmask(&slipif.netmask); uip_fw_default(&slipif); /* Point2point, no default router. */ #endif /* WITH_UIP */ /* * Initialize Contiki and our processes. */ process_init(); process_start(&etimer_process, NULL); process_start(&sensors_process, NULL); /* * Initialize light and humidity/temp sensors. */ SENSORS_ACTIVATE(light_sensor); SENSORS_ACTIVATE(sht11_sensor); ctimer_init(); set_rime_addr(); cc2420_init(); cc2420_set_pan_addr(panId, 0 /*XXX*/, ds2411_id); cc2420_set_channel(RF_CHANNEL); cc2420_set_txpower(31); nullmac_init(&cc2420_driver); rime_init(&nullmac_driver); // xmac_init(&cc2420_driver); // rime_init(&xmac_driver); /* rimeaddr_set_node_addr*/ #if WITH_UIP process_start(&tcpip_process, NULL); process_start(&uip_fw_process, NULL); /* Start IP output */ process_start(&slip_process, NULL); #endif /* WITH_UIP */ SENSORS_ACTIVATE(button_sensor); print_processes(autostart_processes); autostart_start(autostart_processes); energest_init(); /* * This is the scheduler loop. */ printf("process_run()...\n"); ENERGEST_ON(ENERGEST_TYPE_CPU); while (1) { do { /* Reset watchdog. */ } while(process_run() > 0); /* * Idle processing. */ if(lpm_en) { int s = splhigh(); /* Disable interrupts. */ if(process_nevents() != 0) { splx(s); /* Re-enable interrupts. */ } else { static unsigned long irq_energest = 0; /* Re-enable interrupts and go to sleep atomically. */ ENERGEST_OFF(ENERGEST_TYPE_CPU); ENERGEST_ON(ENERGEST_TYPE_LPM); /* We only want to measure the processing done in IRQs when we are asleep, so we discard the processing time done when we were awake. */ energest_type_set(ENERGEST_TYPE_IRQ, irq_energest); _BIS_SR(GIE | SCG0 | /*SCG1 |*/ CPUOFF); /* LPM3 sleep. */ /* We get the current processing time for interrupts that was done during the LPM and store it for next time around. */ dint(); irq_energest = energest_type_time(ENERGEST_TYPE_IRQ); eint(); ENERGEST_OFF(ENERGEST_TYPE_LPM); ENERGEST_ON(ENERGEST_TYPE_CPU); } } } return 0; }
/*---------------------------------------------------------------------------*/ int main(int argc, char **argv) { /* * Initalize hardware. */ msp430_cpu_init(); clock_init(); leds_init(); leds_on(LEDS_RED); clock_wait(2); uart1_init(115200); /* Must come before first printf */ #if WITH_UIP slip_arch_init(115200); #endif /* WITH_UIP */ clock_wait(1); leds_on(LEDS_GREEN); //ds2411_init(); /* XXX hack: Fix it so that the 802.15.4 MAC address is compatible with an Ethernet MAC address - byte 0 (byte 2 in the DS ID) cannot be odd. */ //ds2411_id[2] &= 0xfe; leds_on(LEDS_BLUE); //xmem_init(); leds_off(LEDS_RED); rtimer_init(); /* * Hardware initialization done! */ node_id = NODE_ID; /* Restore node id if such has been stored in external mem */ //node_id_restore(); /* for setting "hardcoded" IEEE 802.15.4 MAC addresses */ #ifdef IEEE_802154_MAC_ADDRESS { uint8_t ieee[] = IEEE_802154_MAC_ADDRESS; //memcpy(ds2411_id, ieee, sizeof(uip_lladdr.addr)); //ds2411_id[7] = node_id & 0xff; } #endif //random_init(ds2411_id[0] + node_id); leds_off(LEDS_BLUE); /* * Initialize Contiki and our processes. */ process_init(); process_start(&etimer_process, NULL); ctimer_init(); init_platform(); set_rime_addr(); cc2520_init(); { uint8_t longaddr[8]; uint16_t shortaddr; shortaddr = (rimeaddr_node_addr.u8[0] << 8) + rimeaddr_node_addr.u8[1]; memset(longaddr, 0, sizeof(longaddr)); rimeaddr_copy((rimeaddr_t *)&longaddr, &rimeaddr_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]); cc2520_set_pan_addr(IEEE802154_PANID, shortaddr, longaddr); } cc2520_set_channel(RF_CHANNEL); 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"); } #if WITH_UIP6 /* memcpy(&uip_lladdr.addr, ds2411_id, sizeof(uip_lladdr.addr)); */ memcpy(&uip_lladdr.addr, rimeaddr_node_addr.u8, UIP_LLADDR_LEN > RIMEADDR_SIZE ? RIMEADDR_SIZE : UIP_LLADDR_LEN); /* Setup nullmac-like MAC for 802.15.4 */ /* sicslowpan_init(sicslowmac_init(&cc2520_driver)); */ /* printf(" %s channel %u\n", sicslowmac_driver.name, RF_CHANNEL); */ /* Setup X-MAC for 802.15.4 */ queuebuf_init(); NETSTACK_RDC.init(); NETSTACK_MAC.init(); NETSTACK_NETWORK.init(); printf("%s %s, channel check rate %lu Hz, radio channel %u\n", NETSTACK_MAC.name, NETSTACK_RDC.name, CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1: NETSTACK_RDC.channel_check_interval()), RF_CHANNEL); 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(!UIP_CONF_IPV6_RPL) { 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]); } #else /* WITH_UIP6 */ NETSTACK_RDC.init(); NETSTACK_MAC.init(); NETSTACK_NETWORK.init(); printf("%s %s, channel check rate %lu Hz, radio channel %u\n", NETSTACK_MAC.name, NETSTACK_RDC.name, CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0? 1: NETSTACK_RDC.channel_check_interval()), RF_CHANNEL); #endif /* WITH_UIP6 */ #if !WITH_UIP && !WITH_UIP6 uart1_set_input(serial_line_input_byte); serial_line_init(); #endif leds_off(LEDS_GREEN); #if TIMESYNCH_CONF_ENABLED timesynch_init(); timesynch_set_authority_level((rimeaddr_node_addr.u8[0] << 4) + 16); #endif /* TIMESYNCH_CONF_ENABLED */ #if WITH_UIP process_start(&tcpip_process, NULL); process_start(&uip_fw_process, NULL); /* Start IP output */ process_start(&slip_process, NULL); slip_set_input_callback(set_gateway); { uip_ipaddr_t hostaddr, netmask; uip_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_fw_register(&slipif);*/ uip_over_mesh_set_gateway_netif(&slipif); uip_fw_default(&meshif); uip_over_mesh_init(UIP_OVER_MESH_CHANNEL); printf("uIP started with IP address %d.%d.%d.%d\n", uip_ipaddr_to_quad(&hostaddr)); } #endif /* WITH_UIP */ energest_init(); ENERGEST_ON(ENERGEST_TYPE_CPU); watchdog_start(); /* Stop the watchdog */ watchdog_stop(); #if !PROCESS_CONF_NO_PROCESS_NAMES print_processes(autostart_processes); #else /* !PROCESS_CONF_NO_PROCESS_NAMES */ putchar('\n'); /* include putchar() */ #endif /* !PROCESS_CONF_NO_PROCESS_NAMES */ autostart_start(autostart_processes); /* * This is the scheduler loop. */ while(1) { int r; do { /* Reset watchdog. */ watchdog_periodic(); r = process_run(); } while(r > 0); /* * Idle processing. */ int s = splhigh(); /* Disable interrupts. */ /* uart1_active is for avoiding LPM3 when still sending or receiving */ if(process_nevents() != 0 || uart1_active()) { splx(s); /* Re-enable interrupts. */ } else { static unsigned long irq_energest = 0; /* Re-enable interrupts and go to sleep atomically. */ ENERGEST_OFF(ENERGEST_TYPE_CPU); ENERGEST_ON(ENERGEST_TYPE_LPM); /* We only want to measure the processing done in IRQs when we are asleep, so we discard the processing time done when we were awake. */ energest_type_set(ENERGEST_TYPE_IRQ, irq_energest); watchdog_stop(); _BIS_SR(GIE | SCG0 | SCG1 | CPUOFF); /* LPM3 sleep. This statement will block until the CPU is woken up by an interrupt that sets the wake up flag. */ /* We get the current processing time for interrupts that was done during the LPM and store it for next time around. */ dint(); irq_energest = energest_type_time(ENERGEST_TYPE_IRQ); eint(); watchdog_start(); ENERGEST_OFF(ENERGEST_TYPE_LPM); ENERGEST_ON(ENERGEST_TYPE_CPU); } } }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(demo_source, ev, data) { static struct etimer et; rimeaddr_t addr; //PROCESS_EXITHANDLER(unicast_close(&unicast);) PROCESS_BEGIN(); // unicast init // unicast_open(&unicast, 146, &unicast_callbacks); // UART init // slip_arch_init(115200); // DATA Storing // data_sensing=(uint8_t *) malloc(UART_Full+1 * sizeof(uint8_t)); //size+1 은 첫번째에 indicator 넣기 위함! data_sensing[0]='B'; //sensor 식별자 sensor A or sensor B //data_sensing[UART_Full]=90; while (1) { etimer_set(&et, CLOCK_SECOND/10); PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); //printf("%d\t%c\n",data_sensing[0],data_sensing[0]); /* RAIDO_LISTEN : * Wait start signal from Sink Node */ if(CURRENT_STATE==RAIDO_LISTEN){ PRINTF("CURRENT_STATE: %d. RAIDO_LISTEN \n",CURRENT_STATE); leds_on(RAIDO_LISTEN); if (RADIO_Input=='S'){ UART_out('S'); CURRENT_STATE=UART_START; RADIO_Input=NULL; } } /* UART_SEND : * 1. Sensor Interface로 부터 Sensing Complete(C) 신호를 받은 경우 * 2. Sensor Interface로 부터 1회 UART 전송을 완료하고 SUCCESS신호를 받은경우 * -> NEXT(N) 신호를 전달하여 다음 데이터 요구 * 1. Sensor Interface로 부터 (!SUCCESS)를 받은 경우 * ->Retransmission(R) 신호 전달 */ else if(CURRENT_STATE==UART_SEND){ PRINTF("CURRENT_STATE: %d. UART_SEND \n",CURRENT_STATE); leds_on(UART_SEND); if(UART_Success==1) UART_out('N'); else if (UART_Success==0) UART_out('R'); CURRENT_STATE=UART_LISTEN; } /* UART_READY : * 1회 전송 가능 data 량을 Sensor interface 로 부터 받은 경우 * data를 packet화 하여 unicast 전송 */ else if(CURRENT_STATE==UART_READY){ PRINTF("CURRENT_STATE: %d. UART_READY \n",CURRENT_STATE); leds_on(UART_READY); //헤더 붙이고, 데이터 패킷화 하여 전송하기 packetbuf_copyfrom(data_sensing, UART_Full+1); addr.u8[0] = 4; addr.u8[1] = 0; //send to F2 unicast_send(&unicast, &addr); CURRENT_STATE=RADIO_SENT; } else if(CURRENT_STATE==RADIO_SENT){ RADIO_NumSend++; PRINTF("CURRENT_STATE: %d. RADIO_SNET \t RADIO_NumSend : %d\n",CURRENT_STATE,RADIO_NumSend); leds_on(RADIO_SENT); if(RADIO_NumSend>=END_SENSING)//End 인 경우 { UART_End=1; //이건 아마 필요없는 기능이 될듯 CURRENT_STATE=RAIDO_LISTEN; RADIO_NumSend=0; } else{ CURRENT_STATE=UART_SEND; } } else if(CURRENT_STATE==UART_START){ PRINTF("CURRENT_STATE: %d. UART_START \n",UART_START); leds_on(UART_START); } else if(CURRENT_STATE==UART_LISTEN){ PRINTF("CURRENT_STATE: %d. UART_LISTEN \n",UART_LISTEN); leds_on(UART_LISTEN); } else { PRINTF("NONE STATE \t%d\n",CURRENT_STATE); leds_on(0); } } PROCESS_END(); }