/** * @brief This function handles External interrupt request (associated with Spirit GPIO 3). * @param None * @retval None */ void M2S_GPIO_3_EXTI_IRQ_HANDLER(void) { /* control the EXTI flag */ if(EXTI_GetFlagStatus(M2S_GPIO_3_EXTI_LINE)) { /* read the IRQ status bytes */ SpiritIrqGetStatus(&xIrqStatus); /* set flags according to the raised IRQ*/ if(xIrqStatus.IRQ_TX_DATA_SENT) { xTxDoneFlag = SET; SdkEvalLedToggle(LED1); } if(xIrqStatus.IRQ_RX_DATA_READY) { xRxDoneFlag = SET; SdkEvalLedToggle(LED2); } if(xIrqStatus.IRQ_RX_DATA_DISC) { SpiritCmdStrobeRx(); SdkEvalLedToggle(LED3); } /* clear the EXTI flag */ EXTI_ClearFlag(M2S_GPIO_3_EXTI_LINE); } }
/** * @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); } }
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); } }
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); } }
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 TX_DATA_SENT IRQ flag */ if(xIrqStatus.IRQ_TX_DATA_SENT) { /* Set the tx_done_flag to manage the event in the main() */ xTxDoneFlag = SET; SdkEvalLedToggle(LED1); } /* Clear the EXTI line flag */ EXTI_ClearITPendingBit(M2S_GPIO_3_EXTI_LINE); } }
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()
/*---------------------------------------------------------------------------*/ 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; }
/** * @brief This function handles the point-to-point packet reception * @param uint8_t *RxFrameBuff = Pointer to ReceiveBuffer * uint8_t cRxlen = length of ReceiveBuffer * @retval None */ void AppliReceiveBuff(uint8_t *RxFrameBuff, uint8_t cRxlen) { uint8_t xIndex = 0; uint8_t ledToggleCtr = 0; /*float rRSSIValue = 0;*/ cmdFlag = RESET; exitTime = SET; exitCounter = TIME_TO_EXIT_RX; pRadioDriver = &spirit_cb; /* Spirit IRQs enable */ pRadioDriver->DisableIrq(); pRadioDriver->EnableRxIrq(); /* payload length config */ pRadioDriver->SetPayloadLen(PAYLOAD_LEN); /* rx timeout config */ pRadioDriver->SetRxTimeout(1000); /* IRQ registers blanking */ pRadioDriver->ClearIrqStatus(); SpiritIrqGetStatus(&xIrqStatus); /* RX command */ pRadioDriver->StartRx(); uint32_t timeout = HAL_GetTick() + 5000; /* wait for data received or timeout period occured */ while((RESET == xRxDoneFlag)&&(RESET == rx_timeout)&&(RESET == spirit_error) && (HAL_GetTick () < timeout)); if(rx_timeout==SET) { HAL_UART_Transmit(&huart1, "T ", 2, 1000); rx_timeout = RESET; } else if(xRxDoneFlag) { xRxDoneFlag=RESET; pRadioDriver->GetRxPacket(RxFrameBuff,&cRxlen); int dbmValue= SpiritQiGetRssidBm(); sprintf(message, "R %d ", dbmValue); /*rRSSIValue = Spirit1GetRssiTH();*/ HAL_UART_Transmit(&huart1, message, strlen(message), 1000); xRxFrame.Cmd = RxFrameBuff[0]; xRxFrame.CmdLen = RxFrameBuff[1]; xRxFrame.Cmdtag = RxFrameBuff[2]; xRxFrame.CmdType = RxFrameBuff[3]; xRxFrame.DataLen = RxFrameBuff[4]; for (xIndex = 5; xIndex < cRxlen; xIndex++) { xRxFrame.DataBuff[xIndex] = RxFrameBuff[xIndex]; } if(xRxFrame.Cmd == LED_TOGGLE) { RadioShieldLedOn(RADIO_SHIELD_LED); HAL_Delay(DELAY_RX_LED_TOGGLE); RadioShieldLedOff(RADIO_SHIELD_LED); cmdFlag = SET; } if(xRxFrame.Cmd == ACK_OK) { for(; ledToggleCtr<5; ledToggleCtr++) { RadioShieldLedToggle(RADIO_SHIELD_LED); HAL_Delay(DELAY_RX_LED_TOGGLE); } RadioShieldLedOff(RADIO_SHIELD_LED); } } else if (spirit_error == SET) { spirit_error = RESET; } }
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); } }