Ken Van Hoeylandt 020aa471e2
File locking refactored (#631)
Remove FileMutex and wire locking into driver subsystems.
2026-08-28 01:06:53 +02:00

86 lines
2.4 KiB
C

// SPDX-License-Identifier: Apache-2.0
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include <stddef.h>
#include <tactility/freertos/freertos.h>
#include <tactility/error.h>
struct Device;
/**
* @brief API for SPI controller drivers.
*/
struct SpiControllerApi {
/**
* @brief Locks the SPI controller.
* @param[in] device the SPI controller device
* @retval ERROR_NONE when the operation was successful
*/
error_t (*lock)(struct Device* device);
/**
* @brief Tries to lock the SPI controller.
* @param[in] device the SPI controller device
* @param[in] timeout the maximum time to wait for the lock
* @retval ERROR_NONE when the operation was successful
* @retval ERROR_TIMEOUT when the operation timed out
*/
error_t (*try_lock)(struct Device* device, TickType_t timeout);
/**
* @brief Unlocks the SPI controller.
* @param[in] device the SPI controller device
* @retval ERROR_NONE when the operation was successful
*/
error_t (*unlock)(struct Device* device);
};
/**
* @brief Locks the SPI controller using the specified controller.
* @param[in] device the SPI controller device
* @retval ERROR_NONE when the operation was successful
*/
error_t spi_controller_lock(struct Device* device);
/**
* @brief Tries to lock the SPI controller using the specified controller.
* @param[in] device the SPI controller device
* @param[in] timeout the maximum ticks to wait for the lock
* @retval ERROR_NONE when the operation was successful
* @retval ERROR_TIMEOUT when the operation timed out
*/
error_t spi_controller_try_lock(struct Device* device, TickType_t timeout);
/**
* @brief Unlocks the SPI controller using the specified controller.
* @param[in] device the SPI controller device
* @retval ERROR_NONE when the operation was successful
*/
error_t spi_controller_unlock(struct Device* device);
/**
* @brief Locks device's parent bus when the parent is a SPI controller.
* @param[in] device the device whose parent may be a SPI controller
* @retval ERROR_NONE when the operation was successful, or the parent is not a SPI controller
*/
error_t spi_controller_lock_bus_of(struct Device* device);
/**
* @brief Unlocks a device's parent bus.
* @param[in] device the device whose parent may be a SPI controller
*/
void spi_controller_unlock_bus_of(struct Device* device);
extern const struct DeviceType SPI_CONTROLLER_TYPE;
#ifdef __cplusplus
}
#endif