/******************************************************************************* * @fn SensorTag_applyFactoryImage * * @brief Load the factory image from external flash and reboot * * @return none */ void SensorTag_applyFactoryImage(void) { if (SensorTag_hasFactoryImage()) { // Load and launch factory image; page 31 must be omitted ((void (*)(uint32_t, uint32_t, uint32_t))BL_OFFSET)(EFL_ADDR_RECOVERY, EFL_SIZE_RECOVERY-0x1000, 0); } }
/******************************************************************************* * @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); // Create periodic clocks for internal periodic events Util_constructClock(&UserDefined_periodicClock, SensorTag_clockHandler, ST_USER_DEFINED_PERIODIC_EVT_PERIOD, ST_USER_DEFINED_PERIODIC_EVT_PERIOD, false, ST_USER_DEFINED_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); GAPRole_SetParameter(GAPROLE_SCAN_RSP_DATA, sizeof(scanRspData), scanRspData); 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(); // Power on self-test for sensors, flash and DevPack selfTestMap = sensorTestExecute(ST_TEST_MAP); if (selfTestMap == ST_TEST_MAP) { SensorTag_blinkLed(Board_LED2,TEST_INDICATION_BLINKS); } else { SensorTag_blinkLed(Board_LED1,TEST_INDICATION_BLINKS); } #ifdef FACTORY_IMAGE // Check if a factory image exists and apply current image if necessary if (!SensorTag_hasFactoryImage()) { SensorTag_saveFactoryImage(); } #endif // Initialize sensors who don't have their own tasks SensorTagMov_init(); // Movement processor SensorTagOpt_init(); // Light meter // Auxiliary services SensorTagKeys_init(); // Simple Keys SensorTagIO_init(); // IO (LED+buzzer+self test) #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 VOID GAPBondMgr_Register(NULL); // Enable interrupt handling for keys and relay PIN_registerIntCb(hGpioPin, SensorTag_callback); }