mirror of
https://github.com/ByteWelder/Tactility.git
synced 2026-04-19 01:45:06 +00:00
- Add kernel support for SPI driver - Add kernel support for UART driver - Implemented ESP32 UART kernel driver - Update existing UART-related code in Tactility to use new kernel driver - Remove UART from tt::hal::Configuration - Remove tt_hal_uart functionality but keep functions for now - Update devicetrees for UART changes - Kernel mutex and recursive mutex: improved locking API design - Other kernel improvements - Added device_exists_of_type() and device_find_by_name()
55 lines
1.4 KiB
C
55 lines
1.4 KiB
C
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
#pragma once
|
|
|
|
#include <tactility/freertos/semphr.h>
|
|
#include <tactility/check.h>
|
|
#include <stdbool.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
struct RecursiveMutex {
|
|
QueueHandle_t handle;
|
|
};
|
|
|
|
inline static void recursive_mutex_construct(struct RecursiveMutex* mutex) {
|
|
check(mutex->handle == NULL);
|
|
mutex->handle = xSemaphoreCreateRecursiveMutex();
|
|
}
|
|
|
|
inline static void recursive_mutex_destruct(struct RecursiveMutex* mutex) {
|
|
check(mutex->handle != NULL);
|
|
check(xPortInIsrContext() != pdTRUE);
|
|
vSemaphoreDelete(mutex->handle);
|
|
mutex->handle = NULL;
|
|
}
|
|
|
|
inline static void recursive_mutex_lock(struct RecursiveMutex* mutex) {
|
|
check(xPortInIsrContext() != pdTRUE);
|
|
xSemaphoreTakeRecursive(mutex->handle, portMAX_DELAY);
|
|
}
|
|
|
|
inline static bool recursive_mutex_is_locked(struct RecursiveMutex* mutex) {
|
|
if (xPortInIsrContext() == pdTRUE) {
|
|
return xSemaphoreGetMutexHolderFromISR(mutex->handle) != NULL;
|
|
} else {
|
|
return xSemaphoreGetMutexHolder(mutex->handle) != NULL;
|
|
}
|
|
}
|
|
|
|
inline static bool recursive_mutex_try_lock(struct RecursiveMutex* mutex, TickType_t timeout) {
|
|
check(xPortInIsrContext() != pdTRUE);
|
|
return xSemaphoreTakeRecursive(mutex->handle, timeout) == pdTRUE;
|
|
}
|
|
|
|
inline static void recursive_mutex_unlock(struct RecursiveMutex* mutex) {
|
|
check(xPortInIsrContext() != pdTRUE);
|
|
xSemaphoreGiveRecursive(mutex->handle);
|
|
}
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|