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:
root
2026-08-23 03:35:29 -04:00
parent f113bf0a05
commit ca13734bf0
151 changed files with 23945 additions and 0 deletions
+67
View File
@@ -0,0 +1,67 @@
/**
* @file board.h
* @brief Custom ECU board definitions
*/
#ifndef BOARD_H
#define BOARD_H
#include <stdint.h>
#include <stdbool.h>
/* ============================================================================
* Board Identification
* ============================================================================ */
#define BOARD_NAME "CustomECU-v1.0"
#define BOARD_MANUFACTURER "Automotive RTOS Team"
#define BOARD_VERSION "1.0"
#define BOARD_MCU "Custom"
/* ============================================================================
* Clock Configuration
* ============================================================================ */
#define SYSTEM_CLOCK 100000000U /* 100 MHz */
#define PERIPHERAL_CLOCK 50000000U /* 50 MHz */
#define TIMER_CLOCK 10000000U /* 10 MHz */
/* ============================================================================
* LED Definitions
* ============================================================================ */
#define LED_COUNT 4
#define LED_STATUS 0
#define LED_ERROR 1
#define LED_CAN_TX 2
#define LED_CAN_RX 3
/* ============================================================================
* Communication Interfaces
* ============================================================================ */
#define CAN_INTERFACE_COUNT 2
#define UART_INTERFACE_COUNT 2
#define SPI_INTERFACE_COUNT 1
#define I2C_INTERFACE_COUNT 1
/* ============================================================================
* Board Functions
* ============================================================================ */
void board_init(void);
void board_clock_init(void);
void board_gpio_init(void);
void board_uart_init(void);
void board_can_init(void);
void board_spi_init(void);
void board_i2c_init(void);
void board_adc_init(void);
void board_pwm_init(void);
void board_watchdog_init(void);
void board_watchdog_service(void);
void board_led_on(uint8_t led);
void board_led_off(uint8_t led);
void board_led_toggle(uint8_t led);
bool board_button_read(uint8_t button);
void board_delay_ms(uint32_t ms);
void board_delay_us(uint32_t us);
float board_get_temperature(void);
float board_get_voltage(void);
#endif /* BOARD_H */
+292
View File
@@ -0,0 +1,292 @@
/**
* @file board_init.c
* @brief Custom ECU board initialization
*/
#include "board.h"
#include "kernel.h"
#include "gpio_driver.h"
#include "uart_driver.h"
#include "can_driver.h"
#include "spi_driver.h"
#include "i2c_driver.h"
#include "adc_driver.h"
#include "pwm_driver.h"
#include <string.h>
static bool board_initialized = false;
/* Board-specific configuration */
typedef struct {
uint32_t can_baudrate;
uint32_t uart_baudrate;
uint8_t node_id;
bool can_fd_enabled;
} BoardConfig_t;
static const BoardConfig_t board_config = {
.can_baudrate = 500000,
.uart_baudrate = 115200,
.node_id = 0x01,
.can_fd_enabled = true
};
/* ============================================================================
* Board Initialization
* ============================================================================ */
void board_init(void) {
if (board_initialized) {
return;
}
/* Initialize clock */
board_clock_init();
/* Initialize GPIO */
board_gpio_init();
/* Initialize UART */
board_uart_init();
/* Initialize CAN */
board_can_init();
/* Initialize SPI */
board_spi_init();
/* Initialize I2C */
board_i2c_init();
/* Initialize ADC */
board_adc_init();
/* Initialize PWM */
board_pwm_init();
/* Initialize watchdog */
board_watchdog_init();
board_initialized = true;
}
/* ============================================================================
* Clock Initialization
* ============================================================================ */
void board_clock_init(void) {
/* Custom clock initialization */
/* This would be implemented for specific hardware */
}
/* ============================================================================
* GPIO Initialization
* ============================================================================ */
void board_gpio_init(void) {
/* Configure status LEDs */
GpioPinConfig_t led_config = {
.mode = GPIO_MODE_OUTPUT,
.output_type = GPIO_OUTPUT_PUSH_PULL,
.pull = GPIO_PULL_NONE,
.speed = GPIO_SPEED_HIGH
};
/* Configure each LED */
for (int i = 0; i < LED_COUNT; i++) {
led_config.port = 0;
led_config.pin = i;
gpio_init(&led_config);
}
/* Turn off all LEDs */
for (int i = 0; i < LED_COUNT; i++) {
board_led_off(i);
}
}
/* ============================================================================
* UART Initialization
* ============================================================================ */
void board_uart_init(void) {
/* Configure debug UART */
UartConfig_t uart_config = {
.baudrate = board_config.uart_baudrate,
.data_bits = UART_DATA_BITS_8,
.stop_bits = UART_STOP_BITS_1,
.parity = UART_PARITY_NONE,
.flow_control = UART_FLOW_CONTROL_NONE,
.enable_rx = true,
.enable_tx = true,
.use_dma = false
};
uart_init(0, &uart_config);
}
/* ============================================================================
* CAN Initialization
* ============================================================================ */
void board_can_init(void) {
/* Configure main CAN interface */
CanConfig_t can_config = {
.nominal_baudrate = board_config.can_baudrate,
.data_baudrate = board_config.can_baudrate,
.frame_type = CAN_FRAME_CLASSIC,
.enable_fd = board_config.can_fd_enabled,
.enable_automatic_retransmission = true,
.filter_count = 0
};
can_init(0, &can_config);
}
/* ============================================================================
* SPI Initialization
* ============================================================================ */
void board_spi_init(void) {
/* Configure SPI for external devices */
SpiConfig_t spi_config = {
.mode = SPI_MODE_0,
.clock_speed = SPI_CLOCK_8MHZ,
.data_order = SPI_DATA_ORDER_MSB_FIRST,
.data_size = 8,
.use_dma = true,
.enable_hardware_cs = false,
.cs_polarity = SPI_CS_ACTIVE_LOW,
.cs_port = 0,
.cs_pin = 10
};
spi_init(0, &spi_config);
}
/* ============================================================================
* I2C Initialization
* ============================================================================ */
void board_i2c_init(void) {
/* Configure I2C for sensors */
I2cConfig_t i2c_config = {
.speed = I2C_SPEED_FAST,
.addressing_mode = I2C_ADDRESSING_7BIT,
.own_address = 0x50,
.enable_general_call = false,
.enable_clock_stretching = true,
.use_dma = false
};
i2c_init(0, &i2c_config);
}
/* ============================================================================
* ADC Initialization
* ============================================================================ */
void board_adc_init(void) {
/* Configure ADC for analog inputs */
AdcConfig_t adc_config = {
.resolution = ADC_RESOLUTION_12BIT,
.mode = ADC_MODE_SCAN,
.trigger_source = ADC_TRIGGER_TIMER,
.reference = ADC_REFERENCE_VDD,
.enable_dma = true,
.conversion_frequency = 1000,
.channel_count = 8,
.channels = {
{.channel = 0, .sampling_time = ADC_SAMPLING_28_5_CYCLES},
{.channel = 1, .sampling_time = ADC_SAMPLING_28_5_CYCLES},
{.channel = 2, .sampling_time = ADC_SAMPLING_28_5_CYCLES},
{.channel = 3, .sampling_time = ADC_SAMPLING_28_5_CYCLES},
{.channel = 4, .sampling_time = ADC_SAMPLING_28_5_CYCLES},
{.channel = 5, .sampling_time = ADC_SAMPLING_28_5_CYCLES},
{.channel = 6, .sampling_time = ADC_SAMPLING_28_5_CYCLES},
{.channel = 7, .sampling_time = ADC_SAMPLING_28_5_CYCLES}
}
};
adc_init(0, &adc_config);
}
/* ============================================================================
* PWM Initialization
* ============================================================================ */
void board_pwm_init(void) {
/* Configure PWM outputs */
PwmConfig_t pwm_config = {
.frequency_hz = 1000,
.alignment = PWM_ALIGNMENT_EDGE,
.period_ticks = 1000,
.prescaler = 100,
.channel_count = 4,
.channels = {
{.channel = 0, .duty_cycle = 0},
{.channel = 1, .duty_cycle = 0},
{.channel = 2, .duty_cycle = 0},
{.channel = 3, .duty_cycle = 0}
},
.enable_fault_protection = true,
.fault_action = PWM_FAULT_DISABLE
};
pwm_init(0, &pwm_config);
}
/* ============================================================================
* Watchdog Initialization
* ============================================================================ */
void board_watchdog_init(void) {
/* Custom watchdog initialization */
}
void board_watchdog_service(void) {
/* Custom watchdog service */
}
/* ============================================================================
* LED Functions
* ============================================================================ */
void board_led_on(uint8_t led) {
if (led < LED_COUNT) {
gpio_write(0, led, true);
}
}
void board_led_off(uint8_t led) {
if (led < LED_COUNT) {
gpio_write(0, led, false);
}
}
void board_led_toggle(uint8_t led) {
if (led < LED_COUNT) {
gpio_toggle(0, led);
}
}
/* ============================================================================
* Button Functions
* ============================================================================ */
bool board_button_read(uint8_t button) {
/* Custom button implementation */
return false;
}
/* ============================================================================
* Delay Functions
* ============================================================================ */
void board_delay_ms(uint32_t ms) {
kernel_delay(ms);
}
void board_delay_us(uint32_t us) {
/* Custom microsecond delay */
}
/* ============================================================================
* Sensor Functions
* ============================================================================ */
float board_get_temperature(void) {
/* Custom temperature sensor reading */
return 25.0f;
}
float board_get_voltage(void) {
/* Custom voltage reading */
return 3.3f;
}
+133
View File
@@ -0,0 +1,133 @@
/**
* @file linker_script.ld
* @brief Linker script for Custom ECU
*/
ENTRY(Reset_Handler)
MEMORY
{
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 2048K
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 512K
EEPROM (rw) : ORIGIN = 0x08080000, LENGTH = 16K
}
_estack = ORIGIN(RAM) + LENGTH(RAM);
_min_stack_size = 0x800;
_min_heap_size = 0x400;
SECTIONS
{
.isr_vector :
{
. = ALIGN(4);
KEEP(*(.isr_vector))
. = ALIGN(4);
} >FLASH
.text :
{
. = ALIGN(4);
*(.text)
*(.text*)
KEEP(*(.init))
KEEP(*(.fini))
. = ALIGN(4);
_etext = .;
} >FLASH
.rodata :
{
. = ALIGN(4);
*(.rodata)
*(.rodata*)
. = ALIGN(4);
} >FLASH
.ARM.extab :
{
*(.ARM.extab* .gnu.linkonce.armextab.*)
} >FLASH
.ARM :
{
__exidx_start = .;
*(.ARM.exidx*)
__exidx_end = .;
} >FLASH
.preinit_array :
{
PROVIDE_HIDDEN(__preinit_array_start = .);
KEEP(*(.preinit_array*))
PROVIDE_HIDDEN(__preinit_array_end = .);
} >FLASH
.init_array :
{
PROVIDE_HIDDEN(__init_array_start = .);
KEEP(*(SORT(.init_array.*)))
KEEP(*(.init_array*))
PROVIDE_HIDDEN(__init_array_end = .);
} >FLASH
.fini_array :
{
PROVIDE_HIDDEN(__fini_array_start = .);
KEEP(*(SORT(.fini_array.*)))
KEEP(*(.fini_array*))
PROVIDE_HIDDEN(__fini_array_end = .);
} >FLASH
_sidata = LOADADDR(.data);
.data :
{
. = ALIGN(4);
_sdata = .;
*(.data)
*(.data*)
. = ALIGN(4);
_edata = .;
} >RAM AT> FLASH
.bss :
{
. = ALIGN(4);
_sbss = .;
__bss_start__ = _sbss;
*(.bss)
*(.bss*)
*(COMMON)
. = ALIGN(4);
_ebss = .;
__bss_end__ = _ebss;
} >RAM
.eeprom :
{
. = ALIGN(4);
*(.eeprom)
*(.eeprom*)
. = ALIGN(4);
} >EEPROM
._user_heap_stack :
{
. = ALIGN(8);
PROVIDE(end = .);
PROVIDE(_end = .);
. = . + _min_heap_size;
. = . + _min_stack_size;
. = ALIGN(8);
} >RAM
/DISCARD/ :
{
libc.a(*)
libm.a(*)
libgcc.a(*)
}
.ARM.attributes 0 : { *(.ARM.attributes) }
}