/********************************************************************* * @fn simpleTopology_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 simpleTopology_init(void) { // ****************************************************************** // 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); // Setup discovery delay as a one-shot timer Util_constructClock(&startDiscClock, simpleTopology_startDiscHandler, DEFAULT_SVC_DISCOVERY_DELAY, 0, false, 0); //init keys and LCD Board_initKeys(simpleTopology_keyChangeHandler); Board_openLCD(); // Setup the GAP { /*-------------------PERIPHERAL-------------------*/ uint16_t advInt = DEFAULT_ADVERTISING_INTERVAL; GAP_SetParamValue(TGAP_CONN_PAUSE_PERIPHERAL, DEFAULT_CONN_PAUSE_PERIPHERAL); 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); /*-------------------CENTRAL-------------------*/ GAP_SetParamValue(TGAP_GEN_DISC_SCAN, DEFAULT_SCAN_DURATION); GAP_SetParamValue(TGAP_CONN_SCAN_INT, DEFAULT_SCAN_INT); GAP_SetParamValue(TGAP_CONN_SCAN_WIND, DEFAULT_SCAN_WIND); GAP_SetParamValue(TGAP_CONN_HIGH_SCAN_INT, DEFAULT_SCAN_INT); GAP_SetParamValue(TGAP_CONN_HIGH_SCAN_WIND, DEFAULT_SCAN_WIND); GAP_SetParamValue(TGAP_GEN_DISC_SCAN_INT, DEFAULT_SCAN_INT); GAP_SetParamValue(TGAP_GEN_DISC_SCAN_WIND, DEFAULT_SCAN_WIND); GAP_SetParamValue(TGAP_LIM_DISC_SCAN_INT, DEFAULT_SCAN_INT); GAP_SetParamValue(TGAP_LIM_DISC_SCAN_WIND, DEFAULT_SCAN_WIND); GAP_SetParamValue(TGAP_CONN_EST_SCAN_INT, DEFAULT_SCAN_INT); GAP_SetParamValue(TGAP_CONN_EST_SCAN_WIND, DEFAULT_SCAN_WIND); GAP_SetParamValue(TGAP_CONN_EST_INT_MIN, DEFAULT_CONN_INT); GAP_SetParamValue(TGAP_CONN_EST_INT_MAX, DEFAULT_CONN_INT); GAP_SetParamValue(TGAP_CONN_EST_SUPERV_TIMEOUT, DEFAULT_CONN_TIMEOUT); GAP_SetParamValue(TGAP_CONN_EST_LATENCY, DEFAULT_CONN_LATENCY); } // Setup the GAP Role Profile { /*--------PERIPHERAL-------------*/ // 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; 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; GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8_t), &initialAdvertEnable, NULL); GAPRole_SetParameter(GAPROLE_ADVERT_OFF_TIME, sizeof(uint16_t), &advertOffTime, NULL); GAPRole_SetParameter(GAPROLE_SCAN_RSP_DATA, sizeof(scanRspData), scanRspData, NULL); GAPRole_SetParameter(GAPROLE_ADVERT_DATA, sizeof(advertData), advertData, NULL); GAPRole_SetParameter(GAPROLE_MIN_CONN_INTERVAL, sizeof(uint16_t), &desiredMinInterval, NULL); GAPRole_SetParameter(GAPROLE_MAX_CONN_INTERVAL, sizeof(uint16_t), &desiredMaxInterval, NULL); GAPRole_SetParameter(GAPROLE_SLAVE_LATENCY, sizeof(uint16_t), &desiredSlaveLatency, NULL); GAPRole_SetParameter(GAPROLE_TIMEOUT_MULTIPLIER, sizeof(uint16_t), &desiredConnTimeout, NULL); /*--------------CENTRAL-----------------*/ uint8_t scanRes = DEFAULT_MAX_SCAN_RES; GAPRole_SetParameter(GAPROLE_MAX_SCAN_RES, sizeof(uint8_t), &scanRes, NULL); // Register with GAP for HCI/Host messages GAP_RegisterForMsgs(selfEntity); } //GATT { /*---------------------SERVER------------------------*/ // Set the GAP Characteristics GGS_SetParameter(GGS_DEVICE_NAME_ATT, GAP_DEVICE_NAME_LEN, attDeviceName); // Initialize GATT Server Services GGS_AddService(GATT_ALL_SERVICES); // GAP GATTServApp_AddService(GATT_ALL_SERVICES); // GATT attributes DevInfo_AddService(); // Device Information Service SimpleProfile_AddService(GATT_ALL_SERVICES); // Simple GATT Profile // Setup Profile Characteristic Values { uint8_t charValue1 = 1; uint8_t charValue2 = 2; uint8_t charValue3 = 3; uint8_t charValue4 = 4; uint8_t charValue5[SIMPLEPROFILE_CHAR5_LEN] = { 1, 2, 3, 4, 5 }; SimpleProfile_SetParameter(SIMPLEPROFILE_CHAR1, sizeof(uint8_t), &charValue1); SimpleProfile_SetParameter(SIMPLEPROFILE_CHAR2, sizeof(uint8_t), &charValue2); SimpleProfile_SetParameter(SIMPLEPROFILE_CHAR3, sizeof(uint8_t), &charValue3); SimpleProfile_SetParameter(SIMPLEPROFILE_CHAR4, sizeof(uint8_t), &charValue4); SimpleProfile_SetParameter(SIMPLEPROFILE_CHAR5, SIMPLEPROFILE_CHAR5_LEN, charValue5); } // Register callback with SimpleGATTprofile SimpleProfile_RegisterAppCBs(&simpleTopology_simpleProfileCBs); /*-----------------CLIENT------------------*/ // Initialize GATT Client VOID GATT_InitClient(); // Register for GATT local events and ATT Responses pending for transmission GATT_RegisterForMsgs(selfEntity); } // Start the Device VOID GAPRole_StartDevice(&simpleTopology_gapRoleCBs); }
/********************************************************************* * @fn SimpleBLEBroadcaster_init * * @brief Initialization function for the Simple BLE Broadcaster App * Task. This is called during initialization and should contain * any application specific initialization (ie. hardware * initialization/setup, table initialization, power up * notification ...). * * @param none * * @return none */ static void SimpleBLEBroadcaster_init(void) { // ****************************************************************** // 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); // Hard code the DB Address till CC2650 board gets its own IEEE address //uint8 bdAddress[B_ADDR_LEN] = { 0x33, 0x33, 0x33, 0x33, 0x33, 0x33 }; //HCI_EXT_SetBDADDRCmd(bdAddress); // Create an RTOS queue for message from profile to be sent to app. appMsgQueue = Util_constructQueue(&appMsg); #ifdef TI_DRIVERS_LCD_INCLUDED //Enable the 3V3 Domain and open LCD Board_openLCD(); #endif //TI_DRIVERS_LCD_INCLUDED // Setup the GAP Broadcaster Role Profile { // For all hardware platforms, device starts advertising upon initialization uint8_t initial_advertising_enable = 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 gapRole_AdvertOffTime = 0; #ifndef BEACON_FEATURE uint8_t advType = GAP_ADTYPE_ADV_SCAN_IND; // use scannable undirected adv #else uint8_t advType = GAP_ADTYPE_ADV_NONCONN_IND; // use non-connectable adv #endif // !BEACON_FEATURE // Set the GAP Role Parameters GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8_t), &initial_advertising_enable); GAPRole_SetParameter(GAPROLE_ADVERT_OFF_TIME, sizeof(uint16_t), &gapRole_AdvertOffTime); GAPRole_SetParameter(GAPROLE_SCAN_RSP_DATA, sizeof (scanRspData), scanRspData); GAPRole_SetParameter(GAPROLE_ADVERT_DATA, sizeof(advertData), advertData); GAPRole_SetParameter(GAPROLE_ADV_EVENT_TYPE, sizeof(uint8_t), &advType); } // 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); } // Start the Device VOID GAPRole_StartDevice(&simpleBLEBroadcaster_BroadcasterCBs); LCD_WRITE_STRING("BLE Broadcaster", LCD_PAGE0); }
/********************************************************************* * @fn glucCollCentral_Init * * @brief Initialization function for the Glucose Collector App Task. * This is called during initialization and should contain * any application specific initialization (ie. hardware * initialization/setup, table initialization, power up * notification). * * * @return none */ static void glucCollCentral_Init() { // ****************************************************************** // 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); // Set device's Sleep Clock Accuracy //HCI_EXT_SetSCACmd(40); // Save the taskId glucCollTaskId = selfEntity; // Create an RTOS queue for message from profile to be sent to app. appMsgQueue = Util_constructQueue(&appMsg); Board_openLCD(); // Create clock objects for discovery and procedure timeout Util_constructClock(&discoveryClock, glucCollCentral_clockHandler, DEFAULT_SVC_DISCOVERY_DELAY, 0, false, GLUCOLL_START_DISCOVERY_EVT); Util_constructClock(&procTimeoutClock, glucCollCentral_clockHandler, GLUCOSE_PROCEDURE_TIMEOUT, 0, false, GLUCOLL_PROCEDURE_TIMEOUT_EVT); // Setup Central Profile { uint8_t scanRes = DEFAULT_MAX_SCAN_RES; GAPCentralRole_SetParameter (GAPCENTRALROLE_MAX_SCAN_RES, sizeof(uint8_t), &scanRes); } // Setup GAP GAP_SetParamValue(TGAP_GEN_DISC_SCAN, DEFAULT_SCAN_DURATION); GAP_SetParamValue(TGAP_LIM_DISC_SCAN, DEFAULT_SCAN_DURATION); GGS_SetParameter(GGS_DEVICE_NAME_ATT, GAP_DEVICE_NAME_LEN, (uint8_t *)glucCollDeviceName); // Setup the GAP Bond Manager { uint32_t passkey = DEFAULT_PASSCODE; uint8_t pairMode = DEFAULT_PAIRING_MODE; uint8_t mitm = DEFAULT_MITM_MODE; uint8_t ioCap = DEFAULT_IO_CAPABILITIES; uint8_t bonding = DEFAULT_BONDING_MODE; GAPBondMgr_SetParameter(GAPBOND_DEFAULT_PASSCODE, sizeof(uint32_t), &passkey); GAPBondMgr_SetParameter(GAPBOND_PAIRING_MODE, sizeof(uint8_t), &pairMode); GAPBondMgr_SetParameter(GAPBOND_MITM_PROTECTION, sizeof(uint8_t), &mitm); GAPBondMgr_SetParameter(GAPBOND_IO_CAPABILITIES, sizeof(uint8_t), &ioCap); GAPBondMgr_SetParameter(GAPBOND_BONDING_ENABLED, sizeof(uint8_t), &bonding); } // Initialize GATT Client VOID GATT_InitClient(); // Register to receive incoming ATT Indications/Notifications GATT_RegisterForInd(glucCollTaskId); // Initialize GATT attributes GGS_AddService(GATT_ALL_SERVICES); // GAP GATTServApp_AddService(GATT_ALL_SERVICES); // GATT attributes // Register for all key events - This app will handle all key events Board_initKeys(glucCollCentral_keyChangeHandler); // Register with bond manager after starting device GAPBondMgr_Register((gapBondCBs_t *)&glucCollBondCB); // Start the Device VOID GAPCentralRole_StartDevice((gapCentralRoleCB_t *)&glucCollRoleCB); }
/********************************************************************* * @fn HostTestApp_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 HostTestApp_init(void) { // Register the current thread as an ICall dispatcher application // so that the application can send and receive messages. ICall_registerApp(&selfEntity, &sem); // Set device's Sleep Clock Accuracy //HCI_EXT_SetSCACmd(40); Board_openLCD(); // Register for unprocessed HCI/Host event messages GAP_RegisterForMsgs(selfEntity); // Initialize GATT Client VOID GATT_InitClient(); // Get build revision VOID Util_buildRevision(&buildRev); #if !defined ( GATT_DB_OFF_CHIP ) #if defined ( GATT_QUAL ) VOID GATTQual_AddService( GATT_ALL_SERVICES ); // Includes GAP and GATT Services #else // Add our services to GATT Server VOID GGS_AddService( GATT_ALL_SERVICES ); VOID GATTServApp_AddService( GATT_ALL_SERVICES ); #if defined ( GATT_TEST ) VOID GATTTest_AddService( GATT_ALL_SERVICES ); #endif #endif // Set device name if ((buildRev.hostInfo & CENTRAL_CFG) && (buildRev.hostInfo & PERIPHERAL_CFG)) { memcpy(deviceName, "TI BLE All", 10); } else if (buildRev.hostInfo & CENTRAL_CFG) { memcpy(deviceName, "TI BLE Central", 14); } else if (buildRev.hostInfo & PERIPHERAL_CFG) { memcpy(deviceName, "TI BLE Peripheral", 17); } else { memcpy(deviceName, "TI BLE Unknown", 14); } VOID GGS_SetParameter(GGS_DEVICE_NAME_ATT, strlen((char *)deviceName), deviceName); VOID GGS_SetParameter(GGS_APPEARANCE_ATT, sizeof(uint16), (void*)&appearance); #endif // GATT_DB_OFF_CHIP LCD_WRITE_STRING("TI BLEv2.0", LCD_PAGE0); LCD_WRITE_STRING("HostTestApp", LCD_PAGE1); // Display Host build configuration if ((buildRev.hostInfo & CENTRAL_CFG) && (buildRev.hostInfo & PERIPHERAL_CFG)) { LCD_WRITE_STRING("All", LCD_PAGE2); } else if ((buildRev.hostInfo & CENTRAL_CFG) && (buildRev.hostInfo & BROADCASTER_CFG)) { LCD_WRITE_STRING("Cent+Bcast", LCD_PAGE2); } else if ((buildRev.hostInfo & PERIPHERAL_CFG) && (buildRev.hostInfo & OBSERVER_CFG)) { LCD_WRITE_STRING("Peri+Observ", LCD_PAGE2); } else if (buildRev.hostInfo & CENTRAL_CFG) { LCD_WRITE_STRING("Central", LCD_PAGE2); } else if (buildRev.hostInfo & PERIPHERAL_CFG) { LCD_WRITE_STRING("Peripheral", LCD_PAGE2); } else { LCD_WRITE_STRING_VALUE("Unknown build cfg", buildRev.hostInfo, 10, LCD_PAGE2); } }