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
kernel.c File Reference

ICARUS Kernel Core Implementation. More...

#include "icarus/kernel.h"
#include "icarus/task.h"
#include "icarus/scheduler.h"
#include "bsp/display.h"
#include "bsp/led.h"
#include <string.h>
#include <stddef.h>

Go to the source code of this file.

Functions

void start_cold_task (icarus_task_t *task)
 
void __enter_critical (void)
 Privileged implementation of enter_critical.
 
void __exit_critical (void)
 Privileged implementation of exit_critical.
 
static void __init_sem (uint8_t semaphore_idx, uint32_t semaphore_count, bool should_engage)
 
static void __init_pipe (uint8_t message_pipe_idx, uint16_t max_messages, bool should_engage)
 
static void os_idle_task (void)
 
static void os_heartbeat_task (void)
 
void __os_init (void)
 Privileged implementation of os_init.
 
void __os_start (void)
 Privileged implementation of os_start.
 
uint32_t * __kernel_get_stack (uint8_t task_idx)
 Privileged implementation of kernel_get_stack.
 
uint32_t * __kernel_get_data (uint8_t task_idx)
 Privileged implementation of kernel_get_data.
 
void * __kernel_protected_data (uint16_t num_words)
 Privileged implementation of kernel_protected_data.
 
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.
 

Variables

icarus_task_ttask_list [128]
 Array of pointers to all task control blocks.
 
icarus_semaphore_tsemaphore_list [64]
 Array of pointers to all semaphores.
 
icarus_pipe_tmessage_pipe_list [64]
 Array of pointers to all message pipes.
 
static icarus_task_t task_pool [128]
 
static icarus_semaphore_t semaphore_pool [64]
 
static icarus_pipe_t message_pipe_pool [64]
 
int8_t cleanup_task_idx [128]
 Cleanup task index queue.
 
uint8_t current_task_index
 Index of currently executing task.
 
uint8_t running_task_count
 Count of tasks in active states.
 
uint8_t num_created_tasks
 Total number of created tasks.
 
volatile uint32_t current_task_ticks_remaining
 Ticks remaining in current task's time slice.
 
volatile uint32_t ticks_per_task
 Configured ticks per time slice.
 
uint32_t cpu_vregisters [16]
 
volatile uint32_t os_tick_count
 System tick counter.
 
volatile uint8_t os_running
 Flag indicating OS is running.
 
volatile uint8_t critical_stack_depth
 
volatile bool scheduler_enabled
 Scheduler enable flag.
 
int8_t current_cleanup_task_idx
 Current cleanup queue write index.
 
static uint32_t stack_pool [128][512]
 
static uint32_t data_pool [128][512]
 
static uint16_t data_pool_word_offsets [128]
 

Detailed Description

ICARUS Kernel Core Implementation.

Version
0.1.0

Core kernel state, data structures, and initialization.

Author
Souham Biswas
Date
2025

Definition in file kernel.c.

Function Documentation

◆ __enter_critical()

void __enter_critical ( void  )

Privileged implementation of enter_critical.

Note
Internal function - use enter_critical() wrapper

Definition at line 114 of file kernel.c.

References critical_stack_depth, and scheduler_enabled.

Referenced by crc16_ccitt(), enter_critical(), and SVC_Handler_C().

◆ __exit_critical()

void __exit_critical ( void  )

Privileged implementation of exit_critical.

Note
Internal function - use exit_critical() wrapper

Definition at line 124 of file kernel.c.

References critical_stack_depth, and scheduler_enabled.

Referenced by crc16_ccitt(), exit_critical(), and SVC_Handler_C().

◆ __init_pipe()

static void __init_pipe ( uint8_t  message_pipe_idx,
uint16_t  max_messages,
bool  should_engage 
)
inlinestatic

◆ __init_sem()

static void __init_sem ( uint8_t  semaphore_idx,
uint32_t  semaphore_count,
bool  should_engage 
)
inlinestatic

◆ __kernel_get_data()

uint32_t * __kernel_get_data ( uint8_t  task_idx)

Privileged implementation of kernel_get_data.

Note
Internal function - use kernel_get_data() wrapper

Definition at line 282 of file kernel.c.

References data_pool.

Referenced by __os_register_task(), kernel_get_data(), and SVC_Handler_C().

◆ __kernel_get_stack()

uint32_t * __kernel_get_stack ( uint8_t  task_idx)

Privileged implementation of kernel_get_stack.

Note
Internal function - use kernel_get_stack() wrapper

Definition at line 269 of file kernel.c.

References stack_pool.

Referenced by __os_register_task(), kernel_get_stack(), and SVC_Handler_C().

◆ __kernel_protected_data()

void * __kernel_protected_data ( uint16_t  num_words)

Privileged implementation of kernel_protected_data.

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

Definition at line 295 of file kernel.c.

References current_task_index, data_pool, data_pool_word_offsets, and ICARUS_DATA_WORDS.

Referenced by kernel_protected_data(), 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_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_init()

◆ __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_start()

void __os_start ( void  )

Privileged implementation of os_start.

Note
Internal function - use os_start() wrapper

Definition at line 253 of file kernel.c.

References current_task_index, ICARUS_MAX_TASKS, num_created_tasks, start_cold_task(), and task_list.

Referenced by os_start().

◆ __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_heartbeat_task()

◆ os_idle_task()

static void os_idle_task ( void  )
static

Definition at line 163 of file kernel.c.

References display_init(), and os_yield().

Referenced by __os_init().

◆ start_cold_task()

void start_cold_task ( icarus_task_t task)
extern

Referenced by __os_start().

Variable Documentation

◆ cleanup_task_idx

int8_t cleanup_task_idx[128]

Cleanup task index queue.

Definition at line 57 of file kernel.c.

Referenced by __os_exit_task(), __os_init(), and __os_kill_process().

◆ cpu_vregisters

uint32_t cpu_vregisters[16]

Definition at line 68 of file kernel.c.

Referenced by __os_init().

◆ critical_stack_depth

volatile uint8_t critical_stack_depth

Definition at line 71 of file kernel.c.

Referenced by __enter_critical(), and __exit_critical().

◆ current_cleanup_task_idx

int8_t current_cleanup_task_idx

Current cleanup queue write index.

Definition at line 73 of file kernel.c.

Referenced by __os_exit_task(), __os_init(), and __os_kill_process().

◆ current_task_index

uint8_t current_task_index

◆ current_task_ticks_remaining

volatile uint32_t current_task_ticks_remaining

Ticks remaining in current task's time slice.

Definition at line 66 of file kernel.c.

Referenced by __os_get_task_ticks_remaining(), __os_init(), __os_yield(), and SysTick_Handler().

◆ data_pool

uint32_t data_pool[128][512]
static

Definition at line 89 of file kernel.c.

Referenced by __kernel_get_data(), and __kernel_protected_data().

◆ data_pool_word_offsets

uint16_t data_pool_word_offsets[128]
static

Definition at line 98 of file kernel.c.

Referenced by __kernel_protected_data(), and __os_init().

◆ message_pipe_list

◆ message_pipe_pool

icarus_pipe_t message_pipe_pool[64]
static

Definition at line 56 of file kernel.c.

Referenced by __os_init().

◆ num_created_tasks

◆ os_running

volatile uint8_t os_running

Flag indicating OS is running.

Definition at line 70 of file kernel.c.

Referenced by __os_init(), __os_is_running(), and SysTick_Handler().

◆ os_tick_count

◆ running_task_count

uint8_t running_task_count

Count of tasks in active states.

Definition at line 64 of file kernel.c.

Referenced by __os_exit_task(), __os_get_running_task_count(), __os_init(), __os_kill_process(), __os_restart_task(), and os_create_task().

◆ scheduler_enabled

volatile bool scheduler_enabled

Scheduler enable flag.

Definition at line 72 of file kernel.c.

Referenced by __enter_critical(), __exit_critical(), __os_init(), and SysTick_Handler().

◆ semaphore_list

◆ semaphore_pool

icarus_semaphore_t semaphore_pool[64]
static

Definition at line 55 of file kernel.c.

Referenced by __os_init().

◆ stack_pool

uint32_t stack_pool[128][512]
static

Definition at line 79 of file kernel.c.

Referenced by __kernel_get_stack().

◆ task_list

◆ task_pool

icarus_task_t task_pool[128]
static

Definition at line 54 of file kernel.c.

Referenced by __os_init().

◆ ticks_per_task

volatile uint32_t ticks_per_task

Configured ticks per time slice.

Definition at line 67 of file kernel.c.

Referenced by __os_init(), and __os_yield().