Пример #1
0
// This function will put the node into a low-duty checking mode to save power
void tdma_snooze()
{
    int8_t v;
    uint8_t i;

// stop the software watchdog timer so it doesn't interrupt
    nrk_sw_wdt_stop(0);
// This flag is cleared only by the button interrupt
    snoozing=1;
// Setup the button interrupt
    nrk_ext_int_configure( NRK_EXT_INT_1,NRK_LEVEL_TRIGGER, &wakeup_func);
// Clear it so it doesn't fire instantly
    EIFR=0xff;
    nrk_ext_int_enable( NRK_EXT_INT_1);
// Now loop and periodically check for packets
    while(1)
    {
        nrk_led_clr(RED_LED);
        nrk_led_clr(GREEN_LED);
        rf_power_up();
        rf_rx_on ();
// check return from button interrupt on next cycle
        if(snoozing==0 ) return;
        tmp_time.secs=0;
        tmp_time.nano_secs=10*NANOS_PER_MS;
        nrk_led_set(RED_LED);
        // Leave radio on for two loops of 10ms for a total of 20ms every 10 seconds
        for(i=0; i<2; i++ )
        {
            v = _tdma_rx ();
            if(v==NRK_OK) {
                nrk_led_set(RED_LED);
                nrk_ext_int_disable( NRK_EXT_INT_1);
                nrk_sw_wdt_update(0);
                nrk_sw_wdt_start(0);
                return NRK_OK;
            }
            nrk_wait(tmp_time);
        }
        nrk_led_clr(RED_LED);
        rf_power_down();
        tmp_time.secs=10;
        tmp_time.nano_secs=0;
        nrk_sw_wdt_stop(0);
        nrk_wait(tmp_time);

    }

}
Пример #2
0
// Resets RF parameters to default values.
// Must be called before jumping to new firmware.
static void resetRF()
{
  // PWR_UP = 0
  rf_power_down();
  // PRIM_RX = 0
  //rf_set_as_tx();
  // RF_CH = 0x02;
  //rf_set_channel(reset_channel);
  // AW = 11 (Default = 5 bytes)
  // RX_ADDR_P0 = TX_ADDR = 0xE7E7E7E7E7
  //rf_set_tx_address(reset_pipe_address,5);
  //rf_set_rx_address(reset_pipe_address, 5, 0);
  // ARD = 0000, ARC = 0011
  //rf_set_auto_rtr(3, 250);
  // RX_PW_P0 = 0x00
  //rf_set_rx_payload_width(0, 0);
  // Disable radio clock
  rf_clock_disable();
}
Пример #3
0
void bmac_disable()
{
    is_enabled=0;
    rf_power_down();
}
Пример #4
0
void tdma_disable ()
{
  tdma_is_enabled = 0;
  rf_power_down ();
}
Пример #5
0
void deep_sleep_button()
{
    int i,cnt;
    nrk_int_disable();
    nrk_eeprom_write_byte(EEPROM_SLEEP_STATE_ADDR,1);
    nrk_led_set(0);
    nrk_spin_wait_us(50000);
    nrk_led_clr(0);
    nrk_led_clr(1);
    nrk_led_clr(2);
    nrk_led_clr(3);
    nrk_watchdog_disable();
    nrk_int_disable();
    _nrk_os_timer_stop();
    nrk_gpio_direction(NRK_BUTTON, NRK_PIN_INPUT);
    rf_power_down();
    // Enable Pullup for button
    //PORTD = 0xff;
    nrk_gpio_set(NRK_BUTTON);
    nrk_ext_int_configure( NRK_EXT_INT_1,NRK_LEVEL_TRIGGER, &wakeup_func);
    EIFR=0xff;
    nrk_ext_int_enable( NRK_EXT_INT_1);
    nrk_int_enable();
    DDRA=0x0;
    DDRB=0x0;
    DDRC=0x0;
    ASSR=0;
    TRXPR = 1 << SLPTR;
    set_sleep_mode(SLEEP_MODE_PWR_DOWN);
    sleep_enable();
    sleep_cpu();
    // reboot
    while(1) {
        //printf( "awake!\r\n" );
        nrk_led_clr(0);
        nrk_led_clr(1);
        nrk_led_set(1);
        cnt=0;
        for(i=0; i<100; i++ )
        {
            //if((PIND & 0x2)==0x2)cnt++;
            if(nrk_gpio_get(NRK_BUTTON)==0)cnt++;
            nrk_spin_wait_us(10000);
        }
        printf( "cnt=%d\n",cnt );
        if(cnt>=50 ) {
            // reboot
            nrk_led_clr(1);
            nrk_led_set(0);
            nrk_eeprom_write_byte(EEPROM_SLEEP_STATE_ADDR,0);
            nrk_spin_wait_us(50000);
            nrk_spin_wait_us(50000);
            nrk_watchdog_enable();
            while(1);

        }
        nrk_led_clr(0);
        nrk_led_clr(1);
        TRXPR = 1 << SLPTR;
        set_sleep_mode(SLEEP_MODE_PWR_DOWN);
        sleep_enable();
        sleep_cpu();
    }
}
Пример #6
0
void bmac_nw_task ()
{
  int8_t v, i;
  int8_t e;
  uint8_t backoff;
  nrk_sig_mask_t event;

  while (bmac_started () == 0)
    nrk_wait_until_next_period ();

//register the signal after bmac_init has been called
  v = nrk_signal_register (bmac_enable_signal);
  if (v == NRK_ERROR)
    nrk_kprintf (PSTR ("Failed to register signal\r\n"));
  backoff = 0;
  while (1) {
#ifdef NRK_SW_WDT
#ifdef BMAC_SW_WDT_ID
    nrk_sw_wdt_update (BMAC_SW_WDT_ID);
#endif
#endif
    rf_power_up ();
    if (is_enabled) {
      v = 1;

#ifdef BMAC_MOD_CCA
      if (rx_buf_empty == 1)
      {
	 if (_bmac_rx () == 1) e = nrk_event_signal (bmac_rx_pkt_signal);
      }
      else
      e = nrk_event_signal (bmac_rx_pkt_signal);
#else
      if (rx_buf_empty == 1)
        v = _bmac_channel_check ();
      // If the buffer is full, signal the receiving task again.
      else
        e = nrk_event_signal (bmac_rx_pkt_signal);
      // bmac_channel check turns on radio, don't turn off if
      // data is coming.

      if (v == 0) {
        if (_bmac_rx () == 1) {
          e = nrk_event_signal (bmac_rx_pkt_signal);
          //if(e==NRK_ERROR) {
          //      nrk_kprintf( PSTR("bmac rx pkt signal failed\r\n"));
          //      printf( "errno: %u \r\n",nrk_errno_get() );
          //}
        }
        //else nrk_kprintf( PSTR("Pkt failed, buf could be corrupt\r\n" ));

      }

#endif
      if (tx_data_ready == 1) {
        _bmac_tx ();
      }
      rf_rx_off ();
      rf_power_down ();

      //do {
      nrk_wait (_bmac_check_period);
      //      if(rx_buf_empty!=1)  nrk_event_signal (bmac_rx_pkt_signal);
      //} while(rx_buf_empty!=1);
    }
    else {
      event = 0;
      do {
        v = nrk_signal_register (bmac_enable_signal);
        event = nrk_event_wait (SIG (bmac_enable_signal));
      }
      while ((event & SIG (bmac_enable_signal)) == 0);
    }
    //nrk_wait_until_next_period();
  }

}