/* * ======== main ======== */ int main(void) { PIN_Handle ledPinHandle; /* Call board init functions */ Board_initGeneral(); Board_initUART(); /* Open LED pins */ ledPinHandle = PIN_open(&ledPinState, ledPinTable); if(!ledPinHandle) { System_abort("Error initializing board LED pins\n"); } PIN_setOutputValue(ledPinHandle, Board_LED1, 1); /* This example has logging and many other debug capabilities enabled */ System_printf("This example does not attempt to minimize code or data " "footprint\n"); System_flush(); System_printf("Starting the UART Echo example\nSystem provider is set to " "SysMin. Halt the target to view any SysMin contents in " "ROV.\n"); /* SysMin will only print to the console when you call flush or exit */ System_flush(); /* Start BIOS */ BIOS_start(); return (0); }
// ----------------------------------------------------------------------------- //! \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; }
int main(void) { Task_Params taskParams; /* Call board init functions */ Board_initGeneral(); memoryInit(spiHandle, 6250); // Board_initWatchdog(); /* Construct heartBeat Task thread */ Task_Params_init(&taskParams); taskParams.arg0 = 1000000 / Clock_tickPeriod; taskParams.stackSize = TASKSTACKSIZE; taskParams.stack = &task0Stack; Task_construct(&task0Struct, (Task_FuncPtr)heartBeatFxn, &taskParams, NULL); /* Open LED pins */ ledPinHandle = PIN_open(&ledPinState, ledPinTable); if(!ledPinHandle) { System_abort("Error initializing board LED pins\n"); } //IOCPortConfigureSet(PIN_SPI_MOSI, PORTID, PIN-CONFIG); // oklart om och hur denna funkar. //IOCPortConfigureSet(DIOn, PORTID, PIN-CONFIG); //PIN_setOutputValue(ledPinHandle, Board_LED1, 1); /* Start BIOS */ BIOS_start(); return (0); }
/******************************************************************************* * @fn bspSpiClose * * @brief Close the RTOS SPI driver * * @return none */ void bspSpiClose(void) { nUsers--; if (nUsers > 0) { // Don't close the driver if still in use return; } if (spiHandle != NULL) { // Close the RTOS driver SPI_close(spiHandle); spiHandle = NULL; } if (hSpiPin == NULL) { // Configure SPI lines as IO and set them according to BoardSpiInitTable hSpiPin = PIN_open(&pinState, BoardSpiInitTable); } nUsers = 0; }
// ----------------------------------------------------------------------------- //! \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; //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 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); }
void led_init(void){ /* Open LED pins */ ledPinHandle = PIN_open(&ledPinState, ledPinTable); if(!ledPinHandle) { System_abort("Error initializing board LED pins\n"); } PIN_setOutputValue(ledPinHandle, Board_LED1, 0); PIN_setOutputValue(ledPinHandle, Board_LED2, 1); }
/** * @fn SBL_resetTarget * * @brief Forces target device to boot from flash image instead of SBL. This * function can be called before SBL_open() or after SBL_open() * * @param rstPinID - Board Pin ID of reset PIN * @param blPinID - Board Pin ID of boot loader PIN * * @return uint8_t - SBL_SUCCESS, SBL_FAILURE */ uint8_t SBL_resetTarget(uint32_t rstPinID, uint32_t blPinID) { uint8_t openedPins = 0; if (hsblPins == NULL) { // Must open pins if SBL_open() has not yet been called openedPins = 1; // Assign PIN IDs to reset and bl rstPIN = (rstPinID & IOC_IOID_MASK); blPIN = (blPinID & IOC_IOID_MASK); // Add PIN IDs to PIN Configuration sblPinsCfg[RST_PIN_IDX] |= rstPIN; sblPinsCfg[BL_PIN_IDX] |= blPIN; // Initialize SBL Pins hsblPins = PIN_open(&sblPins, sblPinsCfg); if (hsblPins == NULL) { return SBL_FAILURE; } } // Guarantee that Boot Loader Pin is high during reset toggle PIN_setOutputValue(hsblPins, blPIN, 1); // Set reset PIN low PIN_setOutputValue(hsblPins, rstPIN, 0); SBL_utilDelay(15); // Release Reset PIN PIN_setOutputValue(hsblPins, rstPIN, 1); // Must close Pins if opened in function if (openedPins) { // Clear SBL PIN IDs rstPIN = (IOID_UNUSED & IOC_IOID_MASK); // Set to 0x000000FF blPIN = (IOID_UNUSED & IOC_IOID_MASK); // Set to 0x000000FF // Clear PIN IDs from PIN Configuration sblPinsCfg[RST_PIN_IDX] &= ~rstPIN; sblPinsCfg[BL_PIN_IDX] &= ~blPIN; // Close PIN Handle PIN_close(hsblPins); hsblPins = NULL; } return SBL_SUCCESS; }
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); }
/******************************************************************************* * @fn Main * * @brief Application Main * * input parameters * * @param None. * * output parameters * * @param None. * * @return None. */ int main() { /* Register Application callback to trap asserts raised in the Stack */ RegisterAssertCback(AssertHandler); PIN_init(BoardGpioInitTable); #ifdef CC1350_LAUNCHXL // Enable 2.4GHz Radio radCtrlHandle = PIN_open(&radCtrlState, radCtrlCfg); #ifdef POWER_SAVING Power_registerNotify(&rFSwitchPowerNotifyObj, PowerCC26XX_ENTERING_STANDBY | PowerCC26XX_AWAKE_STANDBY, (Power_NotifyFxn) rFSwitchNotifyCb, NULL); #endif //POWER_SAVING #endif //CC1350_LAUNCHXL // Enable iCache prefetching VIMSConfigure(VIMS_BASE, TRUE, TRUE); // Enable cache VIMSModeSet(VIMS_BASE, VIMS_MODE_ENABLED); #ifndef POWER_SAVING /* Set constraints for Standby, powerdown and idle mode */ Power_setConstraint(PowerCC26XX_SB_DISALLOW); Power_setConstraint(PowerCC26XX_IDLE_PD_DISALLOW); #endif // POWER_SAVING /* Initialize ICall module */ ICall_init(); /* Start tasks of external images */ ICall_createRemoteTasks(); /* Kick off application */ HostTestApp_createTask(); /* Kick off NPI */ NPITask_createTask(ICALL_SERVICE_CLASS_BLE); /* enable interrupts and start SYS/BIOS */ BIOS_start(); return 0; }
/******************************************************************************* * @fn Main * * @brief Application Main * * input parameters * * @param None. * * output parameters * * @param None. * * @return None. */ int main() { /* Register Application callback to trap asserts raised in the Stack */ RegisterAssertCback(AssertHandler); PIN_init(BoardGpioInitTable); #ifdef CC1350_LAUNCHXL // Enable 2.4GHz Radio radCtrlHandle = PIN_open(&radCtrlState, radCtrlCfg); #ifdef POWER_SAVING Power_registerNotify(&rFSwitchPowerNotifyObj, PowerCC26XX_ENTERING_STANDBY | PowerCC26XX_AWAKE_STANDBY, (Power_NotifyFxn) rFSwitchNotifyCb, NULL); #endif //POWER_SAVING #endif //CC1350_LAUNCHXL #ifndef POWER_SAVING /* Set constraints for Standby, powerdown and idle mode */ Power_setConstraint(PowerCC26XX_SB_DISALLOW); Power_setConstraint(PowerCC26XX_IDLE_PD_DISALLOW); #endif // POWER_SAVING /* Initialize ICall module */ ICall_init(); /* Start tasks of external images - Priority 5 */ ICall_createRemoteTasks(); /* Kick off profile - Priority 3 */ GAPCentralRole_createTask(); /* SDI UART Example Task - Priority 2 */ SDITask_createTask(); /* Kick off application - Priority 1 */ SPPBLEClient_createTask(); /* enable interrupts and start SYS/BIOS */ BIOS_start(); return 0; }
// ----------------------------------------------------------------------------- //! \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 }
/** * @fn SBL_open * * @brief Opens the SBL port for writing images * * @param params - SBL parameters to initialize the port with * * @return uint8_t - SBL_SUCCESS, SBL_FAILURE */ uint8_t SBL_open(SBL_Params *params) { // Assign PIN IDs to reset and bl rstPIN = (params->resetPinID & IOC_IOID_MASK); blPIN = (params->blPinID & IOC_IOID_MASK); // Add PIN IDs to PIN Configuration sblPinsCfg[RST_PIN_IDX] |= rstPIN; sblPinsCfg[BL_PIN_IDX] |= blPIN; // Initialize SBL Pins hsblPins = PIN_open(&sblPins, sblPinsCfg); if (hsblPins == NULL) { return SBL_FAILURE; } // Open SBL Transport Layer return SBL_TL_open(params->targetInterface, params->localInterfaceID); }
/********************************************************************* * @fn Board_openLCD * * @brief Open LCD peripheral on SRF06EB. * * @param none * * @return void */ void Board_openLCD(void) { #ifdef TI_DRIVERS_LCD_INCLUDED //Enable the 3V3 domain for the LCD hLCDPins = PIN_open(&LCDPinState, LCDPinTable); LCD_Params lcdParams; LCD_Params_init(&lcdParams); // Open LCD peripheral lcdHandle = LCD_open(&lcdBuffers[0], 1, &lcdParams); if ( lcdHandle ) { LCD_bufferClear(lcdHandle, 0); LCD_update(lcdHandle, 0); } #endif }
/********************************************************************* * @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; }
/* * ======== I2CCC26XX_initIO ======== * This functions initializes the I2C IOs. * * @pre Function assumes that the I2C handle is pointing to a hardware * module which has already been opened. */ static int I2CCC26XX_initIO(I2C_Handle handle, void *pinCfg) { I2CCC26XX_HWAttrs const *hwAttrs; I2CCC26XX_I2CPinCfg i2cPins; PIN_Config i2cPinTable[3]; uint32_t i=0; /* Get the pointer to the object and hwAttrs */ hwAttrs = handle->hwAttrs; /* If the pinCfg pointer is NULL, use hwAttrs pins */ if (pinCfg == NULL) { i2cPins.pinSDA = hwAttrs->sdaPin; i2cPins.pinSCL = hwAttrs->sclPin; } else { i2cPins.pinSDA = ((I2CCC26XX_I2CPinCfg *)pinCfg)->pinSDA; i2cPins.pinSCL = ((I2CCC26XX_I2CPinCfg *)pinCfg)->pinSCL; } /* Handle error */ if(i2cPins.pinSDA == PIN_UNASSIGNED || i2cPins.pinSCL == PIN_UNASSIGNED) { return I2C_STATUS_ERROR; } /* Configure I2C pins SDA and SCL*/ i2cPinTable[i++] = i2cPins.pinSDA | PIN_INPUT_EN | PIN_PULLUP | PIN_OPENDRAIN; i2cPinTable[i++] = i2cPins.pinSCL | PIN_INPUT_EN | PIN_PULLUP | PIN_OPENDRAIN; i2cPinTable[i++] = PIN_TERMINATE; /* Allocate pins*/ hPin = PIN_open(&pinState, i2cPinTable); if (!hPin) { return I2C_STATUS_ERROR; } /* Set IO muxing for the UART pins */ PINCC26XX_setMux(hPin, i2cPins.pinSDA, IOC_PORT_MCU_I2C_MSSDA); PINCC26XX_setMux(hPin, i2cPins.pinSCL, IOC_PORT_MCU_I2C_MSSCL); return I2C_STATUS_SUCCESS; }
/******************************************************************************* * @fn devpkLcdOpen * * @brief Initialize the LCD * * @descr Initializes the pins used by the LCD, creates resource access * protection semaphore, turns on the LCD device, initializes the * frame buffer, initializes to white background/dark foreground, * and finally clears the display. * * @return true if success */ bool devpkLcdOpen(void) { hLcdPin = PIN_open(&pinState, BoardDevpackLCDPinTable); if (hLcdPin != 0) { display.bg = ClrBlack; display.fg = ClrWhite; // Open the SPI driver bspSpiOpen(); // Exclusive access Semaphore_Params_init(&semParamsLCD); semParamsLCD.mode = Semaphore_Mode_BINARY; Semaphore_construct(&semLCD, 1, &semParamsLCD); hSemLCD = Semaphore_handle(&semLCD); // Turn on the display PIN_setOutputValue(hLcdPin,Board_DEVPK_LCD_DISP,1); // Graphics library init GrContextInit(&g_sContext, &g_sharp96x96LCD); // Graphics properties GrContextForegroundSet(&g_sContext, display.fg); GrContextBackgroundSet(&g_sContext, display.bg); GrContextFontSet(&g_sContext, &g_sFontFixed6x8); // Clear display GrClearDisplay(&g_sContext); GrFlush(&g_sContext); } return hLcdPin != 0; }
void Adc_init() { // Set up pins pinHandle = PIN_open(&pinState, alsPins); }
/******************************************************************************* * @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 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); }
//taskFxn void taskFxn(UArg a0, UArg a1) { Hwi_Params hwiParams; Hwi_Params_init(&hwiParams); hwiParams.enableInt = true; Hwi_construct(&hwi, INT_AUX_ADC, adcIsr, &hwiParams, NULL); UART_Params uParams; // Initialize default values UART_Params_init(&uParams); // Configure custom data, don't care about read params as not used // 115.2kBaud, Text, blocking mode uHandle = UART_open(Board_UART,&uParams); // Set up pins pinHandle = PIN_open(&pinState, alsPins); // Enable clock for ADC digital and analog interface (not currently enabled in driver) AUXWUCClockEnable(AUX_WUC_MODCLKEN0_SOC_M|AUX_WUC_MODCLKEN0_AUX_ADI4_M); // Connect AUX IO7 (DIO23) as analog input. Light sensor on SmartRF06EB AUXADCSelectInput(ADC_COMPB_IN_AUXIO7); // Set up ADC AUXADCEnableSync(AUXADC_REF_FIXED, AUXADC_SAMPLE_TIME_2P7_US, AUXADC_TRIGGER_MANUAL); // Disallow STANDBY mode while using the ADC. Power_setConstraint(Power_SB_DISALLOW); while(1) { //Sleep 100ms in IDLE mode //Task_sleep(100 * 1000 / Clock_tickPeriod); // Trigger ADC sampling AUXADCGenManualTrigger(); // Wait in IDLE until done Semaphore_pend(hSem, BIOS_WAIT_FOREVER ); //System_printf("ADC: %d\r\n", singleSample); //printf ("ADC: %d\r\n"); //printf ("ADC\r\n"); } /* // Disable ADC AUXADCDisable(); // Allow STANDBY mode again Power_releaseConstraint(Power_SB_DISALLOW); // Restore pins to values in BoardGpioTable PIN_close(pinHandle); // Log data through UART UART_write(uHandle, &adcSamples[1], SAMPLESIZE); // Goto STANDBY forever Task_sleep(BIOS_WAIT_FOREVER); */ }
/* * ======== SPICC26XXDMA_hwInit ======== * This functions initializes the SPI IOs. * * @pre Function assumes that the SPI handle is pointing to a hardware * module which has already been opened. */ static bool SPICC26XXDMA_initIO(SPI_Handle handle) { SPICC26XX_Object *object; SPICC26XX_HWAttrs const *hwAttrs; PIN_Config spiPinTable[5]; uint32_t i = 0; /* Get the pointer to the object and hwAttrs */ object = handle->object; hwAttrs = handle->hwAttrs; /* Configure IOs */ /* Build local list of pins, allocate through PIN driver and map HW ports */ if (object->mode == SPI_SLAVE) { /* Configure IOs for slave mode */ spiPinTable[i++] = hwAttrs->mosiPin | PIN_INPUT_EN; spiPinTable[i++] = hwAttrs->misoPin | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_INPUT_DIS | PIN_DRVSTR_MED; spiPinTable[i++] = hwAttrs->clkPin | PIN_INPUT_EN; spiPinTable[i++] = object->csnPin | PIN_INPUT_EN | PIN_PULLUP; } else { /* Configure IOs for master mode */ spiPinTable[i++] = hwAttrs->mosiPin | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_INPUT_DIS | PIN_DRVSTR_MED; spiPinTable[i++] = hwAttrs->misoPin | PIN_INPUT_EN | PIN_PULLDOWN; /* Output low signal on SCLK until SPI module drives signal if clock polarity is configured to '0' */ /* Output high signal on SCLK until SPI module drives signal if clock polarity is configured to '1' */ if (object->frameFormat == SPI_POL0_PHA0 || object->frameFormat == SPI_POL0_PHA1) { spiPinTable[i++] = hwAttrs->clkPin | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_INPUT_DIS | PIN_DRVSTR_MED; } else { spiPinTable[i++] = hwAttrs->clkPin | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_INPUT_DIS | PIN_DRVSTR_MED; } /* If CSN isn't SW controlled, drive it high until SPI module drives signal to avoid glitches */ if(object->csnPin != PIN_UNASSIGNED) { spiPinTable[i++] = object->csnPin | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_INPUT_DIS | PIN_DRVSTR_MED; } } spiPinTable[i++] = PIN_TERMINATE; /* Open and assign pins through pin driver */ if (!(object->pinHandle = PIN_open(&(object->pinState), spiPinTable))) { return false; } /* Set IO muxing for the SPI pins */ if (mode[object->mode] == SSI_MODE_SLAVE) { /* Configure IOs for slave mode */ PINCC26XX_setMux(object->pinHandle, hwAttrs->mosiPin, (hwAttrs->baseAddr == SSI0_BASE ? IOC_PORT_MCU_SSI0_RX : IOC_PORT_MCU_SSI1_RX)); PINCC26XX_setMux(object->pinHandle, hwAttrs->misoPin, (hwAttrs->baseAddr == SSI0_BASE ? IOC_PORT_MCU_SSI0_TX : IOC_PORT_MCU_SSI1_TX)); PINCC26XX_setMux(object->pinHandle, hwAttrs->clkPin, (hwAttrs->baseAddr == SSI0_BASE ? IOC_PORT_MCU_SSI0_CLK : IOC_PORT_MCU_SSI1_CLK)); PINCC26XX_setMux(object->pinHandle, object->csnPin, (hwAttrs->baseAddr == SSI0_BASE ? IOC_PORT_MCU_SSI0_FSS : IOC_PORT_MCU_SSI1_FSS)); } else { /* Configure IOs for master mode */ PINCC26XX_setMux(object->pinHandle, hwAttrs->mosiPin, (hwAttrs->baseAddr == SSI0_BASE ? IOC_PORT_MCU_SSI0_TX : IOC_PORT_MCU_SSI1_TX)); PINCC26XX_setMux(object->pinHandle, hwAttrs->misoPin, (hwAttrs->baseAddr == SSI0_BASE ? IOC_PORT_MCU_SSI0_RX : IOC_PORT_MCU_SSI1_RX)); PINCC26XX_setMux(object->pinHandle, hwAttrs->clkPin, (hwAttrs->baseAddr == SSI0_BASE ? IOC_PORT_MCU_SSI0_CLK : IOC_PORT_MCU_SSI1_CLK)); if(object->csnPin != PIN_UNASSIGNED) { PINCC26XX_setMux(object->pinHandle, object->csnPin, (hwAttrs->baseAddr == SSI0_BASE ? IOC_PORT_MCU_SSI0_FSS : IOC_PORT_MCU_SSI1_FSS)); } } return true; }