/** * \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(int argc, char **argv) { #if UIP_CONF_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 #else printf(CONTIKI_VERSION_STRING " started\n"); #endif /* crappy way of remembering and accessing argc/v */ contiki_argc = argc; contiki_argv = argv; /* native under windows is hardcoded to use the first one or two args */ /* for wpcap configuration so this needs to be "removed" from */ /* contiki_args (used by the native-border-router) */ #ifdef __CYGWIN__ contiki_argc--; contiki_argv++; #ifdef UIP_FALLBACK_INTERFACE contiki_argc--; contiki_argv++; #endif #endif process_init(); process_start(&etimer_process, NULL); ctimer_init(); set_rime_addr(); queuebuf_init(); netstack_init(); printf("MAC %s RDC %s NETWORK %s\n", NETSTACK_MAC.name, NETSTACK_RDC.name, NETSTACK_NETWORK.name); #if WITH_UIP6 memcpy(&uip_lladdr.addr, serial_id, sizeof(uip_lladdr.addr)); process_start(&tcpip_process, NULL); #ifdef __CYGWIN__ process_start(&wpcap_process, NULL); #endif 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]); } /* make it hardcoded... */ lladdr->state = ADDR_AUTOCONF; printf("%02x%02x\n", lladdr->ipaddr.u8[14], lladdr->ipaddr.u8[15]); } #else process_start(&tcpip_process, NULL); #endif serial_line_init(); autostart_start(autostart_processes); /* Make standard output unbuffered. */ setvbuf(stdout, (char *)NULL, _IONBF, 0); select_set_callback(STDIN_FILENO, &stdin_fd); simple_rpl_init(); ip64_init(); while(1) { fd_set fdr; fd_set fdw; int maxfd; int i; int retval; struct timeval tv; retval = process_run(); tv.tv_sec = 0; tv.tv_usec = retval ? 1 : 1000; FD_ZERO(&fdr); FD_ZERO(&fdw); maxfd = 0; for(i = 0; i <= select_max; i++) { if(select_callback[i] != NULL && select_callback[i]->set_fd(&fdr, &fdw)) { maxfd = i; } } retval = select(maxfd + 1, &fdr, &fdw, NULL, &tv); if(retval < 0) { perror("select"); } else if(retval > 0) { /* timeout => retval == 0 */ for(i = 0; i <= maxfd; i++) { if(select_callback[i] != NULL) { select_callback[i]->handle_fd(&fdr, &fdw); } } } etimer_request_poll(); } 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(void) { /* * Initalize hardware. */ halInit(); clock_init(); uart1_init(115200); /* Led initialization */ leds_init(); INTERRUPTS_ON(); PRINTF("\r\nStarting "); PRINTF(CONTIKI_VERSION_STRING); PRINTF(" on %s\r\n", boardDescription->name); boardPrintStringDescription(); PRINTF("\r\n"); /* * Initialize Contiki and our processes. */ process_init(); #if WITH_SERIAL_LINE_INPUT uart1_set_input(serial_line_input_byte); serial_line_init(); #endif /* rtimer and ctimer should be initialized before radio duty cycling layers */ rtimer_init(); /* etimer_process should be initialized before ctimer */ process_start(&etimer_process, NULL); ctimer_init(); netstack_init(); set_rime_addr(); printf("%s %s, channel check rate %lu Hz\n", NETSTACK_MAC.name, NETSTACK_RDC.name, CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1: NETSTACK_RDC.channel_check_interval())); printf("802.15.4 PAN ID 0x%x, EUI-%d:", IEEE802154_CONF_PANID, UIP_CONF_LL_802154?64:16); uip_debug_lladdr_print(&linkaddr_node_addr); printf(", radio channel %u\n", RF_CHANNEL); procinit_init(); energest_init(); ENERGEST_ON(ENERGEST_TYPE_CPU); /* Set the Clear Channel Assessment (CCA) threshold of the radio. The CCA threshold is used both for sending packets and for waking up ContikiMAC nodes. If the CCA threshold is too high, ContikiMAC will not wake up from neighbor transmissions. If the CCA threshold is too low, transmissions will be too restrictive and no packets will be sent. DEFAULT_RADIO_CCA_THRESHOLD is defined in this file. */ ST_RadioSetEdCcaThreshold(DEFAULT_RADIO_CCA_THRESHOLD); autostart_start(autostart_processes); #if NETSTACK_CONF_WITH_IPV6 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]); } #endif /* NETSTACK_CONF_WITH_IPV6 */ watchdog_start(); while(1) { int r; do { /* Reset watchdog. */ watchdog_periodic(); r = process_run(); } while(r > 0); /* watchdog_stop(); */ ENERGEST_SWITCH(ENERGEST_TYPE_CPU, ENERGEST_TYPE_LPM); /* Go to idle mode. */ halSleepWithOptions(SLEEPMODE_IDLE,0); /* We are awake. */ /* watchdog_start(); */ ENERGEST_SWITCH(ENERGEST_TYPE_LPM, ENERGEST_TYPE_CPU); } }
/*---------------------------------------------------------------------------- MAIN function *----------------------------------------------------------------------------*/ int main (void) { /* Main Program */ //************************************************************************************************************ /* this is contiki-code */ watchdog_init(); /* Initialize hardware. */ clock_init(); /* UART4 Initialization */ // uart4_init(115200); USBD_Init(&USB_OTG_dev, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_CDC_cb, &USR_cb); // Led initialization leds_init(); leds_on(LEDS_BLUE); PRINTF("\r\nStarting "); PRINTF(CONTIKI_VERSION_STRING); PRINTF(" on %s \r\n", PLATFORM_NAME); #ifdef __USE_LCD GLCD_Init(); /* Initialize graphical LCD display */ GLCD_Clear(White); /* Clear graphical LCD display */ GLCD_SetBackColor(DarkGreen); GLCD_SetTextColor(White); GLCD_DisplayString(0, 0, __FI, " KUSZ - TU Dortmund "); GLCD_DisplayString(1, 0, __FI, " contiki "); GLCD_DisplayString(2, 0, __FI, " www.tu-dortmund.de "); GLCD_SetBackColor(White); GLCD_SetTextColor(Blue); watchdog_periodic(); #endif // __USE_LCD /* * Initialize Contiki and our processes. */ #ifdef WITH_SERIAL_LINE_INPUT // uart1_set_input(serial_line_input_byte); // serial_line_init(); #endif /* rtimer and ctimer should be initialized before radio duty cycling layers*/ rtimer_init(); process_init(); process_start(&sensors_process, NULL); /* etimers must be started before ctimer_init */ process_start(&etimer_process, NULL); ctimer_init(); /* Start radio and radio receive process */ NETSTACK_RADIO.init(); /* makes use of cpu-specific RNG peripheral - no seed needed */ random_init(0); /* Set addresses BEFORE starting tcpip process */ addr.u8[0] = 0x02; addr.u8[1] = *((uint8_t*)0x1FFF7A10); addr.u8[2] = *((uint8_t*)0x1FFF7A10+1); addr.u8[3] = 0xFF; addr.u8[4] = 0xFE; addr.u8[5] = *((uint8_t*)0x1FFF7A10+2); addr.u8[6] = *((uint8_t*)0x1FFF7A10+3); addr.u8[7] = *((uint8_t*)0x1FFF7A10+4); memcpy(&uip_lladdr.addr, &addr.u8, sizeof(rimeaddr_t)); rimeaddr_set_node_addr(&addr); rf230_set_pan_addr(0xabcd,0xbabe,(uint8_t *)&addr.u8); rf230_set_channel(CHANNEL_802_15_4); rf230_set_txpower(0); /* max */ PRINTF("EUI-64 MAC: %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(); #define ANNOUNCE_BOOT 1 #if ANNOUNCE_BOOT PRINTF("%s %s, channel %u , check rate %u Hz tx power %u\n",NETSTACK_MAC.name, NETSTACK_RDC.name, rf230_get_channel(), CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1:NETSTACK_RDC.channel_check_interval()), rf230_get_txpower()); #if UIP_CONF_IPV6_RPL PRINTF("RPL Enabled\n"); #endif #if UIP_CONF_ROUTER PRINTF("Routing Enabled\n"); #endif #endif /* ANNOUNCE_BOOT */ process_start(&tcpip_process, NULL); /* Autostart other processes */ autostart_start(autostart_processes); #if ANNOUNCE_BOOT PRINTF("Online\n"); #endif /* ANNOUNCE_BOOT */ energest_init(); ENERGEST_ON(ENERGEST_TYPE_CPU); watchdog_start(); while (1) { /* Loop forever */ watchdog_periodic(); process_run(); } }
/*---------------------------------------------------------------------------*/ 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 NETSTACK_CONF_WITH_IPV4 slip_arch_init(115200); #endif /* NETSTACK_CONF_WITH_IPV4 */ 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 = (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]); 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 NETSTACK_CONF_WITH_IPV6 /* memcpy(&uip_lladdr.addr, ds2411_id, sizeof(uip_lladdr.addr)); */ memcpy(&uip_lladdr.addr, linkaddr_node_addr.u8, UIP_LLADDR_LEN > LINKADDR_SIZE ? LINKADDR_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 /* NETSTACK_CONF_WITH_IPV6 */ 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 /* 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 */ 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); } } }
/*---------------------------------------------------------------------------*/ 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) { /* crappy way of remembering and accessing argc/v */ contiki_argc = argc; contiki_argv = argv; /* native under windows is hardcoded to use the first one or two args */ /* for wpcap configuration so this needs to be "removed" from */ /* contiki_args (used by the native-border-router) */ //printf("Cgroups -timer\n"); /*Initalize "hardware".*/ init_timer(); clock_init(); rtimer_init(); //printf("Hello glorious world of cheese\n"); /* * Hardware initialization done! */ process_init(); process_start(&etimer_process, NULL); ctimer_init(); set_rime_addr(); queuebuf_init(); netstack_init(); //printf("MAC %s RDC %s NETWORK %s\n", NETSTACK_MAC.name, NETSTACK_RDC.name, NETSTACK_NETWORK.name); printf("Hello Rika, I am cgroups in contiki!\n"); serial_line_init(); autostart_start(autostart_processes); /* Make standard output unbuffered. */ setvbuf(stdout, (char *)NULL, _IONBF, 0); select_set_callback(STDIN_FILENO, &stdin_fd); /* * This is the scheduler loop. */ while(1) { fd_set fdr; fd_set fdw; int maxfd; int i; int retval; struct timeval tv; retval = process_run(); tv.tv_sec = 0; tv.tv_usec = retval ? 1 : 1000; FD_ZERO(&fdr); FD_ZERO(&fdw); maxfd = 0; for(i = 0; i <= select_max; i++) { if(select_callback[i] != NULL && select_callback[i]->set_fd(&fdr, &fdw)) { maxfd = i; } } retval = select(maxfd + 1, &fdr, &fdw, NULL, &tv); if(retval < 0) { perror("select"); } else if(retval > 0) { /* timeout => retval == 0 */ for(i = 0; i <= maxfd; i++) { if(select_callback[i] != NULL) { select_callback[i]->handle_fd(&fdr, &fdw); } } } etimer_request_poll(); } return 0; }
int main(int argc, char *argv[]) { /* find the argument to -c then strip the talon related front section */ char *recipe = NULL; int talon_returncode = 0; #ifdef HAS_WINSOCK2 WSADATA wsaData; WSAStartup(MAKEWORD(2,2), &wsaData); /* We ignore the result as we are only doing this to use gethostname and if that fails then leaving the host attribute blank is perfectly acceptable. */ #endif #ifdef HAS_GETCOMMANDLINE char *commandline= GetCommandLine(); /* * The command line should be either, * talon -c "some shell commands" * or * talon shell_script_file * * talon could be an absolute path and may have a .exe extension. */ recipe = chompCommand(commandline); if (recipe) { /* there was a -c so extract the quoted commands */ int recipelen = strlen(recipe); if (recipelen > 0 && recipe[recipelen - 1] == '"') recipe[recipelen - 1] = '\0'; /* remove trailing quote */ } else { /* there was no -c so extract the argument as a filename */ recipe = strstr(commandline, "talon"); if (recipe) { /* find the first space */ while (!isspace(*recipe) && *recipe != '\0') recipe++; /* skip past the spaces */ while (isspace(*recipe)) recipe++; recipe = read_recipe_from_file(recipe); if (!recipe) { error("talon: error: bad script file in shell call '%s'\n", commandline); return 1; } } else { error("talon: error: no 'talon' in shell call '%s'\n", commandline); return 1; } } #else /* * The command line should be either, * talon -c "some shell commands" * or * talon shell_script_file * * talon could be an absolute path and may have a .exe extension. */ switch (argc) { case 2: recipe = read_recipe_from_file(argv[1]); break; case 3: if (strcmp("-c", argv[1]) != 0) { error("talon: error: %s\n", "usage is 'talon -c command' or 'talon script_filename'"); return 1; } recipe = argv[2]; break; default: error("talon: error: %s\n", "usage is 'talon -c command' or 'talon script_filename'"); return 1; } #endif /* did we get a recipe at all? */ if (!recipe) { error("talon: error: %s", "no recipe supplied to the shell.\n"); return 1; } /* remove any leading white space on the recipe */ while (isspace(*recipe)) recipe++; /* turn debugging on? */ char *debugstr=talon_getenv("TALON_DEBUG"); if (debugstr) { loglevel=LOGDEBUG; free(debugstr); debugstr=NULL; } DEBUG(("talon: recipe: %s\n", recipe)); /* Make sure that the agent's hostname can be put into the host attribute */ char hostname[HOSTNAME_MAX]; int hostresult=0; hostresult = gethostname(hostname, HOSTNAME_MAX-1); if (0 != hostresult) { DEBUG(("talon: failed to get hostname: %d\n", hostresult)); hostname[0] = '\0'; } talon_setenv("HOSTNAME", hostname); DEBUG(("talon: setenv: hostname: %s\n", hostname)); char varname[VARNAMEMAX]; char varval[VARVALMAX]; int dotagging = 0; int force_descramble_off = 0; char *rp = recipe; if (*rp == TALONDELIMITER) { dotagging = 1; /* there are some talon-specific settings * in the command which must be stripped */ rp++; char *out = varname; char *stopout = varname + VARNAMEMAX - 1; DEBUG(("talon: parameters found\n")); while (*rp != '\0') { switch (*rp) { case '=': *out = '\0'; DEBUG(("talon: varname: %s\n",varname)); out = varval; stopout = varval + VARVALMAX - 1; break; case ';': *out = '\0'; DEBUG(("talon: varval: %s\n",varval)); talon_setenv(varname, varval); out = varname; stopout = varname + VARNAMEMAX - 1; break; default: *out = *rp; if (out < stopout) out++; break; } if (*rp == TALONDELIMITER) { rp++; break; } rp++; } } else { /* This is probably a $(shell) statement * in make so no descrambling needed and * tags are definitely not wanted as they * would corrupt the expected output*/ force_descramble_off = 1; } /* Now take settings from the environment (having potentially modified it) */ if (talon_getenv("TALON_DEBUG")) loglevel=LOGDEBUG; int enverrors = 0; char *shell = talon_getenv("TALON_SHELL"); if (!shell) { error("error: %s", "TALON_SHELL not set in environment\n"); enverrors++; } int timeout = -1; char *timeout_str = talon_getenv("TALON_TIMEOUT"); if (timeout_str) { timeout = atoi(timeout_str); free(timeout_str); timeout_str = NULL; } char *buildid = talon_getenv("TALON_BUILDID"); if (!buildid) { error("error: %s", "TALON_BUILDID not set in environment\n"); enverrors++; } char *attributes = talon_getenv("TALON_RECIPEATTRIBUTES"); if (!attributes) { error("error: %s", "TALON_RECIPEATTRIBUTES not set in environment\n"); enverrors++; } int max_retries = 0; char *retries_str = talon_getenv("TALON_RETRIES"); if (retries_str) { max_retries = atoi(retries_str); free(retries_str); retries_str = NULL; } int descramble = 0; if (! force_descramble_off ) { char *descramblestr = talon_getenv("TALON_DESCRAMBLE"); if (descramblestr) { if (*descramblestr == '0') descramble = 0; else descramble = 1; free(descramblestr); descramblestr = NULL; } } /* check command line lengths if a maximum is supplied */ int shell_cl_max = 0; char *shell_cl_max_str = talon_getenv("TALON_SHELL_CL_MAX"); if (shell_cl_max_str) { shell_cl_max = atoi(shell_cl_max_str); free(shell_cl_max_str); shell_cl_max_str = NULL; } /* Talon can look in a flags variable to alter its behaviour */ int force_success = 0; char *flags_str = talon_getenv("TALON_FLAGS"); if (flags_str) { int c; for (c=0; flags_str[c] !=0; c++) flags_str[c] = tolower(flags_str[c]); if (strstr(flags_str, "forcesuccess")) force_success = 1; /* don't put <recipe> or <CDATA<[[ tags around the output. e.g. if it's XML already*/ if (strstr(flags_str, "rawoutput")) { dotagging = 0; } free(flags_str); flags_str = NULL; } /* Talon subprocesses need to have the "correct" shell variable set. */ talon_setenv("SHELL", shell); /* we have allowed some errors to build up so that the user * can see all of them before we stop and force the user * to fix them */ if (enverrors) { return 1; } /* Run the recipe repeatedly until the retry count expires or * it succeeds. */ int attempt = 0, retries = max_retries; proc *p = NULL; char *args[5]; char *qrp=rp; #ifdef HAS_GETCOMMANDLINE /* re-quote the argument to -c since this helps windows deal with it */ int qrpsize = strlen(rp) + 3; qrp = malloc(qrpsize); qrp[0] = '"'; strcpy(&qrp[1], rp); qrp[qrpsize-2] = '"'; qrp[qrpsize-1] = '\0'; #endif int index = 0; args[index++] = shell; if (dotagging) /* don't do bash -x for non-tagged commands e.g. $(shell output) */ args[index++] = "-x"; args[index++] = "-c"; args[index++] = qrp; args[index++] = NULL; /* get the semaphore ready */ talon_sem.name = buildid; talon_sem.timeout = timeout; do { char talon_attempt[TALON_ATTEMPT_STRMAX]; double start_time = getseconds(); attempt++; snprintf(talon_attempt, TALON_ATTEMPT_STRMAX-1, "%d", attempt); talon_attempt[TALON_ATTEMPT_STRMAX - 1] = '\0'; talon_setenv("TALON_ATTEMPT", talon_attempt); p = process_run(shell, args, timeout); double end_time = getseconds(); if (p) { talon_returncode = p->returncode; if (dotagging) { char status[STATUS_STRMAX]; char timestat[STATUS_STRMAX]; char warning[WARNING_STRMAX]; warning[0] = '\0'; if (shell_cl_max) { int cl_actual = strlen(qrp); if (cl_actual > shell_cl_max) { snprintf(warning, WARNING_STRMAX-1, \ "\n<warning>Command line length '%d' exceeds the shell limit on this system of '%d'. " \ "If this recipe is a compile, try using the '.use_compilation_command_file' variant to reduce overall command line length.</warning>", \ cl_actual, shell_cl_max); warning[WARNING_STRMAX-1] = '\0'; } } char *flagsstr = force_success == 0 ? "" : " flags='FORCESUCCESS'"; char *reasonstr = "" ; if (p->causeofdeath == PROC_TIMEOUTDEATH) reasonstr = " reason='timeout'"; if (p->returncode != 0) { char *exitstr = (force_success || retries <= 0) ? "failed" : "retry"; snprintf(status, STATUS_STRMAX - 1, "\n<status exit='%s' code='%d' attempt='%d'%s%s />", exitstr, p->returncode, attempt, flagsstr, reasonstr ); } else { snprintf(status, STATUS_STRMAX - 1, "\n<status exit='ok' attempt='%d'%s%s />", attempt, flagsstr, reasonstr ); } status[STATUS_STRMAX-1] = '\0'; snprintf(timestat, STATUS_STRMAX - 1, "<time start='%.5f' elapsed='%.3f' />",start_time, end_time-start_time ); timestat[STATUS_STRMAX-1] = '\0'; prependattributes(p->output, attributes); buffer_append(p->output, "\n]]>", 4); buffer_append(p->output, timestat, strlen(timestat)); buffer_append(p->output, status, strlen(status)); buffer_append(p->output, warning, strlen(warning)); buffer_append(p->output, "\n</recipe>\n", 11); } unsigned int iterator = 0; unsigned int written = 0; byteblock *bb; char sub[7] = "�"; if (descramble) sema_wait(&talon_sem); while ((bb = buffer_getbytes(p->output, &iterator))) { if (bb->fill < 1) continue; /* empty buffer */ if (dotagging) { /* the output is XML so we must replace any non-printable characters */ char *ptr = &bb->byte0; char *end = ptr + bb->fill; char *start = ptr; while (ptr < end) { if ((*ptr < 32 || *ptr > 126) && *ptr != 9 && *ptr != 10 && *ptr != 13) { /* output any unwritten characters before this non-printable */ if (ptr > start) write(STDOUT_FILENO, start, ptr - start); /* 0->� 1-> ... 255->ÿ */ sprintf(sub, "&#x%02x;", (unsigned char)*ptr); /* output the modified non-printable character */ write(STDOUT_FILENO, sub, 6); start = ptr + 1; } ptr++; } if (ptr > start) write(STDOUT_FILENO, start, ptr - start); } else { /* the output isn't XML so write out the whole buffer as-is */ written = write(STDOUT_FILENO, &bb->byte0, bb->fill); DEBUG(("talon: wrote %d bytes out of %d\n", written, bb->fill)); } } if (descramble) sema_release(&talon_sem); if (p->returncode == 0 || force_success) { process_free(&p); break; } process_free(&p); } else { error("error: failed to run shell: %s: check the SHELL environment variable.\n", args[0]); return 1; } retries--; } while (retries >= 0); if (buildid) free(buildid); buildid = NULL; if (attributes) free(attributes); attributes = NULL; if (shell) free(shell); shell = NULL; if (force_success) return 0; else return talon_returncode; }
int main(void) { mc1322x_init(); /* m12_init() flips the mux switch */ /* trims the main crystal load capacitance */ if (!FORCE_ECONOTAG_I && CRM->SYS_CNTLbits.XTAL32_EXISTS) { /* M12 based econotag */ PRINTF("trim xtal for M12\n\r"); CRM->XTAL_CNTLbits.XTAL_CTUNE = (M12_CTUNE_4PF << 4) | M12_CTUNE; CRM->XTAL_CNTLbits.XTAL_FTUNE = M12_FTUNE; } else { /* econotag I */ PRINTF("trim xtal for Econotag I\n\r"); CRM->XTAL_CNTLbits.XTAL_CTUNE = (ECONOTAG_CTUNE_4PF << 4) | ECONOTAG_CTUNE; CRM->XTAL_CNTLbits.XTAL_FTUNE = ECONOTAG_FTUNE; } /* create mac address if blank*/ if (mc1322x_config.eui == 0) { /* mac address is blank */ /* construct a new mac address based on IAB or OUI definitions */ /* if an M12_SERIAL number is not defined */ /* generate a random extension in the Redwire experimental IAB */ /* The Redwire IAB (for development only) is: */ /* OUI: 0x0050C2 IAB: 0xA8C */ /* plus a random 24-bit extension */ /* Otherwise, construct a mac based on the M12_SERIAL */ /* Owners of an Econotag I (not M12 based) can request a serial number from Redwire */ /* to use here */ /* M12 mac is of the form "EC473C4D12000000" */ /* Redwire's OUI: EC473C */ /* M12: 4D12 */ /* next six nibbles are the M12 serial number as hex */ /* e.g. if the barcode reads: "12440021" = BDD1D5 */ /* full mac is EC473C4D12BDD1D5 */ #if (M12_SERIAL == 0) /* use random mac from experimental range */ mc1322x_config.eui = (0x0050C2A8Cull << 24) | (*MACA_RANDOM & (0xffffff)); #else /* construct mac from serial number */ mc1322x_config.eui = (0xEC473C4D12ull << 24) | M12_SERIAL; #endif mc1322x_config_save(&mc1322x_config); } /* configure address on maca hardware and RIME */ contiki_maca_set_mac_address(mc1322x_config.eui); #if WITH_UIP6 memcpy(&uip_lladdr.addr, &rimeaddr_node_addr.u8, sizeof(uip_lladdr.addr)); queuebuf_init(); NETSTACK_RDC.init(); NETSTACK_MAC.init(); NETSTACK_NETWORK.init(); #if DEBUG_ANNOTATE print_netstack(); #endif #if ! CETIC_6LBR process_start(&tcpip_process, NULL); #endif #if DEBUG_ANNOTATE print_lladdrs(); #endif #endif /* endif WITH_UIP6 */ process_start(&sensors_process, NULL); print_processes(autostart_processes); autostart_start(autostart_processes); /* Main scheduler loop */ while(1) { check_maca(); if(uart1_input_handler != NULL) { if(uart1_can_get()) { uart1_input_handler(uart1_getc()); } } process_run(); } return 0; }
/*---------------------------------------------------------------------------*/ int main(void) { /* * Initialize hardware. */ halInit(); clock_init(); uart1_init(115200); // Led initialization leds_init(); INTERRUPTS_ON(); PRINTF("\r\nStarting "); PRINTF(CONTIKI_VERSION_STRING); PRINTF(" on %s\r\n",boardDescription->name); /* * Initialize Contiki and our processes. */ process_init(); #if WITH_SERIAL_LINE_INPUT uart1_set_input(serial_line_input_byte); serial_line_init(); #endif process_start(&etimer_process, NULL); ctimer_init(); rtimer_init(); netstack_init(); set_rime_addr(); PRINTF("ACK enable=%u %s %s, channel check rate=%luHz, check interval %ums, clock second=%u, radio channel %u\r\n", ST_RadioAutoAckEnabled(), NETSTACK_MAC.name, NETSTACK_RDC.name, CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0? 1: NETSTACK_RDC.channel_check_interval()), NETSTACK_RDC.channel_check_interval(), CLOCK_SECOND, RF_CHANNEL); #if !UIP_CONF_IPV6 ST_RadioEnableAutoAck(FALSE); // Because frames are not 802.15.4 compatible. ST_RadioEnableAddressFiltering(FALSE); #endif ST_RadioEnableAutoAck(TRUE); procinit_init(); energest_init(); ENERGEST_ON(ENERGEST_TYPE_CPU); autostart_start(autostart_processes); watchdog_start(); while(1){ int r; do { /* Reset watchdog. */ watchdog_periodic(); r = process_run(); } while(r > 0); ENERGEST_OFF(ENERGEST_TYPE_CPU); //watchdog_stop(); ENERGEST_ON(ENERGEST_TYPE_LPM); /* Go to idle mode. */ halSleepWithOptions(SLEEPMODE_IDLE,0); /* We are awake. */ //watchdog_start(); ENERGEST_OFF(ENERGEST_TYPE_LPM); ENERGEST_ON(ENERGEST_TYPE_CPU); } }
int main(int argc, char **argv) { contiki_argc = argc; contiki_argv = argv; /* The first one or two args are used for wpcap configuration */ /* so this needs to be "removed" from contiki_args. */ contiki_argc--; contiki_argv++; #ifdef UIP_FALLBACK_INTERFACE contiki_argc--; contiki_argv++; #endif process_init(); procinit_init(); #ifdef PLATFORM_BUILD program_handler_add(&directory_dsc, "Directory", 1); program_handler_add(&www_dsc, "Web browser", 1); #endif /* PLATFORM_BUILD */ autostart_start(autostart_processes); #if !NETSTACK_CONF_WITH_IPV6 { uip_ipaddr_t addr; uip_ipaddr(&addr, 192,168,0,111); uip_sethostaddr(&addr); log_message("IP Address: ", inet_ntoa(*(struct in_addr*)&addr)); uip_ipaddr(&addr, 255,255,255,0); uip_setnetmask(&addr); log_message("Subnet Mask: ", inet_ntoa(*(struct in_addr*)&addr)); uip_ipaddr(&addr, 192,168,0,1); uip_setdraddr(&addr); log_message("Def. Router: ", inet_ntoa(*(struct in_addr*)&addr)); uip_ipaddr(&addr, 192,168,0,1); uip_nameserver_update(&addr, UIP_NAMESERVER_INFINITE_LIFETIME); log_message("DNS Server: ", inet_ntoa(*(struct in_addr*)&addr)); } #else /* NETSTACK_CONF_WITH_IPV6 */ #if !UIP_CONF_IPV6_RPL #ifdef HARD_CODED_ADDRESS uip_ipaddr_t ipaddr; uiplib_ipaddrconv(HARD_CODED_ADDRESS, &ipaddr); if ((ipaddr.u16[0]!=0) || (ipaddr.u16[1]!=0) || (ipaddr.u16[2]!=0) || (ipaddr.u16[3]!=0)) { #if UIP_CONF_ROUTER uip_ds6_prefix_add(&ipaddr, UIP_DEFAULT_PREFIX_LEN, 0, 0, 0, 0); #else /* UIP_CONF_ROUTER */ uip_ds6_prefix_add(&ipaddr, UIP_DEFAULT_PREFIX_LEN, 0); #endif /* UIP_CONF_ROUTER */ #if !UIP_CONF_IPV6_RPL uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr); uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF); #endif } #endif /* HARD_CODED_ADDRESS */ #endif #endif while(1) { process_run(); etimer_request_poll(); /* Allow user-mode APC to execute. */ SleepEx(10, TRUE); #ifdef PLATFORM_BUILD if(console_resize()) { ctk_restore(); } #endif /* PLATFORM_BUILD */ } }
//#pragma FUNC_NEVER_RETURNS(main); void main(void) { _disable_interrupts(); msp430_init(); clock_init(); // initialize uip_variables memset(uip_buf, 0, UIP_CONF_BUFFER_SIZE); uip_len = 0; leds_init(); buttons_init(); usb_init_proc(); /* Create MAC addresses based on a hash of the unique id (wafle id + x-pos * in wafel + y-pos in wafel). * We use rime addresses in order to use useful rime address handling * functions. */ /* The sicslowmac layer requires the mac address to be placed in the global * (extern) variable rimeaddr_node_addr (declared rimeaddr.h). */ rimeaddr_node_addr.u8[0] = NODE_BASE_ADDR0; rimeaddr_node_addr.u8[1] = NODE_BASE_ADDR1; rimeaddr_node_addr.u8[2] = NODE_BASE_ADDR2; rimeaddr_node_addr.u8[3] = NODE_BASE_ADDR3; rimeaddr_node_addr.u8[4] = NODE_BASE_ADDR4; rimeaddr_node_addr.u8[5] = *((unsigned char*)(WAFERID+2)); // lowest byte of wafer id rimeaddr_node_addr.u8[6] = *((unsigned char*)(WAFERIPOSX)); // lowest byte of x-pos in wafer rimeaddr_node_addr.u8[7] = *((unsigned char*)(WAFERIPOSY)); // lowest byte of y-pos in wafer /* The following line sets the link layer address. This must be done * before the tcpip_process is started since in its initialization * routine the function uip_netif_init() will be called from inside * uip_init()and there the default IPv6 address will be set by combining * the link local prefix (fe80::/64)and the link layer address. */ rimeaddr_copy((rimeaddr_t*)&uip_lladdr.addr, &rimeaddr_node_addr); /* Initialize the process module */ process_init(); /* etimers must be started before ctimer_init */ // clock_init(); process_start(&etimer_process, NULL); /* Start radio and radio receive process */ if (NETSTACK_RADIO.init() == FAILED) { led_on(LED_RED); _disable_interrupts(); LPM4; // die } /* Initialize stack protocols */ queuebuf_init(); NETSTACK_RDC.init(); NETSTACK_MAC.init(); NETSTACK_NETWORK.init(); /* Initialize tcpip process */ process_start(&tcpip_process, NULL); /* Initialize our application(s) */ process_start(&rfid_find_tags, NULL); process_start(&usb_input_process, NULL); process_start(&coap_app_client, NULL); //process_start(&coap_app, NULL); /* Enter main loop */ while(1) { /* poll every running process which has requested to be polled */ process_run(); /* * Enter low power mode 3 safely. The CPU will wake up in the timer * interrupt or whenever a packet arrives. In the timer interrupt * routine, we check wether an etimer has expired and, if so, * we call the etimer_request_poll() function */ //LPM3; } }
/*---------------------------------------------------------------------------*/ 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 */ } }
/*-----------------------------Low level initialization--------------------*/ static void initialize(void) { watchdog_init(); watchdog_start(); #if CONFIG_STACK_MONITOR /* Simple stack pointer highwater monitor. The 'm' command in cdc_task.c * looks for the first overwritten magic number. */ { extern uint16_t __bss_end; uint16_t p=(uint16_t)&__bss_end; do { *(uint16_t *)p = 0x4242; p+=100; } while (p<SP-100); //don't overwrite our own stack } #endif /* Initialize hardware */ // Checks for "finger", jumps to DFU if present. init_lowlevel(); /* Clock */ clock_init(); /* Leds are referred to by number to prevent any possible confusion :) */ /* Led0 Blue Led1 Red Led2 Green Led3 Yellow */ Leds_init(); Led1_on(); /* Get a random (or probably different) seed for the 802.15.4 packet sequence number. * Some layers will ignore duplicates found in a history (e.g. Contikimac) * causing the initial packets to be ignored after a short-cycle restart. */ ADMUX =0x1E; //Select AREF as reference, measure 1.1 volt bandgap reference. ADCSRA=1<<ADEN; //Enable ADC, not free running, interrupt disabled, fastest clock ADCSRA|=1<<ADSC; //Start conversion while (ADCSRA&(1<<ADSC)); //Wait till done PRINTD("ADC=%d\n",ADC); random_init(ADC); ADCSRA=0; //Disable ADC #if USB_CONF_RS232 /* Use rs232 port for serial out (tx, rx, gnd are the three pads behind jackdaw leds */ rs232_init(RS232_PORT_0, USART_BAUD_57600,USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8); /* Redirect stdout to second port */ rs232_redirect_stdout(RS232_PORT_0); #if ANNOUNCE PRINTA("\n\n*******Booting %s*******\n",CONTIKI_VERSION_STRING); #endif #endif /* rtimer init needed for low power protocols */ rtimer_init(); /* Process subsystem. */ process_init(); /* etimer process must be started before USB or ctimer init */ process_start(&etimer_process, NULL); Led2_on(); /* Now we can start USB enumeration */ process_start(&usb_process, NULL); /* Start CDC enumeration, bearing in mind that it may fail */ /* Hopefully we'll get a stdout for startup messages, if we don't already */ #if USB_CONF_SERIAL process_start(&cdc_process, NULL); {unsigned short i; for (i=0;i<65535;i++) { process_run(); watchdog_periodic(); if (stdout) break; } #if !USB_CONF_RS232 PRINTA("\n\n*******Booting %s*******\n",CONTIKI_VERSION_STRING); #endif } #endif if (!stdout) Led3_on(); #if RF230BB #if JACKDAW_CONF_USE_SETTINGS PRINTA("Settings manager will be used.\n"); #else {uint8_t x[2]; *(uint16_t *)x = eeprom_read_word((uint16_t *)&eemem_channel); if((uint8_t)x[0]!=(uint8_t)~x[1]) { PRINTA("Invalid EEPROM settings detected. Rewriting with default values.\n"); get_channel_from_eeprom(); } } #endif ctimer_init(); /* Start radio and radio receive process */ /* Note this starts RF230 process, so must be done after process_init */ NETSTACK_RADIO.init(); /* Set addresses BEFORE starting tcpip process */ memset(&tmp_addr, 0, sizeof(rimeaddr_t)); if(get_eui64_from_eeprom(tmp_addr.u8)); //Fix MAC address init_net(); #if UIP_CONF_IPV6 memcpy(&uip_lladdr.addr, &tmp_addr.u8, 8); #endif rf230_set_pan_addr( get_panid_from_eeprom(), get_panaddr_from_eeprom(), (uint8_t *)&tmp_addr.u8 ); rf230_set_channel(get_channel_from_eeprom()); rf230_set_txpower(get_txpower_from_eeprom()); rimeaddr_set_node_addr(&tmp_addr); /* Initialize stack protocols */ queuebuf_init(); NETSTACK_RDC.init(); NETSTACK_MAC.init(); NETSTACK_NETWORK.init(); #if ANNOUNCE PRINTA("MAC address %x:%x:%x:%x:%x:%x:%x:%x\n\r",tmp_addr.u8[0],tmp_addr.u8[1],tmp_addr.u8[2],tmp_addr.u8[3],tmp_addr.u8[4],tmp_addr.u8[5],tmp_addr.u8[6],tmp_addr.u8[7]); PRINTA("%s %s, channel %u, panid 0x%X",NETSTACK_MAC.name, NETSTACK_RDC.name, rf230_get_channel(), IEEE802154_PANID); if (NETSTACK_RDC.channel_check_interval) { 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_IPV6_RPL #if RPL_BORDER_ROUTER process_start(&tcpip_process, NULL); process_start(&border_router_process, NULL); PRINTD ("RPL Border Router Started\n"); #else process_start(&tcpip_process, NULL); PRINTD ("RPL Started\n"); #endif #if RPL_HTTPD_SERVER extern struct process httpd_process; process_start(&httpd_process, NULL); PRINTD ("Webserver Started\n"); #endif #endif /* UIP_CONF_IPV6_RPL */ #else /* RF230BB */ /* The order of starting these is important! */ process_start(&mac_process, NULL); process_start(&tcpip_process, NULL); #endif /* RF230BB */ /* Start ethernet network and storage process */ process_start(&usb_eth_process, NULL); #if USB_CONF_STORAGE process_start(&storage_process, NULL); #endif /* Autostart other processes */ /* There are none in the default build so autostart_processes will be unresolved in the link. */ /* The AUTOSTART_PROCESSES macro which defines it can only be used in the .co module. */ /* See /examples/ravenusbstick/ravenusb.c for an autostart template. */ #if 0 autostart_start(autostart_processes); #endif #if ANNOUNCE #if USB_CONF_RS232 PRINTA("Online.\n"); #else PRINTA("Online. Type ? for Jackdaw menu.\n"); #endif #endif Leds_off(); }
int main(int argc, char **argv) { bool flip_flop = false; asm ("di"); /* Setup clocks */ CMC = 0x11U; /* Enable XT1, disable X1 */ CSC = 0x80U; /* Start XT1 and HOCO, stop X1 */ CKC = 0x00U; delay_1sec(); OSMC = 0x00; /* Supply fsub to peripherals, including Interval Timer */ uart0_init(); #if __GNUC__ /* Force linking of custom write() function: */ write(1, NULL, 0); #endif /* Setup 12-bit interval timer */ RTCEN = 1; /* Enable 12-bit interval timer and RTC */ ITMK = 1; /* Disable IT interrupt */ ITPR0 = 0; /* Set interrupt priority - highest */ ITPR1 = 0; ITMC = 0x8FFFU; /* Set maximum period 4096/32768Hz = 1/8 s, and start timer */ ITIF = 0; /* Clear interrupt request flag */ ITMK = 0; /* Enable IT interrupt */ /* asm ("ei"); / * Enable interrupts * / */ /* Disable analog inputs because they can conflict with the SPI buses: */ ADPC = 0x01; /* Configure all analog pins as digital I/O. */ PMC0 &= 0xF0; /* Disable analog inputs. */ clock_init(); /* Initialize Joystick Inputs: */ PM5 |= BIT(5) | BIT(4) | BIT(3) | BIT(2) | BIT(1); /* Set pins as inputs. */ PU5 |= BIT(5) | BIT(4) | BIT(3) | BIT(2) | BIT(1); /* Enable internal pull-up resistors. */ /* Initialize LED outputs: */ #define BIT(n) (1 << (n)) PM12 &= ~BIT(0); /* LED1 */ PM4 &= ~BIT(3); /* LED2 */ PM1 &= ~BIT(6); /* LED3 */ PM1 &= ~BIT(5); /* LED4 */ PM0 &= ~BIT(6); /* LED5 */ PM0 &= ~BIT(5); /* LED6 */ PM3 &= ~BIT(0); /* LED7 */ PM5 &= ~BIT(0); /* LED8 */ #if UIP_CONF_IPV6 #if UIP_CONF_IPV6_RPL printf(CONTIKI_VERSION_STRING " started with IPV6, RPL" NEWLINE); #else printf(CONTIKI_VERSION_STRING " started with IPV6" NEWLINE); #endif #else printf(CONTIKI_VERSION_STRING " started" NEWLINE); #endif /* crappy way of remembering and accessing argc/v */ contiki_argc = argc; contiki_argv = argv; process_init(); process_start(&etimer_process, NULL); ctimer_init(); set_rime_addr(); queuebuf_init(); netstack_init(); printf("MAC %s RDC %s NETWORK %s" NEWLINE, NETSTACK_MAC.name, NETSTACK_RDC.name, NETSTACK_NETWORK.name); #if WITH_UIP6 memcpy(&uip_lladdr.addr, serial_id, 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]); } /* make it hardcoded... */ lladdr->state = ADDR_AUTOCONF; printf("%02x%02x" NEWLINE, lladdr->ipaddr.u8[14], lladdr->ipaddr.u8[15]); } #else process_start(&tcpip_process, NULL); #endif serial_line_init(); autostart_start(autostart_processes); while(1) { watchdog_periodic(); if(NETSTACK_RADIO.pending_packet()) { int len; packetbuf_clear(); len = NETSTACK_RADIO.read(packetbuf_dataptr(), PACKETBUF_SIZE); if(len > 0) { packetbuf_set_datalen(len); NETSTACK_RDC.input(); } } while(uart0_can_getchar()) { char c; UART_RX_LED = 1; c = uart0_getchar(); if(uart0_input_handler) { uart0_input_handler(c); } } UART_RX_LED = 0; process_run(); etimer_request_poll(); HEARTBEAT_LED1 = flip_flop; flip_flop = !flip_flop; HEARTBEAT_LED2 = flip_flop; } return 0; }
/*---------------------------------Main Routine----------------------------*/ int main(void) { /* GCC depends on register r1 set to 0 (?) */ asm volatile ("clr r1"); /* Initialize in a subroutine to maximize stack space */ initialize(); #if DEBUG {struct process *p; for(p = PROCESS_LIST();p != NULL; p = ((struct process *)p->next)) { PRINTA("Process=%p Thread=%p Name=\"%s\" \n",p,p->thread,PROCESS_NAME_STRING(p)); } } #endif while(1) { process_run(); watchdog_periodic(); /* Print rssi of all received packets, useful for range testing */ #ifdef RF230_MIN_RX_POWER uint8_t lastprint; if (rf230_last_rssi != lastprint) { //can be set in halbb.c interrupt routine PRINTA("%u ",rf230_last_rssi); lastprint=rf230_last_rssi; } #endif #if 0 /* Clock.c can trigger a periodic PLL calibration in the RF230BB driver. * This can show when that happens. */ extern uint8_t rf230_calibrated; if (rf230_calibrated) { PRINTA("\nRF230 calibrated!\n"); rf230_calibrated=0; } #endif #if TESTRTIMER /* Timeout can be increased up to 8 seconds maximum. * A one second cycle is convenient for triggering the various debug printouts. * The triggers are staggered to avoid printing everything at once. * My Jackdaw is 4% slow. */ if (rtimerflag) { rtimer_set(&rt, RTIMER_NOW()+ RTIMER_ARCH_SECOND*1UL, 1,(void *) rtimercycle, NULL); rtimerflag=0; #if STAMPS if ((rtime%STAMPS)==0) { PRINTA("%us ",rtime); if (rtime%STAMPS*10) PRINTA("\n"); } #endif rtime+=1; #if PINGS && UIP_CONF_IPV6_RPL extern void raven_ping6(void); if ((rtime%PINGS)==1) { PRINTA("**Ping\n"); raven_ping6(); } #endif #if ROUTES && UIP_CONF_IPV6_RPL if ((rtime%ROUTES)==2) { extern uip_ds6_nbr_t uip_ds6_nbr_cache[]; extern uip_ds6_route_t uip_ds6_routing_table[]; extern uip_ds6_netif_t uip_ds6_if; uint8_t i,j; PRINTA("\nAddresses [%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"); } } PRINTA("\nNeighbors [%u max]\n",UIP_DS6_NBR_NB); for(i = 0,j=1; i < UIP_DS6_NBR_NB; i++) { if(uip_ds6_nbr_cache[i].isused) { uip_debug_ipaddr_print(&uip_ds6_nbr_cache[i].ipaddr); PRINTA("\n"); j=0; } } if (j) PRINTA(" <none>"); PRINTA("\nRoutes [%u max]\n",UIP_DS6_ROUTE_NB); for(i = 0,j=1; i < UIP_DS6_ROUTE_NB; i++) { if(uip_ds6_routing_table[i].isused) { uip_debug_ipaddr_print(&uip_ds6_routing_table[i].ipaddr); PRINTA("/%u (via ", uip_ds6_routing_table[i].length); uip_debug_ipaddr_print(&uip_ds6_routing_table[i].nexthop); // if(uip_ds6_routing_table[i].state.lifetime < 600) { PRINTA(") %lus\n", uip_ds6_routing_table[i].state.lifetime); // } else { // PRINTA(")\n"); // } j=0; } } if (j) PRINTA(" <none>"); PRINTA("\n---------\n"); } #endif #if STACKMONITOR && CONFIG_STACK_MONITOR if ((rtime%STACKMONITOR)==3) { extern uint16_t __bss_end; uint16_t p=(uint16_t)&__bss_end; do { if (*(uint16_t *)p != 0x4242) { PRINTA("Never-used stack > %d bytes\n",p-(uint16_t)&__bss_end); break; } p+=100; } while (p<RAMEND-10); } #endif } #endif /* TESTRTIMER */ //Use with RF230BB DEBUGFLOW to show path through driver #if RF230BB&&0 extern uint8_t debugflowsize,debugflow[]; //in rf230bb.c if (debugflowsize) { debugflow[debugflowsize]=0; PRINTA("%s",debugflow); debugflowsize=0; } #endif } return 0; }
/** * \brief Main function for CC26xx-based platforms * * The same main() is used for both Srf+CC26xxEM as well as for the SensorTag */ int main(void) { /* Set the LF XOSC as the LF system clock source */ select_lf_xosc(); /* * Make sure to open the latches - this will be important when returning * from shutdown */ ti_lib_pwr_ctrl_io_freeze_disable(); /* Use DCDC instead of LDO to save current */ ti_lib_pwr_ctrl_source_set(PWRCTRL_PWRSRC_DCDC); lpm_init(); board_init(); /* Enable flash cache and prefetch. */ ti_lib_vims_mode_set(VIMS_BASE, VIMS_MODE_ENABLED); ti_lib_vims_configure(VIMS_BASE, true, true); gpio_interrupt_init(); /* Clock must always be enabled for the semaphore module */ HWREG(AUX_WUC_BASE + AUX_WUC_O_MODCLKEN1) = AUX_WUC_MODCLKEN1_SMPH; leds_init(); fade(LEDS_RED); cc26xx_rtc_init(); clock_init(); rtimer_init(); watchdog_init(); process_init(); random_init(0x1234); /* Character I/O Initialisation */ #if CC26XX_UART_CONF_ENABLE cc26xx_uart_init(); cc26xx_uart_set_input(serial_line_input_byte); #endif serial_line_init(); printf("Starting " CONTIKI_VERSION_STRING "\n"); printf("With DriverLib v%u.%02u.%02u.%u\n", DRIVERLIB_MAJOR_VER, DRIVERLIB_MINOR_VER, DRIVERLIB_PATCH_VER, DRIVERLIB_BUILD_ID); printf(BOARD_STRING " using CC%u\n", CC26XX_MODEL_CPU_VARIANT); process_start(&etimer_process, NULL); ctimer_init(); energest_init(); ENERGEST_ON(ENERGEST_TYPE_CPU); fade(LEDS_YELLOW); printf(" Net: "); printf("%s\n", NETSTACK_NETWORK.name); printf(" MAC: "); printf("%s\n", NETSTACK_MAC.name); printf(" RDC: "); printf("%s", NETSTACK_RDC.name); if(NETSTACK_RDC.channel_check_interval() != 0) { printf(", Channel Check Interval: %u ticks", NETSTACK_RDC.channel_check_interval()); } printf("\n"); netstack_init(); set_rf_params(); #if NETSTACK_CONF_WITH_IPV6 memcpy(&uip_lladdr.addr, &linkaddr_node_addr, sizeof(uip_lladdr.addr)); queuebuf_init(); process_start(&tcpip_process, NULL); #endif /* NETSTACK_CONF_WITH_IPV6 */ fade(LEDS_GREEN); process_start(&sensors_process, NULL); autostart_start(autostart_processes); watchdog_start(); fade(LEDS_ORANGE); while(1) { uint8_t r; do { r = process_run(); watchdog_periodic(); } while(r > 0); /* Drop to some low power mode */ lpm_drop(); } }
/*-----------------------------------------------------------------------------------*/ void main(void) { struct ethernet_config *ethernet_config; close(STDIN_FILENO); close(STDOUT_FILENO); #if !UIP_LOGGING && !LOG_CONF_ENABLED close(STDERR_FILENO); #endif /* !UIP_LOGGING && !LOG_CONF_ENABLED */ process_init(); #if 1 ethernet_config = config_read("contiki.cfg"); #else { static struct ethernet_config config = {0xDE08, "cs8900a.eth"}; uip_ipaddr_t addr; uip_ipaddr(&addr, 192,168,0,128); uip_sethostaddr(&addr); uip_ipaddr(&addr, 255,255,255,0); uip_setnetmask(&addr); uip_ipaddr(&addr, 192,168,0,1); uip_setdraddr(&addr); uip_ipaddr(&addr, 192,168,0,1); resolv_conf(&addr); ethernet_config = &config; } #endif #if (WITH_GUI && WITH_MOUSE) { static const u8_t mouse_sprite[64] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0xE0, 0x00, 0x0F, 0xC0, 0x00, 0x0F, 0x80, 0x00, 0x0F, 0xC0, 0x00, 0x0D, 0xE0, 0x00, 0x08, 0xF0, 0x00, 0x00, 0x78, 0x00, 0x00, 0x3C, 0x00, 0x00, 0x1E, 0x00, 0x00, 0x0F, 0x00, 0x00, 0x07, 0x80, 0x00, 0x03, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; memcpy((void*)0x0E00, mouse_sprite, sizeof(mouse_sprite)); *(u8_t*)0x07F8 = 0x0E00 / 64; VIC.spr0_color = COLOR_WHITE; } #endif /* WITH_GUI && WITH_MOUSE */ procinit_init(); process_start((struct process *)ðernet_process, (char *)ethernet_config); autostart_start(autostart_processes); log_message("Contiki up and running ...", ""); while(1) { if(process_run() < 2) { etimer_request_poll(); } } }
/*---------------------------------------------------------------------------*/ int main(void) { /* * Initialize hardware. */ halInit(); clock_init(); uart1_init(115200); // Led initialization leds_init(); INTERRUPTS_ON(); PRINTF("\r\nStarting "); PRINTF(CONTIKI_VERSION_STRING); PRINTF(" on %s\r\n",boardDescription->name); /* * Initialize Contiki and our processes. */ process_init(); #if WITH_SERIAL_LINE_INPUT uart1_set_input(serial_line_input_byte); serial_line_init(); #endif //etimer_process should be started before ctimer init process_start(&etimer_process, NULL); //ctimer and rtimer should be initialized before netstack to enable RDC (cxmac, contikimac, lpp) ctimer_init(); rtimer_init(); netstack_init(); #if !UIP_CONF_IPV6 ST_RadioEnableAutoAck(FALSE); // Because frames are not 802.15.4 compatible. ST_RadioEnableAddressFiltering(FALSE); #endif set_rime_addr(); procinit_init(); energest_init(); ENERGEST_ON(ENERGEST_TYPE_CPU); autostart_start(autostart_processes); watchdog_start(); while(1){ int r; do { /* Reset watchdog. */ watchdog_periodic(); r = process_run(); } while(r > 0); ENERGEST_OFF(ENERGEST_TYPE_CPU); //watchdog_stop(); ENERGEST_ON(ENERGEST_TYPE_LPM); /* Go to idle mode. */ halSleepWithOptions(SLEEPMODE_IDLE,0); /* We are awake. */ //watchdog_start(); ENERGEST_OFF(ENERGEST_TYPE_LPM); ENERGEST_ON(ENERGEST_TYPE_CPU); } }
int main(void) { /* generic hw init */ hw_init(); /* init uart */ uart_init(); #ifdef DEBUG_INIT printf("AlceOSD hw%dv%d fw%d.%d.%d\r\n", hw_rev >> 4, hw_rev & 0xf, VERSION_MAJOR, VERSION_MINOR, VERSION_DEV); if (RCONbits.WDTO) printf("watchdog reset\r\n"); if (RCONbits.EXTR) printf("external reset\r\n"); if (RCONbits.SWR) printf("software reset\r\n"); if (RCONbits.IOPUWR) printf("ill opcode / uninit W reset\r\n"); if (RCONbits.WDTO) printf("trap conflict reset\r\n"); #endif /* real time clock init */ clock_init(); /* adc init */ adc_init(); /* init video driver */ init_video(); /* try to load config from flash */ config_init(); /* init widget modules */ widgets_init(); /* setup tabs */ tabs_init(); /* welcome message */ console_printf("AlceOSD hw%dv%d fw%d.%d.%d\n", hw_rev >> 4, hw_rev & 0xf, VERSION_MAJOR, VERSION_MINOR, VERSION_DEV); /* init home tracking */ init_home(); /* init flight status tracking */ init_flight_stats(); /* init mavlink module */ mavlink_init(); /* init uavtalk module */ uavtalk_init(); /* link serial ports to processes */ uart_set_config_clients(1); /* enable all interrupts */ _IPL = 0; _IPL3 = 1; console_printf("Processes running...\n"); /* main loop */ process_run(); return 0; }
/*---------------------------------------------------------------------------*/ int main(void) { /* * Initialize hardware. */ halInit(); clock_init(); uart1_init(115200); // Led initialization leds_init(); INTERRUPTS_ON(); PRINTF("\r\nStarting "); PRINTF(CONTIKI_VERSION_STRING); PRINTF(" on %s\r\n",boardDescription->name); /* * Initialize Contiki and our processes. */ process_init(); #if WITH_SERIAL_LINE_INPUT uart1_set_input(serial_line_input_byte); serial_line_init(); #endif /* rtimer and ctimer should be initialized before radio duty cycling layers*/ rtimer_init(); /* etimer_process should be initialized before ctimer */ process_start(&etimer_process, NULL); ctimer_init(); rtimer_init(); netstack_init(); set_rime_addr(); printf("%s %s, channel check rate %lu Hz\n", NETSTACK_MAC.name, NETSTACK_RDC.name, CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1: NETSTACK_RDC.channel_check_interval())); printf("802.15.4 PAN ID 0x%x, EUI-%d:", IEEE802154_CONF_PANID, UIP_CONF_LL_802154?64:16); uip_debug_lladdr_print(&rimeaddr_node_addr); printf(", radio channel %u\n", RF_CHANNEL); procinit_init(); energest_init(); ENERGEST_ON(ENERGEST_TYPE_CPU); autostart_start(autostart_processes); watchdog_start(); while(1){ int r; do { /* Reset watchdog. */ watchdog_periodic(); r = process_run(); } while(r > 0); ENERGEST_OFF(ENERGEST_TYPE_CPU); //watchdog_stop(); ENERGEST_ON(ENERGEST_TYPE_LPM); /* Go to idle mode. */ halSleepWithOptions(SLEEPMODE_IDLE,0); /* We are awake. */ //watchdog_start(); ENERGEST_OFF(ENERGEST_TYPE_LPM); ENERGEST_ON(ENERGEST_TYPE_CPU); } }
/*-------------------------------------------------------------------------*/ int main(void) { initialize(); #ifdef LOWPOWER rf2xx_set_txpower(0xf); #endif while(1) { process_run(); watchdog_periodic(); #if 0 /* Various entry points for debugging in the AVR Studio simulator. * Set as next statement and step into the routine. */ NETSTACK_RADIO.send(packetbuf_hdrptr(), 42); process_poll(&rf230_process); packetbuf_clear(); len = rf230_read(packetbuf_dataptr(), PACKETBUF_SIZE); packetbuf_set_datalen(42); NETSTACK_RDC.input(); #endif #if 0 /* Clock.c can trigger a periodic PLL calibration in the RF230BB driver. * This can show when that happens. */ extern uint8_t rf230_calibrated; if (rf230_calibrated) { PRINTD("\nRF230 calibrated!\n"); rf230_calibrated=0; } #endif /* Set DEBUGFLOWSIZE in contiki-conf.h to track path through MAC, RDC, and RADIO */ #if DEBUGFLOWSIZE if (debugflowsize) { debugflow[debugflowsize]=0; PRINTF("%s",debugflow); debugflowsize=0; } #endif #if PERIODICPRINTS #if TESTRTIMER /* Timeout can be increased up to 8 seconds maximum. * A one second cycle is convenient for triggering the various debug printouts. * The triggers are staggered to avoid printing everything at once. * My raven is 6% slow. */ if (rtimerflag) { rtimer_set(&rt, RTIMER_NOW()+ RTIMER_ARCH_SECOND*1UL, 1,(void *) rtimercycle, NULL); rtimerflag=0; #else if (clocktime!=clock_seconds()) { clocktime=clock_seconds(); #endif #if STAMPS if ((clocktime%STAMPS)==0) { #if ENERGEST_CONF_ON #include "lib/print-stats.h" print_stats(); #elif RADIOSTATS extern volatile unsigned long radioontime; PRINTF("%u(%u)s\n",clocktime,radioontime); #else PRINTF("%us\n",clocktime); #endif } #endif #if TESTRTIMER clocktime+=1; #endif #if PINGS && UIP_CONF_IPV6 extern void raven_ping6(void); if ((clocktime%PINGS)==1) { PRINTF("**Ping\n"); raven_ping6(); } #endif #if ROUTES && UIP_CONF_IPV6 if ((clocktime%ROUTES)==2) { extern uip_ds6_nbr_t uip_ds6_nbr_cache[]; extern uip_ds6_route_t uip_ds6_routing_table[]; extern uip_ds6_netif_t uip_ds6_if; uint8_t i,j; PRINTF("\nAddresses [%u max]\n",UIP_DS6_ADDR_NB); for (i=0;i<UIP_DS6_ADDR_NB;i++) { if (uip_ds6_if.addr_list[i].isused) { ipaddr_add(&uip_ds6_if.addr_list[i].ipaddr); PRINTF("\n"); } } PRINTF("\nNeighbors [%u max]\n",UIP_DS6_NBR_NB); for(i = 0,j=1; i < UIP_DS6_NBR_NB; i++) { if(uip_ds6_nbr_cache[i].isused) { ipaddr_add(&uip_ds6_nbr_cache[i].ipaddr); PRINTF("\n"); j=0; } } if (j) PRINTF(" <none>"); PRINTF("\nRoutes [%u max]\n",UIP_DS6_ROUTE_NB); for(i = 0,j=1; i < UIP_DS6_ROUTE_NB; i++) { if(uip_ds6_routing_table[i].isused) { ipaddr_add(&uip_ds6_routing_table[i].ipaddr); PRINTF("/%u (via ", uip_ds6_routing_table[i].length); ipaddr_add(&uip_ds6_routing_table[i].nexthop); // if(uip_ds6_routing_table[i].state.lifetime < 600) { PRINTF(") %lus\n", uip_ds6_routing_table[i].state.lifetime); // } else { // PRINTF(")\n"); // } j=0; } } if (j) PRINTF(" <none>"); PRINTF("\n---------\n"); } #endif #if STACKMONITOR if ((clocktime%STACKMONITOR)==3) { extern uint16_t __bss_end; uint16_t p=(uint16_t)&__bss_end; do { if (*(uint16_t *)p != 0x4242) { PRINTF("Never-used stack > %d bytes\n",p-(uint16_t)&__bss_end); break; } p+=10; } while (p<RAMEND-10); } #endif } #endif /* PERIODICPRINTS */ //Use with RF230BB DEBUGFLOW to show path through driver #if RF230BB&&0 extern uint8_t rf230processflag; if (rf230processflag) { PRINTF("rf230p%d",rf230processflag); rf230processflag=0; } #endif #if RF230BB&&0 extern uint8_t rf230_interrupt_flag; if (rf230_interrupt_flag) { // if (rf230_interrupt_flag!=11) { PRINTF("**RI%u",rf230_interrupt_flag); // } rf230_interrupt_flag=0; } #endif } return 0; } /*---------------------------------------------------------------------------*/ void log_message(char *m1, char *m2) { PRINTF("%s%s\n", m1, m2); }
static gint idle_callback(gpointer data) { process_run(); return TRUE; }
int main() { disableIRQ(); disableFIQ(); *AT91C_AIC_IDCR = 0xffffffff; *AT91C_PMC_PCDR = 0xffffffff; *AT91C_PMC_PCER = (1 << AT91C_ID_PIOA); dbg_setup_uart(); printf("Initialising\n"); leds_init(); clock_init(); process_init(); process_start(&etimer_process, NULL); ctimer_init(); enableIRQ(); printf("Beginning CC2420 setup\n"); cc2420_init(); cc2420_set_pan_addr(0x2024, 0, NULL); cc2420_set_channel(RF_CHANNEL); rime_init(nullmac_init(&cc2420_driver)); printf("CC2420 setup done\n"); rimeaddr_set_node_addr(&node_addr); printf("Rime started with address %d.%d\n", node_addr.u8[0], node_addr.u8[1]); #if WITH_UIP { 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); printf("Host addr\n"); 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_register(&meshif); uip_fw_default(&meshif); printf("Mesh init\n"); 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 */ #if WITH_UIP process_start(&tcpip_process, NULL); process_start(&uip_fw_process, NULL); /* Start IP output */ trickle_open(&gateway_trickle, CLOCK_SECOND * 4, GATEWAY_TRICKLE_CHANNEL, &trickle_call); #endif /* WITH_UIP */ printf("Heap size: %ld bytes\n", &__heap_end__ - (char*)sbrk(0)); printf("Started\n"); /* procinit_init(); */ autostart_start(autostart_processes); printf("Processes running\n"); while(1) { do { /* Reset watchdog. */ wdt_reset(); } while(process_run() > 0); /* Idle! */ /* Stop processor clock */ *AT91C_PMC_SCDR |= AT91C_PMC_PCK; } return 0; }
/*---------------------------------------------------------------------------*/ int main(void) { #if UIP_CONF_IPV6 /* A hard coded address overrides the stack default MAC address to allow multiple instances. * uip6.c defines it as {0x00,0x06,0x98,0x00,0x02,0x32} giving an ipv6 address of [fe80::206:98ff:fe00:232] * We make it simpler, {0x02,0x00,0x00 + the last three bytes of the hard coded address (if any are nonzero). * HARD_CODED_ADDRESS can be defined in the contiki-conf.h file, or here to allow quick builds using different addresses. * If HARD_CODED_ADDRESS has a prefix it also applied, unless built as a RPL end node. * E.g. bbbb::12:3456 becomes fe80::ff:fe12:3456 and prefix bbbb::/64 if non-RPL * ::10 becomes fe80::ff:fe00:10 and prefix awaits RA or RPL formation * bbbb:: gives an address of bbbb::206:98ff:fe00:232 if non-RPL */ //#define HARD_CODED_ADDRESS "bbbb::20" #ifdef HARD_CODED_ADDRESS { uip_ipaddr_t ipaddr; uiplib_ipaddrconv(HARD_CODED_ADDRESS, &ipaddr); if ((ipaddr.u8[13]!=0) || (ipaddr.u8[14]!=0) || (ipaddr.u8[15]!=0)) { if (sizeof(uip_lladdr)==6) { //Minimal-net uses ethernet MAC uip_lladdr.addr[0]=0x02;uip_lladdr.addr[1]=0;uip_lladdr.addr[2]=0; uip_lladdr.addr[3]=ipaddr.u8[13];; uip_lladdr.addr[4]=ipaddr.u8[14]; uip_lladdr.addr[5]=ipaddr.u8[15]; } } } #endif #endif process_init(); /* procinit_init initializes RPL which sets a ctimer for the first DIS */ /* We must start etimers and ctimers,before calling it */ process_start(&etimer_process, NULL); ctimer_init(); procinit_init(); autostart_start(autostart_processes); #if RPL_BORDER_ROUTER process_start(&border_router_process, NULL); printf("Border Router Process started\n"); #elif UIP_CONF_IPV6_RPL printf("RPL enabled\n"); #endif /* Set default IP addresses if not specified */ #if !UIP_CONF_IPV6 uip_ipaddr_t addr; uip_gethostaddr(&addr); if (addr.u8[0]==0) { uip_ipaddr(&addr, 10,1,1,1); } printf("IP Address: %d.%d.%d.%d\n", uip_ipaddr_to_quad(&addr)); uip_sethostaddr(&addr); uip_getnetmask(&addr); if (addr.u8[0]==0) { uip_ipaddr(&addr, 255,0,0,0); uip_setnetmask(&addr); } printf("Subnet Mask: %d.%d.%d.%d\n", uip_ipaddr_to_quad(&addr)); uip_getdraddr(&addr); if (addr.u8[0]==0) { uip_ipaddr(&addr, 10,1,1,100); uip_setdraddr(&addr); } printf("Def. Router: %d.%d.%d.%d\n", uip_ipaddr_to_quad(&addr)); #else /* UIP_CONF_IPV6 */ #if !UIP_CONF_IPV6_RPL #ifdef HARD_CODED_ADDRESS uip_ipaddr_t ipaddr; uiplib_ipaddrconv(HARD_CODED_ADDRESS, &ipaddr); if ((ipaddr.u16[0]!=0) || (ipaddr.u16[1]!=0) || (ipaddr.u16[2]!=0) || (ipaddr.u16[3]!=0)) { #if UIP_CONF_ROUTER uip_ds6_prefix_add(&ipaddr, UIP_DEFAULT_PREFIX_LEN, 0, 0, 0, 0); #else /* UIP_CONF_ROUTER */ uip_ds6_prefix_add(&ipaddr, UIP_DEFAULT_PREFIX_LEN, 0); #endif /* UIP_CONF_ROUTER */ #if !UIP_CONF_IPV6_RPL uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr); uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF); #endif } #endif /* HARD_CODED_ADDRESS */ #endif #if !RPL_BORDER_ROUTER //Border router process prints addresses later { uint8_t i; for (i=0;i<UIP_DS6_ADDR_NB;i++) { if (uip_ds6_if.addr_list[i].isused) { printf("IPV6 Addresss: ");sprint_ip6(uip_ds6_if.addr_list[i].ipaddr);printf("\n"); } } } #endif #endif /* !UIP_CONF_IPV6 */ /* Make standard output unbuffered. */ setvbuf(stdout, (char *)NULL, _IONBF, 0); while(1) { fd_set fds; int n; struct timeval tv; n = process_run(); /* if(n > 0) { printf("%d processes in queue\n"); }*/ tv.tv_sec = 0; tv.tv_usec = 1; FD_ZERO(&fds); FD_SET(STDIN_FILENO, &fds); select(1, &fds, NULL, NULL, &tv); if(FD_ISSET(STDIN_FILENO, &fds)) { char c; if(read(STDIN_FILENO, &c, 1) > 0) { serial_line_input_byte(c); } } etimer_request_poll(); } 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 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, 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 /* 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); } } }
/** * \brief Main routine for the cc2538dk platform */ int main(void) { nvic_init(); ioc_init(); sys_ctrl_init(); clock_init(); lpm_init(); rtimer_init(); gpio_init(); leds_init(); fade(LEDS_YELLOW); process_init(); watchdog_init(); 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(); INTERRUPTS_ENABLE(); fade(LEDS_GREEN); PUTS(CONTIKI_VERSION_STRING); PUTS(BOARD_STRING); PRINTF(" Net: "); PRINTF("%s\n", NETSTACK_NETWORK.name); PRINTF(" MAC: "); PRINTF("%s\n", NETSTACK_MAC.name); PRINTF(" RDC: "); PRINTF("%s\n", NETSTACK_RDC.name); /* Initialise the H/W RNG engine. */ random_init(0); udma_init(); process_start(&etimer_process, NULL); ctimer_init(); set_rf_params(); #if CRYPTO_CONF_INIT crypto_init(); crypto_disable(); #endif netstack_init(); #if NETSTACK_CONF_WITH_IPV6 memcpy(&uip_lladdr.addr, &linkaddr_node_addr, sizeof(uip_lladdr.addr)); queuebuf_init(); process_start(&tcpip_process, NULL); #endif /* NETSTACK_CONF_WITH_IPV6 */ adc_init(); process_start(&sensors_process, NULL); energest_init(); ENERGEST_ON(ENERGEST_TYPE_CPU); autostart_start(autostart_processes); watchdog_start(); fade(LEDS_ORANGE); while(1) { uint8_t r; do { /* Reset watchdog and handle polls and events */ watchdog_periodic(); r = process_run(); } while(r > 0); /* We have serviced all pending events. Enter a Low-Power mode. */ lpm_enter(); } }
void main(int argc, char **argv) { contiki_argc = argc; contiki_argv = argv; #else /* WITH_ARGS */ void main(void) { #endif /* WITH_ARGS */ videomode(VIDEOMODE_80COL); process_init(); #if 1 ethernet_config = config_read("contiki.cfg"); #else { static struct ethernet_config config = {0xDE08, "cs8900a.eth"}; uip_ipaddr_t addr; uip_ipaddr(&addr, 192,168,0,128); uip_sethostaddr(&addr); uip_ipaddr(&addr, 255,255,255,0); uip_setnetmask(&addr); uip_ipaddr(&addr, 192,168,0,1); uip_setdraddr(&addr); uip_ipaddr(&addr, 192,168,0,1); resolv_conf(&addr); ethernet_config = &config; } #endif #if (WITH_GUI && WITH_MOUSE) { static const uint8_t mouse_sprite[64] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0xE0, 0x00, 0x0F, 0xC0, 0x00, 0x0F, 0x80, 0x00, 0x0F, 0xC0, 0x00, 0x0D, 0xE0, 0x00, 0x08, 0xF0, 0x00, 0x00, 0x78, 0x00, 0x00, 0x3C, 0x00, 0x00, 0x1E, 0x00, 0x00, 0x0F, 0x00, 0x00, 0x07, 0x80, 0x00, 0x03, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; memcpy((void*)0x0E00, mouse_sprite, sizeof(mouse_sprite)); *(uint8_t*)0x07F8 = 0x0E00 / 64; VIC.spr0_color = COLOR_WHITE; } #endif /* WITH_GUI && WITH_MOUSE */ procinit_init(); process_start((struct process *)ðernet_process, (char *)ethernet_config); autostart_start(autostart_processes); log_message("Contiki up and running ...", ""); while(1) { process_run(); etimer_request_poll(); } }
/*---------------------------------------------------------------------------*/ int main(void) { process_init(); procinit_init(); ctimer_init(); autostart_start(autostart_processes); /* Set default IP addresses if not specified */ #if !UIP_CONF_IPV6 uip_ipaddr_t addr; uip_gethostaddr(&addr); if (addr.u8[0]==0) { uip_ipaddr(&addr, 10,1,1,1); } printf("IP Address: %d.%d.%d.%d\n", uip_ipaddr_to_quad(&addr)); uip_sethostaddr(&addr); uip_getnetmask(&addr); if (addr.u8[0]==0) { uip_ipaddr(&addr, 255,0,0,0); uip_setnetmask(&addr); } printf("Subnet Mask: %d.%d.%d.%d\n", uip_ipaddr_to_quad(&addr)); uip_getdraddr(&addr); if (addr.u8[0]==0) { uip_ipaddr(&addr, 10,1,1,100); uip_setdraddr(&addr); } printf("Def. Router: %d.%d.%d.%d\n", uip_ipaddr_to_quad(&addr)); #else /* !UIP_CONF_IPV6 */ uip_ipaddr_t ipaddr; uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0); uip_netif_addr_autoconf_set(&ipaddr, &uip_lladdr); uip_netif_addr_add(&ipaddr, 16, 0, TENTATIVE); printf("IP6 Address: ");sprint_ip6(ipaddr);printf("\n"); #endif /* !UIP_CONF_IPV6 */ /* Make standard output unbuffered. */ setvbuf(stdout, (char *)NULL, _IONBF, 0); while(1) { fd_set fds; int n; struct timeval tv; n = process_run(); /* if(n > 0) { printf("%d processes in queue\n"); }*/ tv.tv_sec = 0; tv.tv_usec = 1; FD_ZERO(&fds); FD_SET(STDIN_FILENO, &fds); select(1, &fds, NULL, NULL, &tv); if(FD_ISSET(STDIN_FILENO, &fds)) { char c; if(read(STDIN_FILENO, &c, 1) > 0) { serial_line_input_byte(c); } } etimer_request_poll(); } return 0; }