Skip to content

Commit

Permalink
[Bouffalolab] Improve BL602&BL702 key-value accessing (#24574)
Browse files Browse the repository at this point in the history
* enable hardware crypto engine for mbedtls

* remove duplicate dependency

* fix restyle

* move platform init to platform.cpp

* update PSM region

* enable ipv6 for wifi sub-module

* fix restyle

* fix compile error
  • Loading branch information
wy-hh authored Jan 22, 2023
1 parent 0783425 commit 8f926b8
Show file tree
Hide file tree
Showing 17 changed files with 226 additions and 164 deletions.
1 change: 1 addition & 0 deletions examples/lighting-app/bouffalolab/bl602/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ bouffalolab_executable("lighting_app") {
"${examples_plat_common_dir}/plat/aos_task.c",
"${examples_plat_common_dir}/plat/demo_pwm.c",
"${examples_plat_common_dir}/plat/main.cpp",
"${examples_plat_common_dir}/plat/platform.cpp",
"${examples_plat_common_dir}/plat/uart.c",
]

Expand Down
2 changes: 2 additions & 0 deletions examples/lighting-app/bouffalolab/bl602/CHIPProjectConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,5 @@
#define CHIP_DEVICE_CONFIG_ENABLE_EXTENDED_DISCOVERY 1

#define CHIP_SYSTEM_CRYPTO_HEADER_RESERVE_SIZE 128

#define CHIP_BLE_DEVICE_NAME "MatterLight"
1 change: 1 addition & 0 deletions examples/lighting-app/bouffalolab/bl702/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ bouffalolab_executable("lighting_app") {
"${examples_plat_common_dir}/plat/LEDWidget.cpp",
"${examples_plat_common_dir}/plat/demo_pwm.c",
"${examples_plat_common_dir}/plat/main.cpp",
"${examples_plat_common_dir}/plat/platform.cpp",
"${examples_plat_common_dir}/plat/uart.c",
]

Expand Down
2 changes: 2 additions & 0 deletions examples/lighting-app/bouffalolab/bl702/CHIPProjectConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,5 @@
#define CHIP_DEVICE_CONFIG_ENABLE_EXTENDED_DISCOVERY 1

#define CHIP_CONFIG_MAX_DEVICE_ADMINS 4 // 3 fabrics + 1 for rotation slack

#define CHIP_BLE_DEVICE_NAME "MatterLight"
134 changes: 4 additions & 130 deletions examples/lighting-app/bouffalolab/common/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
* limitations under the License.
*/

#include "AppConfig.h"
#include "LEDWidget.h"
#include <LEDWidget.h>
#include <plat.h>

#include <app-common/zap-generated/attribute-id.h>
#include <app-common/zap-generated/attribute-type.h>
Expand All @@ -42,10 +42,8 @@

#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
#include <NetworkCommissioningDriver.h>
#include <app/clusters/network-commissioning/network-commissioning.h>
#include <route_hook/bl_route_hook.h>
#endif
#include <PlatformManagerImpl.h>

#if HEAP_MONITORING
#include "MemMonitoring.h"
Expand All @@ -58,20 +56,11 @@
#include <utils_list.h>
#endif

#if PW_RPC_ENABLED
#include "PigweedLogger.h"
#include "Rpc.h"
#endif

#if CONFIG_ENABLE_CHIP_SHELL
#include <ChipShellCollection.h>
#include <lib/shell/Engine.h>
#endif

#if CONFIG_ENABLE_CHIP_SHELL || PW_RPC_ENABLED
#include "uart.h"
#endif

extern "C" {
#include "board.h"
#include <bl_gpio.h>
Expand All @@ -84,11 +73,6 @@ extern "C" {

namespace {

#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
chip::app::Clusters::NetworkCommissioning::Instance
sWiFiNetworkCommissioningInstance(0 /* Endpoint Id */, &(NetworkCommissioning::BLWiFiDriver::GetInstance()));
#endif

#if defined(BL706_NIGHT_LIGHT) || defined(BL602_NIGHT_LIGHT)
ColorLEDWidget sLightLED;
#else
Expand Down Expand Up @@ -117,118 +101,6 @@ AppTask AppTask::sAppTask;
StackType_t AppTask::appStack[APP_TASK_STACK_SIZE / sizeof(StackType_t)];
StaticTask_t AppTask::appTaskStruct;

void PlatformManagerImpl::PlatformInit(void)
{
#if CONFIG_ENABLE_CHIP_SHELL || PW_RPC_ENABLED
uartInit();
#endif

#if PW_RPC_ENABLED
PigweedLogger::pw_init();
#elif CONFIG_ENABLE_CHIP_SHELL
AppTask::StartAppShellTask();
#endif

#if HEAP_MONITORING
MemMonitoring::startHeapMonitoring();
#endif

ChipLogProgress(NotSpecified, "Initializing CHIP stack");
CHIP_ERROR ret = PlatformMgr().InitChipStack();
if (ret != CHIP_NO_ERROR)
{
ChipLogError(NotSpecified, "PlatformMgr().InitChipStack() failed");
appError(ret);
}

chip::DeviceLayer::ConnectivityMgr().SetBLEDeviceName("MatterLight");

#if CHIP_ENABLE_OPENTHREAD

#if CONFIG_ENABLE_CHIP_SHELL
cmd_otcli_init();
#endif

ChipLogProgress(NotSpecified, "Initializing OpenThread stack");
ret = ThreadStackMgr().InitThreadStack();
if (ret != CHIP_NO_ERROR)
{
ChipLogError(NotSpecified, "ThreadStackMgr().InitThreadStack() failed");
appError(ret);
}

#if CHIP_DEVICE_CONFIG_THREAD_FTD
ret = ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_Router);
#else
ret = ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_MinimalEndDevice);
#endif
if (ret != CHIP_NO_ERROR)
{
ChipLogError(NotSpecified, "ConnectivityMgr().SetThreadDeviceType() failed");
appError(ret);
}

#elif CHIP_DEVICE_CONFIG_ENABLE_WIFI

ret = sWiFiNetworkCommissioningInstance.Init();
if (CHIP_NO_ERROR != ret)
{
ChipLogError(NotSpecified, "sWiFiNetworkCommissioningInstance.Init() failed");
}
#endif

chip::DeviceLayer::PlatformMgr().LockChipStack();

// Initialize device attestation config
SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider());

#if CHIP_DEVICE_CONFIG_ENABLE_EXTENDED_DISCOVERY
chip::app::DnssdServer::Instance().SetExtendedDiscoveryTimeoutSecs(EXT_DISCOVERY_TIMEOUT_SECS);
#endif

// Init ZCL Data Model
static chip::CommonCaseDeviceServerInitParams initParams;
(void) initParams.InitializeStaticResourcesBeforeServerInit();

ret = chip::Server::GetInstance().Init(initParams);
if (ret != CHIP_NO_ERROR)
{
ChipLogError(NotSpecified, "chip::Server::GetInstance().Init(initParams) failed");
appError(ret);
}
chip::DeviceLayer::PlatformMgr().UnlockChipStack();

#if CHIP_ENABLE_OPENTHREAD
ChipLogProgress(NotSpecified, "Starting OpenThread task");
// Start OpenThread task
ret = ThreadStackMgrImpl().StartThreadTask();
if (ret != CHIP_NO_ERROR)
{
ChipLogError(NotSpecified, "ThreadStackMgr().StartThreadTask() failed");
appError(ret);
}
#endif

ConfigurationMgr().LogDeviceConfig();

PrintOnboardingCodes(chip::RendezvousInformationFlag(chip::RendezvousInformationFlag::kBLE));
PlatformMgr().AddEventHandler(AppTask::ChipEventHandler, 0);

#ifdef OTA_ENABLED
chip::DeviceLayer::PlatformMgr().LockChipStack();
OTAConfig::Init();
chip::DeviceLayer::PlatformMgr().UnlockChipStack();
#endif // OTA_ENABLED

#if PW_RPC_ENABLED
chip::rpc::Init();
#endif

GetAppTask().PostEvent(AppTask::APP_EVENT_TIMER);

vTaskResume(GetAppTask().sAppTaskHandle);
}

void StartAppTask(void)
{
GetAppTask().sAppTaskHandle = xTaskCreateStatic(GetAppTask().AppTaskMain, APP_TASK_NAME, ArraySize(GetAppTask().appStack), NULL,
Expand Down Expand Up @@ -298,6 +170,8 @@ void AppTask::AppTaskMain(void * pvParameter)
ChipLogError(NotSpecified, "PlatformMgr().StartEventLoopTask() failed");
appError(ret);
}

GetAppTask().PostEvent(AppTask::APP_EVENT_TIMER);
vTaskSuspend(NULL);

#ifndef LED_BTN_RESET
Expand Down
9 changes: 8 additions & 1 deletion examples/lighting-app/bouffalolab/common/AppTask.h
Original file line number Diff line number Diff line change
@@ -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");
Expand Down Expand Up @@ -31,6 +30,14 @@
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_LIGHT_ENDPOINT_ID 1
#define APP_REBOOT_RESET_COUNT 3
#define APP_REBOOT_RESET_COUNT_KEY "app_reset_cnt"

// Application-defined error codes in the CHIP_ERROR space.
#define APP_ERROR_EVENT_QUEUE_FAILED CHIP_APPLICATION_ERROR(0x01)
#define APP_ERROR_CREATE_TASK_FAILED CHIP_APPLICATION_ERROR(0x02)
Expand Down
2 changes: 1 addition & 1 deletion examples/lighting-app/bouffalolab/common/ZclCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* This file implements the handler for data model messages.
*/

#include "AppConfig.h"
#include <plat.h>

#include <AppTask.h>
#include <app-common/zap-generated/ids/Attributes.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type = 4
name = "PSM"
device = 0
address0 = 0x1E9000
size0 = 0x8000
size0 = 0x4000
address1 = 0
size1 = 0
# compressed image must set len,normal image can left it to 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type = 4
name = "PSM"
device = 0
address0 = 0x3C3000
size0 = 0x33000
size0 = 0x4000
address1 = 0
size1 = 0
# compressed image must set len,normal image can left it to 0
Expand Down
7 changes: 3 additions & 4 deletions examples/platform/bouffalolab/common/plat/MemMonitoring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@
* limitations under the License.
*/

#include "MemMonitoring.h"

#include "AppConfig.h"
#include "FreeRTOS.h"
#include <FreeRTOS.h>
#include <MemMonitoring.h>
#include <plat.h>
#include <platform/CHIPDeviceLayer.h>

static StackType_t monitoringStack[MONITORING_STACK_SIZE_byte / sizeof(StackType_t)];
Expand Down
5 changes: 3 additions & 2 deletions examples/platform/bouffalolab/common/plat/aos_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@
* web site: https://www.bouffalolab.com/
*/

#ifdef SYS_AOS_LOOP_ENABLE

#include <FreeRTOS.h>
#include <timers.h>

#ifdef SYS_AOS_LOOP_ENABLE
#include <vfs.h>

#include <aos/kernel.h>
#include <aos/yloop.h>
#include <event_device.h>

#include <AppConfig.h>
#include <plat.h>

static void aos_loop_proc(void * pvParameters)
{
Expand Down
3 changes: 2 additions & 1 deletion examples/platform/bouffalolab/common/plat/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@

#include <FreeRTOS.h>

#include "AppConfig.h"
#include <AppTask.h>
#include <easyflash.h>
#include <lib/support/CHIPMem.h>
#include <lib/support/CHIPPlatformMemory.h>
#include <plat.h>

extern "C" {

Expand Down Expand Up @@ -329,6 +329,7 @@ extern "C" void START_ENTRY(void)
app_init();

easyflash_init();
ef_load_env_cache();

ChipLogProgress(NotSpecified, "Init CHIP Memory");
chip::Platform::MemoryInit(NULL, 0);
Expand Down
Original file line number Diff line number Diff line change
@@ -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");
Expand All @@ -19,30 +18,14 @@

#pragma once

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

#define APP_TASK_NAME "APP"

#define APP_BUTTON_PRESS_JITTER 50
#define APP_BUTTON_PRESS_SHORT 1000
#define APP_BUTTON_PRESS_LONG 4000

#define APP_TASK_PRIORITY 15
#define EXT_DISCOVERY_TIMEOUT_SECS 20
#define APP_LIGHT_ENDPOINT_ID 1
#define APP_REBOOT_RESET_COUNT 3
#define APP_REBOOT_RESET_COUNT_KEY "app_reset_cnt"

#ifdef __cplusplus
extern "C" {
#endif

#define BL_LOG(...) printf(__VA_ARGS__);
void appError(int err);
#define EXT_DISCOVERY_TIMEOUT_SECS 20

#ifdef __cplusplus
}

#include <lib/core/CHIPError.h>
void appError(CHIP_ERROR error);
#else
void appError(int err);
#endif
Loading

0 comments on commit 8f926b8

Please sign in to comment.