Skip to content

Commit 47fee48

Browse files
[NXP] Add some common platform changes (#34159)
* [NXP][platform][common] Add support of boot reason Signed-off-by: Martin Girardot <martin.girardot@nxp.com> * [NXP][platform][common] Update some components - Add StoreSoftwareUpdateCompleted API with empty implementation - Add ICD flags in common config header - Create CHIP_DEVICE_CONFIG_USE_ZEPHYR_BLE flag for BLE Zephry usage - Enclose CHIPDevicePlatformEvent header sections under CHIP_DEVICE_CONFIG_USE_ZEPHYR_BLE - Enclose lwip specific headers under CHIP_SYSTEM_CONFIG_USE_LWIP - Add temporary flag CHIP_DEVICE_CONFIG_INIT_OT_PLAT_ALARM to condition otPlatAlarmInit call. Some platforms are doing this separately and two calls will break things. - Add CHIP_DEVICE_CONFIG_PROCESS_BLE_IN_THREAD flag to override ProcessThreadActivity by extending its default implementation. Some platforms opt to do the BLE processing inside the Thread task, to avoid creating a separate BLE app task. Signed-off-by: marius-alex-tache <marius.tache@nxp.com> --------- Signed-off-by: Martin Girardot <martin.girardot@nxp.com> Signed-off-by: marius-alex-tache <marius.tache@nxp.com> Co-authored-by: Martin Girardot <martin.girardot@nxp.com>
1 parent c6af674 commit 47fee48

9 files changed

+159
-7
lines changed

src/platform/nxp/common/CHIPDeviceNXPPlatformDefaultConfig.h

+12
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,15 @@
106106
#define CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONABLE_DISCOVERY 1
107107
#define CHIP_DEVICE_CONFIG_ENABLE_EXTENDED_DISCOVERY 1
108108
#endif
109+
110+
#ifndef CHIP_DEVICE_CONFIG_USE_ZEPHYR_BLE
111+
#define CHIP_DEVICE_CONFIG_USE_ZEPHYR_BLE 1
112+
#endif // CHIP_DEVICE_CONFIG_USE_ZEPHYR_BLE
113+
114+
#ifndef CHIP_DEVICE_CONFIG_PROCESS_BLE_IN_THREAD
115+
#define CHIP_DEVICE_CONFIG_PROCESS_BLE_IN_THREAD 0
116+
#endif // CHIP_DEVICE_CONFIG_PROCESS_BLE_IN_THREAD
117+
118+
#ifndef CHIP_DEVICE_CONFIG_INIT_OT_PLAT_ALARM
119+
#define CHIP_DEVICE_CONFIG_INIT_OT_PLAT_ALARM 1
120+
#endif // CHIP_DEVICE_CONFIG_INIT_OT_PLAT_ALARM

src/platform/nxp/common/CHIPDevicePlatformEvent.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
*/
2525

2626
#pragma once
27-
#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE
27+
#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE && CHIP_DEVICE_CONFIG_USE_ZEPHYR_BLE
2828
#include <sys/atomic.h>
2929
#include <toolchain.h>
3030
#include <zephyr/bluetooth/bluetooth.h>
@@ -74,7 +74,7 @@ enum InternalPlatformSpecificEventTypes
7474

7575
} // namespace DeviceEventType
7676

77-
#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE
77+
#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE && CHIP_DEVICE_CONFIG_USE_ZEPHYR_BLE
7878
struct BleConnEventType
7979
{
8080
bt_conn * BtConn;
@@ -108,7 +108,7 @@ struct ChipDevicePlatformEvent final
108108
{
109109
union
110110
{
111-
#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE
111+
#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE && CHIP_DEVICE_CONFIG_USE_ZEPHYR_BLE
112112
BleConnEventType BleConnEvent;
113113
BleCCCWriteEventType BleCCCWriteEvent;
114114
BleC1WriteEventType BleC1WriteEvent;

src/platform/nxp/common/CHIPNXPPlatformDefaultConfig.h

+28
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,34 @@
217217
#define WDM_PUBLISHER_MAX_NOTIFIES_IN_FLIGHT 2
218218
#endif // WDM_PUBLISHER_MAX_NOTIFIES_IN_FLIGHT
219219

220+
// ==================== ICD Configuration Overrides ====================
221+
222+
#ifndef NXP_ICD_ENABLED
223+
#define NXP_ICD_ENABLED 0
224+
#endif // NXP_ICD_ENABLED
225+
226+
#if NXP_ICD_ENABLED
227+
#ifndef CHIP_CONFIG_ICD_IDLE_MODE_DURATION_SEC
228+
#define CHIP_CONFIG_ICD_IDLE_MODE_DURATION_SEC NXP_IDLE_MODE_DURATION_SEC
229+
#endif // CHIP_CONFIG_ICD_IDLE_MODE_DURATION_SEC
230+
231+
#ifndef CHIP_CONFIG_ICD_ACTIVE_MODE_DURATION_MS
232+
#define CHIP_CONFIG_ICD_ACTIVE_MODE_DURATION_MS NXP_ACTIVE_MODE_DURATION_MS
233+
#endif // CHIP_CONFIG_ICD_ACTIVE_MODE_DURATION_MS
234+
235+
#ifndef CHIP_CONFIG_ICD_ACTIVE_MODE_THRESHOLD_MS
236+
#define CHIP_CONFIG_ICD_ACTIVE_MODE_THRESHOLD_MS NXP_ACTIVE_MODE_THRESHOLD
237+
#endif // CHIP_CONFIG_ICD_ACTIVE_MODE_THRESHOLD_MS
238+
239+
#ifndef CHIP_CONFIG_ICD_CLIENTS_SUPPORTED_PER_FABRIC
240+
#define CHIP_CONFIG_ICD_CLIENTS_SUPPORTED_PER_FABRIC NXP_ICD_SUPPORTED_CLIENTS_PER_FABRIC
241+
#endif // CHIP_CONFIG_ICD_CLIENTS_SUPPORTED_PER_FABRIC
242+
243+
#ifndef CHIP_CONFIG_SYNCHRONOUS_REPORTS_ENABLED
244+
#define CHIP_CONFIG_SYNCHRONOUS_REPORTS_ENABLED 1
245+
#endif
246+
#endif // NXP_ICD_ENABLED
247+
220248
// ==================== Other Configuration Overrides ====================
221249

222250
#ifndef CHIP_CONFIG_RMP_DEFAULT_MAX_RETRANS

src/platform/nxp/common/ConfigurationManagerImpl.cpp

+57-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333

3434
#include "fsl_device_registers.h"
3535

36+
#if CONFIG_BOOT_REASON_SDK_SUPPORT
37+
#include "fsl_power.h"
38+
#endif
39+
3640
#if CONFIG_CHIP_PLAT_LOAD_REAL_FACTORY_DATA
3741
#include "FactoryDataProvider.h"
3842
#endif
@@ -54,12 +58,61 @@ ConfigurationManagerImpl & ConfigurationManagerImpl::GetDefaultInstance()
5458
return sInstance;
5559
}
5660

61+
#if CONFIG_BOOT_REASON_SDK_SUPPORT
62+
CHIP_ERROR ConfigurationManagerImpl::DetermineBootReason(uint8_t rebootCause)
63+
{
64+
/*
65+
With current implementation kBrownOutReset couldn't be catched
66+
*/
67+
BootReasonType bootReason = BootReasonType::kUnspecified;
68+
69+
if (rebootCause == 0)
70+
{
71+
bootReason = BootReasonType::kPowerOnReboot;
72+
}
73+
74+
else if (rebootCause == kPOWER_ResetCauseWdt)
75+
{
76+
/* Reboot can be due to hardware or software watchdog */
77+
bootReason = BootReasonType::kHardwareWatchdogReset;
78+
}
79+
else if (rebootCause == kPOWER_ResetCauseSysResetReq)
80+
{
81+
/*
82+
kConfigKey_SoftwareUpdateCompleted not supported for now
83+
if (NXPConfig::ConfigValueExists(NXPConfig::kConfigKey_SoftwareUpdateCompleted))
84+
{
85+
bootReason = BootReasonType::kSoftwareUpdateCompleted;
86+
}
87+
else
88+
{
89+
bootReason = BootReasonType::kSoftwareReset;
90+
}
91+
*/
92+
bootReason = BootReasonType::kSoftwareReset;
93+
}
94+
95+
return StoreBootReason(to_underlying(bootReason));
96+
}
97+
#endif
98+
99+
CHIP_ERROR ConfigurationManagerImpl::StoreSoftwareUpdateCompleted()
100+
{
101+
/* Empty implementation*/
102+
return CHIP_NO_ERROR;
103+
}
104+
57105
CHIP_ERROR ConfigurationManagerImpl::Init()
58106
{
59107
CHIP_ERROR err;
60108
uint32_t rebootCount = 0;
61109
bool failSafeArmed;
62110

111+
#if CONFIG_BOOT_REASON_SDK_SUPPORT
112+
uint8_t rebootCause = POWER_GetResetCause();
113+
POWER_ClearResetCause(rebootCause);
114+
#endif
115+
63116
// Initialize the generic implementation base class.
64117
err = Internal::GenericConfigurationManagerImpl<NXPConfig>::Init();
65118
SuccessOrExit(err);
@@ -84,12 +137,15 @@ CHIP_ERROR ConfigurationManagerImpl::Init()
84137
err = StoreTotalOperationalHours(0);
85138
SuccessOrExit(err);
86139
}
87-
140+
#if CONFIG_BOOT_REASON_SDK_SUPPORT
141+
SuccessOrExit(err = DetermineBootReason(rebootCause));
142+
#else
88143
if (!NXPConfig::ConfigValueExists(NXPConfig::kCounterKey_BootReason))
89144
{
90145
err = StoreBootReason(to_underlying(BootReasonType::kUnspecified));
91146
SuccessOrExit(err);
92147
}
148+
#endif
93149

94150
// TODO: Initialize the global GroupKeyStore object here
95151

src/platform/nxp/common/ConfigurationManagerImpl.h

+4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class ConfigurationManagerImpl final : public Internal::GenericConfigurationMana
3939
public:
4040
// This returns an instance of this class.
4141
static ConfigurationManagerImpl & GetDefaultInstance();
42+
CHIP_ERROR StoreSoftwareUpdateCompleted();
4243

4344
private:
4445
// ===== Members that implement the ConfigurationManager public interface.
@@ -78,6 +79,9 @@ class ConfigurationManagerImpl final : public Internal::GenericConfigurationMana
7879
// ===== Private members reserved for use by this class only.
7980

8081
static void DoFactoryReset(intptr_t arg);
82+
#if CONFIG_BOOT_REASON_SDK_SUPPORT
83+
CHIP_ERROR DetermineBootReason(uint8_t rebootCause);
84+
#endif
8185
};
8286

8387
/**

src/platform/nxp/common/ConnectivityManagerImpl.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@
3232
#include <platform/internal/GenericConnectivityManagerImpl_TCP.ipp>
3333
#endif
3434

35+
#if CHIP_SYSTEM_CONFIG_USE_LWIP
3536
#include <lwip/dns.h>
3637
#include <lwip/ip_addr.h>
3738
#include <lwip/nd6.h>
3839
#include <lwip/netif.h>
40+
#endif
3941

4042
#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE
4143
#include <platform/internal/GenericConnectivityManagerImpl_BLE.ipp>

src/platform/nxp/common/DiagnosticDataProviderImpl.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@
2929
#include <platform/DiagnosticDataProvider.h>
3030

3131
#include <inet/InetInterface.h>
32+
33+
#if CHIP_SYSTEM_CONFIG_USE_LWIP
3234
#include <lwip/tcpip.h>
35+
#endif
3336

3437
#if CHIP_DEVICE_CONFIG_ENABLE_WPA
3538
extern "C" {

src/platform/nxp/common/ThreadStackManagerImpl.cpp

+33-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020
/**
2121
* @file
2222
* Provides an implementation of the ThreadStackManager object for
23-
* NXP platforms using the NXP SDK and the OpenThread
24-
* stack.
23+
* NXP platforms using the NXP SDK and the OpenThread stack.
2524
*
2625
*/
2726

@@ -32,7 +31,11 @@
3231
#include <platform/ThreadStackManager.h>
3332

3433
#include <platform/FreeRTOS/GenericThreadStackManagerImpl_FreeRTOS.hpp>
34+
#if CHIP_SYSTEM_CONFIG_USE_LWIP
3535
#include <platform/OpenThread/GenericThreadStackManagerImpl_OpenThread_LwIP.cpp>
36+
#else
37+
#include <platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.hpp>
38+
#endif
3639

3740
#include <lib/support/CHIPPlatformMemory.h>
3841

@@ -59,21 +62,44 @@ CHIP_ERROR ThreadStackManagerImpl::_InitThreadStack(void)
5962
{
6063
CHIP_ERROR err = CHIP_NO_ERROR;
6164

65+
#if CHIP_DEVICE_CONFIG_INIT_OT_PLAT_ALARM
6266
/* Initialize the OpenThread Alarm module to make sure that if calling otInstance,
6367
* it can schedule events
6468
*/
6569
otPlatAlarmInit();
70+
#endif
6671

6772
// Initialize the generic implementation base classes.
6873
err = GenericThreadStackManagerImpl_FreeRTOS<ThreadStackManagerImpl>::DoInit();
6974
SuccessOrExit(err);
75+
#if CHIP_SYSTEM_CONFIG_USE_LWIP
7076
err = GenericThreadStackManagerImpl_OpenThread_LwIP<ThreadStackManagerImpl>::DoInit(NULL);
77+
#else
78+
err = GenericThreadStackManagerImpl_OpenThread<ThreadStackManagerImpl>::DoInit(NULL);
79+
#endif
7180
SuccessOrExit(err);
7281

7382
exit:
7483
return err;
7584
}
7685

86+
#if CHIP_DEVICE_CONFIG_PROCESS_BLE_IN_THREAD
87+
void ThreadStackManagerImpl::ProcessThreadActivity()
88+
{
89+
/* reuse thread task for ble processing.
90+
* by doing this, we avoid allocating a new stack for short-lived
91+
* BLE processing (e.g.: only during Matter commissioning)
92+
*/
93+
#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE
94+
auto * bleManager = &chip::DeviceLayer::Internal::BLEMgrImpl();
95+
bleManager->DoBleProcessing();
96+
#endif
97+
98+
otTaskletsProcess(OTInstance());
99+
otSysProcessDrivers(OTInstance());
100+
}
101+
#endif
102+
77103
bool ThreadStackManagerImpl::IsInitialized()
78104
{
79105
return sInstance.mThreadStackLock != NULL;
@@ -112,3 +138,8 @@ extern "C" void otPlatFree(void * aPtr)
112138
{
113139
return CHIPPlatformMemoryFree(aPtr);
114140
}
141+
142+
extern "C" void * otPlatRealloc(void * p, size_t aSize)
143+
{
144+
return CHIPPlatformMemoryRealloc(p, aSize);
145+
}

src/platform/nxp/common/ThreadStackManagerImpl.h

+17-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@
2828
#include <openthread/tasklet.h>
2929
#include <openthread/thread.h>
3030
#include <platform/FreeRTOS/GenericThreadStackManagerImpl_FreeRTOS.h>
31+
#if CHIP_SYSTEM_CONFIG_USE_LWIP
3132
#include <platform/OpenThread/GenericThreadStackManagerImpl_OpenThread_LwIP.h>
33+
#else
34+
#include <platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.h>
35+
#endif
3236

3337
extern "C" void otSysEventSignalPending(void);
3438

@@ -43,7 +47,11 @@ class ThreadStackManagerImpl;
4347
* using the NXP SDK and the OpenThread stack.
4448
*/
4549
class ThreadStackManagerImpl final : public ThreadStackManager,
50+
#if CHIP_SYSTEM_CONFIG_USE_LWIP
4651
public Internal::GenericThreadStackManagerImpl_OpenThread_LwIP<ThreadStackManagerImpl>,
52+
#else
53+
public Internal::GenericThreadStackManagerImpl_OpenThread<ThreadStackManagerImpl>,
54+
#endif
4755
public Internal::GenericThreadStackManagerImpl_FreeRTOS<ThreadStackManagerImpl>
4856
{
4957
// Allow the ThreadStackManager interface class to delegate method calls to
@@ -53,8 +61,11 @@ class ThreadStackManagerImpl final : public ThreadStackManager,
5361
// Allow the generic implementation base classes to call helper methods on
5462
// this class.
5563
#ifndef DOXYGEN_SHOULD_SKIP_THIS
56-
friend Internal::GenericThreadStackManagerImpl_OpenThread<ThreadStackManagerImpl>;
64+
#if CHIP_SYSTEM_CONFIG_USE_LWIP
5765
friend Internal::GenericThreadStackManagerImpl_OpenThread_LwIP<ThreadStackManagerImpl>;
66+
#else
67+
friend Internal::GenericThreadStackManagerImpl_OpenThread<ThreadStackManagerImpl>;
68+
#endif
5869
friend Internal::GenericThreadStackManagerImpl_FreeRTOS<ThreadStackManagerImpl>;
5970
#endif
6071

@@ -66,6 +77,11 @@ class ThreadStackManagerImpl final : public ThreadStackManager,
6677
public:
6778
// ===== Platform-specific members that may be accessed directly by the application.
6879

80+
#if CHIP_DEVICE_CONFIG_PROCESS_BLE_IN_THREAD
81+
using ThreadStackManager::ProcessThreadActivity;
82+
void ProcessThreadActivity();
83+
#endif
84+
6985
protected:
7086
// ===== Methods that implement the ThreadStackManager abstract interface.
7187
CHIP_ERROR _InitThreadStack(void);

0 commit comments

Comments
 (0)