Skip to content

Commit

Permalink
Add lock/unlock calls for efr32 examples (#15365)
Browse files Browse the repository at this point in the history
* add lock/unlock to lighting app

* add lock/unlock to light-switch app

* add lock/unlock to lock app

* Move event loop start for shell app

* add lock / unlock to window app

* disable lock tracking for ota-requestor-app

* PR review comments

* Update scheduleWork for light-switch

Co-authored-by: Boris Zbarsky <bzbarsky@apple.com>

* fix task start

* align window app tilt and lift

* Comment

Co-authored-by: Boris Zbarsky <bzbarsky@apple.com>
  • Loading branch information
2 people authored and jmeg-sfy committed Mar 8, 2022
1 parent 31bcccb commit abf3f37
Show file tree
Hide file tree
Showing 17 changed files with 197 additions and 47 deletions.
2 changes: 1 addition & 1 deletion examples/light-switch-app/efr32/include/binding-handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
#include "lib/core/CHIPError.h"

CHIP_ERROR InitBindingHandler();
void SwitchToggleOnOff();
void SwitchToggleOnOff(intptr_t context);
6 changes: 3 additions & 3 deletions examples/light-switch-app/efr32/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,11 @@ CHIP_ERROR AppTask::Init()
EFR32_LOG("APP: Done WiFi Init");
/* We will init server when we get IP */
#endif
// Init ZCL Data Model
chip::Server::GetInstance().Init();

chip::DeviceLayer::PlatformMgr().LockChipStack();
// Initialize device attestation config
SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider());
chip::DeviceLayer::PlatformMgr().UnlockChipStack();

// Create FreeRTOS sw timer for Function Selection.
sFunctionTimer = xTimerCreate("FnTmr", // Just a text name, not used by the RTOS kernel
Expand Down Expand Up @@ -337,7 +337,7 @@ void AppTask::SwitchActionEventHandler(AppEvent * aEvent)
{
if (aEvent->Type == AppEvent::kEventType_Button)
{
SwitchToggleOnOff();
chip::DeviceLayer::PlatformMgr().ScheduleWork(SwitchToggleOnOff, 0);
}
}

Expand Down
2 changes: 1 addition & 1 deletion examples/light-switch-app/efr32/src/binding-handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void BoundDeviceChangedHandler(const EmberBindingTableEntry * binding, chip::Dev
}
} // namespace

void SwitchToggleOnOff()
void SwitchToggleOnOff(intptr_t context)
{
chip::BindingManager::GetInstance().NotifyBoundClusterChanged(1, chip::app::Clusters::OnOff::Id, nullptr);
}
Expand Down
6 changes: 6 additions & 0 deletions examples/light-switch-app/efr32/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,19 @@ int main(void)
}
#endif // CHIP_ENABLE_OPENTHREAD

chip::DeviceLayer::PlatformMgr().LockChipStack();
// Init ZCL Data Model
chip::Server::GetInstance().Init();
chip::DeviceLayer::PlatformMgr().UnlockChipStack();

EFR32_LOG("Starting Platform Manager Event Loop");
ret = PlatformMgr().StartEventLoopTask();
if (ret != CHIP_NO_ERROR)
{
EFR32_LOG("PlatformMgr().StartEventLoopTask() failed");
appError(ret);
}

#ifdef WF200_WIFI
// Start wfx bus communication task.
wfx_bus_start();
Expand Down
2 changes: 1 addition & 1 deletion examples/lighting-app/efr32/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class AppTask
static void LightActionEventHandler(AppEvent * aEvent);
static void TimerEventHandler(TimerHandle_t xTimer);

static void UpdateClusterState(void);
static void UpdateClusterState(intptr_t context);

void StartTimer(uint32_t aTimeoutMs);

Expand Down
11 changes: 6 additions & 5 deletions examples/lighting-app/efr32/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,11 @@ CHIP_ERROR AppTask::Init()
EFR32_LOG("APP: Done WiFi Init");
/* We will init server when we get IP */
#endif
// Init ZCL Data Model
chip::Server::GetInstance().Init();

chip::DeviceLayer::PlatformMgr().LockChipStack();
// Initialize device attestation config
SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider());
chip::DeviceLayer::PlatformMgr().UnlockChipStack();

// Create FreeRTOS sw timer for Function Selection.
sFunctionTimer = xTimerCreate("FnTmr", // Just a text name, not used by the RTOS kernel
Expand Down Expand Up @@ -266,7 +266,8 @@ CHIP_ERROR AppTask::Init()
sStatusLED.Init(SYSTEM_STATE_LED);
sLightLED.Init(LIGHT_LED);
sLightLED.Set(LightMgr().IsLightOn());
UpdateClusterState();

chip::DeviceLayer::PlatformMgr().ScheduleWork(UpdateClusterState, reinterpret_cast<intptr_t>(nullptr));

ConfigurationMgr().LogDeviceConfig();

Expand Down Expand Up @@ -606,7 +607,7 @@ void AppTask::ActionCompleted(LightingManager::Action_t aAction)

if (sAppTask.mSyncClusterToButtonAction)
{
UpdateClusterState();
chip::DeviceLayer::PlatformMgr().ScheduleWork(UpdateClusterState, reinterpret_cast<intptr_t>(nullptr));
sAppTask.mSyncClusterToButtonAction = false;
}
}
Expand Down Expand Up @@ -665,7 +666,7 @@ void AppTask::DispatchEvent(AppEvent * aEvent)
}
}

void AppTask::UpdateClusterState(void)
void AppTask::UpdateClusterState(intptr_t context)
{
uint8_t newValue = LightMgr().IsLightOn();

Expand Down
8 changes: 8 additions & 0 deletions examples/lighting-app/efr32/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,19 @@ int main(void)
}
#endif // CHIP_ENABLE_OPENTHREAD

chip::DeviceLayer::PlatformMgr().LockChipStack();
// Init ZCL Data Model
chip::Server::GetInstance().Init();
chip::DeviceLayer::PlatformMgr().UnlockChipStack();

EFR32_LOG("Starting Platform Manager Event Loop");
ret = PlatformMgr().StartEventLoopTask();
if (ret != CHIP_NO_ERROR)
{
EFR32_LOG("PlatformMgr().StartEventLoopTask() failed");
appError(ret);
}

#ifdef WF200_WIFI
// Start wfx bus communication task.
wfx_bus_start();
Expand Down Expand Up @@ -203,7 +209,9 @@ int main(void)
*/
#endif
#ifdef EFR32_OTA_ENABLED
chip::DeviceLayer::PlatformMgr().LockChipStack();
OTAConfig::Init();
chip::DeviceLayer::PlatformMgr().UnlockChipStack();
#endif // EFR32_OTA_ENABLED

EFR32_LOG("Starting App Task");
Expand Down
2 changes: 1 addition & 1 deletion examples/lock-app/efr32/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class AppTask
static void LockActionEventHandler(AppEvent * aEvent);
static void TimerEventHandler(TimerHandle_t xTimer);

static void UpdateClusterState(void);
static void UpdateClusterState(intptr_t context);

void StartTimer(uint32_t aTimeoutMs);

Expand Down
10 changes: 5 additions & 5 deletions examples/lock-app/efr32/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ CHIP_ERROR AppTask::Init()
EFR32_LOG("APP: Done WiFi Init");
/* We will init server when we get IP */
#endif
// Init ZCL Data Model
chip::Server::GetInstance().Init();

chip::DeviceLayer::PlatformMgr().LockChipStack();
// Initialize device attestation config
SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider());
chip::DeviceLayer::PlatformMgr().UnlockChipStack();

// Create FreeRTOS sw timer for Function Selection.
sFunctionTimer = xTimerCreate("FnTmr", // Just a text name, not used by the RTOS kernel
Expand Down Expand Up @@ -156,7 +156,7 @@ CHIP_ERROR AppTask::Init()

sLockLED.Init(LOCK_STATE_LED);
sLockLED.Set(!BoltLockMgr().IsUnlocked());
UpdateClusterState();
chip::DeviceLayer::PlatformMgr().ScheduleWork(UpdateClusterState, reinterpret_cast<intptr_t>(nullptr));

ConfigurationMgr().LogDeviceConfig();

Expand Down Expand Up @@ -484,7 +484,7 @@ void AppTask::ActionCompleted(BoltLockManager::Action_t aAction)

if (sAppTask.mSyncClusterToButtonAction)
{
UpdateClusterState();
chip::DeviceLayer::PlatformMgr().ScheduleWork(UpdateClusterState, reinterpret_cast<intptr_t>(nullptr));
sAppTask.mSyncClusterToButtonAction = false;
}
}
Expand Down Expand Up @@ -539,7 +539,7 @@ void AppTask::DispatchEvent(AppEvent * aEvent)
}
}

void AppTask::UpdateClusterState(void)
void AppTask::UpdateClusterState(intptr_t context)
{
uint8_t newValue = !BoltLockMgr().IsUnlocked();

Expand Down
8 changes: 8 additions & 0 deletions examples/lock-app/efr32/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ int main(void)
}
#endif // CHIP_ENABLE_OPENTHREAD

chip::DeviceLayer::PlatformMgr().LockChipStack();
// Init ZCL Data Model
chip::Server::GetInstance().Init();
chip::DeviceLayer::PlatformMgr().UnlockChipStack();

EFR32_LOG("Starting Platform Manager Event Loop");
ret = PlatformMgr().StartEventLoopTask();
if (ret != CHIP_NO_ERROR)
Expand Down Expand Up @@ -192,8 +197,11 @@ int main(void)
#endif // SL_WFX_USE_SECURE_LINK
#endif /* WF200_WIFI */
#ifdef EFR32_OTA_ENABLED
chip::DeviceLayer::PlatformMgr().LockChipStack();
OTAConfig::Init();
chip::DeviceLayer::PlatformMgr().UnlockChipStack();
#endif // EFR32_OTA_ENABLED

EFR32_LOG("Starting App Task");
ret = GetAppTask().StartAppTask();
if (ret != CHIP_NO_ERROR)
Expand Down
4 changes: 4 additions & 0 deletions examples/ota-requestor-app/efr32/args.gni
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ pw_assert_BACKEND = "$dir_pw_assert_log"
chip_enable_openthread = true
chip_openthread_ftd = false

# Disable stack lock tracking
# Example will not be maintained in the long term and will be depraceted now that OTA is beeing intagrated into our examples
chip_stack_lock_tracking = "None"

declare_args() {
chip_enable_ota_requestor = true
}
2 changes: 2 additions & 0 deletions examples/ota-requestor-app/efr32/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,10 @@ CHIP_ERROR AppTask::Init()
// Init ZCL Data Model
chip::Server::GetInstance().Init();

chip::DeviceLayer::PlatformMgr().LockChipStack();
// Initialize device attestation config
SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider());
chip::DeviceLayer::PlatformMgr().UnlockChipStack();

// Create FreeRTOS sw timer for Function Selection.
sFunctionTimer = xTimerCreate("FnTmr", // Just a text name, not used by the RTOS kernel
Expand Down
17 changes: 9 additions & 8 deletions examples/shell/efr32/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,15 @@ int main(void)
appError(ret);
}
chip::DeviceLayer::ConnectivityMgr().SetBLEDeviceName("EFR32_SHELL");

EFR32_LOG("Starting Platform Manager Event Loop");
ret = PlatformMgr().StartEventLoopTask();
if (ret != CHIP_NO_ERROR)
{
EFR32_LOG("PlatformMgr().StartEventLoopTask() failed");
appError(ret);
}

#if CHIP_ENABLE_OPENTHREAD
EFR32_LOG("Initializing OpenThread stack");
ret = ThreadStackMgr().InitThreadStack();
Expand All @@ -136,14 +145,6 @@ int main(void)
}
#endif // CHIP_ENABLE_OPENTHREAD

EFR32_LOG("Starting Platform Manager Event Loop");
ret = PlatformMgr().StartEventLoopTask();
if (ret != CHIP_NO_ERROR)
{
EFR32_LOG("PlatformMgr().StartEventLoopTask() failed");
appError(ret);
}

#if CHIP_ENABLE_OPENTHREAD
EFR32_LOG("Starting OpenThread task");

Expand Down
15 changes: 15 additions & 0 deletions examples/window-app/common/include/WindowApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,21 @@ class WindowApp
Timer * mTiltTimer = nullptr;
OperationalState mLiftOpState = OperationalState::Stall;
OperationalState mTiltOpState = OperationalState::Stall;

struct CoverWorkData
{
chip::EndpointId mEndpointId;

union
{
chip::Percent100ths percent100ths;
OperationalStatus opStatus;
};
};

static void ScheduleTiltPositionSet(intptr_t arg);
static void ScheduleLiftPositionSet(intptr_t arg);
static void ScheduleOperationalStatusSetWithGlobalUpdate(intptr_t arg);
};

static WindowApp & Instance();
Expand Down
Loading

0 comments on commit abf3f37

Please sign in to comment.