Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Telink] Improved cpu performance #19100

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions examples/light-switch-app/telink/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,14 @@ class AppTask

void DispatchEvent(AppEvent * event);

static void UpdateStatusLED();
static void SwitchActionButtonEventHandler(void);
static void FactoryResetButtonEventHandler(void);
static void StartThreadButtonEventHandler(void);
static void StartBleAdvButtonEventHandler(void);

static void ChipEventHandler(const chip::DeviceLayer::ChipDeviceEvent * event, intptr_t arg);

static void FactoryResetHandler(AppEvent * aEvent);
static void StartThreadHandler(AppEvent * aEvent);
static void SwitchActionEventHandler(AppEvent * aEvent);
Expand Down
84 changes: 53 additions & 31 deletions examples/light-switch-app/telink/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ CHIP_ERROR AppTask::Init()
LEDWidget::InitGpio(SYSTEM_STATE_LED_PORT);
sStatusLED.Init(SYSTEM_STATE_LED_PIN);

UpdateStatusLED();

InitButtons();

// Init ZCL Data Model and start server
Expand All @@ -108,6 +110,11 @@ CHIP_ERROR AppTask::Init()

PrintOnboardingCodes(chip::RendezvousInformationFlags(chip::RendezvousInformationFlag::kBLE));

// Add CHIP event handler and start CHIP thread.
// Note that all the initialization code should happen prior to this point to avoid data races
// between the main and the CHIP threads.
PlatformMgr().AddEventHandler(ChipEventHandler, 0);

ret = ConnectivityMgr().SetBLEDeviceName("TelinkSwitch");
if (ret != CHIP_NO_ERROR)
{
Expand Down Expand Up @@ -140,37 +147,6 @@ CHIP_ERROR AppTask::StartApp()
ret = k_msgq_get(&sAppEventQueue, &event, K_NO_WAIT);
}

// 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 lock request
// (TryLockChipStack()) to avoid blocking other UI activities when the CHIP
// task is busy (e.g. with a long crypto operation).

if (PlatformMgr().TryLockChipStack())
{
sIsThreadProvisioned = ConnectivityMgr().IsThreadProvisioned();
sIsThreadEnabled = ConnectivityMgr().IsThreadEnabled();
sIsThreadAttached = ConnectivityMgr().IsThreadAttached();
sHaveBLEConnections = (ConnectivityMgr().NumBLEConnections() != 0);
PlatformMgr().UnlockChipStack();
}

if (sIsThreadProvisioned && sIsThreadEnabled)
{
if (sIsThreadAttached)
{
sStatusLED.Blink(950, 50);
}
else
{
sStatusLED.Blink(100, 100);
}
}
else
{
sStatusLED.Blink(50, 950);
}

sStatusLED.Animate();
}
}
Expand Down Expand Up @@ -273,6 +249,52 @@ void AppTask::StartBleAdvHandler(AppEvent * aEvent)
}
}

void AppTask::UpdateStatusLED()
{
if (sIsThreadProvisioned && sIsThreadEnabled)
{
if (sIsThreadAttached)
{
sStatusLED.Blink(950, 50);
}
else
{
sStatusLED.Blink(100, 100);
}
}
else
{
sStatusLED.Blink(50, 950);
}
}

void AppTask::ChipEventHandler(const ChipDeviceEvent * event, intptr_t /* arg */)
{
switch (event->Type)
{
case DeviceEventType::kCHIPoBLEAdvertisingChange:
sHaveBLEConnections = ConnectivityMgr().NumBLEConnections() != 0;
UpdateStatusLED();
break;
case DeviceEventType::kThreadStateChange:
sIsThreadProvisioned = ConnectivityMgr().IsThreadProvisioned();
sIsThreadEnabled = ConnectivityMgr().IsThreadEnabled();
sIsThreadAttached = ConnectivityMgr().IsThreadAttached();
UpdateStatusLED();
break;
case DeviceEventType::kThreadConnectivityChange:
#if CONFIG_CHIP_OTA_REQUESTOR
if (event->ThreadConnectivityChange.Result == kConnectivity_Established)
{
InitBasicOTARequestor();
}
#endif
break;
default:
break;
}
}

void AppTask::ActionInitiated(AppTask::Action_t aAction, int32_t aActor) {}

void AppTask::ActionCompleted(AppTask::Action_t aAction, int32_t aActor)
Expand Down
3 changes: 3 additions & 0 deletions examples/lighting-app/telink/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,14 @@ class AppTask

void DispatchEvent(AppEvent * event);

static void UpdateStatusLED();
static void LightingActionButtonEventHandler(void);
static void FactoryResetButtonEventHandler(void);
static void StartThreadButtonEventHandler(void);
static void StartBleAdvButtonEventHandler(void);

static void ChipEventHandler(const chip::DeviceLayer::ChipDeviceEvent * event, intptr_t arg);

static void FactoryResetHandler(AppEvent * aEvent);
static void StartThreadHandler(AppEvent * aEvent);
static void LightingActionEventHandler(AppEvent * aEvent);
Expand Down
84 changes: 53 additions & 31 deletions examples/lighting-app/telink/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ CHIP_ERROR AppTask::Init()
LEDWidget::InitGpio(SYSTEM_STATE_LED_PORT);
sStatusLED.Init(SYSTEM_STATE_LED_PIN);

UpdateStatusLED();

InitButtons();

// Init lighting manager
Expand All @@ -109,6 +111,11 @@ CHIP_ERROR AppTask::Init()
ConfigurationMgr().LogDeviceConfig();
PrintOnboardingCodes(chip::RendezvousInformationFlags(chip::RendezvousInformationFlag::kBLE));

// Add CHIP event handler and start CHIP thread.
// Note that all the initialization code should happen prior to this point to avoid data races
// between the main and the CHIP threads.
PlatformMgr().AddEventHandler(ChipEventHandler, 0);

ret = ConnectivityMgr().SetBLEDeviceName("TelinkLight");
if (ret != CHIP_NO_ERROR)
{
Expand Down Expand Up @@ -141,37 +148,6 @@ CHIP_ERROR AppTask::StartApp()
ret = k_msgq_get(&sAppEventQueue, &event, K_NO_WAIT);
}

// 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 lock request
// (TryLockChipStack()) to avoid blocking other UI activities when the CHIP
// task is busy (e.g. with a long crypto operation).

if (PlatformMgr().TryLockChipStack())
{
sIsThreadProvisioned = ConnectivityMgr().IsThreadProvisioned();
sIsThreadEnabled = ConnectivityMgr().IsThreadEnabled();
sIsThreadAttached = ConnectivityMgr().IsThreadAttached();
sHaveBLEConnections = (ConnectivityMgr().NumBLEConnections() != 0);
PlatformMgr().UnlockChipStack();
}

if (sIsThreadProvisioned && sIsThreadEnabled)
{
if (sIsThreadAttached)
{
sStatusLED.Blink(950, 50);
}
else
{
sStatusLED.Blink(100, 100);
}
}
else
{
sStatusLED.Blink(50, 950);
}

sStatusLED.Animate();
}
}
Expand Down Expand Up @@ -282,6 +258,52 @@ void AppTask::StartBleAdvHandler(AppEvent * aEvent)
}
}

void AppTask::UpdateStatusLED()
{
if (sIsThreadProvisioned && sIsThreadEnabled)
{
if (sIsThreadAttached)
{
sStatusLED.Blink(950, 50);
}
else
{
sStatusLED.Blink(100, 100);
}
}
else
{
sStatusLED.Blink(50, 950);
}
}

void AppTask::ChipEventHandler(const ChipDeviceEvent * event, intptr_t /* arg */)
{
switch (event->Type)
{
case DeviceEventType::kCHIPoBLEAdvertisingChange:
sHaveBLEConnections = ConnectivityMgr().NumBLEConnections() != 0;
UpdateStatusLED();
break;
case DeviceEventType::kThreadStateChange:
sIsThreadProvisioned = ConnectivityMgr().IsThreadProvisioned();
sIsThreadEnabled = ConnectivityMgr().IsThreadEnabled();
sIsThreadAttached = ConnectivityMgr().IsThreadAttached();
UpdateStatusLED();
break;
case DeviceEventType::kThreadConnectivityChange:
#if CONFIG_CHIP_OTA_REQUESTOR
if (event->ThreadConnectivityChange.Result == kConnectivity_Established)
{
InitBasicOTARequestor();
}
#endif
break;
default:
break;
}
}

void AppTask::ActionInitiated(LightingManager::Action_t aAction, int32_t aActor)
{
if (aAction == LightingManager::ON_ACTION)
Expand Down