Skip to content

Commit

Permalink
[Infineon] Implement event-based Thread stack task for CYW30739. (#25796
Browse files Browse the repository at this point in the history
)

* [Infineon] Implement event-based Thread stack task for CYW30739.

* Add EventFlags for platform-specific wrappers of event flags.
* Implement otTaskletsSignalPending and otSysEventSignalPending callback
  functions for the OpenThread stack to notify the Thread stack task if
  there are pending events to be processed.
* Update CYW30739 SDK and ot-ifx submodules for the event-based implementations.
* Use the default value of CHIP_DEVICE_CONFIG_EVENT_LOGGING_CRIT_BUFFER_SIZE.
* Disable OTA of lighting and lock apps because CYW30739 is running out of flash.

* Enable OTA and disable FTD for the flash space.

* Fix the documents.
  • Loading branch information
hsusid authored and pull[bot] committed Oct 17, 2023
1 parent 704ed2d commit 4132784
Show file tree
Hide file tree
Showing 15 changed files with 176 additions and 39 deletions.
2 changes: 1 addition & 1 deletion examples/lighting-app/infineon/cyw30739/args.gni
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import("${chip_root}/src/platform/Infineon/CYW30739/args.gni")

cyw30739_sdk_target = get_label_info(":sdk", "label_no_toolchain")

chip_openthread_ftd = true
chip_openthread_ftd = false

chip_enable_ota_requestor = true

Expand Down
2 changes: 1 addition & 1 deletion examples/lock-app/infineon/cyw30739/args.gni
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import("${chip_root}/src/platform/Infineon/CYW30739/args.gni")

cyw30739_sdk_target = get_label_info(":sdk", "label_no_toolchain")

chip_openthread_ftd = true
chip_openthread_ftd = false

chip_enable_ota_requestor = true

Expand Down
2 changes: 2 additions & 0 deletions src/platform/Infineon/CYW30739/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ static_library("CYW30739") {
"ConnectivityManagerImpl.h",
"DiagnosticDataProviderImpl.cpp",
"DiagnosticDataProviderImpl.h",
"EventFlags.cpp",
"EventFlags.h",
"FactoryDataProvider.cpp",
"FactoryDataProvider.h",
"InetPlatformConfig.h",
Expand Down
1 change: 0 additions & 1 deletion src/platform/Infineon/CYW30739/CHIPDevicePlatformConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,5 @@
// -------------------- Network Telemetry Configuration --------------------

// -------------------- Event Logging Configuration --------------------
#define CHIP_DEVICE_CONFIG_EVENT_LOGGING_CRIT_BUFFER_SIZE 256

// -------------------- Software Update Manager Configuration --------------------
72 changes: 72 additions & 0 deletions src/platform/Infineon/CYW30739/EventFlags.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
*
* Copyright (c) 2022 Project CHIP Authors
* Copyright (c) 2019 Nest Labs, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* @file
* Provides a class that serves as a wrapper for the event system of CYW30739
* platform's underlying RTOS. An event instance is comprised of 32 flags.
* Each flag can be utilized for thread synchronization purposes.
*/
#include "EventFlags.h"

#include <lib/support/CodeUtils.h>

namespace chip {
namespace DeviceLayer {

CHIP_ERROR EventFlags::Init(void)
{
CHIP_ERROR err = CHIP_NO_ERROR;
wiced_result_t result;

mFlags = wiced_rtos_create_event_flags();
VerifyOrExit(mFlags != nullptr, err = CHIP_ERROR_NO_MEMORY);

result = wiced_rtos_init_event_flags(mFlags);
VerifyOrExit(result == WICED_SUCCESS, err = CHIP_ERROR_NO_MEMORY);

exit:
return err;
}

CHIP_ERROR EventFlags::Set(uint32_t flags)
{
assert(!wiced_rtos_check_for_stack_overflow());

if (wiced_rtos_set_event_flags(mFlags, flags) != WICED_SUCCESS)
{
ChipLogError(DeviceLayer, "wiced_rtos_set_event_flags %08lx", flags);
return CHIP_ERROR_INTERNAL;
}
return CHIP_NO_ERROR;
}

CHIP_ERROR EventFlags::WaitAnyForever(uint32_t & flags)
{
const wiced_result_t result =
wiced_rtos_wait_for_event_flags(mFlags, 0xffffffff, &flags, WICED_TRUE, WAIT_FOR_ANY_EVENT, WICED_WAIT_FOREVER);
if (result != WICED_SUCCESS)
{
ChipLogError(DeviceLayer, "wiced_rtos_wait_for_event_flags 0x%08x", result);
return CHIP_ERROR_INTERNAL;
}
return CHIP_NO_ERROR;
}

} // namespace DeviceLayer
} // namespace chip
49 changes: 49 additions & 0 deletions src/platform/Infineon/CYW30739/EventFlags.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
*
* Copyright (c) 2022 Project CHIP Authors
* Copyright (c) 2019 Nest Labs, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* @file
* Provides a class that serves as a wrapper for the event system of CYW30739
* platform's underlying RTOS. An event instance is comprised of 32 flags.
* Each flag can be utilized for thread synchronization purposes.
*/

#pragma once

#include <lib/core/CHIPError.h>
#include <wiced_rtos.h>

namespace chip {
namespace DeviceLayer {

/**
* A class represents an event group with 32 flags.
*/
class EventFlags
{
public:
CHIP_ERROR Init(void);
CHIP_ERROR Set(uint32_t flags);
CHIP_ERROR WaitAnyForever(uint32_t & flags);

private:
wiced_event_flags_t * mFlags;
};

} // namespace DeviceLayer
} // namespace chip
28 changes: 6 additions & 22 deletions src/platform/Infineon/CYW30739/PlatformManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,8 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack(void)
VerifyOrExit(mThread != nullptr, err = CHIP_ERROR_NO_MEMORY);

/* Initialize the event flags. */
mEventFlags = wiced_rtos_create_event_flags();
VerifyOrExit(mEventFlags != nullptr, err = CHIP_ERROR_NO_MEMORY);
ReturnErrorOnFailure(mEventFlags.Init());

result = wiced_rtos_init_event_flags(mEventFlags);
VerifyOrExit(result == WICED_SUCCESS, err = CHIP_ERROR_NO_MEMORY);
/* Initialize the event queue. */
mEventQueue = wiced_rtos_create_queue();
VerifyOrExit(mEventQueue != nullptr, err = CHIP_ERROR_NO_MEMORY);
Expand Down Expand Up @@ -87,12 +84,9 @@ void PlatformManagerImpl::_RunEventLoop(void)

while (true)
{
uint32_t flags_set = 0;
const wiced_result_t result = wiced_rtos_wait_for_event_flags(mEventFlags, 0xffffffff, &flags_set, WICED_TRUE,
WAIT_FOR_ANY_EVENT, WICED_WAIT_FOREVER);
if (result != WICED_SUCCESS)
uint32_t flags_set = 0;
if (mEventFlags.WaitAnyForever(flags_set) != CHIP_NO_ERROR)
{
ChipLogError(DeviceLayer, "wiced_rtos_wait_for_event_flags 0x%08x", result);
continue;
}

Expand Down Expand Up @@ -147,7 +141,7 @@ CHIP_ERROR PlatformManagerImpl::_PostEvent(const ChipDeviceEvent * event)
return CHIP_ERROR_INTERNAL;
}

SetEventFlags(kPostEventFlag);
mEventFlags.Set(kPostEventFlag);

return CHIP_NO_ERROR;
}
Expand All @@ -172,16 +166,6 @@ CHIP_ERROR PlatformManagerImpl::_StartChipTimer(System::Clock::Timeout durationM

void PlatformManagerImpl::_Shutdown() {}

void PlatformManagerImpl::SetEventFlags(uint32_t flags)
{
assert(!wiced_rtos_check_for_stack_overflow());

if (wiced_rtos_set_event_flags(mEventFlags, flags) != WICED_SUCCESS)
{
ChipLogError(DeviceLayer, "%s wiced_rtos_set_event_flags %08lx", __func__, flags);
}
}

void PlatformManagerImpl::HandleTimerEvent(void)
{
const CHIP_ERROR err = static_cast<System::LayerImplFreeRTOS &>(DeviceLayer::SystemLayer()).HandlePlatformTimer();
Expand Down Expand Up @@ -217,7 +201,7 @@ void PlatformManagerImpl::HandlePostEvent(void)
/* Set another application thread event if the event queue is not empty. */
if (!wiced_rtos_is_queue_empty(mEventQueue))
{
SetEventFlags(kPostEventFlag);
mEventFlags.Set(kPostEventFlag);
}
}

Expand All @@ -229,7 +213,7 @@ void PlatformManagerImpl::EventLoopTaskMain(uint32_t arg)

void PlatformManagerImpl::TimerCallback(WICED_TIMER_PARAM_TYPE params)
{
PlatformMgrImpl().SetEventFlags(kTimerEventFlag);
PlatformMgrImpl().mEventFlags.Set(kTimerEventFlag);
}

int PlatformManagerImpl::GetEntropy(void * data, unsigned char * output, size_t len, size_t * olen)
Expand Down
6 changes: 3 additions & 3 deletions src/platform/Infineon/CYW30739/PlatformManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@

#include <hal/wiced_timer.h>
#include <platform/internal/GenericPlatformManagerImpl.h>
#include <wiced_rtos.h>

#include "EventFlags.h"

namespace chip {
namespace DeviceLayer {
Expand Down Expand Up @@ -57,7 +58,6 @@ class PlatformManagerImpl final : public PlatformManager, public Internal::Gener
CHIP_ERROR _StartChipTimer(System::Clock::Timeout durationMS);
void _Shutdown(void);

void SetEventFlags(uint32_t flags);
void HandleTimerEvent(void);
void HandlePostEvent(void);

Expand All @@ -67,7 +67,7 @@ class PlatformManagerImpl final : public PlatformManager, public Internal::Gener
friend PlatformManagerImpl & PlatformMgrImpl(void);

wiced_thread_t * mThread;
wiced_event_flags_t * mEventFlags;
EventFlags mEventFlags;
wiced_queue_t * mEventQueue;
wiced_timer_t mTimer;
wiced_mutex_t * mMutex;
Expand Down
30 changes: 30 additions & 0 deletions src/platform/Infineon/CYW30739/ThreadStackManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ CHIP_ERROR ThreadStackManagerImpl::_InitThreadStack()
mThread = wiced_rtos_create_thread();
VerifyOrExit(mThread != nullptr, err = CHIP_ERROR_NO_MEMORY);

ReturnErrorOnFailure(mEventFlags.Init());

mMutex = wiced_rtos_create_mutex();
VerifyOrExit(mMutex != nullptr, err = CHIP_ERROR_NO_MEMORY);

Expand All @@ -58,6 +60,16 @@ CHIP_ERROR ThreadStackManagerImpl::_InitThreadStack()
return err;
}

void ThreadStackManagerImpl::SignalThreadActivityPending()
{
mEventFlags.Set(kActivityPendingEventFlag);
}

void ThreadStackManagerImpl::SignalThreadActivityPendingFromISR()
{
mEventFlags.Set(kActivityPendingFromISREventFlag);
}

CHIP_ERROR ThreadStackManagerImpl::_StartThreadTask()
{
CHIP_ERROR err = CHIP_NO_ERROR;
Expand Down Expand Up @@ -87,6 +99,12 @@ void ThreadStackManagerImpl::ThreadTaskMain(void)
{
while (true)
{
uint32_t flags = 0;
if (mEventFlags.WaitAnyForever(flags) != CHIP_NO_ERROR)
{
continue;
}

LockThreadStack();
ProcessThreadActivity();
UnlockThreadStack();
Expand All @@ -102,6 +120,18 @@ void ThreadStackManagerImpl::ThreadTaskMain(uint32_t arg)
} // namespace DeviceLayer
} // namespace chip

using namespace ::chip::DeviceLayer;

extern "C" void otTaskletsSignalPending(otInstance * p_instance)
{
ThreadStackMgrImpl().SignalThreadActivityPending();
}

extern "C" void otSysEventSignalPending(void)
{
ThreadStackMgrImpl().SignalThreadActivityPendingFromISR();
}

extern "C" void * otPlatCAlloc(size_t aNum, size_t aSize)
{
return CHIPPlatformMemoryCalloc(aNum, aSize);
Expand Down
13 changes: 7 additions & 6 deletions src/platform/Infineon/CYW30739/ThreadStackManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@

#include <platform/CHIPDeviceEvent.h>
#include <platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.h>
#include <wiced_rtos.h>

#include "EventFlags.h"

namespace chip {
namespace DeviceLayer {
Expand All @@ -45,6 +46,8 @@ class ThreadStackManagerImpl final : public ThreadStackManager,
// ===== Methods that implement the ThreadStackManager abstract interface.
CHIP_ERROR _InitThreadStack();

void SignalThreadActivityPending();
void SignalThreadActivityPendingFromISR();
inline bool IsCurrentTask(void) { return wiced_rtos_is_current_thread(mThread) == WICED_SUCCESS; }

protected:
Expand All @@ -55,18 +58,14 @@ class ThreadStackManagerImpl final : public ThreadStackManager,
bool _TryLockThreadStack();
void _UnlockThreadStack();

// ===== Methods that override the GenericThreadStackManagerImpl_OpenThread abstract interface.

void _OnCHIPoBLEAdvertisingStart();
void _OnCHIPoBLEAdvertisingStop();

private:
// ===== Members for internal use by the following friends.

friend ThreadStackManager & ::chip::DeviceLayer::ThreadStackMgr(void);
friend ThreadStackManagerImpl & ::chip::DeviceLayer::ThreadStackMgrImpl(void);

wiced_thread_t * mThread;
EventFlags mEventFlags;
wiced_mutex_t * mMutex;
static ThreadStackManagerImpl sInstance;

Expand All @@ -75,6 +74,8 @@ class ThreadStackManagerImpl final : public ThreadStackManager,
void ThreadTaskMain(void);

static void ThreadTaskMain(uint32_t arg);
static constexpr uint32_t kActivityPendingEventFlag = 1 << 0;
static constexpr uint32_t kActivityPendingFromISREventFlag = 1 << 1;
};

/**
Expand Down
2 changes: 1 addition & 1 deletion third_party/infineon/cyw30739_sdk/repos/CYW930739M2EVB-01

0 comments on commit 4132784

Please sign in to comment.