ICARUS OS (Intelligent Cooperative Architecture for Real-time Unified Systems) 0.1.0
Preemptive Real-Time Operating System for ARM Cortex-M7
Loading...
Searching...
No Matches
semaphore.c File Reference

ICARUS Semaphore Implementation. More...

#include "icarus/semaphore.h"
#include "icarus/kernel.h"
#include "icarus/scheduler.h"

Go to the source code of this file.

Functions

bool __semaphore_init (uint8_t semaphore_idx, uint32_t semaphore_count)
 Privileged implementation of semaphore_init.
 
bool __semaphore_feed (uint8_t semaphore_idx)
 Privileged implementation of semaphore_feed.
 
bool __semaphore_consume (uint8_t semaphore_idx)
 Privileged implementation of semaphore_consume.
 
bool __semaphore_consume_timeout (uint8_t semaphore_idx, uint32_t max_ticks)
 Privileged implementation of semaphore_consume_timeout.
 
uint32_t __semaphore_get_count (uint8_t semaphore_idx)
 Privileged implementation of semaphore_get_count.
 
uint32_t __semaphore_get_max_count (uint8_t semaphore_idx)
 Privileged implementation of semaphore_get_max_count.
 
bool __sem_can_feed (uint8_t semaphore_idx)
 Privileged call gate: can semaphore accept a feed?
 
bool __sem_can_consume (uint8_t semaphore_idx)
 Privileged call gate: can semaphore be consumed?
 
void __sem_increment (uint8_t semaphore_idx)
 Privileged write gate: increment semaphore count.
 
void __sem_decrement (uint8_t semaphore_idx)
 Privileged write gate: decrement semaphore count.
 

Detailed Description

ICARUS Semaphore Implementation.

Version
0.1.0

Counting semaphore implementation for task synchronization.

Author
Souham Biswas
Date
2025

Definition in file semaphore.c.

Function Documentation

◆ __sem_can_consume()

bool __sem_can_consume ( uint8_t  semaphore_idx)

Privileged call gate: can semaphore be consumed?

Note
Returns true if engaged and count > 0 Used by __semaphore_consume spin loop.

Definition at line 186 of file semaphore.c.

References icarus_semaphore_t::count, ICARUS_MAX_SEMAPHORES, and semaphore_list.

Referenced by sem_can_consume(), and SVC_Handler_C().

◆ __sem_can_feed()

bool __sem_can_feed ( uint8_t  semaphore_idx)

Privileged call gate: can semaphore accept a feed?

Note
Returns true if engaged and count < max_count Used by __semaphore_feed spin loop to avoid direct DTCM reads from unprivileged thread mode once DTCM is priv-only.

Definition at line 172 of file semaphore.c.

References icarus_semaphore_t::count, ICARUS_MAX_SEMAPHORES, icarus_semaphore_t::max_count, and semaphore_list.

Referenced by sem_can_feed(), and SVC_Handler_C().

◆ __sem_decrement()

void __sem_decrement ( uint8_t  semaphore_idx)

Privileged write gate: decrement semaphore count.

Note
Called after sem_can_consume() spin loop exits Runs in privileged SVC handler — already atomic, no critical section needed

Definition at line 213 of file semaphore.c.

References icarus_semaphore_t::count, ICARUS_MAX_SEMAPHORES, os_tick_count, semaphore_list, and icarus_semaphore_t::tick_updated_at.

Referenced by sem_decrement(), and SVC_Handler_C().

◆ __sem_increment()

void __sem_increment ( uint8_t  semaphore_idx)

Privileged write gate: increment semaphore count.

Note
Called after sem_can_feed() spin loop exits Runs in privileged SVC handler — already atomic, no critical section needed

Definition at line 199 of file semaphore.c.

References icarus_semaphore_t::count, ICARUS_MAX_SEMAPHORES, os_tick_count, semaphore_list, and icarus_semaphore_t::tick_updated_at.

Referenced by sem_increment(), and SVC_Handler_C().

◆ __semaphore_consume()

bool __semaphore_consume ( uint8_t  semaphore_idx)

Privileged implementation of semaphore_consume.

Note
Internal function - use semaphore_consume() wrapper
Spin-wait uses sem_can_consume() SVC gate — safe with DTCM priv-only

Definition at line 81 of file semaphore.c.

References ICARUS_MAX_SEMAPHORES, sem_can_consume(), sem_decrement(), semaphore_list, and task_active_sleep().

Referenced by semaphore_consume().

◆ __semaphore_consume_timeout()

bool __semaphore_consume_timeout ( uint8_t  semaphore_idx,
uint32_t  max_ticks 
)

Privileged implementation of semaphore_consume_timeout.

Spins with task_active_sleep(1) checking sem_can_consume() each tick. Returns false if max_ticks elapse without the semaphore becoming available. max_ticks == 0 is a non-blocking try (check once, return immediately).

Parameters
semaphore_idxSemaphore index.
max_ticksMaximum ticks to wait.
Return values
trueAcquired.
falseTimeout or invalid.

Definition at line 116 of file semaphore.c.

References ICARUS_MAX_SEMAPHORES, sem_can_consume(), sem_decrement(), semaphore_list, and task_active_sleep().

Referenced by semaphore_consume_timeout(), and SVC_Handler_C().

◆ __semaphore_feed()

bool __semaphore_feed ( uint8_t  semaphore_idx)

Privileged implementation of semaphore_feed.

Note
Internal function - use semaphore_feed() wrapper
Spin-wait uses sem_can_feed() SVC gate — safe with DTCM priv-only

Definition at line 54 of file semaphore.c.

References ICARUS_MAX_SEMAPHORES, sem_can_feed(), sem_increment(), semaphore_list, and task_active_sleep().

Referenced by semaphore_feed().

◆ __semaphore_get_count()

uint32_t __semaphore_get_count ( uint8_t  semaphore_idx)

Privileged implementation of semaphore_get_count.

Note
Internal function - use semaphore_get_count() wrapper

Definition at line 146 of file semaphore.c.

References icarus_semaphore_t::count, ICARUS_MAX_SEMAPHORES, and semaphore_list.

Referenced by semaphore_get_count(), and SVC_Handler_C().

◆ __semaphore_get_max_count()

uint32_t __semaphore_get_max_count ( uint8_t  semaphore_idx)

Privileged implementation of semaphore_get_max_count.

Note
Internal function - use semaphore_get_max_count() wrapper

Definition at line 158 of file semaphore.c.

References ICARUS_MAX_SEMAPHORES, icarus_semaphore_t::max_count, and semaphore_list.

Referenced by semaphore_get_max_count(), and SVC_Handler_C().

◆ __semaphore_init()

bool __semaphore_init ( uint8_t  semaphore_idx,
uint32_t  semaphore_count 
)

Privileged implementation of semaphore_init.

Note
Internal function - use semaphore_init() wrapper
Runs in SVC handler — already atomic, no critical section needed

Definition at line 35 of file semaphore.c.

References icarus_semaphore_t::count, icarus_semaphore_t::engaged, ICARUS_MAX_SEMAPHORES, icarus_semaphore_t::max_count, os_tick_count, semaphore_list, and icarus_semaphore_t::tick_updated_at.

Referenced by semaphore_init(), and SVC_Handler_C().