예제 #1
0
/**
* @brief  This function handles External interrupt request. In this application it is used
*         to manage the Spirit IRQ configured to be notified on the Spirit GPIO_3.
* @param  None
* @retval None
*/
void P2PInterruptHandler(void)
{
  SpiritIrqGetStatus(&xIrqStatus);
  
  /* Check the SPIRIT TX_DATA_SENT IRQ flag */
  if(xIrqStatus.IRQ_TX_DATA_SENT || xIrqStatus.IRQ_MAX_RE_TX_REACH)
  {
    xTxDoneFlag = SET;
  }
  /* Check the SPIRIT RX_DATA_READY IRQ flag */
  else if(xIrqStatus.IRQ_RX_DATA_READY)
  {
    xRxDoneFlag = SET;   
  }
  /* Check the SPIRIT RX_DATA_DISC IRQ flag */
  else if(xIrqStatus.IRQ_RX_DATA_DISC)
  {    
    /* RX command - to ensure the device will be ready for the next reception */
    if(xIrqStatus.IRQ_RX_TIMEOUT)
    {
      SpiritCmdStrobeFlushRxFifo();
      rx_timeout = SET; 
    }
  }
  else
  {
	  spirit_error = SET;
	  HAL_UART_Transmit(&huart1, ". ", 2, 1000);

  }
}
예제 #2
0
파일: DZ-SBD-MB01.c 프로젝트: bzdegluk/ACQ
void M2S_GPIO_0_EXTI_IRQ_HANDLER(void)
{
 
  /* Check the flag status of EXTI line */
  if(EXTI_GetITStatus(M2S_GPIO_0_EXTI_LINE)){
    
    /* Get the IRQ status */
    SpiritIrqGetStatus(&xIrqStatus);
    
     
    // Check the SPIRIT RX_DATA_DISC IRQ flag 
    if(xIrqStatus.IRQ_RX_DATA_DISC)
    {
      
      SdkEvalLedToggle(LED_YELLOW);  
 
    }
    
    /* Check the SPIRIT RX_DATA_READY IRQ flag */
    if(xIrqStatus.IRQ_RX_DATA_READY)
    {
     
      /* Get the RX FIFO size */
      cRxData=SpiritLinearFifoReadNumElementsRxFifo();
      
      /* Read the RX FIFO */
      SpiritSpiReadLinearFifo(cRxData, vectcRxBuff);
      
      /* Flush the RX FIFO */
      SpiritCmdStrobeFlushRxFifo();


      
#ifdef USE_VCOM
      /* print the received data */
      printf("B data received: [");
      for(uint8_t i=0 ; i<cRxData ; i++)
        printf("%d ", vectcRxBuff[i]);
      printf("]\r\n");
#endif
      
      SdkEvalLedToggle(LED_GREEN);

    }
     
    
     if(xIrqStatus.IRQ_TX_DATA_SENT)
    {
      /* set the tx_done_flag to manage the event in the main() */
      xTxDoneFlag = SET;
      
    } 
    
    /* Clear the EXTI line flag */
    EXTI_ClearITPendingBit(M2S_GPIO_0_EXTI_LINE);
    
  }
}
예제 #3
0
/**
* @brief  this function receives the data
* @param  None
* @retval None
*/
void Spirit1GetRxPacket(uint8_t *buffer, uint8_t cRxData )
{
  /* when rx data ready read the number of received bytes */
  cRxData=SpiritLinearFifoReadNumElementsRxFifo();

  /* read the RX FIFO */
  SpiritSpiReadLinearFifo(cRxData, buffer);
  
  SpiritCmdStrobeFlushRxFifo();
}
예제 #4
0
파일: End_Point.c 프로젝트: bzdegluk/ACQ
void M2S_GPIO_0_EXTI_IRQ_HANDLER(void)
{
  if(EXTI_GetFlagStatus(M2S_GPIO_0_EXTI_LINE))
  {
    SpiritIrqGetStatus(&xIrqStatus); // Get the IRQ status
          if(xIrqStatus.IRQ_RX_DATA_DISC)  // Check the SPIRIT1 RX_DATA_DISC IRQ flag 
        {
  //        SdkEvalLedToggle(LED_YELLOW);  // IRQ: Spirit1 RX data discarded (upon filtering)
        }
    // Check the SPIRIT TX_DATA_SENT IRQ flag
    if(xIrqStatus.IRQ_TX_DATA_SENT)
    {
      // Set the xTxDoneFlag to manage processing of this event in the main()  
      xTxDoneFlag = SET;
      SdkEvalLedToggle(LED_GREEN);
    }
    if(xIrqStatus.IRQ_TX_FIFO_ERROR)
    {
      //   
      xTxDoneFlag = SET;
//      SdkEvalLedToggle(LED_GREEN);
    }
    if(xIrqStatus.IRQ_RX_DATA_READY)
    {
      command_size = SpiritLinearFifoReadNumElementsRxFifo();  //get the size of received command
      SpiritSpiReadLinearFifo(command_size, command_buffer);    //read the buffer
      SpiritCmdStrobeFlushRxFifo();     //flush the RX fifo
      SdkEvalLedToggle(LED_YELLOW);
//      SpiritCmdStrobeRx();
      command_pending = 1;
    }
    
    // Clear the EXTI line flag
   
    EXTI_ClearFlag(M2S_GPIO_0_EXTI_LINE);
  }
} // end of M2S_GPIO_0_EXTI_IRQ_HANDLER()
예제 #5
0
/**
* @brief  System main function.
* @param  None
* @retval None
*/
void main (void)
{
  SDK_SYSTEM_CONFIG();
  
#ifdef USE_VCOM
#ifdef STM8L
  SdkEvalComInit(115200,USART_WordLength_8b,USART_StopBits_1,USART_Parity_No,USART_Mode_Tx);
#elif SDK
  /* VC config */
  SdkEvalVCInit();
  while(bDeviceState != CONFIGURED);
#endif
#endif 

  /* Spirit ON */
  SpiritEnterShutdown();
  SpiritExitShutdown();
  SpiritManagementWaExtraCurrent();
  
#ifdef STM8L
  /* Manually set the XTAL_FREQUENCY */
  SpiritRadioSetXtalFrequency(XTAL_FREQUENCY);    
  /* Initialize the frequency offset variable to compensate XTAL offset */
  xRadioInit.lFrequencyBase = xRadioInit.lFrequencyBase + FREQUENCY_OFFSET;
  /* Initialize the signals to drive the range extender application board */
  RANGE_EXT_INIT(RANGE_TYPE);
#elif SDK
  SpiritManagementIdentificationRFBoard();

  /* if the board has eeprom, we can compensate the offset calling SpiritManagementGetOffset
  (if eeprom is not present this fcn will return 0) */
  xRadioInit.lFrequencyBase = xRadioInit.lFrequencyBase + SpiritManagementGetOffset();
    
  /* Initialize the signals to drive the range extender application board */
  SpiritManagementRangeExtInit();  
#endif

  /* Initialize the signals to drive the range extender application board */
  SpiritManagementRangeExtInit();  
  
  SdkEvalM2SGpioInit(M2S_GPIO_3,M2S_MODE_EXTI_IN);
  SdkEvalM2SGpioInterruptCmd(M2S_GPIO_3,0x0A,0x0A,ENABLE);
  
  /* Spirit IRQ config */
  SpiritGpioInit(&xGpioIRQ);

  /* Spirit Radio config */
  SpiritRadioInit(&xRadioInit);
  
  /* Spirit Radio set power */
  SpiritRadioSetPALevelMaxIndex(7);
  SpiritRadioSetPALeveldBm(7,POWER_DBM);
  
  /* Spirit Packet config */
  SpiritPktStackInit(&xStackInit);
  SpiritPktStackAddressesInit(&xAddressInit);
  SpiritPktStackLlpInit(&xStackLLPInit);
  
  /* Spirit IRQs enable */
  SpiritIrqDeInit(NULL);
  SpiritIrq(TX_DATA_SENT, S_ENABLE);
  SpiritIrq(RX_DATA_READY, S_ENABLE);
  SpiritIrq(RX_DATA_DISC, S_ENABLE);
  
  /* RX timeout config */
  SET_INFINITE_RX_TIMEOUT();
  SpiritTimerSetRxTimeoutStopCondition(SQI_ABOVE_THRESHOLD);
  
  /* Payload length config */
  SpiritPktStackSetPayloadLength(20);
  
  /* Destination address */
  SpiritPktStackSetDestinationAddress(DESTINATION_ADDRESS);
  
  /* IRQ registers blanking */
  SpiritIrqClearStatus();
  
  /* infinite loop */
  while (1){
    /* RX command */
    SpiritCmdStrobeRx();
    
    /* wait for data received */
    while(!xRxDoneFlag);
    xRxDoneFlag=RESET;
    
    /* when rx data ready read the number of received bytes */
    cRxData=SpiritLinearFifoReadNumElementsRxFifo();
    
    /* read the RX FIFO */
    SpiritSpiReadLinearFifo(cRxData, vectcBallBuff);
    SpiritCmdStrobeFlushRxFifo();
    
    /*  A simple way to control if the received data sequence is correct.
    Use a local block.
    */
    {
      SpiritBool correct=S_TRUE;
      
      /* control all the received bytes and verify that they are sequential
      numbers from 1 to 20. If one of them is not an expected value then
      stop the communication.
      */
      for(uint8_t i=0 ; i<cRxData ; i++)
        if(vectcBallBuff[i] != i+1)
          correct=S_FALSE;
      
#ifdef USE_VCOM
      /* send messages via COM */
      if(correct)
      {
        printf("B Rx data: [");
        for(uint8_t i=0 ; i<cRxData ; i++)
          printf("%d ", vectcBallBuff[i]);
        printf("]\r\n");
      }
      else
      {
        printf("data error! ping pong stopped\n\r");
        
      }
      
#endif
      
      /* stop communication if an incorrect sequence has been received */
      if(!correct){
        SdkEvalLedOn(LED4);
        
        while(1);
      }
    }
    
    /* pause between RX and TX */
    SdkDelayMs(500);
    
    /* fit the TX FIFO */
    SpiritCmdStrobeFlushTxFifo();
    SpiritSpiWriteLinearFifo(20, vectcBallBuff);
    
    /* send the TX command */
    SpiritCmdStrobeTx();
    
    /* wait for TX done */
    while(!xTxDoneFlag);
    
    xTxDoneFlag = RESET;
    
#ifdef USE_VCOM
    /* send messages via COM */
    printf("B Tx data: [");
    for(uint8_t i=0 ; i<cRxData ; i++)
      printf("%d ", vectcBallBuff[i]);
    printf("]\n\r");
#endif
    
  }
  
}
void M2S_GPIO_3_EXTI_IRQ_HANDLER(void)
#endif
{
  /* Check the flag status of EXTI line */
  if(EXTI_GetITStatus(M2S_GPIO_3_EXTI_LINE)){

	/* Get the IRQ status */
    SpiritIrqGetStatus(&xIrqStatus);

    /* Check the SPIRIT RX_DATA_DISC IRQ flag */
    if(xIrqStatus.IRQ_RX_DATA_DISC)
    {
      SpiritCmdStrobeRx()
      SdkEvalLedToggle(LED1);
    }

    /* Check the SPIRIT TX_DATA_SENT IRQ flag for the acknoledgement */
    if(xIrqStatus.IRQ_TX_DATA_SENT)
    {
//      SdkEvalLedToggle(LED1);

#ifdef PIGGYBACKING
      SpiritSpiWriteLinearFifo(20, vectcTxBuff);
      printf("Loaded piggybacking data: [");

      for(uint8_t i=0 ; i<20 ; i++)
        printf("%d ", vectcTxBuff[i]);
      printf("]\n\r");
#endif

      SpiritCmdStrobeRx();
    }

    /* Check the SPIRIT RX_DATA_READY IRQ flag */
    if(xIrqStatus.IRQ_RX_DATA_READY)
    {
    	/* Get the RX FIFO size */
    	cRxData=SpiritLinearFifoReadNumElementsRxFifo();

    	/* Read the RX FIFO */
    	SpiritSpiReadLinearFifo(cRxData, vectcRxBuff);

    	/* Flush the RX FIFO */
    	SpiritCmdStrobeFlushRxFifo();

      /*  A simple way to control if the received data sequence is correct (in this case LED2 will toggle) */
      {
        SpiritBool correct=S_TRUE;

        for(uint8_t i=0 ; i<cRxData ; i++)
          if(vectcRxBuff[i] != i+1)
            correct=S_FALSE;

        if(correct)
          SdkEvalLedToggle(LED2);
      }
#ifdef USE_VCOM
      /* print the received data */
      printf("B data received: [");

      for(uint8_t i=0 ; i<cRxData ; i++)
        printf("%d ", vectcRxBuff[i]);
      printf("]\r\n");

#endif
    }
    
    /* Clear the EXTI line flag */
    EXTI_ClearITPendingBit(M2S_GPIO_3_EXTI_LINE);
  }

}
/**
* @brief  System main function.
* @param  None
* @retval None
*/
void main (void)
{
 SDK_SYSTEM_CONFIG();
  
#ifdef USE_VCOM
#ifdef STM8L
  SdkEvalComInit(115200,USART_WordLength_8b,USART_StopBits_1,USART_Parity_No,(USART_Mode_TypeDef)(USART_Mode_Rx | USART_Mode_Tx));
#elif SDK
  /* VC config */
  SdkEvalVCInit();
  while(bDeviceState != CONFIGURED);
#endif
#endif

  /* Spirit ON */
  SpiritEnterShutdown();
  SpiritExitShutdown();
  SpiritManagementWaExtraCurrent();
  
#ifdef STM8L
  /* Manually set the XTAL_FREQUENCY */
  SpiritRadioSetXtalFrequency(XTAL_FREQUENCY);    
  /* Initialize the frequency offset variable to compensate XTAL offset */
  xRadioInit.lFrequencyBase = xRadioInit.lFrequencyBase + FREQUENCY_OFFSET;
  /* Initialize the signals to drive the range extender application board */
  RANGE_EXT_INIT(RANGE_TYPE);
#elif SDK
  SpiritManagementIdentificationRFBoard();

  /* if the board has eeprom, we can compensate the offset calling SpiritManagementGetOffset
  (if eeprom is not present this fcn will return 0) */
  xRadioInit.lFrequencyBase = xRadioInit.lFrequencyBase + SpiritManagementGetOffset();
    
  /* Initialize the signals to drive the range extender application board */
  SpiritManagementRangeExtInit();  
#endif

  /* Reset Spirit registers to default */
  SpiritCmdStrobeSres();
  
  SdkEvalM2SGpioInit(M2S_GPIO_3,M2S_MODE_EXTI_IN);

  /* Spirit IRQ config */
  SpiritGpioInit(&xGpioIRQ);
  
  /* Configure some output signals (to be probed with a scope to verify) */
  SpiritGpioInit(&xGpio1Rx);
  SpiritGpioInit(&xGpio0Sleep);
  
  /* Spirit Radio config */
  SpiritRadioInit(&xRadioInit);
  SpiritCalibrationRco(S_ENABLE);

  /* Spirit Packet config */
  SpiritPktBasicInit(&xBasicInit);
  
  /* IRQ registers blanking */
  SpiritIrqClearStatus();
  
#ifdef STM8L
  enableInterrupts();
#elif SDK
  SdkEvalM2SGpioInterruptCmd(M2S_GPIO_3,0x0A,0x0A,ENABLE);
#endif
  
  SpiritQiSetSqiThreshold(SQI_TH_0);
  SpiritQiSqiCheck(S_ENABLE);
  
  /* Spirit IRQs enable */
  SpiritIrqDeInit(&xIrqStatus);
  SpiritIrq(RX_DATA_READY,S_ENABLE);
  SpiritIrq(RX_DATA_DISC,S_ENABLE);
  
  /* Payload length config */
  SpiritPktBasicSetPayloadLength(20);
  
  /* RX timeout config */
  SET_INFINITE_RX_TIMEOUT();
  SpiritTimerSetRxTimeoutStopCondition(SQI_ABOVE_THRESHOLD);
  
  float fWuTimer;
  uint8_t cWuPrescaler,cWuCounter,cWuReloadCounter;
  
  /* Set the wake Up event every WAKEUP_TIMER ms */
  SpiritTimerSetWakeUpTimerMs(WAKEUP_TIMER);
  
  /* Get the counter and the prescaler of the WU timer */
  SpiritTimerGetWakeUpTimer(&fWuTimer,&cWuCounter,&cWuPrescaler);
  
  /*
  Compute the rephasing timer to be reloaded on sync.
  This value will be equal to: WAKE_UP_TIMER - (PREAMB_TIME + SYNC_TIME) - GUARD_TIME,
  where:
  - (PREAMB_TIME + SYNC_TIME) is the time needed to transmit preamble and sync.
  - GUARD_TIME is a security bound to make the Rx awake before the Tx.
  */
  float fReloadMs = WAKEUP_TIMER-1000.0*(float)(SpiritPktBasicGetPreambleLength()+SpiritPktBasicGetSyncLength())*8.0/DATARATE-10.0;
  
  /* In order to have not lack of accuracy it is recommended that the reload timer
  has the same prescaler of the WakeUp timer.
  So compute the counter using the WU prescaler previously computed.
  */
  cWuReloadCounter=(uint8_t)(fReloadMs*(float)SpiritTimerGetRcoFrequency()/1000/(cWuPrescaler+1))-1;
  
  /* Set the Wake up reload timer */
  SpiritTimerSetWakeUpTimerReload(cWuReloadCounter,cWuPrescaler);
  
  /* Enable the auto reload on sync */
  SpiritTimerLdcrAutoReload(S_ENABLE);
  
  /* Enable the LDCR mode */
  SpiritTimerLdcrMode(S_ENABLE);
  
  SpiritCmdStrobeFlushRxFifo();
  
  /* Set Spirit in Rx state */
  SpiritCmdStrobeRx();
  
  /* infinite loop */
  while (1) {
    
    while(!xRxDataReadyFlag);
    xRxDataReadyFlag=RESET;
      
    if(xFirstReception==RESET)
    {
      SpiritTimerSetRxTimeoutMs(80.0);
      
      xFirstReception=SET;
      SdkEvalLedToggle(LED1);
    }
    
    
    
  }
  
}
void M2S_GPIO_3_EXTI_IRQ_HANDLER(void)
#endif
{
  /* Check the flag status of EXTI line */
  if(EXTI_GetITStatus(M2S_GPIO_3_EXTI_LINE)){
    
    /* Get the IRQ status */
    SpiritIrqGetStatus(&xIrqStatus);
    
    /* Check the SPIRIT RX_DATA_DISC IRQ flag */
    if(xIrqStatus.IRQ_RX_DATA_DISC)
    {
      /* toggle LED1 */
      SdkEvalLedToggle(LED1);
      
      /* RX command - to ensure the device will be ready for the next reception */
      SpiritCmdStrobeRx();
    }
    
    /* Check the SPIRIT RX_DATA_READY IRQ flag */
    if(xIrqStatus.IRQ_RX_DATA_READY)
    {
      /* Get the RX FIFO size */
      cRxData=SpiritLinearFifoReadNumElementsRxFifo();
      
      /* Read the RX FIFO */
      SpiritSpiReadLinearFifo(cRxData, vectcRxBuff);
      
      /* Flush the RX FIFO */
      SpiritCmdStrobeFlushRxFifo();
      
      
      /*  A simple way to check if the received data sequence is correct (in this case LED5 will toggle) */
      {
        SpiritBool xCorrect=S_TRUE;
        
        for(uint8_t i=0 ; i<cRxData ; i++)
          if(vectcRxBuff[i] != i+1)
            xCorrect=S_FALSE;
        
        if(xCorrect) {
          /* toggle LED2 */
          SdkEvalLedToggle(LED2);
//#ifdef USE_VCOM
//          printf("DATA CORRECT\r\n");
//#endif
       }
    }
     /* RX command - to ensure the device will be ready for the next reception */
    SpiritCmdStrobeRx();
 
//#ifdef USE_VCOM
//      /* print the received data */
//      printf("B data received: [");
//      for(uint8_t i=0 ; i<cRxData ; i++)
//        printf("%d ", vectcRxBuff[i]);
//      printf("]\r\n");
//#endif

    }
    
    /* Clear the EXTI line flag */
    EXTI_ClearITPendingBit(M2S_GPIO_3_EXTI_LINE);
    
  }
}