diff --git a/platform/mb851/contiki-main.c b/platform/mb851/contiki-main.c index fce0c640b..d65f023ec 100644 --- a/platform/mb851/contiki-main.c +++ b/platform/mb851/contiki-main.c @@ -86,13 +86,17 @@ #if UIP_CONF_IPV6 -PROCINIT(&tcpip_process, &sensors_process); +PROCINIT(&tcpip_process, &sensors_process); #else -PROCINIT(&sensors_process); +PROCINIT(&sensors_process); #warning "No TCP/IP process!" #endif -SENSORS(&button_sensor,&temperature_sensor,&acc_sensor); +SENSORS(&button_sensor, &temperature_sensor, &acc_sensor); + +/* The default CCA threshold is set to -77, which is the same as the + default setting on the TI CC2420. */ +#define DEFAULT_RADIO_CCA_THRESHOLD -77 /*---------------------------------------------------------------------------*/ static void @@ -101,24 +105,26 @@ set_rime_addr(void) int i; union { uint8_t u8[8]; - }eui64; + } eui64; int8u *stm32w_eui64 = ST_RadioGetEui64(); { - int8u c; - for(c = 0; c < 8; c++) { // Copy the EUI-64 to lladdr converting from Little-Endian to Big-Endian. - eui64.u8[c] = stm32w_eui64[7 - c]; - } + int8u c; + /* Copy the EUI-64 to lladdr converting from Little-Endian to + Big-Endian. */ + for(c = 0; c < 8; c++) { + eui64.u8[c] = stm32w_eui64[7 - c]; + } } - + #if UIP_CONF_IPV6 memcpy(&uip_lladdr.addr, &eui64, sizeof(uip_lladdr.addr)); #endif #if UIP_CONF_IPV6 rimeaddr_set_node_addr((rimeaddr_t *)&eui64); -#else - rimeaddr_set_node_addr((rimeaddr_t *)&eui64.u8[8-RIMEADDR_SIZE]); +#else + rimeaddr_set_node_addr((rimeaddr_t *)&eui64.u8[8 - RIMEADDR_SIZE]); #endif printf("Rime started with address "); @@ -126,7 +132,6 @@ set_rime_addr(void) printf("%d.", rimeaddr_node_addr.u8[i]); } printf("%d\n", rimeaddr_node_addr.u8[i]); - } /*---------------------------------------------------------------------------*/ int @@ -141,7 +146,7 @@ main(void) uart1_init(115200); - // Led initialization + /* Led initialization */ leds_init(); INTERRUPTS_ON(); @@ -160,13 +165,13 @@ main(void) uart1_set_input(serial_line_input_byte); serial_line_init(); #endif - /* rtimer and ctimer should be initialized before radio duty cycling layers*/ - rtimer_init(); - /* etimer_process should be initialized before ctimer */ - process_start(&etimer_process, NULL); - ctimer_init(); - - + /* rtimer and ctimer should be initialized before radio duty cycling + layers */ + rtimer_init(); + /* etimer_process should be initialized before ctimer */ + process_start(&etimer_process, NULL); + ctimer_init(); + netstack_init(); set_rime_addr(); @@ -179,14 +184,23 @@ main(void) IEEE802154_CONF_PANID, UIP_CONF_LL_802154?64:16); uip_debug_lladdr_print(&rimeaddr_node_addr); printf(", radio channel %u\n", RF_CHANNEL); - - procinit_init(); + + procinit_init(); energest_init(); ENERGEST_ON(ENERGEST_TYPE_CPU); + + /* Set the Clear Channel Assessment (CCA) threshold of the + radio. The CCA threshold is used both for sending packets and for + waking up ContikiMAC nodes. If the CCA threshold is too high, + ContikiMAC will not wake up from neighbor transmissions. If the + CCA threshold is too low, transmissions will be too restrictive + and no packets will be sent. DEFAULT_RADIO_CCA_THRESHOLD is + defined in this file. */ + ST_RadioSetEdCcaThreshold(DEFAULT_RADIO_CCA_THRESHOLD); autostart_start(autostart_processes); - +#if UIP_CONF_IPV6 printf("Tentative link-local IPv6 address "); { uip_ds6_addr_t *lladdr; @@ -199,6 +213,7 @@ main(void) printf("%02x%02x\n", lladdr->ipaddr.u8[14], lladdr->ipaddr.u8[15]); } + if(!UIP_CONF_IPV6_RPL) { uip_ipaddr_t ipaddr; int i; @@ -213,10 +228,11 @@ main(void) printf("%02x%02x\n", ipaddr.u8[7 * 2], ipaddr.u8[7 * 2 + 1]); } +#endif /* UIP_CONF_IPV6 */ watchdog_start(); - while(1){ + while(1) { int r; @@ -229,12 +245,12 @@ main(void) ENERGEST_OFF(ENERGEST_TYPE_CPU); - //watchdog_stop(); + /* watchdog_stop(); */ ENERGEST_ON(ENERGEST_TYPE_LPM); /* Go to idle mode. */ halSleepWithOptions(SLEEPMODE_IDLE,0); /* We are awake. */ - //watchdog_start(); + /* watchdog_start(); */ ENERGEST_OFF(ENERGEST_TYPE_LPM); ENERGEST_ON(ENERGEST_TYPE_CPU);