Midnight Sun Firmware
Loading...
Searching...
No Matches
semaphore.h
1#pragma once
2
3/************************************************************************************************
4 * @file semaphore.h
5 *
6 * @brief Header file for the semaphore library
7 *
8 * @date 2024-10-27
9 * @author Midnight Sun Team #24 - MSXVI
10 ************************************************************************************************/
11
12/* Standard library Headers */
13#include <stdbool.h>
14
15/* Inter-component Headers */
16#include "FreeRTOS.h"
17#include "semphr.h"
18
19/* Intra-component Headers */
20#include "status.h"
21
29#define BLOCK_INDEFINITELY UINT16_MAX
30
32typedef struct Semaphore {
33 SemaphoreHandle_t handle;
34 StaticSemaphore_t buffer;
36
37typedef Semaphore Mutex;
38
46
58StatusCode mutex_lock(Mutex *mutex, uint16_t ms_to_wait);
59
71
80StatusCode sem_init(Semaphore *sem, uint32_t max_count, uint32_t initial_count);
81
90StatusCode sem_wait(Semaphore *sem, uint32_t timeout_ms);
91
101
StatusCode sem_post(Semaphore *sem)
Releases a semaphore and increments the counting semaphore.
Definition: semaphore.c:80
StatusCode sem_init(Semaphore *sem, uint32_t max_count, uint32_t initial_count)
Initializes counting semaphore with max and initial count.
Definition: semaphore.c:58
StatusCode sem_wait(Semaphore *sem, uint32_t timeout_ms)
Obtains previously initiated semaphore and decrements the counting semaphore.
Definition: semaphore.c:70
StatusCode mutex_lock(Mutex *mutex, uint16_t ms_to_wait)
Locks a Mutex.
Definition: semaphore.c:27
StatusCode mutex_unlock(Mutex *mutex)
Unlocks a Mutex.
Definition: semaphore.c:46
StatusCode mutex_init(Mutex *mutex)
Initializes a mutex using provided static entity.
Definition: semaphore.c:18
StatusCode
StatusCodes for various errors.
Definition: status.h:27
Semaphore object with handle and buffer.
Definition: semaphore.h:32
StaticSemaphore_t buffer
Definition: semaphore.h:34
SemaphoreHandle_t handle
Definition: semaphore.h:33