Exemplo n.º 1
0
/*---------------------------------------------------------------------------*/
int stm32w_radio_set_channel(uint8_t channel)
{
  if (ST_RadioSetChannel(channel) == ST_SUCCESS)
    return 0;
  else
    return 1;
}
Exemplo n.º 2
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;
}
Exemplo n.º 3
0
/*--------------------------------------------------------------------------*/
static radio_result_t
set_value(radio_param_t param, radio_value_t value)
{
  switch(param) {
  case RADIO_PARAM_POWER_MODE:
    if(value == RADIO_POWER_MODE_ON) {
      stm32w_radio_on();
      return RADIO_RESULT_OK;
    }
    if(value == RADIO_POWER_MODE_OFF) {
      stm32w_radio_off();
      return RADIO_RESULT_OK;
    }
    return RADIO_RESULT_INVALID_VALUE;
  case RADIO_PARAM_CHANNEL:
    if(value < ST_MIN_802_15_4_CHANNEL_NUMBER ||
       value > ST_MAX_802_15_4_CHANNEL_NUMBER) {
      return RADIO_RESULT_INVALID_VALUE;
    }
    if(ST_RadioSetChannel(value) != ST_SUCCESS) {
      return RADIO_RESULT_ERROR;
    }
    return RADIO_RESULT_OK;
  case RADIO_PARAM_PAN_ID:
    ST_RadioSetPanId(value & 0xffff);
    return RADIO_RESULT_OK;
  case RADIO_PARAM_16BIT_ADDR:
    ST_RadioSetNodeId(value & 0xffff);
    return RADIO_RESULT_OK;
  case RADIO_PARAM_RX_MODE:
    if(value & ~(RADIO_RX_MODE_ADDRESS_FILTER |
                 RADIO_RX_MODE_AUTOACK)) {
      return RADIO_RESULT_INVALID_VALUE;
    }
    ST_RadioEnableAddressFiltering((value & RADIO_RX_MODE_ADDRESS_FILTER) != 0);
    ST_RadioEnableAutoAck((value & RADIO_RX_MODE_AUTOACK) != 0);
    return RADIO_RESULT_OK;
  case RADIO_PARAM_TXPOWER:
    if(value < MIN_RADIO_POWER || value > MAX_RADIO_POWER) {
      return RADIO_RESULT_INVALID_VALUE;
    }
    if(ST_RadioSetPower((int8_t)value) != ST_SUCCESS) {
      return RADIO_RESULT_INVALID_VALUE;
    }
    return RADIO_RESULT_OK;
  case RADIO_PARAM_CCA_THRESHOLD:
    ST_RadioSetEdCcaThreshold((int8_t)value);
    return RADIO_RESULT_OK;
  default:
    return RADIO_RESULT_NOT_SUPPORTED;
  }
}
Exemplo n.º 4
0
void radio_init()
{
#ifdef EUI64_TRUNK_ID
	{
		uint8_t *eui = ST_RadioGetEui64();
		my_addr8_ = eui[0];
		my_addr16_ = my_addr8_;
	}
#else
	{
		my_addr8_ = MY_ADDR;
		my_addr16_ = MY_ADDR;
	}
#endif
	result_1 = ST_RadioSetPowerMode(0x00);
#ifdef _STM32W_HIGH_POWER_
	// For High Power Module use this
	uint16_t txPowerMode = 0x0001; //USER_TX_POWER_MODE; // Boost and alternate Tx/RX
	result_1 = ST_RadioSetPowerMode(txPowerMode);
	GPIO_PCCFGH = GPIO_PCCFGH & 0xFFFFFF0F; // PC5
	GPIO_PCCFGH = GPIO_PCCFGH | 0x00000090; // PC5 = 0x9 - Special function (TX select)
	// Prepare PB5, PB6, PB7 for controlling the external amplifier
	GPIO_PBCFGH = GPIO_PBCFGH & 0xFFFF000F;
	GPIO_PBCFGH = GPIO_PBCFGH | 0x00001110;
	GPIO_PBCLR = 0x000000E0;
	GPIO_PBSET = 0x000000C0; // 0xC - enable LNA and activate chip, 0x4 - enable chip (exit sleep)
#endif //_STM32W_HIGH_POWER_

	my_rf_channel_ = DEFAULT_RF_CHANNEL;
	my_tx_power_ = DEFAULT_TX_POWER; // configured power level (default for orodinary communication
	stradio_retransmit_req_ = 0;
	ST_RadioSetNodeId(MY_ADDR);
	ST_RadioSetPanId(MY_PAN_ID);
	result_1 = ST_RadioSetChannel(my_rf_channel_);
	
	phy_set_power_level ( my_tx_power_ );
	stradio_pending_len_ = 0;
	stradio_pending_data_ = NULL;
	stradio_pending_dst_ = 0;
	
	sch_add_loop((sch_loop_func_t)radio_loop);
	

//	GPIO_PBOUT =
}
Exemplo n.º 5
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();
    }
  }
}
Exemplo n.º 6
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;
}
Exemplo n.º 7
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++;
}
Exemplo n.º 8
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;
}
Exemplo n.º 9
0
/*******************************************************************************
** 函数名称:   zigbee_crv_init
** 函数功能:   zigbee接收初始化
** 入口参数:  
** 出口参数:  
** 备    注: 
*******************************************************************************/
void zigbee_rcv_init(void)
{
	ST_RadioSetChannel(Recieve_Channel);  
    ST_RadioInit(ST_RADIO_POWER_MODE_RX_ON);
}