Skip to content

Commit

Permalink
feat: add osal/threadx/EventDispatcherThreadX (#637)
Browse files Browse the repository at this point in the history
* feat: add osal/threadx/EventDispatcherThreadX

* Process review comments
  • Loading branch information
richardapeters authored May 24, 2024
1 parent 23ac162 commit 8c66ddd
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
9 changes: 8 additions & 1 deletion osal/threadx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,14 @@ target_compile_definitions(threadx PUBLIC
"TX_SINGLE_MODE_NON_SECURE=1"
)

add_library(osal.threadx_osal ${EMIL_EXCLUDE_FROM_ALL} STATIC Osal.cpp)
add_library(osal.threadx_osal ${EMIL_EXCLUDE_FROM_ALL} STATIC)

target_sources(osal.threadx_osal PRIVATE
Osal.cpp
EventDispatcherThreadX.cpp
EventDispatcherThreadX.hpp
)

target_link_libraries(osal.threadx_osal PUBLIC infra.util threadx)

if (TARGET_BUILD_UNIX OR TARGET_BUILD_OSX)
Expand Down
28 changes: 28 additions & 0 deletions osal/threadx/EventDispatcherThreadX.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "osal/threadx/EventDispatcherThreadX.hpp"

namespace hal
{
constexpr static ULONG Execute{ 0x01 };

void EventDispatcherThreadXWorker::RequestExecution()
{
if (tx_event_flags_set(&flags, Execute, TX_OR) != TX_SUCCESS)
std::abort();
}

void EventDispatcherThreadXWorker::Idle()
{
ULONG events;
if (tx_event_flags_get(&flags, Execute, TX_OR_CLEAR, &events, TX_WAIT_FOREVER) != TX_SUCCESS)
std::abort();
}

TX_EVENT_FLAGS_GROUP EventDispatcherThreadXWorker::init()
{
TX_EVENT_FLAGS_GROUP flags{};
if (tx_event_flags_create(&flags, const_cast<char*>("")) != TX_SUCCESS)
std::abort();

return flags;
}
}
27 changes: 27 additions & 0 deletions osal/threadx/EventDispatcherThreadX.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#ifndef OSAL_EVENT_DISPATCHER_THREADX_HPP
#define OSAL_EVENT_DISPATCHER_THREADX_HPP

#include "infra/event/EventDispatcherWithWeakPtr.hpp"
#include "tx_api.h"

namespace hal
{
class EventDispatcherThreadXWorker
: public infra::EventDispatcherWithWeakPtrWorker
{
public:
using EventDispatcherWithWeakPtrWorker::EventDispatcherWithWeakPtrWorker;

void RequestExecution() override;
void Idle() override;

private:
TX_EVENT_FLAGS_GROUP flags{ init() };

static TX_EVENT_FLAGS_GROUP init();
};

using EventDispatcherThreadX = infra::EventDispatcherWithWeakPtrConnector<EventDispatcherThreadXWorker>;
}

#endif

0 comments on commit 8c66ddd

Please sign in to comment.