Пример #1
0
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);
    
  }
}
Пример #2
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();
}
void M2S_GPIO_3_EXTI_IRQ_HANDLER(void)
#endif
{
  /* Check the flag status of EXTI line */
  if(EXTI_GetITStatus(M2S_GPIO_3_EXTI_LINE))
  {
    SpiritIrqGetStatus(&xIrqStatus);

    /* Check the SPIRIT TX_DATA_SENT IRQ flag */
    if(xIrqStatus.IRQ_TX_DATA_SENT || xIrqStatus.IRQ_MAX_RE_TX_REACH)
    {
      /* set the tx_done_flag to manage the event in the main() */
      xTxDoneFlag = SET;

      if(xIrqStatus.IRQ_TX_DATA_SENT)
        SdkEvalLedToggle(LED1);

      if(xIrqStatus.IRQ_MAX_RE_TX_REACH)
        SdkEvalLedToggle(LED2);
      
#ifdef USE_VCOM
      printf("N.Elem.TX.FIFO: %d\n\r", SpiritLinearFifoReadNumElementsTxFifo());
      printf("SEQ.NUM.: %d\n\r", SpiritPktCommonGetTransmittedSeqNumber());
      printf("NRETX: %d\n\n\r", SpiritPktStackGetNReTx());
#endif
      
#ifdef PIGGYBACKING
      /* Get the RX FIFO size */
      cRxData=SpiritLinearFifoReadNumElementsRxFifo();

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

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

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

}
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_READY IRQ flag */
    if(xIrqStatus.IRQ_RX_DATA_READY)
    {
      /* Get the RX FIFO size */
      cRxData = SpiritLinearFifoReadNumElementsRxFifo();
      
      /* Read the RX FIFO */
      SpiritSpiReadLinearFifo(cRxData, vectcRxBuff);
      
#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
      /* Set the rx data ready flag */
      xRxDataReadyFlag=SET;
      
      SdkEvalLedToggle(LED2);
    }
    if(xIrqStatus.IRQ_RX_DATA_DISC)
    {
      printf("B data discarded\n\r");
      SdkEvalLedToggle(LED3);
    }
    
    /* Clear the EXTI line flag */
    EXTI_ClearITPendingBit(M2S_GPIO_3_EXTI_LINE);
  }
}
Пример #5
0
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()
Пример #6
0
/*---------------------------------------------------------------------------*/
void
spirit1_interrupt_callback(void)
{
#define INTPRINTF // PRINTF
  SpiritIrqs xIrqStatus;

  if (SpiritSPIBusy() || interrupt_callback_in_progress) {
    process_poll(&spirit_radio_process);
    interrupt_callback_wants_poll = 1;
    return;
  }
  interrupt_callback_wants_poll = 0;
  interrupt_callback_in_progress = 1;

  /* get interrupt source from radio */
  SpiritIrqGetStatus(&xIrqStatus);
  SpiritIrqClearStatus();

  if(xIrqStatus.IRQ_RX_FIFO_ERROR) {
    receiving_packet = 0;
    interrupt_callback_in_progress = 0;
    spirit1_strobe(SPIRIT1_STROBE_FRX);
    return;
  }
  if(xIrqStatus.IRQ_TX_FIFO_ERROR) {
    receiving_packet = 0;
    interrupt_callback_in_progress = 0;
    spirit1_strobe(SPIRIT1_STROBE_FTX);
    return;
  }

  /* The IRQ_VALID_SYNC is used to notify a new packet is coming */
  if(xIrqStatus.IRQ_VALID_SYNC) {
    INTPRINTF("SYNC\n");
    receiving_packet = 1;
  }

  /* The IRQ_TX_DATA_SENT notifies the packet received. Puts the SPIRIT1 in RX */
  if(xIrqStatus.IRQ_TX_DATA_SENT) {
    spirit1_strobe(SPIRIT1_STROBE_RX);
/*    SpiritCmdStrobeRx();*/
    INTPRINTF("SENT\n");
    CLEAR_TXBUF();
    interrupt_callback_in_progress = 0;
    return;
  }

  /* The IRQ_RX_DATA_READY notifies a new packet arrived */
  if(xIrqStatus.IRQ_RX_DATA_READY) {
    SpiritSpiReadLinearFifo(SpiritLinearFifoReadNumElementsRxFifo(), &spirit_rxbuf[1]);
    spirit_rxbuf[0] = SpiritPktBasicGetReceivedPktLength();
    spirit1_strobe(SPIRIT1_STROBE_FRX);

    INTPRINTF("RECEIVED\n");

   	process_poll(&spirit_radio_process);

    receiving_packet = 0;
    
#if NULLRDC_CONF_802154_AUTOACK
    if (spirit_rxbuf[0] == ACK_LEN) {
      /* For debugging purposes we assume this is an ack for us */
      just_got_an_ack = 1;
    }
#endif /* NULLRDC_CONF_802154_AUTOACK */

    interrupt_callback_in_progress = 0;
    return;
  }
  
  if(xIrqStatus.IRQ_RX_DATA_DISC) {
    spirit1_strobe(SPIRIT1_STROBE_FRX);
    CLEAR_RXBUF();
    INTPRINTF("DISC\n");
    receiving_packet = 0;
  }

  interrupt_callback_in_progress = 0;
}
Пример #7
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);
  }

}
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);
    
  }
}