Skip to content

Commit 076483c

Browse files
switch logic to use FreeRTOS API
1 parent 0f79208 commit 076483c

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

examples/platform/silabs/FreeRTOSConfig.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ extern uint32_t SystemCoreClock;
128128
#include "SEGGER_SYSVIEW_FreeRTOS.h"
129129
#endif
130130

131+
#if defined(SL_EM4_SLEEP) && (SL_EM4_SLEEP == 1)
132+
void sl_matter_em4_check(uint32_t expected_idle_time_ms);
133+
#endif // defined(SL_EM4_SLEEP) && (SL_EM4_SLEEP == 1)
134+
131135
/*-----------------------------------------------------------
132136
* Application specific definitions.
133137
*
@@ -143,13 +147,17 @@ extern uint32_t SystemCoreClock;
143147
/* Energy saving modes. */
144148
#if defined(SL_CATALOG_POWER_MANAGER_PRESENT)
145149
#define configUSE_TICKLESS_IDLE 1
150+
#if defined(SL_EM4_SLEEP) && (SL_EM4_SLEEP == 1)
151+
#define configPRE_SLEEP_PROCESSING(x) sl_matter_em4_check(x)
152+
#endif // defined(SL_EM4_SLEEP) && (SL_EM4_SLEEP == 1)
146153
#elif (SLI_SI91X_MCU_INTERFACE && SL_ICD_ENABLED)
147154
#define configUSE_TICKLESS_IDLE 1
148155
#define configEXPECTED_IDLE_TIME_BEFORE_SLEEP 70
149156
#define configPRE_SLEEP_PROCESSING(x)
150157
#define configPOST_SLEEP_PROCESSING(x)
151158
#define configPRE_SUPPRESS_TICKS_AND_SLEEP_PROCESSING(x)
152159
#else
160+
#error "Power Manager should be present..."
153161
#define configUSE_TICKLESS_IDLE 0
154162
#endif // SL_CATALOG_POWER_MANAGER_PRESENT
155163

examples/platform/silabs/MatterConfig.cpp

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -394,22 +394,35 @@ extern "C" void vApplicationIdleHook(void)
394394
#endif // SL_CATALOG_SIMPLE_BUTTON_PRESENT
395395
SiWxPlatformInterface::sl_si91x_uart_power_requirement_handler();
396396
#endif
397+
}
398+
397399
#if CHIP_CONFIG_ENABLE_ICD_SERVER
398400
#if defined(SL_EM4_SLEEP) && (SL_EM4_SLEEP == 1)
401+
extern "C" void sl_matter_em4_check(uint32_t expected_idle_time_ms)
402+
{
399403
if(chip::ICDConfigurationData::GetInstance().GetICDMode() == chip::ICDConfigurationData::ICDMode::LIT)
400404
{
401-
uint32_t sleepTimeRemaining = 0;
402-
sl_sleeptimer_get_remaining_time_of_first_timer( SL_SLEEPTIMER_ANY_FLAG ,&sleepTimeRemaining);
403-
uint32_t sleepTimeMs = sl_sleeptimer_tick_to_ms(sleepTimeRemaining);
404405
uint32_t idleDuration_seconds = chip::ICDConfigurationData::GetInstance().GetIdleModeDuration().count();
405-
406+
uint32_t threshold_ms = idleDuration_seconds * SL_EM4_THRESHOLD_PERCENTAGE * 10;
407+
408+
ChipLogDetail(DeviceLayer, "Expected Idle time (ms): %lu", expected_idle_time_ms);
409+
410+
ChipLogDetail(DeviceLayer, "EM4 Threshold (hh::mm::ss): %ld:%ld:%ld", (threshold_ms / 3600000),
411+
(threshold_ms % 3600000) / 60000,
412+
((threshold_ms % 3600000) % 60000) / 1000);
413+
406414
// Since the sleep timer will never match the actual idle time (hardware latency, etc), we set a threshold
407415
// Multiply by 10 to converts seconds into milliseconds (e.g. 90% of 1000sec in ms is 1000*90*10 = 900000ms)
408-
if (sleepTimeMs >= (idleDuration_seconds * SL_EM4_THRESHOLD_PERCENTAGE * 10))
416+
if (expected_idle_time_ms >= (idleDuration_seconds * SL_EM4_THRESHOLD_PERCENTAGE * 10))
409417
{
410-
OnEM4Trigger(sleepTimeMs);
418+
419+
ChipLogDetail(DeviceLayer, "Going into EM4 for : %ld:%ld:%ld", (expected_idle_time_ms / 3600000),
420+
(expected_idle_time_ms % 3600000) / 60000,
421+
((expected_idle_time_ms % 3600000) % 60000) / 1000);
422+
423+
OnEM4Trigger(expected_idle_time_ms);
411424
}
412425
}
413-
#endif
414-
#endif
415426
}
427+
#endif // defined(SL_EM4_SLEEP) && (SL_EM4_SLEEP == 1)
428+
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER

0 commit comments

Comments
 (0)