Ejemplo n.º 1
0
/*---------------------------------------------------------------------------*/
static int
stm32w_radio_init(void)
{
  /* A channel also needs to be set. */
  ST_RadioSetChannel(RF_CHANNEL);

  /* Initialize radio (analog section, digital baseband and MAC). */
  /* Leave radio powered up in non-promiscuous rx mode. */
  ST_RadioInit(ST_RADIO_POWER_MODE_OFF);

  onoroff = OFF;
  ST_RadioSetPanId(IEEE802154_PANID);

  CLEAN_RXBUFS();
  CLEAN_TXBUF();

#if ST_RADIO_AUTOACK && !(UIP_CONF_LL_802154 && RIMEADDR_CONF_SIZE==8)
#error "Autoack and address filtering can only be used with EUI 64"
#endif
  ST_RadioEnableAutoAck(ST_RADIO_AUTOACK);
  ST_RadioEnableAddressFiltering(ST_RADIO_AUTOACK);

  locked = 0;
  process_start(&stm32w_radio_process, NULL);

  return 0;
}
Ejemplo n.º 2
0
/*******************************************************************************
* Function Name  : main.
* Description    : talk main routine.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void main(void)
{
  u8 i;
  u32 seed;
  StStatus status = ST_SUCCESS;
  
  /* Initialization */
  halInit();
  ST_RadioGetRandomNumbers((u16 *)&seed, 2);
  halCommonSeedRandom(seed);
  uartInit(115200, 8, PARITY_NONE, 1);
  INTERRUPTS_ON();
 
  /* init leds */
  halInitLed(); 
  
  /* Initialize radio (analog section, digital baseband and MAC).
  Leave radio powered up in non-promiscuous rx mode */
  status = ST_RadioInit(ST_RADIO_POWER_MODE_RX_ON);
  assert(status==ST_SUCCESS); 

  /* Setup some node and pan ids.  The packet above is also sent to a device
     with the same node and pan id so that two nodes running this same image
     will talk to each other, even though its not right to have two nodes
     with the same node id */
  ST_RadioSetNodeId(0x1604);
  ST_RadioSetPanId(0x1604);

  printf("\r\nSimpleMAC (%s) Talk Application\r\n",SIMPLEMAC_VERSION_STRING);

  while(1) {

    processSerialInput();

    /* print out any packets that were received */
    if(packetReceived == TRUE) {
      for (i = 8; i <= rxPacket[0]; i++)
        putchar(rxPacket[i]);
      /* The packet has been processed, so free the single entry queue up */
      packetReceived = FALSE;
    }
    ledTime++;
    if (ledTime > 20000) 
    {
      halToggleLed(LED_D1);
      ledTime = 0;
    }
  }
}/* end main ()*/
Ejemplo n.º 3
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();
    }
Ejemplo n.º 4
0
int main (void)
{
  u8 returnValue;
  u32 seed;

  interactive = 1;

  halInit();
  ST_RadioGetRandomNumbers((u16 *)&seed, 2);
  halCommonSeedRandom(seed);
  uartInit(115200, 8, PARITY_NONE, 1);
  INTERRUPTS_ON();  

  /* Initialize radio (analog section, digital baseband and MAC).
  Leave radio powered up in non-promiscuous rx mode */
  returnValue = ST_RadioInit(ST_RADIO_POWER_MODE_RX_ON);

  assert(returnValue==ST_SUCCESS); 

  TIMER_Init();

  printf("Bootloader demo application\r\n");
  
  responsePrintf("{&N API call... &t2x}\r\n", "halGetResetInfo", "resetInfo", 0);

  txBufferInit(FALSE);
  rxBufferInit();
  blInit(NULL, transmitByte, receiveByte);

  ST_RadioSetPanId(IAP_BOOTLOADER_PAN_ID);
  ST_RadioSetChannel(IAP_BOOTLOADER_DEFAULT_CHANNEL);

  commandReaderInit();

  while(1) {
    // Process input and print prompt if it returns TRUE.
    if (processCmdInput(interactive)) {
      if (interactive) {
	printf(">");
      }
      TIMER_Tick();
    }
  }
}
Ejemplo n.º 5
0
/*---------------------------------------------------------------------------*/
static int stm32w_radio_init(void)
{
  
  // A channel needs also to be setted.
  ST_RadioSetChannel(RF_CHANNEL);

  // Initialize radio (analog section, digital baseband and MAC).
  // Leave radio powered up in non-promiscuous rx mode.
  ST_RadioInit(ST_RADIO_POWER_MODE_OFF);
  onoroff = OFF;
  ST_RadioSetNodeId(STM32W_NODE_ID);   // To be deleted.
  ST_RadioSetPanId(IEEE802154_PANID);
  
  CLEAN_RXBUFS();
  CLEAN_TXBUF();
  
  process_start(&stm32w_radio_process, NULL);
  
  return 0;
}
Ejemplo n.º 6
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++;
}
Ejemplo n.º 7
0
/*******************************************************************************
** 函数名称:   Zigbee_Receive
** 函数功能:   zigbee接收处理函数,双向通讯
** 入口参数:  
** 出口参数:  
** 备    注: 
*******************************************************************************/
void Zigbee_Receive(void)
{
	ST_RadioSetChannel(Recieve_Channel);  
    ST_RadioInit(ST_RADIO_POWER_MODE_RX_ON);
		
	RX_Time = 0;
      while(RX_Time <=2200)                                   //接收4ms (5ms 2850个循环)
      {
        if(packetReceived==TRUE)
        {
          if(array_compare(&rxPacket[1],&Card_Cmd[0],9))      //判断帧头
          {
            if((array_compare(&rxPacket[10],&Card_Cmd[9],2)|| //判断是否自身编号或0xFFFF,井上呼叫
                (rxPacket[10]==0xFF)&&(rxPacket[11]==0xFF)))
            {
              UpperCommander = TRUE;
              break;
            }
            else if((rxPacket[10]==0xEE)&&(rxPacket[11]==0xEE)||
                    (rxPacket[10]==Card_Cmd[9])&&(rxPacket[11]==(Card_Cmd[10]&0x80)))
            {
              UpperCommander = FALSE;                         			//取消呼叫进入静默
              break;
            }
            else if(0x40==(rxPacket[11]&0xE0))		      		//日期设置命令,卡号高字节高2位为01表示日期命令,卡号低字节及卡号高字节低6位表示日期
            {
                Factory_Date = (((rxPacket[11]&0x3F)<<8)|rxPacket[10]);//获得出厂日期
                WriteFactoryDateFlag = TRUE;
                break;
            }
          }
          packetReceived = FALSE;
        }      
        RX_Time++;
      }
      packetReceived = FALSE;
}
Ejemplo n.º 8
0
/*******************************************************************************
** 函数名称:   zigbee_crv_init
** 函数功能:   zigbee接收初始化
** 入口参数:  
** 出口参数:  
** 备    注: 
*******************************************************************************/
void zigbee_rcv_init(void)
{
	ST_RadioSetChannel(Recieve_Channel);  
    ST_RadioInit(ST_RADIO_POWER_MODE_RX_ON);
}