PROCESS_THREAD(application1,ev,data) { PROCESS_BEGIN(); sensors_light_init(); printf(">>LAUNCH SUCCESS: %d\n", knot_register_sensor(&application1, (knot_callback)&callback, rate, "Light", LIGHT)); /* Application do something? */ while (1){ PROCESS_WAIT_EVENT(); } PROCESS_END(); }
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; }
/*---------------------------------------------------------------------------*/ 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; }
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(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; }