2020-05-18 20:35:13 +02:00
|
|
|
#include <framework/osal/FreeRTOS/BinarySemaphore.h>
|
2020-05-27 19:56:02 +02:00
|
|
|
#include <framework/osal/FreeRTOS/BinSemaphUsingTask.h>
|
2020-05-18 20:35:13 +02:00
|
|
|
#include <framework/osal/FreeRTOS/CountingSemaphore.h>
|
2020-05-27 19:56:02 +02:00
|
|
|
#include <framework/osal/FreeRTOS/CountingSemaphUsingTask.h>
|
2020-05-18 20:35:13 +02:00
|
|
|
#include <framework/tasks/SemaphoreFactory.h>
|
|
|
|
#include <framework/serviceinterface/ServiceInterfaceStream.h>
|
|
|
|
|
|
|
|
SemaphoreFactory* SemaphoreFactory::factoryInstance = nullptr;
|
2020-05-27 11:48:11 +02:00
|
|
|
const uint32_t SemaphoreIF::NO_TIMEOUT = 0;
|
|
|
|
const uint32_t SemaphoreIF::MAX_TIMEOUT = portMAX_DELAY;
|
2020-05-18 20:35:13 +02:00
|
|
|
|
2020-05-27 19:56:02 +02:00
|
|
|
static const uint32_t USE_REGULAR_SEMAPHORES = 0;
|
|
|
|
static const uint32_t USE_TASK_NOTIFICATIONS = 1;
|
|
|
|
|
2020-05-18 20:35:13 +02:00
|
|
|
SemaphoreFactory::SemaphoreFactory() {
|
|
|
|
}
|
|
|
|
|
|
|
|
SemaphoreFactory::~SemaphoreFactory() {
|
|
|
|
delete factoryInstance;
|
|
|
|
}
|
|
|
|
|
|
|
|
SemaphoreFactory* SemaphoreFactory::instance() {
|
|
|
|
if (factoryInstance == nullptr){
|
|
|
|
factoryInstance = new SemaphoreFactory();
|
|
|
|
}
|
|
|
|
return SemaphoreFactory::factoryInstance;
|
|
|
|
}
|
|
|
|
|
2020-05-27 19:46:56 +02:00
|
|
|
SemaphoreIF* SemaphoreFactory::createBinarySemaphore(uint32_t argument) {
|
2020-05-27 19:56:02 +02:00
|
|
|
if(argument == USE_REGULAR_SEMAPHORES) {
|
|
|
|
return new BinarySemaphore();
|
|
|
|
}
|
|
|
|
else if(argument == USE_TASK_NOTIFICATIONS) {
|
|
|
|
return new BinarySemaphoreUsingTask();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
sif::warning << "SemaphoreFactory: Invalid argument, return regular"
|
|
|
|
"binary semaphore" << std::endl;
|
|
|
|
return new BinarySemaphore();
|
|
|
|
}
|
2020-05-18 20:35:13 +02:00
|
|
|
}
|
|
|
|
|
2020-05-27 21:27:31 +02:00
|
|
|
SemaphoreIF* SemaphoreFactory::createCountingSemaphore(uint8_t maxCount,
|
2020-05-27 19:46:56 +02:00
|
|
|
uint8_t initCount, uint32_t argument) {
|
2020-05-27 19:56:02 +02:00
|
|
|
if(argument == USE_REGULAR_SEMAPHORES) {
|
2020-05-27 21:27:31 +02:00
|
|
|
return new CountingSemaphore(maxCount, initCount);
|
2020-05-27 19:56:02 +02:00
|
|
|
}
|
|
|
|
else if(argument == USE_TASK_NOTIFICATIONS) {
|
2020-05-27 21:27:31 +02:00
|
|
|
return new CountingSemaphoreUsingTask(maxCount, initCount);
|
2020-05-27 19:56:02 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
sif::warning << "SemaphoreFactory: Invalid argument, return regular"
|
|
|
|
"binary semaphore" << std::endl;
|
2020-05-27 21:27:31 +02:00
|
|
|
return new CountingSemaphore(maxCount, initCount);
|
2020-05-27 19:56:02 +02:00
|
|
|
}
|
|
|
|
|
2020-05-18 20:35:13 +02:00
|
|
|
}
|
|
|
|
|
2020-05-27 19:46:56 +02:00
|
|
|
void SemaphoreFactory::deleteSemaphore(SemaphoreIF* semaphore) {
|
2020-05-18 20:35:13 +02:00
|
|
|
delete semaphore;
|
|
|
|
}
|