/*---------------------------------------------------------------------------*/ static void clock_irq_callback( struct tc_module *const module_inst) { // ENERGEST_ON(ENERGEST_TYPE_IRQ); ticks++; //port_pin_toggle_output_level(PIN_PA23); if((ticks % CLOCK_SECOND) == 0) { seconds++; //energest_flush(); // printf("seconds, ticks %d\n", tc_get_count_value(&tc_instance)); } if(etimer_pending()) { etimer_request_poll(); } //ENERGEST_OFF(ENERGEST_TYPE_IRQ); }
/*---------------------------------------------------------------------------*/ void main(void) { /* initialize process manager. */ process_init(); /* start services */ process_start(&etimer_process, NULL); process_start(&serial_line_process, NULL); #ifndef RS232_INTR process_start(&rs232_process, NULL); #endif process_start(&stest_process, NULL); while(1) { process_run(); etimer_request_poll(); } }
/*---------------------------------------------------------------------------*/ int main(void) { /* initialize process manager. */ process_init(); /* start services */ // process_start(&ctk_process, NULL); // process_start(&program_handler_process, NULL); process_start(&etimer_process, NULL); process_start(&tiny_process, NULL); // program_handler_add(&tiny_dsc, "Tiny", 1); while(1) { process_run(); etimer_request_poll(); } }
/*---------------------------------------------------------------------------*/ ISR(TIMERA1, timera1) { watchdog_start(); if(TAIV == 2) { /* HW timer bug fix: Interrupt handler called before TR==CCR. * Occurs when timer state is toggled between STOP and CONT. */ while(TACTL & MC1 && TACCR1 - read_tar() == 1); last_tar = read_tar(); /* Make sure interrupt time is future */ while(!CLOCK_LT(last_tar, TACCR1)) { TACCR1 += INTERVAL; ++count; /* Make sure the CLOCK_CONF_SECOND is a power of two, to ensure that the modulo operation below becomes a logical and and not an expensive divide. Algorithm from Wikipedia: http://en.wikipedia.org/wiki/Power_of_two */ #if (CLOCK_CONF_SECOND & (CLOCK_CONF_SECOND - 1)) != 0 #error CLOCK_CONF_SECOND must be a power of two (i.e., 1, 2, 4, 8, 16, 32, 64, ...). #error Change CLOCK_CONF_SECOND in contiki-conf.h. #endif if(count % CLOCK_CONF_SECOND == 0) { ++seconds; } last_tar = read_tar(); } if(etimer_pending() && (etimer_next_expiration_time() - count - 1) > MAX_TICKS) { etimer_request_poll(); LPM4_EXIT; } } /* if(process_nevents() >= 0) { LPM4_EXIT; }*/ watchdog_stop(); }
/*---------------------------------------------------------------------------*/ interrupt(TIMERA1_VECTOR) timera1 (void) { ENERGEST_ON(ENERGEST_TYPE_IRQ); int taiv = TAIV; if(taiv == 2) { etimer_interrupt(); if(etimer_pending() && (etimer_next_expiration_time() - count - 1) > MAX_TICKS) { etimer_request_poll(); LPM4_EXIT; } } else { if (taiv == TAIV_TACCR2) { radio_abort_rx(); LPM4_EXIT; } } ENERGEST_OFF(ENERGEST_TYPE_IRQ); }
void SimluateRun(CuTest* tc) { /* * Initialize Contiki and our processes. */ process_init(); process_start(&etimer_process, NULL); ctimer_init(); energest_init(); ENERGEST_ON(ENERGEST_TYPE_CPU); window_init(0xff); autostart_start(autostart_processes); process_start(&event_process, NULL); while(run) { int r; do { /* Reset watchdog. */ r = process_run(); } while(r > 0); #if 0 int n = etimer_next_expiration_time(); if (n > 0) { int p = n - clock_time(); if (p > 0) nanosleep(p); } else { nanosleep(1000); } #endif etimer_request_poll(); } }
/*---------------------------------------------------------------------------*/ int main(void) { printf("Starting Contiki\n"); process_init(); procinit_init(); autostart_start(autostart_processes); /* Make standard output unbuffered. */ setvbuf(stdout, (char *)NULL, _IONBF, 0); while(1) { fd_set fds; int n; struct timeval tv; n = process_run(); 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(void) { /* initialize process manager. */ process_init(); /* start services */ process_start(&ctk_process, NULL); process_start(&program_handler_process, NULL); process_start(&etimer_process, NULL); /* register programs to the program handler */ /* program_handler_add(&directory_dsc, "Directory", 1); program_handler_add(&processes_dsc, "Processes", 1); program_handler_add(&shell_dsc, "Command shell", 1); */ while(1) { process_run(); etimer_request_poll(); } }
/*---------------------------------------------------------------------------*/ int main(void) { /* Hardware initialization */ bus_init(); leds_init(); fade(LEDS_GREEN); uart1_init(115200); uart1_set_input(serial_line_input_byte); /* initialize process manager. */ process_init(); serial_line_init(); printf("\n" CONTIKI_VERSION_STRING " started\n"); printf("model: " SENSINODE_MODEL "\n\n"); /* initialize the radio driver */ cc2430_rf_init(); rime_init(sicslowmac_init(&cc2430_rf_driver)); set_rime_addr(); /* start services */ process_start(&etimer_process, NULL); fade(LEDS_RED); autostart_start(autostart_processes); while(1) { process_run(); etimer_request_poll(); } }
/*---------------------------------------------------------------------------*/ interrupt(TIMERA1_VECTOR) timera1 (void) { ENERGEST_ON(ENERGEST_TYPE_IRQ); if(TAIV == 2) { /* HW timer bug fix: Interrupt handler called before TR==CCR. * Occurrs when timer state is toggled between STOP and CONT. */ while (TACTL & MC1 && TACCR1 - TAR == 1); /* Make sure interrupt time is future */ do { TACCR1 += INTERVAL; ++count; /* Make sure the CLOCK_CONF_SECOND is a power of two, to ensure that the modulo operation below becomes a logical and and not an expensive divide. Algorithm from Wikipedia: http://en.wikipedia.org/wiki/Power_of_two */ #if (CLOCK_CONF_SECOND & (CLOCK_CONF_SECOND - 1)) != 0 #error CLOCK_CONF_SECOND must be a power of two (i.e., 1, 2, 4, 8, 16, 32, 64, ...). #error Change CLOCK_CONF_SECOND in contiki-conf.h. #endif if(count % CLOCK_CONF_SECOND == 0) { ++seconds; } } while((TACCR1 - TAR) > INTERVAL); last_tar = TAR; if(etimer_pending() && (etimer_next_expiration_time() - count - 1) > MAX_TICKS) { etimer_request_poll(); LPM4_EXIT; } } ENERGEST_OFF(ENERGEST_TYPE_IRQ); }
int main(int argc, char **argv) { printf("uIPv6 test project\n"); uip_ipaddr_t ipaddr; uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0); if((ipaddr.u16[0] != 0) || (ipaddr.u16[1] != 0) || (ipaddr.u16[2] != 0) || (ipaddr.u16[3] != 0)) { uip_ds6_prefix_add(&ipaddr, UIP_DEFAULT_PREFIX_LEN, 0); uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr); uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF); } printf("Process subsystem init\n"); process_init(); printf("Ok\n"); printf("Start etimer process\n"); process_start(&etimer_process, NULL); printf("Ok\n"); printf("Init ctimer\n"); ctimer_init(); printf("Ok\n"); printf("Init tapdev\n"); tapdev_init(); tcpip_set_outputfunc(tapdev_send); printf("Ok\n"); printf("Start tcpip process\n"); process_start(&tcpip_process, NULL); printf("Ok\n"); printf("Start TCP server on 8080 port\n"); process_start(&tcp_server, NULL); printf("Ok\n"); uint8_t i; for(i = 0; i < UIP_DS6_ADDR_NB; i++) { if(uip_ds6_if.addr_list[i].isused) { printf("IPV6 Addresss: "); printf("%02X%02X:%02X%02X:%02X%02X:%02X%02X:%02X%02X:%02X%02X:%02X%02X:%02X%02X", uip_ds6_if.addr_list[i].ipaddr.u8[0], uip_ds6_if.addr_list[i].ipaddr.u8[1], uip_ds6_if.addr_list[i].ipaddr.u8[2], uip_ds6_if.addr_list[i].ipaddr.u8[3], uip_ds6_if.addr_list[i].ipaddr.u8[4], uip_ds6_if.addr_list[i].ipaddr.u8[5], uip_ds6_if.addr_list[i].ipaddr.u8[6], uip_ds6_if.addr_list[i].ipaddr.u8[7], uip_ds6_if.addr_list[i].ipaddr.u8[8], uip_ds6_if.addr_list[i].ipaddr.u8[9], uip_ds6_if.addr_list[i].ipaddr.u8[10], uip_ds6_if.addr_list[i].ipaddr.u8[11], uip_ds6_if.addr_list[i].ipaddr.u8[12], uip_ds6_if.addr_list[i].ipaddr.u8[13], uip_ds6_if.addr_list[i].ipaddr.u8[14], uip_ds6_if.addr_list[i].ipaddr.u8[15]); printf("\n"); } } while(1){ process_run(); etimer_request_poll(); uip_len = tapdev_poll(); if(uip_len > 0){ if(BUF->type == uip_htons(UIP_ETHTYPE_IPV6)){ tcpip_input(); } } } }
int main(int argc, char **argv) { clock_init(); #if NETSTACK_CONF_WITH_IPV6 #if UIP_CONF_IPV6_RPL printf(CONTIKI_VERSION_STRING " started with IPV6, RPL\n"); #else printf(CONTIKI_VERSION_STRING " started with IPV6\n"); #endif #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(); rtimer_init(); prepare_network(); serial_line_init(); /* Make standard output unbuffered. */ setvbuf(stdout, (char *)NULL, _IONBF, 0); select_set_callback(STDIN_FILENO, &stdin_fd); 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 = 0; if(!retval) { if(etimer_pending()) { clock_time_t t = etimer_next_expiration_time() - clock_time() - 1; if(t < MAX_TICKS) { tv.tv_sec = t / CLOCK_SECOND; tv.tv_usec = (t % CLOCK_SECOND) * 1000; if(tv.tv_usec == 0 && tv.tv_sec == 0) { /* Clock time resolution is milliseconds. Avoid millisecond busy loops. */ tv.tv_usec = 250; } } } else { tv.tv_sec = 60; } /* TODO Replace the busy polling used to read data from the slip pthread */ if(tv.tv_sec) { tv.tv_sec = 0; tv.tv_usec = 10000; } else if(tv.tv_usec > 10000) { tv.tv_usec = 10000; } } 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) { if(errno != EINTR) { 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); } } } if(etimer_pending() && (etimer_next_expiration_time() - clock_time() - 1) > MAX_TICKS) { etimer_request_poll(); } } return 0; }
/*---------------------------------------------------------------------------*/ int main(void) { process_init(); procinit_init(); ctimer_init(); autostart_start(autostart_processes); #if !UIP_CONF_IPV6 uip_ipaddr_t addr; uip_ipaddr(&addr, 192,168,1,2); printf("IP Address: %d.%d.%d.%d\n", uip_ipaddr_to_quad(&addr)); uip_sethostaddr(&addr); uip_ipaddr(&addr, 255,255,255,0); printf("Subnet Mask: %d.%d.%d.%d\n", uip_ipaddr_to_quad(&addr)); uip_setnetmask(&addr); uip_ipaddr(&addr, 192,168,1,1); printf("Def. Router: %d.%d.%d.%d\n", uip_ipaddr_to_quad(&addr)); uip_setdraddr(&addr); #else { 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); } #endif /* 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(void) { 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 !UIP_CONF_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); resolv_conf(&addr); log_message("DNS Server: ", inet_ntoa(*(struct in_addr*)&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 #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 */ } }
/* ----------------------------------------------------------------------------- * Initialise the uip_server * -------------------------------------------------------------------------- */ void uip_server_init(chanend xtcp[], int num_xtcp, xtcp_ipconfig_t *ipconfig, unsigned char *mac_address) { if (ipconfig != NULL) memcpy(&uip_static_ipconfig, ipconfig, sizeof(xtcp_ipconfig_t)); /* set the mac_adress */ memcpy(&uip_lladdr, mac_address, 6); #if 0 //XXX CHSC: not necessary? Be carefully with erasing the mac address... /* The following line sets the uIP's link-layer address. This must be done * before the tcpip_process is started since in its initialisation * 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); #endif //TODO chsc: port the rtimer module (if really needed) // /* rtimers needed for radio cycling */ // rtimer_init(); /* Initialise the process module */ process_init(); /* etimers must be started before ctimer_init */ process_start(&etimer_process, NULL); ctimer_init(); /* this calls have to be made before the uip_init * not exactely proved why. CHSC * */ etimer_request_poll(); process_run(); uip_init(); #if UIP_CONF_IPV6 && UIP_CONF_IPV6_RPL rpl_init(); #endif /* UIP_CONF_IPV6_RPL */ #if UIP_IGMP igmp_init(); #endif /* UIP_IGMP */ if (ipconfig != NULL && (*((int*)ipconfig->ipaddr.u8) != 0)) { uip_static_ip = 1; } if (ipconfig == NULL) { uip_ipaddr_t ipaddr; #if UIP_CONF_IPV4 uip_ipaddr(&ipaddr, 0, 0, 0, 0); uip_sethostaddr(&ipaddr); uip_setdraddr(&ipaddr); uip_setnetmask(&ipaddr); #elif UIP_CONF_IPV6 uip_ip6addr(&ipaddr, 0, 0, 0, 0 , 0, 0, 0, 0); #endif /* UIP_CONF_IPVx */ } else { #if UIP_CONF_IPV4 uip_sethostaddr(&ipconfig->ipaddr); uip_setdraddr(&ipconfig->gateway); uip_setnetmask(&ipconfig->netmask); #ifdef XTCP_VERBOSE_DEBUG printf("Address: ");uip_printip4(uip_hostaddr);printf("\n"); printf("Gateway: ");uip_printip4(uip_draddr);printf("\n"); printf("Netmask: ");uip_printip4(uip_netmask);printf("\n"); #endif /* XTCP_VERBOSE_DEBUG */ #elif UIP_CONF_IPV6 #endif /* UIP_CONF_IPVx */ } #if UIP_CONF_IPV4 { #if UIP_USE_AUTOIP int hwsum = mac_address[0] + mac_address[1] + mac_address[2] + mac_address[3] + mac_address[4] + mac_address[5]; autoip_init(hwsum + (hwsum << 16) + (hwsum << 24)); #endif #if UIP_USE_DHCP dhcpc_init(uip_lladdr.addr, 6); #endif } #endif /* UIP_CONF_IPV4 */ xtcpd_init(xtcp, num_xtcp); }
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; }
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) { /* 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(void) { /* Hardware initialization */ clock_init(); soc_init(); rtimer_init(); /* Init LEDs here */ leds_init(); leds_off(LEDS_ALL); fade(LEDS_GREEN); /* initialize process manager. */ process_init(); /* Init UART */ uart0_init(); #if DMA_ON dma_init(); #endif #if SLIP_ARCH_CONF_ENABLE slip_arch_init(0); #else uart0_set_input(serial_line_input_byte); serial_line_init(); #endif fade(LEDS_RED); PUTSTRING("##########################################\n"); putstring(CONTIKI_VERSION_STRING "\n"); putstring("TI SmartRF05 EB\n"); switch(CHIPID) { case 0xA5: putstring("cc2530"); break; case 0xB5: putstring("cc2531"); break; case 0x95: putstring("cc2533"); break; case 0x8D: putstring("cc2540"); break; } putstring("-F"); switch(CHIPINFO0 & 0x70) { case 0x40: putstring("256, "); break; case 0x30: putstring("128, "); break; case 0x20: putstring("64, "); break; case 0x10: putstring("32, "); break; } puthex(CHIPINFO1 + 1); putstring("KB SRAM\n"); PUTSTRING("\nSDCC Build:\n"); #if STARTUP_VERBOSE #ifdef HAVE_SDCC_BANKING PUTSTRING(" With Banking.\n"); #endif /* HAVE_SDCC_BANKING */ #ifdef SDCC_MODEL_LARGE PUTSTRING(" --model-large\n"); #endif /* SDCC_MODEL_LARGE */ #ifdef SDCC_MODEL_HUGE PUTSTRING(" --model-huge\n"); #endif /* SDCC_MODEL_HUGE */ #ifdef SDCC_STACK_AUTO PUTSTRING(" --stack-auto\n"); #endif /* SDCC_STACK_AUTO */ PUTCHAR('\n'); PUTSTRING(" Net: "); PUTSTRING(NETSTACK_NETWORK.name); PUTCHAR('\n'); PUTSTRING(" MAC: "); PUTSTRING(NETSTACK_MAC.name); PUTCHAR('\n'); PUTSTRING(" RDC: "); PUTSTRING(NETSTACK_RDC.name); PUTCHAR('\n'); PUTSTRING("##########################################\n"); #endif watchdog_init(); /* Initialise the H/W RNG engine. */ random_init(0); /* start services */ process_start(&etimer_process, NULL); ctimer_init(); /* initialize the netstack */ netstack_init(); set_rime_addr(); #if BUTTON_SENSOR_ON || ADC_SENSOR_ON process_start(&sensors_process, NULL); BUTTON_SENSOR_ACTIVATE(); ADC_SENSOR_ACTIVATE(); #endif #if UIP_CONF_IPV6 memcpy(&uip_lladdr.addr, &rimeaddr_node_addr, sizeof(uip_lladdr.addr)); queuebuf_init(); process_start(&tcpip_process, NULL); #endif /* UIP_CONF_IPV6 */ #if VIZTOOL_CONF_ON process_start(&viztool_process, NULL); #endif energest_init(); ENERGEST_ON(ENERGEST_TYPE_CPU); autostart_start(autostart_processes); watchdog_start(); fade(LEDS_YELLOW); while(1) { do { /* Reset watchdog and handle polls and events */ watchdog_periodic(); #if CLOCK_CONF_STACK_FRIENDLY if(sleep_flag) { if(etimer_pending() && (etimer_next_expiration_time() - clock_time() - 1) > MAX_TICKS) { etimer_request_poll(); } sleep_flag = 0; } #endif r = process_run(); } while(r > 0); len = NETSTACK_RADIO.pending_packet(); if(len) { packetbuf_clear(); len = NETSTACK_RADIO.read(packetbuf_dataptr(), PACKETBUF_SIZE); if(len > 0) { packetbuf_set_datalen(len); NETSTACK_RDC.input(); } } #if LPM_MODE #if (LPM_MODE==LPM_MODE_PM2) SLEEP &= ~OSC_PD; /* Make sure both HS OSCs are on */ while(!(SLEEP & HFRC_STB)); /* Wait for RCOSC to be stable */ CLKCON |= OSC; /* Switch to the RCOSC */ while(!(CLKCON & OSC)); /* Wait till it's happened */ SLEEP |= OSC_PD; /* Turn the other one off */ #endif /* LPM_MODE==LPM_MODE_PM2 */ /* * Set MCU IDLE or Drop to PM1. Any interrupt will take us out of LPM * Sleep Timer will wake us up in no more than 7.8ms (max idle interval) */ SLEEPCMD = (SLEEPCMD & 0xFC) | (LPM_MODE - 1); #if (LPM_MODE==LPM_MODE_PM2) /* * Wait 3 NOPs. Either an interrupt occurred and SLEEP.MODE was cleared or * no interrupt occurred and we can safely power down */ __asm nop nop nop __endasm; if(SLEEPCMD & SLEEP_MODE0) { #endif /* LPM_MODE==LPM_MODE_PM2 */ ENERGEST_OFF(ENERGEST_TYPE_CPU); ENERGEST_ON(ENERGEST_TYPE_LPM); /* We are only interested in IRQ energest while idle or in LPM */ ENERGEST_IRQ_RESTORE(irq_energest); /* Go IDLE or Enter PM1 */ PCON |= PCON_IDLE; /* First instruction upon exiting PM1 must be a NOP */ __asm nop __endasm; /* Remember energest IRQ for next pass */ ENERGEST_IRQ_SAVE(irq_energest); ENERGEST_ON(ENERGEST_TYPE_CPU); ENERGEST_OFF(ENERGEST_TYPE_LPM); #if (LPM_MODE==LPM_MODE_PM2) SLEEPCMD &= ~SLEEP_OSC_PD; /* Make sure both HS OSCs are on */ while(!(SLEEPCMD & SLEEP_XOSC_STB)); /* Wait for XOSC to be stable */ CLKCONCMD &= ~CLKCONCMD_OSC; /* Switch to the XOSC */ /* * On occasion the XOSC is reported stable when in reality it's not. * We need to wait for a safeguard of 64us or more before selecting it */ clock_delay(10); while(CLKCONCMD & CLKCONCMD_OSC); /* Wait till it's happened */ } #endif /* LPM_MODE==LPM_MODE_PM2 */ #endif /* LPM_MODE */ } }
/*---------------------------------------------------------------------------*/ 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; }
/*-----------------------------------------------------------------------------------*/ 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(); } } }
void netMainThread(void* arg) { uint8_t i; #if !NETSTACK_CONF_WITH_IPV6 POSTIMER_t arpTimer; #endif POSTIMER_t periodicTimer; int sendRequested; bool packetSeen; #if !NETSTACK_CONF_WITH_IPV6 arpTimer = posTimerCreate(); P_ASSERT("netMainThread1", arpTimer != NULL); posTimerSet(arpTimer, uipGiant, MS(10000), MS(10000)); posTimerStart(arpTimer); #endif periodicTimer = posTimerCreate(); P_ASSERT("netMainThread2", periodicTimer != NULL); posTimerSet(periodicTimer, uipGiant, MS(500), MS(500)); posTimerStart(periodicTimer); posMutexLock(uipMutex); packetSeen = false; while(1) { posMutexUnlock(uipMutex); // Using semaphore here is not fully optimal. // As it is a counting one, it can get bumped // to larger value than 1 by upper or interrupt // layer. However, not much harm is done, // this loop just spins extra times without // doing nothing useful. // A Pico]OS Flag object would be perfect, // but it doesn't work with posTimer* functions. if (!packetSeen || pollTicks == INFINITE) posSemaWait(uipGiant, pollTicks); posMutexLock(uipMutex); sendRequested = dataToSend; dataToSend = 0; packetSeen = false; if (sendRequested) { for(i = 0; i < UIP_CONNS; i++) { uip_len = 0; uip_poll_conn(&uip_conns[i]); if(uip_len > 0) { #if NETCFG_UIP_SPLIT == 1 uip_split_output(); #else #if NETSTACK_CONF_WITH_IPV6 tcpip_ipv6_output(); #else tcpip_output(); #endif #endif } } #if UIP_UDP for(i = 0; i < UIP_UDP_CONNS; i++) { uip_len = 0; uip_udp_periodic(i); if(uip_len > 0) { #if NETSTACK_CONF_WITH_IPV6 tcpip_ipv6_output(); #else tcpip_output(); #endif } } #endif /* UIP_UDP */ } packetSeen = netInterfacePoll(); if (posTimerFired(periodicTimer)) { for(i = 0; i < UIP_CONNS; i++) { uip_periodic(i); if(uip_len > 0) { #if NETCFG_UIP_SPLIT == 1 uip_split_output(); #else #if NETSTACK_CONF_WITH_IPV6 tcpip_ipv6_output(); #else tcpip_output(); #endif #endif } } #if UIP_UDP for(i = 0; i < UIP_UDP_CONNS; i++) { uip_udp_periodic(i); if(uip_len > 0) { #if NETSTACK_CONF_WITH_IPV6 tcpip_ipv6_output(); #else tcpip_output(); #endif } } #endif /* UIP_UDP */ } #if NETSTACK_CONF_WITH_IPV6 == 0 if (posTimerFired(arpTimer)) { uip_arp_timer(); } #endif // Run contiki-style timers. // Instead of posting events to process like // contiki does, it just calls common callback function // to do the work. etimer_request_poll(); } }
/*---------------------------------------------------------------------------*/ int main(int argc, char **argv) { PRINTF(">> %s:main()\n", __FILE__); start: /* Yield once during bootup */ kleenet_schedule_state(MILLISECOND); kleenet_yield_state(); simCurrentTime = NODE_TIME(); PRINTF("> Executing Contiki at simulation time %lu\n", clock_time()); /* Code from contiki-cooja-main.c:process_run_thread_loop (before loop) */ doActionsBeforeTick(); contiki_init(); doActionsAfterTick(); while (1) { /* reboot */ if ((clock_seconds() >= failure_delay()) && reboot_once) { /* symbolic node reboot every 10 seconds */ if (clock_seconds() % 10 == 0) { if (failure_reboot_node()) { PRINTF("main(): rebooting node once @ %lu, %lu seconds\n", clock_time(), clock_seconds()); reboot_once = 0; exit_all_processes(); goto start; } } } /* halt */ if ((clock_seconds() >= failure_delay()) && halt_once) { /* symbolic node outage every 10 seconds */ if (clock_seconds() % 10 == 0) { if (failure_halt_node()) { PRINTF("main(): halting node once @ %lu, %lu seconds\n", clock_time(), clock_seconds()); halt_once = 0; exit_all_processes(); /* loop forerver */ while(1) { kleenet_schedule_state(MILLISECOND); kleenet_yield_state(); } } } } /* Update time */ simCurrentTime = NODE_TIME(); simProcessRunValue = 0; /* Do actions before tick */ doActionsBeforeTick(); /* Poll etimer process */ if (etimer_pending()) { etimer_request_poll(); } /* Code from contiki-cooja-main.c:process_run_thread_loop */ simProcessRunValue = process_run(); while(simProcessRunValue-- > 0) { process_run(); } simProcessRunValue = process_nevents(); /* Do actions after tick */ doActionsAfterTick(); /* Request next tick for remaining events / timers */ if (simProcessRunValue != 0) { kleenet_schedule_state(MILLISECOND); kleenet_yield_state(); continue; } /* Request tick next wakeup time */ if (etimer_pending()) { simNextExpirationTime = etimer_next_expiration_time() - simCurrentTime; } else { simNextExpirationTime = 0; PRINTF("WARNING: No more timers pending\n"); kleenet_schedule_state(MILLISECOND); kleenet_yield_state(); continue; } /* check next expiration time */ if (simNextExpirationTime <= 0) { PRINTF("WARNING: Event timer already expired, but has been delayed: %lu\n", simNextExpirationTime); kleenet_schedule_state(MILLISECOND); } else { kleenet_schedule_state(simNextExpirationTime*MILLISECOND); } /* yield active state */ kleenet_yield_state(); } return 0; }
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 */ } }
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; }
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; }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(etimer_process, ev, data) { struct etimer *t, *u; PROCESS_BEGIN(); timerlist = NULL; while(1) { PROCESS_YIELD(); if(ev == PROCESS_EVENT_EXITED) { struct process *p = data; while(timerlist != NULL && timerlist->p == p) { timerlist = timerlist->next; } if(timerlist != NULL) { t = timerlist; while(t->next != NULL) { if(t->next->p == p) { t->next = t->next->next; } else t = t->next; } } continue; } else if(ev != PROCESS_EVENT_POLL) { continue; } again: u = NULL; for(t = timerlist; t != NULL; t = t->next) { if(timer_expired(&t->timer)) { if(process_post(t->p, PROCESS_EVENT_TIMER, t) == PROCESS_ERR_OK) { /* Reset the process ID of the event timer, to signal that the etimer has expired. This is later checked in the etimer_expired() function. */ t->p = PROCESS_NONE; if(u != NULL) { u->next = t->next; } else { timerlist = t->next; } t->next = NULL; update_time(); goto again; } else { etimer_request_poll(); } } u = t; } } PROCESS_END(); }
/*---------------------------------------------------------------------------*/ int main(void) { clock_init(); #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 */ #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 /* HARD_CODED_ADDRESS */ #endif /* UIP_CONF_IPV6 */ 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(); #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 procinit_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, 172,18,0,2); } 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,255,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, 172,18,0,1); 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 { uip_ipaddr_t ipaddr; #ifdef HARD_CODED_ADDRESS uiplib_ipaddrconv(HARD_CODED_ADDRESS, &ipaddr); #else uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0); #endif if((ipaddr.u16[0] != 0) || (ipaddr.u16[1] != 0) || (ipaddr.u16[2] != 0) || (ipaddr.u16[3] != 0)) { #if UIP_CONF_ROUTER if(!uip_ds6_prefix_add(&ipaddr, UIP_DEFAULT_PREFIX_LEN, 0, 0, 0, 0)) { fprintf(stderr,"uip_ds6_prefix_add() failed.\n"); exit(EXIT_FAILURE); } #else /* UIP_CONF_ROUTER */ if(!uip_ds6_prefix_add(&ipaddr, UIP_DEFAULT_PREFIX_LEN, 0)) { fprintf(stderr,"uip_ds6_prefix_add() failed.\n"); exit(EXIT_FAILURE); } #endif /* UIP_CONF_ROUTER */ uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr); uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF); } } #endif /* !UIP_CONF_IPV6_RPL */ #endif /* !UIP_CONF_IPV6 */ // procinit_init(); // autostart_start(autostart_processes); /* Make standard output unbuffered. */ setvbuf(stdout, (char *)NULL, _IONBF, 0); printf("\n*******%s online*******\n",CONTIKI_VERSION_STRING); #if UIP_CONF_IPV6 && !RPL_BORDER_ROUTER /* Border router process prints addresses later */ { int i = 0; int interface_count = 0; 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"); interface_count++; } } assert(0 < interface_count); } #endif while(1) { fd_set fds; int n; struct timeval tv; clock_time_t next_event; n = process_run(); next_event = etimer_next_expiration_time() - clock_time(); #if DEBUG_SLEEP if(n > 0) printf("sleep: %d events pending\n",n); else printf("sleep: next event @ T-%.03f\n",(double)next_event / (double)CLOCK_SECOND); #endif #ifdef __CYGWIN__ /* wpcap doesn't appear to support select, so * we can't idle the process on windows. */ next_event = 0; #endif if(next_event > (CLOCK_SECOND * 2)) next_event = CLOCK_SECOND * 2; tv.tv_sec = n ? 0 : (next_event / CLOCK_SECOND); tv.tv_usec = n ? 0 : ((next_event % 1000) * 1000); FD_ZERO(&fds); FD_SET(STDIN_FILENO, &fds); #ifdef __CYGWIN__ select(1, &fds, NULL, NULL, &tv); #else FD_SET(tapdev_fd(), &fds); if(0 > select(tapdev_fd() + 1, &fds, NULL, NULL, &tv)) { perror("Call to select() failed."); exit(EXIT_FAILURE); } #endif if(FD_ISSET(STDIN_FILENO, &fds)) { char c; if(read(STDIN_FILENO, &c, 1) > 0) { serial_line_input_byte(c); } } #ifdef __CYGWIN__ process_poll(&wpcap_process); #else process_poll(&tapdev_process); #endif etimer_request_poll(); } return 0; }