Skip to content

Commit

Permalink
Silabs wifi - chip support for EFR32 - Using WF200 and RS911x (#13193)
Browse files Browse the repository at this point in the history
* EFR32+SiLabs WiFi port - using lock app

* Changed Wiseconnect SDK to relative symbolic link

* Moved WiFi stuff to efr32_sdk/repo/matter/wifi

* added Lighting app to silabs_wifi

* Silabs_wifi Lighting-app removed some junk files

* Update for building with scripts/examples/gn_efr32_example.sh

* Rebased to master - Fixes to AppTask.cpp+BUILD.gn

* Merged Thread and WiFi apps (Lighting and Windows) into examples/xxx-app/efr32

* Updated lock-app/efr32 to include WiFi build

* Fixes to ifdef's in lock-app for efr32

* Removed examples/xx-app/silabs_wifi. Merged into examples/xx-app/efr32

* updated build-script for efr32 to use wifi

* WiFi fixes to initialize RS911X for EFR32

* Update for WiFi port to sync with SiLabs work

* WiFi - Added saving SSID/PSK/Security

* Cleaned up comments in BUILD.gn

* Restyled by whitespace

* Restyled by clang-format

* Restyled by gn

* Restyled by shellharden

* Restyled by shfmt

* Restyled by clang-format

* include file reference was changed to <lib/support>

* Added WF200 files and changed Defines to match master

* Fixed issue with build script that does not handle ARG3/4

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Jul 18, 2023
1 parent 929ef36 commit 2751129
Show file tree
Hide file tree
Showing 48 changed files with 2,230 additions and 309 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/examples-efr32.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ jobs:
timeout-minutes: 10
run: |
scripts/examples/gn_efr32_example.sh examples/lighting-app/efr32/ out/lighting_app_debug_rpc BRD4161A \
-args='import("//with_pw_rpc.gni")'
'import("//with_pw_rpc.gni")'
.environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py efr32 BRD4161A+rpc lighting-app \
out/lighting_app_debug_rpc/BRD4161A/chip-efr32-lighting-example.out /tmp/bloat_reports/
- name: Build example EFR32 Window Covering for BRD4161A
Expand Down
6 changes: 6 additions & 0 deletions config/efr32/toolchain/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,9 @@ arm_toolchain("efr32_window_app") {
import("${chip_root}/examples/window-app/efr32/args.gni")
}
}
arm_toolchain("rs911x_lock_app") {
toolchain_args = {
current_os = "freertos"
import("${chip_root}/examples/lock-app/rs911x/args.gni")
}
}
110 changes: 94 additions & 16 deletions examples/lighting-app/efr32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ declare_args() {

# Monitor & log memory usage at runtime.
enable_heap_monitoring = false

# Wifi related stuff - they are overriden by gn -args="use_wf200=true"
use_wf200 = false
use_rs911x = false
use_rs911x_sockets = false
sl_wfx_config_softap = false
sl_wfx_config_scan = false
}

show_qr_code = true
Expand All @@ -52,6 +59,26 @@ show_qr_code = true
if (efr32_board == "BRD4166A" || efr32_board == "BRD4180A") {
show_qr_code = false
}
if (use_rs911x || use_wf200) {
wifi_sdk_dir = "${chip_root}/third_party/efr32_sdk/repo/matter/wifi"
if (use_rs911x) {
wiseconnect_sdk_root = "${chip_root}/third_party/wiseconnect-wifi-bt-sdk"
import("${wifi_sdk_dir}/rs911x/rs911x.gni")
} else {
import("${wifi_sdk_dir}/wf200/wf200.gni")
}
}
efr32_lwip_defs = [ "LWIP_NETIF_API=1" ]
if (use_rs911x || use_wf200) {
efr32_lwip_defs += [
"LWIP_IPV4=1",
"LWIP_ARP=1",
"LWIP_ICMP=1",
"LWIP_DHCP=1",
"LWIP_IPV6_ND=1",
"LWIP_IGMP=1",
]
}

efr32_sdk("sdk") {
sources = [
Expand All @@ -63,6 +90,7 @@ efr32_sdk("sdk") {
"${chip_root}/src/platform/EFR32",
"${efr32_project_dir}/include",
"${examples_plat_dir}",
"${chip_root}/src/lib",
]

defines = [
Expand All @@ -77,10 +105,36 @@ efr32_sdk("sdk") {
"PW_RPC_ENABLED",
]
}
if (use_rs911x) {
defines += rs911x_defs
include_dirs += rs911x_plat_incs
} else if (use_wf200) {
defines += wf200_defs
include_dirs += wf200_plat_incs
} else {
defines += [ "SL_HEAP_SIZE=20480" ]
}
if (use_rs911x_sockets) {
include_dirs += [ "${examples_plat_dir}/wifi/rsi-sockets" ]
defines += rs911x_sock_defs
} else {
# Using LWIP instead of the native TCP/IP stack
# Thread also uses LWIP
#
defines += efr32_lwip_defs
}
if (sl_wfx_config_softap) {
defines += "SL_WFX_CONFIG_SOFTAP"
}
if (sl_wfx_config_scan) {
defines += "SL_WFX_CONFIG_SCAN"
}
}

efr32_executable("lighting_app") {
output_name = "chip-efr32-lighting-example.out"
include_dirs = [ "include" ]
defines = []

sources = [
"${examples_plat_dir}/LEDWidget.cpp",
Expand All @@ -99,26 +153,50 @@ efr32_executable("lighting_app") {
"${chip_root}/examples/lighting-app/lighting-common",
"${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",
"${examples_plat_dir}:efr-matter-shell",
]

if (chip_openthread_ftd) {
deps += [
"${chip_root}/third_party/openthread/repo:libopenthread-cli-ftd",
"${chip_root}/third_party/openthread/repo:libopenthread-ftd",
]
} else {
if (!use_rs911x && !use_wf200) {
deps += [
"${chip_root}/third_party/openthread/repo:libopenthread-cli-mtd",
"${chip_root}/third_party/openthread/repo:libopenthread-mtd",
"${chip_root}/third_party/openthread/platforms:libopenthread-platform",
"${chip_root}/third_party/openthread/platforms:libopenthread-platform-utils",
"${examples_plat_dir}:efr-matter-shell",
]
if (chip_openthread_ftd) {
deps += [
"${chip_root}/third_party/openthread/repo:libopenthread-cli-ftd",
"${chip_root}/third_party/openthread/repo:libopenthread-ftd",
]
} else {
deps += [
"${chip_root}/third_party/openthread/repo:libopenthread-cli-mtd",
"${chip_root}/third_party/openthread/repo:libopenthread-mtd",
]
}
}
if (use_rs911x) {
sources += rs911x_src_plat

# All the stuff from wiseconnect
sources += rs911x_src_sapi

# Apparently - the rsi library needs this (though we may not use use it)
sources += rs911x_src_sock
include_dirs += rs911x_inc_plat

if (use_rs911x_sockets) {
#
# Using native sockets inside RS911x
#
include_dirs += rs911x_sock_inc
} else {
#
# We use LWIP - not built-in sockets
#
sources += rs911x_src_lwip
}
} else if (use_wf200) {
sources += wf200_plat_src
include_dirs += wf200_plat_incs
}

include_dirs = [ "include" ]

defines = []

if (show_qr_code) {
sources += [ "${examples_plat_dir}/display/lcd.c" ]
Expand Down
22 changes: 22 additions & 0 deletions examples/lighting-app/efr32/build_for_wifi_args.gni
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright (c) 2020 Project CHIP Authors
#
# 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.
import("//build_overrides/chip.gni")
import("//build_overrides/pigweed.gni")

efr32_sdk_target = get_label_info(":sdk", "label_no_toolchain")
chip_enable_openthread = false
import("${chip_root}/src/platform/EFR32/wifi_args.gni")

pw_log_BACKEND = "${chip_root}/src/lib/support/pw_log_chip"
pw_assert_BACKEND = "$dir_pw_assert_log"
28 changes: 28 additions & 0 deletions examples/lighting-app/efr32/build_for_wifi_gnfile.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright (c) 2020 Project CHIP Authors
#
# 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.

import("//build_overrides/build.gni")

# The location of the build configuration file.
buildconfig = "${build_root}/config/BUILDCONFIG.gn"

# CHIP uses angle bracket includes.
check_system_includes = true

default_args = {
target_cpu = "arm"
target_os = "freertos"
use_thread = false
import("//build_for_wifi_args.gni")
}
2 changes: 1 addition & 1 deletion examples/lighting-app/efr32/include/AppConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

// ---- Lighting Example App Config ----

#define APP_TASK_NAME "APP"
#define APP_TASK_NAME "Lit"

// Time it takes in ms for the simulated actuator to move from one
// state to another.
Expand Down
4 changes: 4 additions & 0 deletions examples/lighting-app/efr32/include/FreeRTOSConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,11 @@ See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */
#define configENABLE_BACKWARD_COMPATIBILITY (1)
#define configSUPPORT_STATIC_ALLOCATION (1)
#define configSUPPORT_DYNAMIC_ALLOCATION (1)
#ifdef SL_WIFI
#define configTOTAL_HEAP_SIZE ((size_t)(28 * 1024))
#else
#define configTOTAL_HEAP_SIZE ((size_t)(20 * 1024))
#endif

/* Optional functions - most linkers will remove unused functions anyway. */
#define INCLUDE_vTaskPrioritySet (1)
Expand Down
60 changes: 45 additions & 15 deletions examples/lighting-app/efr32/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
#include <platform/OpenThread/OpenThreadUtils.h>
#include <platform/ThreadStackManager.h>
#endif
#ifdef SL_WIFI
#include "wfx_host_events.h"
#endif /* SL_WIFI */

#define FACTORY_RESET_TRIGGER_TIMEOUT 3000
#define FACTORY_RESET_CANCEL_WINDOW_TIMEOUT 3000
Expand All @@ -73,9 +76,17 @@ QueueHandle_t sAppEventQueue;
LEDWidget sStatusLED;
LEDWidget sLightLED;

#ifdef SL_WIFI
bool sIsWiFiProvisioned = false;
bool sIsWiFiEnabled = false;
bool sIsWiFiAttached = false;
#endif /* SL_WIFI */

#if CHIP_ENABLE_OPENTHREAD
bool sIsThreadProvisioned = false;
bool sIsThreadEnabled = false;
bool sHaveBLEConnections = false;
#endif /* CHIP_ENABLE_OPENTHREAD */
bool sHaveBLEConnections = false;

EmberAfIdentifyEffectIdentifier sIdentifyEffect = EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_STOP_EFFECT;

Expand All @@ -88,6 +99,7 @@ StaticTask_t appTaskStruct;
/**********************************************************
* Identify Callbacks
*********************************************************/

namespace {
void OnTriggerIdentifyEffectCompleted(chip::System::Layer * systemLayer, void * appState)
{
Expand Down Expand Up @@ -208,6 +220,18 @@ CHIP_ERROR AppTask::Init()
{
CHIP_ERROR err = CHIP_NO_ERROR;

#ifdef SL_WIFI
/*
* Wait for the WiFi to be initialized
*/
EFR32_LOG("APP: Wait WiFi Init");
while (!wfx_hw_ready())
{
vTaskDelay(10);
}
EFR32_LOG("APP: Done WiFi Init");
/* We will init server when we get IP */
#endif
// Init ZCL Data Model
chip::Server::GetInstance().Init();

Expand Down Expand Up @@ -294,9 +318,16 @@ void AppTask::AppTaskMain(void * pvParameter)
// when the CHIP task is busy (e.g. with a long crypto operation).
if (PlatformMgr().TryLockChipStack())
{
#ifdef SL_WIFI
sIsWiFiProvisioned = ConnectivityMgr().IsWiFiStationProvisioned();
sIsWiFiEnabled = ConnectivityMgr().IsWiFiStationEnabled();
sIsWiFiAttached = ConnectivityMgr().IsWiFiStationConnected();
#endif /* SL_WIFI */
#if CHIP_ENABLE_OPENTHREAD
sIsThreadProvisioned = ConnectivityMgr().IsThreadProvisioned();
sIsThreadEnabled = ConnectivityMgr().IsThreadEnabled();
sHaveBLEConnections = (ConnectivityMgr().NumBLEConnections() != 0);
#endif /* CHIP_ENABLE_OPENTHREAD */
sHaveBLEConnections = (ConnectivityMgr().NumBLEConnections() != 0);
PlatformMgr().UnlockChipStack();
}

Expand Down Expand Up @@ -333,18 +364,16 @@ void AppTask::AppTaskMain(void * pvParameter)
sStatusLED.Blink(300, 700);
}
}
else if (sIsThreadProvisioned && sIsThreadEnabled)
#if CHIP_ENABLE_OPENTHREAD
if (sIsThreadProvisioned && sIsThreadEnabled)
#else
if (sIsWiFiProvisioned && sIsWiFiEnabled && !sIsWiFiAttached)
#endif
{
sStatusLED.Blink(950, 50);
}
else if (sHaveBLEConnections)
{
sStatusLED.Blink(100, 100);
}
else
{
sStatusLED.Blink(50, 950);
}
else if (sHaveBLEConnections) { sStatusLED.Blink(100, 100); }
else { sStatusLED.Blink(50, 950); }
}

sStatusLED.Animate();
Expand Down Expand Up @@ -484,16 +513,17 @@ void AppTask::FunctionHandler(AppEvent * aEvent)
sAppTask.CancelTimer();
sAppTask.mFunction = kFunction_NoneSelected;

#ifdef SL_WIFI
if (!ConnectivityMgr().IsWiFiStationProvisioned())
#else
if (!ConnectivityMgr().IsThreadProvisioned())
#endif /* !SL_WIFI */
{
// Enable BLE advertisements
ConnectivityMgr().SetBLEAdvertisingEnabled(true);
ConnectivityMgr().SetBLEAdvertisingMode(ConnectivityMgr().kFastAdvertising);
}
else
{
EFR32_LOG("Network is already provisioned, Ble advertissement not enabled");
}
else { EFR32_LOG("Network is already provisioned, Ble advertissement not enabled"); }
}
else if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_FactoryReset)
{
Expand Down
Loading

0 comments on commit 2751129

Please sign in to comment.