Example #1
0
/*---------------------------------------------------------------------------*/
static int stm32w_radio_off(void)
{  
  /* Any transmit or receive packets in progress are aborted.
   * Waiting for end of transmission or reception have to be done.
   */
  if(onoroff == ON){
    ST_RadioSleep();
    onoroff = OFF;
    CLEAN_TXBUF();
    CLEAN_RXBUFS();  
  
    ENERGEST_OFF(ENERGEST_TYPE_LISTEN);
  }
  
  return 1;
}
Example #2
0
/**
  * @brief  check if the device needs to go to deep sleep to save power
  * @param  active: Flag to indicate whether the node is active or not
  * @param  batteryOperated: Flag to activate power management
  * @retval None
  */
void powerManagement(boolean active, boolean batteryOperated)
{
  static uint32_t inactiveStartTime = 0;
  
  if (!batteryOperated)
    return;
  
  if (inactiveStartTime == 0)
  {
    inactiveStartTime = halCommonGetInt16uQuarterSecondTick();
  }
  
  if (active)
  {
    /* Reset inactive start time */
    inactiveStartTime = halCommonGetInt16uQuarterSecondTick();
  }
  else
  {
    if(elapsedTimeInt16u(inactiveStartTime, halCommonGetInt16uQuarterSecondTick()) > INACTIVE_TIMEOUT) 
    {
      StStatus status;
      
      ST_RadioSleep();
      ATOMIC(
             halPowerDown();
             halSleepWithOptions(SLEEPMODE_NOTIMER,
                                 BUTTON_S1_WAKE_SOURCE|
#ifdef USE_MB950
                                 BUTTON_S2_WAKE_SOURCE|
                                 BUTTON_S3_WAKE_SOURCE|
                                 BUTTON_S4_WAKE_SOURCE|
                                 BUTTON_S5_WAKE_SOURCE|
#endif /* USE_MB950 */
                                 UART_RX_WAKE_SOURCE);
             halPowerUp();
             )
      /* It is the application's responsibility to reinitialize the UART */
      uartInit();
    
      status = ST_RadioInit(ST_RADIO_POWER_MODE_RX_ON);
      assert(status==ST_SUCCESS);  
      inactiveStartTime = halCommonGetInt16uQuarterSecondTick();
    }
Example #3
0
/*---------------------------------------------------------------------------*/
static int stm32w_radio_off(void)
{  
  /* Any transmit or receive packets in progress are aborted.
   * Waiting for end of transmission or reception have to be done.
   */
  if(locked)
  {
    PRINTF("stm32w: try to off while sending/receiving (lock=%u).\r\n", locked);
    return 0;
  }
  /* off only if there is no transmission or reception of packet. */
  if(onoroff == ON && TXBUF_EMPTY() && !receiving_packet){
    LED_RDC_OFF();
    ST_RadioSleep();
    onoroff = OFF;
    CLEAN_TXBUF();
    CLEAN_RXBUFS();  
  
    ENERGEST_OFF(ENERGEST_TYPE_LISTEN);
  }
  
  return 1;
}
Example #4
0
/*******************************************************************************
** 函数名称:   Zigbee_Transmit
** 函数功能:   zigbee发送函数处理主函数
** 入口参数:  
** 出口参数:  
** 备    注: 
*******************************************************************************/
void Zigbee_Transmit(void)
{
	  ST_RadioEnableOverflowNotification(FALSE);
      ST_RadioSetPowerMode(ST_TX_POWER_MODE_DEFAULT);    
      ST_RadioEnableAddressFiltering(FALSE);
      ST_RadioEnableAutoAck(FALSE);
      ST_RadioSetPower(RF_Power);
      ST_RadioSetChannel(Send_Channel);   
      ST_RadioInit(ST_RADIO_POWER_MODE_OFF); 
	  
	  Card_Cmd[10] |= (0x00|(battery.stat<<5)|(help_flag<<7));				//电池电量及求助状态

	  txBuf[0] =(int8u)(sizeof(Card_Cmd)+2);
      for(int8u ct = 0; ct < (int8u)sizeof(Card_Cmd); ct++)
        txBuf[ct + 1] = Card_Cmd[ct];      
      txPacketInFlight = TRUE;
      if(ST_RadioTransmit(txBuf)==ST_SUCCESS){
        while(txPacketInFlight);
        ST_RadioSleep();
      }
      else
        SendFailTime++;
}