Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Duet3D/RepRapFirmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Crocker <dcrocker@eschertech.com>2018-04-01 18:49:43 +0300
committerDavid Crocker <dcrocker@eschertech.com>2018-04-01 18:49:43 +0300
commit97e7b46202b9f71075101ed86b6967904f87fa98 (patch)
tree4852f94f2497ae43f6f2ba69c6a72ace6f1f7fd0 /src/RTOSIface.cpp
parent4d151a5d02a8bca3810e4a75bf225136548fa1ab (diff)
More RTOS work
Refactored mutex and task interface Output channels, tool list and message box data are now thread safe
Diffstat (limited to 'src/RTOSIface.cpp')
-rw-r--r--src/RTOSIface.cpp126
1 files changed, 68 insertions, 58 deletions
diff --git a/src/RTOSIface.cpp b/src/RTOSIface.cpp
index 5d364739..dbde75c2 100644
--- a/src/RTOSIface.cpp
+++ b/src/RTOSIface.cpp
@@ -13,77 +13,107 @@
# include "task.h"
# include "semphr.h"
-static_assert(RTOSIface::TimeoutUnlimited == portMAX_DELAY, "Bad value for TimeoutUnlimited");
+static_assert(Mutex::TimeoutUnlimited == portMAX_DELAY, "Bad value for TimeoutUnlimited");
+
+void Mutex::Create()
+{
+ if (handle == nullptr)
+ {
+ handle = xSemaphoreCreateRecursiveMutexStatic(&storage);
+ }
+}
+
+bool Mutex::Take(uint32_t timeout) const
+{
+ return xSemaphoreTakeRecursive(handle, timeout) == pdTRUE;
+}
+
+bool Mutex::Release() const
+{
+ return xSemaphoreGiveRecursive(handle) == pdTRUE;
+}
+
+TaskHandle Mutex::GetHolder() const
+{
+ return static_cast<TaskHandle>(xSemaphoreGetMutexHolder(handle));
+}
+
+void Task::Create(TaskFunction_t pxTaskCode, const char * pcName, uint32_t ulStackDepth, void *pvParameters, unsigned int uxPriority, uint32_t * const puxStackBuffer)
+{
+ handle = xTaskCreateStatic(pxTaskCode, pcName, ulStackDepth, pvParameters, uxPriority, puxStackBuffer, &storage);
+}
+
+#else
+
+void Mutex::Create()
+{
+}
+
+bool Mutex::Take(uint32_t timeout) const
+{
+ return true;
+}
+
+bool Mutex::Release() const
+{
+ return true;
+}
+
+TaskHandle Mutex::GetHolder() const
+{
+ return nullptr;
+}
#endif
-Locker::Locker(MutexHandle hnd)
+MutexLocker::MutexLocker(const Mutex *m, uint32_t timeout)
{
- handle = hnd;
+ handle = m;
acquired =
#ifdef RTOS
- hnd == nullptr || xSemaphoreTakeRecursive(hnd, portMAX_DELAY);
+ m == nullptr || m->Take(timeout);
#else
true;
#endif
}
-Locker::Locker(MutexHandle hnd, uint32_t timeout)
+MutexLocker::MutexLocker(const Mutex& m, uint32_t timeout)
{
- handle = hnd;
+ handle = &m;
acquired =
#ifdef RTOS
- hnd == nullptr || xSemaphoreTakeRecursive(hnd, timeout);
+ m.Take(timeout);
#else
true;
#endif
}
-Locker::~Locker()
+void MutexLocker::Release()
{
#ifdef RTOS
if (acquired && handle != nullptr)
{
- xSemaphoreGiveRecursive(handle);
+ handle->Release();
+ acquired = false;
}
#endif
}
-namespace RTOSIface
+MutexLocker::~MutexLocker()
{
-
+ Release();
#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)
+ if (acquired && handle != nullptr)
{
- return xSemaphoreTakeRecursive(hnd, timeout) == pdTRUE;
+ handle->Release();
}
+#endif
+}
- bool ReleaseMutex(MutexHandle hnd)
- {
- return xSemaphoreGiveRecursive(hnd) == pdTRUE;
- }
+namespace RTOSIface
+{
- TaskHandle GetMutexHolder(MutexHandle hnd)
- {
- return static_cast<TaskHandle>(xSemaphoreGetMutexHolder(hnd));
- }
+#ifdef RTOS
TaskHandle GetCurrentTask()
{
@@ -92,26 +122,6 @@ namespace RTOSIface
#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;