Added boolean to encode termination requests; added start flag as system flag

This commit is contained in:
dario
2023-10-27 12:43:13 +02:00
parent 87ef535471
commit 067a48c309
2 changed files with 35 additions and 3 deletions

View File

@@ -14,7 +14,7 @@
/** /**
* @brief Number of bits in task notification flags used internally. * @brief Number of bits in task notification flags used internally.
*/ */
#define STA_RTOS_MAX_BITS_THREAD_SYS_NOTIFY 1U #define STA_RTOS_MAX_BITS_THREAD_SYS_NOTIFY 2U
/** /**
* @brief Number of user usable bits in task notification flags. * @brief Number of user usable bits in task notification flags.
*/ */
@@ -91,10 +91,23 @@ namespace sta
*/ */
uint32_t getFlags(); uint32_t getFlags();
/**
* @brief Wait for certain thread flags.
*
* @return Returns the flags triggering the activation.
*/
uint32_t wait(uint32_t flags);
/** /**
* @brief Send termination request to thread. * @brief Send termination request to thread.
*/ */
void requestTermination(); void requestTermination();
/**
* @brief Returns true if this thread was requested to terminate.
*/
bool checkTerminationRequest();
/** /**
* @brief Forcibly terminate thread. * @brief Forcibly terminate thread.
*/ */
@@ -109,6 +122,7 @@ namespace sta
private: private:
Handle handle_; Handle handle_;
bool terminate_;
}; };
} // namespace sta } // namespace sta

View File

@@ -29,7 +29,16 @@ 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::getFlags() uint32_t RtosThread::getFlags()
@@ -41,7 +50,16 @@ namespace sta
void RtosThread::requestTermination() void RtosThread::requestTermination()
{ {
sysNotify(STA_RTOS_THREAD_FLAG_TERMINATE); // sysNotify(STA_RTOS_THREAD_FLAG_TERMINATE);
terminate_ = true;
}
bool RtosThread::checkTerminationRequest()
{
bool temp = terminate_;
terminate_ = false;
return temp;
} }
void RtosThread::terminate() void RtosThread::terminate()