Adds sitara_depot/free_rtos Original one is on server_gorbunov/SmartForce4.0/sitara_depot
58 lines
1.2 KiB
C++
58 lines
1.2 KiB
C++
#ifndef SRC_APP_SEMAPHORE_SEMAPHORE_HPP_
|
|
#define SRC_APP_SEMAPHORE_SEMAPHORE_HPP_
|
|
|
|
#include <kernel/dpl/SemaphoreP.h>
|
|
#include <kernel/dpl/DebugP.h>
|
|
|
|
namespace free_rtos {
|
|
|
|
/**
|
|
* @brief Ñ++ îáåðòêà ñåìàôîðà â free rtos
|
|
*
|
|
*/
|
|
class Semaphore {
|
|
public:
|
|
enum Type {
|
|
e_semTypeBinary,
|
|
e_semTypeCounting
|
|
};
|
|
|
|
Semaphore() {
|
|
int32_t status = SystemP_FAILURE;
|
|
status = SemaphoreP_constructBinary(&sem_, 0);
|
|
DebugP_assert(SystemP_SUCCESS == status);
|
|
}
|
|
|
|
Semaphore(Semaphore::Type type, uint32_t init_val, uint32_t max_val) {
|
|
int32_t status = SystemP_FAILURE;
|
|
|
|
if (type == Semaphore::e_semTypeBinary) {
|
|
status = SemaphoreP_constructBinary(&sem_, init_val);
|
|
}
|
|
else if (type == Semaphore::e_semTypeCounting) {
|
|
status = SemaphoreP_constructCounting(&sem_, init_val, max_val);
|
|
}
|
|
|
|
DebugP_assert(SystemP_SUCCESS == status);
|
|
}
|
|
|
|
void post() {
|
|
SemaphoreP_post(&sem_);
|
|
}
|
|
|
|
int32_t pend(uint32_t ticks = SystemP_WAIT_FOREVER) {
|
|
return SemaphoreP_pend(&sem_, ticks);
|
|
}
|
|
|
|
~Semaphore() {
|
|
SemaphoreP_destruct(&sem_);
|
|
}
|
|
|
|
private:
|
|
SemaphoreP_Object sem_;
|
|
};
|
|
|
|
}
|
|
|
|
#endif
|