mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/rtos2-utils.git
synced 2025-06-10 01:55:59 +00:00
Merge pull request 'Updated id handling for mutex and signal, sleep() for thread.' (#20) from mut-constr into main
Reviewed-on: https://git.intern.spaceteamaachen.de/ALPAKA/rtos2-utils/pulls/20 Reviewed-by: carlwachter <carlwachter@noreply.git.intern.spaceteamaachen.de>
This commit is contained in:
commit
b30d47413b
@ -23,13 +23,20 @@ namespace sta
|
|||||||
/**
|
/**
|
||||||
* @param handle CMSIS RTOS2 mutex
|
* @param handle CMSIS RTOS2 mutex
|
||||||
*/
|
*/
|
||||||
RtosMutex(osMutexId_t * handle);
|
RtosMutex(osMutexId_t handle);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Construct a new Rtos Mutex object
|
||||||
|
*
|
||||||
|
* @param name The name of the mutex.
|
||||||
|
*/
|
||||||
|
RtosMutex(const char* name);
|
||||||
|
|
||||||
void acquire() override;
|
void acquire() override;
|
||||||
void release() override;
|
void release() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
osMutexId_t * handle_; /**< CMSIS RTOS2 mutex */
|
osMutexId_t handle_; /**< CMSIS RTOS2 mutex */
|
||||||
};
|
};
|
||||||
} // namespace sta
|
} // namespace sta
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ namespace sta
|
|||||||
/**
|
/**
|
||||||
* @param semaphore CMSIS RTOS2 semaphore
|
* @param semaphore CMSIS RTOS2 semaphore
|
||||||
*/
|
*/
|
||||||
RtosSignal(osSemaphoreId_t * semaphore);
|
RtosSignal(osSemaphoreId_t semaphore);
|
||||||
|
|
||||||
void notify() override;
|
void notify() override;
|
||||||
bool peek() override;
|
bool peek() override;
|
||||||
@ -31,7 +31,7 @@ namespace sta
|
|||||||
void wait() override;
|
void wait() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
osSemaphoreId_t * semaphore_; /**< CMSIS RTOS2 semaphore */
|
osSemaphoreId_t semaphore_; /**< CMSIS RTOS2 semaphore */
|
||||||
};
|
};
|
||||||
} // namespace sta
|
} // namespace sta
|
||||||
|
|
||||||
|
@ -74,6 +74,14 @@ namespace sta
|
|||||||
*/
|
*/
|
||||||
RtosThread(const Handle & handle);
|
RtosThread(const Handle & handle);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Sets the thread to BLOCKED for a given number of ticks.
|
||||||
|
* Other threads can run in the meantime.
|
||||||
|
*
|
||||||
|
* @param ticks The number of ticks before setting the thread to READY again.
|
||||||
|
*/
|
||||||
|
void sleep(uint32_t ticks);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Send user notification flags to thread.
|
* @brief Send user notification flags to thread.
|
||||||
*
|
*
|
||||||
|
@ -1,19 +1,29 @@
|
|||||||
#include <sta/rtos/mutex.hpp>
|
#include <sta/rtos/mutex.hpp>
|
||||||
|
|
||||||
|
#include <sta/debug/assert.hpp>
|
||||||
|
|
||||||
|
|
||||||
namespace sta
|
namespace sta
|
||||||
{
|
{
|
||||||
RtosMutex::RtosMutex(osMutexId_t * handle)
|
RtosMutex::RtosMutex(osMutexId_t handle)
|
||||||
: handle_{handle}
|
: handle_{handle}
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
RtosMutex::RtosMutex(const char* name)
|
||||||
|
{
|
||||||
|
osMutexAttr_t attribs = { .name = name};
|
||||||
|
handle_ = osMutexNew(&attribs);
|
||||||
|
|
||||||
|
STA_ASSERT(handle_ != NULL);
|
||||||
|
}
|
||||||
|
|
||||||
void RtosMutex::acquire()
|
void RtosMutex::acquire()
|
||||||
{
|
{
|
||||||
osMutexAcquire(*handle_, osWaitForever);
|
osMutexAcquire(handle_, osWaitForever);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RtosMutex::release()
|
void RtosMutex::release()
|
||||||
{
|
{
|
||||||
osMutexRelease(*handle_);
|
osMutexRelease(handle_);
|
||||||
}
|
}
|
||||||
} // namespace sta
|
} // namespace sta
|
||||||
|
@ -3,27 +3,27 @@
|
|||||||
|
|
||||||
namespace sta
|
namespace sta
|
||||||
{
|
{
|
||||||
RtosSignal::RtosSignal(osSemaphoreId_t * semaphore)
|
RtosSignal::RtosSignal(osSemaphoreId_t semaphore)
|
||||||
: semaphore_{semaphore}
|
: semaphore_{semaphore}
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void RtosSignal::notify()
|
void RtosSignal::notify()
|
||||||
{
|
{
|
||||||
osSemaphoreRelease(*semaphore_);
|
osSemaphoreRelease(semaphore_);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RtosSignal::peek()
|
bool RtosSignal::peek()
|
||||||
{
|
{
|
||||||
return (osSemaphoreGetCount(*semaphore_) != 0);
|
return (osSemaphoreGetCount(semaphore_) != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RtosSignal::test()
|
bool RtosSignal::test()
|
||||||
{
|
{
|
||||||
return (osSemaphoreAcquire(*semaphore_, 0) == osOK);
|
return (osSemaphoreAcquire(semaphore_, 0) == osOK);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RtosSignal::wait()
|
void RtosSignal::wait()
|
||||||
{
|
{
|
||||||
osSemaphoreAcquire(*semaphore_, osWaitForever);
|
osSemaphoreAcquire(semaphore_, osWaitForever);
|
||||||
}
|
}
|
||||||
} // namespace sta
|
} // namespace sta
|
||||||
|
@ -17,6 +17,10 @@ namespace sta
|
|||||||
terminate_{false}
|
terminate_{false}
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
void RtosThread::sleep(uint32_t ticks)
|
||||||
|
{
|
||||||
|
osDelay(ticks);
|
||||||
|
}
|
||||||
|
|
||||||
void RtosThread::notify(uint32_t flags)
|
void RtosThread::notify(uint32_t flags)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user