From 287187748383e801974c0e5cc0fca939938b8a28 Mon Sep 17 00:00:00 2001 From: wyhong <30567533+wy-hh@users.noreply.github.com> Date: Wed, 19 Jul 2023 16:19:47 +0800 Subject: [PATCH] [Bouffalolab] Add BL702 Ethernet support (#27620) * Add BL706 ethernet support * update sdk commit * fix compile error * update matter file * fix restyle * fix comiple error * Add BL706 ethernet support * update sdk commit * fix compile error * update matter file * fix restyle * fix comiple error * fix restyle --------- Co-authored-by: Justin Wood --- .../lighting-app/bouffalolab/bl602/BUILD.gn | 18 +- .../bouffalolab/bl602/CHIPProjectConfig.h | 8 - .../lighting-app/bouffalolab/bl602/args.gni | 1 - .../lighting-app/bouffalolab/bl602/board.h | 7 - .../lighting-app/bouffalolab/bl702/BUILD.gn | 65 ++-- .../bouffalolab/bl702/CHIPProjectConfig.h | 8 - .../lighting-app/bouffalolab/bl702/args.gni | 6 - .../lighting-app/bouffalolab/bl702/board.h | 19 -- .../lighting-app/bouffalolab/bl702l/BUILD.gn | 14 +- .../bouffalolab/bl702l/CHIPProjectConfig.h | 8 - .../lighting-app/bouffalolab/bl702l/args.gni | 6 - .../lighting-app/bouffalolab/bl702l/board.h | 4 - .../bouffalolab/common/AppTask.cpp | 293 +++++++----------- .../lighting-app/bouffalolab/common/AppTask.h | 31 +- .../data_model/lighting-app-thread.matter | 10 +- .../data_model/lighting-app-thread.zap | 15 +- .../data_model/lighting-app-wifi.matter | 10 +- .../data_model/lighting-app-wifi.zap | 15 +- .../bl702/ldscripts/psram_flash.ld | 93 ++---- .../bl702l/ldscripts/psram_flash_rom.ld | 110 +++---- .../bouffalolab/common/plat/MemMonitoring.cpp | 2 - .../bouffalolab/common/plat/demo_pwm.c | 7 +- .../platform/bouffalolab/common/plat/main.cpp | 89 +++--- .../bouffalolab/common/plat/platform.cpp | 141 +++++---- .../platform/bouffalolab/common/plat/uart.c | 67 +++- .../platform/bouffalolab/common/plat/uart.h | 4 + .../route_hook/bl_route_hook.c | 31 +- .../route_hook/bl_route_hook.h | 0 .../route_hook/bl_route_table.c | 2 +- .../route_hook/bl_route_table.h | 0 scripts/build/build/targets.py | 17 +- scripts/build/builders/bouffalolab.py | 31 +- .../build/testdata/all_targets_linux_x64.txt | 2 +- src/lwip/BUILD.gn | 37 +-- src/platform/BUILD.gn | 4 +- .../BL602/ConfigurationManagerImpl.cpp | 10 - .../BL602/ConnectivityManagerImpl.cpp | 174 ++++------- .../BL602/DiagnosticDataProviderImpl.cpp | 71 ----- .../BL602/NetworkCommissioningDriver.cpp | 89 ++---- .../BL602/NetworkCommissioningDriver.h | 4 +- .../bouffalolab/BL602/PlatformManagerImpl.cpp | 145 +-------- src/platform/bouffalolab/BL602/args.gni | 2 + .../bouffalolab/BL602/wifi_mgmr_portable.c | 5 + .../bouffalolab/BL602/wifi_mgmr_portable.h | 1 + src/platform/bouffalolab/BL702/BUILD.gn | 10 + .../BL702/ConfigurationManagerImpl.cpp | 43 +++ .../BL702/ConnectivityManagerImpl.cpp | 43 +++ .../BL702/DiagnosticDataProviderImpl.cpp | 31 +- .../bouffalolab/BL702/EthernetInterface.c | 90 ++++++ .../bouffalolab/BL702/EthernetInterface.h | 30 ++ .../bouffalolab/BL702/PlatformManagerImpl.cpp | 19 +- src/platform/bouffalolab/BL702/args.gni | 4 + .../bouffalolab/BL702/lwip_default_hooks.h | 17 + .../BL702L/DiagnosticDataProviderImpl.cpp | 78 ++--- .../BL702L/PlatformManagerImpl.cpp | 4 - .../BL702L/ThreadStackManagerImpl.cpp | 2 - src/platform/bouffalolab/BL702L/args.gni | 4 + src/platform/bouffalolab/common/BLConfig.cpp | 14 +- src/platform/bouffalolab/common/BLConfig.h | 6 - .../bouffalolab/common/BLEManagerImpl.cpp | 6 +- .../bouffalolab/common/BLEManagerImpl.h | 2 - .../common/CHIPDevicePlatformConfig.h | 2 +- .../bouffalolab/common/CHIPPlatformConfig.h | 9 - .../common/ConfigurationManagerImpl.cpp | 6 - .../common/ConfigurationManagerImpl.h | 4 + .../common/ConnectivityManagerImpl.cpp | 266 +++++++++++++++- .../common/ConnectivityManagerImpl.h | 48 ++- .../common/DiagnosticDataProviderImpl.cpp | 64 ++++ .../bouffalolab/common/SystemPlatformConfig.h | 1 + src/platform/device.gni | 11 +- third_party/bouffalolab/bl702/bl_iot_sdk.gni | 102 +++--- third_party/bouffalolab/bl702l/bl_iot_sdk.gni | 3 +- third_party/bouffalolab/repo | 2 +- 73 files changed, 1323 insertions(+), 1274 deletions(-) rename examples/platform/bouffalolab/{bl602 => common}/route_hook/bl_route_hook.c (88%) rename examples/platform/bouffalolab/{bl602 => common}/route_hook/bl_route_hook.h (100%) rename examples/platform/bouffalolab/{bl602 => common}/route_hook/bl_route_table.c (100%) rename examples/platform/bouffalolab/{bl602 => common}/route_hook/bl_route_table.h (100%) create mode 100644 src/platform/bouffalolab/BL702/ConfigurationManagerImpl.cpp create mode 100644 src/platform/bouffalolab/BL702/ConnectivityManagerImpl.cpp create mode 100644 src/platform/bouffalolab/BL702/EthernetInterface.c create mode 100644 src/platform/bouffalolab/BL702/EthernetInterface.h create mode 100644 src/platform/bouffalolab/BL702/lwip_default_hooks.h diff --git a/examples/lighting-app/bouffalolab/bl602/BUILD.gn b/examples/lighting-app/bouffalolab/bl602/BUILD.gn index 125e9ea45a3e0f..592cc5a2fbe72a 100644 --- a/examples/lighting-app/bouffalolab/bl602/BUILD.gn +++ b/examples/lighting-app/bouffalolab/bl602/BUILD.gn @@ -47,6 +47,7 @@ declare_args() { ota_auto_reboot_delay_seconds = 5 enable_heap_monitoring = false + enable_reset_counter = false setupPinCode = 20202021 setupDiscriminator = 3840 @@ -102,18 +103,20 @@ bouffalolab_executable("lighting_app") { "SYS_AOS_LOOP_ENABLE", ] + if (false == enable_reset_counter) { + defines += [ "BOOT_PIN_RESET=8" ] + } + bl_plat_name = "bl602" sources = [ - "${examples_plat_dir}/route_hook/bl_route_hook.c", - "${examples_plat_dir}/route_hook/bl_route_table.c", + "${examples_plat_common_dir}/route_hook/bl_route_hook.c", + "${examples_plat_common_dir}/route_hook/bl_route_table.c", ] if ("BL602-IoT-Matter-V1" == board) { defines += [ "BL602_IoT_Matter_V1" ] } else if ("BL602-NIGHT-LIGHT" == board) { defines += [ "BL602_NIGHT_LIGHT" ] - } else if ("BL602-IOT-DVK-3S" == board) { - defines += [ "BL602_IOT_DVK_3S" ] } sources += [ @@ -121,6 +124,7 @@ bouffalolab_executable("lighting_app") { "${example_common_dir}/AppTask.cpp", "${example_common_dir}/ZclCallbacks.cpp", "${examples_plat_common_dir}/plat/LEDWidget.cpp", + "${examples_plat_common_dir}/plat/OTAConfig.cpp", "${examples_plat_common_dir}/plat/aos_task.c", "${examples_plat_common_dir}/plat/demo_pwm.c", "${examples_plat_common_dir}/plat/main.cpp", @@ -140,6 +144,7 @@ bouffalolab_executable("lighting_app") { include_dirs = [ "${chip_root}/src/platform/bouffalolab/BL602", "${example_common_dir}", + "${examples_plat_common_dir}/route_hook", "${examples_plat_common_dir}/plat", "${examples_plat_dir}", ] @@ -208,11 +213,6 @@ bouffalolab_executable("lighting_app") { defines += [ "HEAP_MONITORING=1" ] } - if (chip_enable_ota_requestor) { - defines += [ "OTA_ENABLED" ] - sources += [ "${examples_plat_common_dir}/plat/OTAConfig.cpp" ] - } - cflags_c = [ "-Wno-sign-compare" ] ldscript = "${examples_plat_dir}/ldscripts/flash_rom.ld" diff --git a/examples/lighting-app/bouffalolab/bl602/CHIPProjectConfig.h b/examples/lighting-app/bouffalolab/bl602/CHIPProjectConfig.h index 18b7923935696a..3e779aea1ef5fd 100644 --- a/examples/lighting-app/bouffalolab/bl602/CHIPProjectConfig.h +++ b/examples/lighting-app/bouffalolab/bl602/CHIPProjectConfig.h @@ -1,7 +1,6 @@ /* * * Copyright (c) 2021 Project CHIP Authors - * Copyright (c) 2019 Google LLC. * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -107,13 +106,6 @@ */ #define CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_REVISION 1 -/** - * CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE - * - * Enable support for Chip-over-BLE (CHIPoBLE). - */ -#define CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE 1 - /** * CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER * diff --git a/examples/lighting-app/bouffalolab/bl602/args.gni b/examples/lighting-app/bouffalolab/bl602/args.gni index 1a7e2dd427e021..4c69abdaa1259f 100644 --- a/examples/lighting-app/bouffalolab/bl602/args.gni +++ b/examples/lighting-app/bouffalolab/bl602/args.gni @@ -23,7 +23,6 @@ pw_log_BACKEND = "${chip_root}/src/lib/support/pw_log_chip" pw_assert_BACKEND = "$dir_pw_assert_log" pw_rpc_CONFIG = "$dir_pw_rpc:disable_global_mutex" -chip_enable_ota_requestor = true chip_detail_logging = false pw_build_LINK_DEPS = [ diff --git a/examples/lighting-app/bouffalolab/bl602/board.h b/examples/lighting-app/bouffalolab/bl602/board.h index 236c974ddebde5..4e98b267f9acf9 100644 --- a/examples/lighting-app/bouffalolab/bl602/board.h +++ b/examples/lighting-app/bouffalolab/bl602/board.h @@ -48,11 +48,6 @@ #define LED_G_PIN_PORT 1 #define LED_G_PIN 11 -// comment out for last hardware -//#define LED_R_PIN_PORT 0 -//#define LED_R_PIN 20 -//#define LED_G_PIN 21 - #define MAX_PWM_CHANNEL 3 #else @@ -64,7 +59,5 @@ #endif -#define LED_BTN_RESET 8 - #define CHIP_UART_PIN_RX 7 #define CHIP_UART_PIN_TX 16 diff --git a/examples/lighting-app/bouffalolab/bl702/BUILD.gn b/examples/lighting-app/bouffalolab/bl702/BUILD.gn index 028a36f25cc0e7..b382aa7bc95cbc 100644 --- a/examples/lighting-app/bouffalolab/bl702/BUILD.gn +++ b/examples/lighting-app/bouffalolab/bl702/BUILD.gn @@ -49,6 +49,8 @@ declare_args() { config_cache_size = 8192 enable_heap_monitoring = false + enable_reset_counter = false + enable_cdc_module = false setupPinCode = 20202021 setupDiscriminator = 3840 @@ -74,10 +76,13 @@ bl_iot_sdk("sdk") { "CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR=${setupDiscriminator}", "OTA_PERIODIC_TIMEOUT=${ota_periodic_query_timeout_seconds}", "OTA_AUTO_REBOOT_DELAY=${ota_auto_reboot_delay_seconds}", - "OPENTHREAD_CONFIG_PLATFORM_XTAL_ACCURACY=40", "PRINT_DEBUG=0", ] + if (chip_enable_openthread) { + defines += [ "OPENTHREAD_CONFIG_PLATFORM_XTAL_ACCURACY=40" ] + } + if ("BL706C-22" == module_type) { defines += [ "CFG_PSRAM_DUAL_BANK=1" ] } @@ -117,20 +122,20 @@ bouffalolab_executable("lighting_app") { "START_ENTRY=bl702_main", ] - if (enable_psram) { - defines += [ "CFG_USE_PSRAM=1" ] + if (false == enable_reset_counter) { + defines += [ "BOOT_PIN_RESET=31" ] } - if ("BL706C-22" == module_type) { - defines += [ "BOARD_BTN_BOOT_PIN" ] + if (enable_psram) { + defines += [ "CFG_USE_PSRAM=1" ] } if ("XT-ZB6-DevKit" == board) { defines += [ "XT_ZB6_DevKit" ] } else if ("BL706-NIGHT-LIGHT" == board) { defines += [ "BL706_NIGHT_LIGHT" ] - } else if ("BL702-IoT-DVK" == board || "BL706-IoT-DVK" == board) { - defines += [ "BL706_IOT_DVK" ] + } else if ("BL706-ETH" == board) { + defines += [ "BL706_ETHERNET" ] } if (defined(enable_cdc_module) && enable_cdc_module) { @@ -141,6 +146,7 @@ bouffalolab_executable("lighting_app") { "${example_common_dir}/AppTask.cpp", "${example_common_dir}/ZclCallbacks.cpp", "${examples_plat_common_dir}/plat/LEDWidget.cpp", + "${examples_plat_common_dir}/plat/OTAConfig.cpp", "${examples_plat_common_dir}/plat/demo_pwm.c", "${examples_plat_common_dir}/plat/main.cpp", "${examples_plat_common_dir}/plat/platform.cpp", @@ -153,27 +159,38 @@ bouffalolab_executable("lighting_app") { "${chip_root}/examples/providers:device_info_provider", "${chip_root}/src/lib", "${chip_root}/src/setup_payload", - "${chip_root}/third_party/openthread/platforms:libopenthread-platform", - "${chip_root}/third_party/openthread/platforms:libopenthread-platform-utils", ] - if (chip_openthread_ftd) { - defines += [ "CHIP_DEVICE_CONFIG_THREAD_FTD=1" ] + if (chip_enable_openthread) { deps += [ - "${chip_root}/third_party/openthread/repo:libopenthread-cli-ftd", - "${chip_root}/third_party/openthread/repo:libopenthread-ftd", + "${chip_root}/third_party/openthread/platforms:libopenthread-platform", + "${chip_root}/third_party/openthread/platforms:libopenthread-platform-utils", ] + + if (chip_openthread_ftd) { + defines += [ "CHIP_DEVICE_CONFIG_THREAD_FTD=1" ] + deps += [ + "${chip_root}/third_party/openthread/repo:libopenthread-cli-ftd", + "${chip_root}/third_party/openthread/repo:libopenthread-ftd", + ] + } else { + defines += [ "CHIP_DEVICE_CONFIG_THREAD_FTD=0" ] + deps += [ + "${chip_root}/third_party/openthread/repo:libopenthread-cli-mtd", + "${chip_root}/third_party/openthread/repo:libopenthread-mtd", + ] + } } else { - defines += [ "CHIP_DEVICE_CONFIG_THREAD_FTD=0" ] - deps += [ - "${chip_root}/third_party/openthread/repo:libopenthread-cli-mtd", - "${chip_root}/third_party/openthread/repo:libopenthread-mtd", + sources += [ + "${examples_plat_common_dir}/route_hook/bl_route_hook.c", + "${examples_plat_common_dir}/route_hook/bl_route_table.c", ] } include_dirs = [ "${chip_root}/src/platform/bouffalolab/BL702", "${example_common_dir}", + "${examples_plat_common_dir}/route_hook", "${examples_plat_common_dir}/plat", ] @@ -212,11 +229,16 @@ bouffalolab_executable("lighting_app") { "${chip_root}/examples/common/pigweed:descriptor_service.nanopb_rpc", "${chip_root}/examples/common/pigweed:device_service.nanopb_rpc", "${chip_root}/examples/common/pigweed:lighting_service.nanopb_rpc", - "${chip_root}/examples/common/pigweed:ot_cli_service.nanopb_rpc", - "${chip_root}/examples/common/pigweed:thread_service.nanopb_rpc", "${examples_plat_common_dir}/rpc/pw_sys_io:pw_sys_io", ] + if (chip_enable_openthread) { + deps += [ + "${chip_root}/examples/common/pigweed:ot_cli_service.nanopb_rpc", + "${chip_root}/examples/common/pigweed:thread_service.nanopb_rpc", + ] + } + deps += pw_build_LINK_DEPS include_dirs += [ @@ -239,11 +261,6 @@ bouffalolab_executable("lighting_app") { defines += [ "HEAP_MONITORING=1" ] } - if (chip_enable_ota_requestor) { - defines += [ "OTA_ENABLED" ] - sources += [ "${examples_plat_common_dir}/plat/OTAConfig.cpp" ] - } - if (enable_psram) { ldscript = "${examples_plat_dir}/ldscripts/psram_flash.ld" } else { diff --git a/examples/lighting-app/bouffalolab/bl702/CHIPProjectConfig.h b/examples/lighting-app/bouffalolab/bl702/CHIPProjectConfig.h index 1a357d1b10ccbc..19ff4f3eaf13f4 100644 --- a/examples/lighting-app/bouffalolab/bl702/CHIPProjectConfig.h +++ b/examples/lighting-app/bouffalolab/bl702/CHIPProjectConfig.h @@ -1,7 +1,6 @@ /* * * Copyright (c) 2020 Project CHIP Authors - * Copyright (c) 2019 Google LLC. * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -101,13 +100,6 @@ #define CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION 0x0001 #endif -/** - * CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE - * - * Enable support for Chip-over-BLE (CHIPoBLE). - */ -#define CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE 1 - /** * CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER * diff --git a/examples/lighting-app/bouffalolab/bl702/args.gni b/examples/lighting-app/bouffalolab/bl702/args.gni index 8087dc1470f236..e35ae89f6a9426 100644 --- a/examples/lighting-app/bouffalolab/bl702/args.gni +++ b/examples/lighting-app/bouffalolab/bl702/args.gni @@ -23,12 +23,6 @@ pw_log_BACKEND = "${chip_root}/src/lib/support/pw_log_chip" pw_assert_BACKEND = "$dir_pw_assert_log" pw_rpc_CONFIG = "$dir_pw_rpc:disable_global_mutex" -chip_enable_ble = true -chip_enable_openthread = true -chip_enable_wifi = false -lwip_platform = "bl702" - -chip_enable_ota_requestor = true chip_detail_logging = false pw_build_LINK_DEPS = [ diff --git a/examples/lighting-app/bouffalolab/bl702/board.h b/examples/lighting-app/bouffalolab/bl702/board.h index 6b5ee1499400bd..b8c145cb99646f 100644 --- a/examples/lighting-app/bouffalolab/bl702/board.h +++ b/examples/lighting-app/bouffalolab/bl702/board.h @@ -52,15 +52,6 @@ #elif defined(XT_ZB6_DevKit) -// #define LED_B_PIN_PORT 3 -// #define LED_B_PIN 18 - -// #define LED_R_PIN_PORT 4 -// #define LED_R_PIN 19 - -// #define LED_G_PIN_PORT 0 -// #define LED_G_PIN 20 - #define LED_PIN_PORT 3 #define LED_PIN 18 @@ -75,15 +66,5 @@ #endif -#if defined(BOARD_BTN_BOOT_PIN) -#define LED_BTN_RESET 31 -#endif - -#define SPI_WIFI_MISO_PIN 4 -#define SPI_WIFI_MOSI_PIN 5 -#define SPI_WIFI_CLK_PIN 3 -#define SPI_WIFI_CS_PIN 6 -#define SPI_WIFI_IRQ_PIN 10 - #define CHIP_UART_PIN_RX 15 #define CHIP_UART_PIN_TX 14 diff --git a/examples/lighting-app/bouffalolab/bl702l/BUILD.gn b/examples/lighting-app/bouffalolab/bl702l/BUILD.gn index db0209f260a25b..621416e5bb3deb 100644 --- a/examples/lighting-app/bouffalolab/bl702l/BUILD.gn +++ b/examples/lighting-app/bouffalolab/bl702l/BUILD.gn @@ -49,6 +49,7 @@ declare_args() { config_cache_size = 8192 enable_heap_monitoring = false + enable_reset_counter = false setupPinCode = 20202021 setupDiscriminator = 3840 @@ -97,6 +98,7 @@ chip_data_model("bouffalolab-lighting") { zap_pregenerated_dir = "${chip_root}/zzz_generated/lighting-app/zap-generated" is_server = true } + bouffalolab_executable("lighting_app") { output_name = "chip-bl702l-lighting-example.out" bl_plat_name = "bl702l" @@ -108,9 +110,11 @@ bouffalolab_executable("lighting_app") { "START_ENTRY=bl702_main", ] - defines += [ "CFG_USE_PSRAM=1" ] + if (false == enable_reset_counter) { + defines += [ "BOOT_PIN_RESET=16" ] + } - defines += [ "BOARD_BTN_BOOT_PIN" ] + defines += [ "CFG_USE_PSRAM=1" ] if ("BL704L" == board) { defines += [ "XT_ZB6_DevKit" ] @@ -124,6 +128,7 @@ bouffalolab_executable("lighting_app") { "${example_common_dir}/AppTask.cpp", "${example_common_dir}/ZclCallbacks.cpp", "${examples_plat_common_dir}/plat/LEDWidget.cpp", + "${examples_plat_common_dir}/plat/OTAConfig.cpp", "${examples_plat_common_dir}/plat/demo_pwm.c", "${examples_plat_common_dir}/plat/main.cpp", "${examples_plat_common_dir}/plat/platform.cpp", @@ -222,11 +227,6 @@ bouffalolab_executable("lighting_app") { defines += [ "HEAP_MONITORING=1" ] } - if (chip_enable_ota_requestor) { - defines += [ "OTA_ENABLED" ] - sources += [ "${examples_plat_common_dir}/plat/OTAConfig.cpp" ] - } - if (enable_psram) { ldscript = "${examples_plat_dir}/ldscripts/psram_flash_rom.ld" } else { diff --git a/examples/lighting-app/bouffalolab/bl702l/CHIPProjectConfig.h b/examples/lighting-app/bouffalolab/bl702l/CHIPProjectConfig.h index 1a357d1b10ccbc..19ff4f3eaf13f4 100644 --- a/examples/lighting-app/bouffalolab/bl702l/CHIPProjectConfig.h +++ b/examples/lighting-app/bouffalolab/bl702l/CHIPProjectConfig.h @@ -1,7 +1,6 @@ /* * * Copyright (c) 2020 Project CHIP Authors - * Copyright (c) 2019 Google LLC. * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -101,13 +100,6 @@ #define CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION 0x0001 #endif -/** - * CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE - * - * Enable support for Chip-over-BLE (CHIPoBLE). - */ -#define CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE 1 - /** * CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER * diff --git a/examples/lighting-app/bouffalolab/bl702l/args.gni b/examples/lighting-app/bouffalolab/bl702l/args.gni index a897d37c43b2cd..f2eb36a8b29f73 100644 --- a/examples/lighting-app/bouffalolab/bl702l/args.gni +++ b/examples/lighting-app/bouffalolab/bl702l/args.gni @@ -23,12 +23,6 @@ pw_log_BACKEND = "${chip_root}/src/lib/support/pw_log_chip" pw_assert_BACKEND = "$dir_pw_assert_log" pw_rpc_CONFIG = "$dir_pw_rpc:disable_global_mutex" -chip_enable_ble = true -chip_enable_openthread = true -chip_enable_wifi = false -lwip_platform = "bl702l" - -chip_enable_ota_requestor = true chip_detail_logging = false pw_build_LINK_DEPS = [ diff --git a/examples/lighting-app/bouffalolab/bl702l/board.h b/examples/lighting-app/bouffalolab/bl702l/board.h index 5bfcc5457ded45..62ee3648eede00 100644 --- a/examples/lighting-app/bouffalolab/bl702l/board.h +++ b/examples/lighting-app/bouffalolab/bl702l/board.h @@ -75,10 +75,6 @@ #endif -#if defined(BOARD_BTN_BOOT_PIN) -#define LED_BTN_RESET 16 -#endif - #define SPI_WIFI_MISO_PIN 4 #define SPI_WIFI_MOSI_PIN 5 #define SPI_WIFI_CLK_PIN 3 diff --git a/examples/lighting-app/bouffalolab/common/AppTask.cpp b/examples/lighting-app/bouffalolab/common/AppTask.cpp index 28d8e836625496..3171341a9b49ba 100644 --- a/examples/lighting-app/bouffalolab/common/AppTask.cpp +++ b/examples/lighting-app/bouffalolab/common/AppTask.cpp @@ -1,7 +1,6 @@ /* * * Copyright (c) 2020 Project CHIP Authors - * Copyright (c) 2019 Google LLC. * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,22 +16,14 @@ * limitations under the License. */ -#include -#include - #include -#include #include -#include #include #include #include #include #include -#include -#include -#include #include #if HEAP_MONITORING @@ -51,6 +42,9 @@ #include #endif +#include +#include + extern "C" { #include "board.h" #include @@ -140,21 +134,32 @@ void AppTask::AppTaskMain(void * pvParameter) app_event_t appEvent; bool onoff = false; +#ifndef BL706_ETHERNET sLightLED.Init(); +#endif -#ifdef LED_BTN_RESET +#ifdef BOOT_PIN_RESET ButtonInit(); #else /** Without RESET PIN defined, factory reset will be executed if power cycle count(resetCnt) >= APP_REBOOT_RESET_COUNT */ uint32_t resetCnt = 0; size_t saved_value_len = 0; ef_get_env_blob(APP_REBOOT_RESET_COUNT_KEY, &resetCnt, sizeof(resetCnt), &saved_value_len); - resetCnt++; - ef_set_env_blob(APP_REBOOT_RESET_COUNT_KEY, &resetCnt, sizeof(resetCnt)); - /** To share with RESET PIN logic, mButtonPressedTime is used to recorded resetCnt increased. - * +1 makes sure mButtonPressedTime is not zero */ - GetAppTask().mButtonPressedTime = chip::System::SystemClock().GetMonotonicMilliseconds64().count() + 1; + if (resetCnt > APP_REBOOT_RESET_COUNT) + { + resetCnt = 0; + /** To share with RESET PIN logic, mButtonPressedTime is used to recorded resetCnt increased. + * +1 makes sure mButtonPressedTime is not zero; + * a power cycle during factory reset confirm time APP_BUTTON_PRESS_LONG will cancel factoryreset */ + GetAppTask().mButtonPressedTime = System::SystemClock().GetMonotonicMilliseconds64().count() + 1; + } + else + { + resetCnt++; + GetAppTask().mButtonPressedTime = 0; + } + ef_set_env_blob(APP_REBOOT_RESET_COUNT_KEY, &resetCnt, sizeof(resetCnt)); #endif GetAppTask().sTimer = xTimerCreate("lightTmr", pdMS_TO_TICKS(1000), false, NULL, AppTask::TimerCallback); @@ -172,12 +177,12 @@ void AppTask::AppTaskMain(void * pvParameter) appError(ret); } - GetAppTask().PostEvent(AppTask::APP_EVENT_TIMER); - vTaskSuspend(NULL); + GetAppTask().PostEvent(APP_EVENT_TIMER); + GetAppTask().PostEvent(APP_EVENT_LIGHTING_MASK); - GetAppTask().mIsConnected = false; + vTaskSuspend(NULL); - ChipLogProgress(NotSpecified, "App Task started, with heap %d left\r\n", xPortGetFreeHeapSize()); + ChipLogProgress(NotSpecified, "App Task started, with SRAM heap %d left\r\n", xPortGetFreeHeapSize()); while (true) { @@ -188,22 +193,23 @@ void AppTask::AppTaskMain(void * pvParameter) { PlatformMgr().LockChipStack(); - if (APP_EVENT_SYS_PROVISIONED & appEvent) + if (APP_EVENT_LIGHTING_MASK & appEvent) { - LightingUpdate(APP_EVENT_LIGHTING_MASK); + LightingUpdate(appEvent); } if (APP_EVENT_BTN_SHORT & appEvent) { - Clusters::OnOff::Attributes::OnOff::Get(GetAppTask().GetEndpointId(), &onoff); - onoff = !onoff; - Clusters::OnOff::Attributes::OnOff::Set(GetAppTask().GetEndpointId(), onoff); - LightingUpdate((app_event_t)(APP_EVENT_LIGHTING_MASK & appEvent)); - } - - if (APP_EVENT_LIGHTING_MASK & appEvent) - { - LightingUpdate((app_event_t)(APP_EVENT_LIGHTING_MASK & appEvent)); + if (Server::GetInstance().GetFabricTable().FabricCount()) + { + Clusters::OnOff::Attributes::OnOff::Get(GetAppTask().GetEndpointId(), &onoff); + onoff = !onoff; + Clusters::OnOff::Attributes::OnOff::Set(GetAppTask().GetEndpointId(), onoff); + } + else + { + sLightLED.Toggle(); + } } if (APP_EVENT_IDENTIFY_MASK & appEvent) @@ -211,11 +217,6 @@ void AppTask::AppTaskMain(void * pvParameter) IdentifyHandleOp(appEvent); } - if (APP_EVENT_SYS_BLE_ADV & appEvent) - { - LightingUpdate(APP_EVENT_SYS_BLE_ADV); - } - if (APP_EVENT_FACTORY_RESET & appEvent) { DeviceLayer::ConfigurationMgr().InitiateFactoryReset(); @@ -237,57 +238,60 @@ void AppTask::LightingUpdate(app_event_t status) if (APP_EVENT_LIGHTING_MASK & status) { - do + + if (Server::GetInstance().GetFabricTable().FabricCount()) { - if (EMBER_ZCL_STATUS_SUCCESS != Clusters::OnOff::Attributes::OnOff::Get(endpoint, &onoff)) + do { - break; - } + if (EMBER_ZCL_STATUS_SUCCESS != Clusters::OnOff::Attributes::OnOff::Get(endpoint, &onoff)) + { + break; + } - if (EMBER_ZCL_STATUS_SUCCESS != Clusters::LevelControl::Attributes::CurrentLevel::Get(endpoint, v)) - { - break; - } + if (EMBER_ZCL_STATUS_SUCCESS != Clusters::LevelControl::Attributes::CurrentLevel::Get(endpoint, v)) + { + break; + } - if (EMBER_ZCL_STATUS_SUCCESS != Clusters::ColorControl::Attributes::CurrentHue::Get(endpoint, &hue)) - { - break; - } + if (EMBER_ZCL_STATUS_SUCCESS != Clusters::ColorControl::Attributes::CurrentHue::Get(endpoint, &hue)) + { + break; + } - if (EMBER_ZCL_STATUS_SUCCESS != Clusters::ColorControl::Attributes::CurrentSaturation::Get(endpoint, &sat)) - { - break; - } + if (EMBER_ZCL_STATUS_SUCCESS != Clusters::ColorControl::Attributes::CurrentSaturation::Get(endpoint, &sat)) + { + break; + } - if (!onoff) - { - sLightLED.SetLevel(0); - } - else - { - if (v.IsNull()) + if (!onoff) { - // Just pick something. - v.SetNonNull(254); + sLightLED.SetLevel(0); } + else + { + if (v.IsNull()) + { + // Just pick something. + v.SetNonNull(254); + } #if defined(BL706_NIGHT_LIGHT) || defined(BL602_NIGHT_LIGHT) - sLightLED.SetColor(v.Value(), hue, sat); + sLightLED.SetColor(v.Value(), hue, sat); #else - sLightLED.SetLevel(v.Value()); + sLightLED.SetLevel(v.Value()); #endif - } - - } while (0); - } - else if (APP_EVENT_SYS_BLE_ADV & status) - { + } + } while (0); + } + else + { #if defined(BL706_NIGHT_LIGHT) || defined(BL602_NIGHT_LIGHT) - /** show yellow to indicate BLE advertisement */ - sLightLED.SetColor(254, 35, 254); + /** show yellow to indicate not-provision state for extended color light */ + sLightLED.SetColor(254, 35, 254); #else - /** show 30% brightness to indicate BLE advertisement */ - sLightLED.SetLevel(25); + /** show 30% brightness to indicate not-provision state */ + sLightLED.SetLevel(25); #endif + } } } @@ -323,124 +327,40 @@ void AppTask::TimerCallback(TimerHandle_t xTimer) void AppTask::TimerEventHandler(app_event_t event) { - if (event & APP_EVENT_BTN_FACTORY_RESET_PRESS) - { - GetAppTask().mTimerIntvl = APP_BUTTON_PRESS_JITTER; - StartTimer(); - } - else if (event & APP_EVENT_BTN_FACTORY_RESET_IND) + if (GetAppTask().mButtonPressedTime) { - if (GetAppTask().mButtonPressedTime) +#ifdef BOOT_PIN_RESET + if (System::SystemClock().GetMonotonicMilliseconds64().count() - GetAppTask().mButtonPressedTime >= APP_BUTTON_PRESS_SHORT) { - GetAppTask().mIsFactoryResetIndicat = true; -#if defined(BL706_NIGHT_LIGHT) || defined(BL602_NIGHT_LIGHT) +#if defined(BL602_NIGHT_LIGHT) || defined(BL706_NIGHT_LIGHT) + /** change color to indicate to wait factory reset confirm */ sLightLED.SetColor(254, 0, 210); -#ifndef LED_BTN_RESET - uint32_t resetCnt = 0; - GetAppTask().mButtonPressedTime = 0; - ef_set_env_blob(APP_REBOOT_RESET_COUNT_KEY, &resetCnt, sizeof(resetCnt)); - - vTaskDelay(APP_BUTTON_PRESS_LONG); - GetAppTask().PostEvent(APP_EVENT_FACTORY_RESET); -#endif #else + /** toggle led to indicate to wait factory reset confirm */ sLightLED.Toggle(); - GetAppTask().mTimerIntvl = 100; - StartTimer(); #endif } - } - - if (event & APP_EVENT_BTN_FACTORY_RESET_CANCEL) - { - GetAppTask().mTimerIntvl = 1000; - StartTimer(); - if (GetAppTask().mIsFactoryResetIndicat) +#else + if (System::SystemClock().GetMonotonicMilliseconds64().count() - GetAppTask().mButtonPressedTime > APP_BUTTON_PRESS_LONG) { - if (GetAppTask().mIsConnected) - { - LightingUpdate(APP_EVENT_LIGHTING_MASK); - } - else - { - LightingUpdate(APP_EVENT_SYS_BLE_ADV); - } + /** factory reset confirm timeout */ + GetAppTask().mButtonPressedTime = 0; + GetAppTask().PostEvent(APP_EVENT_FACTORY_RESET); } - GetAppTask().mIsFactoryResetIndicat = false; - GetAppTask().mButtonPressedTime = 0; - } - - if (APP_EVENT_TIMER & event) - { - if (GetAppTask().mButtonPressedTime) + else { - if (GetAppTask().mIsFactoryResetIndicat) - { - if (chip::System::SystemClock().GetMonotonicMilliseconds64().count() - GetAppTask().mButtonPressedTime >= - APP_BUTTON_PRESS_LONG) - { - /** factory reset indicat done. */ - sLightLED.SetOnoff(false); - GetAppTask().mTimerIntvl = 1000; - } - else - { -#if !(defined(BL706_NIGHT_LIGHT) || defined(BL602_NIGHT_LIGHT)) - sLightLED.Toggle(); -#endif - } - } - else - { - -#if defined(BL706_NIGHT_LIGHT) && !defined(LED_BTN_RESET) - - if (GetAppTask().mButtonPressedTime) - { - uint32_t resetCnt = 0; - - if (chip::System::SystemClock().GetMonotonicMilliseconds64().count() - GetAppTask().mButtonPressedTime > - APP_BUTTON_PRESS_LONG * 2) - { - GetAppTask().mButtonPressedTime = 0; - } - else if (chip::System::SystemClock().GetMonotonicMilliseconds64().count() - GetAppTask().mButtonPressedTime > - APP_BUTTON_PRESS_LONG) - { - - size_t saved_value_len = 0; - - ef_get_env_blob(APP_REBOOT_RESET_COUNT_KEY, &resetCnt, sizeof(resetCnt), &saved_value_len); - if (resetCnt >= APP_REBOOT_RESET_COUNT) - { - GetAppTask().PostEvent(APP_EVENT_BTN_FACTORY_RESET_IND); - } - - /** a power cycle during factory reset indication state will quit factory reset operation */ - resetCnt = 0; - ef_set_env_blob(APP_REBOOT_RESET_COUNT_KEY, &resetCnt, sizeof(resetCnt)); - } - } +#if defined(BL602_NIGHT_LIGHT) || defined(BL706_NIGHT_LIGHT) + /** change color to indicate to wait factory reset confirm */ + sLightLED.SetColor(254, 0, 210); #else - if (ButtonPressed()) - { - if (!GetAppTask().mIsFactoryResetIndicat && - chip::System::SystemClock().GetMonotonicMilliseconds64().count() - GetAppTask().mButtonPressedTime >= - APP_BUTTON_PRESS_SHORT) - { - GetAppTask().PostEvent(APP_EVENT_BTN_FACTORY_RESET_IND); - } - } - else - { - GetAppTask().PostEvent(APP_EVENT_BTN_FACTORY_RESET_CANCEL); - } + /** toggle led to indicate to wait factory reset confirm */ + sLightLED.Toggle(); #endif - } } - - StartTimer(); +#endif } + + StartTimer(); } void AppTask::IdentifyStartHandler(Identify *) @@ -472,7 +392,7 @@ void AppTask::IdentifyHandleOp(app_event_t event) if (APP_EVENT_IDENTIFY_STOP & event) { identifyState = 0; - LightingUpdate(APP_EVENT_LIGHTING_MASK); + GetAppTask().PostEvent(APP_EVENT_LIGHTING_MASK); ChipLogProgress(NotSpecified, "identify stop"); } } @@ -482,13 +402,12 @@ void AppTask::ButtonEventHandler(uint8_t btnIdx, uint8_t btnAction) GetAppTask().PostEvent(APP_EVENT_FACTORY_RESET); } -#ifdef LED_BTN_RESET -hosal_gpio_dev_t gpio_key = { .port = LED_BTN_RESET, .config = INPUT_HIGH_IMPEDANCE, .priv = NULL }; +#ifdef BOOT_PIN_RESET +hosal_gpio_dev_t gpio_key = { .port = BOOT_PIN_RESET, .config = INPUT_HIGH_IMPEDANCE, .priv = NULL }; void AppTask::ButtonInit(void) { - GetAppTask().mButtonPressedTime = 0; - GetAppTask().mIsFactoryResetIndicat = false; + GetAppTask().mButtonPressedTime = 0; hosal_gpio_init(&gpio_key); hosal_gpio_irq_set(&gpio_key, HOSAL_IRQ_TRIG_POS_PULSE, GetAppTask().ButtonEventHandler, NULL); @@ -511,9 +430,9 @@ void AppTask::ButtonEventHandler(void * arg) #else bl_set_gpio_intmod(gpio_key.port, 1, HOSAL_IRQ_TRIG_NEG_LEVEL); #endif - - GetAppTask().mButtonPressedTime = chip::System::SystemClock().GetMonotonicMilliseconds64().count(); - GetAppTask().PostEvent(APP_EVENT_BTN_FACTORY_RESET_PRESS); + GetAppTask().mButtonPressedTime = System::SystemClock().GetMonotonicMilliseconds64().count(); + GetAppTask().mTimerIntvl = APP_BUTTON_PRESS_JITTER; + GetAppTask().PostEvent(APP_EVENT_TIMER); } else { @@ -524,18 +443,20 @@ void AppTask::ButtonEventHandler(void * arg) #endif if (GetAppTask().mButtonPressedTime) { - presstime = chip::System::SystemClock().GetMonotonicMilliseconds64().count() - GetAppTask().mButtonPressedTime; + presstime = System::SystemClock().GetMonotonicMilliseconds64().count() - GetAppTask().mButtonPressedTime; if (presstime >= APP_BUTTON_PRESS_LONG) { GetAppTask().PostEvent(APP_EVENT_FACTORY_RESET); } else if (presstime <= APP_BUTTON_PRESS_SHORT && presstime >= APP_BUTTON_PRESS_JITTER) { + GetAppTask().mTimerIntvl = 1000; GetAppTask().PostEvent(APP_EVENT_BTN_SHORT); } else { - GetAppTask().PostEvent(APP_EVENT_BTN_FACTORY_RESET_CANCEL); + GetAppTask().mTimerIntvl = 1000; + GetAppTask().PostEvent(APP_EVENT_LIGHTING_MASK); } } diff --git a/examples/lighting-app/bouffalolab/common/AppTask.h b/examples/lighting-app/bouffalolab/common/AppTask.h index dc16c63d26c4bc..3c32ee7311cd65 100644 --- a/examples/lighting-app/bouffalolab/common/AppTask.h +++ b/examples/lighting-app/bouffalolab/common/AppTask.h @@ -29,8 +29,8 @@ using namespace ::chip; using namespace ::chip::DeviceLayer; #define APP_BUTTON_PRESS_JITTER 50 -#define APP_BUTTON_PRESS_SHORT 1000 -#define APP_BUTTON_PRESS_LONG 4000 +#define APP_BUTTON_PRESS_SHORT 1500 +#define APP_BUTTON_PRESS_LONG 5000 #define APP_LIGHT_ENDPOINT_ID 1 #define APP_REBOOT_RESET_COUNT 3 @@ -55,23 +55,9 @@ class AppTask { APP_EVENT_NONE = 0x00000000, - APP_EVENT_BTN_FACTORY_RESET_CANCEL = 0x00000002, - APP_EVENT_BTN_FACTORY_RESET_IND = 0x00000004, - APP_EVENT_BTN_FACTORY_RESET_PRESS = 0x00000008, - - APP_EVENT_BTN_ALL_MASK = - APP_EVENT_BTN_FACTORY_RESET_CANCEL | APP_EVENT_BTN_FACTORY_RESET_IND | APP_EVENT_BTN_FACTORY_RESET_PRESS, - APP_EVENT_TIMER = 0x00000010, - APP_EVENT_BTN_SHORT = 0x00000020, - - APP_EVENT_SYS_BLE_ADV = 0x00000100, - APP_EVENT_SYS_BLE_CONN = 0x00000200, - APP_EVENT_SYS_PROVISIONED = 0x00000400, - APP_EVENT_SYS_LIGHT_TOGGLE = 0x00000800, - APP_EVENT_FACTORY_RESET = 0x00001000, - - APP_EVENT_SYS_ALL_MASK = - APP_EVENT_SYS_BLE_ADV | APP_EVENT_SYS_BLE_CONN | APP_EVENT_SYS_PROVISIONED | APP_EVENT_FACTORY_RESET, + APP_EVENT_TIMER = 0x00000010, + APP_EVENT_BTN_SHORT = 0x00000020, + APP_EVENT_FACTORY_RESET = 0x00000040, APP_EVENT_LIGHTING_ONOFF = 0x00010000, APP_EVENT_LIGHTING_LEVEL = 0x00020000, @@ -83,8 +69,7 @@ class AppTask APP_EVENT_IDENTIFY_STOP = 0x04000000, APP_EVENT_IDENTIFY_MASK = APP_EVENT_IDENTIFY_START | APP_EVENT_IDENTIFY_IDENTIFY | APP_EVENT_IDENTIFY_STOP, - APP_EVENT_ALL_MASK = APP_EVENT_LIGHTING_MASK | APP_EVENT_BTN_ALL_MASK | APP_EVENT_SYS_ALL_MASK | APP_EVENT_TIMER | - APP_EVENT_BTN_SHORT | APP_EVENT_IDENTIFY_MASK, + APP_EVENT_ALL_MASK = APP_EVENT_LIGHTING_MASK | APP_EVENT_TIMER | APP_EVENT_BTN_SHORT | APP_EVENT_IDENTIFY_MASK, }; void SetEndpointId(EndpointId endpointId) @@ -100,7 +85,6 @@ class AppTask static void IdentifyStartHandler(Identify *); static void IdentifyStopHandler(Identify *); static void IdentifyHandleOp(app_event_t event); - bool mIsConnected; private: friend void StartAppTask(void); @@ -119,7 +103,7 @@ class AppTask static void TimerEventHandler(app_event_t event); static void TimerCallback(TimerHandle_t xTimer); -#ifdef LED_BTN_RESET +#ifdef BOOT_PIN_RESET static void ButtonInit(void); static bool ButtonPressed(void); static void ButtonEventHandler(void * arg); @@ -137,7 +121,6 @@ class AppTask TimerHandle_t sTimer; uint32_t mTimerIntvl; uint64_t mButtonPressedTime; - bool mIsFactoryResetIndicat; static StackType_t appStack[APP_TASK_STACK_SIZE / sizeof(StackType_t)]; static StaticTask_t appTaskStruct; diff --git a/examples/lighting-app/bouffalolab/data_model/lighting-app-thread.matter b/examples/lighting-app/bouffalolab/data_model/lighting-app-thread.matter index 383979ff946c11..761728c6e07cec 100644 --- a/examples/lighting-app/bouffalolab/data_model/lighting-app-thread.matter +++ b/examples/lighting-app/bouffalolab/data_model/lighting-app-thread.matter @@ -2140,17 +2140,17 @@ endpoint 1 { } server cluster OnOff { - persist attribute onOff default = 0x00; + persist attribute onOff default = 0x01; ram attribute globalSceneControl default = 0x01; ram attribute onTime default = 0x0000; ram attribute offWaitTime default = 0x0000; - persist attribute startUpOnOff default = 0xFF; + persist attribute startUpOnOff; ram attribute featureMap default = 1; ram attribute clusterRevision default = 5; } server cluster LevelControl { - persist attribute currentLevel default = 0x01; + persist attribute currentLevel default = 0x254; ram attribute remainingTime default = 0x0000; ram attribute minLevel default = 0x01; ram attribute maxLevel default = 0xFE; @@ -2159,11 +2159,11 @@ endpoint 1 { ram attribute maxFrequency default = 0x0000; ram attribute options default = 0x00; ram attribute onOffTransitionTime default = 0x0000; - ram attribute onLevel default = 0xFF; + ram attribute onLevel; ram attribute onTransitionTime; ram attribute offTransitionTime; ram attribute defaultMoveRate default = 50; - persist attribute startUpCurrentLevel default = 255; + persist attribute startUpCurrentLevel; ram attribute featureMap default = 3; ram attribute clusterRevision default = 5; } diff --git a/examples/lighting-app/bouffalolab/data_model/lighting-app-thread.zap b/examples/lighting-app/bouffalolab/data_model/lighting-app-thread.zap index 5b31d85e407fd3..852948f8da1431 100644 --- a/examples/lighting-app/bouffalolab/data_model/lighting-app-thread.zap +++ b/examples/lighting-app/bouffalolab/data_model/lighting-app-thread.zap @@ -6087,7 +6087,7 @@ "storageOption": "NVM", "singleton": 0, "bounded": 0, - "defaultValue": "0x00", + "defaultValue": "0x01", "reportable": 1, "minInterval": 0, "maxInterval": 65344, @@ -6151,7 +6151,7 @@ "storageOption": "NVM", "singleton": 0, "bounded": 0, - "defaultValue": "0xFF", + "defaultValue": null, "reportable": 1, "minInterval": 0, "maxInterval": 65344, @@ -6301,7 +6301,7 @@ "storageOption": "NVM", "singleton": 0, "bounded": 0, - "defaultValue": "0x01", + "defaultValue": "0x254", "reportable": 1, "minInterval": 0, "maxInterval": 65344, @@ -6445,7 +6445,7 @@ "storageOption": "RAM", "singleton": 0, "bounded": 0, - "defaultValue": "0xFF", + "defaultValue": null, "reportable": 1, "minInterval": 1, "maxInterval": 65534, @@ -6509,7 +6509,7 @@ "storageOption": "NVM", "singleton": 0, "bounded": 0, - "defaultValue": "255", + "defaultValue": null, "reportable": 1, "minInterval": 0, "maxInterval": 65344, @@ -8341,5 +8341,6 @@ "endpointVersion": 1, "deviceIdentifier": 269 } - ] -} \ No newline at end of file + ], + "log": [] +} diff --git a/examples/lighting-app/bouffalolab/data_model/lighting-app-wifi.matter b/examples/lighting-app/bouffalolab/data_model/lighting-app-wifi.matter index 06da353cea23bd..cec65b4ff30bb7 100644 --- a/examples/lighting-app/bouffalolab/data_model/lighting-app-wifi.matter +++ b/examples/lighting-app/bouffalolab/data_model/lighting-app-wifi.matter @@ -2002,17 +2002,17 @@ endpoint 1 { } server cluster OnOff { - persist attribute onOff default = 0x00; + persist attribute onOff default = 0x1; ram attribute globalSceneControl default = 0x01; ram attribute onTime default = 0x0000; ram attribute offWaitTime default = 0x0000; - persist attribute startUpOnOff default = 0xFF; + persist attribute startUpOnOff; ram attribute featureMap default = 1; ram attribute clusterRevision default = 5; } server cluster LevelControl { - persist attribute currentLevel default = 0x01; + persist attribute currentLevel default = 0x254; ram attribute remainingTime default = 0x0000; ram attribute minLevel default = 0x01; ram attribute maxLevel default = 0xFE; @@ -2021,11 +2021,11 @@ endpoint 1 { ram attribute maxFrequency default = 0x0000; ram attribute options default = 0x00; ram attribute onOffTransitionTime default = 0x0000; - ram attribute onLevel default = 0xFF; + ram attribute onLevel; ram attribute onTransitionTime; ram attribute offTransitionTime; ram attribute defaultMoveRate default = 50; - persist attribute startUpCurrentLevel default = 255; + persist attribute startUpCurrentLevel; ram attribute featureMap default = 3; ram attribute clusterRevision default = 5; } diff --git a/examples/lighting-app/bouffalolab/data_model/lighting-app-wifi.zap b/examples/lighting-app/bouffalolab/data_model/lighting-app-wifi.zap index 8d717c43e916e2..90bd7a21ea76f9 100644 --- a/examples/lighting-app/bouffalolab/data_model/lighting-app-wifi.zap +++ b/examples/lighting-app/bouffalolab/data_model/lighting-app-wifi.zap @@ -6087,7 +6087,7 @@ "storageOption": "NVM", "singleton": 0, "bounded": 0, - "defaultValue": "0x00", + "defaultValue": "0x1", "reportable": 1, "minInterval": 0, "maxInterval": 65344, @@ -6151,7 +6151,7 @@ "storageOption": "NVM", "singleton": 0, "bounded": 0, - "defaultValue": "0xFF", + "defaultValue": null, "reportable": 1, "minInterval": 0, "maxInterval": 65344, @@ -6301,7 +6301,7 @@ "storageOption": "NVM", "singleton": 0, "bounded": 0, - "defaultValue": "0x01", + "defaultValue": "0x254", "reportable": 1, "minInterval": 0, "maxInterval": 65344, @@ -6445,7 +6445,7 @@ "storageOption": "RAM", "singleton": 0, "bounded": 0, - "defaultValue": "0xFF", + "defaultValue": null, "reportable": 1, "minInterval": 1, "maxInterval": 65534, @@ -6509,7 +6509,7 @@ "storageOption": "NVM", "singleton": 0, "bounded": 0, - "defaultValue": "255", + "defaultValue": null, "reportable": 1, "minInterval": 0, "maxInterval": 65344, @@ -8341,5 +8341,6 @@ "endpointVersion": 1, "deviceIdentifier": 269 } - ] -} \ No newline at end of file + ], + "log": [] +} diff --git a/examples/platform/bouffalolab/bl702/ldscripts/psram_flash.ld b/examples/platform/bouffalolab/bl702/ldscripts/psram_flash.ld index c31a453437bc28..c18b569ac062e3 100644 --- a/examples/platform/bouffalolab/bl702/ldscripts/psram_flash.ld +++ b/examples/platform/bouffalolab/bl702/ldscripts/psram_flash.ld @@ -214,79 +214,44 @@ SECTIONS PROVIDE ( __psram_bss_init_start = . ); /** put the bss data in psram between __psram_bss_init_start and __psram_bss_init_end will bet reset to 0 after psram init*/ - . = ALIGN(8); - KEEP(*lighting-common.*.cpp.o(.bss.*ttributeData*)) - . = ALIGN(8); - KEEP(*lighting-common.*.cpp.o(.bss.*bindingTable*)) - . = ALIGN(8); - KEEP(*lighting-common.*.cpp.o(.bss.appResponseData*)) - . = ALIGN(8); - KEEP(*lighting-common.*.cpp.o(.bss.*NetworkCommissioning*)) - - . = ALIGN(8); - KEEP(*dnssd.Advertiser_ImplMinimalMdns.cpp.o(.bss.*gAdvertiser*)) - . = ALIGN(8); - KEEP(*dnssd.MinimalMdnsServer.cpp.o(.bss.*GlobalMinimalMdnsServer*_instance)) - . = ALIGN(8); - KEEP(*dnssd.Resolver_ImplMinimalMdns.cpp.o(.bss.*gResolver*)) - - /*. = ALIGN(8);*/ - /*KEEP(*libCHIPAppServer.Server.cpp.o(.bss.*sServer*))*/ - - . = ALIGN(8); - KEEP(*bridge-common.*.cpp.o(.bss.*)) - /* . = ALIGN(8); */ - /* # KEEP(*bridge-common.*.cpp.o(.bss.*bindingTable*)) */ - /* # . = ALIGN(8); */ - /* # KEEP(*bridge-common.*.cpp.o(.bss.appResponseData*)) */ - /* # . = ALIGN(8); */ - /* # KEEP(*bridge-common.*.cpp.o(.bss.*NetworkCommissioning*)) */ - - . = ALIGN(8); - KEEP(*libopenthread-cli-*.cli.cpp.o(.bss.*sInterpreterRaw*)) - - . = ALIGN(8); - KEEP(*libopenthread-cli-*.cli_dataset.cpp.o(.bss.*sDataset*)) - - . = ALIGN(8); - KEEP(*libopenthread-ftd.instance.cpp.o(.bss.*gInstanceRaw*)) - - . = ALIGN(8); - KEEP(*commands.Dns.cpp.o(.bss.*)) - - . = ALIGN(8); - KEEP(*commands.BLE.cpp.o(.bss.*)) - - . = ALIGN(8); - KEEP(*commands.Device.cpp.o(.bss.*)) - - . = ALIGN(8); - KEEP(*commands.Base64.cpp.o(.bss.*)) - - . = ALIGN(8); - KEEP(*commands.Base64.cpp.o(.bss.*)) + . = ALIGN(16); + KEEP(*libCHIP.a:*(.sbss.*)) + KEEP(*libCHIP.a:*(.bss.*)) - . = ALIGN(8); -/* KEEP(*shell_common.cmd_*.cpp.o(.bss.*))*/ + . = ALIGN(16); + KEEP(*libCHIPAppServer.a:*(.sbss.*)) + KEEP(*libCHIPAppServer.a:*(.bss.*)) - . = ALIGN(8); - KEEP(*shell_core.Engine.cpp.o(.bss.*theEngineRoot*)) + . = ALIGN(16); + KEEP(*libMatterDeviceInfoProviderExample.a:*(.sbss.*)) + KEEP(*libMatterDeviceInfoProviderExample.a:*(.bss.*)) - . = ALIGN(8); - /* KEEP(*shell_common.globals.cpp.o(.bss.*)) */ + . = ALIGN(16); + KEEP(*src/app/clusters/*/bouffalolab*.cpp.o(.sbss.*)) + KEEP(*src/app/clusters/*/bouffalolab*.cpp.o(.bss.*)) - . = ALIGN(8); - KEEP(*lwip.memp.c.o(.bss.lwip_PBUF_POOL)) - . = ALIGN(8); - KEEP(*sdk_lwip.dns.c.o(.bss.dns_table)) + . = ALIGN(16); + KEEP(*examples/platform/bouffalolab/common/plat/chip*.c.o(.sbss.*)) + KEEP(*examples/platform/bouffalolab/common/plat/chip*.c.o(.sbss.*)) + KEEP(*examples/platform/bouffalolab/common/plat/chip*.cpp.o(.bss.*)) + KEEP(*examples/platform/bouffalolab/common/plat/chip*.cpp.o(.bss.*)) - . = ALIGN(8); - KEEP(*virt_net_spi.c.o(.bss.tx_buffer)) + . = ALIGN(16); + KEEP(*examples/*/bouffalolab/common/chip*.c.o(.sbss.*)) + KEEP(*examples/*/bouffalolab/common/chip*.c.o(.sbss.*)) + KEEP(*examples/*/bouffalolab/common/chip*.cpp.o(.bss.*)) + KEEP(*examples/*/bouffalolab/common/chip*.cpp.o(.bss.*)) - PROVIDE ( __psram_bss_init_end = . ); . = ALIGN(16); + KEEP(*sdk_lwip.*.c.o(.sbss.*)) + KEEP(*sdk_lwip.*.c.o(.bss.*)) + . = ALIGN(16); + KEEP(*stack_main.o(.bss.*)) + + . = ALIGN(16); *(.wifi_ram*) + PROVIDE ( __psram_bss_init_end = . ); } >psram . = ALIGN(8); diff --git a/examples/platform/bouffalolab/bl702l/ldscripts/psram_flash_rom.ld b/examples/platform/bouffalolab/bl702l/ldscripts/psram_flash_rom.ld index 6dce5b3b161f23..60d1ea8358396e 100644 --- a/examples/platform/bouffalolab/bl702l/ldscripts/psram_flash_rom.ld +++ b/examples/platform/bouffalolab/bl702l/ldscripts/psram_flash_rom.ld @@ -10,7 +10,7 @@ MEMORY flash (rxai!w) : ORIGIN = 0x23000000, LENGTH = (2M) tcm_ocram (wxa) : ORIGIN = 0x4201C000 + __CACHE_SIZE, LENGTH = (16K - __CACHE_SIZE + 80K - __EM_SIZE) hbnram (wxa) : ORIGIN = 0x40010000, LENGTH = (4K) - psram (wxa) : ORIGIN = 0x26000000, LENGTH = (2M) + psram (wxa) : ORIGIN = 0x24000000, LENGTH = (2M) } SECTIONS @@ -169,91 +169,53 @@ SECTIONS PROVIDE ( __psram_bss_init_start = . ); /** put the bss data in psram between __psram_bss_init_start and __psram_bss_init_end will bet reset to 0 after psram init*/ - . = ALIGN(8); - KEEP(*lighting-common.*.cpp.o(.bss.*ttributeData*)) - . = ALIGN(8); - KEEP(*lighting-common.*.cpp.o(.bss.*bindingTable*)) - . = ALIGN(8); - KEEP(*lighting-common.*.cpp.o(.bss.appResponseData*)) - . = ALIGN(8); - KEEP(*lighting-common.*.cpp.o(.bss.*NetworkCommissioning*)) - - . = ALIGN(8); - KEEP(*dnssd.Advertiser_ImplMinimalMdns.cpp.o(.bss.*gAdvertiser*)) - . = ALIGN(8); - KEEP(*dnssd.MinimalMdnsServer.cpp.o(.bss.*GlobalMinimalMdnsServer*_instance)) - . = ALIGN(8); - KEEP(*dnssd.Resolver_ImplMinimalMdns.cpp.o(.bss.*gResolver*)) - - /*. = ALIGN(8);*/ - /*KEEP(*libCHIPAppServer.Server.cpp.o(.bss.*sServer*))*/ - - . = ALIGN(8); - KEEP(*bridge-common.*.cpp.o(.bss.*)) - /* . = ALIGN(8); */ - /* # KEEP(*bridge-common.*.cpp.o(.bss.*bindingTable*)) */ - /* # . = ALIGN(8); */ - /* # KEEP(*bridge-common.*.cpp.o(.bss.appResponseData*)) */ - /* # . = ALIGN(8); */ - /* # KEEP(*bridge-common.*.cpp.o(.bss.*NetworkCommissioning*)) */ - - . = ALIGN(8); - KEEP(*libopenthread-cli-*.cli.cpp.o(.bss.*sInterpreterRaw*)) - - . = ALIGN(8); - KEEP(*libopenthread-cli-*.cli_dataset.cpp.o(.bss.*sDataset*)) - - . = ALIGN(8); - KEEP(*libopenthread-ftd.instance.cpp.o(.bss.*gInstanceRaw*)) - - . = ALIGN(8); - KEEP(*commands.Dns.cpp.o(.bss.*)) - - . = ALIGN(8); - KEEP(*commands.BLE.cpp.o(.bss.*)) - - . = ALIGN(8); - KEEP(*commands.Device.cpp.o(.bss.*)) - - . = ALIGN(8); - KEEP(*commands.Base64.cpp.o(.bss.*)) + . = ALIGN(16); + KEEP(*libCHIP.a:*(.sbss.*)) + KEEP(*libCHIP.a:*(.bss.*)) - . = ALIGN(8); - KEEP(*commands.Base64.cpp.o(.bss.*)) + . = ALIGN(16); + KEEP(*libCHIPAppServer.a:*(.sbss.*)) + KEEP(*libCHIPAppServer.a:*(.bss.*)) - . = ALIGN(8); - KEEP(*shell_core.Engine.cpp.o(.bss.*theEngineRoot*)) + . = ALIGN(16); + KEEP(*libMatterDeviceInfoProviderExample.a:*(.sbss.*)) + KEEP(*libMatterDeviceInfoProviderExample.a:*(.bss.*)) - . = ALIGN(8); - KEEP(*sdk_openthread_port.ot_radio.c.o(.bss.otRadio_buffPool)) + . = ALIGN(16); + KEEP(*libopenthread-ftd.a:*(.sbss.*)) + KEEP(*libopenthread-ftd.a:*(.bss.*)) + KEEP(*libopenthread-mtd.a:*(.sbss.*)) + KEEP(*libopenthread-mtd.a:*(.bss.*)) - . = ALIGN(8); - KEEP(*BL702L.PlatformManagerImpl.cpp.o(.bss._ZN4chip11DeviceLayer19PlatformManagerImpl9sInstanceE)) + . = ALIGN(16); + KEEP(*src/app/clusters/*/bouffalolab*.cpp.o(.sbss.*)) + KEEP(*src/app/clusters/*/bouffalolab*.cpp.o(.bss.*)) - . = ALIGN(8); - KEEP(*BL702L.ThreadStackManagerImpl.cpp.o(.bss._ZN4chip11DeviceLayer22ThreadStackManagerImpl9sInstanceE)) + . = ALIGN(16); + KEEP(*examples/platform/bouffalolab/common/plat/chip*.c.o(.sbss.*)) + KEEP(*examples/platform/bouffalolab/common/plat/chip*.c.o(.sbss.*)) + KEEP(*examples/platform/bouffalolab/common/plat/chip*.cpp.o(.bss.*)) + KEEP(*examples/platform/bouffalolab/common/plat/chip*.cpp.o(.bss.*)) - . = ALIGN(8); - KEEP(*libCHIPAppServer.Server.cpp.o(.bss._ZN4chip6Server7sServerE)) + . = ALIGN(16); + KEEP(*examples/*/bouffalolab/common/chip*.c.o(.sbss.*)) + KEEP(*examples/*/bouffalolab/common/chip*.c.o(.sbss.*)) + KEEP(*examples/*/bouffalolab/common/chip*.cpp.o(.bss.*)) + KEEP(*examples/*/bouffalolab/common/chip*.cpp.o(.bss.*)) - . = ALIGN(8); - KEEP(*libaccess.ExampleAccessControlDelegate.cpp.o(.bss.*)) + . = ALIGN(16); + KEEP(*sdk_lwip.*.c.o(.sbss.*)) + KEEP(*sdk_lwip.*.c.o(.bss.*)) + KEEP(*lwip.*.c.o(.bss.*)) - . = ALIGN(8); - KEEP(*libTransportLayer.SessionManager.cpp.o(.bss.*)) - . = ALIGN(8); - KEEP(*lwip.memp.c.o(.bss.*)) - . = ALIGN(8); - KEEP(*sdk_lwip.dns.c.o(.bss.dns_table)) - . = ALIGN(8); - KEEP(*virt_net_spi.c.o(.bss.tx_buffer)) - - PROVIDE ( __psram_bss_init_end = . ); . = ALIGN(16); - + KEEP(*stack_main.o(.bss.*)) + + . = ALIGN(16); *(.wifi_ram*) + PROVIDE ( __psram_bss_init_end = . ); } > psram . = ALIGN(8); diff --git a/examples/platform/bouffalolab/common/plat/MemMonitoring.cpp b/examples/platform/bouffalolab/common/plat/MemMonitoring.cpp index 3e66d05454d838..6e58131f8c1ea8 100644 --- a/examples/platform/bouffalolab/common/plat/MemMonitoring.cpp +++ b/examples/platform/bouffalolab/common/plat/MemMonitoring.cpp @@ -18,8 +18,6 @@ #include #include -#include -#include #include #include diff --git a/examples/platform/bouffalolab/common/plat/demo_pwm.c b/examples/platform/bouffalolab/common/plat/demo_pwm.c index 58e63767c7f83f..c279ddc1aaec7c 100644 --- a/examples/platform/bouffalolab/common/plat/demo_pwm.c +++ b/examples/platform/bouffalolab/common/plat/demo_pwm.c @@ -4,11 +4,12 @@ * Contact information: * web site: https://www.bouffalolab.com/ */ +#include -#include "demo_pwm.h" -#include "board.h" #include -#include + +#include "board.h" +#include "demo_pwm.h" #define PWM_FREQ 1000 #define PWM_DUTY_CYCLE 10000 diff --git a/examples/platform/bouffalolab/common/plat/main.cpp b/examples/platform/bouffalolab/common/plat/main.cpp index abf7ef6f4bdad1..bf04405bf78523 100644 --- a/examples/platform/bouffalolab/common/plat/main.cpp +++ b/examples/platform/bouffalolab/common/plat/main.cpp @@ -27,8 +27,6 @@ #include #include -#include -#include #include extern "C" { @@ -45,7 +43,9 @@ extern "C" { #include #endif #include +#if defined(BL702L_ENABLE) #include +#endif #include #include #ifdef CFG_USE_PSRAM @@ -64,6 +64,7 @@ extern "C" { #endif #include "board.h" +#include } using namespace ::chip; @@ -138,15 +139,13 @@ extern "C" void vApplicationGetIdleTaskMemory(StaticTask_t ** ppxIdleTaskTCBBuff /* If the buffers to be provided to the Idle task are declared inside this function then they must be declared static - otherwise they will be allocated on the stack and so not exists after this function exits. */ - static StaticTask_t xIdleTaskTCB; - static StackType_t uxIdleTaskStack[configMINIMAL_STACK_SIZE]; /* Pass out a pointer to the StaticTask_t structure in which the Idle task's state will be stored. */ - *ppxIdleTaskTCBBuffer = &xIdleTaskTCB; + *ppxIdleTaskTCBBuffer = (StaticTask_t *) pvPortMalloc(sizeof(StaticTask_t)); /* Pass out the array that will be used as the Idle task's stack. */ - *ppxIdleTaskStackBuffer = uxIdleTaskStack; + *ppxIdleTaskStackBuffer = (StackType_t *) pvPortMalloc(sizeof(StackType_t) * configMINIMAL_STACK_SIZE); /* Pass out the size of the array pointed to by *ppxIdleTaskStackBuffer. Note that, as the array is necessarily of type StackType_t, @@ -163,15 +162,13 @@ extern "C" void vApplicationGetTimerTaskMemory(StaticTask_t ** ppxTimerTaskTCBBu /* If the buffers to be provided to the Timer task are declared inside this function then they must be declared static - otherwise they will be allocated on the stack and so not exists after this function exits. */ - static StaticTask_t xTimerTaskTCB; - static StackType_t uxTimerTaskStack[configTIMER_TASK_STACK_DEPTH]; /* Pass out a pointer to the StaticTask_t structure in which the Timer task's state will be stored. */ - *ppxTimerTaskTCBBuffer = &xTimerTaskTCB; + *ppxTimerTaskTCBBuffer = (StaticTask_t *) pvPortMalloc(sizeof(StaticTask_t)); /* Pass out the array that will be used as the Timer task's stack. */ - *ppxTimerTaskStackBuffer = uxTimerTaskStack; + *ppxTimerTaskStackBuffer = (StackType_t *) pvPortMalloc(sizeof(StackType_t) * configTIMER_TASK_STACK_DEPTH); /* Pass out the size of the array pointed to by *ppxTimerTaskStackBuffer. Note that, as the array is necessarily of type StackType_t, @@ -196,7 +193,15 @@ extern "C" void vAssertCalled(void) void * ra = (void *) __builtin_return_address(0); taskDISABLE_INTERRUPTS(); - ChipLogProgress(NotSpecified, "vAssertCalled, ra= %p", ra); + if (xPortIsInsideInterrupt()) + { + printf("vAssertCalled, ra = %p in ISR\r\n", (void *) ra); + } + else + { + printf("vAssertCalled, ra = %p in task %s\r\n", (void *) ra, pcTaskGetName(NULL)); + } + while (true) ; } @@ -208,7 +213,15 @@ extern "C" void __attribute__((weak)) user_vAssertCalled(void) void * ra = (void *) __builtin_return_address(0); taskDISABLE_INTERRUPTS(); - ChipLogProgress(NotSpecified, "vAssertCalled, ra= %p", ra); + if (xPortIsInsideInterrupt()) + { + printf("vAssertCalled, ra = %p in ISR\r\n", (void *) ra); + } + else + { + printf("vAssertCalled, ra = %p in task %s\r\n", (void *) ra, pcTaskGetName(NULL)); + } + while (true) ; } @@ -330,20 +343,6 @@ extern "C" void do_psram_test() } #endif -#ifdef BL702L_ENABLE -void exception_entry_app(uint32_t mcause, uint32_t mepc, uint32_t mtval, uintptr_t * regs, uintptr_t * tasksp) -{ - static const char dbg_str[] = "Exception Entry--->>>\r\n mcause %08lx, mepc %08lx, mtval %08lx\r\n"; - - printf(dbg_str, mcause, mepc, mtval); - - while (1) - { - /*dead loop now*/ - } -} -#endif - extern "C" void setup_heap() { bl_sys_init(); @@ -362,16 +361,6 @@ extern "C" void setup_heap() vPortDefineHeapRegions(xHeapRegions); - bl_sys_early_init(); - -#ifdef BL702L_ENABLE - rom_freertos_init(256, 400); - rom_hal_init(); - rom_lmac154_hook_init(); - - exception_entry_ptr = exception_entry_app; -#endif - #ifdef CFG_USE_PSRAM bl_psram_init(); do_psram_test(); @@ -386,6 +375,14 @@ extern "C" size_t get_heap_size(void) extern "C" void app_init(void) { + bl_sys_early_init(); + +#ifdef BL702L_ENABLE + rom_freertos_init(256, 400); + rom_hal_init(); + rom_lmac154_hook_init(); +#endif + hosal_uart_init(&uart_stdio); ChipLogProgress(NotSpecified, "=================================================="); @@ -403,7 +400,9 @@ extern "C" void app_init(void) blog_init(); bl_irq_init(); +#if defined(BL702L_ENABLE) bl_rtc_init(); +#endif bl_sec_init(); #if defined(BL702_ENABLE) bl_timer_init(); @@ -414,6 +413,9 @@ extern "C" void app_init(void) /* board config is set after system is init*/ hal_board_cfg(0); +#if defined(BL702L_ENABLE) || defined(BL706_WIFI) + hosal_dma_init(); +#endif #ifdef BL602_ENABLE wifi_td_diagnosis_init(); #endif @@ -423,12 +425,9 @@ extern "C" void START_ENTRY(void) { app_init(); - easyflash_init(); - ef_load_env_cache(); - - ChipLogProgress(NotSpecified, "Init CHIP Memory"); - chip::Platform::MemoryInit(NULL, 0); - +#if CONFIG_ENABLE_CHIP_SHELL || PW_RPC_ENABLED + uartInit(); +#endif #ifdef SYS_AOS_LOOP_ENABLE ChipLogProgress(NotSpecified, "Starting AOS loop Task"); aos_loop_start(); @@ -439,6 +438,12 @@ extern "C" void START_ENTRY(void) #endif #endif + easyflash_init(); + ef_load_env_cache(); + + ChipLogProgress(NotSpecified, "Init CHIP Memory"); + chip::Platform::MemoryInit(NULL, 0); + ChipLogProgress(NotSpecified, "Starting App Task"); StartAppTask(); diff --git a/examples/platform/bouffalolab/common/plat/platform.cpp b/examples/platform/bouffalolab/common/plat/platform.cpp index dc2f2a02fbfc1f..d2e6a434e91296 100644 --- a/examples/platform/bouffalolab/common/plat/platform.cpp +++ b/examples/platform/bouffalolab/common/plat/platform.cpp @@ -15,56 +15,61 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - +#include +#include #include #include #include #include #include -#include -#include -#include - -#if CHIP_DEVICE_CONFIG_ENABLE_WIFI -#include -#include -#include -#endif #include +#include #if HEAP_MONITORING #include -#include -#endif - -#if CHIP_ENABLE_OPENTHREAD -#include -#include -#include -#include #endif -#ifdef OTA_ENABLED -#include "OTAConfig.h" -#endif // OTA_ENABLED - #if CONFIG_ENABLE_CHIP_SHELL #include #include #endif #if PW_RPC_ENABLED -#include "PigweedLogger.h" -#include "Rpc.h" +#include +#include +#endif +#if CONFIG_ENABLE_CHIP_SHELL || PW_RPC_ENABLED +#include #endif -#include #if CONFIG_BOUFFALOLAB_FACTORY_DATA_ENABLE || defined(CONFIG_BOUFFALOLAB_FACTORY_DATA_TEST) #include #endif -#if CONFIG_ENABLE_CHIP_SHELL || PW_RPC_ENABLED -#include "uart.h" +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI +#include +#include +#endif + +#if CHIP_ENABLE_OPENTHREAD +#include +#include +#include +#include +#endif + +#if !CHIP_DEVICE_CONFIG_ENABLE_THREAD +#include +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI +#if defined(BL602_ENABLE) +#include +#else +#include +#endif +#else +#include +#endif +#include #endif #include @@ -95,55 +100,18 @@ void ChipEventHandler(const ChipDeviceEvent * event, intptr_t arg) switch (event->Type) { case DeviceEventType::kCHIPoBLEAdvertisingChange: - -#if CHIP_DEVICE_CONFIG_ENABLE_WIFI - GetAppTask().mIsConnected = ConnectivityMgr().IsWiFiStationConnected(); -#endif -#if CHIP_DEVICE_CONFIG_ENABLE_THREAD - GetAppTask().mIsConnected = ConnectivityMgr().IsThreadAttached(); -#endif - - if (ConnectivityMgr().NumBLEConnections()) - { - GetAppTask().PostEvent(AppTask::APP_EVENT_SYS_BLE_CONN); - } - else - { - GetAppTask().PostEvent(AppTask::APP_EVENT_SYS_BLE_ADV); - } ChipLogProgress(NotSpecified, "BLE adv changed, connection number: %d", ConnectivityMgr().NumBLEConnections()); break; #if CHIP_DEVICE_CONFIG_ENABLE_THREAD case DeviceEventType::kThreadStateChange: - ChipLogProgress(NotSpecified, "Thread state changed, IsThreadAttached: %d", ConnectivityMgr().IsThreadAttached()); - if (!GetAppTask().mIsConnected && ConnectivityMgr().IsThreadAttached()) + if (ConnectivityMgr().IsThreadAttached()) { - GetAppTask().PostEvent(AppTask::APP_EVENT_SYS_PROVISIONED); - GetAppTask().mIsConnected = true; -#ifdef OTA_ENABLED chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Seconds32(OTAConfig::kInitOTARequestorDelaySec), OTAConfig::InitOTARequestorHandler, nullptr); -#endif - } - break; -#endif - -#if CHIP_DEVICE_CONFIG_ENABLE_WIFI - case DeviceEventType::kWiFiConnectivityChange: - - ChipLogProgress(NotSpecified, "Wi-Fi state changed to %s.", - ConnectivityMgr().IsWiFiStationConnected() ? "connected" : "disconnected"); - - chip::app::DnssdServer::Instance().StartServer(); - NetworkCommissioning::BLWiFiDriver::GetInstance().SaveConfiguration(); - if (!GetAppTask().mIsConnected && ConnectivityMgr().IsWiFiStationConnected()) - { - GetAppTask().PostEvent(AppTask::APP_EVENT_SYS_PROVISIONED); - GetAppTask().mIsConnected = true; } break; - +#else case DeviceEventType::kInterfaceIpAddressChanged: if ((event->InterfaceIpAddressChanged.Type == InterfaceIpChangeType::kIpV4_Assigned) || (event->InterfaceIpAddressChanged.Type == InterfaceIpChangeType::kIpV6_Assigned)) @@ -152,21 +120,45 @@ void ChipEventHandler(const ChipDeviceEvent * event, intptr_t arg) // will not trigger a 'internet connectivity change' as there is no internet // connectivity. MDNS still wants to refresh its listening interfaces to include the // newly selected address. + chip::app::DnssdServer::Instance().StartServer(); - } - if (event->InterfaceIpAddressChanged.Type == InterfaceIpChangeType::kIpV6_Assigned) - { - ChipLogProgress(NotSpecified, "Initializing route hook..."); bl_route_hook_init(); -#ifdef OTA_ENABLED chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Seconds32(OTAConfig::kInitOTARequestorDelaySec), OTAConfig::InitOTARequestorHandler, nullptr); -#endif } + break; #endif + case DeviceEventType::kInternetConnectivityChange: + if (event->InternetConnectivityChange.IPv4 == kConnectivity_Established) + { + ChipLogProgress(NotSpecified, "IPv4 connectivity ready..."); + } + else if (event->InternetConnectivityChange.IPv4 == kConnectivity_Lost) + { + ChipLogProgress(NotSpecified, "Lost IPv4 connectivity..."); + } + if (event->InternetConnectivityChange.IPv6 == kConnectivity_Established) + { + ChipLogProgress(NotSpecified, "IPv6 connectivity ready..."); + } + else if (event->InternetConnectivityChange.IPv6 == kConnectivity_Lost) + { + ChipLogProgress(NotSpecified, "Lost IPv6 connectivity..."); + } + break; + case DeviceEventType::kCHIPoBLEConnectionEstablished: + ChipLogProgress(NotSpecified, "BLE connection established"); + break; + case DeviceEventType::kCHIPoBLEConnectionClosed: + ChipLogProgress(NotSpecified, "BLE disconnected"); + break; + case DeviceEventType::kCommissioningComplete: + ChipLogProgress(NotSpecified, "Commissioning complete"); + GetAppTask().PostEvent(AppTask::APP_EVENT_LIGHTING_MASK); + break; default: break; } @@ -253,7 +245,12 @@ CHIP_ERROR PlatformManagerImpl::PlatformInit(void) ConfigurationMgr().LogDeviceConfig(); +#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE PrintOnboardingCodes(chip::RendezvousInformationFlag(chip::RendezvousInformationFlag::kBLE)); +#else + PrintOnboardingCodes(chip::RendezvousInformationFlag(chip::RendezvousInformationFlag::kOnNetwork)); +#endif + PlatformMgr().AddEventHandler(ChipEventHandler, 0); #if PW_RPC_ENABLED diff --git a/examples/platform/bouffalolab/common/plat/uart.c b/examples/platform/bouffalolab/common/plat/uart.c index 8f2742f0296f5b..35e0516e480b33 100644 --- a/examples/platform/bouffalolab/common/plat/uart.c +++ b/examples/platform/bouffalolab/common/plat/uart.c @@ -19,12 +19,21 @@ #include #include -#include -#include - #include +#ifdef CFG_USB_CDC_ENABLE +#include +#include +#include +#include +#include +#include +#include +#else +#include +#include extern hosal_uart_dev_t uart_stdio; +#endif #if CONFIG_ENABLE_CHIP_SHELL || PW_RPC_ENABLED @@ -42,6 +51,7 @@ typedef struct _chipUart static chipUart_t chipUart_var; +#ifndef CFG_USB_CDC_ENABLE static int uartTxCallback(void * p_arg) { hosal_uart_ioctl(&uart_stdio, HOSAL_UART_TX_TRIGGER_OFF, NULL); @@ -81,6 +91,39 @@ static int uartRxCallback(void * p_arg) return 0; } +#else +void aosUartRxCallback(int fd, void * param) +{ + uint32_t len = 0, readlen = 0; + BaseType_t xHigherPriorityTaskWoken = 1; + + if (chipUart_var.head >= chipUart_var.tail) + { + if (chipUart_var.head < MAX_BUFFER_SIZE) + { + readlen = len = aos_read(fd, chipUart_var.rxbuf + chipUart_var.head, MAX_BUFFER_SIZE - chipUart_var.head); + chipUart_var.head = (chipUart_var.head + len) % MAX_BUFFER_SIZE; + } + + if (0 == chipUart_var.head) + { + len = aos_read(fd, chipUart_var.rxbuf, chipUart_var.tail - 1); + chipUart_var.head += len; + readlen += len; + } + } + else + { + readlen = aos_read(fd, chipUart_var.rxbuf + chipUart_var.head, chipUart_var.tail - chipUart_var.head - 1); + chipUart_var.head += readlen; + } + + if (chipUart_var.head != chipUart_var.tail) + { + xSemaphoreGiveFromISR(chipUart_var.sema, &xHigherPriorityTaskWoken); + } +} +#endif void uartInit(void) { @@ -88,11 +131,13 @@ void uartInit(void) chipUart_var.sema = xSemaphoreCreateBinaryStatic(&chipUart_var.mutx); +#ifndef CFG_USB_CDC_ENABLE hosal_uart_finalize(&uart_stdio); hosal_uart_init(&uart_stdio); hosal_uart_callback_set(&uart_stdio, HOSAL_UART_RX_CALLBACK, uartRxCallback, NULL); hosal_uart_callback_set(&uart_stdio, HOSAL_UART_TX_CALLBACK, uartTxCallback, NULL); hosal_uart_ioctl(&uart_stdio, HOSAL_UART_MODE_SET, (void *) HOSAL_UART_MODE_INT); +#endif } int16_t uartRead(char * Buf, uint16_t NbBytesToRead) @@ -120,7 +165,23 @@ int16_t uartRead(char * Buf, uint16_t NbBytesToRead) } #endif +#ifndef CFG_USB_CDC_ENABLE int16_t uartWrite(const char * Buf, uint16_t BufLength) { return hosal_uart_send(&uart_stdio, Buf, BufLength); } +#else +int16_t uartWrite(const char * Buf, uint16_t BufLength) +{ + uint16_t sent = 0; + do + { + extern int vfs_fd; + if (vfs_fd >= 0) + { + sent += (uint8_t) aos_write(vfs_fd, Buf + sent, BufLength - sent); + } + } while (sent < BufLength); + return sent; +} +#endif diff --git a/examples/platform/bouffalolab/common/plat/uart.h b/examples/platform/bouffalolab/common/plat/uart.h index a963a343bb8940..ff2a398a395dd7 100644 --- a/examples/platform/bouffalolab/common/plat/uart.h +++ b/examples/platform/bouffalolab/common/plat/uart.h @@ -28,6 +28,10 @@ void uartInit(void); int16_t uartWrite(const char * Buf, uint16_t BufLength); int16_t uartRead(char * Buf, uint16_t NbBytesToRead); +#ifdef CFG_USB_CDC_ENABLE +void aosUartRxCallback(int fd, void * param); +#endif + #ifdef __cplusplus } // extern "C" #endif diff --git a/examples/platform/bouffalolab/bl602/route_hook/bl_route_hook.c b/examples/platform/bouffalolab/common/route_hook/bl_route_hook.c similarity index 88% rename from examples/platform/bouffalolab/bl602/route_hook/bl_route_hook.c rename to examples/platform/bouffalolab/common/route_hook/bl_route_hook.c index bcdbcc4edef34a..93cc731b99857d 100644 --- a/examples/platform/bouffalolab/bl602/route_hook/bl_route_hook.c +++ b/examples/platform/bouffalolab/common/route_hook/bl_route_hook.c @@ -1,8 +1,6 @@ #include #include -#include "bl_route_hook.h" -#include "bl_route_table.h" #include "utils_log.h" #include "lwip/icmp6.h" @@ -12,7 +10,9 @@ #include "lwip/prot/ip6.h" #include "lwip/prot/nd6.h" #include "lwip/raw.h" -#include + +#include "bl_route_hook.h" +#include "bl_route_table.h" typedef struct bl_route_hook_t { @@ -36,6 +36,8 @@ typedef struct rio_header_t rio_header_t; static bl_route_hook_t * s_hooks; +extern struct netif * deviceInterface_getNetif(void); + static bool is_self_address(struct netif * netif, const ip6_addr_t * addr) { for (size_t i = 0; i < LWIP_ARRAYSIZE(netif->ip6_addr); i++) @@ -79,7 +81,7 @@ static void ra_recv_handler(struct netif * netif, const uint8_t * icmp_payload, const uint8_t * rio_data = &icmp_payload[sizeof(rio_header_t)]; uint8_t rio_data_len = opt_len - sizeof(rio_header_t); - log_info("Received RIO\n"); + log_info("Received RIO\r\n"); if (rio_data_len >= prefix_len_bytes) { ip6_addr_t prefix; @@ -93,14 +95,14 @@ static void ra_recv_handler(struct netif * netif, const uint8_t * icmp_payload, route.prefix = prefix; route.preference = preference; route.lifetime_seconds = lwip_ntohl(rio_header.route_lifetime); - log_info("prefix %s lifetime %u\n", ip6addr_ntoa(&prefix), route.lifetime_seconds); + log_info("prefix %s lifetime %u\r\n", ip6addr_ntoa(&prefix), route.lifetime_seconds); if (bl_route_table_add_route_entry(&route) == NULL) { - log_error("Failed to add route table entry\n"); + log_error("Failed to add route table entry\r\n"); } else { - log_info("Added entry to route table\n"); + log_info("Added entry to route table\r\n"); } } } @@ -127,12 +129,12 @@ static uint8_t icmp6_raw_recv_handler(void * arg, struct raw_pcb * pcb, struct p if (p->tot_len != p->len) { - log_error("Ignore segmented ICMP packet\n"); + log_error("Ignore segmented ICMP packet\r\n"); return 0; } if (p->tot_len <= sizeof(struct ip6_hdr) + sizeof(struct icmp6_hdr)) { - log_error("Ignore invalid ICMP packet\n"); + log_error("Ignore invalid ICMP packet\r\n"); return 0; } if (!ip6_addr_islinklocal(&dest) && !ip6_addr_isallnodes_linklocal(&dest) && !ip6_addr_isallrouters_linklocal(&dest)) @@ -151,16 +153,16 @@ static uint8_t icmp6_raw_recv_handler(void * arg, struct raw_pcb * pcb, struct p return 0; } -int8_t bl_route_hook_init() +int8_t bl_route_hook_init(void) { - struct netif * lwip_netif = wifi_mgmr_sta_netif_get(); ip_addr_t router_group = IPADDR6_INIT_HOST(0xFF020000, 0, 0, 0x02); bl_route_hook_t * hook = NULL; uint8_t ret = 0; + struct netif * lwip_netif = deviceInterface_getNetif(); if (lwip_netif == NULL) { - log_error("Invalid network interface\n"); + log_error("Invalid network interface\r\n"); return -1; } @@ -168,7 +170,6 @@ int8_t bl_route_hook_init() { if (iter->netif == lwip_netif) { - log_error("Hook already installed on netif, skip...\n"); return 0; } } @@ -176,13 +177,13 @@ int8_t bl_route_hook_init() hook = (bl_route_hook_t *) malloc(sizeof(bl_route_hook_t)); if (hook == NULL) { - log_error("Cannot allocate hook\n"); + log_error("Cannot allocate hook\r\n"); return -1; } if (mld6_joingroup_netif(lwip_netif, ip_2_ip6(&router_group)) != ERR_OK) { - log_error("Failed to join multicast group\n"); + log_error("Failed to join multicast group\r\n"); ret = -1; goto exit; } diff --git a/examples/platform/bouffalolab/bl602/route_hook/bl_route_hook.h b/examples/platform/bouffalolab/common/route_hook/bl_route_hook.h similarity index 100% rename from examples/platform/bouffalolab/bl602/route_hook/bl_route_hook.h rename to examples/platform/bouffalolab/common/route_hook/bl_route_hook.h diff --git a/examples/platform/bouffalolab/bl602/route_hook/bl_route_table.c b/examples/platform/bouffalolab/common/route_hook/bl_route_table.c similarity index 100% rename from examples/platform/bouffalolab/bl602/route_hook/bl_route_table.c rename to examples/platform/bouffalolab/common/route_hook/bl_route_table.c index 4d2c90129712bf..3e5ae103b36e22 100644 --- a/examples/platform/bouffalolab/bl602/route_hook/bl_route_table.c +++ b/examples/platform/bouffalolab/common/route_hook/bl_route_table.c @@ -1,7 +1,7 @@ -#include "bl_route_table.h" #include #include +#include "bl_route_table.h" #include "lwip/ip6_addr.h" #include "lwip/netif.h" #include "lwip/timeouts.h" diff --git a/examples/platform/bouffalolab/bl602/route_hook/bl_route_table.h b/examples/platform/bouffalolab/common/route_hook/bl_route_table.h similarity index 100% rename from examples/platform/bouffalolab/bl602/route_hook/bl_route_table.h rename to examples/platform/bouffalolab/common/route_hook/bl_route_table.h diff --git a/scripts/build/build/targets.py b/scripts/build/build/targets.py index 0d881407c089da..fe730b371eaed1 100755 --- a/scripts/build/build/targets.py +++ b/scripts/build/build/targets.py @@ -588,12 +588,16 @@ def BuildBouffalolabTarget(): # Boards target.AppendFixedTargets([ - TargetPart('BL602-IoT-Matter-V1', board=BouffalolabBoard.BL602_IoT_Matter_V1, module_type="BL602"), - TargetPart('BL602-IOT-DVK-3S', board=BouffalolabBoard.BL602_IOT_DVK_3S, module_type="BL602"), - TargetPart('BL602-NIGHT-LIGHT', board=BouffalolabBoard.BL602_NIGHT_LIGHT, module_type="BL602"), - TargetPart('XT-ZB6-DevKit', board=BouffalolabBoard.XT_ZB6_DevKit, module_type="BL706C-22"), - TargetPart('BL706-IoT-DVK', board=BouffalolabBoard.BL706_IoT_DVK, module_type="BL706C-22"), - TargetPart('BL706-NIGHT-LIGHT', board=BouffalolabBoard.BL706_NIGHT_LIGHT, module_type="BL706C-22"), + TargetPart('BL602-IoT-Matter-V1', + board=BouffalolabBoard.BL602_IoT_Matter_V1, module_type="BL602"), + TargetPart('BL602-NIGHT-LIGHT', + board=BouffalolabBoard.BL602_NIGHT_LIGHT, module_type="BL602"), + TargetPart('XT-ZB6-DevKit', board=BouffalolabBoard.XT_ZB6_DevKit, + module_type="BL706C-22"), + TargetPart('BL706-NIGHT-LIGHT', + board=BouffalolabBoard.BL706_NIGHT_LIGHT, module_type="BL706C-22"), + TargetPart('BL706-ETH', + board=BouffalolabBoard.BL706_ETH, module_type="BL706C-22"), TargetPart('BL704L-DVK', board=BouffalolabBoard.BL704L_DVK, module_type="BL704L"), ]) @@ -606,6 +610,7 @@ def BuildBouffalolabTarget(): target.AppendModifier('115200', baudrate=115200) target.AppendModifier('rpc', enable_rpcs=True) target.AppendModifier('cdc', enable_cdc=True) + target.AppendModifier('resetCnt', enable_resetCnt=True) target.AppendModifier('rotating_device_id', enable_rotating_device_id=True) return target diff --git a/scripts/build/builders/bouffalolab.py b/scripts/build/builders/bouffalolab.py index 8281ba99e8ca89..20ef4c75046862 100644 --- a/scripts/build/builders/bouffalolab.py +++ b/scripts/build/builders/bouffalolab.py @@ -43,26 +43,23 @@ def FlashBundleName(self): class BouffalolabBoard(Enum): BL602_IoT_Matter_V1 = auto() - BL602_IOT_DVK_3S = auto() BL602_NIGHT_LIGHT = auto() XT_ZB6_DevKit = auto() - BL706_IoT_DVK = auto() BL706_NIGHT_LIGHT = auto() + BL706_ETH = auto() BL704L_DVK = auto() def GnArgName(self): if self == BouffalolabBoard.BL602_IoT_Matter_V1: return 'BL602-IoT-Matter-V1' - elif self == BouffalolabBoard.BL602_IOT_DVK_3S: - return 'BL602-IOT-DVK-3S' elif self == BouffalolabBoard.BL602_NIGHT_LIGHT: return 'BL602-NIGHT-LIGHT' elif self == BouffalolabBoard.XT_ZB6_DevKit: return 'XT-ZB6-DevKit' - elif self == BouffalolabBoard.BL706_IoT_DVK: - return 'BL706-IoT-DVK' elif self == BouffalolabBoard.BL706_NIGHT_LIGHT: return 'BL706-NIGHT-LIGHT' + elif self == BouffalolabBoard.BL706_ETH: + return 'BL706-ETH' elif self == BouffalolabBoard.BL704L_DVK: return 'BL704L-DVK' else: @@ -75,12 +72,13 @@ def __init__(self, root, runner, app: BouffalolabApp = BouffalolabApp.LIGHT, - board: BouffalolabBoard = BouffalolabBoard.BL706_IoT_DVK, + board: BouffalolabBoard = BouffalolabBoard.XT_ZB6_DevKit, enable_rpcs: bool = False, module_type: str = "BL706C-22", baudrate=2000000, enable_shell: bool = False, enable_cdc: bool = False, + enable_resetCnt: bool = False, enable_rotating_device_id: bool = False ): @@ -113,12 +111,28 @@ def __init__(self, self.argsOpt.append('board=\"{}\"'.format(self.board.GnArgName())) self.argsOpt.append('baudrate=\"{}\"'.format(baudrate)) + if bouffalo_chip == "bl602": + self.argsOpt.append('chip_enable_openthread=false') + self.argsOpt.append('chip_enable_wifi=true') if bouffalo_chip == "bl702": self.argsOpt.append('module_type=\"{}\"'.format(module_type)) + if board == BouffalolabBoard.BL706_ETH: + self.argsOpt.append('chip_config_network_layer_ble=false') + self.argsOpt.append('chip_enable_openthread=false') + self.argsOpt.append('chip_enable_wifi=false') + else: + self.argsOpt.append('chip_enable_openthread=true') + self.argsOpt.append('chip_enable_wifi=false') + elif bouffalo_chip == "bl702l": + self.argsOpt.append('chip_enable_openthread=true') + self.argsOpt.append('chip_enable_wifi=false') if enable_cdc: if bouffalo_chip != "bl702": raise Exception('Chip %s does NOT support USB CDC' % bouffalo_chip) + if board == BouffalolabBoard.BL706_ETH: + raise Exception('Board %s does NOT support USB CDC' % self.board.GnArgName()) + self.argsOpt.append('enable_cdc_module=true') if enable_rpcs: @@ -126,6 +140,9 @@ def __init__(self, elif enable_shell: self.argsOpt.append('chip_build_libshell=true') + if enable_resetCnt: + self.argsOpt.append('enable_reset_counter=true') + if enable_rotating_device_id: self.argsOpt.append('chip_enable_additional_data_advertising=true') self.argsOpt.append('chip_enable_rotating_device_id=true') diff --git a/scripts/build/testdata/all_targets_linux_x64.txt b/scripts/build/testdata/all_targets_linux_x64.txt index 40d65afb7f72ff..12765944418c72 100644 --- a/scripts/build/testdata/all_targets_linux_x64.txt +++ b/scripts/build/testdata/all_targets_linux_x64.txt @@ -1,7 +1,7 @@ ameba-amebad-{all-clusters,all-clusters-minimal,light,light-switch,pigweed} asr-{asr582x,asr595x,asr550x}-{all-clusters,all-clusters-minimal,lighting,light-switch,lock,bridge,temperature-measurement,thermostat,ota-requestor}[-ota][-shell][-no_logging][-factory][-rotating_id][-rio] android-{arm,arm64,x86,x64,androidstudio-arm,androidstudio-arm64,androidstudio-x86,androidstudio-x64}-{chip-tool,chip-test,tv-server,tv-casting-app,java-matter-controller}[-no-debug] -bouffalolab-{bl602-iot-matter-v1,bl602-iot-dvk-3s,bl602-night-light,xt-zb6-devkit,bl706-iot-dvk,bl706-night-light,bl704l-dvk}-light[-shell][-115200][-rpc][-cdc][-rotating_device_id] +bouffalolab-{bl602-iot-matter-v1,bl602-night-light,xt-zb6-devkit,bl706-night-light,bl706-eth,bl704l-dvk}-light[-shell][-115200][-rpc][-cdc][-resetcnt][-rotating_device_id] cc32xx-lock ti-cc13x2x7_26x2x7-{lighting,lock,pump,pump-controller}[-mtd] ti-cc13x4_26x4-{all-clusters,lighting,lock,pump,pump-controller}[-mtd][-ftd] diff --git a/src/lwip/BUILD.gn b/src/lwip/BUILD.gn index 60eb4d20e9cf11..24462da32a920c 100644 --- a/src/lwip/BUILD.gn +++ b/src/lwip/BUILD.gn @@ -64,6 +64,7 @@ if (lwip_platform == "cc13xx_26xx") { import("//build_overrides/bouffalolab_iot_sdk.gni") } else if (lwip_platform == "bl702") { import("//build_overrides/bouffalolab_iot_sdk.gni") + import("${chip_root}/src/platform/device.gni") } else if (lwip_platform == "bl702l") { import("//build_overrides/bouffalolab_iot_sdk.gni") } else if (lwip_platform == "mw320") { @@ -111,28 +112,6 @@ if (current_os == "zephyr" || current_os == "mbed") { public_configs = [ "${chip_root}/src:includes" ] public_configs += [ "${psoc6_sdk_build_root}:psoc6_sdk_config" ] } -} else if (lwip_platform == "bl702_lwip") { - import("${bouffalolab_iot_sdk_build_root}/bl702/bl_iot_sdk.gni") - - group("lwip") { - public_deps = [ ":lwip_buildconfig" ] - public_deps += [ "${bouffalolab_iot_sdk_build_root}/bl702:bl_iot_sdk" ] - } - - group("all") { - deps = [ ":lwip" ] - } -} else if (lwip_platform == "bl702l_lwip") { - import("${bouffalolab_iot_sdk_build_root}/bl702l/bl_iot_sdk.gni") - - group("lwip") { - public_deps = [ ":lwip_buildconfig" ] - public_deps += [ "${bouffalolab_iot_sdk_build_root}/bl702l:bl_iot_sdk" ] - } - - group("all") { - deps = [ ":lwip" ] - } } else if (lwip_platform == "qpg") { config("lwip_config") { include_dirs = [ "freertos" ] @@ -161,6 +140,18 @@ if (current_os == "zephyr" || current_os == "mbed") { public_deps += [ "${bouffalolab_iot_sdk_build_root}/bl602:bl_iot_sdk" ] } + group("all") { + deps = [ ":lwip" ] + } +} else if (lwip_platform == "bl702" && defined(chip_enable_openthread) && + chip_enable_openthread == false) { + # bl702 platform will use ethernet or SPI Wi-Fi for connectivity, if openthread is not enabled + import("${bouffalolab_iot_sdk_build_root}/bl702/bl_iot_sdk.gni") + group("lwip") { + public_deps = [ ":lwip_buildconfig" ] + public_deps += [ "${bouffalolab_iot_sdk_build_root}/bl702:bl_iot_sdk" ] + } + group("all") { deps = [ ":lwip" ] } @@ -220,8 +211,6 @@ if (current_os == "zephyr" || current_os == "mbed") { public_deps += [ "${k32w0_sdk_build_root}:k32w0_sdk" ] } else if (lwip_platform == "cyw30739") { public_deps += [ "${cyw30739_sdk_build_root}:cyw30739_sdk" ] - } else if (lwip_platform == "bl602") { - public_deps += [ "${bouffalolab_iot_sdk_build_root}/bl702l:bl_iot_sdk" ] } else if (lwip_platform == "bl702") { public_deps += [ "${bouffalolab_iot_sdk_build_root}/bl702:bl_iot_sdk" ] } else if (lwip_platform == "bl702l") { diff --git a/src/platform/BUILD.gn b/src/platform/BUILD.gn index e0bfc11156a22a..04c4d522b5abe7 100644 --- a/src/platform/BUILD.gn +++ b/src/platform/BUILD.gn @@ -120,7 +120,9 @@ if (chip_device_platform != "none" && chip_device_platform != "external") { if (chip_device_platform == "linux" || chip_device_platform == "darwin" || chip_device_platform == "tizen" || chip_device_platform == "android" || - chip_device_platform == "k32w0" || chip_device_platform == "webos") { + chip_device_platform == "k32w0" || chip_device_platform == "webos" || + chip_device_platform == "bl602" || chip_device_platform == "bl702" || + chip_device_platform == "bl702l") { defines += [ "CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE=${chip_enable_ble}" ] } diff --git a/src/platform/bouffalolab/BL602/ConfigurationManagerImpl.cpp b/src/platform/bouffalolab/BL602/ConfigurationManagerImpl.cpp index b112fe751a4358..5469fb9b1015d8 100644 --- a/src/platform/bouffalolab/BL602/ConfigurationManagerImpl.cpp +++ b/src/platform/bouffalolab/BL602/ConfigurationManagerImpl.cpp @@ -15,18 +15,8 @@ * limitations under the License. */ -#include - #include -#include - -#include -#include - -#include -#include - extern "C" { #include } diff --git a/src/platform/bouffalolab/BL602/ConnectivityManagerImpl.cpp b/src/platform/bouffalolab/BL602/ConnectivityManagerImpl.cpp index 9f209d14ebf133..25ae917a75bd24 100644 --- a/src/platform/bouffalolab/BL602/ConnectivityManagerImpl.cpp +++ b/src/platform/bouffalolab/BL602/ConnectivityManagerImpl.cpp @@ -18,130 +18,86 @@ #include #include -#include -#include -#include -#include -#include -#include - -#include - -#if INET_CONFIG_ENABLE_TCP_ENDPOINT -#include -#endif - -#include - -#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE -#include -#endif - -#if CHIP_DEVICE_CONFIG_ENABLE_THREAD -#include -#endif - -#include - -#include -#include - -#include -#include - -#include -#include -#include -#include - -#define zero(S) memset(&S, 0, sizeof(S)) +#include +#include using namespace ::chip; -using namespace ::chip::Dnssd; -using namespace ::chip::Inet; -using namespace ::chip::System; -using namespace ::chip::TLV; -using namespace ::chip::DeviceLayer::Internal; namespace chip { namespace DeviceLayer { -ConnectivityManager::WiFiStationState ConnectivityManagerImpl::mWiFiStationState = - ConnectivityManager::kWiFiStationState_NotConnected; - -void ConnectivityManagerImpl::WifiStationStateChange(void) +void ConnectivityManagerImpl::OnWiFiStationDisconnected() { - ChipDeviceEvent event; + NetworkCommissioning::BLWiFiDriver::GetInstance().SetLastDisconnectReason(NULL); + uint16_t reason = NetworkCommissioning::BLWiFiDriver::GetInstance().GetLastDisconnectReason(); + uint8_t associationFailureCause = + chip::to_underlying(chip::app::Clusters::WiFiNetworkDiagnostics::AssociationFailureCauseEnum::kUnknown); + WiFiDiagnosticsDelegate * delegate = GetDiagnosticDataProvider().GetWiFiDiagnosticsDelegate(); + + ChipLogError(DeviceLayer, "WiFi station disconnect, reason %d.", reason); - if (ConnectivityManagerImpl::mWiFiStationState == ConnectivityManager::kWiFiStationState_Connected) + switch (reason) { - event.Type = DeviceEventType::kWiFiConnectivityChange; - event.WiFiConnectivityChange.Result = kConnectivity_Established; - PlatformMgr().PostEventOrDie(&event); + case WLAN_FW_TX_ASSOC_FRAME_ALLOCATE_FAIILURE: + case WLAN_FW_ASSOCIATE_FAIILURE: + case WLAN_FW_4WAY_HANDSHAKE_ERROR_PSK_TIMEOUT_FAILURE: + associationFailureCause = + chip::to_underlying(chip::app::Clusters::WiFiNetworkDiagnostics::AssociationFailureCauseEnum::kAssociationFailed); + if (delegate) + { + delegate->OnAssociationFailureDetected(associationFailureCause, reason); + } + break; + case WLAN_FW_TX_AUTH_FRAME_ALLOCATE_FAIILURE: + case WLAN_FW_AUTHENTICATION_FAIILURE: + case WLAN_FW_AUTH_ALGO_FAIILURE: + case WLAN_FW_DEAUTH_BY_AP_WHEN_NOT_CONNECTION: + case WLAN_FW_DEAUTH_BY_AP_WHEN_CONNECTION: + case WLAN_FW_4WAY_HANDSHAKE_TX_DEAUTH_FRAME_TRANSMIT_FAILURE: + case WLAN_FW_4WAY_HANDSHAKE_TX_DEAUTH_FRAME_ALLOCATE_FAIILURE: + case WLAN_FW_AUTH_OR_ASSOC_RESPONSE_TIMEOUT_FAILURE: + case WLAN_FW_DISCONNECT_BY_USER_WITH_DEAUTH: + case WLAN_FW_DISCONNECT_BY_USER_NO_DEAUTH: + associationFailureCause = + chip::to_underlying(chip::app::Clusters::WiFiNetworkDiagnostics::AssociationFailureCauseEnum::kAuthenticationFailed); + if (delegate) + { + delegate->OnAssociationFailureDetected(associationFailureCause, reason); + } + break; + case WLAN_FW_SCAN_NO_BSSID_AND_CHANNEL: + associationFailureCause = + chip::to_underlying(chip::app::Clusters::WiFiNetworkDiagnostics::AssociationFailureCauseEnum::kSsidNotFound); + if (delegate) + { + delegate->OnAssociationFailureDetected(associationFailureCause, reason); + } + break; + case WLAN_FW_BEACON_LOSS: + case WLAN_FW_JOIN_NETWORK_SECURITY_NOMATCH: + case WLAN_FW_JOIN_NETWORK_WEPLEN_ERROR: + case WLAN_FW_DISCONNECT_BY_FW_PS_TX_NULLFRAME_FAILURE: + case WLAN_FW_CREATE_CHANNEL_CTX_FAILURE_WHEN_JOIN_NETWORK: + case WLAN_FW_ADD_STA_FAILURE: + case WLAN_FW_JOIN_NETWORK_FAILURE: + break; + + default: + if (delegate) + { + delegate->OnAssociationFailureDetected(associationFailureCause, reason); + } + break; } -} - -void ConnectivityManagerImpl::DriveStationState() -{ - return; -} - -void ConnectivityManagerImpl::DriveStationState(::chip::System::Layer * aLayer, void * aAppState) -{ - sInstance.DriveStationState(); -} -CHIP_ERROR ConnectivityManagerImpl::_SetWiFiStationMode(WiFiStationMode val) -{ - CHIP_ERROR err = CHIP_NO_ERROR; - - DeviceLayer::SystemLayer().ScheduleWork(DriveStationState, NULL); - - return err; -} - -bool ConnectivityManagerImpl::_IsWiFiStationEnabled(void) -{ - return GetWiFiStationMode() == kWiFiStationMode_Enabled; -} - -void ConnectivityManagerImpl::OnStationConnected() -{ - NetworkCommissioning::BLWiFiDriver::GetInstance().OnConnectWiFiNetwork(); - // TODO Invoke WARM to perform actions that occur when the WiFi station interface comes up. - -#if 0 - // Alert other components of the new state. - ChipDeviceEvent event; - event.Type = DeviceEventType::kWiFiConnectivityChange; - event.WiFiConnectivityChange.Result = kConnectivity_Established; - PlatformMgr().PostEventOrDie(&event); - - UpdateInternetConnectivityState(); -#endif -} - -void ConnectivityManagerImpl::ChangeWiFiStationState(WiFiStationState newState) -{ - if (mWiFiStationState != newState) + if (delegate) { - ChipLogProgress(DeviceLayer, "WiFi station state change: %s -> %s", WiFiStationStateToStr(mWiFiStationState), - WiFiStationStateToStr(newState)); - mWiFiStationState = newState; - SystemLayer().ScheduleLambda([]() { NetworkCommissioning::BLWiFiDriver::GetInstance().OnNetworkStatusChange(); }); + delegate->OnDisconnectionDetected(reason); + delegate->OnConnectionStatusChanged( + chip::to_underlying(chip::app::Clusters::WiFiNetworkDiagnostics::ConnectionStatusEnum::kNotConnected)); } } -void ConnectivityManagerImpl::OnIPv6AddressAvailable() -{ - ChipLogProgress(DeviceLayer, "IPv6 addr available."); - - ChipDeviceEvent event; - event.Type = DeviceEventType::kInterfaceIpAddressChanged; - event.InterfaceIpAddressChanged.Type = InterfaceIpChangeType::kIpV6_Assigned; - PlatformMgr().PostEventOrDie(&event); -} - } // namespace DeviceLayer } // namespace chip diff --git a/src/platform/bouffalolab/BL602/DiagnosticDataProviderImpl.cpp b/src/platform/bouffalolab/BL602/DiagnosticDataProviderImpl.cpp index b49fa9cbde9a5a..8cd34b5bf67d83 100644 --- a/src/platform/bouffalolab/BL602/DiagnosticDataProviderImpl.cpp +++ b/src/platform/bouffalolab/BL602/DiagnosticDataProviderImpl.cpp @@ -20,10 +20,7 @@ #include #include -#include - extern "C" { -#include #include #include @@ -64,74 +61,6 @@ CHIP_ERROR DiagnosticDataProviderImpl::GetBootReason(BootReasonType & bootReason return CHIP_NO_ERROR; } -static int bl_netif_get_all_ip6(struct netif * netif, ip6_addr_t if_ip6[]) -{ - if (netif == NULL || if_ip6 == NULL) - { - return 0; - } - - int addr_count = 0; - for (int i = 0; (i < LWIP_IPV6_NUM_ADDRESSES) && (i < kMaxIPv6AddrCount); i++) - { - if (!ip_addr_cmp(&netif->ip6_addr[i], IP6_ADDR_ANY)) - { - memcpy(&if_ip6[addr_count++], &netif->ip6_addr[i], sizeof(ip6_addr_t)); - } - } - - return addr_count; -} - -CHIP_ERROR DiagnosticDataProviderImpl::GetNetworkInterfaces(NetworkInterface ** netifpp) -{ - NetworkInterface * ifp = new NetworkInterface(); - struct netif * netif; - - netif = wifi_mgmr_sta_netif_get(); - if (netif) - { - Platform::CopyString(ifp->Name, netif->name); - ifp->name = CharSpan::fromCharString(ifp->Name); - ifp->isOperational = true; - ifp->type = EMBER_ZCL_INTERFACE_TYPE_ENUM_WI_FI; - ifp->offPremiseServicesReachableIPv4.SetNull(); - ifp->offPremiseServicesReachableIPv6.SetNull(); - bl_efuse_read_mac(ifp->MacAddress); - ifp->hardwareAddress = ByteSpan(ifp->MacAddress, 6); - - uint32_t ip, gw, mask; - wifi_mgmr_sta_ip_get(&ip, &gw, &mask); - memcpy(ifp->Ipv4AddressesBuffer[0], &ip, kMaxIPv4AddrSize); - ifp->Ipv4AddressSpans[0] = ByteSpan(ifp->Ipv4AddressesBuffer[0], kMaxIPv4AddrSize); - ifp->IPv4Addresses = chip::app::DataModel::List(ifp->Ipv4AddressSpans, 1); - - uint8_t ipv6_addr_count = 0; - ip6_addr_t ip6_addr[kMaxIPv6AddrCount]; - ipv6_addr_count = bl_netif_get_all_ip6(netif, ip6_addr); - for (uint8_t idx = 0; idx < ipv6_addr_count; ++idx) - { - memcpy(ifp->Ipv6AddressesBuffer[idx], ip6_addr[idx].addr, kMaxIPv6AddrSize); - ifp->Ipv6AddressSpans[idx] = ByteSpan(ifp->Ipv6AddressesBuffer[idx], kMaxIPv6AddrSize); - } - ifp->IPv6Addresses = chip::app::DataModel::List(ifp->Ipv6AddressSpans, ipv6_addr_count); - } - - *netifpp = ifp; - - return CHIP_NO_ERROR; -} - -void DiagnosticDataProviderImpl::ReleaseNetworkInterfaces(NetworkInterface * netifp) -{ - while (netifp) - { - NetworkInterface * del = netifp; - netifp = netifp->Next; - delete del; - } -} - CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiBssId(MutableByteSpan & BssId) { return CopySpanToMutableSpan(ByteSpan(wifiMgmr.wifi_mgmr_stat_info.bssid), BssId); diff --git a/src/platform/bouffalolab/BL602/NetworkCommissioningDriver.cpp b/src/platform/bouffalolab/BL602/NetworkCommissioningDriver.cpp index 28f5a5f9a2892d..9cf57c3c5e74d0 100644 --- a/src/platform/bouffalolab/BL602/NetworkCommissioningDriver.cpp +++ b/src/platform/bouffalolab/BL602/NetworkCommissioningDriver.cpp @@ -15,38 +15,25 @@ * limitations under the License. */ -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include + #include #include #include #include -#include -#include -#include -#include - #define WIFI_STA_DISCONNECT_DELAY (pdMS_TO_TICKS(200)) using namespace ::chip; +using namespace ::chip::DeviceLayer::Internal; namespace chip { namespace DeviceLayer { namespace NetworkCommissioning { namespace { -constexpr char kWiFiSSIDKeyName[] = "wifi-ssid"; -constexpr char kWiFiCredentialsKeyName[] = "wifi-pass"; - -constexpr char blWiFiSSIDKeyName[] = "bl-wifi-ssid"; -constexpr char blWiFiCredentialsKeyName[] = "bl-wifi-pass"; - static char WiFiSSIDStr[DeviceLayer::Internal::kMaxWiFiSSIDLength]; static uint8_t scan_type = 0; } // namespace @@ -57,10 +44,11 @@ CHIP_ERROR BLWiFiDriver::Init(NetworkStatusChangeCallback * networkStatusChangeC size_t ssidLen = 0; size_t credentialsLen = 0; - err = PersistedStorage::KeyValueStoreMgr().Get(kWiFiCredentialsKeyName, mSavedNetwork.credentials, + err = PersistedStorage::KeyValueStoreMgr().Get(BLConfig::kBLConfigKey_wifissid, mSavedNetwork.credentials, sizeof(mSavedNetwork.credentials), &credentialsLen); SuccessOrExit(err); - err = PersistedStorage::KeyValueStoreMgr().Get(kWiFiSSIDKeyName, mSavedNetwork.ssid, sizeof(mSavedNetwork.ssid), &ssidLen); + err = PersistedStorage::KeyValueStoreMgr().Get(BLConfig::kBLConfigKey_wifipassword, mSavedNetwork.ssid, + sizeof(mSavedNetwork.ssid), &ssidLen); SuccessOrExit(err); mSavedNetwork.credentialsLen = credentialsLen; @@ -88,25 +76,12 @@ void BLWiFiDriver::Shutdown() CHIP_ERROR BLWiFiDriver::CommitConfiguration() { - ReturnErrorOnFailure(PersistedStorage::KeyValueStoreMgr().Put(kWiFiSSIDKeyName, mStagingNetwork.ssid, mStagingNetwork.ssidLen)); - ReturnErrorOnFailure(PersistedStorage::KeyValueStoreMgr().Put(kWiFiCredentialsKeyName, mStagingNetwork.credentials, - mStagingNetwork.credentialsLen)); - mSavedNetwork = mStagingNetwork; - return CHIP_NO_ERROR; -} - -CHIP_ERROR BLWiFiDriver::SaveConfiguration() -{ - if (NULL == mStagingNetwork.ssid || 0 == mStagingNetwork.ssidLen || NULL == mStagingNetwork.credentials || - 0 == mStagingNetwork.credentialsLen) - { - return CHIP_ERROR_KEY_NOT_FOUND; - } - + ChipLogProgress(NetworkProvisioning, "BLWiFiDriver::CommitConfiguration"); ReturnErrorOnFailure( - PersistedStorage::KeyValueStoreMgr().Put(blWiFiSSIDKeyName, mStagingNetwork.ssid, mStagingNetwork.ssidLen)); - ReturnErrorOnFailure(PersistedStorage::KeyValueStoreMgr().Put(blWiFiCredentialsKeyName, mStagingNetwork.credentials, + PersistedStorage::KeyValueStoreMgr().Put(BLConfig::kBLConfigKey_wifissid, mStagingNetwork.ssid, mStagingNetwork.ssidLen)); + ReturnErrorOnFailure(PersistedStorage::KeyValueStoreMgr().Put(BLConfig::kBLConfigKey_wifipassword, mStagingNetwork.credentials, mStagingNetwork.credentialsLen)); + mSavedNetwork = mStagingNetwork; return CHIP_NO_ERROR; } @@ -164,12 +139,12 @@ Status BLWiFiDriver::ReorderNetwork(ByteSpan networkId, uint8_t index, MutableCh CHIP_ERROR BLWiFiDriver::ConnectWiFiNetwork(const char * ssid, uint8_t ssidLen, const char * key, uint8_t keyLen) { - // ReturnErrorOnFailure(ConnectivityMgr().SetWiFiStationMode(ConnectivityManager::kWiFiStationMode_Disabled)); - char wifi_ssid[64] = { 0 }; char passwd[64] = { 0 }; int state = 0; + ConnectivityMgrImpl().ChangeWiFiStationState(ConnectivityManager::kWiFiStationState_Connecting); + wifi_mgmr_sta_disconnect(); vTaskDelay(WIFI_STA_DISCONNECT_DELAY); @@ -187,33 +162,21 @@ CHIP_ERROR BLWiFiDriver::ConnectWiFiNetwork(const char * ssid, uint8_t ssidLen, wifi_interface = wifi_mgmr_sta_enable(); wifi_mgmr_sta_connect(&wifi_interface, wifi_ssid, passwd, NULL, NULL, 0, 0); - ReturnErrorOnFailure(ConnectivityMgr().SetWiFiStationMode(ConnectivityManager::kWiFiStationMode_Disabled)); - - return ConnectivityMgr().SetWiFiStationMode(ConnectivityManager::kWiFiStationMode_Enabled); -} - -CHIP_ERROR BLWiFiDriver::ReConnectWiFiNetwork(void) -{ - char ssid[64] = { 0 }; - char psk[64] = { 0 }; - size_t ssidLen = 0; - size_t pskLen = 0; - - ReturnErrorOnFailure( - PersistedStorage::KeyValueStoreMgr().Get((const char *) blWiFiSSIDKeyName, (void *) ssid, 64, &ssidLen, 0)); - ReturnErrorOnFailure( - PersistedStorage::KeyValueStoreMgr().Get((const char *) blWiFiCredentialsKeyName, (void *) psk, 64, &pskLen, 0)); - - ConnectWiFiNetwork(ssid, ssidLen, psk, pskLen); - return CHIP_NO_ERROR; } -void BLWiFiDriver::OnConnectWiFiNetwork() +void BLWiFiDriver::OnConnectWiFiNetwork(bool isConnected) { if (mpConnectCallback) { - mpConnectCallback->OnResult(Status::kSuccess, CharSpan(), 0); + if (isConnected) + { + mpConnectCallback->OnResult(Status::kSuccess, CharSpan(), 0); + } + else + { + mpConnectCallback->OnResult(Status::kUnknownError, CharSpan(), 0); + } mpConnectCallback = nullptr; } } @@ -360,7 +323,7 @@ void BLWiFiDriver::OnNetworkStatusChange() return; } - if (ConnectivityManagerImpl::mWiFiStationState == ConnectivityManager::kWiFiStationState_Connected) + if (ConnectivityManagerImpl().GetWiFiStationState() == ConnectivityManager::kWiFiStationState_Connected) { staConnected = true; } @@ -372,14 +335,12 @@ void BLWiFiDriver::OnNetworkStatusChange() return; } mpStatusChangeCallback->OnNetworkingStatusChange( - Status::kSuccess, MakeOptional(ByteSpan(configuredNetwork.networkID, configuredNetwork.networkIDLen)), + Status::kUnknownError, MakeOptional(ByteSpan(configuredNetwork.networkID, configuredNetwork.networkIDLen)), MakeOptional(GetLastDisconnectReason())); } CHIP_ERROR BLWiFiDriver::SetLastDisconnectReason(const ChipDeviceEvent * event) { - // VerifyOrReturnError(event->Type == DeviceEventType::kRtkWiFiStationDisconnectedEvent, CHIP_ERROR_INVALID_ARGUMENT); - uint16_t status_code, reason_code; wifi_mgmr_conn_result_get(&status_code, &reason_code); diff --git a/src/platform/bouffalolab/BL602/NetworkCommissioningDriver.h b/src/platform/bouffalolab/BL602/NetworkCommissioningDriver.h index fc08f778e8fbff..edf2d3f04d90a4 100644 --- a/src/platform/bouffalolab/BL602/NetworkCommissioningDriver.h +++ b/src/platform/bouffalolab/BL602/NetworkCommissioningDriver.h @@ -98,7 +98,6 @@ class BLWiFiDriver final : public WiFiDriver uint8_t GetConnectNetworkTimeoutSeconds() override { return kWiFiConnectNetworkTimeoutSeconds; } CHIP_ERROR CommitConfiguration() override; - CHIP_ERROR SaveConfiguration(); CHIP_ERROR RevertConfiguration() override; Status RemoveNetwork(ByteSpan networkId, MutableCharSpan & outDebugText, uint8_t & outNetworkIndex) override; @@ -111,8 +110,7 @@ class BLWiFiDriver final : public WiFiDriver void ScanNetworks(ByteSpan ssid, ScanCallback * callback) override; CHIP_ERROR ConnectWiFiNetwork(const char * ssid, uint8_t ssidLen, const char * key, uint8_t keyLen); - CHIP_ERROR ReConnectWiFiNetwork(void); - void OnConnectWiFiNetwork(); + void OnConnectWiFiNetwork(bool isConnected); void OnScanWiFiNetworkDone(); void OnNetworkStatusChange(); diff --git a/src/platform/bouffalolab/BL602/PlatformManagerImpl.cpp b/src/platform/bouffalolab/BL602/PlatformManagerImpl.cpp index 56761846061dc2..f16012851d78de 100644 --- a/src/platform/bouffalolab/BL602/PlatformManagerImpl.cpp +++ b/src/platform/bouffalolab/BL602/PlatformManagerImpl.cpp @@ -20,24 +20,14 @@ #include #include -#include -#include #include -#include -#include -#include #include -#include + #include -#include #include -extern "C" { -#include -} - namespace chip { namespace DeviceLayer { @@ -47,117 +37,12 @@ static wifi_conf_t conf = { static int app_entropy_source(void * data, unsigned char * output, size_t len, size_t * olen) { - bl_rand_stream(reinterpret_cast(output), static_cast(len)); *olen = len; return 0; } -static void WifiStaDisconect(void) -{ - NetworkCommissioning::BLWiFiDriver::GetInstance().SetLastDisconnectReason(NULL); - - uint16_t reason = NetworkCommissioning::BLWiFiDriver::GetInstance().GetLastDisconnectReason(); - uint8_t associationFailureCause = - chip::to_underlying(chip::app::Clusters::WiFiNetworkDiagnostics::AssociationFailureCauseEnum::kUnknown); - WiFiDiagnosticsDelegate * delegate = GetDiagnosticDataProvider().GetWiFiDiagnosticsDelegate(); - - if (ConnectivityManagerImpl::mWiFiStationState == ConnectivityManager::kWiFiStationState_Disconnecting) - { - return; - } - - ChipLogError(DeviceLayer, "WiFi station disconnect, reason %d.", reason); - - switch (reason) - { - case WLAN_FW_TX_ASSOC_FRAME_ALLOCATE_FAIILURE: - case WLAN_FW_ASSOCIATE_FAIILURE: - case WLAN_FW_4WAY_HANDSHAKE_ERROR_PSK_TIMEOUT_FAILURE: - associationFailureCause = - chip::to_underlying(chip::app::Clusters::WiFiNetworkDiagnostics::AssociationFailureCauseEnum::kAssociationFailed); - if (delegate) - { - delegate->OnAssociationFailureDetected(associationFailureCause, reason); - } - break; - case WLAN_FW_TX_AUTH_FRAME_ALLOCATE_FAIILURE: - case WLAN_FW_AUTHENTICATION_FAIILURE: - case WLAN_FW_AUTH_ALGO_FAIILURE: - case WLAN_FW_DEAUTH_BY_AP_WHEN_NOT_CONNECTION: - case WLAN_FW_DEAUTH_BY_AP_WHEN_CONNECTION: - case WLAN_FW_4WAY_HANDSHAKE_TX_DEAUTH_FRAME_TRANSMIT_FAILURE: - case WLAN_FW_4WAY_HANDSHAKE_TX_DEAUTH_FRAME_ALLOCATE_FAIILURE: - case WLAN_FW_AUTH_OR_ASSOC_RESPONSE_TIMEOUT_FAILURE: - case WLAN_FW_DISCONNECT_BY_USER_WITH_DEAUTH: - case WLAN_FW_DISCONNECT_BY_USER_NO_DEAUTH: - associationFailureCause = - chip::to_underlying(chip::app::Clusters::WiFiNetworkDiagnostics::AssociationFailureCauseEnum::kAuthenticationFailed); - if (delegate) - { - delegate->OnAssociationFailureDetected(associationFailureCause, reason); - } - break; - case WLAN_FW_SCAN_NO_BSSID_AND_CHANNEL: - associationFailureCause = - chip::to_underlying(chip::app::Clusters::WiFiNetworkDiagnostics::AssociationFailureCauseEnum::kSsidNotFound); - if (delegate) - { - delegate->OnAssociationFailureDetected(associationFailureCause, reason); - } - break; - case WLAN_FW_BEACON_LOSS: - case WLAN_FW_JOIN_NETWORK_SECURITY_NOMATCH: - case WLAN_FW_JOIN_NETWORK_WEPLEN_ERROR: - case WLAN_FW_DISCONNECT_BY_FW_PS_TX_NULLFRAME_FAILURE: - case WLAN_FW_CREATE_CHANNEL_CTX_FAILURE_WHEN_JOIN_NETWORK: - case WLAN_FW_ADD_STA_FAILURE: - case WLAN_FW_JOIN_NETWORK_FAILURE: - break; - - default: - if (delegate) - { - delegate->OnAssociationFailureDetected(associationFailureCause, reason); - } - break; - } - - if (delegate) - { - delegate->OnDisconnectionDetected(reason); - delegate->OnConnectionStatusChanged( - chip::to_underlying(chip::app::Clusters::WiFiNetworkDiagnostics::ConnectionStatusEnum::kNotConnected)); - } - - ConnectivityMgrImpl().ChangeWiFiStationState(ConnectivityManagerImpl::kWiFiStationState_Disconnecting); -} - -static void WifiStaConnected(void) -{ - char ap_ssid[64]; - WiFiDiagnosticsDelegate * delegate = GetDiagnosticDataProvider().GetWiFiDiagnosticsDelegate(); - - if (ConnectivityManagerImpl::mWiFiStationState == ConnectivityManager::kWiFiStationState_Connected) - { - return; - } - - memset(ap_ssid, 0, sizeof(ap_ssid)); - // wifi_mgmr_sta_ssid_get(ap_ssid); - // wifi_mgmr_ap_item_t * ap_info = mgmr_get_ap_info_handle(); - // wifi_mgmr_get_scan_result_filter(ap_info, ap_ssid); - - ConnectivityMgrImpl().ChangeWiFiStationState(ConnectivityManagerImpl::kWiFiStationState_Connected); - ConnectivityMgrImpl().WifiStationStateChange(); - ConnectivityMgrImpl().OnStationConnected(); - if (delegate) - { - delegate->OnConnectionStatusChanged( - chip::to_underlying(chip::app::Clusters::WiFiNetworkDiagnostics::ConnectionStatusEnum::kConnected)); - } -} typedef void (*aos_event_cb)(input_event_t * event, void * private_data); void OnWiFiPlatformEvent(input_event_t * event, void * private_data) @@ -187,9 +72,11 @@ void OnWiFiPlatformEvent(input_event_t * event, void * private_data) break; case CODE_WIFI_ON_DISCONNECT: { ChipLogProgress(DeviceLayer, "WiFi station disconnect, reason %s.", wifi_mgmr_status_code_str(event->value)); - chip::DeviceLayer::PlatformMgr().LockChipStack(); - WifiStaDisconect(); + if (ConnectivityManager::kWiFiStationState_Connecting == ConnectivityMgrImpl().GetWiFiStationState()) + { + ConnectivityMgrImpl().ChangeWiFiStationState(ConnectivityManager::kWiFiStationState_Connecting_Failed); + } chip::DeviceLayer::PlatformMgr().UnlockChipStack(); } break; @@ -198,19 +85,17 @@ void OnWiFiPlatformEvent(input_event_t * event, void * private_data) } break; case CODE_WIFI_ON_GOT_IP: { - ChipLogProgress(DeviceLayer, "WiFi station gets IPv4 address."); - chip::DeviceLayer::PlatformMgr().LockChipStack(); - WifiStaConnected(); + ConnectivityMgrImpl().ChangeWiFiStationState(ConnectivityManagerImpl::kWiFiStationState_Connected); + ConnectivityMgrImpl().OnConnectivityChanged(wifi_mgmr_sta_netif_get()); chip::DeviceLayer::PlatformMgr().UnlockChipStack(); } break; case CODE_WIFI_ON_GOT_IP6: { ChipLogProgress(DeviceLayer, "WiFi station gets IPv6 address."); - chip::DeviceLayer::PlatformMgr().LockChipStack(); - ConnectivityMgrImpl().OnIPv6AddressAvailable(); + ConnectivityMgrImpl().OnConnectivityChanged(wifi_mgmr_sta_netif_get()); chip::DeviceLayer::PlatformMgr().UnlockChipStack(); } break; @@ -223,26 +108,14 @@ void OnWiFiPlatformEvent(input_event_t * event, void * private_data) CHIP_ERROR PlatformManagerImpl::_InitChipStack(void) { - CHIP_ERROR err = CHIP_NO_ERROR; - static uint8_t stack_wifi_init = 0; + CHIP_ERROR err = CHIP_NO_ERROR; TaskHandle_t backup_eventLoopTask; - // Initialize the configuration system. - err = Internal::BLConfig::Init(); - SuccessOrExit(err); - // Initialize LwIP. tcpip_init(NULL, NULL); aos_register_event_filter(EV_WIFI, OnWiFiPlatformEvent, NULL); - if (1 == stack_wifi_init) - { - ChipLogError(DeviceLayer, "Wi-Fi already initialized!"); - return CHIP_NO_ERROR; - } - hal_wifi_start_firmware_task(); - stack_wifi_init = 1; aos_post_event(EV_WIFI, CODE_WIFI_ON_INIT_DONE, 0); err = chip::Crypto::add_entropy_source(app_entropy_source, NULL, 16); diff --git a/src/platform/bouffalolab/BL602/args.gni b/src/platform/bouffalolab/BL602/args.gni index dd482f9a0d6725..2f8964ad4a907c 100644 --- a/src/platform/bouffalolab/BL602/args.gni +++ b/src/platform/bouffalolab/BL602/args.gni @@ -22,6 +22,8 @@ mbedtls_target = "${bouffalolab_iot_sdk_build_root}/bl602:bl_iot_sdk" chip_device_platform = "bl602" +chip_enable_ota_requestor = true + lwip_platform = "bl602" chip_inet_config_enable_ipv4 = true diff --git a/src/platform/bouffalolab/BL602/wifi_mgmr_portable.c b/src/platform/bouffalolab/BL602/wifi_mgmr_portable.c index 04ee57fe66c4b7..47cac9e4e10018 100644 --- a/src/platform/bouffalolab/BL602/wifi_mgmr_portable.c +++ b/src/platform/bouffalolab/BL602/wifi_mgmr_portable.c @@ -144,3 +144,8 @@ bool wifi_mgmr_security_type_is_wpa3(void) return false; } + +struct netif * deviceInterface_getNetif(void) +{ + return wifi_mgmr_sta_netif_get(); +} diff --git a/src/platform/bouffalolab/BL602/wifi_mgmr_portable.h b/src/platform/bouffalolab/BL602/wifi_mgmr_portable.h index cf25c7ef730c14..aa855d23680613 100644 --- a/src/platform/bouffalolab/BL602/wifi_mgmr_portable.h +++ b/src/platform/bouffalolab/BL602/wifi_mgmr_portable.h @@ -16,6 +16,7 @@ bool wifi_mgmr_security_type_is_open(void); bool wifi_mgmr_security_type_is_wpa(void); bool wifi_mgmr_security_type_is_wpa2(void); bool wifi_mgmr_security_type_is_wpa3(void); +struct netif * deviceInterface_getNetif(void); #ifdef __cplusplus } diff --git a/src/platform/bouffalolab/BL702/BUILD.gn b/src/platform/bouffalolab/BL702/BUILD.gn index dd0279175bfd50..e32738e9a59530 100644 --- a/src/platform/bouffalolab/BL702/BUILD.gn +++ b/src/platform/bouffalolab/BL702/BUILD.gn @@ -18,6 +18,8 @@ import("//build_overrides/chip.gni") import("${chip_root}/src/platform/device.gni") assert(chip_device_platform == "bl702") +assert(false == (chip_enable_wifi && chip_enable_openthread), + "Not support Wi-Fi and Thread together") if (chip_enable_openthread) { import("//build_overrides/openthread.gni") @@ -82,6 +84,14 @@ static_library("BL702") { ] deps += [ "${chip_root}/src/lib/dnssd:platform_header" ] } + } else { + sources += [ + "ConfigurationManagerImpl.cpp", + "ConnectivityManagerImpl.cpp", + "EthernetInterface.c", + ] + + deps = [ "${chip_root}/src/lib/dnssd:platform_header" ] } public_deps = [ "${chip_root}/src/platform:platform_base" ] diff --git a/src/platform/bouffalolab/BL702/ConfigurationManagerImpl.cpp b/src/platform/bouffalolab/BL702/ConfigurationManagerImpl.cpp new file mode 100644 index 00000000000000..5a92ee10578fda --- /dev/null +++ b/src/platform/bouffalolab/BL702/ConfigurationManagerImpl.cpp @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2022 Project CHIP Authors + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#if !CHIP_DEVICE_CONFIG_ENABLE_THREAD & !CHIP_DEVICE_CONFIG_ENABLE_WIFI +extern "C" { +#include +} +#endif + +namespace chip { +namespace DeviceLayer { + +#if !CHIP_DEVICE_CONFIG_ENABLE_THREAD & !CHIP_DEVICE_CONFIG_ENABLE_WIFI +CHIP_ERROR ConfigurationManagerImpl::GetPrimaryMACAddress(MutableByteSpan buf) +{ + if (buf.size() != ConfigurationManager::kPrimaryMACAddressLength) + return CHIP_ERROR_INVALID_ARGUMENT; + + eth_get_mac(buf.data()); + + return CHIP_NO_ERROR; +} +#endif + +} // namespace DeviceLayer +} // namespace chip diff --git a/src/platform/bouffalolab/BL702/ConnectivityManagerImpl.cpp b/src/platform/bouffalolab/BL702/ConnectivityManagerImpl.cpp new file mode 100644 index 00000000000000..09e0550170ba1b --- /dev/null +++ b/src/platform/bouffalolab/BL702/ConnectivityManagerImpl.cpp @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2022 Project CHIP Authors + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include + +#include + +#if !CHIP_DEVICE_CONFIG_ENABLE_THREAD && !CHIP_DEVICE_CONFIG_ENABLE_WIFI +#include +#include +#endif + +using namespace ::chip; + +namespace chip { +namespace DeviceLayer { + +#if !CHIP_DEVICE_CONFIG_ENABLE_THREAD && !CHIP_DEVICE_CONFIG_ENABLE_WIFI +extern "C" void ethernetInterface_eventGotIP(struct netif * interface) +{ + ChipLogProgress(DeviceLayer, "ethernetInterface_eventGotIP"); + ConnectivityMgrImpl().OnConnectivityChanged(interface); +} +#endif + +} // namespace DeviceLayer +} // namespace chip diff --git a/src/platform/bouffalolab/BL702/DiagnosticDataProviderImpl.cpp b/src/platform/bouffalolab/BL702/DiagnosticDataProviderImpl.cpp index 62fe129c0a9685..cb067d31f357fc 100644 --- a/src/platform/bouffalolab/BL702/DiagnosticDataProviderImpl.cpp +++ b/src/platform/bouffalolab/BL702/DiagnosticDataProviderImpl.cpp @@ -15,13 +15,13 @@ * limitations under the License. */ -#include #include #include extern "C" { #include } + namespace chip { namespace DeviceLayer { @@ -52,34 +52,5 @@ CHIP_ERROR DiagnosticDataProviderImpl::GetBootReason(BootReasonType & bootReason return CHIP_NO_ERROR; } -CHIP_ERROR DiagnosticDataProviderImpl::GetNetworkInterfaces(NetworkInterface ** netifpp) -{ - NetworkInterface * ifp = new NetworkInterface(); - - const char * threadNetworkName = otThreadGetNetworkName(ThreadStackMgrImpl().OTInstance()); - ifp->name = Span(threadNetworkName, strlen(threadNetworkName)); - ifp->isOperational = true; - ifp->offPremiseServicesReachableIPv4.SetNull(); - ifp->offPremiseServicesReachableIPv6.SetNull(); - ifp->type = EMBER_ZCL_INTERFACE_TYPE_ENUM_THREAD; - uint8_t macBuffer[ConfigurationManager::kPrimaryMACAddressLength]; - ConfigurationMgr().GetPrimary802154MACAddress(macBuffer); - ifp->hardwareAddress = ByteSpan(macBuffer, ConfigurationManager::kPrimaryMACAddressLength); - - *netifpp = ifp; - - return CHIP_NO_ERROR; -} - -void DiagnosticDataProviderImpl::ReleaseNetworkInterfaces(NetworkInterface * netifp) -{ - while (netifp) - { - NetworkInterface * del = netifp; - netifp = netifp->Next; - delete del; - } -} - } // namespace DeviceLayer } // namespace chip diff --git a/src/platform/bouffalolab/BL702/EthernetInterface.c b/src/platform/bouffalolab/BL702/EthernetInterface.c new file mode 100644 index 00000000000000..469ffb79f64852 --- /dev/null +++ b/src/platform/bouffalolab/BL702/EthernetInterface.c @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2022 Project CHIP Authors + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include "EthernetInterface.h" +static struct dhcp6 dhcp6_val; + +extern int8_t bl_route_hook_init(void); + +static void netif_status_callback(struct netif * netif) +{ + if (netif->flags & NETIF_FLAG_UP) + { + for (uint32_t i = 0; i < LWIP_IPV6_NUM_ADDRESSES; i++) + { + if (!ip6_addr_isany(netif_ip6_addr(netif, i)) && ip6_addr_ispreferred(netif_ip6_addr_state(netif, i))) + { + + const ip6_addr_t * ip6addr = netif_ip6_addr(netif, i); + if (ip6_addr_isany(ip6addr) || ip6_addr_islinklocal(ip6addr)) + { + continue; + } + + ethernetInterface_eventGotIP(netif); + break; + } + } + } +} + +static int ethernet_callback(eth_link_state val) +{ + switch (val) + { + case ETH_INIT_STEP_LINKUP: + break; + case ETH_INIT_STEP_READY: + netifapi_netif_set_default(ð_mac); + netifapi_netif_set_up(ð_mac); + + // netifapi_netif_set_up((struct netif *)&obj->netif); + netif_create_ip6_linklocal_address(ð_mac, 1); + eth_mac.ip6_autoconfig_enabled = 1; + dhcp6_set_struct(ð_mac, &dhcp6_val); + dhcp6_enable_stateless(ð_mac); + + /* start dhcp */ + netifapi_dhcp_start(ð_mac); + break; + case ETH_INIT_STEP_LINKDOWN: + break; + } + + return 0; +} + +void ethernetInterface_init(void) +{ + netif_add(ð_mac, NULL, NULL, NULL, NULL, eth_init, ethernet_input); + + ethernet_init(ethernet_callback); + + /* Set callback to be called when interface is brought up/down or address is changed while up */ + netif_set_status_callback(ð_mac, netif_status_callback); + + bl_route_hook_init(); +} + +struct netif * deviceInterface_getNetif(void) +{ + return ð_mac; +} diff --git a/src/platform/bouffalolab/BL702/EthernetInterface.h b/src/platform/bouffalolab/BL702/EthernetInterface.h new file mode 100644 index 00000000000000..7809a5430f5c88 --- /dev/null +++ b/src/platform/bouffalolab/BL702/EthernetInterface.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2022 Project CHIP Authors + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +void ethernetInterface_init(void); +void ethernetInterface_eventGotIP(struct netif * interface); +struct netif * deviceInterface_getNetif(void); + +#ifdef __cplusplus +} +#endif diff --git a/src/platform/bouffalolab/BL702/PlatformManagerImpl.cpp b/src/platform/bouffalolab/BL702/PlatformManagerImpl.cpp index 51fe9632004b3e..9b5fea5a6e59cd 100644 --- a/src/platform/bouffalolab/BL702/PlatformManagerImpl.cpp +++ b/src/platform/bouffalolab/BL702/PlatformManagerImpl.cpp @@ -25,8 +25,13 @@ #include +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD #include #include +#else +#include +#endif + extern "C" { #include } @@ -51,26 +56,26 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack(void) { CHIP_ERROR err; TaskHandle_t backup_eventLoopTask; - otRadio_opt_t opt; - // Initialize the configuration system. - err = Internal::BLConfig::Init(); - SuccessOrExit(err); + // Initialize LwIP. + tcpip_init(NULL, NULL); +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD + otRadio_opt_t opt; opt.byte = 0; opt.bf.isCoexEnable = true; ot_alarmInit(); ot_radioInit(opt); +#else + ethernetInterface_init(); +#endif ReturnErrorOnFailure(System::Clock::InitClock_RealTime()); SetConfigurationMgr(&ConfigurationManagerImpl::GetDefaultInstance()); SetDiagnosticDataProvider(&DiagnosticDataProviderImpl::GetDefaultInstance()); - // Initialize LwIP. - tcpip_init(NULL, NULL); - err = chip::Crypto::add_entropy_source(app_entropy_source, NULL, 16); SuccessOrExit(err); diff --git a/src/platform/bouffalolab/BL702/args.gni b/src/platform/bouffalolab/BL702/args.gni index 47a03c6f7bd268..4a3494612104ac 100644 --- a/src/platform/bouffalolab/BL702/args.gni +++ b/src/platform/bouffalolab/BL702/args.gni @@ -20,6 +20,10 @@ import("${chip_root}/examples/platform/bouffalolab/bl702/args.gni") chip_device_platform = "bl702" +chip_enable_ota_requestor = true + +lwip_platform = "bl702" + riscv_platform_config = "${bouffalolab_iot_sdk_build_root}/common/rsicv.gni" mbedtls_target = "${bouffalolab_iot_sdk_build_root}/bl702:bl_iot_sdk" diff --git a/src/platform/bouffalolab/BL702/lwip_default_hooks.h b/src/platform/bouffalolab/BL702/lwip_default_hooks.h new file mode 100644 index 00000000000000..3c1d1d186c8836 --- /dev/null +++ b/src/platform/bouffalolab/BL702/lwip_default_hooks.h @@ -0,0 +1,17 @@ +#ifndef _LWIP_DEFAULT_HOOKS_H_ +#define _LWIP_DEFAULT_HOOKS_H_ +#include "lwip/arch.h" +#include "lwip/err.h" +#include "lwip/ip_addr.h" + +#ifdef CONFIG_LWIP_HOOK_IP6_ROUTE_DEFAULT +extern struct netif * lwip_hook_ip6_route(const ip6_addr_t * src, const ip6_addr_t * dest); +#define LWIP_HOOK_IP6_ROUTE lwip_hook_ip6_route +#endif + +#ifdef CONFIG_LWIP_HOOK_ND6_GET_GW_DEFAULT +extern const ip6_addr_t * lwip_hook_nd6_get_gw(struct netif * netif, const ip6_addr_t * dest); +#define LWIP_HOOK_ND6_GET_GW lwip_hook_nd6_get_gw +#endif + +#endif /* _LWIP_DEFAULT_HOOKS_H_ */ diff --git a/src/platform/bouffalolab/BL702L/DiagnosticDataProviderImpl.cpp b/src/platform/bouffalolab/BL702L/DiagnosticDataProviderImpl.cpp index c23abe0b572ee8..fcd805ebfccf65 100644 --- a/src/platform/bouffalolab/BL702L/DiagnosticDataProviderImpl.cpp +++ b/src/platform/bouffalolab/BL702L/DiagnosticDataProviderImpl.cpp @@ -24,6 +24,10 @@ #include "FreeRTOS.h" #include +extern "C" { +#include +} + using namespace ::chip::app::Clusters::GeneralDiagnostics; namespace chip { @@ -31,63 +35,29 @@ namespace DeviceLayer { CHIP_ERROR DiagnosticDataProviderImpl::GetBootReason(BootReasonType & bootReason) { - // BL_RST_REASON_E bootCause = bl_sys_rstinfo_get(); - - // if (BL_RST_POR == bootCause) - // { - // bootReason = BootReasonType::kPowerOnReboot; - // } - // else if (BL_RST_BOR == bootCause) - // { - // bootReason = BootReasonType::kBrownOutReset; - // } - // else if (BL_RST_WDT == bootCause) - // { - // bootReason = BootReasonType::kHardwareWatchdogReset; - // } - // else if (BL_RST_SOFTWARE == bootCause) - // { - // bootReason = BootReasonType::kSoftwareReset; - // } - // else - // { - // bootReason = BootReasonType::kUnspecified; - // } - return CHIP_NO_ERROR; -} - -CHIP_ERROR DiagnosticDataProviderImpl::GetNetworkInterfaces(NetworkInterface ** netifpp) -{ - NetworkInterface * ifp = new NetworkInterface(); - -#if CHIP_DEVICE_CONFIG_ENABLE_THREAD - - const char * threadNetworkName = otThreadGetNetworkName(ThreadStackMgrImpl().OTInstance()); - ifp->name = Span(threadNetworkName, strlen(threadNetworkName)); - ifp->isOperational = true; - ifp->offPremiseServicesReachableIPv4.SetNull(); - ifp->offPremiseServicesReachableIPv6.SetNull(); - ifp->type = InterfaceTypeEnum::EMBER_ZCL_INTERFACE_TYPE_ENUM_THREAD; - uint8_t macBuffer[ConfigurationManager::kPrimaryMACAddressLength]; - ConfigurationMgr().GetPrimary802154MACAddress(macBuffer); - ifp->hardwareAddress = ByteSpan(macBuffer, ConfigurationManager::kPrimaryMACAddressLength); + BL_RST_REASON_E bootCause = bl_sys_rstinfo_get(); -#else - /* TODO */ -#endif - - *netifpp = ifp; - return CHIP_NO_ERROR; -} - -void DiagnosticDataProviderImpl::ReleaseNetworkInterfaces(NetworkInterface * netifp) -{ - while (netifp) + if (BL_RST_POR == bootCause) + { + bootReason = BootReasonType::kPowerOnReboot; + } + else if (BL_RST_BOR == bootCause) + { + bootReason = BootReasonType::kBrownOutReset; + } + else if (BL_RST_WDT == bootCause) { - NetworkInterface * del = netifp; - netifp = netifp->Next; - delete del; + bootReason = BootReasonType::kHardwareWatchdogReset; } + else if (BL_RST_SOFTWARE == bootCause) + { + bootReason = BootReasonType::kSoftwareReset; + } + else + { + bootReason = BootReasonType::kUnspecified; + } + return CHIP_NO_ERROR; } } // namespace DeviceLayer diff --git a/src/platform/bouffalolab/BL702L/PlatformManagerImpl.cpp b/src/platform/bouffalolab/BL702L/PlatformManagerImpl.cpp index fa882020058a87..798e0c1413e220 100644 --- a/src/platform/bouffalolab/BL702L/PlatformManagerImpl.cpp +++ b/src/platform/bouffalolab/BL702L/PlatformManagerImpl.cpp @@ -55,10 +55,6 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack(void) CHIP_ERROR err; TaskHandle_t backup_eventLoopTask; - // Initialize the configuration system. - err = Internal::BLConfig::Init(); - SuccessOrExit(err); - otRadio_opt_t opt; opt.byte = 0; diff --git a/src/platform/bouffalolab/BL702L/ThreadStackManagerImpl.cpp b/src/platform/bouffalolab/BL702L/ThreadStackManagerImpl.cpp index 7b9b879c216857..1b1ebf197e006f 100644 --- a/src/platform/bouffalolab/BL702L/ThreadStackManagerImpl.cpp +++ b/src/platform/bouffalolab/BL702L/ThreadStackManagerImpl.cpp @@ -25,8 +25,6 @@ #include -#include - #include #include diff --git a/src/platform/bouffalolab/BL702L/args.gni b/src/platform/bouffalolab/BL702L/args.gni index 07903ca87c5735..58c45b87113ff5 100644 --- a/src/platform/bouffalolab/BL702L/args.gni +++ b/src/platform/bouffalolab/BL702L/args.gni @@ -20,6 +20,10 @@ import("${chip_root}/examples/platform/bouffalolab/bl702l/args.gni") chip_device_platform = "bl702l" +chip_enable_ota_requestor = true + +lwip_platform = "bl702l" + riscv_platform_config = "${bouffalolab_iot_sdk_build_root}/common/rsicv.gni" mbedtls_target = "${bouffalolab_iot_sdk_build_root}/bl702l:bl_iot_sdk" diff --git a/src/platform/bouffalolab/common/BLConfig.cpp b/src/platform/bouffalolab/common/BLConfig.cpp index b8144dd1c23025..de1cc24d139508 100644 --- a/src/platform/bouffalolab/common/BLConfig.cpp +++ b/src/platform/bouffalolab/common/BLConfig.cpp @@ -15,27 +15,15 @@ * limitations under the License. */ +#include #include #include -#include -#include -#include -#include -#include - -#include - namespace chip { namespace DeviceLayer { namespace Internal { -CHIP_ERROR BLConfig::Init() -{ - return CHIP_NO_ERROR; -} - CHIP_ERROR BLConfig::ReadConfigValue(const char * key, uint8_t * val, size_t size, size_t & readsize) { env_node_obj node; diff --git a/src/platform/bouffalolab/common/BLConfig.h b/src/platform/bouffalolab/common/BLConfig.h index 916e849bdbc8fb..1bd80117119a46 100644 --- a/src/platform/bouffalolab/common/BLConfig.h +++ b/src/platform/bouffalolab/common/BLConfig.h @@ -17,10 +17,6 @@ #pragma once -#include - -#include - namespace chip { namespace DeviceLayer { namespace Internal { @@ -80,8 +76,6 @@ class BLConfig static constexpr const char * kCounterKey_TotalOperationalHours = ("total-hours"); static constexpr const char * kCounterKey_UpTime = ("up-time"); - static CHIP_ERROR Init(void); - // Config value accessors. static CHIP_ERROR ReadConfigValue(const char * key, uint8_t * val, size_t size, size_t & readsize); static CHIP_ERROR ReadConfigValue(const char * key, bool & val); diff --git a/src/platform/bouffalolab/common/BLEManagerImpl.cpp b/src/platform/bouffalolab/common/BLEManagerImpl.cpp index 47cfbd8938ade7..73a6f8ff466650 100644 --- a/src/platform/bouffalolab/common/BLEManagerImpl.cpp +++ b/src/platform/bouffalolab/common/BLEManagerImpl.cpp @@ -20,12 +20,8 @@ #if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE -#include "BLEManagerImpl.h" - #include #include -#include -#include #include #include #if CHIP_ENABLE_ADDITIONAL_DATA_ADVERTISING @@ -43,6 +39,8 @@ extern "C" { #include #include +#include "BLEManagerImpl.h" + using namespace ::chip; using namespace ::chip::Ble; using namespace ::chip::System; diff --git a/src/platform/bouffalolab/common/BLEManagerImpl.h b/src/platform/bouffalolab/common/BLEManagerImpl.h index 394da27670056e..1589d88006a19d 100644 --- a/src/platform/bouffalolab/common/BLEManagerImpl.h +++ b/src/platform/bouffalolab/common/BLEManagerImpl.h @@ -23,8 +23,6 @@ #include #include -#include - namespace chip { namespace DeviceLayer { namespace Internal { diff --git a/src/platform/bouffalolab/common/CHIPDevicePlatformConfig.h b/src/platform/bouffalolab/common/CHIPDevicePlatformConfig.h index 698c9419620374..ded512cf0e86a0 100644 --- a/src/platform/bouffalolab/common/CHIPDevicePlatformConfig.h +++ b/src/platform/bouffalolab/common/CHIPDevicePlatformConfig.h @@ -42,4 +42,4 @@ #define CHIP_DEVICE_CONFIG_ENABLE_THREAD_TELEMETRY_FULL 0 #define CHIP_DEVICE_CONFIG_CHIP_TASK_STACK_SIZE (8 * 1024) -#define CHIP_DEVICE_CONFIG_MAX_EVENT_QUEUE_SIZE 25 +#define CHIP_DEVICE_CONFIG_MAX_EVENT_QUEUE_SIZE 50 diff --git a/src/platform/bouffalolab/common/CHIPPlatformConfig.h b/src/platform/bouffalolab/common/CHIPPlatformConfig.h index fce5146e2c4a89..3cb267bdcb6b1e 100644 --- a/src/platform/bouffalolab/common/CHIPPlatformConfig.h +++ b/src/platform/bouffalolab/common/CHIPPlatformConfig.h @@ -90,12 +90,3 @@ #ifndef CHIP_CONFIG_DEBUG_CERT_VALIDATION #define CHIP_CONFIG_DEBUG_CERT_VALIDATION 0 #endif // CHIP_CONFIG_DEBUG_CERT_VALIDATION - -// ==================== FreeRTOS Configuration Overrides ==================== -#ifndef CHIP_CONFIG_FREERTOS_USE_STATIC_TASK -#define CHIP_CONFIG_FREERTOS_USE_STATIC_TASK 1 -#endif - -#ifndef CHIP_CONFIG_FREERTOS_USE_STATIC_QUEUE -#define CHIP_CONFIG_FREERTOS_USE_STATIC_QUEUE 1 -#endif diff --git a/src/platform/bouffalolab/common/ConfigurationManagerImpl.cpp b/src/platform/bouffalolab/common/ConfigurationManagerImpl.cpp index 4618e7f72f7274..d4c06dc2d3868e 100644 --- a/src/platform/bouffalolab/common/ConfigurationManagerImpl.cpp +++ b/src/platform/bouffalolab/common/ConfigurationManagerImpl.cpp @@ -21,12 +21,6 @@ #include -#include -#include - -#include -#include - extern "C" { #include } diff --git a/src/platform/bouffalolab/common/ConfigurationManagerImpl.h b/src/platform/bouffalolab/common/ConfigurationManagerImpl.h index 0427551a341968..b9d207fc1ec9d2 100644 --- a/src/platform/bouffalolab/common/ConfigurationManagerImpl.h +++ b/src/platform/bouffalolab/common/ConfigurationManagerImpl.h @@ -64,6 +64,10 @@ class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImp CHIP_ERROR GetPrimaryWiFiMACAddress(uint8_t * buf) override; #endif +#if !CHIP_DEVICE_CONFIG_ENABLE_WIFI && !CHIP_DEVICE_CONFIG_ENABLE_THREAD + CHIP_ERROR GetPrimaryMACAddress(MutableByteSpan buf) override; +#endif + static void DoFactoryReset(intptr_t arg); }; diff --git a/src/platform/bouffalolab/common/ConnectivityManagerImpl.cpp b/src/platform/bouffalolab/common/ConnectivityManagerImpl.cpp index f1a47e5a68de06..4115f56059480d 100644 --- a/src/platform/bouffalolab/common/ConnectivityManagerImpl.cpp +++ b/src/platform/bouffalolab/common/ConnectivityManagerImpl.cpp @@ -20,6 +20,9 @@ #include #include #include +#include +#include +#include #include #include @@ -33,9 +36,13 @@ #ifdef BL602 #include #endif +#ifdef BL702 +#include +#endif #endif #if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE +#include #include #endif @@ -62,10 +69,8 @@ CHIP_ERROR ConnectivityManagerImpl::_Init() #endif #if CHIP_DEVICE_CONFIG_ENABLE_WIFI - CHIP_ERROR err = SetWiFiStationMode(kWiFiStationMode_Enabled); - NetworkCommissioning::BLWiFiDriver::GetInstance().ReConnectWiFiNetwork(); - - ReturnErrorOnFailure(err); + mWiFiStationState = ConnectivityManager::kWiFiStationState_NotConnected; + ReturnErrorOnFailure(SetWiFiStationMode(kWiFiStationMode_Enabled)); #endif return CHIP_NO_ERROR; @@ -79,5 +84,258 @@ void ConnectivityManagerImpl::_OnPlatformEvent(const ChipDeviceEvent * event) #endif } +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI +bool ConnectivityManagerImpl::_IsWiFiStationEnabled(void) +{ + return GetWiFiStationMode() == kWiFiStationMode_Enabled; +} + +bool ConnectivityManagerImpl::_IsWiFiStationProvisioned(void) +{ + CHIP_ERROR err = CHIP_NO_ERROR; + char ssid[64] = { 0 }; + char psk[64] = { 0 }; + size_t ssidLen = 0; + size_t pskLen = 0; + + err = PersistedStorage::KeyValueStoreMgr().Get(BLConfig::kBLConfigKey_wifissid, (void *) ssid, 64, &ssidLen, 0); + SuccessOrExit(err); + + err = PersistedStorage::KeyValueStoreMgr().Get(BLConfig::kBLConfigKey_wifipassword, (void *) psk, 64, &pskLen, 0); + SuccessOrExit(err); + + return (ssidLen != 0); +exit: + return false; +} + +CHIP_ERROR ConnectivityManagerImpl::_SetWiFiStationMode(WiFiStationMode val) +{ + CHIP_ERROR err = CHIP_NO_ERROR; + + VerifyOrExit(val != kWiFiStationMode_NotSupported, err = CHIP_ERROR_INVALID_ARGUMENT); + + if (val != kWiFiStationMode_ApplicationControlled) + { + DeviceLayer::SystemLayer().ScheduleWork(DriveStationState, NULL); + } + + if (mWiFiStationMode != val) + { + ChipLogProgress(DeviceLayer, "WiFi station mode change: %s -> %s", WiFiStationModeToStr(mWiFiStationMode), + WiFiStationModeToStr(val)); + } + + mWiFiStationMode = val; + +exit: + return err; +} + +void ConnectivityManagerImpl::ChangeWiFiStationState(WiFiStationState newState) +{ + if (mWiFiStationState != newState) + { + ChipLogProgress(DeviceLayer, "WiFi station state change: %s -> %s", WiFiStationStateToStr(mWiFiStationState), + WiFiStationStateToStr(newState)); + mWiFiStationState = newState; + ConnectivityMgrImpl().DriveStationState(); + SystemLayer().ScheduleLambda([]() { NetworkCommissioning::BLWiFiDriver::GetInstance().OnNetworkStatusChange(); }); + } +} + +void ConnectivityManagerImpl::_ClearWiFiStationProvision(void) +{ + CHIP_ERROR err = CHIP_NO_ERROR; + + err = PersistedStorage::KeyValueStoreMgr().Delete(BLConfig::kBLConfigKey_wifissid); + SuccessOrExit(err); + + err = PersistedStorage::KeyValueStoreMgr().Delete(BLConfig::kBLConfigKey_wifipassword); + SuccessOrExit(err); + +exit: + return; +} + +void ConnectivityManagerImpl::_OnWiFiStationProvisionChange(void) +{ + DeviceLayer::SystemLayer().ScheduleWork(DriveStationState, NULL); +} + +CHIP_ERROR ConnectivityManagerImpl::ConnectProvisionedWiFiNetwork(void) +{ + char ssid[64] = { 0 }; + char psk[64] = { 0 }; + size_t ssidLen = 0; + size_t pskLen = 0; + + ReturnErrorOnFailure(PersistedStorage::KeyValueStoreMgr().Get(BLConfig::kBLConfigKey_wifissid, (void *) ssid, 64, &ssidLen, 0)); + ReturnErrorOnFailure( + PersistedStorage::KeyValueStoreMgr().Get(BLConfig::kBLConfigKey_wifipassword, (void *) psk, 64, &pskLen, 0)); + + NetworkCommissioning::BLWiFiDriver::GetInstance().ConnectWiFiNetwork(ssid, ssidLen, psk, pskLen); + + return CHIP_NO_ERROR; +} + +void ConnectivityManagerImpl::OnWiFiStationConnected() +{ + ChipDeviceEvent event; + event.Type = DeviceEventType::kWiFiConnectivityChange; + event.WiFiConnectivityChange.Result = kConnectivity_Established; + PlatformMgr().PostEventOrDie(&event); + + WiFiDiagnosticsDelegate * delegate = GetDiagnosticDataProvider().GetWiFiDiagnosticsDelegate(); + if (delegate) + { + delegate->OnConnectionStatusChanged( + chip::to_underlying(chip::app::Clusters::WiFiNetworkDiagnostics::ConnectionStatusEnum::kConnected)); + } +} + +void ConnectivityManagerImpl::DriveStationState() +{ + ChipLogProgress(DeviceLayer, "DriveStationState: mWiFiStationState=%s", WiFiStationStateToStr(mWiFiStationState)); + switch (mWiFiStationState) + { + case ConnectivityManager::kWiFiStationState_NotConnected: { + if (GetWiFiStationMode() == ConnectivityManager::kWiFiStationMode_Enabled && IsWiFiStationProvisioned()) + { + ConnectProvisionedWiFiNetwork(); + } + } + break; + case ConnectivityManager::kWiFiStationState_Connecting: { + ChipLogProgress(DeviceLayer, "Wi-Fi station is connecting to AP"); + } + break; + case ConnectivityManager::kWiFiStationState_Connecting_Succeeded: { + ChipLogProgress(DeviceLayer, "Wi-Fi station successfully connects to AP"); + mConnectivityFlag.ClearAll(); + mConnectivityFlag.Set(ConnectivityFlags::kAwaitingConnectivity); + } + break; + case ConnectivityManager::kWiFiStationState_Connecting_Failed: { + ChipLogProgress(DeviceLayer, "Wi-Fi station connecting failed"); + mConnectivityFlag.ClearAll(); + OnWiFiStationDisconnected(); + if (ConnectivityManager::kWiFiStationState_Connecting == mWiFiStationState) + { + SystemLayer().ScheduleLambda([]() { NetworkCommissioning::BLWiFiDriver::GetInstance().OnConnectWiFiNetwork(false); }); + } + } + break; + case ConnectivityManager::kWiFiStationState_Connected: { + ChipLogProgress(DeviceLayer, "Wi-Fi stattion connected."); + OnWiFiStationConnected(); + SystemLayer().ScheduleLambda([]() { NetworkCommissioning::BLWiFiDriver::GetInstance().OnConnectWiFiNetwork(true); }); + } + break; + case ConnectivityManager::kWiFiStationState_Disconnecting: { + ChipLogProgress(DeviceLayer, "Wi-Fi station is disconnecting to AP"); + mConnectivityFlag.ClearAll(); + } + break; + default: + break; + } +} + +void ConnectivityManagerImpl::DriveStationState(::chip::System::Layer * aLayer, void * aAppState) +{ + ConnectivityMgrImpl().DriveStationState(); +} +#endif + +#if !CHIP_DEVICE_CONFIG_ENABLE_THREAD +void ConnectivityManagerImpl::OnConnectivityChanged(struct netif * interface) +{ + bool haveIPv4Conn = false; + bool haveIPv6Conn = false; + const bool hadIPv4Conn = mConnectivityFlag.Has(ConnectivityFlags::kHaveIPv4InternetConnectivity); + const bool hadIPv6Conn = mConnectivityFlag.Has(ConnectivityFlags::kHaveIPv6InternetConnectivity); + IPAddress addr; + + if (interface != NULL && netif_is_up(interface) && netif_is_link_up(interface)) + { + mConnectivityFlag.Clear(ConnectivityFlags::kAwaitingConnectivity); + + if (!ip4_addr_isany(netif_ip4_addr(interface)) && !ip4_addr_isany(netif_ip4_gw(interface))) + { + haveIPv4Conn = true; + char addrStr[INET_ADDRSTRLEN]; + ip4addr_ntoa_r(netif_ip4_addr(interface), addrStr, sizeof(addrStr)); + IPAddress::FromString(addrStr, addr); + if (0 != memcmp(netif_ip4_addr(interface), &m_ip4addr, sizeof(ip4_addr_t))) + { + ChipLogProgress(DeviceLayer, "IPv4 Address Assigned, %s", ip4addr_ntoa(netif_ip4_addr(interface))); + memcpy(&m_ip4addr, netif_ip4_addr(interface), sizeof(ip4_addr_t)); + ConnectivityMgrImpl().OnIPv4AddressAvailable(); + } + } + + // Search among the IPv6 addresses assigned to the interface for a Global Unicast + // address (2000::/3) that is in the valid state. If such an address is found... + for (uint32_t i = 0; i < LWIP_IPV6_NUM_ADDRESSES; i++) + { + if (!ip6_addr_islinklocal(netif_ip6_addr(interface, i)) && ip6_addr_isvalid(netif_ip6_addr_state(interface, i))) + { + haveIPv6Conn = true; + if (0 != memcmp(netif_ip6_addr(interface, i), m_ip6addr + i, sizeof(ip6_addr_t))) + { + ChipLogProgress(DeviceLayer, "IPv6 Address Assigned, %s", ip6addr_ntoa(netif_ip6_addr(interface, i))); + memcpy(m_ip6addr + i, netif_ip6_addr(interface, i), sizeof(ip6_addr_t)); + ConnectivityMgrImpl().OnIPv6AddressAvailable(); + } + } + } + } + + // If the internet connectivity state has changed... + if (haveIPv4Conn != hadIPv4Conn || haveIPv6Conn != hadIPv6Conn) + { + // Update the current state. + mConnectivityFlag.Set(ConnectivityFlags::kHaveIPv4InternetConnectivity, haveIPv4Conn); + mConnectivityFlag.Set(ConnectivityFlags::kHaveIPv6InternetConnectivity, haveIPv6Conn); + + // Alert other components of the state change. + ChipDeviceEvent event; + event.Type = DeviceEventType::kInternetConnectivityChange; + event.InternetConnectivityChange.IPv4 = GetConnectivityChange(hadIPv4Conn, haveIPv4Conn); + event.InternetConnectivityChange.IPv6 = GetConnectivityChange(hadIPv6Conn, haveIPv6Conn); + event.InternetConnectivityChange.ipAddress = addr; + PlatformMgr().PostEventOrDie(&event); + + if (haveIPv4Conn != hadIPv4Conn) + { + ChipLogProgress(DeviceLayer, "%s Internet connectivity %s", "IPv4", (haveIPv4Conn) ? "ESTABLISHED" : "LOST"); + } + + if (haveIPv6Conn != hadIPv6Conn) + { + ChipLogProgress(DeviceLayer, "%s Internet connectivity %s", "IPv6", (haveIPv6Conn) ? "ESTABLISHED" : "LOST"); + } + } +} + +void ConnectivityManagerImpl::OnIPv4AddressAvailable() +{ + ChipDeviceEvent event; + event.Type = DeviceEventType::kInterfaceIpAddressChanged; + event.InterfaceIpAddressChanged.Type = InterfaceIpChangeType::kIpV4_Assigned; + PlatformMgr().PostEventOrDie(&event); +} + +void ConnectivityManagerImpl::OnIPv6AddressAvailable() +{ + ChipDeviceEvent event; + event.Type = DeviceEventType::kInterfaceIpAddressChanged; + event.InterfaceIpAddressChanged.Type = InterfaceIpChangeType::kIpV6_Assigned; + PlatformMgr().PostEventOrDie(&event); +} + +#endif + } // namespace DeviceLayer } // namespace chip diff --git a/src/platform/bouffalolab/common/ConnectivityManagerImpl.h b/src/platform/bouffalolab/common/ConnectivityManagerImpl.h index 8c06c585fb806f..0011a8b0fc1467 100644 --- a/src/platform/bouffalolab/common/ConnectivityManagerImpl.h +++ b/src/platform/bouffalolab/common/ConnectivityManagerImpl.h @@ -67,26 +67,52 @@ class ConnectivityManagerImpl final : public ConnectivityManager, // Allow the ConnectivityManager interface class to delegate method calls to // the implementation methods provided by this class. friend class ConnectivityManager; + friend void netif_status_callback(struct netif * netif); -#if CHIP_DEVICE_CONFIG_ENABLE_WIFI public: - static WiFiStationState mWiFiStationState; - +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI bool _IsWiFiStationConnected(void); - void WifiStationStateChange(void); - void OnStationConnected(void); + WiFiStationState GetWiFiStationState(void); void ChangeWiFiStationState(WiFiStationState newState); + void OnWiFiStationStateChanged(void); + void OnWiFiStationConnected(void); + void OnWiFiStationDisconnected(void); +#endif + +#if !CHIP_DEVICE_CONFIG_ENABLE_THREAD + void OnConnectivityChanged(struct netif * interface); + void OnIPv4AddressAvailable(); void OnIPv6AddressAvailable(); #endif private: // ===== Members that implement the ConnectivityManager abstract interface. #if CHIP_DEVICE_CONFIG_ENABLE_WIFI + WiFiStationMode mWiFiStationMode; + WiFiStationState mWiFiStationState; + + BitFlags mConnectivityFlag; + bool _IsWiFiStationEnabled(void); - // bool _IsWiFiStationProvisioned(void); + ConnectivityManager::WiFiStationMode _GetWiFiStationMode(); CHIP_ERROR _SetWiFiStationMode(WiFiStationMode val); - void GetWifiState(void); - WiFiStationState GetWiFiStationState(void); + bool _IsWiFiStationProvisioned(void); + void _ClearWiFiStationProvision(); + void _OnWiFiStationProvisionChange(); + CHIP_ERROR ConnectProvisionedWiFiNetwork(); +#elif !CHIP_DEVICE_CONFIG_ENABLE_THREAD + enum class ConnectivityFlags : uint16_t + { + kHaveIPv4InternetConnectivity = 0x0001, + kHaveIPv6InternetConnectivity = 0x0002, + kAwaitingConnectivity = 0x0010, + }; + BitFlags mConnectivityFlag; +#endif + +#if !CHIP_DEVICE_CONFIG_ENABLE_THREAD + ip4_addr_t m_ip4addr; + ip6_addr_t m_ip6addr[LWIP_IPV6_NUM_ADDRESSES]; #endif void DriveStationState(void); @@ -95,7 +121,6 @@ class ConnectivityManagerImpl final : public ConnectivityManager, void _OnPlatformEvent(const ChipDeviceEvent * event); // ===== Members for internal use by the following friends. - friend ConnectivityManager & ConnectivityMgr(void); friend ConnectivityManagerImpl & ConnectivityMgrImpl(void); @@ -112,6 +137,11 @@ inline bool ConnectivityManagerImpl::_IsWiFiStationConnected(void) { return mWiFiStationState == kWiFiStationState_Connected; } + +inline ConnectivityManager::WiFiStationMode ConnectivityManagerImpl::_GetWiFiStationMode(void) +{ + return kWiFiStationMode_Enabled; +} #endif /** diff --git a/src/platform/bouffalolab/common/DiagnosticDataProviderImpl.cpp b/src/platform/bouffalolab/common/DiagnosticDataProviderImpl.cpp index 6e11e6f91d261e..8ad878a2474dec 100644 --- a/src/platform/bouffalolab/common/DiagnosticDataProviderImpl.cpp +++ b/src/platform/bouffalolab/common/DiagnosticDataProviderImpl.cpp @@ -31,6 +31,7 @@ extern "C" size_t get_heap_size(void); #ifdef CFG_USE_PSRAM extern "C" size_t get_heap3_size(void); #endif +extern "C" struct netif * deviceInterface_getNetif(void); DiagnosticDataProviderImpl & DiagnosticDataProviderImpl::GetDefaultInstance() { @@ -208,6 +209,69 @@ CHIP_ERROR DiagnosticDataProviderImpl::GetActiveNetworkFaults(GeneralFaultsname = Span(threadNetworkName, strlen(threadNetworkName)); + ifp->isOperational = true; + ifp->offPremiseServicesReachableIPv4.SetNull(); + ifp->offPremiseServicesReachableIPv6.SetNull(); + ifp->type = EMBER_ZCL_INTERFACE_TYPE_ENUM_THREAD; + uint8_t macBuffer[ConfigurationManager::kPrimaryMACAddressLength]; + ConfigurationMgr().GetPrimary802154MACAddress(macBuffer); + ifp->hardwareAddress = ByteSpan(macBuffer, ConfigurationManager::kPrimaryMACAddressLength); +#else + + struct netif * netif = deviceInterface_getNetif(); + + Platform::CopyString(ifp->Name, netif->name); + ifp->name = CharSpan::fromCharString(ifp->Name); + ifp->isOperational = true; +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI + ifp->type = EMBER_ZCL_INTERFACE_TYPE_ENUM_WI_FI; +#else + ifp->type = EMBER_ZCL_INTERFACE_TYPE_ENUM_ETHERNET; +#endif + ifp->offPremiseServicesReachableIPv4.SetNull(); + ifp->offPremiseServicesReachableIPv6.SetNull(); + + memcpy(ifp->MacAddress, netif->hwaddr, sizeof(netif->hwaddr)); + ifp->hardwareAddress = ByteSpan(ifp->MacAddress, sizeof(netif->hwaddr)); + + memcpy(ifp->Ipv4AddressesBuffer[0], netif_ip_addr4(netif), kMaxIPv4AddrSize); + ifp->Ipv4AddressSpans[0] = ByteSpan(ifp->Ipv4AddressesBuffer[0], kMaxIPv4AddrSize); + ifp->IPv4Addresses = chip::app::DataModel::List(ifp->Ipv4AddressSpans, 1); + + int addr_count = 0; + for (size_t i = 0; (i < LWIP_IPV6_NUM_ADDRESSES) && (i < kMaxIPv6AddrCount); i++) + { + if (!ip6_addr_isany(&(netif->ip6_addr[i].u_addr.ip6))) + { + memcpy(ifp->Ipv6AddressesBuffer[addr_count], &(netif->ip6_addr[i].u_addr.ip6), sizeof(ip6_addr_t)); + ifp->Ipv6AddressSpans[addr_count] = ByteSpan(ifp->Ipv6AddressesBuffer[addr_count], kMaxIPv6AddrSize); + } + } + ifp->IPv6Addresses = chip::app::DataModel::List(ifp->Ipv6AddressSpans, addr_count); +#endif + + *netifpp = ifp; + + return CHIP_NO_ERROR; +} + +void DiagnosticDataProviderImpl::ReleaseNetworkInterfaces(NetworkInterface * netifp) +{ + while (netifp) + { + NetworkInterface * del = netifp; + netifp = netifp->Next; + delete del; + } +} + DiagnosticDataProvider & GetDiagnosticDataProviderImpl() { return DiagnosticDataProviderImpl::GetDefaultInstance(); diff --git a/src/platform/bouffalolab/common/SystemPlatformConfig.h b/src/platform/bouffalolab/common/SystemPlatformConfig.h index 2fb7579c677dd5..4912f404626de3 100644 --- a/src/platform/bouffalolab/common/SystemPlatformConfig.h +++ b/src/platform/bouffalolab/common/SystemPlatformConfig.h @@ -26,5 +26,6 @@ struct ChipDeviceEvent; } // namespace chip // ==================== Platform Adaptations ==================== +#define CHIP_SYSTEM_CONFIG_PLATFORM_PROVIDES_EVENT_FUNCTIONS 1 #define CHIP_SYSTEM_CONFIG_PLATFORM_PROVIDES_TIME 1 #define CHIP_SYSTEM_CONFIG_EVENT_OBJECT_TYPE const struct ::chip::DeviceLayer::ChipDeviceEvent * diff --git a/src/platform/device.gni b/src/platform/device.gni index d7406635d178dc..ecf01173dbeb05 100644 --- a/src/platform/device.gni +++ b/src/platform/device.gni @@ -111,11 +111,12 @@ declare_args() { } } -if ((chip_device_platform == "bl702" || chip_device_platform == "bl702l") && - chip_enable_openthread) { - chip_mdns = "platform" -} else if (chip_device_platform == "bl702" && chip_enable_wifi) { - chip_mdns = "minimal" +if (chip_device_platform == "bl702" || chip_device_platform == "bl702l") { + if (chip_enable_openthread) { + chip_mdns = "platform" + } else { + chip_mdns = "minimal" + } } _chip_device_layer = "none" diff --git a/third_party/bouffalolab/bl702/bl_iot_sdk.gni b/third_party/bouffalolab/bl702/bl_iot_sdk.gni index 8b69f1b2941cc4..5c35e8c1df9029 100644 --- a/third_party/bouffalolab/bl702/bl_iot_sdk.gni +++ b/third_party/bouffalolab/bl702/bl_iot_sdk.gni @@ -20,8 +20,6 @@ import("${chip_root}/src/lib/lib.gni") declare_args() { bl_iot_sdk_root = "${chip_root}/third_party/bouffalolab/repo" - - enable_cdc_module = false } assert(bl_iot_sdk_root != "", "bl_iot_sdk_root must be specified") @@ -34,14 +32,6 @@ assert(bl_iot_sdk_root != "", "bl_iot_sdk_root must be specified") template("bl_iot_sdk") { sdk_target_name = target_name - if (defined(invoker.enable_zigbee)) { - enable_zigbee = invoker.enable_zigbee - } - - if (defined(invoker.enable_cdc_module)) { - enable_cdc_module = invoker.enable_cdc_module - } - config("${sdk_target_name}_config") { defines = [ "__FILENAME__=strrchr(__FILE__,'/')?strrchr(__FILE__,'/')+1:__FILE__", @@ -241,7 +231,10 @@ template("bl_iot_sdk") { } source_set("${sdk_target_name}_hosal") { - defines = [ "CFG_USE_XTAL32K=1" ] + defines = [ + "CFG_USE_XTAL32K=1", + "DISABLE_PRINT=1", + ] sources = [ "${bl_iot_sdk_root}/components/platform/hosal/bl702_hal/bl_adc.c", @@ -728,62 +721,27 @@ template("bl_iot_sdk") { ] } - config("${sdk_target_name}_config_lwip_port") { - _include_dirs = [ - "${bl_iot_sdk_root}/components/network/lwip/lwip-port", - "${bl_iot_sdk_root}/components/network/lwip/lwip-port/config", - "${bl_iot_sdk_root}/components/stage/virt_net/include", - "${bl_iot_sdk_root}/components/stage/throughput/bl702/inc", - ] - - defines = [ - "TCPIP_THREAD_PRIO=24", - "CFG_ETHERNET_ENABLE=1", - ] - - cflags = [] - foreach(include_dir, _include_dirs) { - cflags += [ "-isystem" + rebase_path(include_dir, root_build_dir) ] - } - - cflags += [ - "-Wno-conversion", - "-Wno-unused-function", + config("${sdk_target_name}_config_ethernet") { + include_dirs = [ + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_ethernet/Inc", ] } - source_set("${sdk_target_name}_lwip_port") { - defines = [ - "SPI_WIFI_RXBUFF_IN_PSRAM=1", - "VIRT_NET_SPI_RX_TASK_PRIORITY=25", - ] - - # include_dirs = [ - # "${bl_iot_sdk_root}/components/network/lwip/lwip-port/arch", - # "${bl_iot_sdk_root}/components/network/lwip/lwip-port/FreeRTOS", - # "${bl_iot_sdk_root}/components/stage/throughput" - # ] - - # sources = [ - # "${bl_iot_sdk_root}/components/network/lwip/lwip-port/FreeRTOS/ethernetif.c", - # "${bl_iot_sdk_root}/components/network/lwip/lwip-port/FreeRTOS/sys_arch.c" - # ] - - # sources += [ - # "${bl_iot_sdk_root}/components/stage/throughput/bl702/src/tp_spi_master.c", - # ] - # sources += [ - # "${bl_iot_sdk_root}/components/stage/virt_net/src/virt_net.c", - # "${bl_iot_sdk_root}/components/stage/virt_net/src/virt_net_spi.c", - # ] + source_set("${sdk_target_name}_ethernet") { + defines = [ "DISABLE_PRINT=1" ] + sources = [ "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_ethernet/Src/eth_bd.c" ] + configs += [ + ":${sdk_target_name}_config_BSP_Driver", + ":${sdk_target_name}_config_hosal", + ":${sdk_target_name}_config_utils", + ":${sdk_target_name}_config_freertos", + ":${sdk_target_name}_config_lwip", + ] public_configs = [ ":${sdk_target_name}_config", - ":${sdk_target_name}_config_lwip_port", - ":${sdk_target_name}_config_lwip", + ":${sdk_target_name}_config_ethernet", ] - - cflags = [ "-Wno-sign-compare" ] } config("${sdk_target_name}_config_lwip") { @@ -797,12 +755,15 @@ template("bl_iot_sdk") { ] defines = [ + "CFG_ETHERNET_ENABLE=1", "LWIP_IPV6=1", "LWIP_IPV4=1", "LWIP_IPV6_DHCP6=1", "LWIP_IPV6_SCOPES=0", "PBUF_POOL_SIZE=20", - "PBUF_POOL_BUFSIZE=(1280+150)", + "PBUF_POOL_BUFSIZE=1600", + "CONFIG_LWIP_HOOK_IP6_ROUTE_DEFAULT", + "CONFIG_LWIP_HOOK_ND6_GET_GW_DEFAULT", ] } @@ -881,6 +842,12 @@ template("bl_iot_sdk") { ":${sdk_target_name}_config", ":${sdk_target_name}_config_lwip", ] + + cflags = [ + "-Wno-incompatible-pointer-types", + "-Wno-unused-variable", + "-Wno-sign-compare", + ] } group(sdk_target_name) { @@ -888,6 +855,7 @@ template("bl_iot_sdk") { ":${sdk_target_name}_BSP_Driver", ":${sdk_target_name}_bl702_freertos", ":${sdk_target_name}_ble", + ":${sdk_target_name}_ethernet", ":${sdk_target_name}_fs", ":${sdk_target_name}_hosal", ":${sdk_target_name}_libc", @@ -898,16 +866,16 @@ template("bl_iot_sdk") { ":${sdk_target_name}_utils", ] - if (chip_enable_openthread) { + if (defined(invoker.chip_enable_wifi) && invoker.chip_enable_wifi) { + } else if (defined(invoker.chip_enable_openthread) && + invoker.chip_enable_openthread) { public_deps += [ ":${sdk_target_name}_openthread_port" ] - } - - if (chip_enable_wifi) { - public_deps += [ ":${sdk_target_name}_lwip_port" ] + } else { + public_deps += [ ":${sdk_target_name}_ethernet" ] public_deps += [ ":${sdk_target_name}_lwip" ] } - if (enable_cdc_module) { + if (defined(invoker.enable_cdc_module) && invoker.enable_cdc_module) { public_deps += [ ":${sdk_target_name}_bl702_usb_cdc" ] } } diff --git a/third_party/bouffalolab/bl702l/bl_iot_sdk.gni b/third_party/bouffalolab/bl702l/bl_iot_sdk.gni index 9362f2db1ac614..89d35bc98bb1a5 100644 --- a/third_party/bouffalolab/bl702l/bl_iot_sdk.gni +++ b/third_party/bouffalolab/bl702l/bl_iot_sdk.gni @@ -687,7 +687,8 @@ template("bl_iot_sdk") { ":${sdk_target_name}_utils", ] public_configs = [ ":${sdk_target_name}_config_BSP_Driver" ] - if (chip_enable_openthread) { + if (defined(invoker.chip_enable_openthread) && + invoker.chip_enable_openthread) { public_deps += [ ":${sdk_target_name}_openthread_port" ] } } diff --git a/third_party/bouffalolab/repo b/third_party/bouffalolab/repo index 31489e4c11dbe3..d1aba795ad1b36 160000 --- a/third_party/bouffalolab/repo +++ b/third_party/bouffalolab/repo @@ -1 +1 @@ -Subproject commit 31489e4c11dbe341f7a38792efc6d7a95d1d48ea +Subproject commit d1aba795ad1b36ab2a0f58f664caf176e26fe97b