Skip to content

Commit

Permalink
fix sed consumption (#20450)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkardous-silabs authored Jul 7, 2022
1 parent 5810508 commit e39b339
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
44 changes: 38 additions & 6 deletions examples/light-switch-app/efr32/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@
#include "AppTask.h"
#include "AppConfig.h"
#include "AppEvent.h"
#if !(defined(CHIP_DEVICE_CONFIG_ENABLE_SED) && CHIP_DEVICE_CONFIG_ENABLE_SED)
#include "LEDWidget.h"
#endif // !(defined(CHIP_DEVICE_CONFIG_ENABLE_SED) && CHIP_DEVICE_CONFIG_ENABLE_SED)
#include "binding-handler.h"
#if !(defined(CHIP_DEVICE_CONFIG_ENABLE_SED) && CHIP_DEVICE_CONFIG_ENABLE_SED)
#include "sl_simple_led_instances.h"

#endif // !(defined(CHIP_DEVICE_CONFIG_ENABLE_SED) && CHIP_DEVICE_CONFIG_ENABLE_SED)
#ifdef DISPLAY_ENABLED
#include "lcd.h"
#ifdef QR_CODE_ENABLED
Expand Down Expand Up @@ -67,8 +70,10 @@
#define APP_EVENT_QUEUE_SIZE 10
#define EXAMPLE_VENDOR_ID 0xcafe

#if !(defined(CHIP_DEVICE_CONFIG_ENABLE_SED) && CHIP_DEVICE_CONFIG_ENABLE_SED)
#define SYSTEM_STATE_LED &sl_led_led0
#define LIGHT_LED &sl_led_led1
#endif // !(defined(CHIP_DEVICE_CONFIG_ENABLE_SED) && CHIP_DEVICE_CONFIG_ENABLE_SED)

#define APP_FUNCTION_BUTTON &sl_button_btn0
#define APP_LIGHT_SWITCH &sl_button_btn1

Expand All @@ -81,31 +86,41 @@ TimerHandle_t sFunctionTimer; // FreeRTOS app sw timer.
TaskHandle_t sAppTaskHandle;
QueueHandle_t sAppEventQueue;

#if !(defined(CHIP_DEVICE_CONFIG_ENABLE_SED) && CHIP_DEVICE_CONFIG_ENABLE_SED)
LEDWidget sStatusLED;
#endif // !(defined(CHIP_DEVICE_CONFIG_ENABLE_SED) && CHIP_DEVICE_CONFIG_ENABLE_SED)

#ifdef SL_WIFI

#if !(defined(CHIP_DEVICE_CONFIG_ENABLE_SED) && CHIP_DEVICE_CONFIG_ENABLE_SED)
bool sIsWiFiProvisioned = false;
bool sIsWiFiEnabled = false;
bool sIsWiFiAttached = false;
#endif // !CHIP_DEVICE_CONFIG_ENABLE_SED

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

#if !(defined(CHIP_DEVICE_CONFIG_ENABLE_SED) && CHIP_DEVICE_CONFIG_ENABLE_SED)
#if CHIP_ENABLE_OPENTHREAD
bool sIsThreadProvisioned = false;
bool sIsThreadEnabled = false;
#endif /* CHIP_ENABLE_OPENTHREAD */
bool sHaveBLEConnections = false;
#endif // !CHIP_DEVICE_CONFIG_ENABLE_SED

#if !(defined(CHIP_DEVICE_CONFIG_ENABLE_SED) && CHIP_DEVICE_CONFIG_ENABLE_SED)
EmberAfIdentifyEffectIdentifier sIdentifyEffect = EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_STOP_EFFECT;
#endif // !(defined(CHIP_DEVICE_CONFIG_ENABLE_SED) && CHIP_DEVICE_CONFIG_ENABLE_SED)

uint8_t sAppEventQueueBuffer[APP_EVENT_QUEUE_SIZE * sizeof(AppEvent)];
StaticQueue_t sAppEventQueueStruct;

StackType_t appStack[APP_TASK_STACK_SIZE / sizeof(StackType_t)];
StaticTask_t appTaskStruct;

#if !(defined(CHIP_DEVICE_CONFIG_ENABLE_SED) && CHIP_DEVICE_CONFIG_ENABLE_SED)
namespace {
void OnTriggerIdentifyEffectCompleted(chip::System::Layer * systemLayer, void * appState)
{
Expand Down Expand Up @@ -153,6 +168,8 @@ Identify gIdentify = {
EMBER_ZCL_IDENTIFY_IDENTIFY_TYPE_VISIBLE_LED,
OnTriggerIdentifyEffect,
};
#endif // #if !(defined(CHIP_DEVICE_CONFIG_ENABLE_SED) && CHIP_DEVICE_CONFIG_ENABLE_SED)

} // namespace
using namespace chip::TLV;
using namespace ::chip::DeviceLayer;
Expand Down Expand Up @@ -216,8 +233,10 @@ CHIP_ERROR AppTask::Init()
LightMgr().SetCallbacks(ActionInitiated, ActionCompleted);

// Initialize LEDs
#if !(defined(CHIP_DEVICE_CONFIG_ENABLE_SED) && CHIP_DEVICE_CONFIG_ENABLE_SED)
LEDWidget::InitGpio();
sStatusLED.Init(SYSTEM_STATE_LED);
#endif
UpdateClusterState();

ConfigurationMgr().LogDeviceConfig();
Expand Down Expand Up @@ -266,13 +285,17 @@ void AppTask::AppTaskMain(void * pvParameter)

while (true)
{
BaseType_t eventReceived = xQueueReceive(sAppEventQueue, &event, pdMS_TO_TICKS(10));
#if !(defined(CHIP_DEVICE_CONFIG_ENABLE_SED) && CHIP_DEVICE_CONFIG_ENABLE_SED)
BaseType_t eventReceived = xQueueReceive(sAppEventQueue, &event, 10);
#else
BaseType_t eventReceived = xQueueReceive(sAppEventQueue, &event, portMAX_DELAY);
#endif // !(defined(CHIP_DEVICE_CONFIG_ENABLE_SED) && CHIP_DEVICE_CONFIG_ENABLE_SED)
while (eventReceived == pdTRUE)
{
sAppTask.DispatchEvent(&event);
eventReceived = xQueueReceive(sAppEventQueue, &event, 0);
}

#if !(defined(CHIP_DEVICE_CONFIG_ENABLE_SED) && CHIP_DEVICE_CONFIG_ENABLE_SED)
// Collect connectivity and configuration state from the CHIP stack. Because
// the CHIP event loop is being run in a separate task, the stack must be
// locked while these values are queried. However we use a non-blocking
Expand Down Expand Up @@ -334,11 +357,18 @@ void AppTask::AppTaskMain(void * pvParameter)
{
sStatusLED.Blink(950, 50);
}
else if (sHaveBLEConnections) { sStatusLED.Blink(100, 100); }
else { sStatusLED.Blink(50, 950); }
else if (sHaveBLEConnections)
{
sStatusLED.Blink(100, 100);
}
else
{
sStatusLED.Blink(50, 950);
}
}

sStatusLED.Animate();
#endif // #if !(defined(CHIP_DEVICE_CONFIG_ENABLE_SED) && CHIP_DEVICE_CONFIG_ENABLE_SED)
}
}

Expand Down Expand Up @@ -407,8 +437,10 @@ void AppTask::FunctionTimerEventHandler(AppEvent * aEvent)

// Turn off all LEDs before starting blink to make sure blink is
// co-ordinated.
#if !(defined(CHIP_DEVICE_CONFIG_ENABLE_SED) && CHIP_DEVICE_CONFIG_ENABLE_SED)
sStatusLED.Set(false);
sStatusLED.Blink(500);
#endif // !(defined(CHIP_DEVICE_CONFIG_ENABLE_SED) && CHIP_DEVICE_CONFIG_ENABLE_SED)
}
else if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_FactoryReset)
{
Expand Down
1 change: 1 addition & 0 deletions third_party/openthread/platforms/efr32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ source_set("libopenthread-efr32") {
"${openthread_efr32_root}/src/src/misc.c",
"${openthread_efr32_root}/src/src/radio.c",
"${openthread_efr32_root}/src/src/security_manager.c",
"${openthread_efr32_root}/src/src/sleep.c",
"${openthread_efr32_root}/src/src/system.c",
"${openthread_root}/examples/apps/cli/cli_uart.cpp",
]
Expand Down

0 comments on commit e39b339

Please sign in to comment.