From 593ee66b03070d945e09ab6022c0265f35bf5285 Mon Sep 17 00:00:00 2001 From: chirag-silabs Date: Tue, 10 Sep 2024 21:25:47 +0530 Subject: [PATCH 01/17] adding queue logic to the semaphore --- examples/platform/silabs/BaseApplication.cpp | 16 +- src/platform/silabs/BLEManagerImpl.h | 15 +- src/platform/silabs/SiWx917/BUILD.gn | 2 +- src/platform/silabs/rs911x/BLEManagerImpl.cpp | 237 ++++++++---------- src/platform/silabs/rs911x/rsi_ble_config.h | 10 - ...{wfx_sl_ble_init.c => wfx_sl_ble_init.cpp} | 172 +++++-------- src/platform/silabs/rs911x/wfx_sl_ble_init.h | 23 +- 7 files changed, 207 insertions(+), 268 deletions(-) rename src/platform/silabs/rs911x/{wfx_sl_ble_init.c => wfx_sl_ble_init.cpp} (71%) diff --git a/examples/platform/silabs/BaseApplication.cpp b/examples/platform/silabs/BaseApplication.cpp index cbef67996c4528..a488e4efa251da 100644 --- a/examples/platform/silabs/BaseApplication.cpp +++ b/examples/platform/silabs/BaseApplication.cpp @@ -857,14 +857,14 @@ void BaseApplication::OnPlatformEvent(const ChipDeviceEvent * event, intptr_t) SILABS_LOG("Failed to initialize DIC module\n"); } #endif // DIC_ENABLE -#ifdef DISPLAY_ENABLED - SilabsLCD::Screen_e screen; - AppTask::GetLCD().GetScreen(screen); - // Update the LCD screen with SSID and connected state - VerifyOrReturn(screen == SilabsLCD::Screen_e::StatusScreen); - BaseApplication::UpdateLCDStatusScreen(false); - AppTask::GetLCD().SetScreen(screen); -#endif // DISPLAY_ENABLED +// #ifdef DISPLAY_ENABLED +// SilabsLCD::Screen_e screen; +// AppTask::GetLCD().GetScreen(screen); +// // Update the LCD screen with SSID and connected state +// VerifyOrReturn(screen == SilabsLCD::Screen_e::StatusScreen); +// BaseApplication::UpdateLCDStatusScreen(false); +// AppTask::GetLCD().SetScreen(screen); +// #endif // DISPLAY_ENABLED if ((event->ThreadConnectivityChange.Result == kConnectivity_Established) || (event->InternetConnectivityChange.IPv6 == kConnectivity_Established)) { diff --git a/src/platform/silabs/BLEManagerImpl.h b/src/platform/silabs/BLEManagerImpl.h index 4ff6d9d85413bf..bf6f9f14bd16b6 100644 --- a/src/platform/silabs/BLEManagerImpl.h +++ b/src/platform/silabs/BLEManagerImpl.h @@ -33,6 +33,7 @@ extern "C" { #include #include #include +#include "wfx_sl_ble_init.h" #ifdef __cplusplus } #endif // __cplusplus @@ -58,12 +59,12 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla void HandleBootEvent(void); #if (SLI_SI91X_ENABLE_BLE || RSI_BLE_ENABLE) - void HandleConnectEvent(void); - void HandleConnectionCloseEvent(uint16_t reason); - void HandleWriteEvent(rsi_ble_event_write_t evt); - void UpdateMtu(rsi_ble_event_mtu_t evt); + void HandleConnectEvent(sl_wfx_msg_t * evt); + void HandleConnectionCloseEvent(sl_wfx_msg_t * evt); + void HandleWriteEvent(sl_wfx_msg_t * evt); + void UpdateMtu(sl_wfx_msg_t * evt); void HandleTxConfirmationEvent(BLE_CONNECTION_OBJECT conId); - void HandleTXCharCCCDWrite(rsi_ble_event_write_t * evt); + void HandleTXCharCCCDWrite(sl_wfx_msg_t * evt); void HandleSoftTimerEvent(void); int32_t SendBLEAdvertisementCommand(void); #else @@ -80,7 +81,7 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla #if CHIP_ENABLE_ADDITIONAL_DATA_ADVERTISING #if (SLI_SI91X_ENABLE_BLE || RSI_BLE_ENABLE) - static void HandleC3ReadRequest(rsi_ble_read_req_t * rsi_ble_read_req); + static void HandleC3ReadRequest(sl_wfx_msg_t * rsi_ble_read_req); #else #if CHIP_ENABLE_ADDITIONAL_DATA_ADVERTISING static void HandleC3ReadRequest(volatile sl_bt_msg_t * evt); @@ -186,7 +187,7 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla #endif #if (SLI_SI91X_ENABLE_BLE || RSI_BLE_ENABLE) - void HandleRXCharWrite(rsi_ble_event_write_t * evt); + void HandleRXCharWrite(sl_wfx_msg_t * evt); #else void HandleRXCharWrite(volatile sl_bt_msg_t * evt); #endif diff --git a/src/platform/silabs/SiWx917/BUILD.gn b/src/platform/silabs/SiWx917/BUILD.gn index ca3c4042349113..4415c0f1fbcf39 100644 --- a/src/platform/silabs/SiWx917/BUILD.gn +++ b/src/platform/silabs/SiWx917/BUILD.gn @@ -64,7 +64,7 @@ static_library("SiWx917") { "../../SingletonConfigurationManager.cpp", "../rs911x/BLEManagerImpl.cpp", "../rs911x/rsi_ble_config.h", - "../rs911x/wfx_sl_ble_init.c", + "../rs911x/wfx_sl_ble_init.cpp", "../rs911x/wfx_sl_ble_init.h", ] diff --git a/src/platform/silabs/rs911x/BLEManagerImpl.cpp b/src/platform/silabs/rs911x/BLEManagerImpl.cpp index 6fea061de76ab8..d76bfb0050f127 100644 --- a/src/platform/silabs/rs911x/BLEManagerImpl.cpp +++ b/src/platform/silabs/rs911x/BLEManagerImpl.cpp @@ -28,51 +28,47 @@ #include "cmsis_os2.h" #include -#ifndef SLI_SI91X_MCU_INTERFACE -#include "rail.h" + + +#include +#include +#include +#include +#include + +#if CHIP_ENABLE_ADDITIONAL_DATA_ADVERTISING +#include #endif + +// #ifndef SLI_SI91X_MCU_INTERFACE +// #include "rail.h" +// #endif #include #ifdef __cplusplus extern "C" { #endif -#include "FreeRTOS.h" -#include "event_groups.h" -#include "task.h" -#include "timers.h" -#include "wfx_host_events.h" -#include "wfx_rsi.h" #include "wfx_sl_ble_init.h" #if !(SLI_SI91X_MCU_INTERFACE | EXP_BOARD) #include #endif #include -#include #ifdef __cplusplus } #endif -#include -#include -#include -#include -#include -#include - -#if CHIP_ENABLE_ADDITIONAL_DATA_ADVERTISING -#include -#endif - +#define WFX_QUEUE_SIZE 10 #define BLE_MIN_CONNECTION_INTERVAL_MS 24 #define BLE_MAX_CONNECTION_INTERVAL_MS 40 #define BLE_SLAVE_LATENCY_MS 0 #define BLE_TIMEOUT_MS 400 -#define BLE_DEFAULT_TIMER_PERIOD_MS (1) #define BLE_SEND_INDICATION_TIMER_PERIOD_MS (5000) -extern sl_wfx_msg_t event_msg; +// Used to send the Indication Confirmation +uint8_t dev_address[RSI_DEV_ADDR_LEN]; +uint16_t ble_measurement_hndl; -osSemaphoreId_t sl_ble_event_sem; osSemaphoreId_t sl_rs_ble_init_sem; +osMessageQueueId_t sBleEventQueue = NULL; osTimerId_t sbleAdvTimeoutTimer; @@ -111,92 +107,86 @@ void sl_ble_init() NULL, rsi_ble_on_event_indication_confirmation, NULL); // Exchange of GATT info with BLE stack - rsi_ble_add_matter_service(); - // initializing the application events map - rsi_ble_app_init_events(); rsi_ble_set_random_address_with_value(randomAddrBLE); + + sBleEventQueue = osMessageQueueNew(WFX_QUEUE_SIZE, sizeof(WfxEvent_t), NULL); + VerifyOrDie(sBleEventQueue != nullptr); + chip::DeviceLayer::Internal::BLEMgrImpl().HandleBootEvent(); } +void ProcessEvent(BleEvent_t inEvent) +{ + switch (inEvent.eventType) + { + case RSI_BLE_CONN_EVENT: { + BLEMgrImpl().HandleConnectEvent((inEvent.eventData)); + // Requests the connection parameters change with the remote device + rsi_ble_conn_params_update(inEvent.eventData->resp_enh_conn.dev_addr, BLE_MIN_CONNECTION_INTERVAL_MS, + BLE_MAX_CONNECTION_INTERVAL_MS, BLE_SLAVE_LATENCY_MS, BLE_TIMEOUT_MS); + rsi_ble_set_data_len(inEvent.eventData->resp_enh_conn.dev_addr, RSI_BLE_TX_OCTETS, RSI_BLE_TX_TIME); + + // Used to send the Indication confirmation + memcpy(dev_address,inEvent.eventData->resp_enh_conn.dev_addr, RSI_DEV_ADDR_LEN); + ble_measurement_hndl = inEvent.eventData->rsi_ble_measurement_hndl; + } + break; + case RSI_BLE_DISCONN_EVENT: { + // event invokes when disconnection was completed + BLEMgrImpl().HandleConnectionCloseEvent(inEvent.eventData); + } + break; + case RSI_BLE_MTU_EVENT: { + // event invokes when write/notification events received + BLEMgrImpl().UpdateMtu(inEvent.eventData); + } + break; + case RSI_BLE_EVENT_GATT_RD: { +#if CHIP_ENABLE_ADDITIONAL_DATA_ADVERTISING + if (inEvent.eventData->rsi_ble_read_req->type == 0) + { + BLEMgrImpl().HandleC3ReadRequest(&inEvent.eventData); + } +#endif // CHIP_ENABLE_ADDITIONAL_DATA_ADVERTISING + } + break; + case RSI_BLE_GATT_WRITE_EVENT: { + // event invokes when write/notification events received + BLEMgrImpl().HandleWriteEvent(inEvent.eventData); + } + break; + case RSI_BLE_GATT_INDICATION_CONFIRMATION: { + BLEMgrImpl().HandleTxConfirmationEvent(1); + } + break; + default: + break; + } +} + void sl_ble_event_handling_task(void * args) { - int32_t event_id; + sl_status_t status; + BleEvent_t bleEvent; //! This semaphore is waiting for wifi module initialization. osSemaphoreAcquire(sl_rs_ble_init_sem, osWaitForever); - + // This function initialize BLE and start BLE advertisement. sl_ble_init(); // Application event map while (1) { - // checking for events list - event_id = rsi_ble_app_get_event(); - if (event_id == -1) + status = osMessageQueueGet(sBleEventQueue, &bleEvent, NULL, osWaitForever); + if (status == osOK) { - //! This semaphore is waiting for next ble event task - osSemaphoreAcquire(sl_ble_event_sem, osWaitForever); - continue; + ProcessEvent(bleEvent); } - switch (event_id) + else { - case RSI_BLE_CONN_EVENT: { - rsi_ble_app_clear_event(RSI_BLE_CONN_EVENT); - BLEMgrImpl().HandleConnectEvent(); - // Requests the connection parameters change with the remote device - rsi_ble_conn_params_update(event_msg.resp_enh_conn.dev_addr, BLE_MIN_CONNECTION_INTERVAL_MS, - BLE_MAX_CONNECTION_INTERVAL_MS, BLE_SLAVE_LATENCY_MS, BLE_TIMEOUT_MS); - rsi_ble_set_data_len(event_msg.resp_enh_conn.dev_addr, RSI_BLE_TX_OCTETS, RSI_BLE_TX_TIME); - } - break; - case RSI_BLE_DISCONN_EVENT: { - // event invokes when disconnection was completed - BLEMgrImpl().HandleConnectionCloseEvent(event_msg.reason); - // clear the served event - rsi_ble_app_clear_event(RSI_BLE_DISCONN_EVENT); - } - break; - case RSI_BLE_MTU_EVENT: { - // event invokes when write/notification events received - BLEMgrImpl().UpdateMtu(event_msg.rsi_ble_mtu); - // clear the served event - rsi_ble_app_clear_event(RSI_BLE_MTU_EVENT); - } - break; - case RSI_BLE_EVENT_GATT_RD: { -#if CHIP_ENABLE_ADDITIONAL_DATA_ADVERTISING - if (event_msg.rsi_ble_read_req->type == 0) - { - BLEMgrImpl().HandleC3ReadRequest(event_msg.rsi_ble_read_req); - } -#endif // CHIP_ENABLE_ADDITIONAL_DATA_ADVERTISING - // clear the served event - rsi_ble_app_clear_event(RSI_BLE_EVENT_GATT_RD); - } - break; - case RSI_BLE_GATT_WRITE_EVENT: { - // event invokes when write/notification events received - BLEMgrImpl().HandleWriteEvent(event_msg.rsi_ble_write); - // clear the served event - rsi_ble_app_clear_event(RSI_BLE_GATT_WRITE_EVENT); - } - break; - case RSI_BLE_GATT_INDICATION_CONFIRMATION: { - BLEMgrImpl().HandleTxConfirmationEvent(1); - rsi_ble_app_clear_event(RSI_BLE_GATT_INDICATION_CONFIRMATION); - } - break; - default: - break; - } - - if (chip::DeviceLayer::ConnectivityMgr().IsWiFiStationConnected()) - { - // Once DUT is connected adding a 500ms delay - // TODO: Fix this with a better event handling - vTaskDelay(pdMS_TO_TICKS(500)); + ChipLogError(DeviceLayer, "sl_ble_event_handling_task: get event failed: 0x%lx", static_cast(status)); } } } @@ -228,23 +218,6 @@ namespace { #define TIMER_MS_2_TIMERTICK(ms) ((TIMER_CLK_FREQ * ms) / 1000) #define TIMER_S_2_TIMERTICK(s) (TIMER_CLK_FREQ * s) -#define BLE_MAX_BUFFER_SIZE (3076) -#define BLE_MAX_ADVERTISERS (1) -#define BLE_CONFIG_MAX_PERIODIC_ADVERTISING_SYNC (0) -#define BLE_CONFIG_MAX_SOFTWARE_TIMERS (4) -#define BLE_CONFIG_MIN_TX_POWER (-30) -#define BLE_CONFIG_MAX_TX_POWER (80) -#define BLE_CONFIG_RF_PATH_GAIN_TX (0) -#define BLE_CONFIG_RF_PATH_GAIN_RX (0) - -// Default Connection parameters -#define BLE_CONFIG_MIN_INTERVAL (16) // Time = Value x 1.25 ms = 30ms -#define BLE_CONFIG_MAX_INTERVAL (80) // Time = Value x 1.25 ms = 100ms -#define BLE_CONFIG_LATENCY (0) -#define BLE_CONFIG_TIMEOUT (100) // Time = Value x 10 ms = 1s -#define BLE_CONFIG_MIN_CE_LENGTH (0) // Leave to min value -#define BLE_CONFIG_MAX_CE_LENGTH (0xFFFF) // Leave to max value - const uint8_t UUID_CHIPoBLEService[] = { 0xFB, 0x34, 0x9B, 0x5F, 0x80, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0xF6, 0xFF, 0x00, 0x00 }; const uint8_t ShortUUID_CHIPoBLEService[] = { 0xF6, 0xFF }; @@ -258,7 +231,6 @@ CHIP_ERROR BLEManagerImpl::_Init() CHIP_ERROR err; sl_rs_ble_init_sem = osSemaphoreNew(1, 0, NULL); - sl_ble_event_sem = osSemaphoreNew(1, 0, NULL); sBleThread = osThreadNew(sl_ble_event_handling_task, NULL, &kBleTaskAttr); @@ -465,8 +437,7 @@ CHIP_ERROR BLEManagerImpl::SendIndication(BLE_CONNECTION_OBJECT conId, const Chi PacketBufferHandle data) { int32_t status = 0; - status = rsi_ble_indicate_value(event_msg.resp_enh_conn.dev_addr, event_msg.rsi_ble_measurement_hndl, (data->DataLength()), - data->Start()); + status = rsi_ble_indicate_value(dev_address, ble_measurement_hndl,data->DataLength(),data->Start()); if (status != RSI_SUCCESS) { @@ -761,9 +732,9 @@ CHIP_ERROR BLEManagerImpl::StopAdvertising(void) return err; } -void BLEManagerImpl::UpdateMtu(rsi_ble_event_mtu_t evt) +void BLEManagerImpl::UpdateMtu(sl_wfx_msg_t * evt) { - CHIPoBLEConState * bleConnState = GetConnectionState(event_msg.connectionHandle); + CHIPoBLEConState * bleConnState = GetConnectionState(evt->connectionHandle); if (bleConnState != NULL) { // bleConnState->MTU is a 10-bit field inside a uint16_t. We're @@ -775,10 +746,10 @@ void BLEManagerImpl::UpdateMtu(rsi_ble_event_mtu_t evt) // TODO: https://github.com/project-chip/connectedhomeip/issues/2569 // tracks making this safe with a check or explaining why no check // is needed. - ChipLogProgress(DeviceLayer, "DriveBLEState UpdateMtu %d", evt.mtu_size); + ChipLogProgress(DeviceLayer, "DriveBLEState UpdateMtu %d", evt->rsi_ble_mtu.mtu_size); #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wconversion" - bleConnState->mtu = evt.mtu_size; + bleConnState->mtu = evt->rsi_ble_mtu.mtu_size; #pragma GCC diagnostic pop ; } @@ -790,14 +761,14 @@ void BLEManagerImpl::HandleBootEvent(void) PlatformMgr().ScheduleWork(DriveBLEState, 0); } -void BLEManagerImpl::HandleConnectEvent(void) +void BLEManagerImpl::HandleConnectEvent(sl_wfx_msg_t * evt) { - AddConnection(event_msg.connectionHandle, event_msg.bondingHandle); + AddConnection(evt->connectionHandle, evt->bondingHandle); PlatformMgr().ScheduleWork(DriveBLEState, 0); } // TODO:: Implementation need to be done. -void BLEManagerImpl::HandleConnectionCloseEvent(uint16_t reason) +void BLEManagerImpl::HandleConnectionCloseEvent(sl_wfx_msg_t * evt) { uint8_t connHandle = 1; @@ -807,7 +778,7 @@ void BLEManagerImpl::HandleConnectionCloseEvent(uint16_t reason) event.Type = DeviceEventType::kCHIPoBLEConnectionError; event.CHIPoBLEConnectionError.ConId = connHandle; - switch (reason) + switch (evt->reason) { case RSI_BT_CTRL_REMOTE_USER_TERMINATED: @@ -819,7 +790,7 @@ void BLEManagerImpl::HandleConnectionCloseEvent(uint16_t reason) event.CHIPoBLEConnectionError.Reason = BLE_ERROR_CHIPOBLE_PROTOCOL_ABORT; } - ChipLogProgress(DeviceLayer, "BLE GATT connection closed (con %u, reason %x)", connHandle, reason); + ChipLogProgress(DeviceLayer, "BLE GATT connection closed (con %u, reason %x)", connHandle, evt->reason); PlatformMgr().PostEventOrDie(&event); @@ -831,37 +802,37 @@ void BLEManagerImpl::HandleConnectionCloseEvent(uint16_t reason) } } -void BLEManagerImpl::HandleWriteEvent(rsi_ble_event_write_t evt) +void BLEManagerImpl::HandleWriteEvent(sl_wfx_msg_t * evt) { - ChipLogProgress(DeviceLayer, "Char Write Req, packet type %d", evt.pkt_type); + ChipLogProgress(DeviceLayer, "Char Write Req, packet type %d", evt->rsi_ble_write.pkt_type); - if (evt.handle[0] == (uint8_t) event_msg.rsi_ble_gatt_server_client_config_hndl) // TODO:: compare the handle exactly + if (evt->rsi_ble_write.handle[0] == (uint8_t) evt->rsi_ble_gatt_server_client_config_hndl) // TODO:: compare the handle exactly { - HandleTXCharCCCDWrite(&evt); + HandleTXCharCCCDWrite(evt); } else { - HandleRXCharWrite(&evt); + HandleRXCharWrite(evt); } } // TODO:: Need to implement this -void BLEManagerImpl::HandleTXCharCCCDWrite(rsi_ble_event_write_t * evt) +void BLEManagerImpl::HandleTXCharCCCDWrite(sl_wfx_msg_t * evt) { CHIP_ERROR err = CHIP_NO_ERROR; bool isIndicationEnabled = false; ChipDeviceEvent event; CHIPoBLEConState * bleConnState; - bleConnState = GetConnectionState(event_msg.connectionHandle); + bleConnState = GetConnectionState(evt->connectionHandle); VerifyOrExit(bleConnState != NULL, err = CHIP_ERROR_NO_MEMORY); // Determine if the client is enabling or disabling notification/indication. - if (evt->att_value[0] != 0) + if (evt->rsi_ble_write.att_value[0] != 0) { isIndicationEnabled = true; } - ChipLogProgress(DeviceLayer, "HandleTXcharCCCDWrite - Config Flags value : %d", evt->att_value[0]); + ChipLogProgress(DeviceLayer, "HandleTXcharCCCDWrite - Config Flags value : %d", evt->rsi_ble_write.att_value[0]); ChipLogProgress(DeviceLayer, "CHIPoBLE %s received", isIndicationEnabled ? "subscribe" : "unsubscribe"); if (isIndicationEnabled) @@ -891,13 +862,13 @@ void BLEManagerImpl::HandleTXCharCCCDWrite(rsi_ble_event_write_t * evt) } } -void BLEManagerImpl::HandleRXCharWrite(rsi_ble_event_write_t * evt) +void BLEManagerImpl::HandleRXCharWrite(sl_wfx_msg_t * evt) { uint8_t conId = 1; CHIP_ERROR err = CHIP_NO_ERROR; System::PacketBufferHandle buf; - uint16_t writeLen = evt->length; - uint8_t * data = (uint8_t *) evt->att_value; + uint16_t writeLen = evt->rsi_ble_write.length; + uint8_t * data = (uint8_t *) evt->rsi_ble_write.att_value; // Copy the data to a packet buffer. buf = System::PacketBufferHandle::NewWithData(data, writeLen, 0, 0); @@ -1024,9 +995,9 @@ CHIP_ERROR BLEManagerImpl::EncodeAdditionalDataTlv() return err; } -void BLEManagerImpl::HandleC3ReadRequest(rsi_ble_read_req_t * rsi_ble_read_req) +void BLEManagerImpl::HandleC3ReadRequest(sl_wfx_msg_t * evt) { - sl_status_t ret = rsi_ble_gatt_read_response(rsi_ble_read_req->dev_addr, GATT_READ_RESP, rsi_ble_read_req->handle, + sl_status_t ret = rsi_ble_gatt_read_response(evt->rsi_ble_read_req.dev_addr, GATT_READ_RESP, evt->rsi_ble_read_req.handle, GATT_READ_ZERO_OFFSET, sInstance.c3AdditionalDataBufferHandle->DataLength(), sInstance.c3AdditionalDataBufferHandle->Start()); if (ret != SL_STATUS_OK) diff --git a/src/platform/silabs/rs911x/rsi_ble_config.h b/src/platform/silabs/rs911x/rsi_ble_config.h index 781ad80a29e7d7..de207a99af1601 100644 --- a/src/platform/silabs/rs911x/rsi_ble_config.h +++ b/src/platform/silabs/rs911x/rsi_ble_config.h @@ -38,15 +38,6 @@ #define RSI_FAILURE -1 #endif -#define RSI_BLE_CONN_EVENT (0x01) -#define RSI_BLE_DISCONN_EVENT (0x02) -#define RSI_BLE_GATT_WRITE_EVENT (0x03) -#define RSI_BLE_MTU_EVENT (0x04) -#define RSI_BLE_GATT_INDICATION_CONFIRMATION (0x05) -#define RSI_BLE_RESP_ATT_VALUE (0x06) -#define RSI_BLE_EVENT_GATT_RD (0x08) -#define RSI_BLE_ADDR_LENGTH 6 - #define RSI_SSID (0x0D) #define RSI_SECTYPE (0x0E) #define RSI_BLE_WLAN_DISCONN_NOTIFY (0x0F) @@ -62,7 +53,6 @@ #define RSI_BLE_DEV_NAME "CCP_DEVICE" #define RSI_BLE_SET_RAND_ADDR "00:23:A7:12:34:56" -#define RSI_BLE_EVENT_GATT_RD (0x08) #define RSI_BLE_ADDR_LENGTH 6 #define CLEAR_WHITELIST (0x00) diff --git a/src/platform/silabs/rs911x/wfx_sl_ble_init.c b/src/platform/silabs/rs911x/wfx_sl_ble_init.cpp similarity index 71% rename from src/platform/silabs/rs911x/wfx_sl_ble_init.c rename to src/platform/silabs/rs911x/wfx_sl_ble_init.cpp index 23bc666b20b528..452ee017619863 100644 --- a/src/platform/silabs/rs911x/wfx_sl_ble_init.c +++ b/src/platform/silabs/rs911x/wfx_sl_ble_init.cpp @@ -20,51 +20,37 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#ifdef __cplusplus +extern "C" { +#endif #include "wfx_sl_ble_init.h" #include "ble_config.h" #include "cmsis_os2.h" +#ifdef __cplusplus +} +#endif #include "silabs_utils.h" + // Global Variables rsi_ble_t att_list; sl_wfx_msg_t event_msg; -extern osSemaphoreId_t sl_ble_event_sem; +BleEvent_t bleEvent; + +extern osMessageQueueId_t sBleEventQueue; // Memory to initialize driver uint8_t bt_global_buf[BT_GLOBAL_BUFF_LEN]; const uint8_t ShortUUID_CHIPoBLEService[] = { 0xF6, 0xFF }; -/*==============================================*/ -/** - * @fn rsi_ble_app_init_events - * @brief initializes the event parameter. - * @param[in] none. - * @return none. - * @section description - * This function is used during BLE initialization. - */ -void rsi_ble_app_init_events() +void BlePostEvent(BleEvent_t * event) { - event_msg.ble_app_event_map = 0; - event_msg.ble_app_event_mask = 0xFFFFFFFF; - event_msg.ble_app_event_mask = event_msg.ble_app_event_mask; // To suppress warning while compiling - return; -} - -/*==============================================*/ -/** - * @fn rsi_ble_app_clear_event - * @brief clears the specific event. - * @param[in] event_num, specific event number. - * @return none. - * @section description - * This function is used to clear the specific event. - */ -void rsi_ble_app_clear_event(uint32_t event_num) -{ - event_msg.event_num = event_num; - event_msg.ble_app_event_map &= ~BIT(event_num); - return; + sl_status_t status = osMessageQueuePut(sBleEventQueue, event, 0, 0); + if (status != osOK) + { + SILABS_LOG("BlePostEvent: failed to post event: 0x%lx", status); + // TODO: Handle error, requeue event depending on queue size or notify relevant task, Chipdie, etc. + } } /*==============================================*/ @@ -78,8 +64,9 @@ void rsi_ble_app_clear_event(uint32_t event_num) */ void rsi_ble_on_mtu_event(rsi_ble_event_mtu_t * rsi_ble_mtu) { - memcpy(&event_msg.rsi_ble_mtu, rsi_ble_mtu, sizeof(rsi_ble_event_mtu_t)); - rsi_ble_app_set_event(RSI_BLE_MTU_EVENT); + bleEvent.eventType = RSI_BLE_MTU_EVENT; + memcpy(&bleEvent.eventData->rsi_ble_mtu, rsi_ble_mtu, sizeof(rsi_ble_event_mtu_t)); + BlePostEvent(&bleEvent); } /*==============================================*/ @@ -94,9 +81,10 @@ void rsi_ble_on_mtu_event(rsi_ble_event_mtu_t * rsi_ble_mtu) */ void rsi_ble_on_gatt_write_event(uint16_t event_id, rsi_ble_event_write_t * rsi_ble_write) { - event_msg.event_id = event_id; - memcpy(&event_msg.rsi_ble_write, rsi_ble_write, sizeof(rsi_ble_event_write_t)); - rsi_ble_app_set_event(RSI_BLE_GATT_WRITE_EVENT); + bleEvent.eventType = RSI_BLE_GATT_WRITE_EVENT; + bleEvent.eventData->event_id = event_id; + memcpy(&bleEvent.eventData->rsi_ble_write, rsi_ble_write, sizeof(rsi_ble_event_write_t)); + BlePostEvent(&bleEvent); } /*==============================================*/ @@ -110,10 +98,11 @@ void rsi_ble_on_gatt_write_event(uint16_t event_id, rsi_ble_event_write_t * rsi_ */ void rsi_ble_on_enhance_conn_status_event(rsi_ble_event_enhance_conn_status_t * resp_enh_conn) { - event_msg.connectionHandle = 1; - event_msg.bondingHandle = 255; - memcpy(event_msg.resp_enh_conn.dev_addr, resp_enh_conn->dev_addr, RSI_DEV_ADDR_LEN); - rsi_ble_app_set_event(RSI_BLE_CONN_EVENT); + bleEvent.eventType = RSI_BLE_CONN_EVENT; + bleEvent.eventData->connectionHandle = 1; + bleEvent.eventData->bondingHandle = 255; + memcpy(bleEvent.eventData->resp_enh_conn.dev_addr, resp_enh_conn->dev_addr, RSI_DEV_ADDR_LEN); + BlePostEvent(&bleEvent); } /*==============================================*/ @@ -128,8 +117,9 @@ void rsi_ble_on_enhance_conn_status_event(rsi_ble_event_enhance_conn_status_t * */ void rsi_ble_on_disconnect_event(rsi_ble_event_disconnect_t * resp_disconnect, uint16_t reason) { - event_msg.reason = reason; - rsi_ble_app_set_event(RSI_BLE_DISCONN_EVENT); + bleEvent.eventType = RSI_BLE_DISCONN_EVENT; + bleEvent.eventData->reason = reason; + BlePostEvent(&bleEvent); } /*==============================================*/ @@ -143,9 +133,10 @@ void rsi_ble_on_disconnect_event(rsi_ble_event_disconnect_t * resp_disconnect, u */ void rsi_ble_on_event_indication_confirmation(uint16_t resp_status, rsi_ble_set_att_resp_t * rsi_ble_event_set_att_rsp) { - event_msg.resp_status = resp_status; - memcpy(&event_msg.rsi_ble_event_set_att_rsp, rsi_ble_event_set_att_rsp, sizeof(rsi_ble_set_att_resp_t)); - rsi_ble_app_set_event(RSI_BLE_GATT_INDICATION_CONFIRMATION); + bleEvent.eventType = RSI_BLE_GATT_INDICATION_CONFIRMATION; + bleEvent.eventData->resp_status = resp_status; + memcpy(&bleEvent.eventData->rsi_ble_event_set_att_rsp, rsi_ble_event_set_att_rsp, sizeof(rsi_ble_set_att_resp_t)); + BlePostEvent(&bleEvent); } /*==============================================*/ @@ -160,51 +151,10 @@ void rsi_ble_on_event_indication_confirmation(uint16_t resp_status, rsi_ble_set_ */ void rsi_ble_on_read_req_event(uint16_t event_id, rsi_ble_read_req_t * rsi_ble_read_req) { - event_msg.event_id = event_id; - memcpy(&event_msg.rsi_ble_read_req, rsi_ble_read_req, sizeof(rsi_ble_read_req_t)); - rsi_ble_app_set_event(RSI_BLE_EVENT_GATT_RD); -} - -/*==============================================*/ -/**s - * @fn rsi_ble_app_get_event - * @brief returns the first set event based on priority - * @param[in] none. - * @return int32_t - * > 0 = event number - * -1 = not received any event - * @section description - * This function returns the highest priority event among all the set events - */ -int32_t rsi_ble_app_get_event(void) -{ - uint32_t ix; - - for (ix = 0; ix < 32; ix++) - { - if (event_msg.ble_app_event_map & (1 << ix)) - { - return ix; - } - } - - return (-1); -} - -/*==============================================*/ -/** - * @fn rsi_ble_app_set_event - * @brief set the specific event. - * @param[in] event_num, specific event number. - * @return none. - * @section description - * This function is used to set/raise the specific event. - */ -void rsi_ble_app_set_event(uint32_t event_num) -{ - event_msg.ble_app_event_map |= BIT(event_num); - osSemaphoreRelease(sl_ble_event_sem); - return; + bleEvent.eventType = RSI_BLE_EVENT_GATT_RD; + bleEvent.eventData->event_id = event_id; + memcpy(&bleEvent.eventData->rsi_ble_read_req, rsi_ble_read_req, sizeof(rsi_ble_read_req_t)); + BlePostEvent(&bleEvent); } /*==============================================*/ @@ -371,12 +321,18 @@ uint32_t rsi_ble_add_matter_service(void) custom_service.val.val16 = RSI_BLE_MATTER_CUSTOM_SERVICE_VALUE_16; uint8_t data[RSI_BLE_MATTER_CUSTOM_SERVICE_DATA_LENGTH] = { RSI_BLE_MATTER_CUSTOM_SERVICE_DATA }; - static const uuid_t custom_characteristic_RX = { .size = RSI_BLE_CUSTOM_CHARACTERISTIC_RX_SIZE, - .reserved = { RSI_BLE_CUSTOM_CHARACTERISTIC_RX_RESERVED }, - .val.val128.data1 = RSI_BLE_CUSTOM_CHARACTERISTIC_RX_VALUE_128_DATA_1, - .val.val128.data2 = RSI_BLE_CUSTOM_CHARACTERISTIC_RX_VALUE_128_DATA_2, - .val.val128.data3 = RSI_BLE_CUSTOM_CHARACTERISTIC_RX_VALUE_128_DATA_3, - .val.val128.data4 = { RSI_BLE_CUSTOM_CHARACTERISTIC_RX_VALUE_128_DATA_4 } }; + static const uuid_t custom_characteristic_RX = { + .size = RSI_BLE_CUSTOM_CHARACTERISTIC_RX_SIZE, + .reserved = { RSI_BLE_CUSTOM_CHARACTERISTIC_RX_RESERVED }, + .val = { + .val128 = { + .data1 = { RSI_BLE_CUSTOM_CHARACTERISTIC_RX_VALUE_128_DATA_1 }, + .data2 = { RSI_BLE_CUSTOM_CHARACTERISTIC_RX_VALUE_128_DATA_2 }, + .data3 = { RSI_BLE_CUSTOM_CHARACTERISTIC_RX_VALUE_128_DATA_3 }, + .data4 = { RSI_BLE_CUSTOM_CHARACTERISTIC_RX_VALUE_128_DATA_4 } + } + } + }; rsi_ble_resp_add_serv_t new_serv_resp = { 0 }; rsi_ble_add_service(custom_service, &new_serv_resp); @@ -393,12 +349,18 @@ uint32_t rsi_ble_add_matter_service(void) RSI_BLE_ATT_PROPERTY_WRITE | RSI_BLE_ATT_PROPERTY_READ, // Set read, write, write without response data, sizeof(data), ATT_REC_IN_HOST); - static const uuid_t custom_characteristic_TX = { .size = RSI_BLE_CUSTOM_CHARACTERISTIC_TX_SIZE, - .reserved = { RSI_BLE_CUSTOM_CHARACTERISTIC_TX_RESERVED }, - .val.val128.data1 = RSI_BLE_CUSTOM_CHARACTERISTIC_TX_VALUE_128_DATA_1, - .val.val128.data2 = RSI_BLE_CUSTOM_CHARACTERISTIC_TX_VALUE_128_DATA_2, - .val.val128.data3 = RSI_BLE_CUSTOM_CHARACTERISTIC_TX_VALUE_128_DATA_3, - .val.val128.data4 = { RSI_BLE_CUSTOM_CHARACTERISTIC_TX_VALUE_128_DATA_4 } }; + static const uuid_t custom_characteristic_TX = { + .size = RSI_BLE_CUSTOM_CHARACTERISTIC_TX_SIZE, + .reserved = { RSI_BLE_CUSTOM_CHARACTERISTIC_TX_RESERVED }, + .val = { + .val128 = { + .data1 = { RSI_BLE_CUSTOM_CHARACTERISTIC_TX_VALUE_128_DATA_1 }, + .data2 = { RSI_BLE_CUSTOM_CHARACTERISTIC_TX_VALUE_128_DATA_2 }, + .data3 = { RSI_BLE_CUSTOM_CHARACTERISTIC_TX_VALUE_128_DATA_3 }, + .data4 = { RSI_BLE_CUSTOM_CHARACTERISTIC_TX_VALUE_128_DATA_4 } + } + } + }; // Adding custom characteristic declaration to the custom service rsi_ble_add_char_serv_att( @@ -408,13 +370,13 @@ uint32_t rsi_ble_add_matter_service(void) new_serv_resp.start_handle + RSI_BLE_CHARACTERISTIC_TX_MEASUREMENT_HANDLE_LOCATION, custom_characteristic_TX); // Adding characteristic value attribute to the service - event_msg.rsi_ble_measurement_hndl = new_serv_resp.start_handle + RSI_BLE_CHARACTERISTIC_TX_MEASUREMENT_HANDLE_LOCATION; + bleEvent.eventData->rsi_ble_measurement_hndl = new_serv_resp.start_handle + RSI_BLE_CHARACTERISTIC_TX_MEASUREMENT_HANDLE_LOCATION; // Adding characteristic value attribute to the service - event_msg.rsi_ble_gatt_server_client_config_hndl = + bleEvent.eventData->rsi_ble_gatt_server_client_config_hndl = new_serv_resp.start_handle + RSI_BLE_CHARACTERISTIC_TX_GATT_SERVER_CLIENT_HANDLE_LOCATION; - rsi_ble_add_char_val_att(new_serv_resp.serv_handler, event_msg.rsi_ble_measurement_hndl, custom_characteristic_TX, + rsi_ble_add_char_val_att(new_serv_resp.serv_handler, bleEvent.eventData->rsi_ble_measurement_hndl, custom_characteristic_TX, RSI_BLE_ATT_PROPERTY_WRITE_NO_RESPONSE | RSI_BLE_ATT_PROPERTY_WRITE | RSI_BLE_ATT_PROPERTY_READ | RSI_BLE_ATT_PROPERTY_NOTIFY | RSI_BLE_ATT_PROPERTY_INDICATE, // Set read, write, write without response diff --git a/src/platform/silabs/rs911x/wfx_sl_ble_init.h b/src/platform/silabs/rs911x/wfx_sl_ble_init.h index e3d11e0057a98f..a93eaa8be3137d 100644 --- a/src/platform/silabs/rs911x/wfx_sl_ble_init.h +++ b/src/platform/silabs/rs911x/wfx_sl_ble_init.h @@ -52,11 +52,21 @@ #include #include +typedef enum +{ + RSI_BLE_CONN_EVENT, + RSI_BLE_DISCONN_EVENT, + RSI_BLE_GATT_WRITE_EVENT, + RSI_BLE_MTU_EVENT, + RSI_BLE_GATT_INDICATION_CONFIRMATION, + RSI_BLE_RESP_ATT_VALUE, + RSI_BLE_EVENT_GATT_RD +} BleEventType_e; + typedef struct sl_wfx_msg_s { uint8_t connectionHandle; uint8_t bondingHandle; - uint32_t event_num; uint16_t reason; uint16_t event_id; uint16_t resp_status; @@ -66,14 +76,17 @@ typedef struct sl_wfx_msg_s rsi_ble_event_disconnect_t * resp_disconnect; rsi_ble_read_req_t * rsi_ble_read_req; rsi_ble_set_att_resp_t rsi_ble_event_set_att_rsp; - uint32_t ble_app_event_map; - uint32_t ble_app_event_mask; uint16_t rsi_ble_measurement_hndl; uint16_t rsi_ble_gatt_server_client_config_hndl; uint16_t subscribed; - } sl_wfx_msg_t; +typedef struct BleEvent_s +{ + BleEventType_e eventType; + sl_wfx_msg_t * eventData; +} BleEvent_t; + #define ATT_REC_IN_HOST (0) #define RSI_BT_CTRL_REMOTE_USER_TERMINATED (0x4E13) @@ -108,6 +121,8 @@ typedef struct sl_wfx_msg_s #define RSI_BLE_CHARACTERISTIC_TX_GATT_SERVER_CLIENT_HANDLE_LOCATION (5) // ALL Ble functions +void BlePostEvent(BleEvent_t * event); +void BleGetEvent(BleEvent_t event); void rsi_ble_on_connect_event(rsi_ble_event_conn_status_t * resp_conn); void rsi_ble_on_disconnect_event(rsi_ble_event_disconnect_t * resp_disconnect, uint16_t reason); void rsi_ble_on_enhance_conn_status_event(rsi_ble_event_enhance_conn_status_t * resp_enh_conn); From b0ee040f7e733c7f4ba8a99429504afac33a4640 Mon Sep 17 00:00:00 2001 From: chirag-silabs Date: Tue, 10 Sep 2024 23:50:14 +0530 Subject: [PATCH 02/17] removing the extern keyword for the queue --- src/platform/silabs/rs911x/BLEManagerImpl.cpp | 12 +++--------- src/platform/silabs/rs911x/wfx_sl_ble_init.cpp | 15 ++++++++++++++- src/platform/silabs/rs911x/wfx_sl_ble_init.h | 5 +++-- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/platform/silabs/rs911x/BLEManagerImpl.cpp b/src/platform/silabs/rs911x/BLEManagerImpl.cpp index d76bfb0050f127..6d120a3ba09b53 100644 --- a/src/platform/silabs/rs911x/BLEManagerImpl.cpp +++ b/src/platform/silabs/rs911x/BLEManagerImpl.cpp @@ -29,7 +29,6 @@ #include "cmsis_os2.h" #include - #include #include #include @@ -56,7 +55,6 @@ extern "C" { } #endif -#define WFX_QUEUE_SIZE 10 #define BLE_MIN_CONNECTION_INTERVAL_MS 24 #define BLE_MAX_CONNECTION_INTERVAL_MS 40 #define BLE_SLAVE_LATENCY_MS 0 @@ -68,7 +66,6 @@ uint8_t dev_address[RSI_DEV_ADDR_LEN]; uint16_t ble_measurement_hndl; osSemaphoreId_t sl_rs_ble_init_sem; -osMessageQueueId_t sBleEventQueue = NULL; osTimerId_t sbleAdvTimeoutTimer; @@ -99,7 +96,7 @@ void sl_ble_init() // registering the GAP callback functions rsi_ble_gap_register_callbacks(NULL, NULL, rsi_ble_on_disconnect_event, NULL, NULL, NULL, rsi_ble_on_enhance_conn_status_event, - NULL, NULL, NULL); + NULL, NULL, NULL); // registering the GATT call back functions rsi_ble_gatt_register_callbacks(NULL, NULL, NULL, NULL, NULL, NULL, NULL, rsi_ble_on_gatt_write_event, NULL, NULL, @@ -109,10 +106,7 @@ void sl_ble_init() // Exchange of GATT info with BLE stack rsi_ble_add_matter_service(); rsi_ble_set_random_address_with_value(randomAddrBLE); - - sBleEventQueue = osMessageQueueNew(WFX_QUEUE_SIZE, sizeof(WfxEvent_t), NULL); - VerifyOrDie(sBleEventQueue != nullptr); - + InitBleEventQueue(); chip::DeviceLayer::Internal::BLEMgrImpl().HandleBootEvent(); } @@ -179,7 +173,7 @@ void sl_ble_event_handling_task(void * args) // Application event map while (1) { - status = osMessageQueueGet(sBleEventQueue, &bleEvent, NULL, osWaitForever); + status = osMessageQueueGet(GetBleEventQueue(), &bleEvent, NULL, osWaitForever); if (status == osOK) { ProcessEvent(bleEvent); diff --git a/src/platform/silabs/rs911x/wfx_sl_ble_init.cpp b/src/platform/silabs/rs911x/wfx_sl_ble_init.cpp index 452ee017619863..a3f224987ebbe8 100644 --- a/src/platform/silabs/rs911x/wfx_sl_ble_init.cpp +++ b/src/platform/silabs/rs911x/wfx_sl_ble_init.cpp @@ -29,6 +29,8 @@ extern "C" { #ifdef __cplusplus } #endif +#include + #include "silabs_utils.h" // Global Variables @@ -37,12 +39,23 @@ sl_wfx_msg_t event_msg; BleEvent_t bleEvent; -extern osMessageQueueId_t sBleEventQueue; +static osMessageQueueId_t sBleEventQueue = NULL; // Memory to initialize driver uint8_t bt_global_buf[BT_GLOBAL_BUFF_LEN]; const uint8_t ShortUUID_CHIPoBLEService[] = { 0xF6, 0xFF }; +void InitBleEventQueue() +{ + sBleEventQueue = osMessageQueueNew(WFX_QUEUE_SIZE, sizeof(WfxEvent_t), NULL); + VerifyOrDie(sBleEventQueue != nullptr); +} + +osMessageQueueId_t GetBleEventQueue() +{ + return sBleEventQueue; +} + void BlePostEvent(BleEvent_t * event) { sl_status_t status = osMessageQueuePut(sBleEventQueue, event, 0, 0); diff --git a/src/platform/silabs/rs911x/wfx_sl_ble_init.h b/src/platform/silabs/rs911x/wfx_sl_ble_init.h index a93eaa8be3137d..608cd328931999 100644 --- a/src/platform/silabs/rs911x/wfx_sl_ble_init.h +++ b/src/platform/silabs/rs911x/wfx_sl_ble_init.h @@ -88,6 +88,7 @@ typedef struct BleEvent_s } BleEvent_t; #define ATT_REC_IN_HOST (0) +#define WFX_QUEUE_SIZE 10 #define RSI_BT_CTRL_REMOTE_USER_TERMINATED (0x4E13) #define RSI_BT_CTRL_REMOTE_DEVICE_TERMINATED_CONNECTION_DUE_TO_LOW_RESOURCES (0x4E14) @@ -121,8 +122,8 @@ typedef struct BleEvent_s #define RSI_BLE_CHARACTERISTIC_TX_GATT_SERVER_CLIENT_HANDLE_LOCATION (5) // ALL Ble functions -void BlePostEvent(BleEvent_t * event); -void BleGetEvent(BleEvent_t event); +void InitBleEventQueue(); +osMessageQueueId_t GetBleEventQueue(); void rsi_ble_on_connect_event(rsi_ble_event_conn_status_t * resp_conn); void rsi_ble_on_disconnect_event(rsi_ble_event_disconnect_t * resp_disconnect, uint16_t reason); void rsi_ble_on_enhance_conn_status_event(rsi_ble_event_enhance_conn_status_t * resp_enh_conn); From dee0bbbda18178a6dc57c90722b2533c18ce1598 Mon Sep 17 00:00:00 2001 From: chirag-silabs Date: Wed, 11 Sep 2024 00:00:35 +0530 Subject: [PATCH 03/17] cleanup of ble defines and variables --- src/platform/silabs/rs911x/BLEManagerImpl.cpp | 7 +------ src/platform/silabs/rs911x/wfx_sl_ble_init.cpp | 17 ++++------------- src/platform/silabs/rs911x/wfx_sl_ble_init.h | 5 +---- 3 files changed, 6 insertions(+), 23 deletions(-) diff --git a/src/platform/silabs/rs911x/BLEManagerImpl.cpp b/src/platform/silabs/rs911x/BLEManagerImpl.cpp index 6d120a3ba09b53..4cbcfdf8d18931 100644 --- a/src/platform/silabs/rs911x/BLEManagerImpl.cpp +++ b/src/platform/silabs/rs911x/BLEManagerImpl.cpp @@ -26,7 +26,6 @@ #include #if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE -#include "cmsis_os2.h" #include #include @@ -39,9 +38,6 @@ #include #endif -// #ifndef SLI_SI91X_MCU_INTERFACE -// #include "rail.h" -// #endif #include #ifdef __cplusplus extern "C" { @@ -66,7 +62,6 @@ uint8_t dev_address[RSI_DEV_ADDR_LEN]; uint16_t ble_measurement_hndl; osSemaphoreId_t sl_rs_ble_init_sem; - osTimerId_t sbleAdvTimeoutTimer; static osThreadId_t sBleThread; @@ -96,7 +91,7 @@ void sl_ble_init() // registering the GAP callback functions rsi_ble_gap_register_callbacks(NULL, NULL, rsi_ble_on_disconnect_event, NULL, NULL, NULL, rsi_ble_on_enhance_conn_status_event, - NULL, NULL, NULL); + NULL, NULL, NULL); // registering the GATT call back functions rsi_ble_gatt_register_callbacks(NULL, NULL, NULL, NULL, NULL, NULL, NULL, rsi_ble_on_gatt_write_event, NULL, NULL, diff --git a/src/platform/silabs/rs911x/wfx_sl_ble_init.cpp b/src/platform/silabs/rs911x/wfx_sl_ble_init.cpp index a3f224987ebbe8..1108d308b5611a 100644 --- a/src/platform/silabs/rs911x/wfx_sl_ble_init.cpp +++ b/src/platform/silabs/rs911x/wfx_sl_ble_init.cpp @@ -20,31 +20,22 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include +#include + #ifdef __cplusplus extern "C" { #endif #include "wfx_sl_ble_init.h" -#include "ble_config.h" -#include "cmsis_os2.h" #ifdef __cplusplus } #endif -#include - -#include "silabs_utils.h" // Global Variables rsi_ble_t att_list; -sl_wfx_msg_t event_msg; - BleEvent_t bleEvent; - static osMessageQueueId_t sBleEventQueue = NULL; -// Memory to initialize driver -uint8_t bt_global_buf[BT_GLOBAL_BUFF_LEN]; -const uint8_t ShortUUID_CHIPoBLEService[] = { 0xF6, 0xFF }; - void InitBleEventQueue() { sBleEventQueue = osMessageQueueNew(WFX_QUEUE_SIZE, sizeof(WfxEvent_t), NULL); @@ -61,7 +52,7 @@ void BlePostEvent(BleEvent_t * event) sl_status_t status = osMessageQueuePut(sBleEventQueue, event, 0, 0); if (status != osOK) { - SILABS_LOG("BlePostEvent: failed to post event: 0x%lx", status); + ChipLogError(DeviceLayer,"BlePostEvent: failed to post event: 0x%lx", status); // TODO: Handle error, requeue event depending on queue size or notify relevant task, Chipdie, etc. } } diff --git a/src/platform/silabs/rs911x/wfx_sl_ble_init.h b/src/platform/silabs/rs911x/wfx_sl_ble_init.h index 608cd328931999..0bfbd303a5eb32 100644 --- a/src/platform/silabs/rs911x/wfx_sl_ble_init.h +++ b/src/platform/silabs/rs911x/wfx_sl_ble_init.h @@ -29,11 +29,8 @@ #define WFX_SL_BLE_INIT // BLE include file to refer BLE APIs -#include "FreeRTOS.h" +#include "cmsis_os2.h" #include "ble_config.h" -#include "event_groups.h" -#include "task.h" -#include "timers.h" #include "wfx_host_events.h" #include "wfx_rsi.h" #include From f09533dc97dcaf19dfe97a67b3784c5892ed0a33 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Tue, 10 Sep 2024 18:33:46 +0000 Subject: [PATCH 04/17] Restyled by whitespace --- src/platform/silabs/rs911x/BLEManagerImpl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platform/silabs/rs911x/BLEManagerImpl.cpp b/src/platform/silabs/rs911x/BLEManagerImpl.cpp index 4cbcfdf8d18931..fee42e82ffce98 100644 --- a/src/platform/silabs/rs911x/BLEManagerImpl.cpp +++ b/src/platform/silabs/rs911x/BLEManagerImpl.cpp @@ -161,7 +161,7 @@ void sl_ble_event_handling_task(void * args) //! This semaphore is waiting for wifi module initialization. osSemaphoreAcquire(sl_rs_ble_init_sem, osWaitForever); - + // This function initialize BLE and start BLE advertisement. sl_ble_init(); From b10dcfc46b3edced8b8989430f5870d90042e19e Mon Sep 17 00:00:00 2001 From: chirag-silabs Date: Wed, 11 Sep 2024 00:20:13 +0530 Subject: [PATCH 05/17] restyling the PR --- src/platform/silabs/BLEManagerImpl.h | 4 +- src/platform/silabs/rs911x/BLEManagerImpl.cpp | 7 ++- .../silabs/rs911x/wfx_sl_ble_init.cpp | 49 ++++++++----------- src/platform/silabs/rs911x/wfx_sl_ble_init.h | 2 +- 4 files changed, 26 insertions(+), 36 deletions(-) diff --git a/src/platform/silabs/BLEManagerImpl.h b/src/platform/silabs/BLEManagerImpl.h index bf6f9f14bd16b6..15e4852c78dd52 100644 --- a/src/platform/silabs/BLEManagerImpl.h +++ b/src/platform/silabs/BLEManagerImpl.h @@ -24,16 +24,14 @@ #pragma once #if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE -#include "FreeRTOS.h" -#include "timers.h" #if (SLI_SI91X_ENABLE_BLE || RSI_BLE_ENABLE) #ifdef __cplusplus extern "C" { #endif // __cplusplus +#include "wfx_sl_ble_init.h" #include #include #include -#include "wfx_sl_ble_init.h" #ifdef __cplusplus } #endif // __cplusplus diff --git a/src/platform/silabs/rs911x/BLEManagerImpl.cpp b/src/platform/silabs/rs911x/BLEManagerImpl.cpp index fee42e82ffce98..837308e40e18cd 100644 --- a/src/platform/silabs/rs911x/BLEManagerImpl.cpp +++ b/src/platform/silabs/rs911x/BLEManagerImpl.cpp @@ -117,7 +117,7 @@ void ProcessEvent(BleEvent_t inEvent) rsi_ble_set_data_len(inEvent.eventData->resp_enh_conn.dev_addr, RSI_BLE_TX_OCTETS, RSI_BLE_TX_TIME); // Used to send the Indication confirmation - memcpy(dev_address,inEvent.eventData->resp_enh_conn.dev_addr, RSI_DEV_ADDR_LEN); + memcpy(dev_address, inEvent.eventData->resp_enh_conn.dev_addr, RSI_DEV_ADDR_LEN); ble_measurement_hndl = inEvent.eventData->rsi_ble_measurement_hndl; } break; @@ -150,7 +150,7 @@ void ProcessEvent(BleEvent_t inEvent) } break; default: - break; + break; } } @@ -426,8 +426,7 @@ CHIP_ERROR BLEManagerImpl::SendIndication(BLE_CONNECTION_OBJECT conId, const Chi PacketBufferHandle data) { int32_t status = 0; - status = rsi_ble_indicate_value(dev_address, ble_measurement_hndl,data->DataLength(),data->Start()); - + status = rsi_ble_indicate_value(dev_address, ble_measurement_hndl, data->DataLength(), data->Start()); if (status != RSI_SUCCESS) { ChipLogProgress(DeviceLayer, "indication failed with error code %lx ", status); diff --git a/src/platform/silabs/rs911x/wfx_sl_ble_init.cpp b/src/platform/silabs/rs911x/wfx_sl_ble_init.cpp index 1108d308b5611a..673f86cac96c5f 100644 --- a/src/platform/silabs/rs911x/wfx_sl_ble_init.cpp +++ b/src/platform/silabs/rs911x/wfx_sl_ble_init.cpp @@ -1,5 +1,5 @@ /******************************************************************************* - * @file wfx_sl_ble_init.c + * @file wfx_sl_ble_init.cpp * @brief ******************************************************************************* * # License @@ -20,8 +20,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include #include +#include #ifdef __cplusplus extern "C" { @@ -52,7 +52,7 @@ void BlePostEvent(BleEvent_t * event) sl_status_t status = osMessageQueuePut(sBleEventQueue, event, 0, 0); if (status != osOK) { - ChipLogError(DeviceLayer,"BlePostEvent: failed to post event: 0x%lx", status); + ChipLogError(DeviceLayer, "BlePostEvent: failed to post event: 0x%lx", status); // TODO: Handle error, requeue event depending on queue size or notify relevant task, Chipdie, etc. } } @@ -85,7 +85,7 @@ void rsi_ble_on_mtu_event(rsi_ble_event_mtu_t * rsi_ble_mtu) */ void rsi_ble_on_gatt_write_event(uint16_t event_id, rsi_ble_event_write_t * rsi_ble_write) { - bleEvent.eventType = RSI_BLE_GATT_WRITE_EVENT; + bleEvent.eventType = RSI_BLE_GATT_WRITE_EVENT; bleEvent.eventData->event_id = event_id; memcpy(&bleEvent.eventData->rsi_ble_write, rsi_ble_write, sizeof(rsi_ble_event_write_t)); BlePostEvent(&bleEvent); @@ -102,7 +102,7 @@ void rsi_ble_on_gatt_write_event(uint16_t event_id, rsi_ble_event_write_t * rsi_ */ void rsi_ble_on_enhance_conn_status_event(rsi_ble_event_enhance_conn_status_t * resp_enh_conn) { - bleEvent.eventType = RSI_BLE_CONN_EVENT; + bleEvent.eventType = RSI_BLE_CONN_EVENT; bleEvent.eventData->connectionHandle = 1; bleEvent.eventData->bondingHandle = 255; memcpy(bleEvent.eventData->resp_enh_conn.dev_addr, resp_enh_conn->dev_addr, RSI_DEV_ADDR_LEN); @@ -137,7 +137,7 @@ void rsi_ble_on_disconnect_event(rsi_ble_event_disconnect_t * resp_disconnect, u */ void rsi_ble_on_event_indication_confirmation(uint16_t resp_status, rsi_ble_set_att_resp_t * rsi_ble_event_set_att_rsp) { - bleEvent.eventType = RSI_BLE_GATT_INDICATION_CONFIRMATION; + bleEvent.eventType = RSI_BLE_GATT_INDICATION_CONFIRMATION; bleEvent.eventData->resp_status = resp_status; memcpy(&bleEvent.eventData->rsi_ble_event_set_att_rsp, rsi_ble_event_set_att_rsp, sizeof(rsi_ble_set_att_resp_t)); BlePostEvent(&bleEvent); @@ -155,7 +155,7 @@ void rsi_ble_on_event_indication_confirmation(uint16_t resp_status, rsi_ble_set_ */ void rsi_ble_on_read_req_event(uint16_t event_id, rsi_ble_read_req_t * rsi_ble_read_req) { - bleEvent.eventType = RSI_BLE_EVENT_GATT_RD; + bleEvent.eventType = RSI_BLE_EVENT_GATT_RD; bleEvent.eventData->event_id = event_id; memcpy(&bleEvent.eventData->rsi_ble_read_req, rsi_ble_read_req, sizeof(rsi_ble_read_req_t)); BlePostEvent(&bleEvent); @@ -326,16 +326,12 @@ uint32_t rsi_ble_add_matter_service(void) uint8_t data[RSI_BLE_MATTER_CUSTOM_SERVICE_DATA_LENGTH] = { RSI_BLE_MATTER_CUSTOM_SERVICE_DATA }; static const uuid_t custom_characteristic_RX = { - .size = RSI_BLE_CUSTOM_CHARACTERISTIC_RX_SIZE, + .size = RSI_BLE_CUSTOM_CHARACTERISTIC_RX_SIZE, .reserved = { RSI_BLE_CUSTOM_CHARACTERISTIC_RX_RESERVED }, - .val = { - .val128 = { - .data1 = { RSI_BLE_CUSTOM_CHARACTERISTIC_RX_VALUE_128_DATA_1 }, - .data2 = { RSI_BLE_CUSTOM_CHARACTERISTIC_RX_VALUE_128_DATA_2 }, - .data3 = { RSI_BLE_CUSTOM_CHARACTERISTIC_RX_VALUE_128_DATA_3 }, - .data4 = { RSI_BLE_CUSTOM_CHARACTERISTIC_RX_VALUE_128_DATA_4 } - } - } + .val = { .val128 = { .data1 = { RSI_BLE_CUSTOM_CHARACTERISTIC_RX_VALUE_128_DATA_1 }, + .data2 = { RSI_BLE_CUSTOM_CHARACTERISTIC_RX_VALUE_128_DATA_2 }, + .data3 = { RSI_BLE_CUSTOM_CHARACTERISTIC_RX_VALUE_128_DATA_3 }, + .data4 = { RSI_BLE_CUSTOM_CHARACTERISTIC_RX_VALUE_128_DATA_4 } } } }; rsi_ble_resp_add_serv_t new_serv_resp = { 0 }; @@ -353,17 +349,13 @@ uint32_t rsi_ble_add_matter_service(void) RSI_BLE_ATT_PROPERTY_WRITE | RSI_BLE_ATT_PROPERTY_READ, // Set read, write, write without response data, sizeof(data), ATT_REC_IN_HOST); - static const uuid_t custom_characteristic_TX = { - .size = RSI_BLE_CUSTOM_CHARACTERISTIC_TX_SIZE, - .reserved = { RSI_BLE_CUSTOM_CHARACTERISTIC_TX_RESERVED }, - .val = { - .val128 = { - .data1 = { RSI_BLE_CUSTOM_CHARACTERISTIC_TX_VALUE_128_DATA_1 }, - .data2 = { RSI_BLE_CUSTOM_CHARACTERISTIC_TX_VALUE_128_DATA_2 }, - .data3 = { RSI_BLE_CUSTOM_CHARACTERISTIC_TX_VALUE_128_DATA_3 }, - .data4 = { RSI_BLE_CUSTOM_CHARACTERISTIC_TX_VALUE_128_DATA_4 } - } - } + static const uuid_t custom_characteristic_TX = { + .size = RSI_BLE_CUSTOM_CHARACTERISTIC_TX_SIZE, + .reserved = { RSI_BLE_CUSTOM_CHARACTERISTIC_TX_RESERVED }, + .val = { .val128 = { .data1 = { RSI_BLE_CUSTOM_CHARACTERISTIC_TX_VALUE_128_DATA_1 }, + .data2 = { RSI_BLE_CUSTOM_CHARACTERISTIC_TX_VALUE_128_DATA_2 }, + .data3 = { RSI_BLE_CUSTOM_CHARACTERISTIC_TX_VALUE_128_DATA_3 }, + .data4 = { RSI_BLE_CUSTOM_CHARACTERISTIC_TX_VALUE_128_DATA_4 } } } }; // Adding custom characteristic declaration to the custom service @@ -374,7 +366,8 @@ uint32_t rsi_ble_add_matter_service(void) new_serv_resp.start_handle + RSI_BLE_CHARACTERISTIC_TX_MEASUREMENT_HANDLE_LOCATION, custom_characteristic_TX); // Adding characteristic value attribute to the service - bleEvent.eventData->rsi_ble_measurement_hndl = new_serv_resp.start_handle + RSI_BLE_CHARACTERISTIC_TX_MEASUREMENT_HANDLE_LOCATION; + bleEvent.eventData->rsi_ble_measurement_hndl = + new_serv_resp.start_handle + RSI_BLE_CHARACTERISTIC_TX_MEASUREMENT_HANDLE_LOCATION; // Adding characteristic value attribute to the service bleEvent.eventData->rsi_ble_gatt_server_client_config_hndl = diff --git a/src/platform/silabs/rs911x/wfx_sl_ble_init.h b/src/platform/silabs/rs911x/wfx_sl_ble_init.h index 0bfbd303a5eb32..fa1e0b971ac4d5 100644 --- a/src/platform/silabs/rs911x/wfx_sl_ble_init.h +++ b/src/platform/silabs/rs911x/wfx_sl_ble_init.h @@ -29,8 +29,8 @@ #define WFX_SL_BLE_INIT // BLE include file to refer BLE APIs -#include "cmsis_os2.h" #include "ble_config.h" +#include "cmsis_os2.h" #include "wfx_host_events.h" #include "wfx_rsi.h" #include From b4620fb274f810eb1e22cd3d61adf5dc3b3851f5 Mon Sep 17 00:00:00 2001 From: chirag-silabs Date: Wed, 11 Sep 2024 00:20:40 +0530 Subject: [PATCH 06/17] removing the temp change --- examples/platform/silabs/BaseApplication.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/platform/silabs/BaseApplication.cpp b/examples/platform/silabs/BaseApplication.cpp index a488e4efa251da..cbef67996c4528 100644 --- a/examples/platform/silabs/BaseApplication.cpp +++ b/examples/platform/silabs/BaseApplication.cpp @@ -857,14 +857,14 @@ void BaseApplication::OnPlatformEvent(const ChipDeviceEvent * event, intptr_t) SILABS_LOG("Failed to initialize DIC module\n"); } #endif // DIC_ENABLE -// #ifdef DISPLAY_ENABLED -// SilabsLCD::Screen_e screen; -// AppTask::GetLCD().GetScreen(screen); -// // Update the LCD screen with SSID and connected state -// VerifyOrReturn(screen == SilabsLCD::Screen_e::StatusScreen); -// BaseApplication::UpdateLCDStatusScreen(false); -// AppTask::GetLCD().SetScreen(screen); -// #endif // DISPLAY_ENABLED +#ifdef DISPLAY_ENABLED + SilabsLCD::Screen_e screen; + AppTask::GetLCD().GetScreen(screen); + // Update the LCD screen with SSID and connected state + VerifyOrReturn(screen == SilabsLCD::Screen_e::StatusScreen); + BaseApplication::UpdateLCDStatusScreen(false); + AppTask::GetLCD().SetScreen(screen); +#endif // DISPLAY_ENABLED if ((event->ThreadConnectivityChange.Result == kConnectivity_Established) || (event->InternetConnectivityChange.IPv6 == kConnectivity_Established)) { From 73b54339e57642ff4c5dd83ba0e1f321506cde75 Mon Sep 17 00:00:00 2001 From: chirag-silabs Date: Wed, 11 Sep 2024 00:22:59 +0530 Subject: [PATCH 07/17] restyling the PR --- src/platform/silabs/rs911x/wfx_sl_ble_init.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platform/silabs/rs911x/wfx_sl_ble_init.cpp b/src/platform/silabs/rs911x/wfx_sl_ble_init.cpp index 673f86cac96c5f..ddfefa2e117f41 100644 --- a/src/platform/silabs/rs911x/wfx_sl_ble_init.cpp +++ b/src/platform/silabs/rs911x/wfx_sl_ble_init.cpp @@ -121,7 +121,7 @@ void rsi_ble_on_enhance_conn_status_event(rsi_ble_event_enhance_conn_status_t * */ void rsi_ble_on_disconnect_event(rsi_ble_event_disconnect_t * resp_disconnect, uint16_t reason) { - bleEvent.eventType = RSI_BLE_DISCONN_EVENT; + bleEvent.eventType = RSI_BLE_DISCONN_EVENT; bleEvent.eventData->reason = reason; BlePostEvent(&bleEvent); } From bc0a9a1ad97a8adc08e01ec944afe9be5def82f2 Mon Sep 17 00:00:00 2001 From: chirag-silabs Date: Wed, 11 Sep 2024 11:03:26 +0530 Subject: [PATCH 08/17] reverting BLEManagerImpl.h to fix --- src/platform/silabs/BLEManagerImpl.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/platform/silabs/BLEManagerImpl.h b/src/platform/silabs/BLEManagerImpl.h index 15e4852c78dd52..0ab4e3c81737e5 100644 --- a/src/platform/silabs/BLEManagerImpl.h +++ b/src/platform/silabs/BLEManagerImpl.h @@ -24,6 +24,8 @@ #pragma once #if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE +#include "FreeRTOS.h" +#include "timers.h" #if (SLI_SI91X_ENABLE_BLE || RSI_BLE_ENABLE) #ifdef __cplusplus extern "C" { From 52219f000052d6365a1fc0e23ed691e8394976b3 Mon Sep 17 00:00:00 2001 From: chirag-silabs Date: Wed, 11 Sep 2024 11:37:20 +0530 Subject: [PATCH 09/17] fixing the build for the 91x ncp --- src/platform/silabs/efr32/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platform/silabs/efr32/BUILD.gn b/src/platform/silabs/efr32/BUILD.gn index 177cfc01fa33fe..a0827df0725b30 100644 --- a/src/platform/silabs/efr32/BUILD.gn +++ b/src/platform/silabs/efr32/BUILD.gn @@ -70,7 +70,7 @@ static_library("efr32") { sources += [ "../rs911x/BLEManagerImpl.cpp", "../rs911x/rsi_ble_config.h", - "../rs911x/wfx_sl_ble_init.c", + "../rs911x/wfx_sl_ble_init.cpp", "../rs911x/wfx_sl_ble_init.h", ] } else { From 7ddd0df61259d4ca3c7c667449704549a5aec6db Mon Sep 17 00:00:00 2001 From: chirag-silabs Date: Tue, 17 Sep 2024 22:47:33 +0530 Subject: [PATCH 10/17] addressing review comments --- src/platform/silabs/BLEManagerImpl.h | 10 ++ src/platform/silabs/rs911x/BLEManagerImpl.cpp | 128 ++++++++++-------- .../silabs/rs911x/wfx_sl_ble_init.cpp | 39 ++---- 3 files changed, 90 insertions(+), 87 deletions(-) diff --git a/src/platform/silabs/BLEManagerImpl.h b/src/platform/silabs/BLEManagerImpl.h index 0ab4e3c81737e5..ed3879580a7537 100644 --- a/src/platform/silabs/BLEManagerImpl.h +++ b/src/platform/silabs/BLEManagerImpl.h @@ -59,6 +59,8 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla void HandleBootEvent(void); #if (SLI_SI91X_ENABLE_BLE || RSI_BLE_ENABLE) + // Used for posting the event in the BLE queue + void BlePostEvent(BleEvent_t * event); void HandleConnectEvent(sl_wfx_msg_t * evt); void HandleConnectionCloseEvent(sl_wfx_msg_t * evt); void HandleWriteEvent(sl_wfx_msg_t * evt); @@ -94,6 +96,14 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla // the implementation methods provided by this class. friend BLEManager; +#if (SLI_SI91X_ENABLE_BLE || RSI_BLE_ENABLE) + // rs91x BLE task handling + osMessageQueueId_t sBleEventQueue = NULL; + static void sl_ble_event_handling_task(void * args); + void sl_ble_init(); + void ProcessEvent(BleEvent_t inEvent); +#endif + // ===== Members that implement the BLEManager internal interface. CHIP_ERROR _Init(void); diff --git a/src/platform/silabs/rs911x/BLEManagerImpl.cpp b/src/platform/silabs/rs911x/BLEManagerImpl.cpp index 837308e40e18cd..b20e7b6a590740 100644 --- a/src/platform/silabs/rs911x/BLEManagerImpl.cpp +++ b/src/platform/silabs/rs911x/BLEManagerImpl.cpp @@ -80,32 +80,43 @@ using namespace ::chip; using namespace ::chip::Ble; using namespace ::chip::DeviceLayer::Internal; -void sl_ble_init() -{ - uint8_t randomAddrBLE[RSI_BLE_ADDR_LENGTH] = { 0 }; - uint64_t randomAddr = chip::Crypto::GetRandU64(); - memcpy(randomAddrBLE, &randomAddr, RSI_BLE_ADDR_LENGTH); - // Set the two least significant bits as the first 2 bits of the address has to be '11' to ensure the address is a random - // non-resolvable private address - randomAddrBLE[(RSI_BLE_ADDR_LENGTH - 1)] |= 0xC0; +namespace chip { +namespace DeviceLayer { +namespace Internal { - // registering the GAP callback functions - rsi_ble_gap_register_callbacks(NULL, NULL, rsi_ble_on_disconnect_event, NULL, NULL, NULL, rsi_ble_on_enhance_conn_status_event, - NULL, NULL, NULL); +namespace { - // registering the GATT call back functions - rsi_ble_gatt_register_callbacks(NULL, NULL, NULL, NULL, NULL, NULL, NULL, rsi_ble_on_gatt_write_event, NULL, NULL, - rsi_ble_on_read_req_event, rsi_ble_on_mtu_event, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, rsi_ble_on_event_indication_confirmation, NULL); +#define CHIP_ADV_DATA_TYPE_FLAGS 0x01 +#define CHIP_ADV_DATA_TYPE_UUID 0x03 +#define CHIP_ADV_DATA_TYPE_NAME 0x09 +#define CHIP_ADV_DATA_TYPE_SERVICE_DATA 0x16 - // Exchange of GATT info with BLE stack - rsi_ble_add_matter_service(); - rsi_ble_set_random_address_with_value(randomAddrBLE); - InitBleEventQueue(); - chip::DeviceLayer::Internal::BLEMgrImpl().HandleBootEvent(); -} +#define CHIP_ADV_DATA_FLAGS 0x06 + +#define CHIP_ADV_DATA 0 +#define CHIP_ADV_SCAN_RESPONSE_DATA 1 +#define CHIP_ADV_SHORT_UUID_LEN 2 + +#define MAX_RESPONSE_DATA_LEN 31 +#define MAX_ADV_DATA_LEN 31 + +// Timer Frequency used. +#define TIMER_CLK_FREQ ((uint32_t) 32768) + +// Convert msec to timer ticks. +#define TIMER_MS_2_TIMERTICK(ms) ((TIMER_CLK_FREQ * ms) / 1000) +#define TIMER_S_2_TIMERTICK(s) (TIMER_CLK_FREQ * s) -void ProcessEvent(BleEvent_t inEvent) +const uint8_t UUID_CHIPoBLEService[] = { 0xFB, 0x34, 0x9B, 0x5F, 0x80, 0x00, 0x00, 0x80, + 0x00, 0x10, 0x00, 0x00, 0xF6, 0xFF, 0x00, 0x00 }; +const uint8_t ShortUUID_CHIPoBLEService[] = { 0xF6, 0xFF }; + +} // namespace + +BLEManagerImpl BLEManagerImpl::sInstance; + + +void BLEManagerImpl::ProcessEvent(BleEvent_t inEvent) { switch (inEvent.eventType) { @@ -154,7 +165,17 @@ void ProcessEvent(BleEvent_t inEvent) } } -void sl_ble_event_handling_task(void * args) +void BLEManagerImpl::BlePostEvent(BleEvent_t * event) +{ + sl_status_t status = osMessageQueuePut(sInstance.sBleEventQueue, event, 0, 0); + if (status != osOK) + { + ChipLogError(DeviceLayer, "BlePostEvent: failed to post event: 0x%lx", status); + // TODO: Handle error, requeue event depending on queue size or notify relevant task, Chipdie, etc. + } +} + +void BLEManagerImpl::sl_ble_event_handling_task(void * args) { sl_status_t status; BleEvent_t bleEvent; @@ -163,15 +184,15 @@ void sl_ble_event_handling_task(void * args) osSemaphoreAcquire(sl_rs_ble_init_sem, osWaitForever); // This function initialize BLE and start BLE advertisement. - sl_ble_init(); + sInstance.sl_ble_init(); // Application event map while (1) { - status = osMessageQueueGet(GetBleEventQueue(), &bleEvent, NULL, osWaitForever); + status = osMessageQueueGet(sInstance.sBleEventQueue, &bleEvent, NULL, osWaitForever); if (status == osOK) { - ProcessEvent(bleEvent); + sInstance.ProcessEvent(bleEvent); } else { @@ -180,40 +201,33 @@ void sl_ble_event_handling_task(void * args) } } -namespace chip { -namespace DeviceLayer { -namespace Internal { - -namespace { - -#define CHIP_ADV_DATA_TYPE_FLAGS 0x01 -#define CHIP_ADV_DATA_TYPE_UUID 0x03 -#define CHIP_ADV_DATA_TYPE_NAME 0x09 -#define CHIP_ADV_DATA_TYPE_SERVICE_DATA 0x16 - -#define CHIP_ADV_DATA_FLAGS 0x06 - -#define CHIP_ADV_DATA 0 -#define CHIP_ADV_SCAN_RESPONSE_DATA 1 -#define CHIP_ADV_SHORT_UUID_LEN 2 - -#define MAX_RESPONSE_DATA_LEN 31 -#define MAX_ADV_DATA_LEN 31 - -// Timer Frequency used. -#define TIMER_CLK_FREQ ((uint32_t) 32768) +void BLEManagerImpl::sl_ble_init() +{ + uint8_t randomAddrBLE[RSI_BLE_ADDR_LENGTH] = { 0 }; + uint64_t randomAddr = chip::Crypto::GetRandU64(); + memcpy(randomAddrBLE, &randomAddr, RSI_BLE_ADDR_LENGTH); + // Set the two least significant bits as the first 2 bits of the address has to be '11' to ensure the address is a random + // non-resolvable private address + randomAddrBLE[(RSI_BLE_ADDR_LENGTH - 1)] |= 0xC0; -// Convert msec to timer ticks. -#define TIMER_MS_2_TIMERTICK(ms) ((TIMER_CLK_FREQ * ms) / 1000) -#define TIMER_S_2_TIMERTICK(s) (TIMER_CLK_FREQ * s) + // registering the GAP callback functions + rsi_ble_gap_register_callbacks(NULL, NULL, rsi_ble_on_disconnect_event, NULL, NULL, NULL, rsi_ble_on_enhance_conn_status_event, + NULL, NULL, NULL); -const uint8_t UUID_CHIPoBLEService[] = { 0xFB, 0x34, 0x9B, 0x5F, 0x80, 0x00, 0x00, 0x80, - 0x00, 0x10, 0x00, 0x00, 0xF6, 0xFF, 0x00, 0x00 }; -const uint8_t ShortUUID_CHIPoBLEService[] = { 0xF6, 0xFF }; + // registering the GATT call back functions + rsi_ble_gatt_register_callbacks(NULL, NULL, NULL, NULL, NULL, NULL, NULL, rsi_ble_on_gatt_write_event, NULL, NULL, + rsi_ble_on_read_req_event, rsi_ble_on_mtu_event, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, rsi_ble_on_event_indication_confirmation, NULL); -} // namespace + // Exchange of GATT info with BLE stack + rsi_ble_add_matter_service(); + rsi_ble_set_random_address_with_value(randomAddrBLE); + + sInstance.sBleEventQueue = osMessageQueueNew(WFX_QUEUE_SIZE, sizeof(WfxEvent_t), NULL); + VerifyOrDie(sInstance.sBleEventQueue != nullptr); -BLEManagerImpl BLEManagerImpl::sInstance; + chip::DeviceLayer::Internal::BLEMgrImpl().HandleBootEvent(); +} CHIP_ERROR BLEManagerImpl::_Init() { @@ -221,7 +235,7 @@ CHIP_ERROR BLEManagerImpl::_Init() sl_rs_ble_init_sem = osSemaphoreNew(1, 0, NULL); - sBleThread = osThreadNew(sl_ble_event_handling_task, NULL, &kBleTaskAttr); + sBleThread = osThreadNew(sInstance.sl_ble_event_handling_task, NULL, &kBleTaskAttr); VerifyOrReturnError(sBleThread != nullptr, CHIP_ERROR_INCORRECT_STATE); diff --git a/src/platform/silabs/rs911x/wfx_sl_ble_init.cpp b/src/platform/silabs/rs911x/wfx_sl_ble_init.cpp index ddfefa2e117f41..13251c6c1e8e14 100644 --- a/src/platform/silabs/rs911x/wfx_sl_ble_init.cpp +++ b/src/platform/silabs/rs911x/wfx_sl_ble_init.cpp @@ -22,6 +22,8 @@ */ #include #include +// #include +#include #ifdef __cplusplus extern "C" { @@ -32,30 +34,7 @@ extern "C" { #endif // Global Variables -rsi_ble_t att_list; BleEvent_t bleEvent; -static osMessageQueueId_t sBleEventQueue = NULL; - -void InitBleEventQueue() -{ - sBleEventQueue = osMessageQueueNew(WFX_QUEUE_SIZE, sizeof(WfxEvent_t), NULL); - VerifyOrDie(sBleEventQueue != nullptr); -} - -osMessageQueueId_t GetBleEventQueue() -{ - return sBleEventQueue; -} - -void BlePostEvent(BleEvent_t * event) -{ - sl_status_t status = osMessageQueuePut(sBleEventQueue, event, 0, 0); - if (status != osOK) - { - ChipLogError(DeviceLayer, "BlePostEvent: failed to post event: 0x%lx", status); - // TODO: Handle error, requeue event depending on queue size or notify relevant task, Chipdie, etc. - } -} /*==============================================*/ /** @@ -70,7 +49,7 @@ void rsi_ble_on_mtu_event(rsi_ble_event_mtu_t * rsi_ble_mtu) { bleEvent.eventType = RSI_BLE_MTU_EVENT; memcpy(&bleEvent.eventData->rsi_ble_mtu, rsi_ble_mtu, sizeof(rsi_ble_event_mtu_t)); - BlePostEvent(&bleEvent); + chip::DeviceLayer::Internal::BLEMgrImpl().BlePostEvent(&bleEvent); } /*==============================================*/ @@ -88,7 +67,7 @@ void rsi_ble_on_gatt_write_event(uint16_t event_id, rsi_ble_event_write_t * rsi_ bleEvent.eventType = RSI_BLE_GATT_WRITE_EVENT; bleEvent.eventData->event_id = event_id; memcpy(&bleEvent.eventData->rsi_ble_write, rsi_ble_write, sizeof(rsi_ble_event_write_t)); - BlePostEvent(&bleEvent); + chip::DeviceLayer::Internal::BLEMgrImpl().BlePostEvent(&bleEvent); } /*==============================================*/ @@ -106,7 +85,7 @@ void rsi_ble_on_enhance_conn_status_event(rsi_ble_event_enhance_conn_status_t * bleEvent.eventData->connectionHandle = 1; bleEvent.eventData->bondingHandle = 255; memcpy(bleEvent.eventData->resp_enh_conn.dev_addr, resp_enh_conn->dev_addr, RSI_DEV_ADDR_LEN); - BlePostEvent(&bleEvent); + chip::DeviceLayer::Internal::BLEMgrImpl().BlePostEvent(&bleEvent); } /*==============================================*/ @@ -123,7 +102,7 @@ void rsi_ble_on_disconnect_event(rsi_ble_event_disconnect_t * resp_disconnect, u { bleEvent.eventType = RSI_BLE_DISCONN_EVENT; bleEvent.eventData->reason = reason; - BlePostEvent(&bleEvent); + chip::DeviceLayer::Internal::BLEMgrImpl().BlePostEvent(&bleEvent); } /*==============================================*/ @@ -140,7 +119,7 @@ void rsi_ble_on_event_indication_confirmation(uint16_t resp_status, rsi_ble_set_ bleEvent.eventType = RSI_BLE_GATT_INDICATION_CONFIRMATION; bleEvent.eventData->resp_status = resp_status; memcpy(&bleEvent.eventData->rsi_ble_event_set_att_rsp, rsi_ble_event_set_att_rsp, sizeof(rsi_ble_set_att_resp_t)); - BlePostEvent(&bleEvent); + chip::DeviceLayer::Internal::BLEMgrImpl().BlePostEvent(&bleEvent); } /*==============================================*/ @@ -158,7 +137,7 @@ void rsi_ble_on_read_req_event(uint16_t event_id, rsi_ble_read_req_t * rsi_ble_r bleEvent.eventType = RSI_BLE_EVENT_GATT_RD; bleEvent.eventData->event_id = event_id; memcpy(&bleEvent.eventData->rsi_ble_read_req, rsi_ble_read_req, sizeof(rsi_ble_read_req_t)); - BlePostEvent(&bleEvent); + chip::DeviceLayer::Internal::BLEMgrImpl().BlePostEvent(&bleEvent); } /*==============================================*/ @@ -260,7 +239,7 @@ void rsi_ble_add_char_val_att(void * serv_handler, uint16_t handle, uuid_t att_t uint8_t data_len, uint8_t auth_read) { rsi_ble_req_add_att_t new_att = { 0 }; - + rsi_ble_t att_list; memset(&new_att, 0, sizeof(rsi_ble_req_add_att_t)); //! preparing the attributes new_att.serv_handler = serv_handler; From 1ba41df96776b18d0ad207f4483d761fac0f32a9 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Tue, 17 Sep 2024 17:17:54 +0000 Subject: [PATCH 11/17] Restyled by whitespace --- src/platform/silabs/BLEManagerImpl.h | 2 +- src/platform/silabs/rs911x/BLEManagerImpl.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/platform/silabs/BLEManagerImpl.h b/src/platform/silabs/BLEManagerImpl.h index ed3879580a7537..871dc6ff312593 100644 --- a/src/platform/silabs/BLEManagerImpl.h +++ b/src/platform/silabs/BLEManagerImpl.h @@ -97,7 +97,7 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla friend BLEManager; #if (SLI_SI91X_ENABLE_BLE || RSI_BLE_ENABLE) - // rs91x BLE task handling + // rs91x BLE task handling osMessageQueueId_t sBleEventQueue = NULL; static void sl_ble_event_handling_task(void * args); void sl_ble_init(); diff --git a/src/platform/silabs/rs911x/BLEManagerImpl.cpp b/src/platform/silabs/rs911x/BLEManagerImpl.cpp index b20e7b6a590740..28383f73c39952 100644 --- a/src/platform/silabs/rs911x/BLEManagerImpl.cpp +++ b/src/platform/silabs/rs911x/BLEManagerImpl.cpp @@ -222,7 +222,7 @@ void BLEManagerImpl::sl_ble_init() // Exchange of GATT info with BLE stack rsi_ble_add_matter_service(); rsi_ble_set_random_address_with_value(randomAddrBLE); - + sInstance.sBleEventQueue = osMessageQueueNew(WFX_QUEUE_SIZE, sizeof(WfxEvent_t), NULL); VerifyOrDie(sInstance.sBleEventQueue != nullptr); From 28d72193f6c0b53b7cb9ce05e5c914d95c4398dd Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Tue, 17 Sep 2024 17:17:55 +0000 Subject: [PATCH 12/17] Restyled by clang-format --- src/platform/silabs/rs911x/BLEManagerImpl.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/platform/silabs/rs911x/BLEManagerImpl.cpp b/src/platform/silabs/rs911x/BLEManagerImpl.cpp index 28383f73c39952..f3df02647314fc 100644 --- a/src/platform/silabs/rs911x/BLEManagerImpl.cpp +++ b/src/platform/silabs/rs911x/BLEManagerImpl.cpp @@ -115,7 +115,6 @@ const uint8_t ShortUUID_CHIPoBLEService[] = { 0xF6, 0xFF }; BLEManagerImpl BLEManagerImpl::sInstance; - void BLEManagerImpl::ProcessEvent(BleEvent_t inEvent) { switch (inEvent.eventType) From 05f15049fac5d7f9c57a1942dae76d1ff156748e Mon Sep 17 00:00:00 2001 From: chirag-silabs Date: Wed, 18 Sep 2024 11:58:37 +0530 Subject: [PATCH 13/17] modifying the file to have classes --- src/platform/silabs/BLEManagerImpl.h | 18 +-- src/platform/silabs/rs911x/BLEManagerImpl.cpp | 42 +++---- .../silabs/rs911x/wfx_sl_ble_init.cpp | 56 ++++----- src/platform/silabs/rs911x/wfx_sl_ble_init.h | 116 +++++++++--------- 4 files changed, 113 insertions(+), 119 deletions(-) diff --git a/src/platform/silabs/BLEManagerImpl.h b/src/platform/silabs/BLEManagerImpl.h index 871dc6ff312593..649b0362038a38 100644 --- a/src/platform/silabs/BLEManagerImpl.h +++ b/src/platform/silabs/BLEManagerImpl.h @@ -60,13 +60,13 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla #if (SLI_SI91X_ENABLE_BLE || RSI_BLE_ENABLE) // Used for posting the event in the BLE queue - void BlePostEvent(BleEvent_t * event); - void HandleConnectEvent(sl_wfx_msg_t * evt); - void HandleConnectionCloseEvent(sl_wfx_msg_t * evt); - void HandleWriteEvent(sl_wfx_msg_t * evt); - void UpdateMtu(sl_wfx_msg_t * evt); + void BlePostEvent(SilabsBleWrapper::BleEvent_t * event); + void HandleConnectEvent(SilabsBleWrapper::sl_wfx_msg_t * evt); + void HandleConnectionCloseEvent(SilabsBleWrapper::sl_wfx_msg_t * evt); + void HandleWriteEvent(SilabsBleWrapper::sl_wfx_msg_t * evt); + void UpdateMtu(SilabsBleWrapper::sl_wfx_msg_t * evt); void HandleTxConfirmationEvent(BLE_CONNECTION_OBJECT conId); - void HandleTXCharCCCDWrite(sl_wfx_msg_t * evt); + void HandleTXCharCCCDWrite(SilabsBleWrapper::sl_wfx_msg_t * evt); void HandleSoftTimerEvent(void); int32_t SendBLEAdvertisementCommand(void); #else @@ -83,7 +83,7 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla #if CHIP_ENABLE_ADDITIONAL_DATA_ADVERTISING #if (SLI_SI91X_ENABLE_BLE || RSI_BLE_ENABLE) - static void HandleC3ReadRequest(sl_wfx_msg_t * rsi_ble_read_req); + static void HandleC3ReadRequest(SilabsBleWrapper::sl_wfx_msg_t * rsi_ble_read_req); #else #if CHIP_ENABLE_ADDITIONAL_DATA_ADVERTISING static void HandleC3ReadRequest(volatile sl_bt_msg_t * evt); @@ -101,7 +101,7 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla osMessageQueueId_t sBleEventQueue = NULL; static void sl_ble_event_handling_task(void * args); void sl_ble_init(); - void ProcessEvent(BleEvent_t inEvent); + void ProcessEvent(SilabsBleWrapper::BleEvent_t inEvent); #endif // ===== Members that implement the BLEManager internal interface. @@ -197,7 +197,7 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla #endif #if (SLI_SI91X_ENABLE_BLE || RSI_BLE_ENABLE) - void HandleRXCharWrite(sl_wfx_msg_t * evt); + void HandleRXCharWrite(SilabsBleWrapper::sl_wfx_msg_t * evt); #else void HandleRXCharWrite(volatile sl_bt_msg_t * evt); #endif diff --git a/src/platform/silabs/rs911x/BLEManagerImpl.cpp b/src/platform/silabs/rs911x/BLEManagerImpl.cpp index f3df02647314fc..01b7c165b9e9c6 100644 --- a/src/platform/silabs/rs911x/BLEManagerImpl.cpp +++ b/src/platform/silabs/rs911x/BLEManagerImpl.cpp @@ -115,11 +115,11 @@ const uint8_t ShortUUID_CHIPoBLEService[] = { 0xF6, 0xFF }; BLEManagerImpl BLEManagerImpl::sInstance; -void BLEManagerImpl::ProcessEvent(BleEvent_t inEvent) +void BLEManagerImpl::ProcessEvent(SilabsBleWrapper::BleEvent_t inEvent) { switch (inEvent.eventType) { - case RSI_BLE_CONN_EVENT: { + case SilabsBleWrapper::BleEventType_e::RSI_BLE_CONN_EVENT: { BLEMgrImpl().HandleConnectEvent((inEvent.eventData)); // Requests the connection parameters change with the remote device rsi_ble_conn_params_update(inEvent.eventData->resp_enh_conn.dev_addr, BLE_MIN_CONNECTION_INTERVAL_MS, @@ -131,17 +131,17 @@ void BLEManagerImpl::ProcessEvent(BleEvent_t inEvent) ble_measurement_hndl = inEvent.eventData->rsi_ble_measurement_hndl; } break; - case RSI_BLE_DISCONN_EVENT: { + case SilabsBleWrapper::BleEventType_e::RSI_BLE_DISCONN_EVENT: { // event invokes when disconnection was completed BLEMgrImpl().HandleConnectionCloseEvent(inEvent.eventData); } break; - case RSI_BLE_MTU_EVENT: { + case SilabsBleWrapper::BleEventType_e::RSI_BLE_MTU_EVENT: { // event invokes when write/notification events received BLEMgrImpl().UpdateMtu(inEvent.eventData); } break; - case RSI_BLE_EVENT_GATT_RD: { + case SilabsBleWrapper::BleEventType_e::RSI_BLE_EVENT_GATT_RD: { #if CHIP_ENABLE_ADDITIONAL_DATA_ADVERTISING if (inEvent.eventData->rsi_ble_read_req->type == 0) { @@ -150,12 +150,12 @@ void BLEManagerImpl::ProcessEvent(BleEvent_t inEvent) #endif // CHIP_ENABLE_ADDITIONAL_DATA_ADVERTISING } break; - case RSI_BLE_GATT_WRITE_EVENT: { + case SilabsBleWrapper::BleEventType_e::RSI_BLE_GATT_WRITE_EVENT: { // event invokes when write/notification events received BLEMgrImpl().HandleWriteEvent(inEvent.eventData); } break; - case RSI_BLE_GATT_INDICATION_CONFIRMATION: { + case SilabsBleWrapper::BleEventType_e::RSI_BLE_GATT_INDICATION_CONFIRMATION: { BLEMgrImpl().HandleTxConfirmationEvent(1); } break; @@ -164,7 +164,7 @@ void BLEManagerImpl::ProcessEvent(BleEvent_t inEvent) } } -void BLEManagerImpl::BlePostEvent(BleEvent_t * event) +void BLEManagerImpl::BlePostEvent(SilabsBleWrapper::BleEvent_t * event) { sl_status_t status = osMessageQueuePut(sInstance.sBleEventQueue, event, 0, 0); if (status != osOK) @@ -177,7 +177,7 @@ void BLEManagerImpl::BlePostEvent(BleEvent_t * event) void BLEManagerImpl::sl_ble_event_handling_task(void * args) { sl_status_t status; - BleEvent_t bleEvent; + SilabsBleWrapper::BleEvent_t bleEvent; //! This semaphore is waiting for wifi module initialization. osSemaphoreAcquire(sl_rs_ble_init_sem, osWaitForever); @@ -210,16 +210,16 @@ void BLEManagerImpl::sl_ble_init() randomAddrBLE[(RSI_BLE_ADDR_LENGTH - 1)] |= 0xC0; // registering the GAP callback functions - rsi_ble_gap_register_callbacks(NULL, NULL, rsi_ble_on_disconnect_event, NULL, NULL, NULL, rsi_ble_on_enhance_conn_status_event, + rsi_ble_gap_register_callbacks(NULL, NULL, SilabsBleWrapper::rsi_ble_on_disconnect_event, NULL, NULL, NULL, SilabsBleWrapper::rsi_ble_on_enhance_conn_status_event, NULL, NULL, NULL); // registering the GATT call back functions - rsi_ble_gatt_register_callbacks(NULL, NULL, NULL, NULL, NULL, NULL, NULL, rsi_ble_on_gatt_write_event, NULL, NULL, - rsi_ble_on_read_req_event, rsi_ble_on_mtu_event, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, rsi_ble_on_event_indication_confirmation, NULL); + rsi_ble_gatt_register_callbacks(NULL, NULL, NULL, NULL, NULL, NULL, NULL, SilabsBleWrapper::rsi_ble_on_gatt_write_event, NULL, NULL, + SilabsBleWrapper::rsi_ble_on_read_req_event, SilabsBleWrapper::rsi_ble_on_mtu_event, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, SilabsBleWrapper::rsi_ble_on_event_indication_confirmation, NULL); // Exchange of GATT info with BLE stack - rsi_ble_add_matter_service(); + SilabsBleWrapper::rsi_ble_add_matter_service(); rsi_ble_set_random_address_with_value(randomAddrBLE); sInstance.sBleEventQueue = osMessageQueueNew(WFX_QUEUE_SIZE, sizeof(WfxEvent_t), NULL); @@ -733,7 +733,7 @@ CHIP_ERROR BLEManagerImpl::StopAdvertising(void) return err; } -void BLEManagerImpl::UpdateMtu(sl_wfx_msg_t * evt) +void BLEManagerImpl::UpdateMtu(SilabsBleWrapper::sl_wfx_msg_t * evt) { CHIPoBLEConState * bleConnState = GetConnectionState(evt->connectionHandle); if (bleConnState != NULL) @@ -762,14 +762,14 @@ void BLEManagerImpl::HandleBootEvent(void) PlatformMgr().ScheduleWork(DriveBLEState, 0); } -void BLEManagerImpl::HandleConnectEvent(sl_wfx_msg_t * evt) +void BLEManagerImpl::HandleConnectEvent(SilabsBleWrapper::sl_wfx_msg_t * evt) { AddConnection(evt->connectionHandle, evt->bondingHandle); PlatformMgr().ScheduleWork(DriveBLEState, 0); } // TODO:: Implementation need to be done. -void BLEManagerImpl::HandleConnectionCloseEvent(sl_wfx_msg_t * evt) +void BLEManagerImpl::HandleConnectionCloseEvent(SilabsBleWrapper::sl_wfx_msg_t * evt) { uint8_t connHandle = 1; @@ -803,7 +803,7 @@ void BLEManagerImpl::HandleConnectionCloseEvent(sl_wfx_msg_t * evt) } } -void BLEManagerImpl::HandleWriteEvent(sl_wfx_msg_t * evt) +void BLEManagerImpl::HandleWriteEvent(SilabsBleWrapper::sl_wfx_msg_t * evt) { ChipLogProgress(DeviceLayer, "Char Write Req, packet type %d", evt->rsi_ble_write.pkt_type); @@ -818,7 +818,7 @@ void BLEManagerImpl::HandleWriteEvent(sl_wfx_msg_t * evt) } // TODO:: Need to implement this -void BLEManagerImpl::HandleTXCharCCCDWrite(sl_wfx_msg_t * evt) +void BLEManagerImpl::HandleTXCharCCCDWrite(SilabsBleWrapper::sl_wfx_msg_t * evt) { CHIP_ERROR err = CHIP_NO_ERROR; bool isIndicationEnabled = false; @@ -863,7 +863,7 @@ void BLEManagerImpl::HandleTXCharCCCDWrite(sl_wfx_msg_t * evt) } } -void BLEManagerImpl::HandleRXCharWrite(sl_wfx_msg_t * evt) +void BLEManagerImpl::HandleRXCharWrite(SilabsBleWrapper::sl_wfx_msg_t * evt) { uint8_t conId = 1; CHIP_ERROR err = CHIP_NO_ERROR; @@ -996,7 +996,7 @@ CHIP_ERROR BLEManagerImpl::EncodeAdditionalDataTlv() return err; } -void BLEManagerImpl::HandleC3ReadRequest(sl_wfx_msg_t * evt) +void BLEManagerImpl::HandleC3ReadRequest(SilabsBleWrapper::sl_wfx_msg_t * evt) { sl_status_t ret = rsi_ble_gatt_read_response(evt->rsi_ble_read_req.dev_addr, GATT_READ_RESP, evt->rsi_ble_read_req.handle, GATT_READ_ZERO_OFFSET, sInstance.c3AdditionalDataBufferHandle->DataLength(), diff --git a/src/platform/silabs/rs911x/wfx_sl_ble_init.cpp b/src/platform/silabs/rs911x/wfx_sl_ble_init.cpp index 13251c6c1e8e14..f31d62844af108 100644 --- a/src/platform/silabs/rs911x/wfx_sl_ble_init.cpp +++ b/src/platform/silabs/rs911x/wfx_sl_ble_init.cpp @@ -22,19 +22,13 @@ */ #include #include -// #include #include - -#ifdef __cplusplus -extern "C" { -#endif #include "wfx_sl_ble_init.h" -#ifdef __cplusplus -} -#endif + +using namespace chip::DeviceLayer::Internal; // Global Variables -BleEvent_t bleEvent; +SilabsBleWrapper::BleEvent_t bleEvent; /*==============================================*/ /** @@ -45,11 +39,11 @@ BleEvent_t bleEvent; * @section description * This callback function is invoked when mtu exhange event is received */ -void rsi_ble_on_mtu_event(rsi_ble_event_mtu_t * rsi_ble_mtu) +void SilabsBleWrapper::rsi_ble_on_mtu_event(rsi_ble_event_mtu_t * rsi_ble_mtu) { - bleEvent.eventType = RSI_BLE_MTU_EVENT; + bleEvent.eventType = BleEventType_e::RSI_BLE_MTU_EVENT; memcpy(&bleEvent.eventData->rsi_ble_mtu, rsi_ble_mtu, sizeof(rsi_ble_event_mtu_t)); - chip::DeviceLayer::Internal::BLEMgrImpl().BlePostEvent(&bleEvent); + BLEMgrImpl().BlePostEvent(&bleEvent); } /*==============================================*/ @@ -62,12 +56,12 @@ void rsi_ble_on_mtu_event(rsi_ble_event_mtu_t * rsi_ble_mtu) * @section description * This callback function is invoked when write/notify/indication events are received */ -void rsi_ble_on_gatt_write_event(uint16_t event_id, rsi_ble_event_write_t * rsi_ble_write) +void SilabsBleWrapper::rsi_ble_on_gatt_write_event(uint16_t event_id, rsi_ble_event_write_t * rsi_ble_write) { - bleEvent.eventType = RSI_BLE_GATT_WRITE_EVENT; + bleEvent.eventType = BleEventType_e::RSI_BLE_GATT_WRITE_EVENT; bleEvent.eventData->event_id = event_id; memcpy(&bleEvent.eventData->rsi_ble_write, rsi_ble_write, sizeof(rsi_ble_event_write_t)); - chip::DeviceLayer::Internal::BLEMgrImpl().BlePostEvent(&bleEvent); + BLEMgrImpl().BlePostEvent(&bleEvent); } /*==============================================*/ @@ -79,13 +73,13 @@ void rsi_ble_on_gatt_write_event(uint16_t event_id, rsi_ble_event_write_t * rsi_ * @section description * This callback function indicates the status of the connection */ -void rsi_ble_on_enhance_conn_status_event(rsi_ble_event_enhance_conn_status_t * resp_enh_conn) +void SilabsBleWrapper::rsi_ble_on_enhance_conn_status_event(rsi_ble_event_enhance_conn_status_t * resp_enh_conn) { - bleEvent.eventType = RSI_BLE_CONN_EVENT; + bleEvent.eventType = BleEventType_e::RSI_BLE_CONN_EVENT; bleEvent.eventData->connectionHandle = 1; bleEvent.eventData->bondingHandle = 255; memcpy(bleEvent.eventData->resp_enh_conn.dev_addr, resp_enh_conn->dev_addr, RSI_DEV_ADDR_LEN); - chip::DeviceLayer::Internal::BLEMgrImpl().BlePostEvent(&bleEvent); + BLEMgrImpl().BlePostEvent(&bleEvent); } /*==============================================*/ @@ -98,11 +92,11 @@ void rsi_ble_on_enhance_conn_status_event(rsi_ble_event_enhance_conn_status_t * * @section description * This callback function indicates disconnected device information and status */ -void rsi_ble_on_disconnect_event(rsi_ble_event_disconnect_t * resp_disconnect, uint16_t reason) +void SilabsBleWrapper::rsi_ble_on_disconnect_event(rsi_ble_event_disconnect_t * resp_disconnect, uint16_t reason) { - bleEvent.eventType = RSI_BLE_DISCONN_EVENT; + bleEvent.eventType = BleEventType_e::RSI_BLE_DISCONN_EVENT; bleEvent.eventData->reason = reason; - chip::DeviceLayer::Internal::BLEMgrImpl().BlePostEvent(&bleEvent); + BLEMgrImpl().BlePostEvent(&bleEvent); } /*==============================================*/ @@ -114,12 +108,12 @@ void rsi_ble_on_disconnect_event(rsi_ble_event_disconnect_t * resp_disconnect, u * @return none * @section description */ -void rsi_ble_on_event_indication_confirmation(uint16_t resp_status, rsi_ble_set_att_resp_t * rsi_ble_event_set_att_rsp) +void SilabsBleWrapper::rsi_ble_on_event_indication_confirmation(uint16_t resp_status, rsi_ble_set_att_resp_t * rsi_ble_event_set_att_rsp) { - bleEvent.eventType = RSI_BLE_GATT_INDICATION_CONFIRMATION; + bleEvent.eventType = BleEventType_e::RSI_BLE_GATT_INDICATION_CONFIRMATION; bleEvent.eventData->resp_status = resp_status; memcpy(&bleEvent.eventData->rsi_ble_event_set_att_rsp, rsi_ble_event_set_att_rsp, sizeof(rsi_ble_set_att_resp_t)); - chip::DeviceLayer::Internal::BLEMgrImpl().BlePostEvent(&bleEvent); + BLEMgrImpl().BlePostEvent(&bleEvent); } /*==============================================*/ @@ -132,12 +126,12 @@ void rsi_ble_on_event_indication_confirmation(uint16_t resp_status, rsi_ble_set_ * @section description * This callback function is invoked when read events are received */ -void rsi_ble_on_read_req_event(uint16_t event_id, rsi_ble_read_req_t * rsi_ble_read_req) +void SilabsBleWrapper::rsi_ble_on_read_req_event(uint16_t event_id, rsi_ble_read_req_t * rsi_ble_read_req) { - bleEvent.eventType = RSI_BLE_EVENT_GATT_RD; + bleEvent.eventType = BleEventType_e::RSI_BLE_EVENT_GATT_RD; bleEvent.eventData->event_id = event_id; memcpy(&bleEvent.eventData->rsi_ble_read_req, rsi_ble_read_req, sizeof(rsi_ble_read_req_t)); - chip::DeviceLayer::Internal::BLEMgrImpl().BlePostEvent(&bleEvent); + BLEMgrImpl().BlePostEvent(&bleEvent); } /*==============================================*/ @@ -153,7 +147,7 @@ void rsi_ble_on_read_req_event(uint16_t event_id, rsi_ble_read_req_t * rsi_ble_r * @section description * This function is used to store all attribute records */ -void rsi_gatt_add_attribute_to_list(rsi_ble_t * p_val, uint16_t handle, uint16_t data_len, uint8_t * data, uuid_t uuid, +void SilabsBleWrapper::rsi_gatt_add_attribute_to_list(rsi_ble_t * p_val, uint16_t handle, uint16_t data_len, uint8_t * data, uuid_t uuid, uint8_t char_prop) { if ((p_val->DATA_ix + data_len) >= BLE_ATT_REC_SIZE) @@ -187,7 +181,7 @@ void rsi_gatt_add_attribute_to_list(rsi_ble_t * p_val, uint16_t handle, uint16_t * @section description * This function is used at application to add characteristic attribute */ -void rsi_ble_add_char_serv_att(void * serv_handler, uint16_t handle, uint8_t val_prop, uint16_t att_val_handle, uuid_t att_val_uuid) +void SilabsBleWrapper::rsi_ble_add_char_serv_att(void * serv_handler, uint16_t handle, uint8_t val_prop, uint16_t att_val_handle, uuid_t att_val_uuid) { rsi_ble_req_add_att_t new_att = { 0 }; @@ -235,7 +229,7 @@ void rsi_ble_add_char_serv_att(void * serv_handler, uint16_t handle, uint8_t val * This function is used at application to create new service. */ -void rsi_ble_add_char_val_att(void * serv_handler, uint16_t handle, uuid_t att_type_uuid, uint8_t val_prop, uint8_t * data, +void SilabsBleWrapper::rsi_ble_add_char_val_att(void * serv_handler, uint16_t handle, uuid_t att_type_uuid, uint8_t val_prop, uint8_t * data, uint8_t data_len, uint8_t auth_read) { rsi_ble_req_add_att_t new_att = { 0 }; @@ -297,7 +291,7 @@ void rsi_ble_add_char_val_att(void * serv_handler, uint16_t handle, uuid_t att_t * This function is used at application to create new service. */ -uint32_t rsi_ble_add_matter_service(void) +uint32_t SilabsBleWrapper::rsi_ble_add_matter_service(void) { uuid_t custom_service = { RSI_BLE_MATTER_CUSTOM_SERVICE_UUID }; custom_service.size = RSI_BLE_MATTER_CUSTOM_SERVICE_SIZE; diff --git a/src/platform/silabs/rs911x/wfx_sl_ble_init.h b/src/platform/silabs/rs911x/wfx_sl_ble_init.h index fa1e0b971ac4d5..a71467a532e419 100644 --- a/src/platform/silabs/rs911x/wfx_sl_ble_init.h +++ b/src/platform/silabs/rs911x/wfx_sl_ble_init.h @@ -20,14 +20,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#pragma once /** * Include files * */ - -#ifndef WFX_SL_BLE_INIT -#define WFX_SL_BLE_INIT - // BLE include file to refer BLE APIs #include "ble_config.h" #include "cmsis_os2.h" @@ -49,41 +46,6 @@ #include #include -typedef enum -{ - RSI_BLE_CONN_EVENT, - RSI_BLE_DISCONN_EVENT, - RSI_BLE_GATT_WRITE_EVENT, - RSI_BLE_MTU_EVENT, - RSI_BLE_GATT_INDICATION_CONFIRMATION, - RSI_BLE_RESP_ATT_VALUE, - RSI_BLE_EVENT_GATT_RD -} BleEventType_e; - -typedef struct sl_wfx_msg_s -{ - uint8_t connectionHandle; - uint8_t bondingHandle; - uint16_t reason; - uint16_t event_id; - uint16_t resp_status; - rsi_ble_event_mtu_t rsi_ble_mtu; - rsi_ble_event_write_t rsi_ble_write; - rsi_ble_event_enhance_conn_status_t resp_enh_conn; - rsi_ble_event_disconnect_t * resp_disconnect; - rsi_ble_read_req_t * rsi_ble_read_req; - rsi_ble_set_att_resp_t rsi_ble_event_set_att_rsp; - uint16_t rsi_ble_measurement_hndl; - uint16_t rsi_ble_gatt_server_client_config_hndl; - uint16_t subscribed; -} sl_wfx_msg_t; - -typedef struct BleEvent_s -{ - BleEventType_e eventType; - sl_wfx_msg_t * eventData; -} BleEvent_t; - #define ATT_REC_IN_HOST (0) #define WFX_QUEUE_SIZE 10 @@ -118,27 +80,65 @@ typedef struct BleEvent_s #define RSI_BLE_CHARACTERISTIC_TX_MEASUREMENT_HANDLE_LOCATION (4) #define RSI_BLE_CHARACTERISTIC_TX_GATT_SERVER_CLIENT_HANDLE_LOCATION (5) +namespace chip { +namespace DeviceLayer { +namespace Internal { + +class SilabsBleWrapper { +public: + typedef enum BleEventType + { + RSI_BLE_CONN_EVENT, + RSI_BLE_DISCONN_EVENT, + RSI_BLE_GATT_WRITE_EVENT, + RSI_BLE_MTU_EVENT, + RSI_BLE_GATT_INDICATION_CONFIRMATION, + RSI_BLE_RESP_ATT_VALUE, + RSI_BLE_EVENT_GATT_RD + } BleEventType_e; + + typedef struct sl_wfx_msg_s + { + uint8_t connectionHandle; + uint8_t bondingHandle; + uint16_t reason; + uint16_t event_id; + uint16_t resp_status; + rsi_ble_event_mtu_t rsi_ble_mtu; + rsi_ble_event_write_t rsi_ble_write; + rsi_ble_event_enhance_conn_status_t resp_enh_conn; + rsi_ble_event_disconnect_t * resp_disconnect; + rsi_ble_read_req_t * rsi_ble_read_req; + rsi_ble_set_att_resp_t rsi_ble_event_set_att_rsp; + uint16_t rsi_ble_measurement_hndl; + uint16_t rsi_ble_gatt_server_client_config_hndl; + uint16_t subscribed; + } sl_wfx_msg_t; + + typedef struct BleEvent_s + { + BleEventType_e eventType; + sl_wfx_msg_t * eventData; + } BleEvent_t; + // ALL Ble functions -void InitBleEventQueue(); -osMessageQueueId_t GetBleEventQueue(); -void rsi_ble_on_connect_event(rsi_ble_event_conn_status_t * resp_conn); -void rsi_ble_on_disconnect_event(rsi_ble_event_disconnect_t * resp_disconnect, uint16_t reason); -void rsi_ble_on_enhance_conn_status_event(rsi_ble_event_enhance_conn_status_t * resp_enh_conn); -void rsi_ble_on_gatt_write_event(uint16_t event_id, rsi_ble_event_write_t * rsi_ble_write); -void rsi_ble_on_mtu_event(rsi_ble_event_mtu_t * rsi_ble_mtu); -void rsi_ble_on_event_indication_confirmation(uint16_t resp_status, rsi_ble_set_att_resp_t * rsi_ble_event_set_att_rsp); -void rsi_ble_on_read_req_event(uint16_t event_id, rsi_ble_read_req_t * rsi_ble_read_req); -void rsi_gatt_add_attribute_to_list(rsi_ble_t * p_val, uint16_t handle, uint16_t data_len, uint8_t * data, uuid_t uuid, +static void rsi_ble_on_connect_event(rsi_ble_event_conn_status_t * resp_conn); +static void rsi_ble_on_disconnect_event(rsi_ble_event_disconnect_t * resp_disconnect, uint16_t reason); +static void rsi_ble_on_enhance_conn_status_event(rsi_ble_event_enhance_conn_status_t * resp_enh_conn); +static void rsi_ble_on_gatt_write_event(uint16_t event_id, rsi_ble_event_write_t * rsi_ble_write); +static void rsi_ble_on_mtu_event(rsi_ble_event_mtu_t * rsi_ble_mtu); +static void rsi_ble_on_event_indication_confirmation(uint16_t resp_status, rsi_ble_set_att_resp_t * rsi_ble_event_set_att_rsp); +static void rsi_ble_on_read_req_event(uint16_t event_id, rsi_ble_read_req_t * rsi_ble_read_req); +static void rsi_gatt_add_attribute_to_list(rsi_ble_t * p_val, uint16_t handle, uint16_t data_len, uint8_t * data, uuid_t uuid, uint8_t char_prop); -void rsi_ble_add_char_serv_att(void * serv_handler, uint16_t handle, uint8_t val_prop, uint16_t att_val_handle, +static void rsi_ble_add_char_serv_att(void * serv_handler, uint16_t handle, uint8_t val_prop, uint16_t att_val_handle, uuid_t att_val_uuid); -void rsi_ble_add_char_val_att(void * serv_handler, uint16_t handle, uuid_t att_type_uuid, uint8_t val_prop, uint8_t * data, +static void rsi_ble_add_char_val_att(void * serv_handler, uint16_t handle, uuid_t att_type_uuid, uint8_t val_prop, uint8_t * data, uint8_t data_len, uint8_t auth_read); -uint32_t rsi_ble_add_matter_service(void); -void rsi_ble_app_set_event(uint32_t event_num); -int32_t rsi_ble_app_get_event(void); -void rsi_ble_app_clear_event(uint32_t event_num); -void rsi_ble_app_init_events(); -void rsi_ble_event_handling_task(void); +static uint32_t rsi_ble_add_matter_service(void); -#endif +}; + +} // namespace Internal +} // namespace DeviceLayer +} // namespace chip \ No newline at end of file From 3d4e357cc174520389cc0010c97ae40bd53302cc Mon Sep 17 00:00:00 2001 From: chirag-silabs Date: Wed, 18 Sep 2024 12:03:42 +0530 Subject: [PATCH 14/17] restyling the PR --- src/platform/silabs/rs911x/BLEManagerImpl.cpp | 11 +++--- .../silabs/rs911x/wfx_sl_ble_init.cpp | 16 +++++---- src/platform/silabs/rs911x/wfx_sl_ble_init.h | 34 +++++++++---------- 3 files changed, 32 insertions(+), 29 deletions(-) diff --git a/src/platform/silabs/rs911x/BLEManagerImpl.cpp b/src/platform/silabs/rs911x/BLEManagerImpl.cpp index 01b7c165b9e9c6..c78acdb1fd339e 100644 --- a/src/platform/silabs/rs911x/BLEManagerImpl.cpp +++ b/src/platform/silabs/rs911x/BLEManagerImpl.cpp @@ -210,13 +210,14 @@ void BLEManagerImpl::sl_ble_init() randomAddrBLE[(RSI_BLE_ADDR_LENGTH - 1)] |= 0xC0; // registering the GAP callback functions - rsi_ble_gap_register_callbacks(NULL, NULL, SilabsBleWrapper::rsi_ble_on_disconnect_event, NULL, NULL, NULL, SilabsBleWrapper::rsi_ble_on_enhance_conn_status_event, - NULL, NULL, NULL); + rsi_ble_gap_register_callbacks(NULL, NULL, SilabsBleWrapper::rsi_ble_on_disconnect_event, NULL, NULL, NULL, + SilabsBleWrapper::rsi_ble_on_enhance_conn_status_event, NULL, NULL, NULL); // registering the GATT call back functions - rsi_ble_gatt_register_callbacks(NULL, NULL, NULL, NULL, NULL, NULL, NULL, SilabsBleWrapper::rsi_ble_on_gatt_write_event, NULL, NULL, - SilabsBleWrapper::rsi_ble_on_read_req_event, SilabsBleWrapper::rsi_ble_on_mtu_event, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, SilabsBleWrapper::rsi_ble_on_event_indication_confirmation, NULL); + rsi_ble_gatt_register_callbacks(NULL, NULL, NULL, NULL, NULL, NULL, NULL, SilabsBleWrapper::rsi_ble_on_gatt_write_event, NULL, + NULL, SilabsBleWrapper::rsi_ble_on_read_req_event, SilabsBleWrapper::rsi_ble_on_mtu_event, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + SilabsBleWrapper::rsi_ble_on_event_indication_confirmation, NULL); // Exchange of GATT info with BLE stack SilabsBleWrapper::rsi_ble_add_matter_service(); diff --git a/src/platform/silabs/rs911x/wfx_sl_ble_init.cpp b/src/platform/silabs/rs911x/wfx_sl_ble_init.cpp index f31d62844af108..7d944732948a57 100644 --- a/src/platform/silabs/rs911x/wfx_sl_ble_init.cpp +++ b/src/platform/silabs/rs911x/wfx_sl_ble_init.cpp @@ -20,10 +20,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include "wfx_sl_ble_init.h" #include #include #include -#include "wfx_sl_ble_init.h" using namespace chip::DeviceLayer::Internal; @@ -108,7 +108,8 @@ void SilabsBleWrapper::rsi_ble_on_disconnect_event(rsi_ble_event_disconnect_t * * @return none * @section description */ -void SilabsBleWrapper::rsi_ble_on_event_indication_confirmation(uint16_t resp_status, rsi_ble_set_att_resp_t * rsi_ble_event_set_att_rsp) +void SilabsBleWrapper::rsi_ble_on_event_indication_confirmation(uint16_t resp_status, + rsi_ble_set_att_resp_t * rsi_ble_event_set_att_rsp) { bleEvent.eventType = BleEventType_e::RSI_BLE_GATT_INDICATION_CONFIRMATION; bleEvent.eventData->resp_status = resp_status; @@ -147,8 +148,8 @@ void SilabsBleWrapper::rsi_ble_on_read_req_event(uint16_t event_id, rsi_ble_read * @section description * This function is used to store all attribute records */ -void SilabsBleWrapper::rsi_gatt_add_attribute_to_list(rsi_ble_t * p_val, uint16_t handle, uint16_t data_len, uint8_t * data, uuid_t uuid, - uint8_t char_prop) +void SilabsBleWrapper::rsi_gatt_add_attribute_to_list(rsi_ble_t * p_val, uint16_t handle, uint16_t data_len, uint8_t * data, + uuid_t uuid, uint8_t char_prop) { if ((p_val->DATA_ix + data_len) >= BLE_ATT_REC_SIZE) { //! Check for max data length for the characteristic value @@ -181,7 +182,8 @@ void SilabsBleWrapper::rsi_gatt_add_attribute_to_list(rsi_ble_t * p_val, uint16_ * @section description * This function is used at application to add characteristic attribute */ -void SilabsBleWrapper::rsi_ble_add_char_serv_att(void * serv_handler, uint16_t handle, uint8_t val_prop, uint16_t att_val_handle, uuid_t att_val_uuid) +void SilabsBleWrapper::rsi_ble_add_char_serv_att(void * serv_handler, uint16_t handle, uint8_t val_prop, uint16_t att_val_handle, + uuid_t att_val_uuid) { rsi_ble_req_add_att_t new_att = { 0 }; @@ -229,8 +231,8 @@ void SilabsBleWrapper::rsi_ble_add_char_serv_att(void * serv_handler, uint16_t h * This function is used at application to create new service. */ -void SilabsBleWrapper::rsi_ble_add_char_val_att(void * serv_handler, uint16_t handle, uuid_t att_type_uuid, uint8_t val_prop, uint8_t * data, - uint8_t data_len, uint8_t auth_read) +void SilabsBleWrapper::rsi_ble_add_char_val_att(void * serv_handler, uint16_t handle, uuid_t att_type_uuid, uint8_t val_prop, + uint8_t * data, uint8_t data_len, uint8_t auth_read) { rsi_ble_req_add_att_t new_att = { 0 }; rsi_ble_t att_list; diff --git a/src/platform/silabs/rs911x/wfx_sl_ble_init.h b/src/platform/silabs/rs911x/wfx_sl_ble_init.h index a71467a532e419..d5b7c8107c14b5 100644 --- a/src/platform/silabs/rs911x/wfx_sl_ble_init.h +++ b/src/platform/silabs/rs911x/wfx_sl_ble_init.h @@ -84,7 +84,8 @@ namespace chip { namespace DeviceLayer { namespace Internal { -class SilabsBleWrapper { +class SilabsBleWrapper +{ public: typedef enum BleEventType { @@ -121,22 +122,21 @@ class SilabsBleWrapper { sl_wfx_msg_t * eventData; } BleEvent_t; -// ALL Ble functions -static void rsi_ble_on_connect_event(rsi_ble_event_conn_status_t * resp_conn); -static void rsi_ble_on_disconnect_event(rsi_ble_event_disconnect_t * resp_disconnect, uint16_t reason); -static void rsi_ble_on_enhance_conn_status_event(rsi_ble_event_enhance_conn_status_t * resp_enh_conn); -static void rsi_ble_on_gatt_write_event(uint16_t event_id, rsi_ble_event_write_t * rsi_ble_write); -static void rsi_ble_on_mtu_event(rsi_ble_event_mtu_t * rsi_ble_mtu); -static void rsi_ble_on_event_indication_confirmation(uint16_t resp_status, rsi_ble_set_att_resp_t * rsi_ble_event_set_att_rsp); -static void rsi_ble_on_read_req_event(uint16_t event_id, rsi_ble_read_req_t * rsi_ble_read_req); -static void rsi_gatt_add_attribute_to_list(rsi_ble_t * p_val, uint16_t handle, uint16_t data_len, uint8_t * data, uuid_t uuid, - uint8_t char_prop); -static void rsi_ble_add_char_serv_att(void * serv_handler, uint16_t handle, uint8_t val_prop, uint16_t att_val_handle, - uuid_t att_val_uuid); -static void rsi_ble_add_char_val_att(void * serv_handler, uint16_t handle, uuid_t att_type_uuid, uint8_t val_prop, uint8_t * data, - uint8_t data_len, uint8_t auth_read); -static uint32_t rsi_ble_add_matter_service(void); - + // ALL Ble functions + static void rsi_ble_on_connect_event(rsi_ble_event_conn_status_t * resp_conn); + static void rsi_ble_on_disconnect_event(rsi_ble_event_disconnect_t * resp_disconnect, uint16_t reason); + static void rsi_ble_on_enhance_conn_status_event(rsi_ble_event_enhance_conn_status_t * resp_enh_conn); + static void rsi_ble_on_gatt_write_event(uint16_t event_id, rsi_ble_event_write_t * rsi_ble_write); + static void rsi_ble_on_mtu_event(rsi_ble_event_mtu_t * rsi_ble_mtu); + static void rsi_ble_on_event_indication_confirmation(uint16_t resp_status, rsi_ble_set_att_resp_t * rsi_ble_event_set_att_rsp); + static void rsi_ble_on_read_req_event(uint16_t event_id, rsi_ble_read_req_t * rsi_ble_read_req); + static void rsi_gatt_add_attribute_to_list(rsi_ble_t * p_val, uint16_t handle, uint16_t data_len, uint8_t * data, uuid_t uuid, + uint8_t char_prop); + static void rsi_ble_add_char_serv_att(void * serv_handler, uint16_t handle, uint8_t val_prop, uint16_t att_val_handle, + uuid_t att_val_uuid); + static void rsi_ble_add_char_val_att(void * serv_handler, uint16_t handle, uuid_t att_type_uuid, uint8_t val_prop, + uint8_t * data, uint8_t data_len, uint8_t auth_read); + static uint32_t rsi_ble_add_matter_service(void); }; } // namespace Internal From ef83f1b30eb6817c25bf85b2ee2ce97ff7acecac Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Wed, 18 Sep 2024 06:34:02 +0000 Subject: [PATCH 15/17] Restyled by whitespace --- src/platform/silabs/rs911x/wfx_sl_ble_init.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platform/silabs/rs911x/wfx_sl_ble_init.h b/src/platform/silabs/rs911x/wfx_sl_ble_init.h index d5b7c8107c14b5..95b31695c039f0 100644 --- a/src/platform/silabs/rs911x/wfx_sl_ble_init.h +++ b/src/platform/silabs/rs911x/wfx_sl_ble_init.h @@ -141,4 +141,4 @@ class SilabsBleWrapper } // namespace Internal } // namespace DeviceLayer -} // namespace chip \ No newline at end of file +} // namespace chip From 39912b1c78c2e6a816929d2f02068c8f79f1ac61 Mon Sep 17 00:00:00 2001 From: chirag-silabs Date: Fri, 20 Sep 2024 11:13:24 +0530 Subject: [PATCH 16/17] cleanup the unused from the .h file and fixing build --- src/platform/silabs/BLEManagerImpl.h | 3 --- src/platform/silabs/rs911x/wfx_sl_ble_init.cpp | 1 - src/platform/silabs/rs911x/wfx_sl_ble_init.h | 7 ------- 3 files changed, 11 deletions(-) diff --git a/src/platform/silabs/BLEManagerImpl.h b/src/platform/silabs/BLEManagerImpl.h index 649b0362038a38..6d901db16e95db 100644 --- a/src/platform/silabs/BLEManagerImpl.h +++ b/src/platform/silabs/BLEManagerImpl.h @@ -31,9 +31,6 @@ extern "C" { #endif // __cplusplus #include "wfx_sl_ble_init.h" -#include -#include -#include #ifdef __cplusplus } #endif // __cplusplus diff --git a/src/platform/silabs/rs911x/wfx_sl_ble_init.cpp b/src/platform/silabs/rs911x/wfx_sl_ble_init.cpp index 7d944732948a57..263eeb828d76c8 100644 --- a/src/platform/silabs/rs911x/wfx_sl_ble_init.cpp +++ b/src/platform/silabs/rs911x/wfx_sl_ble_init.cpp @@ -20,7 +20,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "wfx_sl_ble_init.h" #include #include #include diff --git a/src/platform/silabs/rs911x/wfx_sl_ble_init.h b/src/platform/silabs/rs911x/wfx_sl_ble_init.h index 95b31695c039f0..d69b3bee7a08f6 100644 --- a/src/platform/silabs/rs911x/wfx_sl_ble_init.h +++ b/src/platform/silabs/rs911x/wfx_sl_ble_init.h @@ -33,13 +33,6 @@ #include #include #include -#if !(SLI_SI91X_MCU_INTERFACE | EXP_BOARD) -#include -#include -#include -#include -#include -#endif #include #include #include From f9c09326206d1cd23b8d15fa1adb6ed5496ec9b6 Mon Sep 17 00:00:00 2001 From: chirag-silabs Date: Tue, 24 Sep 2024 21:41:45 +0530 Subject: [PATCH 17/17] Addressing review comments --- src/platform/silabs/rs911x/BLEManagerImpl.cpp | 12 ++++++------ src/platform/silabs/rs911x/wfx_sl_ble_init.cpp | 12 ++++++------ src/platform/silabs/rs911x/wfx_sl_ble_init.h | 14 +++++++------- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/platform/silabs/rs911x/BLEManagerImpl.cpp b/src/platform/silabs/rs911x/BLEManagerImpl.cpp index c78acdb1fd339e..841fc1a4b6e266 100644 --- a/src/platform/silabs/rs911x/BLEManagerImpl.cpp +++ b/src/platform/silabs/rs911x/BLEManagerImpl.cpp @@ -119,7 +119,7 @@ void BLEManagerImpl::ProcessEvent(SilabsBleWrapper::BleEvent_t inEvent) { switch (inEvent.eventType) { - case SilabsBleWrapper::BleEventType_e::RSI_BLE_CONN_EVENT: { + case SilabsBleWrapper::BleEventType::RSI_BLE_CONN_EVENT: { BLEMgrImpl().HandleConnectEvent((inEvent.eventData)); // Requests the connection parameters change with the remote device rsi_ble_conn_params_update(inEvent.eventData->resp_enh_conn.dev_addr, BLE_MIN_CONNECTION_INTERVAL_MS, @@ -131,17 +131,17 @@ void BLEManagerImpl::ProcessEvent(SilabsBleWrapper::BleEvent_t inEvent) ble_measurement_hndl = inEvent.eventData->rsi_ble_measurement_hndl; } break; - case SilabsBleWrapper::BleEventType_e::RSI_BLE_DISCONN_EVENT: { + case SilabsBleWrapper::BleEventType::RSI_BLE_DISCONN_EVENT: { // event invokes when disconnection was completed BLEMgrImpl().HandleConnectionCloseEvent(inEvent.eventData); } break; - case SilabsBleWrapper::BleEventType_e::RSI_BLE_MTU_EVENT: { + case SilabsBleWrapper::BleEventType::RSI_BLE_MTU_EVENT: { // event invokes when write/notification events received BLEMgrImpl().UpdateMtu(inEvent.eventData); } break; - case SilabsBleWrapper::BleEventType_e::RSI_BLE_EVENT_GATT_RD: { + case SilabsBleWrapper::BleEventType::RSI_BLE_EVENT_GATT_RD: { #if CHIP_ENABLE_ADDITIONAL_DATA_ADVERTISING if (inEvent.eventData->rsi_ble_read_req->type == 0) { @@ -150,12 +150,12 @@ void BLEManagerImpl::ProcessEvent(SilabsBleWrapper::BleEvent_t inEvent) #endif // CHIP_ENABLE_ADDITIONAL_DATA_ADVERTISING } break; - case SilabsBleWrapper::BleEventType_e::RSI_BLE_GATT_WRITE_EVENT: { + case SilabsBleWrapper::BleEventType::RSI_BLE_GATT_WRITE_EVENT: { // event invokes when write/notification events received BLEMgrImpl().HandleWriteEvent(inEvent.eventData); } break; - case SilabsBleWrapper::BleEventType_e::RSI_BLE_GATT_INDICATION_CONFIRMATION: { + case SilabsBleWrapper::BleEventType::RSI_BLE_GATT_INDICATION_CONFIRMATION: { BLEMgrImpl().HandleTxConfirmationEvent(1); } break; diff --git a/src/platform/silabs/rs911x/wfx_sl_ble_init.cpp b/src/platform/silabs/rs911x/wfx_sl_ble_init.cpp index 263eeb828d76c8..c1af13e2cd807c 100644 --- a/src/platform/silabs/rs911x/wfx_sl_ble_init.cpp +++ b/src/platform/silabs/rs911x/wfx_sl_ble_init.cpp @@ -40,7 +40,7 @@ SilabsBleWrapper::BleEvent_t bleEvent; */ void SilabsBleWrapper::rsi_ble_on_mtu_event(rsi_ble_event_mtu_t * rsi_ble_mtu) { - bleEvent.eventType = BleEventType_e::RSI_BLE_MTU_EVENT; + bleEvent.eventType = BleEventType::RSI_BLE_MTU_EVENT; memcpy(&bleEvent.eventData->rsi_ble_mtu, rsi_ble_mtu, sizeof(rsi_ble_event_mtu_t)); BLEMgrImpl().BlePostEvent(&bleEvent); } @@ -57,7 +57,7 @@ void SilabsBleWrapper::rsi_ble_on_mtu_event(rsi_ble_event_mtu_t * rsi_ble_mtu) */ void SilabsBleWrapper::rsi_ble_on_gatt_write_event(uint16_t event_id, rsi_ble_event_write_t * rsi_ble_write) { - bleEvent.eventType = BleEventType_e::RSI_BLE_GATT_WRITE_EVENT; + bleEvent.eventType = BleEventType::RSI_BLE_GATT_WRITE_EVENT; bleEvent.eventData->event_id = event_id; memcpy(&bleEvent.eventData->rsi_ble_write, rsi_ble_write, sizeof(rsi_ble_event_write_t)); BLEMgrImpl().BlePostEvent(&bleEvent); @@ -74,7 +74,7 @@ void SilabsBleWrapper::rsi_ble_on_gatt_write_event(uint16_t event_id, rsi_ble_ev */ void SilabsBleWrapper::rsi_ble_on_enhance_conn_status_event(rsi_ble_event_enhance_conn_status_t * resp_enh_conn) { - bleEvent.eventType = BleEventType_e::RSI_BLE_CONN_EVENT; + bleEvent.eventType = BleEventType::RSI_BLE_CONN_EVENT; bleEvent.eventData->connectionHandle = 1; bleEvent.eventData->bondingHandle = 255; memcpy(bleEvent.eventData->resp_enh_conn.dev_addr, resp_enh_conn->dev_addr, RSI_DEV_ADDR_LEN); @@ -93,7 +93,7 @@ void SilabsBleWrapper::rsi_ble_on_enhance_conn_status_event(rsi_ble_event_enhanc */ void SilabsBleWrapper::rsi_ble_on_disconnect_event(rsi_ble_event_disconnect_t * resp_disconnect, uint16_t reason) { - bleEvent.eventType = BleEventType_e::RSI_BLE_DISCONN_EVENT; + bleEvent.eventType = BleEventType::RSI_BLE_DISCONN_EVENT; bleEvent.eventData->reason = reason; BLEMgrImpl().BlePostEvent(&bleEvent); } @@ -110,7 +110,7 @@ void SilabsBleWrapper::rsi_ble_on_disconnect_event(rsi_ble_event_disconnect_t * void SilabsBleWrapper::rsi_ble_on_event_indication_confirmation(uint16_t resp_status, rsi_ble_set_att_resp_t * rsi_ble_event_set_att_rsp) { - bleEvent.eventType = BleEventType_e::RSI_BLE_GATT_INDICATION_CONFIRMATION; + bleEvent.eventType = BleEventType::RSI_BLE_GATT_INDICATION_CONFIRMATION; bleEvent.eventData->resp_status = resp_status; memcpy(&bleEvent.eventData->rsi_ble_event_set_att_rsp, rsi_ble_event_set_att_rsp, sizeof(rsi_ble_set_att_resp_t)); BLEMgrImpl().BlePostEvent(&bleEvent); @@ -128,7 +128,7 @@ void SilabsBleWrapper::rsi_ble_on_event_indication_confirmation(uint16_t resp_st */ void SilabsBleWrapper::rsi_ble_on_read_req_event(uint16_t event_id, rsi_ble_read_req_t * rsi_ble_read_req) { - bleEvent.eventType = BleEventType_e::RSI_BLE_EVENT_GATT_RD; + bleEvent.eventType = BleEventType::RSI_BLE_EVENT_GATT_RD; bleEvent.eventData->event_id = event_id; memcpy(&bleEvent.eventData->rsi_ble_read_req, rsi_ble_read_req, sizeof(rsi_ble_read_req_t)); BLEMgrImpl().BlePostEvent(&bleEvent); diff --git a/src/platform/silabs/rs911x/wfx_sl_ble_init.h b/src/platform/silabs/rs911x/wfx_sl_ble_init.h index d69b3bee7a08f6..1e770de0727100 100644 --- a/src/platform/silabs/rs911x/wfx_sl_ble_init.h +++ b/src/platform/silabs/rs911x/wfx_sl_ble_init.h @@ -80,7 +80,7 @@ namespace Internal { class SilabsBleWrapper { public: - typedef enum BleEventType + enum class BleEventType : uint8_t { RSI_BLE_CONN_EVENT, RSI_BLE_DISCONN_EVENT, @@ -89,9 +89,9 @@ class SilabsBleWrapper RSI_BLE_GATT_INDICATION_CONFIRMATION, RSI_BLE_RESP_ATT_VALUE, RSI_BLE_EVENT_GATT_RD - } BleEventType_e; + }; - typedef struct sl_wfx_msg_s + struct sl_wfx_msg_t { uint8_t connectionHandle; uint8_t bondingHandle; @@ -107,13 +107,13 @@ class SilabsBleWrapper uint16_t rsi_ble_measurement_hndl; uint16_t rsi_ble_gatt_server_client_config_hndl; uint16_t subscribed; - } sl_wfx_msg_t; + }; - typedef struct BleEvent_s + struct BleEvent_t { - BleEventType_e eventType; + BleEventType eventType; sl_wfx_msg_t * eventData; - } BleEvent_t; + }; // ALL Ble functions static void rsi_ble_on_connect_event(rsi_ble_event_conn_status_t * resp_conn);