// ----------------------------------------------------------------------------- //! \brief This routine initializes the transport layer and opens the port //! of the device. Note that based on project defines, either the //! UART, or SPI driver can be used. //! //! \param[in] npiCBTx - Call back function for TX complete event //! \param[in] npiCBRx - Call back function for RX event //! \param[in] npiCBMrdy - Call back function for MRDY event //! //! \return void // ----------------------------------------------------------------------------- void NPITL_initTL(npiRtosCB_t npiCBTx, npiRtosCB_t npiCBRx, npiRtosCB_t npiCBMrdy) { ICall_CSState key; key = ICall_enterCriticalSection(); taskTxCB = npiCBTx; taskRxCB = npiCBRx; #if (NPI_FLOW_CTRL == 1) taskMrdyCB = npiCBMrdy; #endif // NPI_FLOW_CTRL = 1 transportInit(npiRxBuf,npiTxBuf, NPITL_transmissionCallBack); #if (NPI_FLOW_CTRL == 1) SRDY_DISABLE(); // Initialize SRDY/MRDY. Enable int after callback registered hNpiHandshakePins = PIN_open(&npiHandshakePins, npiHandshakePinsCfg); PIN_registerIntCb(hNpiHandshakePins, NPITL_MRDYPinHwiFxn); PIN_setConfig(hNpiHandshakePins, PIN_BM_IRQ, MRDY_PIN | PIN_IRQ_BOTHEDGES); // Enable wakeup PIN_setConfig(hNpiHandshakePins, PINCC26XX_BM_WAKEUP, MRDY_PIN | PINCC26XX_WAKEUP_NEGEDGE); mrdy_state = PIN_getInputValue(MRDY_PIN); #endif // NPI_FLOW_CTRL = 1 ICall_leaveCriticalSection(key); return; }
// ----------------------------------------------------------------------------- //! \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 Initialization for the LCD Thread //! //! \return void // ----------------------------------------------------------------------------- static void LCDTask_inititializeTask(void) { LCDTask_events = 0; LCDTask_State = LCDTASK_OFF_STATE; delay_ms(4000); // Handling of buttons, relay and MPU interrupt hlGpioPin = PIN_open(&pinGpioState, lcdMotionPinsCfg); // if (hGpioPin == 0) { // //HWREGB(GPIO_BASE+GPIO_O_DOUT3_0+Board_LCD_PWR) = 1; // //HWREGB(GPIO_BASE+GPIO_O_DOUT3_0+Board_LCD_PWR) = 0; // } else { motion_state = PIN_getInputValue(Board_LCD_MOTION); PIN_registerIntCb(hlGpioPin, LCD_WakeupPinHwiFxn); // // // Enable IRQ PIN_setConfig(hlGpioPin, PIN_BM_IRQ, Board_LCD_MOTION | PIN_IRQ_BOTHEDGES); // // Enable wakeup //PIN_setConfig(hlGpioPin, PINCC26XX_BM_WAKEUP, Board_LCD_MOTION | PINCC26XX_WAKEUP_POSEDGE); // // Init SPI Bus // bspSpiOpen(); // Init LCD Variables ILI9341_init(hGpioPin); // } }
// ----------------------------------------------------------------------------- //! \brief This routine initializes the transport layer and opens the port //! of the device. Note that based on project defines, either the //! UART, or SPI driver can be used. //! //! \param[in] params - Transport Layer parameters //! //! \return void // ----------------------------------------------------------------------------- void NPITL_openTL(NPITL_Params *params) { _npiCSKey_t key; key = NPIUtil_EnterCS(); // Set NPI Task Call backs memcpy(&taskCBs, ¶ms->npiCallBacks, sizeof(params->npiCallBacks)); // Allocate memory for Transport Layer Tx/Rx buffers npiBufSize = params->npiTLBufSize; npiRxBuf = NPIUTIL_MALLOC(params->npiTLBufSize); memset(npiRxBuf, 0, npiBufSize); npiTxBuf = NPIUTIL_MALLOC(params->npiTLBufSize); memset(npiTxBuf, 0, npiBufSize); // This will be updated to be able to select SPI/UART TL at runtime // Now only compile time with the NPI_USE_[UART,SPI] flag #if defined(NPI_USE_UART) #elif defined(NPI_USE_SPI) transportOpen(params->portBoardID, ¶ms->portParams.spiParams, NPITL_transmissionCallBack); #endif //NPI_USE_UART hNpiHandshakePins = PIN_open(&npiHandshakePins, npiHandshakePinsCfg); 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 hNpiProfilingDebugPin= PIN_open(&npiProfilingDebugPin, npiProfilingDebugPinCfg); #endif //NPI_SW_HANDSHAKING_DEBUG npiTLParams = *params; //Keep a copy of TLParams local to the TL so that the UART can be closed/reopened #ifndef POWER_SAVING // This call will start repeated Uart Reads when Power Savings is disabled transportRead(); #endif NPIUtil_ExitCS(key); }
// ----------------------------------------------------------------------------- //! \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 }
// ----------------------------------------------------------------------------- //! \brief This routine initializes the transport layer and opens the port //! of the device. Note that based on project defines, either the //! UART, or SPI driver can be used. //! //! \param[in] params - Transport Layer parameters //! //! \return void // ----------------------------------------------------------------------------- void NPITL_openTL(NPITL_Params *params) { _npiCSKey_t key; key = NPIUtil_EnterCS(); // Set NPI Task Call backs memcpy(&taskCBs, ¶ms->npiCallBacks, sizeof(params->npiCallBacks)); // Allocate memory for Transport Layer Tx/Rx buffers npiBufSize = params->npiTLBufSize; npiRxBuf = NPIUTIL_MALLOC(params->npiTLBufSize); memset(npiRxBuf, 0, npiBufSize); npiTxBuf = NPIUTIL_MALLOC(params->npiTLBufSize); memset(npiTxBuf, 0, npiBufSize); 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); //Note that open TL is only called when NPI task is being initialized //transportLayerState variable defaults to closed. #ifdef SWHS_DEBUG //Open Profiling Pin if in debug mode hNpiProfilingPin = PIN_open(&npiProfilingPin, npiProfilingPinCfg); #endif //SWHS_DEBUG //Keep a copy of TLParams local to the TL so that the UART can be closed/reopened npiTLParams = *params; //Here we will initialize the transport which will setup the callbacks //This call does not open the UART transportInit( &npiTLParams.portParams.uartParams, NPITL_transmissionCallBack, NPITL_handshakeCompleteCallBack); NPIUtil_ExitCS(key); }
/********************************************************************* * @fn Board_initKeys * * @brief Enable interrupts for keys on GPIOs. * * @param appKeyCB - application key pressed callback * * @return none */ void Board_initKeys(keysPressedCB_t appKeyCB) { // Initialize KEY pins. Enable int after callback registered hKeyPins = PIN_open(&keyPins, keyPinsCfg); PIN_registerIntCb(hKeyPins, Board_keyCallback); PIN_setConfig(hKeyPins, PIN_BM_IRQ, Board_BTN1 | PIN_IRQ_NEGEDGE); PIN_setConfig(hKeyPins, PIN_BM_IRQ, Board_BTN2 | PIN_IRQ_NEGEDGE); #ifdef POWER_SAVING //Enable wakeup PIN_setConfig(hKeyPins, PINCC26XX_BM_WAKEUP, Board_BTN1 | PINCC26XX_WAKEUP_NEGEDGE); PIN_setConfig(hKeyPins, PINCC26XX_BM_WAKEUP, Board_BTN2 | PINCC26XX_WAKEUP_NEGEDGE); #endif // Setup keycallback for keys Util_constructClock(&keyChangeClock, Board_keyChangeHandler, KEY_DEBOUNCE_TIMEOUT, 0, false, 0); // Set the application callback appKeyChangeHandler = appKeyCB; }
// ----------------------------------------------------------------------------- //! \brief This routine initializes the transport layer and opens the port //! of the device. Note that based on project defines, either the //! UART, or SPI driver can be used. //! //! \param[in] params - Transport Layer parameters //! //! \return void // ----------------------------------------------------------------------------- void NPITL_openTL(NPITL_Params *params) { _npiCSKey_t key; key = NPIUtil_EnterCS(); // Set NPI Task Call backs memcpy(&taskCBs, ¶ms->npiCallBacks, sizeof(params->npiCallBacks)); // Allocate memory for Transport Layer Tx/Rx buffers npiBufSize = params->npiTLBufSize; npiRxBuf = NPIUTIL_MALLOC(params->npiTLBufSize); memset(npiRxBuf, 0, npiBufSize); npiTxBuf = NPIUTIL_MALLOC(params->npiTLBufSize); memset(npiTxBuf, 0, npiBufSize); // This will be updated to be able to select SPI/UART TL at runtime // Now only compile time with the NPI_USE_[UART,SPI] flag #if defined(NPI_USE_UART) transportOpen(params->portBoardID, ¶ms->portParams.uartParams, NPITL_transmissionCallBack); #elif defined(NPI_USE_SPI) transportOpen(params->portBoardID, ¶ms->portParams.spiParams, NPITL_transmissionCallBack); #endif //NPI_USE_UART #if (NPI_FLOW_CTRL == 1) // Assign PIN IDs to remRdy and locRrdy #ifdef NPI_MASTER remRdyPIN = (params->srdyPinID & IOC_IOID_MASK); locRdyPIN = (params->mrdyPinID & IOC_IOID_MASK); #else remRdyPIN = (params->mrdyPinID & IOC_IOID_MASK); locRdyPIN = (params->srdyPinID & IOC_IOID_MASK); #endif //NPI_MASTER // Add PIN IDs to PIN Configuration npiHandshakePinsCfg[REM_RDY_PIN_IDX] |= remRdyPIN; npiHandshakePinsCfg[LOC_RDY_PIN_IDX] |= locRdyPIN; // Initialize LOCRDY/REMRDY. Enable int after callback registered hNpiHandshakePins = PIN_open(&npiHandshakePins, npiHandshakePinsCfg); PIN_registerIntCb(hNpiHandshakePins, NPITL_remRdyPINHwiFxn); PIN_setConfig(hNpiHandshakePins, PIN_BM_IRQ, remRdyPIN | PIN_IRQ_BOTHEDGES); // Enable wakeup PIN_setConfig(hNpiHandshakePins, PINCC26XX_BM_WAKEUP, remRdyPIN | PINCC26XX_WAKEUP_NEGEDGE); remRdy_state = PIN_getInputValue(remRdyPIN); // If MRDY is already low then we must initiate a read because there was // a prior MRDY negedge that was missed if (!remRdy_state) { NPITL_setPM(); if (taskCBs.remRdyCB) { transportRemRdyEvent(); LocRDY_ENABLE(); } } #endif // NPI_FLOW_CTRL = 1 #if (NPI_FLOW_CTRL == 0) // This call will start repeated Uart Reads when Power Savings is disabled transportRead(); #endif // NPI_FLOW_CTRL = 0 NPIUtil_ExitCS(key); }