mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/rtos2-utils.git
synced 2025-06-12 02:36:00 +00:00
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:
commit
615900f16e
@ -34,6 +34,11 @@ namespace sta
|
|||||||
*/
|
*/
|
||||||
RtosQueue(osMessageQueueId_t handle);
|
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.
|
* @brief Place message in queue.
|
||||||
*
|
*
|
||||||
|
@ -21,6 +21,13 @@ namespace sta
|
|||||||
{
|
{
|
||||||
STA_ASSERT(handle != nullptr);
|
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>
|
template <typename T>
|
||||||
bool RtosQueue<T>::put(const Message & msg, uint32_t timeout /* = osWaitForever */)
|
bool RtosQueue<T>::put(const Message & msg, uint32_t timeout /* = osWaitForever */)
|
||||||
|
@ -35,9 +35,9 @@
|
|||||||
#define STA_RTOS_THREAD_FLAG_ERROR_CODE ( 1UL << 31 )
|
#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 )
|
#define STA_RTOS_THREAD_FLAGS_ERROR_CODE_BITS UINT32_C( 0x0000000F )
|
||||||
@ -81,10 +81,37 @@ namespace sta
|
|||||||
*/
|
*/
|
||||||
void notify(uint32_t flags);
|
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.
|
* @brief Send termination request to thread.
|
||||||
*/
|
*/
|
||||||
void requestTermination();
|
void requestTermination();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Resets the terminate bool to false.
|
||||||
|
*
|
||||||
|
* @return Returns the previous value of this variable.
|
||||||
|
*/
|
||||||
|
bool resetTerminationRequest();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Forcibly terminate thread.
|
* @brief Forcibly terminate thread.
|
||||||
*/
|
*/
|
||||||
@ -99,6 +126,7 @@ namespace sta
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
Handle handle_;
|
Handle handle_;
|
||||||
|
bool terminate_;
|
||||||
};
|
};
|
||||||
} // namespace sta
|
} // namespace sta
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ namespace sta
|
|||||||
* @param callback The callback function to call upon timer timeout.
|
* @param callback The callback function to call upon timer timeout.
|
||||||
* @param arg The argument to pass to the callback function.
|
* @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.
|
* @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 callback The callback function to call upon timer timeout.
|
||||||
* @param arg The argument to pass to the callback function.
|
* @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.
|
* @brief Run the timer for a given number of milliseconds.
|
||||||
|
@ -44,15 +44,15 @@ void startALPAKA(void * arg)
|
|||||||
{
|
{
|
||||||
STA_ASSERT_MSG(osKernelGetState() != osKernelInactive, "Cannot call startALPAKA() before osKernelInitialize()");
|
STA_ASSERT_MSG(osKernelGetState() != osKernelInactive, "Cannot call startALPAKA() before osKernelInitialize()");
|
||||||
|
|
||||||
// Call further initialization code
|
|
||||||
sta::rtos::startupExtras(arg);
|
|
||||||
|
|
||||||
// Initialize HAL
|
// Initialize HAL
|
||||||
sta::initHAL();
|
sta::initHAL();
|
||||||
|
|
||||||
// Initialize RTOS system resources
|
// Initialize RTOS system resources
|
||||||
sta::rtos::initSystem();
|
sta::rtos::initSystem();
|
||||||
|
|
||||||
|
// Call further initialization code
|
||||||
|
sta::rtos::startupExtras(arg);
|
||||||
|
|
||||||
// Wake threads
|
// Wake threads
|
||||||
sta::rtos::signalStartupEvent();
|
sta::rtos::signalStartupEvent();
|
||||||
|
|
||||||
|
@ -29,13 +29,46 @@ namespace sta
|
|||||||
STA_ASSERT(handle_.get() != nullptr);
|
STA_ASSERT(handle_.get() != nullptr);
|
||||||
STA_ASSERT_MSG(IS_THREAD_SYS_FLAGS(flags), "Only system flags allowed");
|
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()
|
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()
|
void RtosThread::terminate()
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
|
|
||||||
namespace sta {
|
namespace sta {
|
||||||
RtosTimer::RtosTimer(void (*callback)(void *arg), void *arg)
|
RtosTimer::RtosTimer(std::function<void(void*)> callback, void *arg)
|
||||||
: timer_id_{NULL},
|
: timer_id_{NULL},
|
||||||
timer_attr_{.name="Timer", .attr_bits=osTimerOnce},
|
timer_attr_{.name="Timer", .attr_bits=osTimerOnce},
|
||||||
callback_{callback},
|
callback_{callback},
|
||||||
@ -28,7 +28,7 @@ namespace sta {
|
|||||||
osTimerDelete(timer_id_);
|
osTimerDelete(timer_id_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RtosTimer::setCallback(void (*callback)(void *arg), void *arg)
|
void RtosTimer::setCallback(std::function<void(void*)> callback, void *arg)
|
||||||
{
|
{
|
||||||
callback_ = callback;
|
callback_ = callback;
|
||||||
callbackArg_ = arg;
|
callbackArg_ = arg;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user