ca13734bf0
Add kernel (Cortex-M0/M3/M4, Tricore, S32K, RISC-V ports), drivers, middleware (CAN stack, diagnostics, safety), applications, board support, build/test tooling, and documentation.
38 lines
955 B
C
38 lines
955 B
C
/**
|
|
* @file semaphore.h
|
|
* @brief Semaphore synchronization primitive
|
|
*/
|
|
|
|
#ifndef SEMAPHORE_H
|
|
#define SEMAPHORE_H
|
|
|
|
#include "kernel.h"
|
|
|
|
/* Semaphore Types */
|
|
typedef enum {
|
|
SEMAPHORE_BINARY = 0,
|
|
SEMAPHORE_COUNTING = 1,
|
|
SEMAPHORE_MUTEX = 2
|
|
} SemaphoreType_t;
|
|
|
|
/* Semaphore Control Block */
|
|
typedef struct {
|
|
SemaphoreType_t type;
|
|
uint32_t count;
|
|
uint32_t max_count;
|
|
TaskHandle_t owner; /* For mutex */
|
|
uint8_t priority_ceiling;
|
|
TaskHandle_t* waiting_tasks;
|
|
uint32_t waiting_count;
|
|
} Semaphore_t;
|
|
|
|
/* Semaphore Functions */
|
|
KernelStatus_t semaphore_create(Semaphore_t* sem, SemaphoreType_t type,
|
|
uint32_t initial_count, uint32_t max_count);
|
|
KernelStatus_t semaphore_take(Semaphore_t* sem, TimeOut_t timeout);
|
|
KernelStatus_t semaphore_give(Semaphore_t* sem);
|
|
KernelStatus_t semaphore_delete(Semaphore_t* sem);
|
|
uint32_t semaphore_get_count(Semaphore_t* sem);
|
|
|
|
#endif /* SEMAPHORE_H */
|