示例#1
0
文件: main.c 项目: x893/WDS
/** \fn void main(void)
 * \brief The main function of the demo.
 *
 * \todo Create description
 */
void main(void)
{
  // Initialize the Hardware and Radio
  vInitializeHW();

#ifdef SILABS_LCD_DOG_GLCD
  /* Initialize graphic LCD */
  vLcd_InitLcd();

  /* Set logo location to center */
  bLcd_LcdSetPictureCursor(bLcd_Line1_c, 35u);

  /* Draw SiLabs logo */
  vLcd_LcdDrawPicture(silabs66x30);
#endif

  // Start RX
  vRadio_StartRX(pRadioConfiguration->Radio_ChannelNumber);

  while (TRUE)
  {
    // The following Handlers requires care on invoking time interval
    if (wIsr_MsTick)
    {
      vHmi_LedHandler();
      vHmi_BuzzHandler();
      vHmi_PbHandler();

      wIsr_MsTick = 0;
    }

    // Demo Application Poll-Handler function
    DemoApp_Pollhandler();
  }
}
示例#2
0
文件: main.c 项目: ckt1010/Robin
/** \fn void main(void)
 * \brief The main function of the demo.
 *
 * \todo Create description
 */
void main(void)
{
  xdata U8 buf[] = {0x7E,0x05,0x01, 0x02, 0x03, 0x7D, 0x5D, 0x00, 0x83, 0x7E};
  U16 i=65536;
  // Initialize the Hardware and Radio
  vInitializeHW();

  // Start RX
  vRadio_StartRX(pRadioConfiguration->Radio_ChannelNumber);
  while (TRUE)
  {

	Uart_revc_Radio_trans();

    if(gRadio_CheckReceived())
	{
		if(Uart_trans_Radio_recv()==0)
		//if(LED)
		//LED = ILLUMINATE;
		//else
		LED ^= EXTINGUISH;
	}
//	Uart_trans_Radio_recv_test(buf);
  }
}
示例#3
0
U8 set_hop_table(U8 UserChannel)
{
    U8 i=0,j=0;
    if(UserChannel>32)
    {
      UserChannel = PUBLIC_CHANNEL;
      
    }
    si4438_phy.RF_status=RF_IDLE_FLAG;
    si446x_change_state(SI446X_CMD_CHANGE_STATE_ARG_NEW_STATE_ENUM_READY);
    Clear_int_status();
    Pro2Cmd[i++]=0x11;
    Pro2Cmd[i++]=0x50;
    Pro2Cmd[i++]=0x0C;
    Pro2Cmd[i++]=0x00;
    Pro2Cmd[i++]=Si4438HopRegister[j++]=0x30; 
    Pro2Cmd[i++]=Si4438HopRegister[j++]=0x04;
    Pro2Cmd[i++]=Si4438HopRegister[j++]=ChannelsSupported[0][0]; 
    Pro2Cmd[i++]=Si4438HopRegister[j++]=ChannelsSupported[0][1];
    Pro2Cmd[i++]=Si4438HopRegister[j++]=ChannelsSupported[UserChannel][0];
    Pro2Cmd[i++]=Si4438HopRegister[j++]=ChannelsSupported[UserChannel][1];
    Pro2Cmd[i++]=Si4438HopRegister[j++]=0xFF;
    Pro2Cmd[i++]=Si4438HopRegister[j++]=0xFF;
    Pro2Cmd[i++]=Si4438HopRegister[j++]=0xFF;
    Pro2Cmd[i++]=Si4438HopRegister[j++]=0xFF;
    Pro2Cmd[i++]=Si4438HopRegister[j++]=0xFF;
    Pro2Cmd[i++]=Si4438HopRegister[j++]=0xFF;
      
    if(set_property(Pro2Cmd,0x10)==SI446X_SUCCESS)
    {
      DBUG("set_hop_table=%d\r\n",UserChannel);
      set_pchannel=UserChannel;
      si4438_phy.PhyPrivateChannel=UserChannel;
      Clear_int_status();
      vRadio_StartRX(ChannelsSupported[0][0]);
      return TRUE;
    }
    return FALSE;
  
    
}
示例#4
0
/**
 *  main - main application loop. Sets up platform and then performs simple
 *  transfers (simplex) while incrementing the sequence number for the lifetime 
 *  of execution.
 *
 *    @return   Exit code of the main application, however, this application
 *              should never exit.
 */
int main(void)
{
  RCC_ClocksTypeDef RCC_ClockFreq;
  RCC_GetClocksFreq(&RCC_ClockFreq);
  
  if (SysTick_Config(RCC_ClockFreq.HCLK_Frequency/1000))
  { 
    /* Capture error */ 
    while (1);
  }
  
  Il_Hw_Init(); 
  
  Init_SI4463_Pin();
  
  vRadio_Init(); 
  
  ClkSwitch2HseSystemInit();

  RCC_GetClocksFreq(&RCC_ClockFreq);
  
  if (SysTick_Config(RCC_ClockFreq.HCLK_Frequency/1000))
  { 
    /* Capture error */ 
    while (1);
  }
  
  Il_Hw_Init(); 
  
  Uart_Init();
    
  Init_SI4463_Pin();
  
//TimingBaseInit(50000);
  
//  while(1)
//  {
////  //LedD4StaInvert();  
////    GPIOB->BSRR  = 0x00000040;
////    GPIOB->BRR  = 0x00000040;
//  }
  
  //EXTILine_TimingSync_Config();
  
  //si446x_get_int_status(0u, 0u, 0u);
  uint8_t testBuff[6]={0x05,0xD0,0x01,0x02,0x03,0xD6};
  
  //UartSendByte(testBuff, 6); 
  
  vRadio_StartRX(pRadioConfiguration->Radio_ChannelNumber);
  
  RadioGotoRxSta();
  
  SI4463_Enable_NIRQ_Int();

  if (!ProtocolInit(&gProtocolSetupInfo))
  {
    return false;
  }
  
  while(true)
  {
    if(GetPubRxBufCount()>0x00)
    {
      //UartSendByte(timMark, 1);
      //UartSendByte(uartRxDataBuff, uartRxCount);
      //uartDataProcess();
      PubRxDataProcess();
    }  
    
    if(GetPubTxBufCount()>0x00)
    {
      PubTxDataProcess();
    }  
    
    if (!ProtocolBusy())
    {
      // Increment the sequence number for the next transmission.
      gPacket.seqNum++;
    }
  }
  
//  while (true)
//  {
//    // Perform a simple transfer of the packet.
//    if (!ProtocolSimpleTransfer((unsigned char*)&gPacket, sizeof(struct sPacket)))
//    {
//      // Put the microcontroller into a low power state (sleep). Remain here
//      // until the ISR wakes up the processor.
//      //McuSleep();
//    }
//    
//    /**
//     *  Check if the protocol is busy. If it is, a new transfer cannot occur
//     *  until it becomes ready for the next instruction. Do not increment the
//     *  sequence number until the protocol is ready. This prevents incrementing
//     *  the sequence number more than once between transmissions.
//     */
//    if (!ProtocolBusy())
//    {
//      // Increment the sequence number for the next transmission.
//      gPacket.seqNum++;
//    }
//  }
}
示例#5
0
文件: main.c 项目: x893/WDS
/** \fn void main(void)
 * \brief The main function of the demo.
 *
 * \todo Create description
 */
void main(void)
{
  /*! State Machine variable */
  eLDCState lLDCState = LDC_STATE_CHIP_WAKEUP;
  static U8  lFlag = 0u;
  static U16 lMsCount = 0u;
  static U16 lTimeoutCount = 0u;
  static U16 lPacketProcessCount = 0u;

  // Initialize the Hardware and Radio
  vInitializeHW();

  /* Start Timer2 to get 1ms ticks */
  vTmr_StartTmr2(bTmr_Tmr2Both_c, wwTmr_Tmr2Periode.U16, TRUE, bTmr_TxXCLK_00_c);

  while (TRUE)
  {

    /* Radio timing state machine */
    switch (lLDCState)
    {
    case LDC_STATE_CHIP_WAKEUP:
      /* Set Radio Chip to RX */
      vRadio_StartRX(pRadioConfiguration->Radio_ChannelNumber);

      /* Reset time counter */
      lMsCount = 0u;

      /* Wait for Preamble Detect */
      lLDCState = LDC_STATE_WAIT_PREAMBLE;
      break;

    case LDC_STATE_WAIT_PREAMBLE:
      /* Check if the allowed timeout already elapsed */
      if (lMsCount > LDC_CONFIG_AWAKE_TIME_MS)
      {
        /* Reset time counter */
        lMsCount -= LDC_CONFIG_AWAKE_TIME_MS;

        /* Set Radio into Sleep state */
        si4455_change_state(SI4455_CMD_CHANGE_STATE_ARG_NEW_STATE_ENUM_SLEEP);

        lLDCState = LDC_STATE_SLEEP;
      }
      break;

    case LDC_STATE_WAIT_SYNCWORD:
      /* Preamble detected, wait for Sync */

      /* Check if Sync Word timeout already elapsed */
      if (lTimeoutCount > 0u)
      {
        lTimeoutCount -= 1u;
      }
      else
      {
        lLDCState = LDC_STATE_WAIT_PREAMBLE;
      }

      break;

    case LDC_STATE_WAIT_PACKET_RX:
      /* Sync Word received, wait for Packet RX IT */

      /* Check if Packet RX timeout already elapsed */
      if (lTimeoutCount > 0u)
      {
        lTimeoutCount -= 1u;
      }
      else
      {
        /* Set Radio Chip to RX */
        vRadio_StartRX(pRadioConfiguration->Radio_ChannelNumber);

        lLDCState = LDC_STATE_WAIT_PREAMBLE;
      }

      break;

    case LDC_STATE_SLEEP:
      /* Radio in Sleep state */

      /* Check if Sleep timeout elapsed */
      if (lMsCount > LDC_CONFIG_SLEEP_TIME_MS)
      {
        lLDCState = LDC_STATE_CHIP_WAKEUP;
      }
      break;

    default:
      /* Unknown state */

      lLDCState = LDC_STATE_CHIP_WAKEUP;
      break;
    }


    /* Check for NIRQ signal */
    if (FALSE == RF_NIRQ)
    {
      /* Read & Clear Interrupt Pending flags */
      si4455_get_int_status(0u, 0u, 0u);

      if (Si4455Cmd.GET_INT_STATUS.PH_PEND & SI4455_CMD_GET_INT_STATUS_ARG_PACKET_RX_PEND_CLR_BIT)
      {
        /* Packet RX */

        /* Read FIFO content */
        si4455_read_rx_fifo(pRadioConfiguration->Radio_PacketLength, (U8 *) &fixRadioPacket[0u]);

        /*- Reset RX FIFO */
        si4455_fifo_info(0x02);

        /* Wait for processing payload */
        lLDCState = LDC_STATE_WAIT_PREAMBLE;

        /* Set packet received flag */
        lFlag |= (1u << FLAG_PACKET_RX);

        // Invoke once the Demo Application Poll-Handler function
        DemoApp_Pollhandler();

        /* Set Packet processing time interval */
        lPacketProcessCount = 300u;
      }
      else if (Si4455Cmd.GET_INT_STATUS.MODEM_PEND & SI4455_CMD_GET_INT_STATUS_ARG_PREAMBLE_DETECT_PEND_CLR_BIT)
      {
        /* Preamble detected */

        /* Set Sync Word Detect timeout */
        lTimeoutCount = LDC_CONFIG_SYNC_TIMEOUT_MS;

        /* Wait for Sync Word detected IT */
        lLDCState = LDC_STATE_WAIT_SYNCWORD;
      }
      else if (Si4455Cmd.GET_INT_STATUS.MODEM_PEND & SI4455_CMD_GET_INT_STATUS_ARG_SYNC_DETECT_PEND_CLR_BIT)
      {
        /* Sync word detected */

        /* Set Packet RX timeout */
        lTimeoutCount = LDC_CONFIG_PACKET_RX_TIMEOUT_MS;

        /* Wait for Packer RX IT */
        lLDCState = LDC_STATE_WAIT_PACKET_RX;
      }
      else
      {
        /* Packet CRC Error => Clear RX FIFO */
        si4455_fifo_info(0x02);

        /* Set the radio into Preamble search */
        lLDCState = LDC_STATE_WAIT_PREAMBLE;
      }
    }


    if (wIsr_MsTick)
    {
      /* Clear tick flag */
      wIsr_MsTick = FALSE;

      /* Increase time counter by 1 */
      lMsCount += 1u;

      if (lFlag&(1u << FLAG_PACKET_RX))
      {
        // The following Handlers only invoked if payload processing takes place
        vHmi_LedHandler();
        vHmi_BuzzHandler();

        if (0u == lPacketProcessCount--)
        {
          /* Clear Packet processing indicator */
          lFlag &= ~(1u << FLAG_PACKET_RX);
        }
      }
    }

    /* If not processing payload */
    if (!(lFlag&(1u << FLAG_PACKET_RX)))
    {
      /* Set MCU into low-power IDLE state (waken up by Timer2 overflow IT) */
      ENTER_IDLE;
    }

  }
}
示例#6
0
/**
 *  main - main application loop. Sets up platform and then goes to sleep for
 *  the lifetime of execution.
 *
 *    @return   Exit code of the main application, however, this application
 *              should never exit.
 */
int main(void)
{
  RCC_ClocksTypeDef RCC_ClockFreq;
  RCC_GetClocksFreq(&RCC_ClockFreq);
  
  if (SysTick_Config(RCC_ClockFreq.HCLK_Frequency/1000))
  { 
    /* Capture error */ 
    while (1);
  }
  
  Il_Hw_Init(); 
  
  Init_SI4463_Pin();
  
  vRadio_Init(); 
  
  ClkSwitch2HseSystemInit();

  RCC_GetClocksFreq(&RCC_ClockFreq);
  
  if (SysTick_Config(RCC_ClockFreq.HCLK_Frequency/1000))
  { 
    /* Capture error */ 
    while (1);
  }
  
  Il_Hw_Init(); 
  
  Uart_Init();
    
  Init_SI4463_Pin();
  
//TimingBaseInit(50000);
  
//  while(1)
//  {
////  //LedD4StaInvert();  
////    GPIOB->BSRR  = 0x00000040;
////    GPIOB->BRR  = 0x00000040;
//  }
  
  //EXTILine_TimingSync_Config();
  
  //si446x_get_int_status(0u, 0u, 0u);
  uint8_t testBuff[6]={0x05,0xD0,0x01,0x02,0x03,0xD6};
  
  //UartSendByte(testBuff, 6); 
  
  vRadio_StartRX(pRadioConfiguration->Radio_ChannelNumber);
  
  RadioGotoRxSta();
  
  SI4463_Enable_NIRQ_Int();

  if (!ProtocolInit(&gProtocolSetupInfo))
  {
    return false;
  }
  
  while(1)
  {
    if(GetPubTxBufCount()>0x00)
    {
      PubTxDataProcess();
    }  
  }  
}
示例#7
0
文件: radio.c 项目: Ryoma521/ChlTest
uint8 SI4463_Config_Transmit_singlerate(U8 * pSrc1,U8 len1)
{
  
  //发送第一个包
   trx_state = 0;//f发送模式
  
  /* Check if the radio is already in TX state */
  si446x_request_device_state();
  if (SI446X_CMD_REQUEST_DEVICE_STATE_REP_MAIN_STATE_ENUM_TX == \
      (Si446xCmd.REQUEST_DEVICE_STATE.CURR_STATE & 0x0F)) {
    /* Still transmitting */
    return FALSE;
  }

  /* Reset TX FIFO */
  si446x_fifo_info(SI446X_CMD_FIFO_INFO_ARG_TX_BIT);

  /* Fill the TX FIFO with data */
  si446x_write_tx_fifo(len1, pSrc1);


  /* Start sending packet, channel 0, START immediately,
   * Packet length according to 'len', go READY when done */
  si446x_start_tx(0u, 0x30,  len1);
  
  uint32 counter = 0;
  while (PKT_Sent_Flag!=1)//发送等待
  {
  //等待保护
  asm("nop");
  counter++;
  if(counter >= 0xFFFFFFFF)
    {
     //第一个包未发送成功
    counter=0;
    return FALSE;
    }  
  }
  
   PKT_Sent_Flag =0;
  
  
#if 0
  //DelayMs(1);
//发送第二个包
  
  vRadio_config_2nd();
  
  trx_state = 0;//f发送模式
  
  /* Check if the radio is already in TX state */
  si446x_request_device_state();
  if (SI446X_CMD_REQUEST_DEVICE_STATE_REP_MAIN_STATE_ENUM_TX == \
      (Si446xCmd.REQUEST_DEVICE_STATE.CURR_STATE & 0x0F)) {
    /* Still transmitting */
    return FALSE;
  }

  /* Reset TX FIFO */
  si446x_fifo_info(SI446X_CMD_FIFO_INFO_ARG_TX_BIT);

  /* Fill the TX FIFO with data */
  si446x_write_tx_fifo(len2, pSrc2);


  /* Start sending packet, channel 0, START immediately,
   * Packet length according to 'len', go READY when done */
  si446x_start_tx(0u, 0x30,  len2);
  
  
  while (PKT_Sent_Flag!=1)//发送等待
  {
  //等待保护
  asm("nop");
  counter++;
  if(counter >= 0xFFFFFFFF)
  {
     //第一个包未发送成功
    counter=0;
    return FALSE;
  }
    
  }
  
  PKT_Sent_Flag =0;
  vRadio_config_1st();
  
  vRadio_StartRX_1st(pRadioConfiguration_1st->Radio_ChannelNumber);//回复第一个包的接收模式
  trx_state = 1;//第二个包发完之后默认为接收状态
   
#endif 
  
    vRadio_StartRX(pRadioConfiguration->Radio_ChannelNumber);//回复第一个包的接收模式
  trx_state = 1;//第二个包发完之后默认为接收状态
  
  return TRUE;
}