Skip to content

Commit

Permalink
EFR32: Windows application modifications
Browse files Browse the repository at this point in the history
  • Loading branch information
silabs-srishylam committed Aug 26, 2022
1 parent 7870328 commit 05fe3d8
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 36 deletions.
1 change: 1 addition & 0 deletions examples/window-app/common/include/WindowApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ class WindowApp

virtual ~WindowApp() = default;
virtual CHIP_ERROR Init();
virtual CHIP_ERROR StartAppTask();
virtual CHIP_ERROR Start() = 0;
virtual CHIP_ERROR Run();
virtual void Finish();
Expand Down
27 changes: 27 additions & 0 deletions examples/window-app/common/src/WindowApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ using namespace ::chip::Credentials;
using namespace ::chip::DeviceLayer;
using namespace chip::app::Clusters::WindowCovering;

#ifdef SL_WIFI
#include "wfx_host_events.h"
#include <app/clusters/network-commissioning/network-commissioning.h>
#include <platform/EFR32/NetworkCommissioningWiFiDriver.h>
#endif

#ifdef SL_WIFI
chip::app::Clusters::NetworkCommissioning::Instance
sWiFiNetworkCommissioningInstance(0 /* Endpoint Id */, &(chip::DeviceLayer::NetworkCommissioning::SlWiFiDriver::GetInstance()));
#endif

inline void OnTriggerEffectCompleted(chip::System::Layer * systemLayer, void * appState)
{
WindowApp::Instance().PostEvent(WindowApp::EventId::WinkOff);
Expand Down Expand Up @@ -109,10 +120,26 @@ WindowApp::Cover * WindowApp::GetCover(chip::EndpointId endpoint)
return nullptr;
}

CHIP_ERROR WindowApp::StartAppTask() { return CHIP_NO_ERROR;}

CHIP_ERROR WindowApp::Init()
{
ConfigurationMgr().LogDeviceConfig();

#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 */
sWiFiNetworkCommissioningInstance.Init();
#endif

// Timers
mLongPressTimer = CreateTimer("Timer:LongPress", LONG_PRESS_TIMEOUT, OnLongPressTimeout, this);

Expand Down
2 changes: 2 additions & 0 deletions examples/window-app/efr32/include/WindowAppImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class WindowAppImpl : public WindowApp
static WindowAppImpl sInstance;

WindowAppImpl();
CHIP_ERROR StartAppTask(void);
static void AppTaskMain(void * pvParameter);
CHIP_ERROR Init() override;
CHIP_ERROR Start() override;
void Finish() override;
Expand Down
70 changes: 37 additions & 33 deletions examples/window-app/efr32/src/WindowAppImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,13 @@
#include <sl_simple_led_instances.h>
#include <sl_system_kernel.h>

#ifdef SL_WIFI
#include "wfx_host_events.h"
#endif

#ifdef DISPLAY_ENABLED
#include <LcdPainter.h>
SilabsLCD slLCD;
#endif

#define APP_TASK_STACK_SIZE (4096)
#define APP_MAIN_TASK_SIZE (APP_TASK_STACK_SIZE + 2048)
#define APP_TASK_PRIORITY 2
#define APP_EVENT_QUEUE_SIZE 10
#define EXAMPLE_VENDOR_ID 0xcafe
Expand All @@ -54,7 +51,6 @@ using namespace chip::app::Clusters::WindowCovering;
//------------------------------------------------------------------------------
// Timers
//------------------------------------------------------------------------------

WindowAppImpl::Timer::Timer(const char * name, uint32_t timeoutInMs, Callback callback, void * context) :
WindowApp::Timer(name, timeoutInMs, callback, context)
{
Expand Down Expand Up @@ -125,7 +121,9 @@ void WindowAppImpl::Timer::TimerCallback(TimerHandle_t xTimer)
//------------------------------------------------------------------------------

StackType_t sAppStack[APP_TASK_STACK_SIZE / sizeof(StackType_t)];
StackType_t sAppMainStack[APP_MAIN_TASK_SIZE / sizeof(StackType_t)];
StaticTask_t sAppTaskStruct;
StaticTask_t sAppMainTaskStruct;

uint8_t sAppEventQueueBuffer[APP_EVENT_QUEUE_SIZE * sizeof(WindowApp::Event)];
StaticQueue_t sAppEventQueueStruct;
Expand Down Expand Up @@ -156,38 +154,30 @@ void WindowAppImpl::OnIconTimeout(WindowApp::Timer & timer)
#endif
}

CHIP_ERROR WindowAppImpl::Init()
CHIP_ERROR WindowAppImpl::StartAppTask()
{
#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
WindowApp::Init();

// Initialize App Task
mHandle = xTaskCreateStatic(OnTaskCallback, APP_TASK_NAME, ArraySize(sAppStack), NULL, 1, sAppStack, &sAppTaskStruct);
if (NULL == mHandle)
{
EFR32_LOG("Failed to allocate app task");
return CHIP_ERROR_NO_MEMORY;
}
// Start App task.
TaskHandle_t a = xTaskCreateStatic(AppTaskMain, APP_TASK_NAME, ArraySize(sAppMainStack), NULL, 1, sAppMainStack, &sAppMainTaskStruct);
return (a == nullptr) ? CHIP_ERROR_NO_MEMORY : CHIP_NO_ERROR;
}

// Initialize App Queue
mQueue = xQueueCreateStatic(APP_EVENT_QUEUE_SIZE, sizeof(WindowApp::Event), sAppEventQueueBuffer, &sAppEventQueueStruct);
if (NULL == mQueue)
void WindowAppImpl::AppTaskMain(void * pvParameter){
CHIP_ERROR err = sInstance.Init();
if (err != CHIP_NO_ERROR)
{
EFR32_LOG("Failed to allocate app event queue");
return CHIP_ERROR_NO_MEMORY;
EFR32_LOG("AppTask.Init() failed");
appError(err);
}
vTaskSuspend(NULL);
}

CHIP_ERROR WindowAppImpl::Init()
{
chip::DeviceLayer::PlatformMgr().LockChipStack();
WindowApp::Init();
chip::DeviceLayer::PlatformMgr().UnlockChipStack();
// Initialize App Task

// Initialize LEDs
LEDWidget::InitGpio();
mStatusLED.Init(APP_STATE_LED);
Expand All @@ -197,7 +187,21 @@ CHIP_ERROR WindowAppImpl::Init()
slLCD.Init();
#endif

return CHIP_NO_ERROR;
mHandle = xTaskCreateStatic(OnTaskCallback, APP_TASK_NAME, ArraySize(sAppStack), NULL, 1, sAppStack, &sAppTaskStruct);
if (NULL == mHandle)
{
EFR32_LOG("Failed to allocate app task");
return CHIP_ERROR_NO_MEMORY;
}

// Initialize App Queue
mQueue = xQueueCreateStatic(APP_EVENT_QUEUE_SIZE, sizeof(WindowApp::Event), sAppEventQueueBuffer, &sAppEventQueueStruct);
if (NULL == mQueue)
{
EFR32_LOG("Failed to allocate app event queue");
return CHIP_ERROR_NO_MEMORY;
}
return CHIP_NO_ERROR;
}

CHIP_ERROR WindowAppImpl::Start()
Expand Down
7 changes: 4 additions & 3 deletions examples/window-app/efr32/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,9 @@ int main(void)
chip::DeviceLayer::SetDeviceInfoProvider(&gExampleDeviceInfoProvider);

WindowApp & app = WindowApp::Instance();

EFR32_LOG("Starting App");

chip::DeviceLayer::PlatformMgr().LockChipStack();
err = app.Init();
// err = app.Init();
// Initialize device attestation config
#ifdef EFR32_ATTESTATION_CREDENTIALS
SetDeviceAttestationCredentialsProvider(EFR32::GetEFR32DacProvider());
Expand All @@ -69,6 +68,8 @@ int main(void)
#endif
chip::DeviceLayer::PlatformMgr().UnlockChipStack();

EFR32_LOG("Starting App Task");
err = app.StartAppTask();
if (err != CHIP_NO_ERROR)
{
EFR32_LOG("App Init failed");
Expand Down

0 comments on commit 05fe3d8

Please sign in to comment.