summaryrefslogtreecommitdiff
path: root/sensor/patchedBLE/src/FreeRTOS.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'sensor/patchedBLE/src/FreeRTOS.cpp')
-rw-r--r--sensor/patchedBLE/src/FreeRTOS.cpp44
1 files changed, 16 insertions, 28 deletions
diff --git a/sensor/patchedBLE/src/FreeRTOS.cpp b/sensor/patchedBLE/src/FreeRTOS.cpp
index 1ae01d7..1f12c88 100644
--- a/sensor/patchedBLE/src/FreeRTOS.cpp
+++ b/sensor/patchedBLE/src/FreeRTOS.cpp
@@ -11,17 +11,22 @@
#include <sstream>
#include <iomanip>
#include "FreeRTOS.h"
-#include <esp_log.h>
#include "sdkconfig.h"
-
+#if defined(ARDUINO_ARCH_ESP32) && defined(CONFIG_ARDUHAL_ESP_LOG)
+#include "esp32-hal-log.h"
+#define LOG_TAG ""
+#else
+#include "esp_log.h"
static const char* LOG_TAG = "FreeRTOS";
+#endif
+
/**
* Sleep for the specified number of milliseconds.
* @param[in] ms The period in milliseconds for which to sleep.
*/
void FreeRTOS::sleep(uint32_t ms) {
- ::vTaskDelay(ms/portTICK_PERIOD_MS);
+ ::vTaskDelay(ms / portTICK_PERIOD_MS);
} // sleep
@@ -32,7 +37,7 @@ void FreeRTOS::sleep(uint32_t ms) {
* @param[in] param An optional parameter to be passed to the started task.
* @param[in] stackSize An optional paremeter supplying the size of the stack in which to run the task.
*/
-void FreeRTOS::startTask(void task(void*), std::string taskName, void *param, int stackSize) {
+void FreeRTOS::startTask(void task(void*), std::string taskName, void* param, uint32_t stackSize) {
::xTaskCreate(task, taskName.data(), stackSize, param, 5, NULL);
} // startTask
@@ -51,23 +56,9 @@ void FreeRTOS::deleteTask(TaskHandle_t pTask) {
* @return The time in milliseconds since the %FreeRTOS scheduler started.
*/
uint32_t FreeRTOS::getTimeSinceStart() {
- return (uint32_t)(xTaskGetTickCount()*portTICK_PERIOD_MS);
+ return (uint32_t) (xTaskGetTickCount() * portTICK_PERIOD_MS);
} // getTimeSinceStart
-/*
- * public:
- Semaphore(std::string = "<Unknown>");
- ~Semaphore();
- void give();
- void take(std::string owner="<Unknown>");
- void take(uint32_t timeoutMs, std::string owner="<Unknown>");
- private:
- SemaphoreHandle_t m_semaphore;
- std::string m_name;
- std::string m_owner;
- };
- *
- */
/**
* @brief Wait for a semaphore to be released by trying to take it and
@@ -78,7 +69,6 @@ uint32_t FreeRTOS::getTimeSinceStart() {
uint32_t FreeRTOS::Semaphore::wait(std::string owner) {
ESP_LOGV(LOG_TAG, ">> wait: Semaphore waiting: %s for %s", toString().c_str(), owner.c_str());
-
if (m_usePthreads) {
pthread_mutex_lock(&m_pthread_mutex);
} else {
@@ -134,7 +124,7 @@ void FreeRTOS::Semaphore::give() {
xSemaphoreGive(m_semaphore);
}
// #ifdef ARDUINO_ARCH_ESP32
-// FreeRTOS::sleep(10);
+// FreeRTOS::sleep(10);
// #endif
m_owner = std::string("<N/A>");
@@ -171,14 +161,13 @@ void FreeRTOS::Semaphore::giveFromISR() {
* @param [in] owner The new owner (for debugging)
* @return True if we took the semaphore.
*/
-bool FreeRTOS::Semaphore::take(std::string owner)
-{
+bool FreeRTOS::Semaphore::take(std::string owner) {
ESP_LOGD(LOG_TAG, "Semaphore taking: %s for %s", toString().c_str(), owner.c_str());
bool rc = false;
if (m_usePthreads) {
pthread_mutex_lock(&m_pthread_mutex);
} else {
- rc = ::xSemaphoreTake(m_semaphore, portMAX_DELAY);
+ rc = ::xSemaphoreTake(m_semaphore, portMAX_DELAY) == pdTRUE;
}
m_owner = owner;
if (rc) {
@@ -198,13 +187,12 @@ bool FreeRTOS::Semaphore::take(std::string owner)
* @return True if we took the semaphore.
*/
bool FreeRTOS::Semaphore::take(uint32_t timeoutMs, std::string owner) {
-
ESP_LOGV(LOG_TAG, "Semaphore taking: %s for %s", toString().c_str(), owner.c_str());
bool rc = false;
if (m_usePthreads) {
assert(false); // We apparently don't have a timed wait for pthreads.
} else {
- rc = ::xSemaphoreTake(m_semaphore, timeoutMs/portTICK_PERIOD_MS);
+ rc = ::xSemaphoreTake(m_semaphore, timeoutMs / portTICK_PERIOD_MS) == pdTRUE;
}
m_owner = owner;
if (rc) {
@@ -279,8 +267,8 @@ void Ringbuffer::returnItem(void* item) {
* @param [in] wait How long to wait before giving up. The default is to wait indefinitely.
* @return
*/
-uint32_t Ringbuffer::send(void* data, size_t length, TickType_t wait) {
- return ::xRingbufferSend(m_handle, data, length, wait);
+bool Ringbuffer::send(void* data, size_t length, TickType_t wait) {
+ return ::xRingbufferSend(m_handle, data, length, wait) == pdTRUE;
} // send