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
scheduler.h File Reference

ICARUS Scheduler - Task Scheduling and Timing. More...

#include <stdint.h>
#include "icarus/types.h"

Go to the source code of this file.

Functions

void os_yield (void)
 Voluntarily yield CPU to scheduler.
 
uint32_t task_active_sleep (uint32_t ticks)
 Sleep for specified ticks (cooperative)
 
uint32_t task_blocking_sleep (uint32_t ticks)
 Sleep with scheduler disabled (blocking)
 
uint32_t task_busy_wait (uint32_t ticks)
 Busy-wait for specified ticks.
 
uint32_t os_get_tick_count (void)
 Get current system tick count.
 
uint8_t os_get_running_task_count (void)
 Get number of active tasks.
 
const char * os_get_current_task_name (void)
 Get name of currently executing task.
 
uint32_t os_get_task_ticks_remaining (void)
 Get remaining ticks in current time slice.
 
const char * os_get_task_name (uint8_t task_idx)
 Get task name by index (safe from unprivileged mode)
 
uint8_t os_get_num_created_tasks (void)
 Get number of created tasks (safe from unprivileged mode)
 
uint8_t os_is_running (void)
 Check if OS is running (safe from unprivileged mode)
 
icarus_task_state_t os_get_task_state (uint8_t task_idx)
 Get a task's current state (safe from unprivileged mode).
 
uint32_t os_get_task_dispatch_count (uint8_t task_idx)
 Get a task's dispatch count (times scheduled to run).
 
uint32_t os_get_stack_watermark (uint8_t task_idx)
 Get a task's stack high-water mark (minimum free words).
 
void os_update_stack_watermark (uint8_t task_idx)
 Scan a task's stack for the sentinel pattern and update the watermark field in the TCB.
 
void __os_yield (void)
 Privileged implementation of os_yield.
 
uint32_t __task_active_sleep (uint32_t ticks)
 Privileged implementation of task_active_sleep.
 
uint32_t __task_blocking_sleep (uint32_t ticks)
 Privileged implementation of task_blocking_sleep.
 
uint32_t __task_busy_wait (uint32_t ticks)
 Privileged implementation of task_busy_wait.
 
uint32_t __os_get_tick_count (void)
 Privileged implementation of os_get_tick_count.
 
uint8_t __os_get_running_task_count (void)
 Privileged implementation of os_get_running_task_count.
 
const char * __os_get_current_task_name (void)
 Privileged implementation of os_get_current_task_name.
 
uint32_t __os_get_task_ticks_remaining (void)
 Privileged implementation of os_get_task_ticks_remaining.
 
const char * __os_get_task_name (uint8_t task_idx)
 Privileged implementation of os_get_task_name.
 
uint8_t __os_get_num_created_tasks (void)
 Privileged implementation of os_get_num_created_tasks.
 
uint8_t __os_is_running (void)
 Privileged implementation of os_is_running.
 
icarus_task_state_t __os_get_task_state (uint8_t task_idx)
 Privileged implementation of os_get_task_state.
 
uint32_t __os_get_task_dispatch_count (uint8_t task_idx)
 Privileged implementation of os_get_task_dispatch_count.
 
uint32_t __os_get_stack_watermark (uint8_t task_idx)
 Privileged implementation of os_get_stack_watermark.
 
void __os_update_stack_watermark (uint8_t task_idx)
 Scan a task's stack from the base upward for the sentinel pattern (0xDEADC0DE) and update the watermark.
 

Detailed Description

ICARUS Scheduler - Task Scheduling and Timing.

Version
0.1.0

Task scheduling, yielding, and sleep functions.

Author
Souham Biswas
Date
2025

Definition in file scheduler.h.

Function Documentation

◆ __os_get_current_task_name()

const char * __os_get_current_task_name ( void  )

Privileged implementation of os_get_current_task_name.

Note
Internal function - use os_get_current_task_name() wrapper
Copies name from DTCM to RAM_D1 buffer for unprivileged access

Definition at line 65 of file scheduler.c.

References current_task_index, ICARUS_MAX_TASK_NAME_LEN, icarus_task_t::name, num_created_tasks, task_list, and task_name_buffer.

Referenced by os_get_current_task_name(), and SVC_Handler_C().

◆ __os_get_num_created_tasks()

uint8_t __os_get_num_created_tasks ( void  )

Privileged implementation of os_get_num_created_tasks.

Note
Internal function - use os_get_num_created_tasks() wrapper
Runs in SVC handler — reads num_created_tasks from DTCM in privileged mode

Definition at line 345 of file kernel.c.

References num_created_tasks.

Referenced by os_get_num_created_tasks(), and SVC_Handler_C().

◆ __os_get_running_task_count()

uint8_t __os_get_running_task_count ( void  )

Privileged implementation of os_get_running_task_count.

Note
Internal function - use os_get_running_task_count() wrapper

Definition at line 56 of file scheduler.c.

References running_task_count.

Referenced by os_get_running_task_count(), and SVC_Handler_C().

◆ __os_get_stack_watermark()

uint32_t __os_get_stack_watermark ( uint8_t  task_idx)

Privileged implementation of os_get_stack_watermark.

Parameters
task_idxTask index.
Returns
Minimum free stack words observed.

Definition at line 387 of file kernel.c.

References num_created_tasks, icarus_task_t::stack_watermark, and task_list.

Referenced by os_get_stack_watermark(), and SVC_Handler_C().

◆ __os_get_task_dispatch_count()

uint32_t __os_get_task_dispatch_count ( uint8_t  task_idx)

Privileged implementation of os_get_task_dispatch_count.

Parameters
task_idxTask index.
Returns
Dispatch count.

Definition at line 375 of file kernel.c.

References icarus_task_t::dispatch_count, num_created_tasks, and task_list.

Referenced by os_get_task_dispatch_count(), and SVC_Handler_C().

◆ __os_get_task_name()

const char * __os_get_task_name ( uint8_t  task_idx)

Privileged implementation of os_get_task_name.

Note
Internal function - use os_get_task_name() wrapper
Runs in SVC handler — reads task_list from DTCM in privileged mode
Copies name to RAM_D1 buffer to allow unprivileged access

Definition at line 315 of file kernel.c.

References ICARUS_MAX_TASK_NAME_LEN, icarus_task_t::name, num_created_tasks, and task_list.

Referenced by os_get_task_name(), and SVC_Handler_C().

◆ __os_get_task_state()

icarus_task_state_t __os_get_task_state ( uint8_t  task_idx)

Privileged implementation of os_get_task_state.

Parameters
task_idxTask index.
Returns
Task state enum value.

Definition at line 363 of file kernel.c.

References num_created_tasks, task_list, icarus_task_t::task_state, and TASK_STATE_FINISHED.

Referenced by os_get_task_state(), and SVC_Handler_C().

◆ __os_get_task_ticks_remaining()

uint32_t __os_get_task_ticks_remaining ( void  )

Privileged implementation of os_get_task_ticks_remaining.

Note
Internal function - use os_get_task_ticks_remaining() wrapper

Definition at line 87 of file scheduler.c.

References current_task_ticks_remaining.

Referenced by os_get_task_ticks_remaining(), and SVC_Handler_C().

◆ __os_get_tick_count()

uint32_t __os_get_tick_count ( void  )

Privileged implementation of os_get_tick_count.

Note
Internal function - use os_get_tick_count() wrapper

Definition at line 48 of file scheduler.c.

References os_tick_count.

Referenced by os_get_tick_count(), and SVC_Handler_C().

◆ __os_is_running()

uint8_t __os_is_running ( void  )

Privileged implementation of os_is_running.

Note
Internal function - use os_is_running() wrapper
Runs in SVC handler — reads os_running from DTCM in privileged mode

Definition at line 354 of file kernel.c.

References os_running.

Referenced by os_is_running(), and SVC_Handler_C().

◆ __os_update_stack_watermark()

void __os_update_stack_watermark ( uint8_t  task_idx)

Scan a task's stack from the base upward for the sentinel pattern (0xDEADC0DE) and update the watermark.

Parameters
task_idxTask index.

Definition at line 399 of file kernel.c.

References num_created_tasks, icarus_task_t::stack_base, icarus_task_t::stack_size, icarus_task_t::stack_watermark, and task_list.

Referenced by os_update_stack_watermark(), and SVC_Handler_C().

◆ __os_yield()

void __os_yield ( void  )

Privileged implementation of os_yield.

Note
Internal function - use os_yield() wrapper

Definition at line 99 of file scheduler.c.

References current_task_ticks_remaining, and ticks_per_task.

Referenced by __os_exit_task(), __os_kill_process(), __task_active_sleep(), os_yield(), and SVC_Handler_C().

◆ __task_active_sleep()

uint32_t __task_active_sleep ( uint32_t  ticks)

Privileged implementation of task_active_sleep.

Note
Internal function - use task_active_sleep() wrapper

Definition at line 108 of file scheduler.c.

References __os_yield(), current_task_index, icarus_task_t::global_tick_paused, os_tick_count, task_list, icarus_task_t::task_state, TASK_STATE_BLOCKED, and icarus_task_t::ticks_to_pause.

Referenced by SVC_Handler_C(), and task_active_sleep().

◆ __task_blocking_sleep()

uint32_t __task_blocking_sleep ( uint32_t  ticks)

Privileged implementation of task_blocking_sleep.

Note
Internal function - use task_blocking_sleep() wrapper
Spin-wait calls public SVC wrappers — only safe from thread mode

Definition at line 121 of file scheduler.c.

References enter_critical(), exit_critical(), and task_busy_wait().

Referenced by task_blocking_sleep().

◆ __task_busy_wait()

uint32_t __task_busy_wait ( uint32_t  ticks)

Privileged implementation of task_busy_wait.

Note
Internal function - use task_busy_wait() wrapper
Uses os_get_tick_count() SVC gate — safe with DTCM priv-only

Definition at line 133 of file scheduler.c.

References os_get_tick_count(), and os_tick_count.

Referenced by task_busy_wait().

◆ os_get_current_task_name()

const char * os_get_current_task_name ( void  )

Get name of currently executing task.

Returns
Task name string or "unknown"

Definition at line 575 of file svc.c.

◆ os_get_num_created_tasks()

uint8_t os_get_num_created_tasks ( void  )

Get number of created tasks (safe from unprivileged mode)

Returns
Number of tasks registered with os_register_task()
Note
Uses SVC to read num_created_tasks from DTCM in privileged mode

Get number of created tasks (safe from unprivileged mode)

Returns
Number of tasks registered with os_register_task()
Note
Safe to call from unprivileged mode once DTCM is priv-only

Definition at line 1145 of file svc.c.

References __os_get_num_created_tasks(), and SVC_GET_NUM_TASKS.

Referenced by display_init().

◆ os_get_running_task_count()

uint8_t os_get_running_task_count ( void  )

Get number of active tasks.

Returns
Count of tasks in RUNNING/READY/BLOCKED state

Definition at line 594 of file svc.c.

References __os_get_running_task_count(), and SVC_OS_GET_RUNNING_TASK_COUNT.

◆ os_get_stack_watermark()

uint32_t os_get_stack_watermark ( uint8_t  task_idx)

Get a task's stack high-water mark (minimum free words).

Parameters
task_idxTask index.
Returns
Minimum free stack words observed, or 0 if invalid.
Note
The watermark is updated lazily — call os_update_stack_watermark() to force a scan.

Get a task's stack high-water mark (minimum free words).

Definition at line 1225 of file svc.c.

References __os_get_stack_watermark(), and SVC_GET_STACK_WATERMARK.

◆ os_get_task_dispatch_count()

uint32_t os_get_task_dispatch_count ( uint8_t  task_idx)

Get a task's dispatch count (times scheduled to run).

Parameters
task_idxTask index.
Returns
Dispatch count, or 0 if index is invalid.

Get a task's dispatch count (times scheduled to run).

Definition at line 1205 of file svc.c.

References __os_get_task_dispatch_count(), and SVC_GET_TASK_DISPATCH_COUNT.

◆ os_get_task_name()

const char * os_get_task_name ( uint8_t  task_idx)

Get task name by index (safe from unprivileged mode)

Parameters
task_idxTask index (0 to num_created_tasks-1)
Returns
Pointer to task name string, or NULL if invalid index
Note
Uses SVC to read task_list from DTCM in privileged mode

Get task name by index (safe from unprivileged mode)

Parameters
task_idxTask index (0 to num_created_tasks-1)
Returns
Pointer to task name string, or NULL if invalid index
Note
Safe to call from unprivileged mode once DTCM is priv-only

Definition at line 1123 of file svc.c.

References __os_get_task_name(), and SVC_GET_TASK_NAME.

Referenced by display_init().

◆ os_get_task_state()

icarus_task_state_t os_get_task_state ( uint8_t  task_idx)

Get a task's current state (safe from unprivileged mode).

Parameters
task_idxTask index (0 to num_created_tasks-1).
Returns
Task state, or TASK_STATE_FINISHED if index is invalid.
Note
Uses SVC to read task_list from DTCM in privileged mode.

Get a task's current state (safe from unprivileged mode).

Definition at line 1185 of file svc.c.

References __os_get_task_state(), and SVC_GET_TASK_STATE.

◆ os_get_task_ticks_remaining()

uint32_t os_get_task_ticks_remaining ( void  )

Get remaining ticks in current time slice.

Returns
Ticks remaining before preemption

Definition at line 613 of file svc.c.

References __os_get_task_ticks_remaining(), and SVC_OS_GET_TASK_TICKS_REMAINING.

◆ os_get_tick_count()

uint32_t os_get_tick_count ( void  )

Get current system tick count.

Returns
Ticks since os_start()
Note
Placed in ITCM for zero wait-state execution

Definition at line 556 of file svc.c.

References __os_get_tick_count(), and SVC_OS_GET_TICK_COUNT.

Referenced by __task_busy_wait().

◆ os_is_running()

uint8_t os_is_running ( void  )

Check if OS is running (safe from unprivileged mode)

Returns
1 if OS is running, 0 otherwise
Note
Uses SVC to read os_running from DTCM in privileged mode
Returns
1 if OS is running, 0 otherwise
Note
Safe to call from unprivileged mode once DTCM is priv-only

Definition at line 1166 of file svc.c.

References __os_is_running(), and SVC_OS_IS_RUNNING.

Referenced by os_heartbeat_task().

◆ os_update_stack_watermark()

void os_update_stack_watermark ( uint8_t  task_idx)

Scan a task's stack for the sentinel pattern and update the watermark field in the TCB.

Parameters
task_idxTask index.

Scan a task's stack for the sentinel pattern and update the watermark field in the TCB.

Definition at line 1245 of file svc.c.

References __os_update_stack_watermark(), and SVC_UPDATE_STACK_WATERMARK.

◆ os_yield()

void os_yield ( void  )

Voluntarily yield CPU to scheduler.

Note
Placed in ITCM for zero wait-state execution

Definition at line 511 of file svc.c.

◆ task_active_sleep()

uint32_t task_active_sleep ( uint32_t  ticks)

Sleep for specified ticks (cooperative)

Parameters
ticksNumber of ticks to sleep
Returns
Actual ticks elapsed
Note
Placed in ITCM for zero wait-state execution

Sleep for specified ticks (cooperative)

Definition at line 522 of file svc.c.

◆ task_blocking_sleep()

uint32_t task_blocking_sleep ( uint32_t  ticks)

Sleep with scheduler disabled (blocking)

Parameters
ticksNumber of ticks to wait
Returns
Actual ticks elapsed
Warning
Blocks all other tasks!

Sleep with scheduler disabled (blocking)

Definition at line 542 of file svc.c.

References __task_blocking_sleep().

Referenced by __io_putchar().

◆ task_busy_wait()

uint32_t task_busy_wait ( uint32_t  ticks)

Busy-wait for specified ticks.

Parameters
ticksNumber of ticks to wait
Returns
Actual ticks elapsed

Busy-wait for specified ticks.

Definition at line 549 of file svc.c.

References __task_busy_wait().

Referenced by __task_blocking_sleep().