Skip to content

Commit

Permalink
Merge 181c2da into d73a1ba
Browse files Browse the repository at this point in the history
  • Loading branch information
jmartinez-silabs authored Oct 13, 2020
2 parents d73a1ba + 181c2da commit 1415422
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 58 deletions.
6 changes: 5 additions & 1 deletion examples/lighting-app/efr32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,11 @@ efr32_executable("lighting_app") {
ldscript = "${efr32_project_dir}/ldscripts/efr32-light-example-MG21.ld"
}

ldflags = [ "-T" + rebase_path(ldscript, root_build_dir) ]
ldflags = [
"-Wl,--print-memory-usage",
"-fstack-usage",
"-T" + rebase_path(ldscript, root_build_dir),
]
}

group("efr32") {
Expand Down
4 changes: 2 additions & 2 deletions examples/lighting-app/efr32/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ class AppTask
{
kFunction_NoneSelected = 0,
kFunction_SoftwareUpdate = 0,
kFunction_FactoryReset,
kFunction_StartThread = 1,
kFunction_FactoryReset = 2,

kFunction_Invalid
} Function;

Function_t mFunction;
bool mFunctionTimerActive;
bool mSyncClusterToButtonAction;
chip::Ble::BLEEndPoint * mBLEEndPoint;

static AppTask sAppTask;
};
Expand Down
29 changes: 18 additions & 11 deletions examples/lighting-app/efr32/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@
#include <setup_payload/QRCodeSetupPayloadGenerator.h>
#include <setup_payload/SetupPayload.h>

using namespace chip::TLV;
using namespace chip::DeviceLayer;

#include <platform/CHIPDeviceLayer.h>
#if CHIP_ENABLE_OPENTHREAD
#include <platform/EFR32/ThreadStackManagerImpl.h>
Expand Down Expand Up @@ -67,6 +64,7 @@ static bool sIsThreadAttached = false;
static bool sHaveBLEConnections = false;
static bool sHaveServiceConnectivity = false;

using namespace chip::TLV;
using namespace ::chip::DeviceLayer;

AppTask AppTask::sAppTask;
Expand Down Expand Up @@ -355,7 +353,7 @@ void AppTask::FunctionTimerEventHandler(AppEvent * aEvent)

// If we reached here, the button was held past FACTORY_RESET_TRIGGER_TIMEOUT,
// initiate factory reset
if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_SoftwareUpdate)
if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_StartThread)
{
EFR32_LOG("Factory Reset Triggered. Release button within %ums to cancel.", FACTORY_RESET_CANCEL_WINDOW_TIMEOUT);

Expand Down Expand Up @@ -400,20 +398,29 @@ void AppTask::FunctionHandler(AppEvent * aEvent)
if (!sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_NoneSelected)
{
sAppTask.StartTimer(FACTORY_RESET_TRIGGER_TIMEOUT);
sAppTask.mFunction = kFunction_SoftwareUpdate;
sAppTask.mFunction = kFunction_StartThread;
}
}
else
{
// If the button was released before factory reset got initiated, trigger a
// software update.
if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_SoftwareUpdate)
// If the button was released before factory reset got initiated, start Thread Network
if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_StartThread)
{
sAppTask.CancelTimer();

sAppTask.mFunction = kFunction_NoneSelected;

EFR32_LOG("Software Update currently not supported.");
#if CHIP_ENABLE_OPENTHREAD
if (!chip::DeviceLayer::ConnectivityMgr().IsThreadProvisioned())
{
StartDefaultThreadNetwork();
EFR32_LOG("Device is not commissioned to a Thread network. Starting with the default configuration.");
}
else
{
EFR32_LOG("Device is commissioned to a Thread network.");
}
#elif
EFR32_LOG("Thread is not defined.");
#endif
}
else if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_FactoryReset)
{
Expand Down
6 changes: 5 additions & 1 deletion examples/lock-app/efr32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,11 @@ efr32_executable("lock_app") {
ldscript = "${efr32_project_dir}/ldscripts/efr32-lock-example-MG21.ld"
}

ldflags = [ "-T" + rebase_path(ldscript, root_build_dir) ]
ldflags = [
"-Wl,--print-memory-usage",
"-fstack-usage",
"-T" + rebase_path(ldscript, root_build_dir),
]
}

group("efr32") {
Expand Down
3 changes: 1 addition & 2 deletions examples/lock-app/efr32/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class AppTask
{
kFunction_NoneSelected = 0,
kFunction_SoftwareUpdate = 0,
kFunction_Joiner = 1,
kFunction_StartThread = 1,
kFunction_FactoryReset = 2,

kFunction_Invalid
Expand All @@ -76,7 +76,6 @@ class AppTask
Function_t mFunction;
bool mFunctionTimerActive;
bool mSyncClusterToButtonAction;
chip::Ble::BLEEndPoint * mBLEEndPoint;

static AppTask sAppTask;
};
Expand Down
52 changes: 17 additions & 35 deletions examples/lock-app/efr32/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,12 @@
#include <setup_payload/QRCodeSetupPayloadGenerator.h>
#include <setup_payload/SetupPayload.h>

using namespace chip::TLV;
using namespace chip::DeviceLayer;

#include <platform/CHIPDeviceLayer.h>
#if CHIP_ENABLE_OPENTHREAD
#include <platform/EFR32/ThreadStackManagerImpl.h>
#include <platform/OpenThread/OpenThreadUtils.h>
#include <platform/ThreadStackManager.h>
#include <platform/internal/DeviceNetworkInfo.h>
#define JOINER_START_TRIGGER_TIMEOUT 1500
#endif

#define FACTORY_RESET_TRIGGER_TIMEOUT 3000
Expand All @@ -68,6 +64,7 @@ static bool sIsPairedToAccount = false;
static bool sHaveBLEConnections = false;
static bool sHaveServiceConnectivity = false;

using namespace chip::TLV;
using namespace ::chip::DeviceLayer;

AppTask AppTask::sAppTask;
Expand Down Expand Up @@ -358,17 +355,8 @@ void AppTask::FunctionTimerEventHandler(AppEvent * aEvent)

// If we reached here, the button was held past FACTORY_RESET_TRIGGER_TIMEOUT,
// initiate factory reset
if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_SoftwareUpdate)
{
#if CHIP_ENABLE_OPENTHREAD
EFR32_LOG("Release button now to Start Thread Joiner");
EFR32_LOG("Hold to trigger Factory Reset");
sAppTask.mFunction = kFunction_Joiner;
sAppTask.StartTimer(FACTORY_RESET_TRIGGER_TIMEOUT);
}
else if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_Joiner)
if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_StartThread)
{
#endif
EFR32_LOG("Factory Reset Triggered. Release button within %ums to cancel.", FACTORY_RESET_CANCEL_WINDOW_TIMEOUT);

// Start timer for FACTORY_RESET_CANCEL_WINDOW_TIMEOUT to allow user to
Expand Down Expand Up @@ -411,37 +399,31 @@ void AppTask::FunctionHandler(AppEvent * aEvent)
{
if (!sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_NoneSelected)
{
#if CHIP_ENABLE_OPENTHREAD
sAppTask.StartTimer(JOINER_START_TRIGGER_TIMEOUT);
#else
sAppTask.StartTimer(FACTORY_RESET_TRIGGER_TIMEOUT);
#endif

sAppTask.mFunction = kFunction_SoftwareUpdate;
sAppTask.mFunction = kFunction_StartThread;
}
}
else
{
// If the button was released before factory reset got initiated, trigger a
// software update.
if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_SoftwareUpdate)
// If the button was released before factory reset got initiated, start Thread Network
if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_StartThread)
{
sAppTask.CancelTimer();

sAppTask.mFunction = kFunction_NoneSelected;

EFR32_LOG("Software Update currently not supported.");
}
#if CHIP_ENABLE_OPENTHREAD
else if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_Joiner)
{
sAppTask.CancelTimer();
sAppTask.mFunction = kFunction_NoneSelected;

CHIP_ERROR error = ThreadStackMgr().JoinerStart();
EFR32_LOG("Thread joiner triggered: %s", chip::ErrorStr(error));
}
if (!chip::DeviceLayer::ConnectivityMgr().IsThreadProvisioned())
{
StartDefaultThreadNetwork();
EFR32_LOG("Device is not commissioned to a Thread network. Starting with the default configuration.");
}
else
{
EFR32_LOG("Device is commissioned to a Thread network.");
}
#elif
EFR32_LOG("Thread is not defined.");
#endif
}
else if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_FactoryReset)
{
// Set lock status LED back to show state of lock.
Expand Down
29 changes: 29 additions & 0 deletions examples/platform/efr32/Service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,32 @@ void PublishService()
}
ThreadStackMgrImpl().UnlockThreadStack();
}

void StartDefaultThreadNetwork(void)
{
// Set default thread network Info and enable the etWORK

chip::DeviceLayer::Internal::DeviceNetworkInfo deviceNetworkInfo;
memset(&deviceNetworkInfo, 0, sizeof(deviceNetworkInfo));
const char * networkName = "OpenThread";
const uint8_t masterKey[chip::DeviceLayer::Internal::kThreadNetworkKeyLength] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55,
0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb,
0xcc, 0xdd, 0xee, 0xff };
const uint8_t threadMeshPrefix[chip::DeviceLayer::Internal::kThreadMeshPrefixLength] = { 0xfd, 0xde, 0xad, 0x00,
0xbe, 0xef, 0x00, 0x00 };

const uint8_t extendedPanId[chip::DeviceLayer::Internal::kThreadExtendedPANIdLength] = { 0xDE, 0xAD, 0x00, 0xBE,
0xEF, 0x00, 0xCA, 0xFE };
memcpy(deviceNetworkInfo.ThreadNetworkName, networkName, strlen(networkName));
memcpy(deviceNetworkInfo.ThreadExtendedPANId, extendedPanId, sizeof(extendedPanId));
deviceNetworkInfo.FieldPresent.ThreadExtendedPANId = true;
memcpy(deviceNetworkInfo.ThreadNetworkKey, masterKey, sizeof(masterKey));
deviceNetworkInfo.FieldPresent.ThreadMeshPrefix = true;
memcpy(deviceNetworkInfo.ThreadMeshPrefix, threadMeshPrefix, sizeof(threadMeshPrefix));
deviceNetworkInfo.ThreadPANId = 0x1234;
deviceNetworkInfo.ThreadChannel = 11;

chip::DeviceLayer::ThreadStackMgr().SetThreadEnabled(false);
chip::DeviceLayer::ThreadStackMgr().SetThreadProvision(deviceNetworkInfo);
chip::DeviceLayer::ThreadStackMgr().SetThreadEnabled(true);
}
1 change: 1 addition & 0 deletions examples/platform/efr32/Service.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@

void SetDeviceName(const char * newDeviceName);
void PublishService();
void StartDefaultThreadNetwork(void);
4 changes: 2 additions & 2 deletions src/platform/EFR32/CHIPDevicePlatformConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,11 @@
#endif // CHIP_DEVICE_CONFIG_BLE_APP_TASK_STACK_SIZE

#ifndef CHIP_DEVICE_CONFIG_CHIP_TASK_STACK_SIZE
#define CHIP_DEVICE_CONFIG_CHIP_TASK_STACK_SIZE 8192
#define CHIP_DEVICE_CONFIG_CHIP_TASK_STACK_SIZE 4096
#endif // CHIP_DEVICE_CONFIG_CHIP_TASK_STACK_SIZE

#ifndef CHIP_DEVICE_CONFIG_THREAD_TASK_STACK_SIZE
#define CHIP_DEVICE_CONFIG_THREAD_TASK_STACK_SIZE 8192
#define CHIP_DEVICE_CONFIG_THREAD_TASK_STACK_SIZE 4096
#endif // CHIP_DEVICE_CONFIG_THREAD_TASK_STACK_SIZE

#define CHIP_DEVICE_CONFIG_ENABLE_WIFI_TELEMETRY 0
Expand Down
10 changes: 6 additions & 4 deletions third_party/efr32_sdk/efr32_arm.gni
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@

import("efr32_board.gni")

arm_arch = "armv7e-m"
arm_abi = "aapcs"
arm_cpu = "cortex-m4"

if (efr32_family == "efr32mg12") {
arm_arch = "armv7e-m"
arm_abi = "aapcs"
arm_cpu = "cortex-m4"
arm_float_abi = "softfp"
arm_fpu = "fpv4-sp-d16"
} else if (efr32_family == "efr32mg21") {
arm_arch = "armv8-m.main+dsp"
arm_abi = "aapcs"
arm_cpu = "cortex-m33"
arm_float_abi = "hard"
arm_fpu = "fpv5-sp-d16"
}

0 comments on commit 1415422

Please sign in to comment.