-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes for PR 2041 (Continuous time updates)
- Loading branch information
1 parent
a16ff8c
commit a796bc1
Showing
9 changed files
with
77 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#define ASSERT(expr) assert(expr) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include "semphr.h" | ||
#include <SDL2/SDL.h> | ||
#include <stdexcept> | ||
|
||
QueueHandle_t xSemaphoreCreateMutex() { | ||
SemaphoreHandle_t xSemaphore = xQueueCreate(1, 1); | ||
Queue_t *pxQueue = (Queue_t *)xSemaphore; | ||
pxQueue->queue.push_back(0); | ||
return xSemaphore; | ||
}; | ||
|
||
BaseType_t xSemaphoreTake(SemaphoreHandle_t xSemaphore, | ||
TickType_t xTicksToWait) { | ||
Queue_t *pxQueue = (Queue_t *)xSemaphore; | ||
while (!pxQueue->queue.empty()) { | ||
if (xTicksToWait <= 25) { | ||
return false; | ||
} | ||
SDL_Delay(25); | ||
xTicksToWait -= 25; | ||
} | ||
std::lock_guard<std::mutex> guard(pxQueue->mutex); | ||
if (!pxQueue->queue.empty()) { | ||
return false; | ||
} | ||
pxQueue->queue.push_back(0); | ||
return true; | ||
} | ||
BaseType_t xSemaphoreGive(SemaphoreHandle_t xSemaphore) { | ||
Queue_t *pxQueue = (Queue_t *)xSemaphore; | ||
std::lock_guard<std::mutex> guard(pxQueue->mutex); | ||
if (pxQueue->queue.size() != 1) { | ||
throw std::runtime_error("Mutex released without being held"); | ||
} | ||
pxQueue->queue.pop_back(); | ||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#pragma once | ||
|
||
#include "FreeRTOS.h" | ||
#include "queue.h" | ||
|
||
typedef QueueHandle_t SemaphoreHandle_t; | ||
|
||
QueueHandle_t xSemaphoreCreateMutex(); | ||
|
||
BaseType_t xSemaphoreTake( SemaphoreHandle_t xSemaphore, TickType_t xTicksToWait); | ||
BaseType_t xSemaphoreGive( SemaphoreHandle_t xSemaphore); |