/*-----------------------------Low level initialization--------------------*/ static void initialize(void) { watchdog_init(); watchdog_start(); #if CONFIG_STACK_MONITOR /* Simple stack pointer highwater monitor. The 'm' command in cdc_task.c * looks for the first overwritten magic number. */ { extern uint16_t __bss_end; uint16_t p=(uint16_t)&__bss_end; do { *(uint16_t *)p = 0x4242; p+=100; } while (p<RAMEND-100); } #endif /* Initialize hardware */ // Checks for "finger", jumps to DFU if present. init_lowlevel(); /* Clock */ clock_init(); #if USB_CONF_RS232 /* Use rs232 port for serial out (tx, rx, gnd are the three pads behind jackdaw leds */ rs232_init(RS232_PORT_0, USART_BAUD_57600,USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8); /* Redirect stdout to second port */ rs232_redirect_stdout(RS232_PORT_0); #if ANNOUNCE printf_P(PSTR("\n\n\n********BOOTING CONTIKI*********\n")); #endif #endif Leds_init(); /* rtimer init needed for low power protocols */ rtimer_init(); /* Process subsystem. */ process_init(); /* etimer process must be started before ctimer init */ process_start(&etimer_process, NULL); #if RF230BB ctimer_init(); /* Start radio and radio receive process */ /* Note this starts RF230 process, so must be done after process_init */ NETSTACK_RADIO.init(); /* Set addresses BEFORE starting tcpip process */ memset(&tmp_addr, 0, sizeof(rimeaddr_t)); if(!get_eui64_from_eeprom(tmp_addr.u8)) { #if JACKDAW_CONF_RANDOM_MAC // It doesn't look like we have a valid EUI-64 address // so let's try to make a new one from scratch. Leds_off(); Led2_on(); generate_new_eui64(tmp_addr.u8); if(!set_eui64_to_eeprom(tmp_addr.u8)) { watchdog_periodic(); int i; for(i=0;i<20;i++) { Led1_toggle(); _delay_ms(100); } Led1_off(); } Led2_off(); #else tmp_addr.u8[0]=0x02; tmp_addr.u8[1]=0x12; tmp_addr.u8[2]=0x13; tmp_addr.u8[3]=0xff; tmp_addr.u8[4]=0xfe; tmp_addr.u8[5]=0x14; tmp_addr.u8[6]=0x15; tmp_addr.u8[7]=0x16; #endif /* JACKDAW_CONF_RANDOM_MAC */ } //Fix MAC address init_net(); #if UIP_CONF_IPV6 memcpy(&uip_lladdr.addr, &tmp_addr.u8, 8); #endif rf230_set_pan_addr( get_panid_from_eeprom(), get_panaddr_from_eeprom(), (uint8_t *)&tmp_addr.u8 ); #if JACKDAW_CONF_USE_SETTINGS /* Allow radio code to overrite power for testing miniature Raven mesh */ #ifndef RF230_MAX_TX_POWER rf230_set_txpower(settings_get_uint8(SETTINGS_KEY_TXPOWER,0)); #endif #endif rimeaddr_set_node_addr(&tmp_addr); /* Initialize stack protocols */ queuebuf_init(); NETSTACK_RDC.init(); NETSTACK_MAC.init(); NETSTACK_NETWORK.init(); rf230_set_channel(get_channel_from_eeprom()); #if ANNOUNCE && USB_CONF_RS232 printf_P(PSTR("MAC address %x:%x:%x:%x:%x:%x:%x:%x\n\r"),tmp_addr.u8[0],tmp_addr.u8[1],tmp_addr.u8[2],tmp_addr.u8[3],tmp_addr.u8[4],tmp_addr.u8[5],tmp_addr.u8[6],tmp_addr.u8[7]); printf_P(PSTR("%s %s, channel %u"),NETSTACK_MAC.name, NETSTACK_RDC.name,rf230_get_channel()); if (NETSTACK_RDC.channel_check_interval) { unsigned short tmp; tmp=CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval == 0 ? 1:\ NETSTACK_RDC.channel_check_interval()); if (tmp<65535) printf_P(PSTR(", check rate %u Hz"),tmp); } printf_P(PSTR("\n")); #endif #if UIP_CONF_IPV6_RPL #if RPL_BORDER_ROUTER process_start(&tcpip_process, NULL); process_start(&border_router_process, NULL); PRINTF ("RPL Border Router Started\n"); #else process_start(&tcpip_process, NULL); PRINTF ("RPL Started\n"); #endif #if RPL_HTTPD_SERVER extern struct process httpd_process; process_start(&httpd_process, NULL); PRINTF ("Webserver Started\n"); #endif #endif /* UIP_CONF_IPV6_RPL */ #else /* RF230BB */ /* The order of starting these is important! */ process_start(&mac_process, NULL); process_start(&tcpip_process, NULL); #endif /* RF230BB */ /* Setup USB */ process_start(&usb_process, NULL); #if USB_CONF_SERIAL process_start(&cdc_process, NULL); #endif process_start(&usb_eth_process, NULL); #if USB_CONF_STORAGE process_start(&storage_process, NULL); #endif #if ANNOUNCE #if USB_CONF_SERIAL&&!USB_CONF_RS232 {unsigned short i; printf_P(PSTR("\n\n\n********BOOTING CONTIKI*********\n\r")); /* Allow USB CDC to keep up with printfs */ for (i=0;i<8000;i++) process_run(); #if RF230BB printf_P(PSTR("MAC address %x:%x:%x:%x:%x:%x:%x:%x\n\r"),tmp_addr.u8[0],tmp_addr.u8[1],tmp_addr.u8[2],tmp_addr.u8[3],tmp_addr.u8[4],tmp_addr.u8[5],tmp_addr.u8[6],tmp_addr.u8[7]); for (i=0;i<8000;i++) process_run(); printf_P(PSTR("%s %s, channel %u"),NETSTACK_MAC.name, NETSTACK_RDC.name,rf230_get_channel()); if (NETSTACK_RDC.channel_check_interval) { i=CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval == 0 ? 1:\ NETSTACK_RDC.channel_check_interval()); if (i<65535) printf_P(PSTR(", check rate %u Hz"),i); } printf_P(PSTR("\n\r")); for (i=0;i<8000;i++) process_run(); #endif /* RF230BB */ printf_P(PSTR("System online.\n\r")); } #elif USB_CONF_RS232 printf_P(PSTR("System online.\n")); #endif #endif /* ANNOUNCE */ }
/*---------------------------------------------------------------------------- MAIN function *----------------------------------------------------------------------------*/ int main (void) { /* Main Program */ //************************************************************************************************************ /* this is contiki-code */ watchdog_init(); /* Initialize hardware. */ clock_init(); /* UART4 Initialization */ // uart4_init(115200); USBD_Init(&USB_OTG_dev, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_CDC_cb, &USR_cb); // Led initialization leds_init(); leds_on(LEDS_BLUE); PRINTF("\r\nStarting "); PRINTF(CONTIKI_VERSION_STRING); PRINTF(" on %s \r\n", PLATFORM_NAME); #ifdef __USE_LCD GLCD_Init(); /* Initialize graphical LCD display */ GLCD_Clear(White); /* Clear graphical LCD display */ GLCD_SetBackColor(DarkGreen); GLCD_SetTextColor(White); GLCD_DisplayString(0, 0, __FI, " KUSZ - TU Dortmund "); GLCD_DisplayString(1, 0, __FI, " contiki "); GLCD_DisplayString(2, 0, __FI, " www.tu-dortmund.de "); GLCD_SetBackColor(White); GLCD_SetTextColor(Blue); watchdog_periodic(); #endif // __USE_LCD /* * Initialize Contiki and our processes. */ #ifdef WITH_SERIAL_LINE_INPUT // uart1_set_input(serial_line_input_byte); // serial_line_init(); #endif /* rtimer and ctimer should be initialized before radio duty cycling layers*/ rtimer_init(); process_init(); process_start(&sensors_process, NULL); /* etimers must be started before ctimer_init */ process_start(&etimer_process, NULL); ctimer_init(); /* Start radio and radio receive process */ NETSTACK_RADIO.init(); /* makes use of cpu-specific RNG peripheral - no seed needed */ random_init(0); /* Set addresses BEFORE starting tcpip process */ addr.u8[0] = 0x02; addr.u8[1] = *((uint8_t*)0x1FFF7A10); addr.u8[2] = *((uint8_t*)0x1FFF7A10+1); addr.u8[3] = 0xFF; addr.u8[4] = 0xFE; addr.u8[5] = *((uint8_t*)0x1FFF7A10+2); addr.u8[6] = *((uint8_t*)0x1FFF7A10+3); addr.u8[7] = *((uint8_t*)0x1FFF7A10+4); memcpy(&uip_lladdr.addr, &addr.u8, sizeof(rimeaddr_t)); rimeaddr_set_node_addr(&addr); rf230_set_pan_addr(0xabcd,0xbabe,(uint8_t *)&addr.u8); rf230_set_channel(CHANNEL_802_15_4); rf230_set_txpower(0); /* max */ PRINTF("EUI-64 MAC: %x-%x-%x-%x-%x-%x-%x-%x\n",addr.u8[0],addr.u8[1],addr.u8[2],addr.u8[3],addr.u8[4],addr.u8[5],addr.u8[6],addr.u8[7]); /* Initialize stack protocols */ queuebuf_init(); NETSTACK_RDC.init(); NETSTACK_MAC.init(); NETSTACK_NETWORK.init(); #define ANNOUNCE_BOOT 1 #if ANNOUNCE_BOOT PRINTF("%s %s, channel %u , check rate %u Hz tx power %u\n",NETSTACK_MAC.name, NETSTACK_RDC.name, rf230_get_channel(), CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1:NETSTACK_RDC.channel_check_interval()), rf230_get_txpower()); #if UIP_CONF_IPV6_RPL PRINTF("RPL Enabled\n"); #endif #if UIP_CONF_ROUTER PRINTF("Routing Enabled\n"); #endif #endif /* ANNOUNCE_BOOT */ process_start(&tcpip_process, NULL); /* Autostart other processes */ autostart_start(autostart_processes); #if ANNOUNCE_BOOT PRINTF("Online\n"); #endif /* ANNOUNCE_BOOT */ energest_init(); ENERGEST_ON(ENERGEST_TYPE_CPU); watchdog_start(); while (1) { /* Loop forever */ watchdog_periodic(); process_run(); } }
/*-----------------------------Low level initialization--------------------*/ static void initialize(void) { watchdog_init(); watchdog_start(); #if CONFIG_STACK_MONITOR /* Simple stack pointer highwater monitor. The 'm' command in cdc_task.c * looks for the first overwritten magic number. */ { extern uint16_t __bss_end; uint16_t p=(uint16_t)&__bss_end; do { *(uint16_t *)p = 0x4242; p+=100; } while (p<SP-100); //don't overwrite our own stack } #endif /* Initialize hardware */ // Checks for "finger", jumps to DFU if present. init_lowlevel(); /* Clock */ clock_init(); /* Leds are referred to by number to prevent any possible confusion :) */ /* Led0 Blue Led1 Red Led2 Green Led3 Yellow */ Leds_init(); Led1_on(); /* Get a random (or probably different) seed for the 802.15.4 packet sequence number. * Some layers will ignore duplicates found in a history (e.g. Contikimac) * causing the initial packets to be ignored after a short-cycle restart. */ ADMUX =0x1E; //Select AREF as reference, measure 1.1 volt bandgap reference. ADCSRA=1<<ADEN; //Enable ADC, not free running, interrupt disabled, fastest clock ADCSRA|=1<<ADSC; //Start conversion while (ADCSRA&(1<<ADSC)); //Wait till done PRINTD("ADC=%d\n",ADC); random_init(ADC); ADCSRA=0; //Disable ADC #if USB_CONF_RS232 /* Use rs232 port for serial out (tx, rx, gnd are the three pads behind jackdaw leds */ rs232_init(RS232_PORT_0, USART_BAUD_57600,USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8); /* Redirect stdout to second port */ rs232_redirect_stdout(RS232_PORT_0); #if ANNOUNCE PRINTA("\n\n*******Booting %s*******\n",CONTIKI_VERSION_STRING); #endif #endif /* rtimer init needed for low power protocols */ rtimer_init(); /* Process subsystem. */ process_init(); /* etimer process must be started before USB or ctimer init */ process_start(&etimer_process, NULL); Led2_on(); /* Now we can start USB enumeration */ process_start(&usb_process, NULL); /* Start CDC enumeration, bearing in mind that it may fail */ /* Hopefully we'll get a stdout for startup messages, if we don't already */ #if USB_CONF_SERIAL process_start(&cdc_process, NULL); {unsigned short i; for (i=0;i<65535;i++) { process_run(); watchdog_periodic(); if (stdout) break; } #if !USB_CONF_RS232 PRINTA("\n\n*******Booting %s*******\n",CONTIKI_VERSION_STRING); #endif } #endif if (!stdout) Led3_on(); #if RF230BB #if JACKDAW_CONF_USE_SETTINGS PRINTA("Settings manager will be used.\n"); #else {uint8_t x[2]; *(uint16_t *)x = eeprom_read_word((uint16_t *)&eemem_channel); if((uint8_t)x[0]!=(uint8_t)~x[1]) { PRINTA("Invalid EEPROM settings detected. Rewriting with default values.\n"); get_channel_from_eeprom(); } } #endif ctimer_init(); /* Start radio and radio receive process */ /* Note this starts RF230 process, so must be done after process_init */ NETSTACK_RADIO.init(); /* Set addresses BEFORE starting tcpip process */ memset(&tmp_addr, 0, sizeof(rimeaddr_t)); if(get_eui64_from_eeprom(tmp_addr.u8)); //Fix MAC address init_net(); #if UIP_CONF_IPV6 memcpy(&uip_lladdr.addr, &tmp_addr.u8, 8); #endif rf230_set_pan_addr( get_panid_from_eeprom(), get_panaddr_from_eeprom(), (uint8_t *)&tmp_addr.u8 ); rf230_set_channel(get_channel_from_eeprom()); rf230_set_txpower(get_txpower_from_eeprom()); rimeaddr_set_node_addr(&tmp_addr); /* Initialize stack protocols */ queuebuf_init(); NETSTACK_RDC.init(); NETSTACK_MAC.init(); NETSTACK_NETWORK.init(); #if ANNOUNCE PRINTA("MAC address %x:%x:%x:%x:%x:%x:%x:%x\n\r",tmp_addr.u8[0],tmp_addr.u8[1],tmp_addr.u8[2],tmp_addr.u8[3],tmp_addr.u8[4],tmp_addr.u8[5],tmp_addr.u8[6],tmp_addr.u8[7]); PRINTA("%s %s, channel %u",NETSTACK_MAC.name, NETSTACK_RDC.name,rf230_get_channel()); if (NETSTACK_RDC.channel_check_interval) { unsigned short tmp; tmp=CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval == 0 ? 1:\ NETSTACK_RDC.channel_check_interval()); if (tmp<65535) PRINTA(", check rate %u Hz",tmp); } PRINTA("\n"); #endif #if UIP_CONF_IPV6_RPL #if RPL_BORDER_ROUTER process_start(&tcpip_process, NULL); process_start(&border_router_process, NULL); PRINTD ("RPL Border Router Started\n"); #else process_start(&tcpip_process, NULL); PRINTD ("RPL Started\n"); #endif #if RPL_HTTPD_SERVER extern struct process httpd_process; process_start(&httpd_process, NULL); PRINTD ("Webserver Started\n"); #endif #endif /* UIP_CONF_IPV6_RPL */ #else /* RF230BB */ /* The order of starting these is important! */ process_start(&mac_process, NULL); process_start(&tcpip_process, NULL); #endif /* RF230BB */ /* Start ethernet network and storage process */ process_start(&usb_eth_process, NULL); #if USB_CONF_STORAGE process_start(&storage_process, NULL); #endif /* Autostart other processes */ /* There are none in the default build so autostart_processes will be unresolved in the link. */ /* The AUTOSTART_PROCESSES macro which defines it can only be used in the .co module. */ /* See /examples/ravenusbstick/ravenusb.c for an autostart template. */ #if 0 autostart_start(autostart_processes); #endif #if ANNOUNCE #if USB_CONF_RS232 PRINTA("Online.\n"); #else PRINTA("Online. Type ? for Jackdaw menu.\n"); #endif #endif Leds_off(); }
void menu_process(char c) { static enum menustate_enum /* Defines an enumeration type */ { normal, channel, txpower } menustate = normal; static char channel_string[3]; static uint8_t channel_string_i;// = 0; int tempchannel; if (menustate == channel) { switch(c) { case '\r': case '\n': if (channel_string_i) { channel_string[channel_string_i] = 0; tempchannel = atoi(channel_string); if ((tempchannel < 11) || (tempchannel > 26)) { PRINTF_P(PSTR("\n\rInvalid input\n\r")); } else { rf230_set_channel(tempchannel); #if CONTIKI_CONF_SETTINGS_MANAGER if(settings_set_uint8(SETTINGS_KEY_CHANNEL, tempchannel) == SETTINGS_STATUS_OK) { PRINTF_P(PSTR("\n\rChannel changed to %d and stored in EEPROM.\n\r"), tempchannel); } else { PRINTF_P(PSTR("\n\rChannel changed to %d, but unable to store in EEPROM!\n\r"), tempchannel); } #else PRINTF_P(PSTR("\n\rChannel changed to %d.\n\r"), tempchannel); #endif } } else { PRINTF_P(PSTR("\n\rChannel unchanged.\n\r")); } menustate = normal; break; case '\b': if (channel_string_i) { channel_string_i--; PRINTF_P(PSTR("\b \b")); } break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': if (channel_string_i > 1) { // This time the user has gone too far. // Beep at them. putc('\a', stdout); break; } putc(c, stdout); channel_string[channel_string_i] = c; channel_string_i++; break; default: break; } } else if (menustate == txpower) { switch(c) { case '\r': case '\n': if (channel_string_i) { channel_string[channel_string_i] = 0; tempchannel = atoi(channel_string); if ((tempchannel < 0) || (tempchannel > 15)) { PRINTF_P(PSTR("\n\rInvalid input\n\r")); } else { PRINTF_P(PSTR(" ")); //for some reason needs a print here to clear the string input... rf230_set_txpower(tempchannel); #if CONTIKI_CONF_SETTINGS_MANAGER if(settings_set_uint8(SETTINGS_KEY_TXPOWER, tempchannel) == SETTINGS_STATUS_OK) { PRINTF_P(PSTR("\n\rTransmit power changed to %d, and stored in EEPROM.\n\r"), tempchannel); } else { PRINTF_P(PSTR("\n\rTransmit power changed to %d, but unable to store in EEPROM!\n\r"), tempchannel); } #else PRINTF_P(PSTR("\n\rTransmit power changed to %d.\n\r"), tempchannel); #endif } } else { PRINTF_P(PSTR("\n\rTransmit power unchanged.\n\r")); } menustate = normal; break; case '\b': if (channel_string_i) { channel_string_i--; PRINTF_P(PSTR("\b \b")); } break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': if (channel_string_i > 1) { // This time the user has gone too far. // Beep at them. putc('\a', stdout); break; } putc(c, stdout); channel_string[channel_string_i] = c; channel_string_i++; break; default: break; } } else { uint8_t i; switch(c) { case '\r': case '\n': break; case 'h': case '?': menu_print(); break; case 'd': if (mx_console_mode.debugOn) { PRINTF_P(PSTR("Node does not output debug strings\n\r")); mx_console_mode.debugOn = 0; } else { PRINTF_P(PSTR("Node now outputs debug strings\n\r")); mx_console_mode.debugOn = 1; } break; case 'c': PRINTF_P(PSTR("\nSelect 802.15.4 Channel in range 11-26 [%d]: "), rf230_get_channel()); menustate = channel; channel_string_i = 0; break; case 'p': PRINTF_P(PSTR("\nSelect transmit power (0=+3dBm 15=-17.2dBm) [%d]: "), rf230_get_txpower()); menustate = txpower; channel_string_i = 0; break; #if UIP_CONF_IPV6_RPL #include "rpl.h" extern uip_ds6_nbr_t uip_ds6_nbr_cache[]; extern uip_ds6_netif_t uip_ds6_if; case 'N': { uint8_t i,j; PRINTF_P(PSTR("\n\rAddresses [%u max]\n\r"),UIP_DS6_ADDR_NB); for (i=0;i<UIP_DS6_ADDR_NB;i++) { if (uip_ds6_if.addr_list[i].isused) { ipaddr_add(&uip_ds6_if.addr_list[i].ipaddr); PRINTF_P(PSTR("\n\r")); } } PRINTF_P(PSTR("\n\rNeighbors [%u max]\n\r"),UIP_DS6_NBR_NB); for(i = 0,j=1; i < UIP_DS6_NBR_NB; i++) { if(uip_ds6_nbr_cache[i].isused) { ipaddr_add(&uip_ds6_nbr_cache[i].ipaddr); PRINTF_P(PSTR("\n\r")); j=0; } } if (j) PRINTF_P(PSTR(" <none>")); PRINTF_P(PSTR("\n\rRoutes [%u max]\n\r"),UIP_DS6_ROUTE_NB); { uip_ds6_route_t *r; j = 1; for(r = uip_ds6_route_list_head(); r != NULL; r = list_item_next(r)) { ipaddr_add(&r->ipaddr); PRINTF_P(PSTR("/%u (via "), r->length); ipaddr_add(&r->nexthop); if(r->state.lifetime < 600) { PRINTF_P(PSTR(") %lus\n\r"), r->state.lifetime); } else { PRINTF_P(PSTR(")\n\r")); } j = 0; } } if (j) PRINTF_P(PSTR(" <none>")); PRINTF_P(PSTR("\n\r---------\n\r")); break; } case 'G': PRINTF_P(PSTR("Global repair returns %d\n\r"),rpl_repair_root(RPL_DEFAULT_INSTANCE)); break; case 'L': rpl_local_repair(rpl_get_any_dag()); PRINTF_P(PSTR("Local repair initiated\n\r")); break; #endif case 'm': PRINTF_P(PSTR("Currently running on\n\r")); PRINTF_P(PSTR(" * %s\n\r"), CONTIKI_VERSION_STRING); PRINTF_P(PSTR(" * NETSTACK_MAC: %s, NETSTACK_RDC: %s\n\r"), NETSTACK_MAC.name, NETSTACK_RDC.name); #if 1 { int i; PRINTF_P(PSTR(" * Address: ")); for (i = 0; i < 6; i += 2) { PRINTF_P(PSTR("%02x%02x:"), uip_lladdr.addr[i], uip_lladdr.addr[i + 1]); } PRINTF_P(PSTR("%02x%02x\n\r"), uip_lladdr.addr[6], uip_lladdr.addr[7]); } #endif #if UIP_CONF_IPV6_RPL PRINTF_P(PSTR(" * RPL Enabled\n\r")); #endif #if UIP_CONF_ROUTER PRINTF_P(PSTR(" * Routing Enabled\n\r")); #endif #if CONVERTTXPOWER PRINTF_P(PSTR(" * Operates on channel %d with TX power "),rf230_get_channel()); printtxpower(); PRINTF_P(PSTR("\n\r")); #else //just show the raw value PRINTF_P(PSTR(" * Operates on channel %d\n\r"), rf230_get_channel()); PRINTF_P(PSTR(" * TX Power(0=+3dBm, 15=-17.2dBm): %d\n\r"), rf230_get_txpower()); #endif if (rf230_smallest_rssi) { PRINTF_P(PSTR(" * Current/Last/Smallest RSSI: %d/%d/%ddBm\n\r"), -91+(rf230_rssi()-1), -91+(rf230_last_rssi-1),-91+(rf230_smallest_rssi-1)); rf230_smallest_rssi=0; } else { PRINTF_P(PSTR(" * Current/Last/Smallest RSSI: %d/%d/--dBm\n\r"), -91+(rf230_rssi()-1), -91+(rf230_last_rssi-1)); } #if CONFIG_STACK_MONITOR /* See contiki-raven-main.c for initialization of the magic numbers */ { extern uint16_t __bss_end; uint16_t p=(uint16_t)&__bss_end; do { if (*(uint16_t *)p != 0x4242) { printf_P(PSTR(" * Never-used stack > %d bytes\n\r"),p-(uint16_t)&__bss_end); break; } p+=100; } while (p<RAMEND-100); } #endif break; case 'e': PRINTF_P(PSTR("Energy Scan:\n")); { uint8_t i; uint16_t j; uint8_t previous_channel = rf230_get_channel(); int8_t RSSI, maxRSSI[17]; uint16_t accRSSI[17]; bzero((void*)accRSSI,sizeof(accRSSI)); bzero((void*)maxRSSI,sizeof(maxRSSI)); for(j=0;j<(1<<12);j++) { for(i=11;i<=26;i++) { rf230_listen_channel(i); _delay_us(3*10); RSSI = rf230_rssi(); //multiplies rssi register by 3 for consistency with energy-detect register maxRSSI[i-11]=Max(maxRSSI[i-11],RSSI); accRSSI[i-11]+=RSSI; } if(j&(1<<7)) { leds_on(LEDS_RED); if(!(j&((1<<7)-1))) { PRINTF_P(PSTR(".")); } } else { leds_off(LEDS_RED); } watchdog_periodic(); } rf230_set_channel(previous_channel); PRINTF_P(PSTR("\n")); for(i=11;i<=26;i++) { uint8_t activity=Min(maxRSSI[i-11],accRSSI[i-11]/(1<<7)); PRINTF_P(PSTR(" %d: %02ddB "),i, -91+(maxRSSI[i-11]-1)); for(;activity--;maxRSSI[i-11]--) { PRINTF_P(PSTR("#")); } for(;maxRSSI[i-11]>0;maxRSSI[i-11]--) { PRINTF_P(PSTR(":")); } PRINTF_P(PSTR("\n")); } } PRINTF_P(PSTR("Done.\n")); break; case 'R': PRINTF_P(PSTR("Resetting...\n\r")); leds_on(LEDS_ALL); for(i = 0; i < 20; i++) _delay_ms(100); watchdog_reboot(); break; default: PRINTF_P(PSTR("%c is not a valid option! h for menu\n\r"), c); break; } } }