Skip to content

Commit d4c2eaf

Browse files
[NXP][common][mcxw71_k32w1] Update ButtonApp::HandleLongPress and PlatformManagerImpl (project-chip#35989)
* [nxp][examples][common] Schedule ButtonApp::HandleLongPress on Matter task * Remove CleanReset call * Schedule button work on matter task. This code is run from interrupt and Reset might call some functions (e.g. LogEvent) that must be run from matter task. See PlatformMgr().HandleServerShuttingDown() from PlatformManagerImpl::_Shutdown. Signed-off-by: Andrei Menzopol <andrei.menzopol@nxp.com> * [nxp][platform][mcxw71_k32w1] Update PlatformManagerImpl.cpp * Add .HandleServerShuttingDown PlatformManagerImpl::_Shutdown() * Use NVIC_SystemReset instead of HAL_ResetMCU * Rename CleanReset to Reset Signed-off-by: Andrei Menzopol <andrei.menzopol@nxp.com> * Restyled by clang-format --------- Signed-off-by: Andrei Menzopol <andrei.menzopol@nxp.com> Co-authored-by: Restyled.io <commits@restyled.io>
1 parent 50b5dfb commit d4c2eaf

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

examples/platform/nxp/common/matter_button/source/ButtonApp.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,14 @@ void chip::NXP::App::ButtonApp::HandleShortPress()
4848

4949
void chip::NXP::App::ButtonApp::HandleLongPress()
5050
{
51-
chip::DeviceLayer::PlatformMgrImpl().CleanReset();
51+
// Execute "clean" reset
52+
chip::DeviceLayer::PlatformMgr().ScheduleWork(
53+
[](intptr_t arg) {
54+
chip::DeviceLayer::PlatformMgr().StopEventLoopTask();
55+
chip::DeviceLayer::PlatformMgr().Shutdown();
56+
chip::DeviceLayer::PlatformMgrImpl().Reset();
57+
},
58+
(intptr_t) nullptr);
5259
}
5360

5461
void chip::NXP::App::ButtonApp::HandleDoubleClick()

src/platform/nxp/mcxw71_k32w1/PlatformManagerImpl.cpp

+10-5
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848

4949
#include <mbedtls/platform.h>
5050

51-
extern "C" void HAL_ResetMCU(void);
5251
extern "C" void freertos_mbedtls_mutex_init(void);
5352

5453
extern uint8_t __data_end__[], m_data0_end[];
@@ -93,14 +92,16 @@ CHIP_ERROR PlatformManagerImpl::ServiceInit(void)
9392
return CHIP_NO_ERROR;
9493
}
9594

96-
void PlatformManagerImpl::CleanReset()
95+
void PlatformManagerImpl::Reset()
9796
{
98-
StopEventLoopTask();
99-
Shutdown();
10097
#if (CHIP_PLAT_NVM_SUPPORT == 1)
10198
NvCompletePendingOperations();
10299
#endif
103-
HAL_ResetMCU();
100+
// Restart the system.
101+
NVIC_SystemReset();
102+
while (1)
103+
{
104+
}
104105
}
105106

106107
void PlatformManagerImpl::ScheduleResetInIdle(void)
@@ -200,6 +201,10 @@ void PlatformManagerImpl::_Shutdown()
200201
ChipLogError(DeviceLayer, "Failed to get current uptime since the Node’s last reboot");
201202
}
202203

204+
/* Handle the server shutting down & emit the ShutDown event */
205+
/* Make sure to call this function from Matter Task */
206+
PlatformMgr().HandleServerShuttingDown();
207+
/* Shutdown all layers */
203208
Internal::GenericPlatformManagerImpl_FreeRTOS<PlatformManagerImpl>::_Shutdown();
204209
}
205210

src/platform/nxp/mcxw71_k32w1/PlatformManagerImpl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class PlatformManagerImpl final : public PlatformManager, public Internal::Gener
5151
System::Clock::Timestamp GetStartTime() { return mStartTime; }
5252
void HardwareInit(void);
5353
CHIP_ERROR ServiceInit(void);
54-
void CleanReset();
54+
void Reset();
5555
void StopBLEConnectivity() {}
5656
void ScheduleResetInIdle(void);
5757
bool GetResetInIdleValue(void);

0 commit comments

Comments
 (0)