diff --git a/examples/platform/silabs/SiWx917/SiWx917/rsi_if.c b/examples/platform/silabs/SiWx917/SiWx917/rsi_if.c index 3b15cd8f29e7af..f54846b34314e8 100644 --- a/examples/platform/silabs/SiWx917/SiWx917/rsi_if.c +++ b/examples/platform/silabs/SiWx917/SiWx917/rsi_if.c @@ -63,6 +63,7 @@ bool hasNotifiedIPV4 = false; #endif /* CHIP_DEVICE_CONFIG_ENABLE_IPV4 */ bool hasNotifiedWifiConnectivity = false; +extern rsi_semaphore_handle_t sl_ble_init_sem; /* * This file implements the interface to the RSI SAPIs */ @@ -275,7 +276,7 @@ static int32_t wfx_rsi_init(void) /* Initialize WiSeConnect or Module features. */ WFX_RSI_LOG("%s: rsi_wireless_init", __func__); - if ((status = rsi_wireless_init(OPER_MODE_0, COEX_MODE_0)) != RSI_SUCCESS) + if ((status = rsi_wireless_init(OPER_MODE_0, RSI_OPERMODE_WLAN_BLE)) != RSI_SUCCESS) { WFX_RSI_LOG("%s: error: rsi_wireless_init failed with status: %02x", __func__, status); return status; @@ -331,6 +332,7 @@ static int32_t wfx_rsi_init(void) } #endif wfx_rsi.dev_state |= WFX_RSI_ST_DEV_READY; + rsi_semaphore_post(&sl_ble_init_sem); WFX_RSI_LOG("%s: RSI: OK", __func__); return RSI_SUCCESS; } diff --git a/src/platform/silabs/BLEManagerImpl.h b/src/platform/silabs/BLEManagerImpl.h index e0a04e5f356e7e..347f8e722ecc7f 100644 --- a/src/platform/silabs/BLEManagerImpl.h +++ b/src/platform/silabs/BLEManagerImpl.h @@ -66,6 +66,7 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla void HandleTxConfirmationEvent(BLE_CONNECTION_OBJECT conId); void HandleTXCharCCCDWrite(rsi_ble_event_write_t * evt); void HandleSoftTimerEvent(void); + CHIP_ERROR StartAdvertising(void); #else void HandleConnectEvent(volatile sl_bt_msg_t * evt); void HandleConnectionCloseEvent(volatile sl_bt_msg_t * evt); @@ -74,7 +75,7 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla void HandleTxConfirmationEvent(BLE_CONNECTION_OBJECT conId); void HandleTXCharCCCDWrite(volatile sl_bt_msg_t * evt); void HandleSoftTimerEvent(volatile sl_bt_msg_t * evt); - + CHIP_ERROR StartAdvertising(void); #endif // RS91X_BLE_ENABLE #if CHIP_ENABLE_ADDITIONAL_DATA_ADVERTISING @@ -180,7 +181,6 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla CHIP_ERROR MapBLEError(int bleErr); void DriveBLEState(void); CHIP_ERROR ConfigureAdvertisingData(void); - CHIP_ERROR StartAdvertising(void); CHIP_ERROR StopAdvertising(void); #if CHIP_ENABLE_ADDITIONAL_DATA_ADVERTISING CHIP_ERROR EncodeAdditionalDataTlv(); diff --git a/src/platform/silabs/SiWx917/BLEManagerImpl.cpp b/src/platform/silabs/SiWx917/BLEManagerImpl.cpp index 6563f4b5b2e790..c2b6c7a2f1769b 100644 --- a/src/platform/silabs/SiWx917/BLEManagerImpl.cpp +++ b/src/platform/silabs/SiWx917/BLEManagerImpl.cpp @@ -58,21 +58,52 @@ extern uint16_t rsi_ble_measurement_hndl; extern rsi_ble_event_conn_status_t conn_event_to_app; extern sl_wfx_msg_t event_msg; -// StaticTask_t busInitTaskStruct; +StaticTask_t rsiBLETaskStruct; +rsi_semaphore_handle_t sl_ble_init_sem; +rsi_semaphore_handle_t sl_ble_event_sem; /* wfxRsi Task will use as its stack */ -// StackType_t wfxRsiInitTaskStack[WFX_RSI_TASK_SZ] = { 0 }; +StackType_t wfxBLETaskStack[WFX_RSI_TASK_SZ] = { 0 }; using namespace ::chip; using namespace ::chip::Ble; -void rsi_ble_event_handling_task(void) +void sl_ble_init() { - int32_t event_id; + WFX_RSI_LOG("%s starting", __func__); + + // 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); + + // 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, NULL, + rsi_ble_on_mtu_event, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + rsi_ble_on_event_indication_confirmation, NULL); + rsi_semaphore_create(&sl_ble_event_sem, 0); + WFX_RSI_LOG("registering rsi_ble_add_service"); + + // Exchange of GATT info with BLE stack + rsi_ble_add_matter_service(); + + // initializing the application events map + rsi_ble_app_init_events(); - // int32_t event_id; WFX_RSI_LOG("StartAdvertising"); - // chip::DeviceLayer::Internal::BLEManagerImpl().StartAdvertising(); //TODO:: Called on after init of module + chip::DeviceLayer::Internal::BLEManagerImpl().StartAdvertising(); // TODO:: Called on after init of module + WFX_RSI_LOG("%s Ended", __func__); +} + +void sl_ble_event_handling_task(void) +{ + int32_t event_id; + + WFX_RSI_LOG("%s starting", __func__); + rsi_semaphore_create(&sl_ble_init_sem, 0); + //! This semaphore is waiting for wifi module initialization. + rsi_semaphore_wait(&sl_ble_init_sem, 0); + + sl_ble_init(); // Application event map while (1) @@ -81,6 +112,7 @@ void rsi_ble_event_handling_task(void) event_id = rsi_ble_app_get_event(); if (event_id == -1) { + rsi_semaphore_wait(&sl_ble_event_sem, 0); continue; } switch (event_id) @@ -88,12 +120,12 @@ void rsi_ble_event_handling_task(void) case RSI_BLE_CONN_EVENT: { rsi_ble_app_clear_event(RSI_BLE_CONN_EVENT); chip::DeviceLayer::Internal::BLEMgrImpl().HandleConnectEvent(); - WFX_RSI_LOG(" RSI_BLE : Module got connected"); + WFX_RSI_LOG("%s Module got connected", __func__); } break; case RSI_BLE_DISCONN_EVENT: { // event invokes when disconnection was completed - WFX_RSI_LOG(" RSI_BLE : Module got Disconnected"); + WFX_RSI_LOG("%s Module got Disconnected", __func__); chip::DeviceLayer::Internal::BLEMgrImpl().HandleConnectionCloseEvent(event_msg.reason); // clear the served event rsi_ble_app_clear_event(RSI_BLE_DISCONN_EVENT); @@ -101,7 +133,7 @@ void rsi_ble_event_handling_task(void) break; case RSI_BLE_MTU_EVENT: { // event invokes when write/notification events received - WFX_RSI_LOG("RSI_BLE:: RSI_BLE_MTU_EVENT"); + WFX_RSI_LOG("%s RSI_BLE_MTU_EVENT", __func__); chip::DeviceLayer::Internal::BLEMgrImpl().UpdateMtu(event_msg.rsi_ble_mtu); // clear the served event rsi_ble_app_clear_event(RSI_BLE_MTU_EVENT); @@ -109,14 +141,14 @@ void rsi_ble_event_handling_task(void) break; case RSI_BLE_GATT_WRITE_EVENT: { // event invokes when write/notification events received - WFX_RSI_LOG("RSI_BLE : RSI_BLE_GATT_WRITE_EVENT"); + WFX_RSI_LOG("%s RSI_BLE_GATT_WRITE_EVENT", __func__); chip::DeviceLayer::Internal::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: { - WFX_RSI_LOG("RSI_BLE : indication confirmation"); + WFX_RSI_LOG("%s indication confirmation", __func__); chip::DeviceLayer::Internal::BLEMgrImpl().HandleTxConfirmationEvent(1); rsi_ble_app_clear_event(RSI_BLE_GATT_INDICATION_CONFIRMATION); } @@ -130,7 +162,7 @@ void rsi_ble_event_handling_task(void) } } - WFX_RSI_LOG("%s END", __func__); + WFX_RSI_LOG("%s Ended", __func__); } namespace chip { @@ -198,21 +230,18 @@ CHIP_ERROR BLEManagerImpl::_Init() CHIP_ERROR err; ChipLogProgress(DeviceLayer, "%s Start ", __func__); - // wfx_rsi.init_task = xTaskCreateStatic((TaskFunction_t) wfx_sl_module_init, "init_task", WFX_RSI_TASK_SZ, NULL, 1, - // wfxRsiInitTaskStack, &busInitTaskStruct); + wfx_rsi.ble_task = xTaskCreateStatic((TaskFunction_t) sl_ble_event_handling_task, "rsi_ble", WFX_RSI_TASK_SZ, NULL, 1, + wfxBLETaskStack, &rsiBLETaskStruct); - if (NULL == wfx_rsi.init_task) + if (wfx_rsi.ble_task == NULL) { - WFX_RSI_LOG("%s: error: failed to create task.", __func__); + WFX_RSI_LOG("%s: error: failed to create ble task.", __func__); } // Initialize the CHIP BleLayer. err = BleLayer::Init(this, this, &DeviceLayer::SystemLayer()); SuccessOrExit(err); - return err; - - ble_rsi_task(); memset(mBleConnections, 0, sizeof(mBleConnections)); memset(mIndConfId, kUnusedIndex, sizeof(mIndConfId)); mServiceMode = ConnectivityManager::kCHIPoBLEServiceMode_Enabled; @@ -295,7 +324,6 @@ CHIP_ERROR BLEManagerImpl::_GetDeviceName(char * buf, size_t bufSize) CHIP_ERROR BLEManagerImpl::_SetDeviceName(const char * deviceName) { ChipLogProgress(DeviceLayer, "_SetDeviceName Started"); - rsi_bt_set_local_name((uint8_t *) RSI_BLE_DEV_NAME); if (mServiceMode == ConnectivityManager::kCHIPoBLEServiceMode_NotSupported) { ChipLogProgress(DeviceLayer, "_SetDeviceName CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE"); @@ -382,13 +410,9 @@ bool BLEManagerImpl::UnsubscribeCharacteristic(BLE_CONNECTION_OBJECT conId, cons bool BLEManagerImpl::CloseConnection(BLE_CONNECTION_OBJECT conId) { CHIP_ERROR err = CHIP_NO_ERROR; - // int32_t ret; ChipLogProgress(DeviceLayer, "Closing BLE GATT connection (con %u)", conId); - // ret = rsi_ble_disconnect(1); - // err = MapBLEError(ret); - if (err != CHIP_NO_ERROR) { ChipLogError(DeviceLayer, "sl_bt_connection_close() failed: %s", ErrorStr(err)); @@ -413,6 +437,7 @@ bool BLEManagerImpl::SendIndication(BLE_CONNECTION_OBJECT conId, const ChipBleUU if (status != RSI_SUCCESS) { WFX_RSI_LOG("indication %d failed with error code %lx ", status); + return false; } return true; @@ -515,7 +540,6 @@ CHIP_ERROR BLEManagerImpl::ConfigureAdvertisingData(void) uint32_t index = 0; uint32_t mDeviceNameLength = 0; uint8_t mDeviceIdInfoLength = 0; - err = ConfigurationMgr().GetBLEDeviceIdentificationInfo(mDeviceIdInfo); ChipLogProgress(DeviceLayer, "ConfigureAdvertisingData start"); @@ -524,6 +548,7 @@ CHIP_ERROR BLEManagerImpl::ConfigureAdvertisingData(void) memset(responseData, 0, MAX_RESPONSE_DATA_LEN); memset(advData, 0, MAX_ADV_DATA_LEN); + err = ConfigurationMgr().GetBLEDeviceIdentificationInfo(mDeviceIdInfo); SuccessOrExit(err); if (!mFlags.Has(Flags::kDeviceNameSet)) @@ -555,22 +580,8 @@ CHIP_ERROR BLEManagerImpl::ConfigureAdvertisingData(void) advData[index++] = ShortUUID_CHIPoBLEService[0]; // AD value advData[index++] = ShortUUID_CHIPoBLEService[1]; - // TODO:: replace the hardcoded values by calling the GetBLEDeviceIdentificationInfo - advData[index++] = 0; // OpCode - advData[index++] = 0; // DeviceDiscriminatorAndAdvVersion [] - advData[index++] = 15; // DeviceDiscriminatorAndAdvVersion [] - advData[index++] = 241; // DeviceVendorId [] - advData[index++] = 255; // DeviceVendorId [] - advData[index++] = 5; // DeviceProductId[] - advData[index++] = 128; // DeviceProductId[] - advData[index++] = 0; // AdditionalDataFlag - - //! prepare advertise data //local/device name - advData[index++] = strlen(RSI_BLE_DEV_NAME) + 1; - advData[index++] = 9; - - memcpy(&advData[index], RSI_BLE_DEV_NAME, strlen(RSI_BLE_DEV_NAME)); // AD value - index += strlen(RSI_BLE_DEV_NAME); + memcpy(&advData[index], (void *) &mDeviceIdInfo, mDeviceIdInfoLength); // AD value + index += mDeviceIdInfoLength; #if CHIP_ENABLE_ADDITIONAL_DATA_ADVERTISING ReturnErrorOnFailure(EncodeAdditionalDataTlv()); @@ -612,10 +623,6 @@ CHIP_ERROR BLEManagerImpl::StartAdvertising(void) ChipLogDetail(DeviceLayer, "Start BLE advertissement"); } - // bd_addr unusedBdAddr; // We can ignore this field when setting random address. - - // (void) unusedBdAddr; - err = ConfigureAdvertisingData(); SuccessOrExit(err); @@ -656,13 +663,7 @@ CHIP_ERROR BLEManagerImpl::StopAdvertising(void) { mFlags.Clear(Flags::kAdvertising).Clear(Flags::kRestartAdvertising); mFlags.Set(Flags::kFastAdvertisingEnabled, true); - - // ret = sl_bt_advertiser_stop(advertising_set_handle); - // sl_bt_advertiser_delete_set(advertising_set_handle); advertising_set_handle = 0xff; - // err = MapBLEError(ret); - // SuccessOrExit(err); - CancelBleAdvTimeoutTimer(); } @@ -720,19 +721,19 @@ void BLEManagerImpl::HandleConnectionCloseEvent(uint16_t reason) event.Type = DeviceEventType::kCHIPoBLEConnectionError; event.CHIPoBLEConnectionError.ConId = connHandle; - // switch (reason) - // { - // - // case RSI_REMOTE_DEV_TERMINATE_CONN: - // case RSI_BT_CTRL_REMOTE_DEVICE_TERMINATED_CONNECTION_DUE_TO_LOW_RESOURCES: - // case RSI_BT_CTRL_REMOTE_POWERING_OFF: - // event.CHIPoBLEConnectionError.Reason = BLE_ERROR_REMOTE_DEVICE_DISCONNECTED; - // break; - // default: - // event.CHIPoBLEConnectionError.Reason = BLE_ERROR_CHIPOBLE_PROTOCOL_ABORT; - // } + switch (reason) + { - // ChipLogProgress(DeviceLayer, "BLE GATT connection closed (con %u, reason %u)", connHandle, conn_evt->reason); + case RSI_BT_CTRL_REMOTE_USER_TERMINATED: + case RSI_BT_CTRL_REMOTE_DEVICE_TERMINATED_CONNECTION_DUE_TO_LOW_RESOURCES: + case RSI_BT_CTRL_REMOTE_POWERING_OFF: + event.CHIPoBLEConnectionError.Reason = BLE_ERROR_REMOTE_DEVICE_DISCONNECTED; + break; + default: + event.CHIPoBLEConnectionError.Reason = BLE_ERROR_CHIPOBLE_PROTOCOL_ABORT; + } + + ChipLogProgress(DeviceLayer, "BLE GATT connection closed (con %u, reason %x)", connHandle, reason); PlatformMgr().PostEventOrDie(&event); @@ -748,9 +749,9 @@ void BLEManagerImpl::HandleWriteEvent(rsi_ble_event_write_t evt) { // RSI_BLE_WRITE_REQUEST_EVENT ChipLogProgress(DeviceLayer, "Char Write Req, packet type %d", evt.pkt_type); - uint8_t attribute = (uint8_t) event_msg.rsi_ble_measurement_hndl; + // uint8_t attribute = (uint8_t) event_msg.rsi_ble_measurement_hndl; - WFX_RSI_LOG("attribute = %d,rsi_ble_measurement_hndl = %d", attribute, event_msg.rsi_ble_measurement_hndl); + WFX_RSI_LOG("event_msg.rsi_ble_gatt_server_client_config_hndl = %d", event_msg.rsi_ble_gatt_server_client_config_hndl); if (evt.handle[0] == (uint8_t) event_msg.rsi_ble_gatt_server_client_config_hndl) // TODO:: compare the handle exactly { @@ -763,13 +764,34 @@ void BLEManagerImpl::HandleWriteEvent(rsi_ble_event_write_t evt) } } +// TODO:: Need to implement this void BLEManagerImpl::HandleTXCharCCCDWrite(rsi_ble_event_write_t * evt) { - CHIP_ERROR err = CHIP_NO_ERROR; + CHIP_ERROR err = CHIP_NO_ERROR; + bool isIndicationEnabled = false; ChipDeviceEvent event; - // whether the client is enabling or disabling indications. + + // Determine if the client is enabling or disabling notification/indication. + if (evt->att_value[0] != 0) + { + isIndicationEnabled = true; + } + ChipLogProgress(DeviceLayer, "HandleTXcharCCCDWrite - Config Flags value : %d", evt->att_value[0]); + ChipLogProgress(DeviceLayer, "CHIPoBLE %s received", isIndicationEnabled ? "subscribe" : "unsubscribe"); + + if (isIndicationEnabled) + { + // Post an event to the CHIP queue to process either a CHIPoBLE Subscribe or Unsubscribe based on + // whether the client is enabling or disabling indications. + { + event.Type = DeviceEventType::kCHIPoBLESubscribe; + event.CHIPoBLESubscribe.ConId = 1; + err = PlatformMgr().PostEvent(&event); + } + } + else { - event.Type = DeviceEventType::kCHIPoBLESubscribe; + event.Type = DeviceEventType::kCHIPoBLEUnsubscribe; event.CHIPoBLESubscribe.ConId = 1; err = PlatformMgr().PostEvent(&event); } @@ -783,11 +805,6 @@ void BLEManagerImpl::HandleRXCharWrite(rsi_ble_event_write_t * evt) uint16_t writeLen = evt->length; uint8_t * data = (uint8_t *) evt->att_value; - for (int i = 0; i < evt->length; i++) - { - ChipLogDetail(DeviceLayer, "HandleRXCharWrite value : %d", evt->att_value[i]); - } - // Copy the data to a packet buffer. buf = System::PacketBufferHandle::NewWithData(data, writeLen, 0, 0); VerifyOrExit(!buf.IsNull(), err = CHIP_ERROR_NO_MEMORY); @@ -813,17 +830,6 @@ void BLEManagerImpl::HandleRXCharWrite(rsi_ble_event_write_t * evt) void BLEManagerImpl::HandleTxConfirmationEvent(BLE_CONNECTION_OBJECT conId) { ChipDeviceEvent event; - // uint8_t timerHandle = sInstance.GetTimerHandle(conId, false); - // - // ChipLogProgress(DeviceLayer, "Tx Confirmation received"); - // - // // stop indication confirmation timer // TODO:: Need to find the proper repleacement - // if (timerHandle < kMaxConnections) - // { - // ChipLogProgress(DeviceLayer, " stop soft timer"); - // // sl_bt_system_set_lazy_soft_timer(0, 0, timerHandle, false); - // } - event.Type = DeviceEventType::kCHIPoBLEIndicateConfirm; event.CHIPoBLEIndicateConfirm.ConId = conId; PlatformMgr().PostEventOrDie(&event); @@ -832,19 +838,7 @@ void BLEManagerImpl::HandleTxConfirmationEvent(BLE_CONNECTION_OBJECT conId) // TODO:: Need to Implement void BLEManagerImpl::HandleSoftTimerEvent(void) { - - // BLE Manager starts soft timers with timer handles less than kMaxConnections - // If we receive a callback for unknown timer handle ignore this. - // if (evt->data.evt_system_soft_timer.handle < kMaxConnections) - // { - // ChipLogProgress(DeviceLayer, "BLEManagerImpl::HandleSoftTimerEvent CHIPOBLE_PROTOCOL_ABORT"); - // ChipDeviceEvent event; - // event.Type = DeviceEventType::kCHIPoBLEConnectionError; - // event.CHIPoBLEConnectionError.ConId = mIndConfId[evt->data.evt_system_soft_timer.handle]; - // sInstance.mIndConfId[evt->data.evt_system_soft_timer.handle] = kUnusedIndex; - // event.CHIPoBLEConnectionError.Reason = BLE_ERROR_CHIPOBLE_PROTOCOL_ABORT; - // PlatformMgr().PostEventOrDie(&event); - // } + // TODO:: Need to Implement } bool BLEManagerImpl::RemoveConnection(uint8_t connectionHandle) @@ -941,12 +935,6 @@ CHIP_ERROR BLEManagerImpl::EncodeAdditionalDataTlv() // TODO:: Need the void BLEManagerImpl::HandleC3ReadRequest(void) { - // sl_bt_evt_gatt_server_user_read_request_t * readReq = - // (sl_bt_evt_gatt_server_user_read_request_t *) &(evt->data.evt_gatt_server_user_read_request); - // ChipLogDetail(DeviceLayer, "Read request received for CHIPoBLEChar_C3 - opcode:%d", readReq->att_opcode); - // sl_status_t ret = sl_bt_gatt_server_send_user_read_response(readReq->connection, readReq->characteristic, 0, - // sInstance.c3AdditionalDataBufferHandle->DataLength(), - // sInstance.c3AdditionalDataBufferHandle->Start(), nullptr); // if (ret != SL_STATUS_OK) // { diff --git a/src/platform/silabs/SiWx917/bluetooth/wfx_sl_ble_init.c b/src/platform/silabs/SiWx917/bluetooth/wfx_sl_ble_init.c index 115e5c16ffdcec..27f29d00b63791 100644 --- a/src/platform/silabs/SiWx917/bluetooth/wfx_sl_ble_init.c +++ b/src/platform/silabs/SiWx917/bluetooth/wfx_sl_ble_init.c @@ -36,128 +36,12 @@ rsi_ble_event_conn_status_t conn_event_to_app; rsi_ble_t att_list; sl_wfx_msg_t event_msg; +extern rsi_semaphore_handle_t sl_ble_event_sem; // Memory to initialize driver uint8_t bt_global_buf[BT_GLOBAL_BUFF_LEN]; -static uint8_t wfx_rsi_drv_buf[WFX_RSI_BUF_SZ]; const uint8_t ShortUUID_CHIPoBLEService[] = { 0xF6, 0xFF }; -/* Rsi driver Task will use as its stack */ -// StackType_t driverRsiTaskStack[WFX_RSI_WLAN_TASK_SZ] = { 0 }; - -/* Structure that will hold the TCB of the wfxRsi Task being created. */ -// StaticTask_t driverRsiTaskBuffer; - -StaticTask_t rsiBLETaskStruct; - -/* wfxRsi Task will use as its stack */ -StackType_t wfxBLETaskStack[WFX_RSI_TASK_SZ] = { 0 }; - -int32_t ble_rsi_task(void) -{ - int32_t status; - uint8_t buf[RSI_RESPONSE_HOLD_BUFF_SIZE]; - // extern void rsi_hal_board_init(void); - // - // WFX_RSI_LOG("%s: starting(HEAP_SZ = %d)", __func__, SL_HEAP_SIZE); - // - // //! Driver initialization - // status = rsi_driver_init(wfx_rsi_drv_buf, WFX_RSI_BUF_SZ); - // if ((status < RSI_DRIVER_STATUS) || (status > WFX_RSI_BUF_SZ)) - // { - // WFX_RSI_LOG("%s: error: RSI Driver initialization failed with status: %02x", __func__, status); - // return status; - // } - // - // WFX_RSI_LOG("%s: rsi_device_init", __func__); - // - // /* ! Redpine module intialisation */ - // if ((status = rsi_device_init(LOAD_NWP_FW)) != RSI_SUCCESS) - // { - // WFX_RSI_LOG("%s: error: rsi_device_init failed with status: %02x", __func__, status); - // return status; - // } - // WFX_RSI_LOG("%s: start wireless drv task", __func__); - // - // /* - // * Create the driver task - // */ - // wfx_rsi.drv_task = xTaskCreateStatic((TaskFunction_t) rsi_wireless_driver_task, "rsi_drv", WFX_RSI_WLAN_TASK_SZ, NULL, - // 1, driverRsiTaskStack, &driverRsiTaskBuffer); - // if (NULL == wfx_rsi.drv_task) - // { - // WFX_RSI_LOG("%s: error: Create the driver task failed", __func__); - // return RSI_ERROR_INVALID_PARAM; - // } - // - // /* Initialize WiSeConnect or Module features. */ - // WFX_RSI_LOG("%s: rsi_wireless_init", __func__); - // if ((status = rsi_wireless_init(OPER_MODE_0, RSI_OPERMODE_WLAN_BLE)) != RSI_SUCCESS) - // { - // WFX_RSI_LOG("%s: error: Initialize WiSeConnect failed with status: %02x", __func__, status); - // return status; - // } - // - // WFX_RSI_LOG("%s: get FW version..", __func__); - // - // /* - // * Get the MAC and other info to let the user know about it. - // */ - // if (rsi_wlan_get(RSI_FW_VERSION, buf, sizeof(buf)) != RSI_SUCCESS) - // { - // WFX_RSI_LOG("%s: error: rsi_wlan_get(RSI_FW_VERSION) failed with status: %02x", __func__, status); - // return status; - // } - // - // buf[sizeof(buf) - 1] = 0; - // WFX_RSI_LOG("%s: RSI firmware version: %s", __func__, buf); - // //! Send feature frame - // if ((status = rsi_send_feature_frame()) != RSI_SUCCESS) - // { - // WFX_RSI_LOG("%s: error: rsi_send_feature_frame failed with status: %02x", __func__, status); - // return status; - // } - // - // WFX_RSI_LOG("%s: sent rsi_send_feature_frame", __func__); - // /* initializes wlan radio parameters and WLAN supplicant parameters. - // */ - // (void) rsi_wlan_radio_init(); /* Required so we can get MAC address */ - // if ((status = rsi_wlan_get(RSI_MAC_ADDRESS, &wfx_rsi.sta_mac.octet[0], RESP_BUFF_SIZE)) != RSI_SUCCESS) - // { - // WFX_RSI_LOG("%s: error: rsi_wlan_get failed with status: %02x", __func__, status); - // return status; - // } - - // 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); - - // 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, NULL, - rsi_ble_on_mtu_event, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - rsi_ble_on_event_indication_confirmation, NULL); - - WFX_RSI_LOG("registering rsi_ble_add_service"); - - // Exchange of GATT info with BLE stack - rsi_ble_add_matter_service(); - - // initializing the application events map - rsi_ble_app_init_events(); - - wfx_rsi.ble_task = xTaskCreateStatic((TaskFunction_t) rsi_ble_event_handling_task, "rsi_ble", WFX_RSI_TASK_SZ, NULL, 2, - wfxBLETaskStack, &rsiBLETaskStruct); - WFX_RSI_LOG("%s: rsi_task_suspend init_task ", __func__); - if (wfx_rsi.ble_task == NULL) - { - WFX_RSI_LOG("%s: error: failed to create ble task.", __func__); - } - - WFX_RSI_LOG("%s complete", __func__); - // rsi_task_destroy((rsi_task_handle_t *)wfx_rsi.init_task); - return RSI_SUCCESS; -} - /*==============================================*/ /** * @fn rsi_ble_app_init_events @@ -169,10 +53,10 @@ int32_t ble_rsi_task(void) */ void rsi_ble_app_init_events() { + WFX_RSI_LOG("%s: starting", __func__); 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 - WFX_RSI_LOG("Function :: rsi_ble_app_init_events"); return; } @@ -187,6 +71,7 @@ void rsi_ble_app_init_events() */ void rsi_ble_app_clear_event(uint32_t event_num) { + WFX_RSI_LOG("%s: starting", __func__); event_msg.event_num = event_num; event_msg.ble_app_event_map &= ~BIT(event_num); return; @@ -203,8 +88,7 @@ void rsi_ble_app_clear_event(uint32_t event_num) */ void rsi_ble_on_mtu_event(rsi_ble_event_mtu_t * rsi_ble_mtu) { - WFX_RSI_LOG(" RSI_BLE : rsi_ble_on_mtu_event"); - memset(&event_msg.rsi_ble_mtu, 0, sizeof(rsi_ble_event_mtu_t)); + WFX_RSI_LOG("%s: starting", __func__); memcpy(&event_msg.rsi_ble_mtu, rsi_ble_mtu, sizeof(rsi_ble_event_mtu_t)); rsi_ble_app_set_event(RSI_BLE_MTU_EVENT); } @@ -221,8 +105,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) { - WFX_RSI_LOG(" RSI_BLE : rsi_ble_on_gatt_write_event"); - memset(&event_msg.rsi_ble_write, 0, sizeof(rsi_ble_event_write_t)); + WFX_RSI_LOG("%s: starting", __func__); 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); @@ -239,7 +122,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) { - WFX_RSI_LOG(" RSI_BLE : rsi_ble_on_enhance_conn_status_event"); + WFX_RSI_LOG("%s: starting", __func__); 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); @@ -258,7 +141,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) { - WFX_RSI_LOG(" RSI_BLE : rsi_ble_on_disconnect_event"); + WFX_RSI_LOG("%s: starting", __func__); event_msg.reason = reason; memcpy(event_msg.resp_disconnect, resp_disconnect, sizeof(rsi_ble_event_disconnect_t)); rsi_ble_app_set_event(RSI_BLE_DISCONN_EVENT); @@ -275,7 +158,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) { - WFX_RSI_LOG(" RSI_BLE : rsi_ble_on_event_indication_confirmation"); + WFX_RSI_LOG("%s: starting", __func__); 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); @@ -318,7 +201,9 @@ int32_t rsi_ble_app_get_event(void) */ void rsi_ble_app_set_event(uint32_t event_num) { + WFX_RSI_LOG("%s: starting", __func__); event_msg.ble_app_event_map |= BIT(event_num); + rsi_semaphore_post(&sl_ble_event_sem); return; } diff --git a/src/platform/silabs/SiWx917/bluetooth/wfx_sl_ble_init.h b/src/platform/silabs/SiWx917/bluetooth/wfx_sl_ble_init.h index 497d2b5ee33bfe..e52e1553de540d 100644 --- a/src/platform/silabs/SiWx917/bluetooth/wfx_sl_ble_init.h +++ b/src/platform/silabs/SiWx917/bluetooth/wfx_sl_ble_init.h @@ -53,8 +53,36 @@ #include "rsi_board.h" #endif +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; + 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_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; + #define ATT_REC_IN_HOST 0 +#define RSI_BT_CTRL_REMOTE_USER_TERMINATED 0x4E13 +#define RSI_BT_CTRL_REMOTE_DEVICE_TERMINATED_CONNECTION_DUE_TO_LOW_RESOURCES 0x4E14 +#define RSI_BT_CTRL_REMOTE_POWERING_OFF 0x4E15 +#define RSI_BT_CTRL_TERMINATED_MIC_FAILURE 0x4E3D +#define RSI_BT_FAILED_TO_ESTABLISH_CONN 0x4E3E +#define RSI_BT_INVALID_RANGE 0x4E60 + #define RSI_BLE_MATTER_CUSTOM_SERVICE_UUID 0 #define RSI_BLE_MATTER_CUSTOM_SERVICE_SIZE 2 #define RSI_BLE_MATTER_CUSTOM_SERVICE_VALUE_16 0xFFF6 @@ -79,26 +107,7 @@ #define RSI_BLE_CHARACTERISTIC_TX_MEASUREMENT_HANDLE_LOCATION 4 #define RSI_BLE_CHARACTERISTIC_TX_GATT_SERVER_CLIENT_HANDLE_LOCATION 5 -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; - 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_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; -} sl_wfx_msg_t; - -int32_t ble_rsi_task(void); +// ALL Ble functions 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); diff --git a/third_party/silabs/SiWx917_sdk.gni b/third_party/silabs/SiWx917_sdk.gni index b50ceedf817803..7b5b3fbecbfc9f 100644 --- a/third_party/silabs/SiWx917_sdk.gni +++ b/third_party/silabs/SiWx917_sdk.gni @@ -24,7 +24,9 @@ declare_args() { # Location of the efr32 SDK. efr32_sdk_root = "${chip_root}/third_party/silabs/gecko_sdk" sdk_support_root = "${chip_root}/third_party/silabs/matter_support" - wiseconnect_sdk_root = "${chip_root}/third_party/silabs/wisemcu-wifi-bt-sdk" + wiseconnect_sdk_root = + "${chip_root}/third_party/silabs/wiseconnect-wifi-bt-sdk" + wisemcu_sdk_root = "${chip_root}/third_party/silabs/wisemcu-wifi-bt-sdk" examples_plat_dir = "${chip_root}/examples/platform/silabs/SiWx917" # Build openthread with prebuilt silabs lib @@ -84,21 +86,22 @@ template("efr32_sdk") { "${sdk_support_root}/platform/emdrv/nvm3/inc", "${sdk_support_root}/matter/mbedtls/tinycrypt/inc", "${chip_root}/third_party/mbedtls/repo/include", + "${chip_root}/third_party/mbedtls/repo/library", ### CCP includes ### - "${wiseconnect_sdk_root}/platforms/si91x/drivers/peripheral_drivers/inc", - "${wiseconnect_sdk_root}/platforms/si91x/core/chip/inc", - "${wiseconnect_sdk_root}/platforms/si91x/core/config", - "${wiseconnect_sdk_root}/platforms/si91x/drivers/cmsis_driver/config", - "${wiseconnect_sdk_root}/platforms/si91x/drivers/rom_driver/inc", - "${wiseconnect_sdk_root}/platforms/si91x/drivers/systemlevel/inc", - - "${wiseconnect_sdk_root}/platforms/si91x/drivers/cmsis_driver", - "${wiseconnect_sdk_root}/platforms/si91x/drivers/cmsis_driver/CMSIS/Driver/Include", - "${wiseconnect_sdk_root}/platforms/si91x/boards/brd4325a/inc", - "${wiseconnect_sdk_root}/platforms/si91x/core/cmsis", - "${wiseconnect_sdk_root}/third_party/freertos/include", - "${wiseconnect_sdk_root}/third_party/freertos/portable/GCC/ARM_CM4F", + "${wisemcu_sdk_root}/platforms/si91x/drivers/peripheral_drivers/inc", + "${wisemcu_sdk_root}/platforms/si91x/core/chip/inc", + "${wisemcu_sdk_root}/platforms/si91x/core/config", + "${wisemcu_sdk_root}/platforms/si91x/drivers/cmsis_driver/config", + "${wisemcu_sdk_root}/platforms/si91x/drivers/rom_driver/inc", + "${wisemcu_sdk_root}/platforms/si91x/drivers/systemlevel/inc", + + "${wisemcu_sdk_root}/platforms/si91x/drivers/cmsis_driver", + "${wisemcu_sdk_root}/platforms/si91x/drivers/cmsis_driver/CMSIS/Driver/Include", + "${wisemcu_sdk_root}/platforms/si91x/boards/brd4325a/inc", + "${wisemcu_sdk_root}/platforms/si91x/core/cmsis", + "${wisemcu_sdk_root}/third_party/freertos/include", + "${wisemcu_sdk_root}/third_party/freertos/portable/GCC/ARM_CM4F", "${examples_plat_dir}/device/inc", "${wiseconnect_sdk_root}/sapi/include", @@ -138,6 +141,7 @@ template("efr32_sdk") { "RSI_BLE_ENABLE=1", "BRD4325A", "CHIP_9117", + "RSI_BLE_ENABLE=1", "TINYCRYPT_PRIMITIVES", "OPTIMIZE_TINYCRYPT_ASM", "RS91X_BLE_ENABLE=1", @@ -254,46 +258,42 @@ template("efr32_sdk") { "${sdk_support_root}/platform/emdrv/nvm3/src/nvm3_lock.c", ######## CCP Platform ######### - "${wiseconnect_sdk_root}/platforms/si91x/boards/brd4325a/src/rsi_board.c", - - #"${wiseconnect_sdk_root}/platforms/si91x/boards/brd4325a/src/syscalls.c", - "${wiseconnect_sdk_root}/platforms/si91x/core/chip/src/rsi_deepsleep_commonflash.c", - "${wiseconnect_sdk_root}/platforms/si91x/core/chip/src/rsi_ps_ram_func.c", - "${wiseconnect_sdk_root}/platforms/si91x/core/chip/src/rsi_system_config.c", - "${wiseconnect_sdk_root}/platforms/si91x/core/chip/src/system_RS1xxxx.c", - - #"${wiseconnect_sdk_root}/platforms/si91x/drivers/cmsis_driver/UDMA.c", - #"${wiseconnect_sdk_root}/platforms/si91x/drivers/cmsis_driver/USART.c", - - "${wiseconnect_sdk_root}/platforms/si91x/drivers/peripheral_drivers/src/clock_update.c", - "${wiseconnect_sdk_root}/platforms/si91x/drivers/peripheral_drivers/src/rsi_comparator.c", - "${wiseconnect_sdk_root}/platforms/si91x/drivers/peripheral_drivers/src/rsi_egpio.c", - "${wiseconnect_sdk_root}/platforms/si91x/drivers/peripheral_drivers/src/rsi_udma.c", - "${wiseconnect_sdk_root}/platforms/si91x/drivers/peripheral_drivers/src/rsi_udma_wrapper.c", - "${wiseconnect_sdk_root}/platforms/si91x/drivers/peripheral_drivers/src/rsi_usart.c", - "${wiseconnect_sdk_root}/platforms/si91x/drivers/systemlevel/src/rsi_ipmu.c", - "${wiseconnect_sdk_root}/platforms/si91x/drivers/systemlevel/src/rsi_pll.c", - "${wiseconnect_sdk_root}/platforms/si91x/drivers/systemlevel/src/rsi_power_save.c", - "${wiseconnect_sdk_root}/platforms/si91x/drivers/systemlevel/src/rsi_processor_sensor.c", - "${wiseconnect_sdk_root}/platforms/si91x/drivers/systemlevel/src/rsi_rtc.c", - "${wiseconnect_sdk_root}/platforms/si91x/drivers/systemlevel/src/rsi_temp_sensor.c", - "${wiseconnect_sdk_root}/platforms/si91x/drivers/systemlevel/src/rsi_time_period.c", - "${wiseconnect_sdk_root}/platforms/si91x/drivers/systemlevel/src/rsi_ulpss_clk.c", - "${wiseconnect_sdk_root}/platforms/si91x/drivers/systemlevel/src/rsi_wwdt.c", - "${wiseconnect_sdk_root}/third_party/freertos/croutine.c", - "${wiseconnect_sdk_root}/third_party/freertos/event_groups.c", - "${wiseconnect_sdk_root}/third_party/freertos/list.c", - "${wiseconnect_sdk_root}/third_party/freertos/portable/GCC/ARM_CM4F/port.c", - "${wiseconnect_sdk_root}/third_party/freertos/queue.c", - "${wiseconnect_sdk_root}/third_party/freertos/stream_buffer.c", - "${wiseconnect_sdk_root}/third_party/freertos/tasks.c", - "${wiseconnect_sdk_root}/third_party/freertos/timers.c", + "${wisemcu_sdk_root}/platforms/si91x/boards/brd4325a/src/rsi_board.c", + + #"${wisemcu_sdk_root}/platforms/si91x/boards/brd4325a/src/syscalls.c", + "${wisemcu_sdk_root}/platforms/si91x/core/chip/src/rsi_deepsleep_commonflash.c", + "${wisemcu_sdk_root}/platforms/si91x/core/chip/src/rsi_ps_ram_func.c", + "${wisemcu_sdk_root}/platforms/si91x/core/chip/src/rsi_system_config.c", + "${wisemcu_sdk_root}/platforms/si91x/core/chip/src/system_RS1xxxx.c", # Bluetooth "${wiseconnect_sdk_root}/sapi/bluetooth/rsi_ble_gap_apis.c", "${wiseconnect_sdk_root}/sapi/bluetooth/rsi_ble_gatt_apis.c", "${wiseconnect_sdk_root}/sapi/bluetooth/rsi_bt_common_apis.c", "${wiseconnect_sdk_root}/sapi/driver/rsi_bt_ble.c", + "${wisemcu_sdk_root}/platforms/si91x/drivers/peripheral_drivers/src/clock_update.c", + "${wisemcu_sdk_root}/platforms/si91x/drivers/peripheral_drivers/src/rsi_comparator.c", + "${wisemcu_sdk_root}/platforms/si91x/drivers/peripheral_drivers/src/rsi_egpio.c", + "${wisemcu_sdk_root}/platforms/si91x/drivers/peripheral_drivers/src/rsi_udma.c", + "${wisemcu_sdk_root}/platforms/si91x/drivers/peripheral_drivers/src/rsi_udma_wrapper.c", + "${wisemcu_sdk_root}/platforms/si91x/drivers/peripheral_drivers/src/rsi_usart.c", + "${wisemcu_sdk_root}/platforms/si91x/drivers/systemlevel/src/rsi_ipmu.c", + "${wisemcu_sdk_root}/platforms/si91x/drivers/systemlevel/src/rsi_pll.c", + "${wisemcu_sdk_root}/platforms/si91x/drivers/systemlevel/src/rsi_power_save.c", + "${wisemcu_sdk_root}/platforms/si91x/drivers/systemlevel/src/rsi_processor_sensor.c", + "${wisemcu_sdk_root}/platforms/si91x/drivers/systemlevel/src/rsi_rtc.c", + "${wisemcu_sdk_root}/platforms/si91x/drivers/systemlevel/src/rsi_temp_sensor.c", + "${wisemcu_sdk_root}/platforms/si91x/drivers/systemlevel/src/rsi_time_period.c", + "${wisemcu_sdk_root}/platforms/si91x/drivers/systemlevel/src/rsi_ulpss_clk.c", + "${wisemcu_sdk_root}/platforms/si91x/drivers/systemlevel/src/rsi_wwdt.c", + "${wisemcu_sdk_root}/third_party/freertos/croutine.c", + "${wisemcu_sdk_root}/third_party/freertos/event_groups.c", + "${wisemcu_sdk_root}/third_party/freertos/list.c", + "${wisemcu_sdk_root}/third_party/freertos/portable/GCC/ARM_CM4F/port.c", + "${wisemcu_sdk_root}/third_party/freertos/queue.c", + "${wisemcu_sdk_root}/third_party/freertos/stream_buffer.c", + "${wisemcu_sdk_root}/third_party/freertos/tasks.c", + "${wisemcu_sdk_root}/third_party/freertos/timers.c", # mbedtls "${chip_root}/third_party/mbedtls/repo/library/aes.c",