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

[NXP][k32w1] Rework reference apps #34926

Merged
merged 52 commits into from
Aug 15, 2024
Merged
Changes from 1 commit
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
432a3d5
[NXP][platform][common] Update pw RPC flag in streamer_nxp
marius-alex-tache Apr 26, 2024
61e1ed1
[NXP][examples][common] Fix binding issue due to generated Zap flag r…
Martin-NXP Mar 11, 2024
17d3fcd
[NXP][examples][common] make-pretty update
dinabenamar Mar 21, 2024
7d8b409
[NXP][examples][common] Fix contact-sensor-app always returning empty…
marian-chereji-nxp Apr 17, 2024
52050ce
[NXP][examples][common] Call init using the base class reference
marius-alex-tache Mar 7, 2024
7ab8b46
[NXP][examples][common] Update app task common code
marius-alex-tache Mar 13, 2024
49f046f
[NXP][examples][common] Add additional common components
marius-alex-tache Mar 11, 2024
fb11017
[NXP][examples][common] Add missing header in Identify
marius-alex-tache Apr 25, 2024
620f5b3
[NXP][examples][common] Add multi-image OTA requestor initiator
marius-alex-tache Apr 25, 2024
0cdbd93
[NXP][examples][common] Update pw RPC implementation
marius-alex-tache Apr 26, 2024
8497a83
[NXP][examples][common] Small updates to common app code
marius-alex-tache May 8, 2024
20e3f0c
[NXP][examples][common] Make Animate pure virtual
marius-alex-tache May 20, 2024
e99c091
[NXP][examples][common] Add pw RPC init
marius-alex-tache May 21, 2024
c711556
[NXP][examples][common] Allow platforms to redefine the path to the F…
dinabenamar Apr 19, 2024
04549f1
[NXP][examples][common] Add TestEventTriggerDelegate
andrei-menzopol Jun 13, 2024
2c80ef5
[NXP][examples][common] Minor updates for some components
marius-alex-tache Jul 19, 2024
a01f2e0
[NXP][examples][common] Add initial version of lighting app
marius-alex-tache Apr 25, 2024
90f9450
[NXP][examples][common] Add initial version of contact sensor
marius-alex-tache Jul 19, 2024
701c801
[NXP][openthread][k32w1] Update mbedtls target
marius-alex-tache Jun 27, 2024
76b82ae
[NXP][platform][k32w] OTA/FactoryData changes
andrei-menzopol Apr 19, 2024
59a8fbf
[NXP][platform][k32w1] SDK 2.15 platform updates
andrei-menzopol Feb 23, 2024
2f20b3d
[NXP][platform][k32w1] Add "chip_key_storage" solution selector and l…
marian-chereji-nxp Feb 29, 2024
35976e6
[NXP][platform][k32w1] Add Zephyr NVS based key storage build option
marian-chereji-nxp Feb 28, 2024
5286a60
[NXP][examples][k32w1] App updates
marius-alex-tache Jun 26, 2024
2ff7754
[NXP][examples][k32w1] Update ZclCallbacks after transition to common…
marius-alex-tache Jul 19, 2024
f67e410
[NXP][k32w1] Remove k32w parent folder
marius-alex-tache Jul 19, 2024
91810b4
[NXP][platform][k32w1] Add FactoryDataDriver implementation
marius-alex-tache Jul 19, 2024
6d0de7b
[NXP][platform][k32w] Remove k32w/common
marius-alex-tache Jul 11, 2024
6ef126c
[NXP][scripts] Minor updates for NXP related scripts
marius-alex-tache Jun 27, 2024
d74e6d9
[NXP][platform][common] Add nxp_factory_data, nxp_ota gn targets
marius-alex-tache Feb 7, 2024
0e505b3
[NXP][platform][common] Create NXPConfigNVS.cpp file, remove NXPConfi…
Martin-NXP Feb 29, 2024
2498362
[NXP] revert mcxw71 headers
marius-alex-tache Aug 12, 2024
0659f55
[NXP][k32w1] Add default logging target
marius-alex-tache Aug 12, 2024
8365373
[NXP][k32w1] Update paths to reference nxp_matter_support
marius-alex-tache Aug 12, 2024
3eee1ac
[NXP] Bump nxp_matter_support
marius-alex-tache Aug 12, 2024
331c1de
Restyled by whitespace
restyled-commits Aug 12, 2024
1a1c128
Restyled by clang-format
restyled-commits Aug 12, 2024
06fb4d0
Restyled by gn
restyled-commits Aug 12, 2024
34c5e39
Restyled by prettier-markdown
restyled-commits Aug 12, 2024
8afe39b
Restyled by autopep8
restyled-commits Aug 12, 2024
6bf2a79
Restyled by isort
restyled-commits Aug 12, 2024
1ce6752
[NXP][k32w1] Fix gn import order
marius-alex-tache Aug 12, 2024
e0b5178
[NXP][k32w1] Fix wrong README reference
marius-alex-tache Aug 12, 2024
f9afafd
[NXP][k32w1] Update workflow docker image
marius-alex-tache Aug 12, 2024
e43140b
[NXP][rw61x] Adding nxp_ota and nxp_factory_data as they are now mand…
chapongatien Jul 17, 2024
2e62c7c
[NXP][platform][common] Fix build warning
yeaissa May 21, 2024
64f2686
Restyled by gn
restyled-commits Aug 12, 2024
29c29ec
[NXP][platform] Remove deprecated files
marius-alex-tache Aug 13, 2024
983ac33
[NXP][workflow] Create separate jobs for k32w0/k32w1
marius-alex-tache Aug 13, 2024
a31bd00
[NXP][k32w0] Adding nxp_ota and nxp_factory_data as they are now mand…
marius-alex-tache Jul 18, 2024
1c2025c
[NXP][scripts] Fix script issue when there is no --args
Martin-NXP Jul 31, 2024
084b400
[NXP][k32w1] Disable SMU2
marius-alex-tache Aug 14, 2024
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
Prev Previous commit
Next Next commit
[NXP][examples][common] Update app task common code
New task base API:
- PostEventsProcessedAction - this will be called in the main loop,
after all events have been processed. An example of concrete action
is to animate some LEDs.
- PrintOnboardingInfo - the default implementation remains the same.
It can be overwritten by the concrete application task class.
- AppMatter_DisallowDeviceToSleep/AppMatter_AllowDeviceToSleep -
An application that uses low power mode should overwrite the API to
implement the allow/disallow entering low power mechanism.
Before taking the OT mutex, the device is disallowed to enter low power.
The device is allowed to enter low power after the OT mutex is released.

Other changes:
- The app event queue handle should be static such that the concrete
application task can initialize it during Start() call.
- The ticksToWait passed to xQueueReceived is used to specify
the maximum amount of time the task should block waiting for an event.
This can be modified according to the application needs, e.g. is needed
by an application that has LED animation.
- PostEvent should take into account ISR context when populating the event queue.
- PostEvent becomes a static method.
- Thread device type is specified by the following flag: CONFIG_THREAD_DEVICE_TYPE
This is set by default to kThreadDeviceType_Router.

Signed-off-by: marius-alex-tache <marius.tache@nxp.com>
(cherry picked from commit d88e78ea6c973eb736915110bb227ad3515eec98)
  • Loading branch information
marius-alex-tache committed Aug 14, 2024
commit 7ab8b469c0c7cd50c5e193237db38a1970d9233d
43 changes: 37 additions & 6 deletions examples/platform/nxp/common/app_task/include/AppTaskBase.h
Original file line number Diff line number Diff line change
@@ -27,9 +27,8 @@
#include <app/server/Server.h>
#include <platform/NetworkCommissioning.h>

namespace chip {
namespace NXP {
namespace App {
namespace chip::NXP::App {

class AppTaskBase
{
public:
@@ -79,6 +78,13 @@ class AppTaskBase
*/
virtual void PostInitMatterStack(void) {};

/**
* \brief This function is called in AppTaskMain after all events are processed in current loop iteration.
*
* Example of usage: It can be used to animate some LEDs.
*/
virtual void PostEventsProcessedAction() {}

/**
* \brief This function could be overridden in order to register features.
*
@@ -97,6 +103,31 @@ class AppTaskBase
*/
virtual void AppMatter_RegisterCustomCliCommands(void) {};

/**
* \brief Disallow entering low power mode.
*
* This function can be overridden in order to implement a specific disallow mechanism.
*
*/
virtual void AppMatter_DisallowDeviceToSleep(void) {}

/**
* \brief Allow entering low power mode.
*
* This function can be overridden in order to implement a specific allow mechanism.
*
*/
virtual void AppMatter_AllowDeviceToSleep(void) {}

/**
* \brief Print onboarding information.
*
* It can be overwritten by derived classes for custom information,
* such as setting the commissioning flow to kUserActionRequired.
*
*/
virtual void PrintOnboardingInfo();

/**
* \brief This function could be overridden in order to dispatch event.
*
@@ -142,6 +173,7 @@ class AppTaskBase

private:
inline static chip::CommonCaseDeviceServerInitParams initParams;

/* Functions used by the public commisioning handlers */
static void StartCommissioning(intptr_t arg);
static void StopCommissioning(intptr_t arg);
@@ -154,6 +186,5 @@ class AppTaskBase
* Applications can use this to gain access to features of the AppTaskBase.
*/
extern AppTaskBase & GetAppTask();
} // namespace App
} // namespace NXP
} // namespace chip

} // namespace chip::NXP::App
22 changes: 16 additions & 6 deletions examples/platform/nxp/common/app_task/include/AppTaskFreeRTOS.h
Original file line number Diff line number Diff line change
@@ -21,9 +21,8 @@

#include "AppTaskBase.h"

namespace chip {
namespace NXP {
namespace App {
namespace chip::NXP::App {

class AppTaskFreeRTOS : public AppTaskBase
{
public:
@@ -72,9 +71,20 @@ class AppTaskFreeRTOS : public AppTaskBase
*/
virtual CHIP_ERROR AppMatter_Register(void) override;

/**
* \brief The app event queue handle should be static such that the concrete
* application task can initialize it during Start() call.
*/
QueueHandle_t appEventQueue;

/**
* \brief This value is used when xQueueReceive is called to specify
* the maximum amount of time the task should block waiting for an event.
* This can be modified according to the application needs.
*/
TickType_t ticksToWait;

private:
void DispatchEvent(const AppEvent & event);
};
} // namespace App
} // namespace NXP
} // namespace chip
} // namespace chip::NXP::App
10 changes: 4 additions & 6 deletions examples/platform/nxp/common/app_task/include/AppTaskZephyr.h
Original file line number Diff line number Diff line change
@@ -21,9 +21,8 @@

#include "AppTaskBase.h"

namespace chip {
namespace NXP {
namespace App {
namespace chip::NXP::App {

class AppTaskZephyr : public AppTaskBase
{
public:
@@ -65,6 +64,5 @@ class AppTaskZephyr : public AppTaskBase
private:
void DispatchEvent(const AppEvent & event);
};
} // namespace App
} // namespace NXP
} // namespace chip

} // namespace chip::NXP::App
53 changes: 45 additions & 8 deletions examples/platform/nxp/common/app_task/source/AppTaskBase.cpp
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@
#include "AppFactoryData.h"
#include "CHIPDeviceManager.h"
#include "CommonDeviceCallbacks.h"
#include "OperationalKeystore.h"

#include <app/server/Dnssd.h>
#include <lib/dnssd/Advertiser.h>
@@ -67,6 +68,19 @@
#include <lib/shell/commands/WiFi.h>
#endif

#ifdef SMOKE_CO_ALARM
#include <app/TestEventTriggerDelegate.h>
#include <app/clusters/smoke-co-alarm-server/SmokeCOTestEventTriggerHandler.h>
#endif

/**
* \brief This flag can be set in build system to overwrite the default value.
*
*/
#ifndef CONFIG_THREAD_DEVICE_TYPE
#define CONFIG_THREAD_DEVICE_TYPE kThreadDeviceType_Router
#endif

using namespace chip;
using namespace chip::TLV;
using namespace ::chip::Credentials;
@@ -90,12 +104,14 @@ static uint8_t sTestEventTriggerEnableKey[TestEventTriggerDelegate::kEnableKeyLe
#if CONFIG_NET_L2_OPENTHREAD
void LockOpenThreadTask(void)
{
chip::NXP::App::GetAppTask().AppMatter_DisallowDeviceToSleep();
chip::DeviceLayer::ThreadStackMgr().LockThreadStack();
}

void UnlockOpenThreadTask(void)
{
chip::DeviceLayer::ThreadStackMgr().UnlockThreadStack();
chip::NXP::App::GetAppTask().AppMatter_AllowDeviceToSleep();
}
#endif

@@ -107,7 +123,20 @@ void chip::NXP::App::AppTaskBase::InitServer(intptr_t arg)
static OTATestEventTriggerDelegate testEventTriggerDelegate{ ByteSpan(sTestEventTriggerEnableKey) };
initParams.testEventTriggerDelegate = &testEventTriggerDelegate;
#endif

#ifdef SMOKE_CO_ALARM
static SimpleTestEventTriggerDelegate sTestEventTriggerDelegate{};
static SmokeCOTestEventTriggerHandler sSmokeCOTestEventTriggerHandler{};
VerifyOrDie(sTestEventTriggerDelegate.Init(ByteSpan(sTestEventTriggerEnableKey)) == CHIP_NO_ERROR);
VerifyOrDie(sTestEventTriggerDelegate.AddHandler(&sSmokeCOTestEventTriggerHandler) == CHIP_NO_ERROR);
initParams.testEventTriggerDelegate = &sTestEventTriggerDelegate;
#endif

#if CHIP_CRYPTO_PLATFORM
initParams.operationalKeystore = chip::NXP::App::OperationalKeystore::GetInstance();
#endif
(void) initParams.InitializeStaticResourcesBeforeServerInit();

#if CONFIG_NET_L2_OPENTHREAD
// Init ZCL Data Model and start server
chip::Inet::EndPointStateOpenThread::OpenThreadEndpointInitParam nativeParams;
@@ -118,8 +147,11 @@ void chip::NXP::App::AppTaskBase::InitServer(intptr_t arg)
#endif

VerifyOrDie((chip::Server::GetInstance().Init(initParams)) == CHIP_NO_ERROR);

gExampleDeviceInfoProvider.SetStorageDelegate(&Server::GetInstance().GetPersistentStorage());
auto * persistentStorage = &Server::GetInstance().GetPersistentStorage();
#if CHIP_CRYPTO_PLATFORM
chip::NXP::App::OperationalKeystore::Init(persistentStorage);
#endif
gExampleDeviceInfoProvider.SetStorageDelegate(persistentStorage);
chip::DeviceLayer::SetDeviceInfoProvider(&gExampleDeviceInfoProvider);

GetAppTask().PostInitMatterServerInstance();
@@ -188,7 +220,7 @@ CHIP_ERROR chip::NXP::App::AppTaskBase::Init()
return err;
}

err = ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_Router);
err = ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::CONFIG_THREAD_DEVICE_TYPE);
if (err != CHIP_NO_ERROR)
{
return err;
@@ -229,11 +261,7 @@ CHIP_ERROR chip::NXP::App::AppTaskBase::Init()
ConfigurationMgr().LogDeviceConfig();

// QR code will be used with CHIP Tool
#if CONFIG_NETWORK_LAYER_BLE
PrintOnboardingCodes(chip::RendezvousInformationFlag(chip::RendezvousInformationFlag::kBLE));
#else
PrintOnboardingCodes(chip::RendezvousInformationFlag(chip::RendezvousInformationFlag::kOnNetwork));
#endif /* CONFIG_NETWORK_LAYER_BLE */
PrintOnboardingInfo();

/* Start a task to run the CHIP Device event loop. */
err = PlatformMgr().StartEventLoopTask();
@@ -335,3 +363,12 @@ void chip::NXP::App::AppTaskBase::FactoryResetHandler(void)
chip::Server::GetInstance().GenerateShutDownEvent();
chip::Server::GetInstance().ScheduleFactoryReset();
}

void chip::NXP::App::AppTaskBase::PrintOnboardingInfo()
{
#if CONFIG_NETWORK_LAYER_BLE
PrintOnboardingCodes(chip::RendezvousInformationFlag(chip::RendezvousInformationFlag::kBLE));
#else
PrintOnboardingCodes(chip::RendezvousInformationFlag(chip::RendezvousInformationFlag::kOnNetwork));
#endif /* CONFIG_NETWORK_LAYER_BLE */
}
40 changes: 26 additions & 14 deletions examples/platform/nxp/common/app_task/source/AppTaskFreeRTOS.cpp
Original file line number Diff line number Diff line change
@@ -50,8 +50,6 @@
#endif
#define APP_EVENT_QUEUE_SIZE 10

static QueueHandle_t sAppEventQueue;

using namespace chip;
using namespace chip::TLV;
using namespace ::chip::Credentials;
@@ -71,6 +69,7 @@ chip::DeviceLayer::NetworkCommissioning::WiFiDriver * chip::NXP::App::AppTaskFre
CHIP_ERROR chip::NXP::App::AppTaskFreeRTOS::AppMatter_Register()
{
CHIP_ERROR err = CHIP_NO_ERROR;

/* Register Matter CLI cmds */
#ifdef ENABLE_CHIP_SHELL
err = chip::NXP::App::GetAppCLI().Init();
@@ -92,14 +91,16 @@ CHIP_ERROR chip::NXP::App::AppTaskFreeRTOS::Start()
CHIP_ERROR err = CHIP_NO_ERROR;
TaskHandle_t taskHandle;

sAppEventQueue = xQueueCreate(APP_EVENT_QUEUE_SIZE, sizeof(AppEvent));
if (sAppEventQueue == NULL)
appEventQueue = xQueueCreate(APP_EVENT_QUEUE_SIZE, sizeof(AppEvent));
if (appEventQueue == NULL)
{
err = CHIP_ERROR_NO_MEMORY;
ChipLogError(DeviceLayer, "Failed to allocate app event queue");
assert(err == CHIP_NO_ERROR);
}

ticksToWait = portMAX_DELAY;

/* AppTaskMain function will loss actual object instance, give it as parameter */
if (xTaskCreate(&AppTaskFreeRTOS::AppTaskMain, "AppTaskMain", APP_TASK_STACK_SIZE, this, APP_TASK_PRIORITY, &taskHandle) !=
pdPASS)
@@ -122,31 +123,42 @@ void chip::NXP::App::AppTaskFreeRTOS::AppTaskMain(void * pvParameter)

sAppTask->PreInitMatterStack();
err = sAppTask->Init();
VerifyOrDieWithMsg(err == CHIP_NO_ERROR, DeviceLayer, "AppTask.Init() failed");
sAppTask->PostInitMatterStack();
if (err != CHIP_NO_ERROR)
{
ChipLogError(DeviceLayer, "AppTask.Init() failed");
assert(err == CHIP_NO_ERROR);
}

while (true)
{
BaseType_t eventReceived = xQueueReceive(sAppEventQueue, &event, portMAX_DELAY);
BaseType_t eventReceived = xQueueReceive(sAppTask->appEventQueue, &event, sAppTask->ticksToWait);
while (eventReceived == pdTRUE)
{
sAppTask->DispatchEvent(event);
eventReceived = xQueueReceive(sAppEventQueue, &event, 0);
eventReceived = xQueueReceive(sAppTask->appEventQueue, &event, 0);
}

sAppTask->PostEventsProcessedAction();
}
}

void chip::NXP::App::AppTaskFreeRTOS::PostEvent(const AppEvent & event)
{
if (sAppEventQueue != NULL)
if (appEventQueue != NULL)
{
if (!xQueueSend(sAppEventQueue, &event, 0))
if (__get_IPSR())
{
portBASE_TYPE taskToWake = pdFALSE;
if (!xQueueSendToFrontFromISR(appEventQueue, &event, &taskToWake))
{
ChipLogError(DeviceLayer, "Failed to post event to app task event queue from ISR");
}

portYIELD_FROM_ISR(taskToWake);
}
else
{
ChipLogError(DeviceLayer, "Failed to post event to app task event queue");
if (!xQueueSend(appEventQueue, &event, 0))
{
ChipLogError(DeviceLayer, "Failed to post event to app task event queue");
}
}
}
}