diff options
author | David Crocker <dcrocker@eschertech.com> | 2018-03-30 20:39:09 +0300 |
---|---|---|
committer | David Crocker <dcrocker@eschertech.com> | 2018-03-30 20:39:09 +0300 |
commit | de270d2a00fd83cc3961a749432bff940601f1dd (patch) | |
tree | 7a9f781a99def2ffa10734c1053d94e0cb3651d4 /src/RTOSIface.cpp | |
parent | 22e0ac40dd0f7fb5a362476d054bfbb6e8aa4293 (diff) |
Thread safe file system
Various changes to maske the filesystem thread safe
Diffstat (limited to 'src/RTOSIface.cpp')
-rw-r--r-- | src/RTOSIface.cpp | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/src/RTOSIface.cpp b/src/RTOSIface.cpp new file mode 100644 index 00000000..5d364739 --- /dev/null +++ b/src/RTOSIface.cpp @@ -0,0 +1,124 @@ +/* + * RTOS.cpp + * + * Created on: 30 Mar 2018 + * Author: David + */ + +#include "RTOSIface.h" + +#ifdef RTOS + +# include "FreeRTOS.h" +# include "task.h" +# include "semphr.h" + +static_assert(RTOSIface::TimeoutUnlimited == portMAX_DELAY, "Bad value for TimeoutUnlimited"); + +#endif + +Locker::Locker(MutexHandle hnd) +{ + handle = hnd; + acquired = +#ifdef RTOS + hnd == nullptr || xSemaphoreTakeRecursive(hnd, portMAX_DELAY); +#else + true; +#endif +} + +Locker::Locker(MutexHandle hnd, uint32_t timeout) +{ + handle = hnd; + acquired = +#ifdef RTOS + hnd == nullptr || xSemaphoreTakeRecursive(hnd, timeout); +#else + true; +#endif +} + +Locker::~Locker() +{ +#ifdef RTOS + if (acquired && handle != nullptr) + { + xSemaphoreGiveRecursive(handle); + } +#endif +} + +namespace RTOSIface +{ + +#ifdef RTOS + + TaskHandle CreateTask(TaskFunction_t pxTaskCode, const char * pcName, uint32_t ulStackDepth, void *pvParameters, unsigned int uxPriority, + uint32_t * const puxStackBuffer, TaskStorage& taskBuffer) + { + return static_cast<TaskHandle>(xTaskCreateStatic(pxTaskCode, pcName, ulStackDepth, pvParameters, uxPriority, puxStackBuffer, &taskBuffer)); + } + + void SuspendTask(TaskHandle hnd) + { + vTaskSuspend(hnd); + } + + MutexHandle CreateMutex(MutexStorage& st) + { + return static_cast<MutexHandle>(xSemaphoreCreateRecursiveMutexStatic(&st)); + } + + bool TakeMutex(MutexHandle hnd, uint32_t timeout) + { + return xSemaphoreTakeRecursive(hnd, timeout) == pdTRUE; + } + + bool ReleaseMutex(MutexHandle hnd) + { + return xSemaphoreGiveRecursive(hnd) == pdTRUE; + } + + TaskHandle GetMutexHolder(MutexHandle hnd) + { + return static_cast<TaskHandle>(xSemaphoreGetMutexHolder(hnd)); + } + + TaskHandle GetCurrentTask() + { + return static_cast<TaskHandle>(xTaskGetCurrentTaskHandle()); + } + +#else + + MutexHandle CreateMutex(MutexStorage& st) + { + return static_cast<MutexHandle>((void *)&st); + } + + bool TakeMutex(MutexHandle hnd, uint32_t timeout) + { + return true; + } + + bool ReleaseMutex(MutexHandle hnd) + { + return true; + } + + TaskHandle GetMutexHolder(MutexHandle hnd) + { + return nullptr; + } + + TaskHandle GetCurrentTask() + { + return nullptr; + } + +#endif + +} + +// End |