// ----------------------------------------------------------------------------- //! \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] 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); } } }
static void keysTaskInit(void) { Util_constructClock(&longPressCheckClock, Keys_clockHandler, KEYS_LONG_PRESSURE_TIMEOUT, 0, false, LONG_PRESSURE_TIMEOUT_EVT); hGpioPinKeys = PIN_open(&pinGpioStateKeys, KeysPinTable); status = PIN_registerIntCb(hGpioPinKeys, Key_callback); // Register task with BLE stack ICall_Errno err = ICall_registerApp(&keysSelfEntity, &keysSem); }
// ----------------------------------------------------------------------------- //! \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; }
/******************************************************************************* * @fn SensorTag_init * * @brief Called during initialization and contains application * specific initialization (ie. hardware initialization/setup, * table initialization, power up notification, etc), and * profile initialization/setup. * * @param none * * @return none */ static void SensorTag_init(void) { //uint8_t selfTestMap; // Setup I2C for sensors //bspI2cInit(); // Handling of buttons, LED, relay hGpioPin = PIN_open(&pinGpioState, SensortagAppPinTable); PIN_registerIntCb(hGpioPin, SensorTag_callback); // *************************************************************************** // N0 STACK API CALLS CAN OCCUR BEFORE THIS CALL TO ICall_registerApp // *************************************************************************** // Register the current thread as an ICall dispatcher application // so that the application can send and receive messages. ICall_registerApp(&selfEntity, &sem); // Create an RTOS queue for message from profile to be sent to app. appMsgQueue = Util_constructQueue(&appMsg); // Create one-shot clocks for internal periodic events. Util_constructClock(&periodicClock, SensorTag_clockHandler, ST_PERIODIC_EVT_PERIOD, 0, false, ST_PERIODIC_EVT); // Setup the GAP GAP_SetParamValue(TGAP_CONN_PAUSE_PERIPHERAL, DEFAULT_CONN_PAUSE_PERIPHERAL); // Setup the GAP Peripheral Role Profile { // For all hardware platforms, device starts advertising upon initialization uint8_t initialAdvertEnable = TRUE; // By setting this to zero, the device will go into the waiting state after // being discoverable for 30.72 second, and will not being advertising again // until the enabler is set back to TRUE uint16_t advertOffTime = 0; uint8_t enableUpdateRequest = DEFAULT_ENABLE_UPDATE_REQUEST; uint16_t desiredMinInterval = DEFAULT_DESIRED_MIN_CONN_INTERVAL; uint16_t desiredMaxInterval = DEFAULT_DESIRED_MAX_CONN_INTERVAL; uint16_t desiredSlaveLatency = DEFAULT_DESIRED_SLAVE_LATENCY; uint16_t desiredConnTimeout = DEFAULT_DESIRED_CONN_TIMEOUT; // Set the GAP Role Parameters GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8_t), &initialAdvertEnable); GAPRole_SetParameter(GAPROLE_ADVERT_OFF_TIME, sizeof(uint16_t), &advertOffTime); //Returns 18, but this seems to be normal GAPRole_SetParameter(GAPROLE_SCAN_RSP_DATA, sizeof(scanRspData), scanRspData); //Returns 18 GAPRole_SetParameter(GAPROLE_ADVERT_DATA, sizeof(advertData), advertData); GAPRole_SetParameter(GAPROLE_PARAM_UPDATE_ENABLE, sizeof(uint8_t), &enableUpdateRequest); GAPRole_SetParameter(GAPROLE_MIN_CONN_INTERVAL, sizeof(uint16_t), &desiredMinInterval); GAPRole_SetParameter(GAPROLE_MAX_CONN_INTERVAL, sizeof(uint16_t), &desiredMaxInterval); GAPRole_SetParameter(GAPROLE_SLAVE_LATENCY, sizeof(uint16_t), &desiredSlaveLatency); GAPRole_SetParameter(GAPROLE_TIMEOUT_MULTIPLIER, sizeof(uint16_t), &desiredConnTimeout); } // Set the GAP Characteristics GGS_SetParameter(GGS_DEVICE_NAME_ATT, GAP_DEVICE_NAME_LEN, (void*)attDeviceName); #ifdef FEATURE_OAD // Register connection parameter update GAPRole_RegisterAppCBs( ¶mUpdateCB); #endif // Set advertising interval { uint16_t advInt = DEFAULT_ADVERTISING_INTERVAL; GAP_SetParamValue(TGAP_LIM_DISC_ADV_INT_MIN, advInt); GAP_SetParamValue(TGAP_LIM_DISC_ADV_INT_MAX, advInt); GAP_SetParamValue(TGAP_GEN_DISC_ADV_INT_MIN, advInt); GAP_SetParamValue(TGAP_GEN_DISC_ADV_INT_MAX, advInt); } // Initialize GATT attributes GGS_AddService(GATT_ALL_SERVICES); // GAP GATTServApp_AddService(GATT_ALL_SERVICES); // GATT attributes DevInfo_AddService(); // Device Information Service // Add application specific device information SensorTag_setDeviceInfo(); #ifdef FACTORY_IMAGE // Check if a factory image exists and apply current image if necessary //if (!SensorTag_hasFactoryImage()) //{ // SensorTag_saveFactoryImage(); //} #endif #ifdef FEATURE_REGISTER_SERVICE //Register_addService(); // Generic register access // #endif #ifdef FEATURE_LCD SensorTagDisplay_init(); // Display service DevPack LCD #endif #ifdef FEATURE_OAD SensorTagConnectionControl_init(); // Connection control to // support OAD for iOs/Android OAD_addService(); // OAD Profile OAD_register((oadTargetCBs_t *)&simpleBLEPeripheral_oadCBs); hOadQ = Util_constructQueue(&oadQ); #endif // Start the Device GAPRole_StartDevice(&SensorTag_gapRoleCBs); // Start Bond Manager GAPBondMgr_Register(NULL); // Enable interrupt handling for keys and relay PIN_registerIntCb(hGpioPin, SensorTag_callback); }
/*! * @brief Function to initialize the CC26XX SPI peripheral specified by the * particular handle. The parameter specifies which mode the SPI * will operate. * * The function will set a dependency on it power domain, i.e. power up the * module and enable the clock. The IOs are allocated. Neither the SPI nor UDMA module * will be enabled. * * @pre SPI controller has been initialized. * Calling context: Task * * @param handle A SPI_Handle * * @param params Pointer to a parameter block, if NULL it will use * default values * * @return A SPI_Handle on success or a NULL on an error or if it has been * already opened * * @sa SPICC26XXDMA_close() */ SPI_Handle SPICC26XXDMA_open(SPI_Handle handle, SPI_Params *params) { /* Use union to save on stack allocation */ union { Semaphore_Params semParams; Hwi_Params hwiParams; } paramsUnion; SPI_Params defaultParams; SPICC26XX_Object *object; SPICC26XX_HWAttrs const *hwAttrs; unsigned int key; /* Get the pointer to the object and hwAttrs */ object = handle->object; hwAttrs = handle->hwAttrs; /* Disable preemption while checking if the SPI is open. */ key = Hwi_disable(); /* Check if the SPI is open already with the base addr. */ if (object->isOpen == true) { Hwi_restore(key); Log_warning1("SPI:(%p) already in use.", hwAttrs->baseAddr); return (NULL); } /* Mark the handle as being used */ object->isOpen = true; Hwi_restore(key); /* If params are NULL use defaults */ if (params == NULL) { /* No params passed in, so use the defaults */ SPI_Params_init(&defaultParams); params = &defaultParams; } Assert_isTrue((params->dataSize >= 4) && (params->dataSize <= 16), NULL); /* Initialize the SPI object */ object->currentTransaction = NULL; object->bitRate = params->bitRate; object->dataSize = params->dataSize; object->frameFormat = params->frameFormat; object->mode = params->mode; object->transferMode = params->transferMode; object->transferTimeout = params->transferTimeout; object->returnPartial = false; #ifdef SPICC26XXDMA_WAKEUP_ENABLED object->wakeupCallbackFxn = NULL; #endif /* Determine if we need to use an 8-bit or 16-bit framesize for the DMA */ object->frameSize = (params->dataSize < 9) ? SPICC26XXDMA_8bit : SPICC26XXDMA_16bit; Log_print2(Diags_USER2,"SPI:(%p) DMA buffer incrementation size: %s", hwAttrs->baseAddr, (object->frameSize) ? (UArg)"16-bit" : (UArg)"8-bit"); /* Register power dependency - i.e. power up and enable clock for SPI. */ Power_setDependency(hwAttrs->powerMngrId); /* Configure the hardware module */ SPICC26XXDMA_initHw(handle); /* CSN is initialized using hwAttrs initially, but can be re-configured later */ object->csnPin = hwAttrs->csnPin; /* Configure IOs after hardware has been initialized so that IOs aren't */ /* toggled unnecessary and make sure it was successful */ if (!SPICC26XXDMA_initIO(handle)) { /* Trying to use SPI driver when some other driver or application * has already allocated these pins, error! */ Log_warning0("Could not allocate SPI pins, already in use."); /* Release power dependency - i.e. potentially power down serial domain. */ Power_releaseDependency(hwAttrs->powerMngrId); /* Mark the module as available */ key = Hwi_disable(); object->isOpen = false; Hwi_restore(key); /* Signal back to application that SPI driver was not succesfully opened */ return (NULL); } /* Create the Hwi for this SPI peripheral. */ Hwi_Params_init(¶msUnion.hwiParams); paramsUnion.hwiParams.arg = (UArg) handle; Hwi_construct(&(object->hwi), (int) hwAttrs->intNum, SPICC26XXDMA_hwiFxn, ¶msUnion.hwiParams, NULL); /* Check the transfer mode */ if (object->transferMode == SPI_MODE_BLOCKING) { Log_print1(Diags_USER2, "SPI DMA:(%p) in SPI_MODE_BLOCKING mode", hwAttrs->baseAddr); /* Create a semaphore to block task execution for the duration of the * SPI transfer */ Semaphore_Params_init(¶msUnion.semParams); paramsUnion.semParams.mode = Semaphore_Mode_BINARY; Semaphore_construct(&(object->transferComplete), 0, ¶msUnion.semParams); /* Store internal callback function */ object->transferCallbackFxn = SPICC26XXDMA_transferCallback; } else { Log_print1(Diags_USER2, "SPI DMA:(%p) in SPI_MODE_CALLBACK mode", hwAttrs->baseAddr); /* Check to see if a callback function was defined for async mode */ Assert_isTrue(params->transferCallbackFxn != NULL, NULL); /* Save the callback function pointer */ object->transferCallbackFxn = params->transferCallbackFxn; } /* Declare the dependency on the UDMA driver */ object->udmaHandle = UDMACC26XX_open(); /* Configure PIN driver for CSN callback in optional RETURN_PARTIAL slave mode */ /* and/or optional wake up on CSN assert slave mode */ if (object->mode == SPI_SLAVE) { PIN_registerIntCb(object->pinHandle, SPICC26XXDMA_csnCallback); PIN_setUserArg(object->pinHandle, (UArg) handle); } Log_print1(Diags_USER1, "SPI:(%p) opened", hwAttrs->baseAddr); /* Register notification functions */ #ifdef SPICC26XXDMA_WAKEUP_ENABLED Power_registerNotify(&object->spiPreObj, Power_ENTERING_STANDBY, (Fxn)spiPreNotify, (UInt32)handle, NULL ); #endif Power_registerNotify(&object->spiPostObj, Power_AWAKE_STANDBY, (Fxn)spiPostNotify, (UInt32)handle, NULL ); return (handle); }
// ----------------------------------------------------------------------------- //! \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); }