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

ICARUS Kernel Core - State and Initialization. More...

#include <stdint.h>
#include <stdbool.h>
#include "bsp/retarget_hal.h"
#include "icarus/config.h"
#include "icarus/types.h"

Go to the source code of this file.

Functions

void os_init (void)
 Initialize the ICARUS kernel.
 
void os_start (void)
 Start the ICARUS scheduler.
 
void os_yield (void)
 Voluntarily yield CPU to scheduler.
 
uint32_t task_active_sleep (uint32_t ticks)
 Sleep for specified ticks (cooperative, via SVC)
 
const char * os_get_current_task_name (void)
 Get name of currently executing task.
 
void enter_critical (void)
 Enter critical section (disable scheduler)
 
void exit_critical (void)
 Exit critical section (re-enable scheduler if outermost)
 
uint32_t * kernel_get_stack (uint8_t task_idx)
 Get stack pointer for task index (internal use)
 
uint32_t * kernel_get_data (uint8_t task_idx)
 Get data pointer for task index (internal use)
 
void * kernel_protected_data (uint16_t num_words)
 Allocate protected data words for current task.
 
bool bkpram_write (const void *src, uint32_t offset, uint32_t len)
 Copy data into battery-backed RAM (RAM_D3) via SVC.
 
void __enter_critical (void)
 Privileged implementation of enter_critical.
 
void __exit_critical (void)
 Privileged implementation of exit_critical.
 
void __os_init (void)
 Privileged implementation of os_init.
 
void __os_start (void)
 Privileged implementation of os_start.
 
void * __kernel_protected_data (uint16_t num_words)
 Privileged implementation of kernel_protected_data.
 
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.
 

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.
 
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.
 
volatile uint32_t os_tick_count
 System tick counter.
 
volatile uint8_t os_running
 Flag indicating OS is running.
 
volatile bool scheduler_enabled
 Scheduler enable flag.
 
int8_t cleanup_task_idx [128]
 Cleanup task index queue.
 
int8_t current_cleanup_task_idx
 Current cleanup queue write index.
 

Detailed Description

ICARUS Kernel Core - State and Initialization.

Version
0.1.0

Core kernel state variables, data structures, and initialization. This is the foundation layer that other kernel modules depend on.

Author
Souham Biswas
Date
2025

Definition in file kernel.h.

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().

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

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

◆ bkpram_write()

bool bkpram_write ( const void *  src,
uint32_t  offset,
uint32_t  len 
)

Copy data into battery-backed RAM (RAM_D3) via SVC.

On target this issues an SVC that runs a validated memcpy in privileged mode, allowing unprivileged tasks to persist data into BKPRAM without an MPU region grant. Under HOST_TEST the call is a no-op that returns true.

Parameters
[in]srcSource buffer (caller-owned, any memory domain).
[in]offsetByte offset into BKPRAM (0 .. BSP_RAM_D3_SIZE-1).
[in]lenNumber of bytes to copy (must be > 0).
Return values
trueWrite completed successfully.
falseValidation failed (offset+len exceeds BKPRAM, or len==0).

Copy data into battery-backed RAM (RAM_D3) via SVC.

On target this issues an SVC that runs a validated memcpy in privileged mode, allowing unprivileged tasks to persist data into BKPRAM without an MPU region grant. Under HOST_TEST the call is a no-op that returns true.

Parameters
[in]srcSource buffer (caller-owned, any memory domain).
[in]offsetByte offset into BKPRAM (0 .. BSP_RAM_D3_SIZE-1).
[in]lenNumber of bytes to copy (must be > 0).
Return values
trueWrite completed successfully.
falseValidation failed (offset+len exceeds BKPRAM, or len==0).

Copy data into battery-backed RAM (RAM_D3) via SVC.

Definition at line 1737 of file svc.c.

References SVC_BKPRAM_WRITE.

◆ enter_critical()

void enter_critical ( void  )

Enter critical section (disable scheduler)

Note
Supports nesting

Definition at line 478 of file svc.c.

References __enter_critical(), and SVC_ENTER_CRITICAL.

Referenced by __task_blocking_sleep().

◆ exit_critical()

void exit_critical ( void  )

Exit critical section (re-enable scheduler if outermost)

Definition at line 489 of file svc.c.

References __exit_critical(), and SVC_EXIT_CRITICAL.

Referenced by __task_blocking_sleep().

◆ kernel_get_data()

uint32_t * kernel_get_data ( uint8_t  task_idx)

Get data pointer for task index (internal use)

Parameters
task_idxTask index
Returns
Pointer to data memory

Get data pointer for task index (internal use)

Definition at line 734 of file svc.c.

References __kernel_get_data(), and SVC_KERNEL_GET_DATA.

◆ kernel_get_stack()

uint32_t * kernel_get_stack ( uint8_t  task_idx)

Get stack pointer for task index (internal use)

Parameters
task_idxTask index
Returns
Pointer to stack memory

Get stack pointer for task index (internal use)

Definition at line 714 of file svc.c.

References __kernel_get_stack(), and SVC_KERNEL_GET_STACK.

◆ kernel_protected_data()

void * kernel_protected_data ( uint16_t  num_words)

Allocate protected data words for current task.

Definition at line 754 of file svc.c.

References __kernel_protected_data(), and SVC_KERNEL_PROTECTED_DATA.

◆ os_get_current_task_name()

const char * os_get_current_task_name ( void  )

Get name of currently executing task.

Definition at line 575 of file svc.c.

References __os_get_current_task_name(), and SVC_OS_GET_CURRENT_TASK_NAME.

Referenced by os_heartbeat_task().

◆ os_init()

void os_init ( void  )

Initialize the ICARUS kernel.

Must be called before any other kernel function. Initializes:

  • Task pool and task list
  • Semaphore pool
  • Message pipe pool
  • System tasks (idle, heartbeat)
Precondition
HAL must be initialized (hal_init() called)
Postcondition
Kernel is ready for task registration

Definition at line 501 of file svc.c.

References __os_init().

Referenced by main().

◆ os_start()

void os_start ( void  )

Start the ICARUS scheduler.

Begins task execution. This function does not return.

Precondition
os_init() must have been called
At least one task must be registered
Warning
This function never returns!

Definition at line 502 of file svc.c.

References __os_start().

Referenced by main().

◆ os_yield()

void os_yield ( void  )

Voluntarily yield CPU to scheduler.

Definition at line 511 of file svc.c.

References __os_yield(), and SVC_OS_YIELD.

Referenced by os_idle_task().

◆ task_active_sleep()

uint32_t task_active_sleep ( uint32_t  ticks)

Sleep for specified ticks (cooperative, via SVC)

Definition at line 522 of file svc.c.

References __task_active_sleep(), and SVC_TASK_ACTIVE_SLEEP.

Referenced by __pipe_dequeue(), __pipe_enqueue(), __semaphore_consume(), __semaphore_consume_timeout(), __semaphore_feed(), CDC_Write(), and os_heartbeat_task().

Variable Documentation

◆ cleanup_task_idx

int8_t cleanup_task_idx[128]
extern

Cleanup task index queue.

Definition at line 57 of file kernel.c.

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

◆ current_cleanup_task_idx

int8_t current_cleanup_task_idx
extern

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
extern

◆ current_task_ticks_remaining

volatile uint32_t current_task_ticks_remaining
extern

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().

◆ message_pipe_list

icarus_pipe_t* message_pipe_list[64]
extern

◆ num_created_tasks

◆ os_running

volatile uint8_t os_running
extern

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
extern

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
extern

Scheduler enable flag.

Definition at line 72 of file kernel.c.

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

◆ semaphore_list

◆ task_list

◆ ticks_per_task

volatile uint32_t ticks_per_task
extern

Configured ticks per time slice.

Definition at line 67 of file kernel.c.

Referenced by __os_init(), and __os_yield().