Esempio n. 1
0
/*--------------------------------------------------------------------------*/
static radio_result_t
get_value(radio_param_t param, radio_value_t *value)
{
  if(!value) {
    return RADIO_RESULT_INVALID_VALUE;
  }
  switch(param) {
  case RADIO_PARAM_POWER_MODE:
    *value = onoroff == ON ? RADIO_POWER_MODE_ON : RADIO_POWER_MODE_OFF;
    return RADIO_RESULT_OK;
  case RADIO_PARAM_CHANNEL:
    *value = ST_RadioGetChannel();
    return RADIO_RESULT_OK;
  case RADIO_PARAM_PAN_ID:
    *value = ST_RadioGetPanId();
    return RADIO_RESULT_OK;
  case RADIO_PARAM_16BIT_ADDR:
    *value = ST_RadioGetNodeId();
    return RADIO_RESULT_OK;
  case RADIO_PARAM_RX_MODE:
    *value = 0;
    if(ST_RadioAddressFilteringEnabled()) {
      *value |= RADIO_RX_MODE_ADDRESS_FILTER;
    }
    if(ST_RadioAutoAckEnabled()) {
      *value |= RADIO_RX_MODE_AUTOACK;
    }
    return RADIO_RESULT_OK;
  case RADIO_PARAM_TXPOWER:
    *value = ST_RadioGetPower();
    return RADIO_RESULT_OK;
  case RADIO_PARAM_CCA_THRESHOLD:
    *value = ST_RadioGetEdCcaThreshold();
    return RADIO_RESULT_OK;
  case RADIO_PARAM_RSSI:
    *value = ST_RadioEnergyDetection();
    return RADIO_RESULT_OK;

  case RADIO_CONST_CHANNEL_MIN:
    *value = ST_MIN_802_15_4_CHANNEL_NUMBER;
    return RADIO_RESULT_OK;
  case RADIO_CONST_CHANNEL_MAX:
    *value = ST_MAX_802_15_4_CHANNEL_NUMBER;
    return RADIO_RESULT_OK;

  case RADIO_CONST_TXPOWER_MIN:
    *value = MIN_RADIO_POWER;
    return RADIO_RESULT_OK;
  case RADIO_CONST_TXPOWER_MAX:
    *value = MAX_RADIO_POWER;
    return RADIO_RESULT_OK;

  default:
    return RADIO_RESULT_NOT_SUPPORTED;
  }
}
Esempio n. 2
0
/*---------------------------------------------------------------------------*/
int
main(void)
{
  
  /*
   * Initialize hardware.
   */
  halInit();
  clock_init();
  
  uart1_init(115200);
  
  // Led initialization
  leds_init();
    
  INTERRUPTS_ON(); 

  PRINTF("\r\nStarting ");
  PRINTF(CONTIKI_VERSION_STRING);
  PRINTF(" on %s\r\n",boardDescription->name);

  /*
   * Initialize Contiki and our processes.
   */
  
  process_init();
  
#if WITH_SERIAL_LINE_INPUT
  uart1_set_input(serial_line_input_byte);
  serial_line_init();
#endif
  
  
  process_start(&etimer_process, NULL);   
  ctimer_init();
  rtimer_init();
  
  netstack_init();
  set_rime_addr();
  
  
PRINTF("ACK enable=%u %s %s, channel check rate=%luHz, check interval %ums, clock second=%u, radio channel %u\r\n",
         ST_RadioAutoAckEnabled(), NETSTACK_MAC.name, NETSTACK_RDC.name,  
         CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0? 1:
                         NETSTACK_RDC.channel_check_interval()), NETSTACK_RDC.channel_check_interval(), CLOCK_SECOND,
         RF_CHANNEL);
  
#if !UIP_CONF_IPV6
  ST_RadioEnableAutoAck(FALSE); // Because frames are not 802.15.4 compatible. 
  ST_RadioEnableAddressFiltering(FALSE);
#endif
  ST_RadioEnableAutoAck(TRUE);

  
  procinit_init(); 
    


  energest_init();
  ENERGEST_ON(ENERGEST_TYPE_CPU);
  
  autostart_start(autostart_processes);
  
  
  watchdog_start();
  
  while(1){
    
    int r;    
    
    do {
      /* Reset watchdog. */
      watchdog_periodic();
      r = process_run();
    } while(r > 0);
    
    
    
    ENERGEST_OFF(ENERGEST_TYPE_CPU);
    //watchdog_stop();    
    ENERGEST_ON(ENERGEST_TYPE_LPM);
    /* Go to idle mode. */
    halSleepWithOptions(SLEEPMODE_IDLE,0);
    /* We are awake. */
    //watchdog_start();
    ENERGEST_OFF(ENERGEST_TYPE_LPM);
    ENERGEST_ON(ENERGEST_TYPE_CPU);  
    
  }
  
}