// ----------------------------------------------------------------------------- //! \brief This is a HWI function handler for the MRDY pin. Some MRDY //! functionality can execute from this HWI context. Others //! must be executed from task context hence the taskCBs.remRdyCB() //! //! \param[in] hPin - PIN Handle //! \param[in] pinId - ID of pin that triggered HWI //! //! \return void // ----------------------------------------------------------------------------- static void NPITL_remRdyPINHwiFxn(PIN_Handle hPin, PIN_Id pinId) { // The pin driver does not currently support returning whether the int // was neg or pos edge so we must use a variable to keep track of state. remRdy_state ^= 1; if (remRdy_state == 0) { mrdyPktStamp = txPktCount; NPITL_setPM(); } else { transportStopTransfer(); npiRxActive = FALSE; } // Signal to registered task that Rem Ready signal has changed state if (taskCBs.remRdyCB) { taskCBs.remRdyCB(remRdy_state); } // Check the physical state of the pin to see if it matches the variable // state. If not trigger another task call back if (remRdy_state != PIN_getInputValue(remRdyPIN)) { remRdy_state = PIN_getInputValue(remRdyPIN); if (taskCBs.remRdyCB) { taskCBs.remRdyCB(remRdy_state); } } }
// ----------------------------------------------------------------------------- //! \brief This callback is invoked on the completion of one transmission //! to/from the host MCU. Any bytes receives will be [0,Rxlen) in //! npiRxBuf. //! If bytes were receives or transmitted, this function notifies //! the NPI task via registered call backs //! //! \param[in] Rxlen - length of the data received //! \param[in] Txlen - length of the data transferred //! //! \return void // ----------------------------------------------------------------------------- static void NPITL_transmissionCallBack(uint16_t Rxlen, uint16_t Txlen) { npiRxBufHead = 0; npiRxBufTail = Rxlen; npiTxActive = FALSE; //Since the largest valid NPI packet size is 4096 //valid RxLen fields should only be up to 0x0FFF //a larger RxLen value tells the TL that a Rx is in progress //and the UART cannot be closed yet //in the above case, a CB will be triggered for the Tx, but Rx will wait //until ReadCB completes at NPITLUART layer if(!(Rxlen & 0x1000)) { //Since we have rx/tx'd a complete packet, it is time to close out the TL //and ready the processor for sleep #ifdef SWHS_DEBUG //Set Pin if in debug mode PIN_setOutputValue(hNpiProfilingPin, Board_LED2, 1); #endif //SWHS_DEBUG transportClose(); // Open the Pins for ISR hNpiUartRxPin = PIN_open(&npiUartRxPin, npiUartRxPinCfg); PIN_registerIntCb(hNpiUartRxPin, NPITL_rxPinHwiFxn); PIN_setConfig(hNpiUartRxPin, PIN_BM_IRQ, Board_UART_RX | PIN_IRQ_BOTHEDGES); // Enable wakeup PIN_setConfig(hNpiUartRxPin, PINCC26XX_BM_WAKEUP, Board_UART_RX | PINCC26XX_WAKEUP_NEGEDGE); #ifdef SWHS_DEBUG //Set Pin if in debug mode PIN_setOutputValue(hNpiProfilingPin, Board_LED2, 0); #endif //SWHS_DEBUG //It is also valid to clear all flags at this point trasnportLayerState = TL_closed; // If Task is registered, invoke transaction complete callback if (taskCBs.transCompleteCB) { taskCBs.transCompleteCB(Rxlen, Txlen); } NPITL_relPM(); } else { //be sure to indicate TL is still busy trasnportLayerState = TL_busy; // If Task is registered, invoke transaction complete callback //note that RxLen is zero because the read is incomplete if (taskCBs.transCompleteCB) { taskCBs.transCompleteCB(0, Txlen); } } }
// ----------------------------------------------------------------------------- //! \brief This function is used to trigger the RemRdy Event in the task //! from a chirp callBack //! //! \return void // ----------------------------------------------------------------------------- void NPITL_chirpRecievedCB(void) { //Call the RemRdy call back in the task if (taskCBs.remRdyCB) { taskCBs.remRdyCB(remRdy_state); } }
// ----------------------------------------------------------------------------- //! \brief This is a HWI function handler for the MRDY pin. Some MRDY //! functionality can execute from this HWI context. Others //! must be executed from task context hence the taskCBs.remRdyCB() //! //! \param[in] hPin - PIN Handle //! \param[in] pinId - ID of pin that triggered HWI //! //! \return void // ----------------------------------------------------------------------------- static void NPITL_remRdyPINHwiFxn(PIN_Handle hPin, PIN_Id pinId) { NPITL_setPM(); // Signal to registered task that Rem Ready signal has changed state if (taskCBs.remRdyCB) { taskCBs.remRdyCB(remRdy_state); } }
// ----------------------------------------------------------------------------- //! \brief This is a HWI function handler for the UART Rx pin. It will wake //! the TL and signal the app to open the TL by closing UART and //! opening the GPIO //! //! \param[in] hPin - PIN Handle //! \param[in] pinId - ID of pin that triggered HWI //! //! \return void // ----------------------------------------------------------------------------- static void NPITL_rxPinHwiFxn(PIN_Handle hPin, PIN_Id pinId) { NPITL_setPM(); // Signal to registered task that TL is awake, needs to open if (taskCBs.tlOpenCB) { taskCBs.tlOpenCB(); } }
// ----------------------------------------------------------------------------- //! \brief This routine notifies the app layer that the HS is complete //! //! \return void // ----------------------------------------------------------------------------- static void NPITL_handshakeCompleteCallBack(hsTransactionRole role) { //If we are the initiator, give the app the signal to send the message //else if not the initiator, our TL is busy because we are listening(reading) //whatever the initiator wanted to tell us if(HS_INITIATOR == role) trasnportLayerState = TL_ready; else trasnportLayerState = TL_busy; //Trigger the HS complete callback in the task if (taskCBs.handshakeCompleteCB) { taskCBs.handshakeCompleteCB(role); } }
// ----------------------------------------------------------------------------- //! \brief This callback is invoked on the completion of one transmission //! to/from the host MCU. Any bytes receives will be [0,Rxlen) in //! npiRxBuf. //! If bytes were receives or transmitted, this function notifies //! the NPI task via registered call backs //! //! \param[in] Rxlen - length of the data received //! \param[in] Txlen - length of the data transferred //! //! \return void // ----------------------------------------------------------------------------- static void NPITL_transmissionCallBack(uint16_t Rxlen, uint16_t Txlen) { npiRxBufHead = 0; npiRxBufTail = Rxlen; npiTxActive = FALSE; // If Task is registered, invoke transaction complete callback if (taskCBs.transCompleteCB) { taskCBs.transCompleteCB(Rxlen, Txlen); } #if (NPI_FLOW_CTRL == 1) NPITL_relPM(); LocRDY_DISABLE(); #endif // NPI_FLOW_CTRL = 1 }
// ----------------------------------------------------------------------------- //! \brief This callback is invoked on the completion of one transmission //! to/from the host MCU. Any bytes receives will be [0,Rxlen) in //! npiRxBuf. //! If bytes were receives or transmitted, this function notifies //! the NPI task via registered call backs //! //! \param[in] Rxlen - length of the data received //! \param[in] Txlen - length of the data transferred //! //! \return void // ----------------------------------------------------------------------------- static void NPITL_transmissionCallBack(uint16_t Rxlen, uint16_t Txlen) { npiRxBufHead = 0; npiRxBufTail = Rxlen; npiTxActive = FALSE; // If Task is registered, invoke transaction complete callback if (taskCBs.transCompleteCB) { taskCBs.transCompleteCB(Rxlen, Txlen); } #ifdef NPI_SW_HANDSHAKING_DEBUG //Set the profiling pin high PIN_setOutputValue(hNpiProfilingDebugPin, profilingDebugPin, 1); #endif //NPI_SW_HANDSHAKING_DEBUG // Close the UART transportClose(); // Open the Pins for ISR hNpiHandshakePins = PIN_open(&npiHandshakePins, npiHandshakePinsCfg); //replace remRdyPIN with Board_UART_RX PIN_registerIntCb(hNpiHandshakePins, NPITL_remRdyPINHwiFxn); PIN_setConfig(hNpiHandshakePins, PIN_BM_IRQ, Board_UART_RX | PIN_IRQ_BOTHEDGES); // Enable wakeup PIN_setConfig(hNpiHandshakePins, PINCC26XX_BM_WAKEUP, Board_UART_RX | PINCC26XX_WAKEUP_NEGEDGE); #ifdef NPI_SW_HANDSHAKING_DEBUG //Indicate that we are now asleep in the GPIO state PIN_setOutputValue(hNpiProfilingDebugPin, profilingDebugPin, 0); #endif //NPI_SW_HANDSHAKING_DEBUG //It is also valid to clear all flags at this point _npiCSKey_t key; key = NPIUtil_EnterCS(); handshakingState = HS_GPIO_STATE; NPIUtil_ExitCS(key); #ifdef POWER_SAVING NPITL_relPM(); #endif //POWER_SAVING }