Merge pull request 'alpaka-initialization' (#13) from alpaka-initialization into main

Reviewed-on: https://git.intern.spaceteamaachen.de/ALPAKA/rtos2-utils/pulls/13
This commit is contained in:
carlwachter 2023-11-09 17:37:45 +00:00
commit 615900f16e
7 changed files with 84 additions and 11 deletions

View File

@ -34,6 +34,11 @@ namespace sta
*/
RtosQueue(osMessageQueueId_t handle);
/**
* @param length The maximum number of elements to be stored in the queue.
*/
RtosQueue(uint32_t length);
/**
* @brief Place message in queue.
*

View File

@ -21,6 +21,13 @@ namespace sta
{
STA_ASSERT(handle != nullptr);
}
template <typename T>
RtosQueue<T>::RtosQueue(uint32_t length)
: handle_{osMessageQueueNew(length, sizeof(Message), NULL)}
{
STA_ASSERT(handle_ != NULL);
}
template <typename T>
bool RtosQueue<T>::put(const Message & msg, uint32_t timeout /* = osWaitForever */)

View File

@ -35,9 +35,9 @@
#define STA_RTOS_THREAD_FLAG_ERROR_CODE ( 1UL << 31 )
/**
* @brief Request thread termination.
* @brief Request thread start.
*/
#define STA_RTOS_THREAD_FLAG_TERMINATE ( 1UL << 30 )
#define STA_RTOS_THREAD_FLAG_START ( 1UL << 30 )
#define STA_RTOS_THREAD_FLAGS_ERROR_CODE_BITS UINT32_C( 0x0000000F )
@ -81,10 +81,37 @@ namespace sta
*/
void notify(uint32_t flags);
/**
* @return Returns the flags that were set for this thread.
*/
uint32_t getFlags();
/**
* @brief Wait for certain thread flags.
*
* @return Returns the flags triggering the activation.
*/
uint32_t wait(uint32_t flags);
/**
* @brief Clears the thread flags set for this thread.
*
* @return Returns the thread flags that set before clearing.
*/
uint32_t clear(uint32_t flags);
/**
* @brief Send termination request to thread.
*/
void requestTermination();
/**
* @brief Resets the terminate bool to false.
*
* @return Returns the previous value of this variable.
*/
bool resetTerminationRequest();
/**
* @brief Forcibly terminate thread.
*/
@ -99,6 +126,7 @@ namespace sta
private:
Handle handle_;
bool terminate_;
};
} // namespace sta

View File

@ -28,7 +28,7 @@ namespace sta
* @param callback The callback function to call upon timer timeout.
* @param arg The argument to pass to the callback function.
*/
RtosTimer(void (*callback)(void *arg), void *arg);
RtosTimer(std::function<void(void*)>, void *arg);
/**
* @brief Initializes the timer with a callback that has no effect.
@ -43,7 +43,7 @@ namespace sta
* @param callback The callback function to call upon timer timeout.
* @param arg The argument to pass to the callback function.
*/
void setCallback(void (*callback)(void *arg), void *arg);
void setCallback(std::function<void(void*)> callback, void *arg);
/**
* @brief Run the timer for a given number of milliseconds.

View File

@ -44,15 +44,15 @@ void startALPAKA(void * arg)
{
STA_ASSERT_MSG(osKernelGetState() != osKernelInactive, "Cannot call startALPAKA() before osKernelInitialize()");
// Call further initialization code
sta::rtos::startupExtras(arg);
// Initialize HAL
sta::initHAL();
// Initialize RTOS system resources
sta::rtos::initSystem();
// Call further initialization code
sta::rtos::startupExtras(arg);
// Wake threads
sta::rtos::signalStartupEvent();

View File

@ -29,13 +29,46 @@ namespace sta
STA_ASSERT(handle_.get() != nullptr);
STA_ASSERT_MSG(IS_THREAD_SYS_FLAGS(flags), "Only system flags allowed");
osThreadFlagsSet(handle_.get(), flags);
uint32_t rslt = osThreadFlagsSet(handle_.get(), flags);
STA_ASSERT_MSG(rslt != osFlagsErrorUnknown, "Unknown thread flag error.");
STA_ASSERT_MSG(rslt != osFlagsErrorParameter, "Parameter thread_id is not a valid thread or flags has highest bit set.");
STA_ASSERT_MSG(rslt != osFlagsErrorResource, "The thread is in invalid state.");
}
uint32_t RtosThread::wait(uint32_t flags)
{
return osThreadFlagsWait(flags, osFlagsWaitAny, osWaitForever);
}
uint32_t RtosThread::clear(uint32_t flags)
{
uint32_t setFlags = osThreadFlagsClear(flags);
STA_ASSERT(setFlags != (uint32_t)osError);
return setFlags;
}
uint32_t RtosThread::getFlags()
{
STA_ASSERT(handle_.get() != nullptr);
return osThreadFlagsGet();
}
void RtosThread::requestTermination()
{
sysNotify(STA_RTOS_THREAD_FLAG_TERMINATE);
// sysNotify(STA_RTOS_THREAD_FLAG_TERMINATE);
terminate_ = true;
}
bool RtosThread::resetTerminationRequest()
{
bool temp = terminate_;
terminate_ = false;
return temp;
}
void RtosThread::terminate()

View File

@ -4,7 +4,7 @@
namespace sta {
RtosTimer::RtosTimer(void (*callback)(void *arg), void *arg)
RtosTimer::RtosTimer(std::function<void(void*)> callback, void *arg)
: timer_id_{NULL},
timer_attr_{.name="Timer", .attr_bits=osTimerOnce},
callback_{callback},
@ -28,7 +28,7 @@ namespace sta {
osTimerDelete(timer_id_);
}
void RtosTimer::setCallback(void (*callback)(void *arg), void *arg)
void RtosTimer::setCallback(std::function<void(void*)> callback, void *arg)
{
callback_ = callback;
callbackArg_ = arg;