[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>
diff --git a/src/platform/nxp/common/CHIPDeviceNXPPlatformDefaultConfig.h b/src/platform/nxp/common/CHIPDeviceNXPPlatformDefaultConfig.h
index fba6a32..28e2603 100644
--- a/src/platform/nxp/common/CHIPDeviceNXPPlatformDefaultConfig.h
+++ b/src/platform/nxp/common/CHIPDeviceNXPPlatformDefaultConfig.h
@@ -106,3 +106,15 @@
#define CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONABLE_DISCOVERY 1
#define CHIP_DEVICE_CONFIG_ENABLE_EXTENDED_DISCOVERY 1
#endif
+
+#ifndef CHIP_DEVICE_CONFIG_USE_ZEPHYR_BLE
+#define CHIP_DEVICE_CONFIG_USE_ZEPHYR_BLE 1
+#endif // CHIP_DEVICE_CONFIG_USE_ZEPHYR_BLE
+
+#ifndef CHIP_DEVICE_CONFIG_PROCESS_BLE_IN_THREAD
+#define CHIP_DEVICE_CONFIG_PROCESS_BLE_IN_THREAD 0
+#endif // CHIP_DEVICE_CONFIG_PROCESS_BLE_IN_THREAD
+
+#ifndef CHIP_DEVICE_CONFIG_INIT_OT_PLAT_ALARM
+#define CHIP_DEVICE_CONFIG_INIT_OT_PLAT_ALARM 1
+#endif // CHIP_DEVICE_CONFIG_INIT_OT_PLAT_ALARM
diff --git a/src/platform/nxp/common/CHIPDevicePlatformEvent.h b/src/platform/nxp/common/CHIPDevicePlatformEvent.h
index 4ea4ffc..5c6a5c3 100644
--- a/src/platform/nxp/common/CHIPDevicePlatformEvent.h
+++ b/src/platform/nxp/common/CHIPDevicePlatformEvent.h
@@ -24,7 +24,7 @@
*/
#pragma once
-#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE
+#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE && CHIP_DEVICE_CONFIG_USE_ZEPHYR_BLE
#include <sys/atomic.h>
#include <toolchain.h>
#include <zephyr/bluetooth/bluetooth.h>
@@ -74,7 +74,7 @@
} // namespace DeviceEventType
-#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE
+#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE && CHIP_DEVICE_CONFIG_USE_ZEPHYR_BLE
struct BleConnEventType
{
bt_conn * BtConn;
@@ -108,7 +108,7 @@
{
union
{
-#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE
+#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE && CHIP_DEVICE_CONFIG_USE_ZEPHYR_BLE
BleConnEventType BleConnEvent;
BleCCCWriteEventType BleCCCWriteEvent;
BleC1WriteEventType BleC1WriteEvent;
diff --git a/src/platform/nxp/common/CHIPNXPPlatformDefaultConfig.h b/src/platform/nxp/common/CHIPNXPPlatformDefaultConfig.h
index 9282ffb..0c263fc 100644
--- a/src/platform/nxp/common/CHIPNXPPlatformDefaultConfig.h
+++ b/src/platform/nxp/common/CHIPNXPPlatformDefaultConfig.h
@@ -217,6 +217,34 @@
#define WDM_PUBLISHER_MAX_NOTIFIES_IN_FLIGHT 2
#endif // WDM_PUBLISHER_MAX_NOTIFIES_IN_FLIGHT
+// ==================== ICD Configuration Overrides ====================
+
+#ifndef NXP_ICD_ENABLED
+#define NXP_ICD_ENABLED 0
+#endif // NXP_ICD_ENABLED
+
+#if NXP_ICD_ENABLED
+#ifndef CHIP_CONFIG_ICD_IDLE_MODE_DURATION_SEC
+#define CHIP_CONFIG_ICD_IDLE_MODE_DURATION_SEC NXP_IDLE_MODE_DURATION_SEC
+#endif // CHIP_CONFIG_ICD_IDLE_MODE_DURATION_SEC
+
+#ifndef CHIP_CONFIG_ICD_ACTIVE_MODE_DURATION_MS
+#define CHIP_CONFIG_ICD_ACTIVE_MODE_DURATION_MS NXP_ACTIVE_MODE_DURATION_MS
+#endif // CHIP_CONFIG_ICD_ACTIVE_MODE_DURATION_MS
+
+#ifndef CHIP_CONFIG_ICD_ACTIVE_MODE_THRESHOLD_MS
+#define CHIP_CONFIG_ICD_ACTIVE_MODE_THRESHOLD_MS NXP_ACTIVE_MODE_THRESHOLD
+#endif // CHIP_CONFIG_ICD_ACTIVE_MODE_THRESHOLD_MS
+
+#ifndef CHIP_CONFIG_ICD_CLIENTS_SUPPORTED_PER_FABRIC
+#define CHIP_CONFIG_ICD_CLIENTS_SUPPORTED_PER_FABRIC NXP_ICD_SUPPORTED_CLIENTS_PER_FABRIC
+#endif // CHIP_CONFIG_ICD_CLIENTS_SUPPORTED_PER_FABRIC
+
+#ifndef CHIP_CONFIG_SYNCHRONOUS_REPORTS_ENABLED
+#define CHIP_CONFIG_SYNCHRONOUS_REPORTS_ENABLED 1
+#endif
+#endif // NXP_ICD_ENABLED
+
// ==================== Other Configuration Overrides ====================
#ifndef CHIP_CONFIG_RMP_DEFAULT_MAX_RETRANS
diff --git a/src/platform/nxp/common/ConfigurationManagerImpl.cpp b/src/platform/nxp/common/ConfigurationManagerImpl.cpp
index e99f913..ad8f00e 100644
--- a/src/platform/nxp/common/ConfigurationManagerImpl.cpp
+++ b/src/platform/nxp/common/ConfigurationManagerImpl.cpp
@@ -33,6 +33,10 @@
#include "fsl_device_registers.h"
+#if CONFIG_BOOT_REASON_SDK_SUPPORT
+#include "fsl_power.h"
+#endif
+
#if CONFIG_CHIP_PLAT_LOAD_REAL_FACTORY_DATA
#include "FactoryDataProvider.h"
#endif
@@ -54,12 +58,61 @@
return sInstance;
}
+#if CONFIG_BOOT_REASON_SDK_SUPPORT
+CHIP_ERROR ConfigurationManagerImpl::DetermineBootReason(uint8_t rebootCause)
+{
+ /*
+ With current implementation kBrownOutReset couldn't be catched
+ */
+ BootReasonType bootReason = BootReasonType::kUnspecified;
+
+ if (rebootCause == 0)
+ {
+ bootReason = BootReasonType::kPowerOnReboot;
+ }
+
+ else if (rebootCause == kPOWER_ResetCauseWdt)
+ {
+ /* Reboot can be due to hardware or software watchdog */
+ bootReason = BootReasonType::kHardwareWatchdogReset;
+ }
+ else if (rebootCause == kPOWER_ResetCauseSysResetReq)
+ {
+ /*
+ kConfigKey_SoftwareUpdateCompleted not supported for now
+ if (NXPConfig::ConfigValueExists(NXPConfig::kConfigKey_SoftwareUpdateCompleted))
+ {
+ bootReason = BootReasonType::kSoftwareUpdateCompleted;
+ }
+ else
+ {
+ bootReason = BootReasonType::kSoftwareReset;
+ }
+ */
+ bootReason = BootReasonType::kSoftwareReset;
+ }
+
+ return StoreBootReason(to_underlying(bootReason));
+}
+#endif
+
+CHIP_ERROR ConfigurationManagerImpl::StoreSoftwareUpdateCompleted()
+{
+ /* Empty implementation*/
+ return CHIP_NO_ERROR;
+}
+
CHIP_ERROR ConfigurationManagerImpl::Init()
{
CHIP_ERROR err;
uint32_t rebootCount = 0;
bool failSafeArmed;
+#if CONFIG_BOOT_REASON_SDK_SUPPORT
+ uint8_t rebootCause = POWER_GetResetCause();
+ POWER_ClearResetCause(rebootCause);
+#endif
+
// Initialize the generic implementation base class.
err = Internal::GenericConfigurationManagerImpl<NXPConfig>::Init();
SuccessOrExit(err);
@@ -84,12 +137,15 @@
err = StoreTotalOperationalHours(0);
SuccessOrExit(err);
}
-
+#if CONFIG_BOOT_REASON_SDK_SUPPORT
+ SuccessOrExit(err = DetermineBootReason(rebootCause));
+#else
if (!NXPConfig::ConfigValueExists(NXPConfig::kCounterKey_BootReason))
{
err = StoreBootReason(to_underlying(BootReasonType::kUnspecified));
SuccessOrExit(err);
}
+#endif
// TODO: Initialize the global GroupKeyStore object here
diff --git a/src/platform/nxp/common/ConfigurationManagerImpl.h b/src/platform/nxp/common/ConfigurationManagerImpl.h
index 062cc9d..e680942 100644
--- a/src/platform/nxp/common/ConfigurationManagerImpl.h
+++ b/src/platform/nxp/common/ConfigurationManagerImpl.h
@@ -39,6 +39,7 @@
public:
// This returns an instance of this class.
static ConfigurationManagerImpl & GetDefaultInstance();
+ CHIP_ERROR StoreSoftwareUpdateCompleted();
private:
// ===== Members that implement the ConfigurationManager public interface.
@@ -78,6 +79,9 @@
// ===== Private members reserved for use by this class only.
static void DoFactoryReset(intptr_t arg);
+#if CONFIG_BOOT_REASON_SDK_SUPPORT
+ CHIP_ERROR DetermineBootReason(uint8_t rebootCause);
+#endif
};
/**
diff --git a/src/platform/nxp/common/ConnectivityManagerImpl.cpp b/src/platform/nxp/common/ConnectivityManagerImpl.cpp
index 0386de6..cbdb866 100644
--- a/src/platform/nxp/common/ConnectivityManagerImpl.cpp
+++ b/src/platform/nxp/common/ConnectivityManagerImpl.cpp
@@ -32,10 +32,12 @@
#include <platform/internal/GenericConnectivityManagerImpl_TCP.ipp>
#endif
+#if CHIP_SYSTEM_CONFIG_USE_LWIP
#include <lwip/dns.h>
#include <lwip/ip_addr.h>
#include <lwip/nd6.h>
#include <lwip/netif.h>
+#endif
#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE
#include <platform/internal/GenericConnectivityManagerImpl_BLE.ipp>
diff --git a/src/platform/nxp/common/DiagnosticDataProviderImpl.cpp b/src/platform/nxp/common/DiagnosticDataProviderImpl.cpp
index 0dd9b52..93a73d2 100644
--- a/src/platform/nxp/common/DiagnosticDataProviderImpl.cpp
+++ b/src/platform/nxp/common/DiagnosticDataProviderImpl.cpp
@@ -29,7 +29,10 @@
#include <platform/DiagnosticDataProvider.h>
#include <inet/InetInterface.h>
+
+#if CHIP_SYSTEM_CONFIG_USE_LWIP
#include <lwip/tcpip.h>
+#endif
#if CHIP_DEVICE_CONFIG_ENABLE_WPA
extern "C" {
diff --git a/src/platform/nxp/common/ThreadStackManagerImpl.cpp b/src/platform/nxp/common/ThreadStackManagerImpl.cpp
index b15ad60..5667eef 100644
--- a/src/platform/nxp/common/ThreadStackManagerImpl.cpp
+++ b/src/platform/nxp/common/ThreadStackManagerImpl.cpp
@@ -20,8 +20,7 @@
/**
* @file
* Provides an implementation of the ThreadStackManager object for
- * NXP platforms using the NXP SDK and the OpenThread
- * stack.
+ * NXP platforms using the NXP SDK and the OpenThread stack.
*
*/
@@ -32,7 +31,11 @@
#include <platform/ThreadStackManager.h>
#include <platform/FreeRTOS/GenericThreadStackManagerImpl_FreeRTOS.hpp>
+#if CHIP_SYSTEM_CONFIG_USE_LWIP
#include <platform/OpenThread/GenericThreadStackManagerImpl_OpenThread_LwIP.cpp>
+#else
+#include <platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.hpp>
+#endif
#include <lib/support/CHIPPlatformMemory.h>
@@ -59,21 +62,44 @@
{
CHIP_ERROR err = CHIP_NO_ERROR;
+#if CHIP_DEVICE_CONFIG_INIT_OT_PLAT_ALARM
/* Initialize the OpenThread Alarm module to make sure that if calling otInstance,
* it can schedule events
*/
otPlatAlarmInit();
+#endif
// Initialize the generic implementation base classes.
err = GenericThreadStackManagerImpl_FreeRTOS<ThreadStackManagerImpl>::DoInit();
SuccessOrExit(err);
+#if CHIP_SYSTEM_CONFIG_USE_LWIP
err = GenericThreadStackManagerImpl_OpenThread_LwIP<ThreadStackManagerImpl>::DoInit(NULL);
+#else
+ err = GenericThreadStackManagerImpl_OpenThread<ThreadStackManagerImpl>::DoInit(NULL);
+#endif
SuccessOrExit(err);
exit:
return err;
}
+#if CHIP_DEVICE_CONFIG_PROCESS_BLE_IN_THREAD
+void ThreadStackManagerImpl::ProcessThreadActivity()
+{
+ /* reuse thread task for ble processing.
+ * by doing this, we avoid allocating a new stack for short-lived
+ * BLE processing (e.g.: only during Matter commissioning)
+ */
+#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE
+ auto * bleManager = &chip::DeviceLayer::Internal::BLEMgrImpl();
+ bleManager->DoBleProcessing();
+#endif
+
+ otTaskletsProcess(OTInstance());
+ otSysProcessDrivers(OTInstance());
+}
+#endif
+
bool ThreadStackManagerImpl::IsInitialized()
{
return sInstance.mThreadStackLock != NULL;
@@ -112,3 +138,8 @@
{
return CHIPPlatformMemoryFree(aPtr);
}
+
+extern "C" void * otPlatRealloc(void * p, size_t aSize)
+{
+ return CHIPPlatformMemoryRealloc(p, aSize);
+}
diff --git a/src/platform/nxp/common/ThreadStackManagerImpl.h b/src/platform/nxp/common/ThreadStackManagerImpl.h
index 6f9fae8..83990db 100644
--- a/src/platform/nxp/common/ThreadStackManagerImpl.h
+++ b/src/platform/nxp/common/ThreadStackManagerImpl.h
@@ -28,7 +28,11 @@
#include <openthread/tasklet.h>
#include <openthread/thread.h>
#include <platform/FreeRTOS/GenericThreadStackManagerImpl_FreeRTOS.h>
+#if CHIP_SYSTEM_CONFIG_USE_LWIP
#include <platform/OpenThread/GenericThreadStackManagerImpl_OpenThread_LwIP.h>
+#else
+#include <platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.h>
+#endif
extern "C" void otSysEventSignalPending(void);
@@ -43,7 +47,11 @@
* using the NXP SDK and the OpenThread stack.
*/
class ThreadStackManagerImpl final : public ThreadStackManager,
+#if CHIP_SYSTEM_CONFIG_USE_LWIP
public Internal::GenericThreadStackManagerImpl_OpenThread_LwIP<ThreadStackManagerImpl>,
+#else
+ public Internal::GenericThreadStackManagerImpl_OpenThread<ThreadStackManagerImpl>,
+#endif
public Internal::GenericThreadStackManagerImpl_FreeRTOS<ThreadStackManagerImpl>
{
// Allow the ThreadStackManager interface class to delegate method calls to
@@ -53,8 +61,11 @@
// Allow the generic implementation base classes to call helper methods on
// this class.
#ifndef DOXYGEN_SHOULD_SKIP_THIS
- friend Internal::GenericThreadStackManagerImpl_OpenThread<ThreadStackManagerImpl>;
+#if CHIP_SYSTEM_CONFIG_USE_LWIP
friend Internal::GenericThreadStackManagerImpl_OpenThread_LwIP<ThreadStackManagerImpl>;
+#else
+ friend Internal::GenericThreadStackManagerImpl_OpenThread<ThreadStackManagerImpl>;
+#endif
friend Internal::GenericThreadStackManagerImpl_FreeRTOS<ThreadStackManagerImpl>;
#endif
@@ -66,6 +77,11 @@
public:
// ===== Platform-specific members that may be accessed directly by the application.
+#if CHIP_DEVICE_CONFIG_PROCESS_BLE_IN_THREAD
+ using ThreadStackManager::ProcessThreadActivity;
+ void ProcessThreadActivity();
+#endif
+
protected:
// ===== Methods that implement the ThreadStackManager abstract interface.
CHIP_ERROR _InitThreadStack(void);