Add full automotive RTOS project
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.
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* @file isr.h
|
||||
* @brief Interrupt Service Routine management
|
||||
*/
|
||||
|
||||
#ifndef ISR_H
|
||||
#define ISR_H
|
||||
|
||||
#include "kernel.h"
|
||||
|
||||
/* ISR Types */
|
||||
typedef void (*ISRHandler_t)(void);
|
||||
|
||||
/* ISR Configuration */
|
||||
typedef struct {
|
||||
uint32_t irq_number;
|
||||
ISRHandler_t handler;
|
||||
uint8_t priority;
|
||||
} ISRConfig_t;
|
||||
|
||||
/* ISR Functions */
|
||||
KernelStatus_t isr_register(uint32_t irq_number, ISRHandler_t handler,
|
||||
uint8_t priority);
|
||||
KernelStatus_t isr_unregister(uint32_t irq_number);
|
||||
KernelStatus_t isr_enable(uint32_t irq_number);
|
||||
KernelStatus_t isr_disable(uint32_t irq_number);
|
||||
KernelStatus_t isr_set_priority(uint32_t irq_number, uint8_t priority);
|
||||
void isr_enter(void);
|
||||
void isr_exit(void);
|
||||
bool isr_is_in_context(void);
|
||||
|
||||
/* Critical Section Management */
|
||||
void critical_section_enter(void);
|
||||
void critical_section_exit(void);
|
||||
|
||||
#endif /* ISR_H */
|
||||
@@ -0,0 +1,102 @@
|
||||
/**
|
||||
* @file kernel.h
|
||||
* @brief Core kernel definitions and types for Automotive RTOS
|
||||
* @author Automotive RTOS Team
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
#ifndef KERNEL_H
|
||||
#define KERNEL_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
/* Kernel Version */
|
||||
#define KERNEL_VERSION_MAJOR 1
|
||||
#define KERNEL_VERSION_MINOR 0
|
||||
#define KERNEL_VERSION_PATCH 0
|
||||
|
||||
/* Configuration Constants */
|
||||
#define MAX_TASKS 32
|
||||
#define MAX_PRIORITY_LEVELS 16
|
||||
#define MAX_TASK_NAME_LENGTH 16
|
||||
#define IDLE_TASK_PRIORITY (MAX_PRIORITY_LEVELS - 1)
|
||||
|
||||
/* Task States */
|
||||
typedef enum {
|
||||
TASK_SUSPENDED = 0,
|
||||
TASK_READY = 1,
|
||||
TASK_RUNNING = 2,
|
||||
TASK_BLOCKED = 3,
|
||||
TASK_TERMINATED = 4
|
||||
} TaskState_t;
|
||||
|
||||
/* Task Priority Type */
|
||||
typedef uint8_t TaskPriority_t;
|
||||
|
||||
/* Task Handle */
|
||||
typedef struct TaskControlBlock* TaskHandle_t;
|
||||
|
||||
/* Task Function */
|
||||
typedef void (*TaskFunction_t)(void* parameters);
|
||||
|
||||
/* Time Types */
|
||||
typedef uint32_t TickType_t;
|
||||
typedef uint32_t TimeOut_t;
|
||||
|
||||
/* Error Codes */
|
||||
typedef enum {
|
||||
KERNEL_OK = 0,
|
||||
KERNEL_ERROR = -1,
|
||||
KERNEL_INVALID_PARAMETER = -2,
|
||||
KERNEL_OUT_OF_MEMORY = -3,
|
||||
KERNEL_TASK_NOT_FOUND = -4,
|
||||
KERNEL_PRIORITY_INVALID = -5,
|
||||
KERNEL_TIMEOUT = -6,
|
||||
KERNEL_RESOURCE_BUSY = -7
|
||||
} KernelStatus_t;
|
||||
|
||||
/* Task Creation Parameters */
|
||||
typedef struct {
|
||||
const char* name;
|
||||
TaskFunction_t function;
|
||||
void* parameters;
|
||||
uint32_t stack_size;
|
||||
TaskPriority_t priority;
|
||||
TickType_t period_ticks; /* 0 for aperiodic tasks */
|
||||
} TaskConfig_t;
|
||||
|
||||
/* Task Statistics */
|
||||
typedef struct {
|
||||
uint32_t execution_count;
|
||||
TickType_t last_execution_time;
|
||||
TickType_t max_execution_time;
|
||||
TickType_t total_execution_time;
|
||||
uint32_t stack_high_water_mark;
|
||||
uint32_t deadline_misses;
|
||||
} TaskStatistics_t;
|
||||
|
||||
/* Kernel Core Functions */
|
||||
KernelStatus_t kernel_init(void);
|
||||
KernelStatus_t kernel_start(void);
|
||||
void kernel_stop(void);
|
||||
TickType_t kernel_get_tick_count(void);
|
||||
KernelStatus_t kernel_delay(TickType_t ticks);
|
||||
|
||||
/* Task Management Functions */
|
||||
TaskHandle_t task_create(const TaskConfig_t* config);
|
||||
KernelStatus_t task_delete(TaskHandle_t task);
|
||||
KernelStatus_t task_suspend(TaskHandle_t task);
|
||||
KernelStatus_t task_resume(TaskHandle_t task);
|
||||
KernelStatus_t task_set_priority(TaskHandle_t task, TaskPriority_t new_priority);
|
||||
TaskPriority_t task_get_priority(TaskHandle_t task);
|
||||
TaskState_t task_get_state(TaskHandle_t task);
|
||||
KernelStatus_t task_get_statistics(TaskHandle_t task, TaskStatistics_t* stats);
|
||||
|
||||
/* Scheduler Control */
|
||||
void scheduler_yield(void);
|
||||
void scheduler_lock(void);
|
||||
void scheduler_unlock(void);
|
||||
TaskHandle_t scheduler_get_current_task(void);
|
||||
|
||||
#endif /* KERNEL_H */
|
||||
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* @file mutex.h
|
||||
* @brief Mutex with priority inheritance
|
||||
*/
|
||||
|
||||
#ifndef MUTEX_H
|
||||
#define MUTEX_H
|
||||
|
||||
#include "kernel.h"
|
||||
|
||||
/* Mutex Control Block */
|
||||
typedef struct {
|
||||
TaskHandle_t owner;
|
||||
TaskPriority_t original_priority;
|
||||
uint32_t lock_count;
|
||||
TaskHandle_t* waiting_tasks;
|
||||
uint32_t waiting_count;
|
||||
bool recursive;
|
||||
} Mutex_t;
|
||||
|
||||
/* Mutex Functions */
|
||||
KernelStatus_t mutex_create(Mutex_t* mutex, bool recursive);
|
||||
KernelStatus_t mutex_lock(Mutex_t* mutex, TimeOut_t timeout);
|
||||
KernelStatus_t mutex_unlock(Mutex_t* mutex);
|
||||
KernelStatus_t mutex_delete(Mutex_t* mutex);
|
||||
TaskHandle_t mutex_get_owner(Mutex_t* mutex);
|
||||
|
||||
#endif /* MUTEX_H */
|
||||
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* @file queue.h
|
||||
* @brief Message queue for inter-task communication
|
||||
*/
|
||||
|
||||
#ifndef QUEUE_H
|
||||
#define QUEUE_H
|
||||
|
||||
#include "kernel.h"
|
||||
|
||||
/* Queue Control Block */
|
||||
typedef struct {
|
||||
void* buffer;
|
||||
uint32_t item_size;
|
||||
uint32_t max_items;
|
||||
uint32_t current_items;
|
||||
uint32_t head;
|
||||
uint32_t tail;
|
||||
TaskHandle_t* waiting_senders;
|
||||
TaskHandle_t* waiting_receivers;
|
||||
uint32_t waiting_sender_count;
|
||||
uint32_t waiting_receiver_count;
|
||||
} Queue_t;
|
||||
|
||||
/* Queue Functions */
|
||||
KernelStatus_t queue_create(Queue_t* queue, void* buffer, uint32_t item_size,
|
||||
uint32_t max_items);
|
||||
KernelStatus_t queue_send(Queue_t* queue, const void* item, TimeOut_t timeout);
|
||||
KernelStatus_t queue_receive(Queue_t* queue, void* item, TimeOut_t timeout);
|
||||
KernelStatus_t queue_send_from_isr(Queue_t* queue, const void* item);
|
||||
KernelStatus_t queue_receive_from_isr(Queue_t* queue, void* item);
|
||||
uint32_t queue_get_count(Queue_t* queue);
|
||||
KernelStatus_t queue_delete(Queue_t* queue);
|
||||
|
||||
#endif /* QUEUE_H */
|
||||
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* @file scheduler.h
|
||||
* @brief Priority-based preemptive scheduler
|
||||
*/
|
||||
|
||||
#ifndef SCHEDULER_H
|
||||
#define SCHEDULER_H
|
||||
|
||||
#include "kernel.h"
|
||||
#include "task.h"
|
||||
|
||||
/* Scheduler Types */
|
||||
typedef enum {
|
||||
SCHEDULER_PRIORITY_PREEMPTIVE = 0,
|
||||
SCHEDULER_ROUND_ROBIN = 1,
|
||||
SCHEDULER_EDF = 2, /* Earliest Deadline First */
|
||||
SCHEDULER_RATE_MONOTONIC = 3
|
||||
} SchedulerType_t;
|
||||
|
||||
/* Scheduler Configuration */
|
||||
typedef struct {
|
||||
SchedulerType_t type;
|
||||
TickType_t time_slice_ticks; /* For round-robin */
|
||||
bool enable_deadline_monitoring;
|
||||
} SchedulerConfig_t;
|
||||
|
||||
/* Scheduler Interface */
|
||||
void scheduler_init(const SchedulerConfig_t* config);
|
||||
void scheduler_start(void);
|
||||
void scheduler_tick(void);
|
||||
void scheduler_add_task(TaskHandle_t task);
|
||||
void scheduler_remove_task(TaskHandle_t task);
|
||||
void scheduler_update_task_state(TaskHandle_t task, TaskState_t new_state);
|
||||
TaskHandle_t scheduler_select_next_task(void);
|
||||
void scheduler_context_switch(TaskHandle_t next_task);
|
||||
|
||||
/* Scheduler Statistics */
|
||||
typedef struct {
|
||||
uint32_t context_switches;
|
||||
uint32_t preemptions;
|
||||
TickType_t max_scheduling_latency;
|
||||
TickType_t total_idle_time;
|
||||
} SchedulerStatistics_t;
|
||||
|
||||
void scheduler_get_statistics(SchedulerStatistics_t* stats);
|
||||
|
||||
#endif /* SCHEDULER_H */
|
||||
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* @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 */
|
||||
@@ -0,0 +1,58 @@
|
||||
/**
|
||||
* @file task.h
|
||||
* @brief Task management interface
|
||||
*/
|
||||
|
||||
#ifndef TASK_H
|
||||
#define TASK_H
|
||||
|
||||
#include "kernel.h"
|
||||
|
||||
/* Internal Task Control Block */
|
||||
struct TaskControlBlock {
|
||||
/* Task Identification */
|
||||
char name[MAX_TASK_NAME_LENGTH];
|
||||
TaskHandle_t self;
|
||||
uint32_t task_id;
|
||||
|
||||
/* Task Function */
|
||||
TaskFunction_t function;
|
||||
void* parameters;
|
||||
|
||||
/* Stack Management */
|
||||
uint32_t* stack_pointer;
|
||||
uint32_t* stack_base;
|
||||
uint32_t stack_size;
|
||||
uint32_t stack_high_water_mark;
|
||||
|
||||
/* Scheduling Information */
|
||||
TaskPriority_t priority;
|
||||
TaskState_t state;
|
||||
TickType_t period_ticks;
|
||||
TickType_t last_wake_time;
|
||||
TickType_t deadline_ticks;
|
||||
|
||||
/* Blocking Information */
|
||||
TickType_t block_timeout;
|
||||
void* blocked_on;
|
||||
|
||||
/* Statistics */
|
||||
TaskStatistics_t statistics;
|
||||
|
||||
/* List Management */
|
||||
struct TaskControlBlock* next;
|
||||
struct TaskControlBlock* prev;
|
||||
|
||||
/* Architecture Specific */
|
||||
uint32_t context[32]; /* CPU register context */
|
||||
};
|
||||
|
||||
/* Internal Task Management Functions */
|
||||
void task_init(void);
|
||||
void task_switch_context(TaskHandle_t next_task);
|
||||
TaskHandle_t task_get_idle_task(void);
|
||||
void task_update_statistics(void);
|
||||
void task_check_stack_overflow(void);
|
||||
bool task_is_ready(TaskHandle_t task);
|
||||
|
||||
#endif /* TASK_H */
|
||||
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* @file timer.h
|
||||
* @brief Software timer management
|
||||
*/
|
||||
|
||||
#ifndef TIMER_H
|
||||
#define TIMER_H
|
||||
|
||||
#include "kernel.h"
|
||||
|
||||
/* Timer Types */
|
||||
typedef enum {
|
||||
TIMER_ONE_SHOT = 0,
|
||||
TIMER_PERIODIC = 1
|
||||
} TimerType_t;
|
||||
|
||||
/* Timer Callback */
|
||||
typedef void (*TimerCallback_t)(void* parameters);
|
||||
|
||||
/* Timer Control Block */
|
||||
typedef struct {
|
||||
char name[16];
|
||||
TimerType_t type;
|
||||
TickType_t period_ticks;
|
||||
TickType_t expiry_time;
|
||||
TimerCallback_t callback;
|
||||
void* parameters;
|
||||
bool is_active;
|
||||
struct Timer* next;
|
||||
} Timer_t;
|
||||
|
||||
/* Timer Functions */
|
||||
KernelStatus_t timer_create(Timer_t* timer, const char* name, TimerType_t type,
|
||||
TickType_t period, TimerCallback_t callback,
|
||||
void* parameters);
|
||||
KernelStatus_t timer_start(Timer_t* timer);
|
||||
KernelStatus_t timer_stop(Timer_t* timer);
|
||||
KernelStatus_t timer_reset(Timer_t* timer);
|
||||
KernelStatus_t timer_delete(Timer_t* timer);
|
||||
bool timer_is_active(Timer_t* timer);
|
||||
void timer_process_expired(void);
|
||||
|
||||
#endif /* TIMER_H */
|
||||
Reference in New Issue
Block a user