diff --git a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/simple_peripheral.c b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/simple_peripheral.c index c53094a..8bc2f1c 100644 --- a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/simple_peripheral.c +++ b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/simple_peripheral.c @@ -509,154 +509,198 @@ void SimpleBLEPeripheral_createTask(void) { // How often to perform periodic event (in msec) #define SBP_PERIODIC_EVT_PERIOD 10 // 802 ~= 1 sec -static void SimpleBLEPeripheral_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, &semaphore); +/********************************************************************* + * @fn SimpleBLEPeripheral_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 SimpleBLEPeripheral_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, &semaphore); #ifdef USE_RCOSC - RCOSC_enableCalibration(); -#endif // USE_RCOSC + RCOSC_enableCalibration(); +#endif // USE_RCOSC -#ifdef USE_FPGA - // configure RF Core SMI Data Link - IOCPortConfigureSet(IOID_12, IOC_PORT_RFC_GPO0, IOC_STD_OUTPUT); - IOCPortConfigureSet(IOID_11, IOC_PORT_RFC_GPI0, IOC_STD_INPUT); +#if defined( USE_FPGA ) + // configure RF Core SMI Data Link + IOCPortConfigureSet(IOID_12, IOC_PORT_RFC_GPO0, IOC_STD_OUTPUT); + IOCPortConfigureSet(IOID_11, IOC_PORT_RFC_GPI0, IOC_STD_INPUT); - // configure RF Core SMI Command Link - IOCPortConfigureSet(IOID_10, IOC_IOCFG0_PORT_ID_RFC_SMI_CL_OUT, IOC_STD_OUTPUT); - IOCPortConfigureSet(IOID_9, IOC_IOCFG0_PORT_ID_RFC_SMI_CL_IN, IOC_STD_INPUT); + // configure RF Core SMI Command Link + IOCPortConfigureSet(IOID_10, IOC_IOCFG0_PORT_ID_RFC_SMI_CL_OUT, IOC_STD_OUTPUT); + IOCPortConfigureSet(IOID_9, IOC_IOCFG0_PORT_ID_RFC_SMI_CL_IN, IOC_STD_INPUT); - // configure RF Core tracer IO - IOCPortConfigureSet(IOID_8, IOC_PORT_RFC_TRC, IOC_STD_OUTPUT); -#else // !USE_FPGA -#ifdef DEBUG_SW_TRACE + // configure RF Core tracer IO + IOCPortConfigureSet(IOID_8, IOC_PORT_RFC_TRC, IOC_STD_OUTPUT); +#else // !USE_FPGA + #if defined( DEBUG_SW_TRACE ) // configure RF Core tracer IO IOCPortConfigureSet(IOID_8, IOC_PORT_RFC_TRC, IOC_STD_OUTPUT | IOC_CURRENT_4MA | IOC_SLEW_ENABLE); -#endif // DEBUG_SW_TRACE -#endif // USE_FPGA + #endif // DEBUG_SW_TRACE +#endif // USE_FPGA - // Create an RTOS queue for message from profile to be sent to app. - appMsgQueue = Util_constructQueue(&appMsg); + // 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. + // Create one-shot clocks for internal periodic events. + // Util_constructClock(&periodicClock, SimpleBLEPeripheral_clockHandler, + // SBP_PERIODIC_EVT_PERIOD, 0, false, SBP_PERIODIC_EVT); - // Setup the GAP - GAP_SetParamValue(TGAP_CONN_PAUSE_PERIPHERAL, DEFAULT_CONN_PAUSE_PERIPHERAL); + // dispHandle = Display_open(Display_Type_LCD, NULL); - // Setup the GAP Peripheral Role Profile - { - // For all hardware platforms, device starts advertising upon initialization - uint8_t initialAdvertEnable = TRUE; + // Setup the GAP + GAP_SetParamValue(TGAP_CONN_PAUSE_PERIPHERAL, DEFAULT_CONN_PAUSE_PERIPHERAL); - // 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; + // Setup the GAP Peripheral Role Profile + { + // For all hardware platforms, device starts advertising upon initialization + uint8_t initialAdvertEnable = TRUE; - 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; + // 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; - // Set the GAP Role Parameters - GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8_t), &initialAdvertEnable); - GAPRole_SetParameter(GAPROLE_ADVERT_OFF_TIME, sizeof(uint16_t), &advertOffTime); + 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; - // GAPRole_SetParameter(GAPROLE_SCAN_RSP_DATA, sizeof(SCAN_RESP_DATA), SCAN_RESP_DATA); - GAPRole_SetParameter(GAPROLE_ADVERT_DATA, sizeof(advertData), advertData); + // 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_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); - } + // GAPRole_SetParameter(GAPROLE_SCAN_RSP_DATA, sizeof(scanRspData), + // scanRspData); + GAPRole_SetParameter(GAPROLE_ADVERT_DATA, sizeof(advertData), advertData); - // Set the GAP Characteristics - // GGS_SetParameter(GGS_DEVICE_NAME_ATT, sizeof(DEVICE_NAME), DEVICE_NAME); + 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 advertising interval - { - uint16_t advInt = DEFAULT_ADVERTISING_INTERVAL; + // Set the GAP Characteristics + // GGS_SetParameter(GGS_DEVICE_NAME_ATT, GAP_DEVICE_NAME_LEN, attDeviceName); - 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); - } + // Set advertising interval + { + uint16_t advInt = DEFAULT_ADVERTISING_INTERVAL; - // Setup the GAP Bond Manager - { - uint32_t passkey = 0; // passkey "000000" - uint8_t pairMode = GAPBOND_PAIRING_MODE_WAIT_FOR_REQ; - uint8_t mitm = TRUE; - uint8_t ioCap = GAPBOND_IO_CAP_DISPLAY_ONLY; - uint8_t bonding = TRUE; + 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); + } - 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); - } + // Setup the GAP Bond Manager + { + uint32_t passkey = 0; // passkey "000000" + uint8_t pairMode = GAPBOND_PAIRING_MODE_WAIT_FOR_REQ; + uint8_t mitm = TRUE; + uint8_t ioCap = GAPBOND_IO_CAP_DISPLAY_ONLY; + uint8_t bonding = TRUE; - // Initialize GATT attributes - GGS_AddService(GATT_ALL_SERVICES); // GAP - GATTServApp_AddService(GATT_ALL_SERVICES); // GATT attributes - DevInfo_AddService(); // Device Information Service + 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 attributes + GGS_AddService(GATT_ALL_SERVICES); // GAP + GATTServApp_AddService(GATT_ALL_SERVICES); // GATT attributes + DevInfo_AddService(); // Device Information Service #ifndef FEATURE_OAD_ONCHIP - SimpleProfile_AddService(GATT_ALL_SERVICES); // Simple GATT Profile -#endif //! FEATURE_OAD_ONCHIP + SimpleProfile_AddService(GATT_ALL_SERVICES); // Simple GATT Profile +#endif //!FEATURE_OAD_ONCHIP #ifdef FEATURE_OAD - VOID OAD_addService(); // OAD Profile - OAD_register((oadTargetCBs_t *)&simpleBLEPeripheral_oadCBs); - hOadQ = Util_constructQueue(&oadQ); -#endif // FEATURE_OAD + VOID OAD_addService(); // OAD Profile + OAD_register((oadTargetCBs_t *)&simpleBLEPeripheral_oadCBs); + hOadQ = Util_constructQueue(&oadQ); +#endif //FEATURE_OAD #ifdef IMAGE_INVALIDATE - Reset_addService(); -#endif // IMAGE_INVALIDATE + Reset_addService(); +#endif //IMAGE_INVALIDATE + #ifndef FEATURE_OAD_ONCHIP - // Setup the SimpleProfile Characteristic Values - { - uint8_t charValue1 = 1; - uint8_t charValue2 = 2; - uint8_t charValue3[SIMPLEPROFILE_CHAR3_LEN] = {0}; - uint8_t charValue4[SIMPLEPROFILE_CHAR4_LEN] = {0}; - uint8_t charValue5[SIMPLEPROFILE_CHAR5_LEN] = {1, 2, 3, 4, 5}; + // Setup the SimpleProfile Characteristic Values + { + uint8_t charValue1 = 1; + uint8_t charValue2 = 2; + uint8_t charValue3[SIMPLEPROFILE_CHAR3_LEN] = {0}; + uint8_t charValue4[SIMPLEPROFILE_CHAR4_LEN] = {0}; + 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, SIMPLEPROFILE_CHAR3_LEN, charValue3); - SimpleProfile_SetParameter(SIMPLEPROFILE_CHAR4, SIMPLEPROFILE_CHAR4_LEN, charValue4); - SimpleProfile_SetParameter(SIMPLEPROFILE_CHAR5, SIMPLEPROFILE_CHAR5_LEN, charValue5); - } + SimpleProfile_SetParameter(SIMPLEPROFILE_CHAR1, sizeof(uint8_t), + &charValue1); + SimpleProfile_SetParameter(SIMPLEPROFILE_CHAR2, sizeof(uint8_t), + &charValue2); + SimpleProfile_SetParameter(SIMPLEPROFILE_CHAR3, SIMPLEPROFILE_CHAR3_LEN, + charValue3); + SimpleProfile_SetParameter(SIMPLEPROFILE_CHAR4, SIMPLEPROFILE_CHAR4_LEN, + charValue4); + SimpleProfile_SetParameter(SIMPLEPROFILE_CHAR5, SIMPLEPROFILE_CHAR5_LEN, + charValue5); + } - // Register callback with SimpleGATTprofile - SimpleProfile_RegisterAppCBs(&SimpleBLEPeripheral_simpleProfileCBs); -#endif //! FEATURE_OAD_ONCHIP + // Register callback with SimpleGATTprofile + SimpleProfile_RegisterAppCBs(&SimpleBLEPeripheral_simpleProfileCBs); +#endif //!FEATURE_OAD_ONCHIP - // Start the Device - VOID GAPRole_StartDevice(&SimpleBLEPeripheral_gapRoleCBs); + // Start the Device + VOID GAPRole_StartDevice(&SimpleBLEPeripheral_gapRoleCBs); - // Start Bond Manager - VOID GAPBondMgr_Register(&simpleBLEPeripheral_BondMgrCBs); + // Start Bond Manager + VOID GAPBondMgr_Register(&simpleBLEPeripheral_BondMgrCBs); - // Register with GAP for HCI/Host messages - GAP_RegisterForMsgs(selfEntity); + // Register with GAP for HCI/Host messages + GAP_RegisterForMsgs(selfEntity); - // Register for GATT local events and ATT Responses pending for transmission - GATT_RegisterForMsgs(selfEntity); + // Register for GATT local events and ATT Responses pending for transmission + GATT_RegisterForMsgs(selfEntity); - HCI_LE_ReadMaxDataLenCmd(); + HCI_LE_ReadMaxDataLenCmd(); + +/* +#if defined FEATURE_OAD +#if defined (HAL_IMAGE_A) + Display_print0(dispHandle, 0, 0, "BLE Peripheral A"); +#else + Display_print0(dispHandle, 0, 0, "BLE Peripheral B"); +#endif // HAL_IMAGE_A +#else + Display_print0(dispHandle, 0, 0, "BLE Peripheral"); +#endif // FEATURE_OAD +*/ } @@ -731,11 +775,7 @@ static bool power_on(uint32_t delta_time) * * @return None. */ -// static Clock_Struct detectKeyClock; -// static void detectKey_clockHandler(UArg arg); - - -static void SimpleBLEPeripheral_taskFxn(UArg a0, UArg a1) +static void SimpleBLEPeripheral_taskFxn(UArg a0, UArg a1) { batteryADC_flag = false; @@ -780,29 +820,32 @@ static void SimpleBLEPeripheral_taskFxn(UArg a0, UArg a1) break; } - // main loop + // Application main loop for (;;) { // Waits for a signal to the semaphore associated with the calling thread. // Note that the semaphore associated with a thread is signaled when a // message is queued to the message receive queue of the thread or when // ICall_signal() function is called onto the semaphore. - ICall_Errno errno = ICall_wait(ICALL_TIMEOUT_FOREVER); // let errno wait for infinite time, if periodicClock time up then execute below code - if (errno == ICALL_ERRNO_SUCCESS) { - ICall_EntityID dest; - ICall_ServiceEnum src; - ICall_HciExtEvt * pMsg = NULL; - if (ICall_fetchServiceMsg(&src, &dest, (void **)&pMsg) == ICALL_ERRNO_SUCCESS) { // if successfully retreived a meaasage from who? + + ICall_Errno errno = ICall_wait(ICALL_TIMEOUT_FOREVER); // let errno wait for infinite time, if periodicClock time up then execute below code + if (errno == ICALL_ERRNO_SUCCESS) { + ICall_EntityID dest; + ICall_ServiceEnum src; + ICall_HciExtEvt *pMsg = NULL; + + if (ICall_fetchServiceMsg(&src, &dest, + (void **)&pMsg) == ICALL_ERRNO_SUCCESS) { uint8 safeToDealloc = TRUE; - if ((src == ICALL_SERVICE_CLASS_BLE) && (dest == selfEntity)) { // src: source id who sent the massage; dest: entity id of the destination of the massage + if ((src == ICALL_SERVICE_CLASS_BLE) && (dest == selfEntity)) { ICall_Stack_Event *pEvt = (ICall_Stack_Event *)pMsg; // Check for BLE stack events first if (pEvt->signature == 0xffff) { if (pEvt->event_flag & SBP_CONN_EVT_END_EVT) { - // Try to retransmit pending ATT Response (if any) - SimpleBLEPeripheral_sendAttRsp(); + // Try to retransmit pending ATT Response (if any) + SimpleBLEPeripheral_sendAttRsp(); } } else { // Process inter-task message @@ -815,15 +858,15 @@ static void SimpleBLEPeripheral_taskFxn(UArg a0, UArg a1) } } - // If RTOS queue is not empty, process app message. //RTOS is the OS on Elite + // If RTOS queue is not empty, process app message. while (!Queue_empty(appMsgQueue)) { sbpEvt_t *pMsg = (sbpEvt_t *)Util_dequeueMsg(appMsgQueue); if (pMsg) { - // Process message. - SimpleBLEPeripheral_processAppMsg(pMsg); + // Process message. + SimpleBLEPeripheral_processAppMsg(pMsg); - // Free the space from the message. - ICall_free(pMsg); + // Free the space from the message. + ICall_free(pMsg); } } }