Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bouffalolab] Remove lwip in BL70X Thread Application #30020

Merged
merged 7 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/lighting-app/bouffalolab/bl702l/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ bl_iot_sdk("sdk") {
}

chip_data_model("bouffalolab-lighting") {
zap_file = "${example_dir}/data_model/lighting-app-wifi.zap"
zap_file = "${example_dir}/data_model/lighting-app-thread.zap"

zap_pregenerated_dir = "${chip_root}/zzz_generated/lighting-app/zap-generated"
is_server = true
Expand Down
20 changes: 20 additions & 0 deletions examples/platform/bouffalolab/common/plat/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,18 @@ void ChipEventHandler(const ChipDeviceEvent * event, intptr_t arg)
}
}

#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
void LockOpenThreadTask(void)
{
chip::DeviceLayer::ThreadStackMgr().LockThreadStack();
}

void UnlockOpenThreadTask(void)
{
chip::DeviceLayer::ThreadStackMgr().UnlockThreadStack();
}
#endif

CHIP_ERROR PlatformManagerImpl::PlatformInit(void)
{
chip::RendezvousInformationFlags rendezvousMode(chip::RendezvousInformationFlag::kOnNetwork);
Expand Down Expand Up @@ -235,6 +247,14 @@ CHIP_ERROR PlatformManagerImpl::PlatformInit(void)
static CommonCaseDeviceServerInitParams initParams;
(void) initParams.InitializeStaticResourcesBeforeServerInit();

#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
chip::Inet::EndPointStateOpenThread::OpenThreadEndpointInitParam nativeParams;
nativeParams.lockCb = LockOpenThreadTask;
nativeParams.unlockCb = UnlockOpenThreadTask;
nativeParams.openThreadInstancePtr = chip::DeviceLayer::ThreadStackMgrImpl().OTInstance();
initParams.endpointNativeParams = static_cast<void *>(&nativeParams);
#endif

ReturnLogErrorOnFailure(chip::Server::GetInstance().Init(initParams));

gExampleDeviceInfoProvider.SetStorageDelegate(&chip::Server::GetInstance().GetPersistentStorage());
Expand Down
2 changes: 2 additions & 0 deletions scripts/build/builders/bouffalolab.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ def __init__(self,
self.argsOpt.append(f'chip_inet_config_enable_ipv4={str(enable_ethernet or enable_wifi).lower()}')

if enable_thread:
self.argsOpt.append('chip_system_config_use_open_thread_inet_endpoints=true')
self.argsOpt.append('chip_with_lwip=false')
self.argsOpt.append(f'openthread_project_core_config_file="{bouffalo_chip}-openthread-core-bl-config.h"')
if not use_matter_openthread:
self.argsOpt.append(
Expand Down
3 changes: 3 additions & 0 deletions src/platform/bouffalolab/BL702/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,7 @@ static_library("BL702") {

deps += [ "${chip_root}/src/credentials:credentials_header" ]
public_deps = [ "${chip_root}/src/platform:platform_base" ]

public_configs =
[ "${chip_root}/src/lib/address_resolve:default_address_resolve_config" ]
}
5 changes: 5 additions & 0 deletions src/platform/bouffalolab/BL702/PlatformManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@
#include <platform/bouffalolab/common/DiagnosticDataProviderImpl.h>
#include <platform/internal/GenericPlatformManagerImpl_FreeRTOS.ipp>

#if CHIP_SYSTEM_CONFIG_USE_LWIP
#include <lwip/tcpip.h>
#endif

#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
#include <platform/bouffalolab/BL702/wifi_mgmr_portable.h>
#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI
Expand Down Expand Up @@ -62,8 +65,10 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack(void)
CHIP_ERROR err;
TaskHandle_t backup_eventLoopTask;

#if CHIP_SYSTEM_CONFIG_USE_LWIP
// Initialize LwIP.
tcpip_init(NULL, NULL);
#endif

#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
otRadio_opt_t opt;
Expand Down
10 changes: 5 additions & 5 deletions src/platform/bouffalolab/BL702/ThreadStackManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@

#include <platform/internal/CHIPDeviceLayerInternal.h>

#include <platform/FreeRTOS/GenericThreadStackManagerImpl_FreeRTOS.hpp>
#include <platform/OpenThread/GenericThreadStackManagerImpl_OpenThread_LwIP.cpp>

#include <platform/OpenThread/OpenThreadUtils.h>
#include <platform/ThreadStackManager.h>

#include <openthread/platform/entropy.h>
#include <platform/FreeRTOS/GenericThreadStackManagerImpl_FreeRTOS.hpp>
#include <platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.hpp>

#include <lib/support/CHIPPlatformMemory.h>

#include <openthread/platform/entropy.h>

#include <mbedtls/platform.h>

#include <openthread_port.h>
Expand All @@ -51,7 +51,7 @@ CHIP_ERROR ThreadStackManagerImpl::InitThreadStack(otInstance * otInst)
// Initialize the generic implementation base classes.
err = GenericThreadStackManagerImpl_FreeRTOS<ThreadStackManagerImpl>::DoInit();
SuccessOrExit(err);
err = GenericThreadStackManagerImpl_OpenThread_LwIP<ThreadStackManagerImpl>::DoInit(otInstanceInitSingle());
err = GenericThreadStackManagerImpl_OpenThread<ThreadStackManagerImpl>::DoInit(otInst);
SuccessOrExit(err);

mbedtls_platform_set_calloc_free(pvPortCalloc, vPortFree);
Expand Down
3 changes: 3 additions & 0 deletions src/platform/bouffalolab/BL702L/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,7 @@ static_library("BL702L") {

deps += [ "${chip_root}/src/credentials:credentials_header" ]
public_deps = [ "${chip_root}/src/platform:platform_base" ]

public_configs =
[ "${chip_root}/src/lib/address_resolve:default_address_resolve_config" ]
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
#include <platform/DiagnosticDataProvider.h>
#include <platform/bouffalolab/common/DiagnosticDataProviderImpl.h>

#include "FreeRTOS.h"
#include <lwip/tcpip.h>
#include <FreeRTOS.h>

extern "C" {
#include <bl_sys.h>
Expand Down
4 changes: 4 additions & 0 deletions src/platform/bouffalolab/BL702L/PlatformManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
#include <platform/bouffalolab/common/DiagnosticDataProviderImpl.h>
#include <platform/internal/GenericPlatformManagerImpl_FreeRTOS.ipp>

#if CHIP_SYSTEM_CONFIG_USE_LWIP
#include <lwip/tcpip.h>
#endif

extern "C" {
#include <bl_sec.h>
Expand Down Expand Up @@ -68,8 +70,10 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack(void)

ReturnErrorOnFailure(System::Clock::InitClock_RealTime());

#if CHIP_SYSTEM_CONFIG_USE_LWIP
// Initialize LwIP.
tcpip_init(NULL, NULL);
#endif

err = chip::Crypto::add_entropy_source(app_entropy_source, NULL, 16);
SuccessOrExit(err);
Expand Down
10 changes: 6 additions & 4 deletions src/platform/bouffalolab/BL702L/ThreadStackManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@

#include <platform/internal/CHIPDeviceLayerInternal.h>

#include <platform/FreeRTOS/GenericThreadStackManagerImpl_FreeRTOS.hpp>
#include <platform/OpenThread/GenericThreadStackManagerImpl_OpenThread_LwIP.cpp>

#include <platform/OpenThread/OpenThreadUtils.h>
#include <platform/ThreadStackManager.h>

#include <platform/FreeRTOS/GenericThreadStackManagerImpl_FreeRTOS.hpp>
#include <platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.hpp>

#include <lib/support/CHIPPlatformMemory.h>

#include <openthread/platform/entropy.h>

#include <mbedtls/platform.h>
Expand Down Expand Up @@ -54,7 +56,7 @@ CHIP_ERROR ThreadStackManagerImpl::InitThreadStack(otInstance * otInst)
// Initialize the generic implementation base classes.
err = GenericThreadStackManagerImpl_FreeRTOS<ThreadStackManagerImpl>::DoInit();
SuccessOrExit(err);
err = GenericThreadStackManagerImpl_OpenThread_LwIP<ThreadStackManagerImpl>::DoInit(otInst);
err = GenericThreadStackManagerImpl_OpenThread<ThreadStackManagerImpl>::DoInit(otInst);
SuccessOrExit(err);

mbedtls_platform_set_calloc_free(pvPortCalloc, vPortFree);
Expand Down
5 changes: 3 additions & 2 deletions src/platform/bouffalolab/common/BLConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ namespace Internal {

void BLConfig::Init(void)
{
env_node_obj node;

easyflash_init();
ef_load_env_cache();

if (ef_get_env(kBLKey_factoryResetFlag))
if (ef_get_env_obj(kBLKey_factoryResetFlag, &node))
{

ef_print_env_cb([](env_node_obj_t env, void * arg1, void * arg2) {
if (ENV_WRITE == env->status)
{
Expand Down
4 changes: 4 additions & 0 deletions src/platform/bouffalolab/common/SystemPlatformConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,9 @@ struct ChipDeviceEvent;
#define CHIP_SYSTEM_CONFIG_PLATFORM_PROVIDES_TIME 1
#define CHIP_SYSTEM_CONFIG_EVENT_OBJECT_TYPE const struct ::chip::DeviceLayer::ChipDeviceEvent *

#if CHIP_ENABLE_OPENTHREAD
#define CHIP_SYSTEM_CONFIG_PACKETBUFFER_POOL_SIZE 8
#endif

// #define CHIP_CONFIG_SHA256_CONTEXT_SIZE sizeof(bl_sha_ctx_t)
#define CHIP_CONFIG_SHA256_CONTEXT_SIZE ((7 + 1 + 5 + 18 + 16 + 16 + 7) * sizeof(unsigned int))
9 changes: 3 additions & 6 deletions src/platform/bouffalolab/common/ThreadStackManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,10 @@

#pragma once

#include <platform/FreeRTOS/GenericThreadStackManagerImpl_FreeRTOS.h>
#include <platform/OpenThread/GenericThreadStackManagerImpl_OpenThread_LwIP.h>

#include <openthread/tasklet.h>
#include <openthread/thread.h>

#include <queue.h>
#include <platform/FreeRTOS/GenericThreadStackManagerImpl_FreeRTOS.h>
#include <platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.h>

extern "C" void otSysEventSignalPending(void);
extern "C" void otrLock(void);
Expand All @@ -41,7 +38,7 @@ class ThreadStackManagerImpl;
* using the Bouffalolab SDK and the OpenThread stack.
*/
class ThreadStackManagerImpl final : public ThreadStackManager,
public Internal::GenericThreadStackManagerImpl_OpenThread_LwIP<ThreadStackManagerImpl>,
public Internal::GenericThreadStackManagerImpl_OpenThread<ThreadStackManagerImpl>,
public Internal::GenericThreadStackManagerImpl_FreeRTOS<ThreadStackManagerImpl>
{
// Allow the ThreadStackManager interface class to delegate method calls to
Expand Down
10 changes: 10 additions & 0 deletions src/system/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ if (chip_device_platform == "cc13x2_26x2") {
import("//build_overrides/mt793x_sdk.gni")
} else if (chip_device_platform == "stm32") {
import("//build_overrides/stm32_sdk.gni")
} else if (chip_device_platform == "bl702") {
import("//build_overrides/bouffalolab_iot_sdk.gni")
} else if (chip_device_platform == "bl702l") {
import("//build_overrides/bouffalolab_iot_sdk.gni")
}

buildconfig_header("system_buildconfig") {
Expand Down Expand Up @@ -192,6 +196,12 @@ source_set("system_config_header") {
if (chip_device_platform == "stm32") {
public_deps += [ "${stm32_sdk_build_root}:stm32_sdk" ]
}
if (chip_device_platform == "bl702") {
public_deps += [ "${bouffalolab_iot_sdk_build_root}/bl702:bl_iot_sdk" ]
}
if (chip_device_platform == "bl702l") {
public_deps += [ "${bouffalolab_iot_sdk_build_root}/bl702l:bl_iot_sdk" ]
}

# Add platform here as needed.
}
Expand Down
4 changes: 4 additions & 0 deletions third_party/bouffalolab/bl702/bl_iot_sdk.gni
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,10 @@ template("bl_iot_sdk") {
"${bl_iot_sdk_root}/components/stage/blfdt/inc",
"${bl_iot_sdk_root}/components/stage/cli/cli/include",
]

if (defined(invoker.enable_cdc_module) && invoker.enable_cdc_module) {
cflags_cc = [ "-Wno-shadow" ]
}
}

source_set("${sdk_target_name}_stage") {
Expand Down
Loading