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
+238
View File
@@ -0,0 +1,238 @@
/**
* @file board_config.h
* @brief Board-specific configuration
*/
#ifndef BOARD_CONFIG_H
#define BOARD_CONFIG_H
#include "mcu_config.h"
/* ============================================================================
* Board Selection
* ============================================================================ */
#define BOARD_STM32F407_DISCOVERY 1
#define BOARD_NXP_S32K144_EVB 0
#define BOARD_INFINEON_TC397_EVB 0
#if (BOARD_STM32F407_DISCOVERY + BOARD_NXP_S32K144_EVB + BOARD_INFINEON_TC397_EVB) != 1
#error "Exactly one board must be selected"
#endif
/* ============================================================================
* Pin Mapping
* ============================================================================ */
#if BOARD_STM32F407_DISCOVERY
/* STM32F407 Discovery board pin mapping */
/* LED pins */
#define LED1_PORT 0 /* GPIOA */
#define LED1_PIN 0
#define LED2_PORT 0
#define LED2_PIN 1
#define LED3_PORT 0
#define LED3_PIN 2
#define LED4_PORT 0
#define LED4_PIN 3
/* Button pins */
#define BUTTON1_PORT 0 /* GPIOA */
#define BUTTON1_PIN 0
/* UART pins */
#define UART1_TX_PORT 0 /* GPIOA */
#define UART1_TX_PIN 9
#define UART1_RX_PORT 0
#define UART1_RX_PIN 10
/* CAN pins */
#define CAN1_TX_PORT 1 /* GPIOB */
#define CAN1_TX_PIN 9
#define CAN1_RX_PORT 1
#define CAN1_RX_PIN 8
/* SPI pins */
#define SPI1_SCK_PORT 0 /* GPIOA */
#define SPI1_SCK_PIN 5
#define SPI1_MISO_PORT 0
#define SPI1_MISO_PIN 6
#define SPI1_MOSI_PORT 0
#define SPI1_MOSI_PIN 7
/* I2C pins */
#define I2C1_SCL_PORT 1 /* GPIOB */
#define I2C1_SCL_PIN 6
#define I2C1_SDA_PORT 1
#define I2C1_SDA_PIN 7
/* ADC pins */
#define ADC1_CH0_PORT 0 /* GPIOA */
#define ADC1_CH0_PIN 0
#define ADC1_CH1_PORT 0
#define ADC1_CH1_PIN 1
/* PWM pins */
#define PWM1_CH1_PORT 0 /* GPIOA */
#define PWM1_CH1_PIN 8
#define PWM1_CH2_PORT 0
#define PWM1_CH2_PIN 9
#elif BOARD_NXP_S32K144_EVB
/* NXP S32K144 EVB pin mapping */
/* LED pins */
#define LED_RED_PORT 2 /* GPIOC */
#define LED_RED_PIN 0
#define LED_GREEN_PORT 2
#define LED_GREEN_PIN 1
#define LED_BLUE_PORT 2
#define LED_BLUE_PIN 2
/* Button pins */
#define BUTTON1_PORT 2 /* GPIOC */
#define BUTTON1_PIN 3
#define BUTTON2_PORT 2
#define BUTTON2_PIN 4
/* UART pins */
#define UART0_TX_PORT 0 /* GPIOA */
#define UART0_TX_PIN 2
#define UART0_RX_PORT 0
#define UART0_RX_PIN 3
/* CAN pins */
#define CAN0_TX_PORT 4 /* GPIOE */
#define CAN0_TX_PIN 5
#define CAN0_RX_PORT 4
#define CAN0_RX_PIN 4
/* SPI pins */
#define SPI0_SCK_PORT 0 /* GPIOA */
#define SPI0_SCK_PIN 6
#define SPI0_MISO_PORT 0
#define SPI0_MISO_PIN 7
#define SPI0_MOSI_PORT 0
#define SPI0_MOSI_PIN 8
#elif BOARD_INFINEON_TC397_EVB
/* Infineon TC397 EVB pin mapping */
/* LED pins */
#define LED1_PORT 0 /* P00 */
#define LED1_PIN 0
#define LED2_PORT 0
#define LED2_PIN 1
/* Button pins */
#define BUTTON1_PORT 0 /* P00 */
#define BUTTON1_PIN 2
/* UART pins */
#define UART0_TX_PORT 0 /* P00 */
#define UART0_TX_PIN 3
#define UART0_RX_PORT 0
#define UART0_RX_PIN 4
/* CAN pins */
#define CAN0_TX_PORT 0 /* P00 */
#define CAN0_TX_PIN 5
#define CAN0_RX_PORT 0
#define CAN0_RX_PIN 6
#endif
/* ============================================================================
* Board Features
* ============================================================================ */
/* Debug interface */
#define DEBUG_INTERFACE_SWD 1
#define DEBUG_INTERFACE_JTAG 0
/* External crystal frequency */
#define EXTERNAL_CRYSTAL_HZ 8000000U
/* Board voltage */
#define BOARD_VOLTAGE 3.3f /* Volts */
/* ============================================================================
* External Components
* ============================================================================ */
/* External memory */
#define EXT_FLASH_ENABLED 0
#define EXT_RAM_ENABLED 0
/* External sensors */
#define TEMP_SENSOR_ENABLED 1
#define ACCELEROMETER_ENABLED 1
#define GYROSCOPE_ENABLED 0
/* Display */
#define LCD_DISPLAY_ENABLED 1
#define LCD_WIDTH 240
#define LCD_HEIGHT 320
#define LCD_COLOR_DEPTH 16
/* CAN transceiver */
#define CAN_TRANSCEIVER_ENABLED 1
#define CAN_TRANSCEIVER_TYPE 0 /* 0=TJA1050, 1=MCP2551 */
/* ============================================================================
* Board-Specific Functions
* ============================================================================ */
/* Board initialization function */
void board_init(void);
/* Board-specific GPIO initialization */
void board_gpio_init(void);
/* Board-specific clock initialization */
void board_clock_init(void);
/* Board-specific peripheral initialization */
void board_peripheral_init(void);
/* Board-specific CAN initialization */
void board_can_init(void);
/* Board-specific UART initialization */
void board_uart_init(void);
/* Board-specific SPI initialization */
void board_spi_init(void);
/* Board-specific I2C initialization */
void board_i2c_init(void);
/* Board-specific ADC initialization */
void board_adc_init(void);
/* Board-specific PWM initialization */
void board_pwm_init(void);
/* Board LED control */
void board_led_on(uint8_t led);
void board_led_off(uint8_t led);
void board_led_toggle(uint8_t led);
/* Board button reading */
bool board_button_read(uint8_t button);
/* Board-specific delay */
void board_delay_ms(uint32_t ms);
void board_delay_us(uint32_t us);
/* Board-specific watchdog */
void board_watchdog_init(void);
void board_watchdog_service(void);
/* Board temperature reading */
float board_get_temperature(void);
/* Board voltage reading */
float board_get_voltage(void);
#endif /* BOARD_CONFIG_H */
+198
View File
@@ -0,0 +1,198 @@
/**
* @file can_config.h
* @brief CAN bus configuration for automotive applications
*/
#ifndef CAN_CONFIG_H
#define CAN_CONFIG_H
#include <stdint.h>
/* ============================================================================
* CAN Hardware Configuration
* ============================================================================ */
/* Number of CAN controllers */
#define CAN_CONTROLLER_COUNT 2
/* CAN controller base addresses */
#define CAN0_BASE_ADDRESS 0x40006400U
#define CAN1_BASE_ADDRESS 0x40006800U
/* CAN controller interrupts */
#define CAN0_IRQ_NUMBER 19
#define CAN1_IRQ_NUMBER 20
/* CAN controller priorities */
#define CAN0_IRQ_PRIORITY 5
#define CAN1_IRQ_PRIORITY 5
/* ============================================================================
* CAN Baudrate Configuration
* ============================================================================ */
/* CAN baudrates */
#define CAN_BAUDRATE_125K 125000
#define CAN_BAUDRATE_250K 250000
#define CAN_BAUDRATE_500K 500000
#define CAN_BAUDRATE_1M 1000000
/* CAN FD baudrates */
#define CAN_FD_BAUDRATE_2M 2000000
#define CAN_FD_BAUDRATE_5M 5000000
#define CAN_FD_BAUDRATE_8M 8000000
/* Default CAN baudrate */
#define CAN_DEFAULT_BAUDRATE CAN_BAUDRATE_500K
/* CAN FD data baudrate */
#define CAN_FD_DATA_BAUDRATE CAN_FD_BAUDRATE_2M
/* ============================================================================
* CAN Frame Configuration
* ============================================================================ */
/* Enable CAN FD */
#define CAN_FD_ENABLED 1
/* Maximum CAN frame length */
#define CAN_MAX_FRAME_LENGTH 64
/* Enable automatic retransmission */
#define CAN_AUTO_RETRANSMIT 1
/* Maximum retransmission attempts */
#define CAN_MAX_RETRANSMIT 3
/* ============================================================================
* CAN Message IDs
* ============================================================================ */
/* OBD-II IDs */
#define CAN_ID_OBD_REQUEST 0x7DF
#define CAN_ID_OBD_RESPONSE 0x7E8
#define CAN_ID_OBD_RESPONSE_2 0x7E9
/* Diagnostic IDs */
#define CAN_ID_DIAG_REQUEST 0x700
#define CAN_ID_DIAG_RESPONSE 0x708
/* Network management IDs */
#define CAN_ID_NM_BASE 0x400
#define CAN_ID_NM_END 0x4FF
/* ============================================================================
* Application Message IDs
* ============================================================================ */
/* Engine control messages */
#define CAN_ID_ENGINE_DATA 0x100
#define CAN_ID_ENGINE_CONTROL 0x101
#define CAN_ID_ENGINE_STATUS 0x102
#define CAN_ID_ENGINE_FAULT 0x103
/* Transmission messages */
#define CAN_ID_TRANSMISSION_DATA 0x110
#define CAN_ID_TRANSMISSION_CONTROL 0x111
#define CAN_ID_GEAR_POSITION 0x112
/* Brake control messages */
#define CAN_ID_BRAKE_DATA 0x120
#define CAN_ID_BRAKE_CONTROL 0x121
#define CAN_ID_ABS_DATA 0x122
#define CAN_ID_WHEEL_SPEED 0x123
/* Steering messages */
#define CAN_ID_STEERING_ANGLE 0x130
#define CAN_ID_STEERING_TORQUE 0x131
#define CAN_ID_STEERING_CONTROL 0x132
/* Body control messages */
#define CAN_ID_BODY_CONTROL 0x140
#define CAN_ID_DOOR_STATUS 0x141
#define CAN_ID_LIGHT_STATUS 0x142
#define CAN_ID_WINDOW_CONTROL 0x143
/* Dashboard messages */
#define CAN_ID_SPEED 0x150
#define CAN_ID_RPM 0x151
#define CAN_ID_FUEL_LEVEL 0x152
#define CAN_ID_TEMPERATURE 0x153
/* Safety messages */
#define CAN_ID_AIRBAG_STATUS 0x160
#define CAN_ID_SEATBELT_STATUS 0x161
#define CAN_ID_CRASH_DETECTION 0x162
/* ============================================================================
* CAN Filter Configuration
* ============================================================================ */
typedef struct {
uint32_t filter_id;
uint32_t filter_mask;
bool is_extended;
uint8_t controller;
uint8_t fifo;
} CanFilterConfig_t;
/* Default CAN filters */
static const CanFilterConfig_t can_filters[] = {
/* Engine messages */
{.filter_id = 0x100, .filter_mask = 0x1F0, .is_extended = false, .controller = 0, .fifo = 0},
/* Transmission messages */
{.filter_id = 0x110, .filter_mask = 0x1F0, .is_extended = false, .controller = 0, .fifo = 0},
/* Brake messages */
{.filter_id = 0x120, .filter_mask = 0x1F0, .is_extended = false, .controller = 0, .fifo = 0},
/* Steering messages */
{.filter_id = 0x130, .filter_mask = 0x1F0, .is_extended = false, .controller = 0, .fifo = 0},
/* Body control messages */
{.filter_id = 0x140, .filter_mask = 0x1F0, .is_extended = false, .controller = 0, .fifo = 1},
/* Dashboard messages */
{.filter_id = 0x150, .filter_mask = 0x1F0, .is_extended = false, .controller = 0, .fifo = 1},
/* Safety messages */
{.filter_id = 0x160, .filter_mask = 0x1F0, .is_extended = false, .controller = 0, .fifo = 0},
/* OBD-II messages */
{.filter_id = 0x7DF, .filter_mask = 0x7FF, .is_extended = false, .controller = 1, .fifo = 0},
/* Diagnostic messages */
{.filter_id = 0x700, .filter_mask = 0x7F0, .is_extended = false, .controller = 1, .fifo = 1},
/* Network management */
{.filter_id = 0x400, .filter_mask = 0x700, .is_extended = false, .controller = 0, .fifo = 1}
};
#define CAN_FILTER_COUNT (sizeof(can_filters) / sizeof(CanFilterConfig_t))
/* ============================================================================
* CAN TP Configuration
* ============================================================================ */
/* CAN TP timeouts */
#define CAN_TP_N_AS_TIMEOUT 1000 /* ms */
#define CAN_TP_N_BS_TIMEOUT 1000 /* ms */
#define CAN_TP_N_CR_TIMEOUT 1000 /* ms */
/* CAN TP parameters */
#define CAN_TP_STMIN_DEFAULT 10 /* ms */
#define CAN_TP_BS_DEFAULT 8 /* frames */
#define CAN_TP_MAX_PAYLOAD 4096 /* bytes */
/* ============================================================================
* CAN NM Configuration
* ============================================================================ */
/* CAN NM parameters */
#define CAN_NM_TIMEOUT 2000 /* ms */
#define CAN_NM_REPEAT_TIME 500 /* ms */
#define CAN_NM_WAIT_BUS_SLEEP 2000 /* ms */
/* ============================================================================
* CAN Statistics
* ============================================================================ */
/* Enable CAN statistics collection */
#define CAN_STATS_ENABLED 1
/* Statistics buffer size */
#define CAN_STATS_BUFFER_SIZE 100
#endif /* CAN_CONFIG_H */
+266
View File
@@ -0,0 +1,266 @@
/**
* @file kernel_config.h
* @brief Kernel configuration for Automotive RTOS
*/
#ifndef KERNEL_CONFIG_H
#define KERNEL_CONFIG_H
/* ============================================================================
* Kernel Version Information
* ============================================================================ */
#define KERNEL_VERSION_MAJOR 1
#define KERNEL_VERSION_MINOR 0
#define KERNEL_VERSION_PATCH 0
#define KERNEL_VERSION_STRING "1.0.0"
/* ============================================================================
* Basic Kernel Configuration
* ============================================================================ */
/* Maximum number of tasks */
#define MAX_TASKS 32
/* Maximum priority levels (0 = highest, 15 = lowest) */
#define MAX_PRIORITY_LEVELS 16
/* Idle task priority (lowest) */
#define IDLE_TASK_PRIORITY (MAX_PRIORITY_LEVELS - 1)
/* Maximum task name length */
#define MAX_TASK_NAME_LENGTH 16
/* System tick rate in Hz */
#define TICK_RATE_HZ 1000
/* Tick period in milliseconds */
#define TICK_PERIOD_MS (1000 / TICK_RATE_HZ)
/* ============================================================================
* Scheduler Configuration
* ============================================================================ */
/* Scheduler type */
#define SCHEDULER_TYPE SCHEDULER_PRIORITY_PREEMPTIVE
/* Enable round-robin scheduling for same priority tasks */
#define ENABLE_ROUND_ROBIN 1
/* Round-robin time slice in ticks */
#define ROUND_ROBIN_TIME_SLICE 10
/* Enable deadline monitoring */
#define ENABLE_DEADLINE_MONITORING 1
/* Maximum allowed deadline misses before fault */
#define MAX_DEADLINE_MISSES 10
/* ============================================================================
* Synchronization Primitives
* ============================================================================ */
/* Maximum number of semaphores */
#define MAX_SEMAPHORES 32
/* Maximum number of mutexes */
#define MAX_MUTEXES 16
/* Maximum number of message queues */
#define MAX_QUEUES 16
/* Maximum queue size */
#define MAX_QUEUE_SIZE 256
/* Maximum number of event groups */
#define MAX_EVENT_GROUPS 8
/* Maximum number of software timers */
#define MAX_TIMERS 16
/* ============================================================================
* Memory Management
* ============================================================================ */
/* Enable memory protection */
#define ENABLE_MEMORY_PROTECTION 1
/* Enable stack overflow detection */
#define ENABLE_STACK_CHECK 1
/* Stack fill pattern for overflow detection */
#define STACK_FILL_PATTERN 0xA5A5A5A5
/* Default task stack size */
#define DEFAULT_TASK_STACK_SIZE 1024
/* Minimum task stack size */
#define MIN_TASK_STACK_SIZE 256
/* Idle task stack size */
#define IDLE_TASK_STACK_SIZE 512
/* ISR stack size */
#define ISR_STACK_SIZE 2048
/* Heap size for dynamic allocation */
#define HEAP_SIZE 65536
/* Enable heap usage tracking */
#define ENABLE_HEAP_TRACKING 1
/* ============================================================================
* Interrupt Management
* ============================================================================ */
/* Maximum number of ISR handlers */
#define MAX_ISR_HANDLERS 128
/* Maximum interrupt nesting level */
#define MAX_INTERRUPT_NESTING 8
/* Kernel interrupt priority (highest) */
#define KERNEL_INTERRUPT_PRIORITY 0
/* System call interrupt priority */
#define SYSCALL_INTERRUPT_PRIORITY 1
/* PendSV interrupt priority (lowest) */
#define PENDSV_INTERRUPT_PRIORITY (MAX_PRIORITY_LEVELS - 1)
/* SysTick interrupt priority */
#define SYSTICK_INTERRUPT_PRIORITY (MAX_PRIORITY_LEVELS - 1)
/* ============================================================================
* Fault Handling
* ============================================================================ */
/* Enable fault handlers */
#define ENABLE_FAULT_HANDLERS 1
/* Enable hard fault handler */
#define ENABLE_HARD_FAULT_HANDLER 1
/* Enable bus fault handler */
#define ENABLE_BUS_FAULT_HANDLER 1
/* Enable usage fault handler */
#define ENABLE_USAGE_FAULT_HANDLER 1
/* Enable memory management fault handler */
#define ENABLE_MEM_FAULT_HANDLER 1
/* Maximum number of fault records */
#define MAX_FAULT_RECORDS 16
/* ============================================================================
* Debug and Trace
* ============================================================================ */
/* Enable debug output */
#define ENABLE_DEBUG_OUTPUT 1
/* Debug level (0=off, 1=error, 2=warning, 3=info, 4=debug) */
#define DEBUG_LEVEL 3
/* Enable trace functionality */
#define ENABLE_TRACE 0
/* Trace buffer size */
#define TRACE_BUFFER_SIZE 4096
/* Enable assertions */
#define ENABLE_ASSERT 1
/* Enable runtime statistics */
#define ENABLE_RUNTIME_STATS 1
/* ============================================================================
* Power Management
* ============================================================================ */
/* Enable power management */
#define ENABLE_POWER_MANAGEMENT 1
/* Enable sleep modes */
#define ENABLE_SLEEP_MODE 1
/* Enable deep sleep modes */
#define ENABLE_DEEP_SLEEP 0
/* Idle task uses WFI */
#define IDLE_TASK_USES_WFI 1
/* ============================================================================
* Safety Features
* ============================================================================ */
/* Enable watchdog integration */
#define ENABLE_WATCHDOG 1
/* Watchdog timeout in milliseconds */
#define WATCHDOG_TIMEOUT_MS 100
/* Enable task supervision */
#define ENABLE_TASK_SUPERVISION 1
/* Enable E2E protection */
#define ENABLE_E2E_PROTECTION 1
/* Enable memory ECC */
#define ENABLE_MEMORY_ECC 1
/* Enable clock monitoring */
#define ENABLE_CLOCK_MONITORING 1
/* Enable temperature monitoring */
#define ENABLE_TEMP_MONITORING 1
/* ============================================================================
* Communication
* ============================================================================ */
/* Enable CAN support */
#define ENABLE_CAN 1
/* Enable LIN support */
#define ENABLE_LIN 0
/* Enable FlexRay support */
#define ENABLE_FLEXRAY 0
/* Enable Ethernet support */
#define ENABLE_ETHERNET 0
/* ============================================================================
* Diagnostics
* ============================================================================ */
/* Enable UDS support */
#define ENABLE_UDS 1
/* Enable OBD-II support */
#define ENABLE_OBD_II 1
/* Enable DTC management */
#define ENABLE_DTC_MANAGEMENT 1
/* Maximum number of DTCs */
#define MAX_DTC_COUNT 100
/* ============================================================================
* Configuration Validation
* ============================================================================ */
#if MAX_TASKS > 255
#error "MAX_TASKS must be less than 256"
#endif
#if MAX_PRIORITY_LEVELS > 32
#error "MAX_PRIORITY_LEVELS must be less than 33"
#endif
#if TICK_RATE_HZ < 100 || TICK_RATE_HZ > 10000
#error "TICK_RATE_HZ must be between 100 and 10000"
#endif
#endif /* KERNEL_CONFIG_H */
+220
View File
@@ -0,0 +1,220 @@
/**
* @file mcu_config.h
* @brief MCU-specific configuration
*/
#ifndef MCU_CONFIG_H
#define MCU_CONFIG_H
/* ============================================================================
* MCU Selection
* ============================================================================ */
/* Select target MCU */
#define MCU_STM32F407VG 1
#define MCU_NXP_S32K144 0
#define MCU_INFINEON_TC397 0
#if (MCU_STM32F407VG + MCU_NXP_S32K144 + MCU_INFINEON_TC397) != 1
#error "Exactly one MCU must be selected"
#endif
/* ============================================================================
* Clock Configuration
* ============================================================================ */
#if MCU_STM32F407VG
/* STM32F407VG clock configuration */
#define HSE_VALUE 8000000U /* External crystal */
#define HSI_VALUE 16000000U /* Internal oscillator */
#define LSE_VALUE 32768U /* Low speed external */
#define LSI_VALUE 32000U /* Low speed internal */
#define SYSTEM_CLOCK 168000000U /* 168 MHz */
#define AHB_CLOCK 168000000U /* 168 MHz */
#define APB1_CLOCK 42000000U /* 42 MHz */
#define APB2_CLOCK 84000000U /* 84 MHz */
/* PLL configuration */
#define PLL_M 8
#define PLL_N 336
#define PLL_P 2
#define PLL_Q 7
#elif MCU_NXP_S32K144
/* NXP S32K144 clock configuration */
#define SOSC_FREQUENCY 8000000U /* System oscillator */
#define SPLL_FREQUENCY 160000000U /* System PLL */
#define FIRC_FREQUENCY 48000000U /* Fast IRC */
#define SIRC_FREQUENCY 8000000U /* Slow IRC */
#define SYSTEM_CLOCK 160000000U /* 160 MHz */
#define BUS_CLOCK 40000000U /* 40 MHz */
#define FLASH_CLOCK 20000000U /* 20 MHz */
/* PLL configuration */
#define PLL_MULT 20
#define PLL_DIV 1
#elif MCU_INFINEON_TC397
/* Infineon TC397 clock configuration */
#define F_OSC 20000000U /* External oscillator */
#define F_PLL 300000000U /* PLL frequency */
#define SYSTEM_CLOCK 300000000U /* 300 MHz */
#define PERIPHERAL_CLOCK 150000000U /* 150 MHz */
#define STM_CLOCK 100000000U /* 100 MHz */
/* PLL configuration */
#define PLL_N 30
#define PLL_P 2
#define PLL_K2 1
#endif
/* ============================================================================
* Peripheral Configuration
* ============================================================================ */
#if MCU_STM32F407VG
/* STM32F407VG peripherals */
#define GPIO_PORT_COUNT 6
#define UART_COUNT 6
#define SPI_COUNT 3
#define I2C_COUNT 3
#define CAN_COUNT 2
#define ADC_COUNT 3
#define TIMER_COUNT 14
#define DMA_STREAM_COUNT 16
/* GPIO ports */
#define GPIOA_ENABLE 1
#define GPIOB_ENABLE 1
#define GPIOC_ENABLE 1
#define GPIOD_ENABLE 1
#define GPIOE_ENABLE 1
#define GPIOF_ENABLE 0
#define GPIOG_ENABLE 0
/* UART configuration */
#define UART1_ENABLE 1
#define UART2_ENABLE 1
#define UART3_ENABLE 0
#define UART4_ENABLE 0
#define UART5_ENABLE 0
#define UART6_ENABLE 0
/* SPI configuration */
#define SPI1_ENABLE 1
#define SPI2_ENABLE 1
#define SPI3_ENABLE 0
/* I2C configuration */
#define I2C1_ENABLE 1
#define I2C2_ENABLE 0
#define I2C3_ENABLE 0
/* CAN configuration */
#define CAN1_ENABLE 1
#define CAN2_ENABLE 1
/* ADC configuration */
#define ADC1_ENABLE 1
#define ADC2_ENABLE 0
#define ADC3_ENABLE 0
#elif MCU_NXP_S32K144
/* NXP S32K144 peripherals */
#define GPIO_PORT_COUNT 5
#define UART_COUNT 3
#define SPI_COUNT 3
#define I2C_COUNT 2
#define CAN_COUNT 3
#define ADC_COUNT 2
#define TIMER_COUNT 5
/* GPIO ports */
#define GPIOA_ENABLE 1
#define GPIOB_ENABLE 1
#define GPIOC_ENABLE 1
#define GPIOD_ENABLE 1
#define GPIOE_ENABLE 1
/* UART configuration */
#define UART0_ENABLE 1
#define UART1_ENABLE 1
#define UART2_ENABLE 0
/* SPI configuration */
#define SPI0_ENABLE 1
#define SPI1_ENABLE 1
#define SPI2_ENABLE 0
/* I2C configuration */
#define I2C0_ENABLE 1
#define I2C1_ENABLE 0
/* CAN configuration */
#define CAN0_ENABLE 1
#define CAN1_ENABLE 1
#define CAN2_ENABLE 0
/* ADC configuration */
#define ADC0_ENABLE 1
#define ADC1_ENABLE 1
#elif MCU_INFINEON_TC397
/* Infineon TC397 peripherals */
#define GPIO_PORT_COUNT 16
#define UART_COUNT 4
#define SPI_COUNT 4
#define I2C_COUNT 2
#define CAN_COUNT 4
#define ADC_COUNT 8
#define TIMER_COUNT 20
#endif
/* ============================================================================
* Interrupt Configuration
* ============================================================================ */
/* NVIC priority grouping */
#define NVIC_PRIORITY_GROUPING 4 /* 4 bits preemption, 0 bits sub-priority */
/* Maximum interrupt priority */
#define MAX_INTERRUPT_PRIORITY 15
/* ============================================================================
* Power Configuration
* ============================================================================ */
/* Voltage monitoring */
#define ENABLE_VOLTAGE_MONITORING 1
#define VOLTAGE_MONITOR_THRESHOLD 2.7f /* Volts */
/* Temperature monitoring */
#define ENABLE_TEMP_MONITORING 1
#define TEMP_MONITOR_THRESHOLD 125 /* °C */
/* Brown-out reset */
#define ENABLE_BROWN_OUT_RESET 1
#define BROWN_OUT_THRESHOLD 2.7f /* Volts */
/* ============================================================================
* Safety Configuration
* ============================================================================ */
/* Watchdog */
#define WATCHDOG_ENABLED 1
#define WATCHDOG_TIMEOUT 100 /* ms */
#define WATCHDOG_WINDOW 50 /* ms */
/* Clock security system */
#define ENABLE_CLOCK_SECURITY 1
/* Memory protection */
#define ENABLE_MPU 1
/* ECC */
#define ENABLE_ECC 1
#endif /* MCU_CONFIG_H */
+211
View File
@@ -0,0 +1,211 @@
/**
* @file memory_config.h
* @brief Memory configuration for automotive RTOS
*/
#ifndef MEMORY_CONFIG_H
#define MEMORY_CONFIG_H
#include <stdint.h>
/* ============================================================================
* Memory Map Configuration
* ============================================================================ */
/* Flash memory configuration */
#define FLASH_BASE_ADDRESS 0x08000000U
#define FLASH_SIZE 0x00100000U /* 1 MB */
#define FLASH_PAGE_SIZE 0x00002000U /* 8 KB */
#define FLASH_SECTOR_SIZE 0x00010000U /* 64 KB */
/* RAM memory configuration */
#define RAM_BASE_ADDRESS 0x20000000U
#define RAM_SIZE 0x00020000U /* 128 KB */
/* CCM RAM (Core Coupled Memory) */
#define CCM_RAM_BASE_ADDRESS 0x10000000U
#define CCM_RAM_SIZE 0x00010000U /* 64 KB */
/* External RAM configuration */
#define EXT_RAM_BASE_ADDRESS 0x60000000U
#define EXT_RAM_SIZE 0x00800000U /* 8 MB */
/* ============================================================================
* Memory Regions
* ============================================================================ */
/* Kernel memory region */
#define KERNEL_MEMORY_START FLASH_BASE_ADDRESS
#define KERNEL_MEMORY_SIZE 0x00040000U /* 256 KB */
/* Application memory region */
#define APP_MEMORY_START (KERNEL_MEMORY_START + KERNEL_MEMORY_SIZE)
#define APP_MEMORY_SIZE 0x00080000U /* 512 KB */
/* Calibration data region */
#define CALIBRATION_MEMORY_START (APP_MEMORY_START + APP_MEMORY_SIZE)
#define CALIBRATION_MEMORY_SIZE 0x00020000U /* 128 KB */
/* Bootloader region */
#define BOOTLOADER_MEMORY_START FLASH_BASE_ADDRESS
#define BOOTLOADER_MEMORY_SIZE 0x00010000U /* 64 KB */
/* ============================================================================
* Stack Configuration
* ============================================================================ */
/* Main stack (MSP) */
#define MAIN_STACK_SIZE 0x00001000U /* 4 KB */
/* Process stack (PSP) */
#define PROCESS_STACK_SIZE 0x00000800U /* 2 KB */
/* ISR stack */
#define ISR_STACK_SIZE 0x00000800U /* 2 KB */
/* Exception stack */
#define EXCEPTION_STACK_SIZE 0x00000400U /* 1 KB */
/* ============================================================================
* Heap Configuration
* ============================================================================ */
/* Heap region */
#define HEAP_START (RAM_BASE_ADDRESS + 0x00010000U)
#define HEAP_SIZE 0x00010000U /* 64 KB */
/* Heap alignment */
#define HEAP_ALIGNMENT 8
/* Minimum heap block size */
#define HEAP_MIN_BLOCK_SIZE 16
/* Enable heap poisoning */
#define ENABLE_HEAP_POISONING 1
/* Heap poison value */
#define HEAP_POISON_VALUE 0xDEADBEEF
/* ============================================================================
* Memory Protection Units (MPU)
* ============================================================================ */
/* Number of MPU regions */
#define MPU_REGION_COUNT 8
/* MPU region definitions */
typedef struct {
uint32_t base_address;
uint32_t size;
uint8_t permissions;
bool executable;
bool cacheable;
bool bufferable;
} MpuRegionConfig_t;
/* Default MPU configuration */
static const MpuRegionConfig_t mpu_regions[] = {
/* Kernel code region (read-only, executable) */
{
.base_address = KERNEL_MEMORY_START,
.size = KERNEL_MEMORY_SIZE,
.permissions = 0x05, /* Read-only */
.executable = true,
.cacheable = true,
.bufferable = false
},
/* Application code region (read-only, executable) */
{
.base_address = APP_MEMORY_START,
.size = APP_MEMORY_SIZE,
.permissions = 0x05, /* Read-only */
.executable = true,
.cacheable = true,
.bufferable = false
},
/* RAM region (read-write, non-executable) */
{
.base_address = RAM_BASE_ADDRESS,
.size = RAM_SIZE,
.permissions = 0x03, /* Read-write */
.executable = false,
.cacheable = true,
.bufferable = true
},
/* Peripheral region (read-write, non-executable) */
{
.base_address = 0x40000000U,
.size = 0x10000000U, /* 256 MB */
.permissions = 0x03, /* Read-write */
.executable = false,
.cacheable = false,
.bufferable = true
},
/* External memory region */
{
.base_address = 0x60000000U,
.size = 0x10000000U, /* 256 MB */
.permissions = 0x03, /* Read-write */
.executable = false,
.cacheable = true,
.bufferable = true
}
};
#define MPU_REGION_COUNT_CONFIGURED (sizeof(mpu_regions) / sizeof(MpuRegionConfig_t))
/* ============================================================================
* Memory Pools
* ============================================================================ */
/* Memory pool configurations */
#define MEMORY_POOL_COUNT 4
typedef struct {
uint32_t block_size;
uint32_t block_count;
uint32_t total_size;
} MemoryPoolConfig_t;
static const MemoryPoolConfig_t memory_pools[MEMORY_POOL_COUNT] = {
{.block_size = 32, .block_count = 64, .total_size = 2048},
{.block_size = 64, .block_count = 64, .total_size = 4096},
{.block_size = 128, .block_count = 32, .total_size = 4096},
{.block_size = 256, .block_count = 16, .total_size = 4096}
};
/* ============================================================================
* DMA Configuration
* ============================================================================ */
/* DMA channels */
#define DMA_CHANNEL_COUNT 8
/* DMA buffer sizes */
#define DMA_BUFFER_SIZE_CAN 512
#define DMA_BUFFER_SIZE_UART 256
#define DMA_BUFFER_SIZE_SPI 1024
#define DMA_BUFFER_SIZE_ADC 512
/* DMA priorities */
#define DMA_PRIORITY_LOW 0
#define DMA_PRIORITY_MEDIUM 1
#define DMA_PRIORITY_HIGH 2
#define DMA_PRIORITY_VERY_HIGH 3
/* ============================================================================
* ECC Configuration
* ============================================================================ */
/* Enable ECC */
#define ENABLE_ECC 1
/* ECC protected regions */
#define ECC_FLASH_ENABLED 1
#define ECC_RAM_ENABLED 1
/* ECC error handling */
#define ECC_SINGLE_ERROR_CORRECT 1
#define ECC_DOUBLE_ERROR_DETECT 1
#endif /* MEMORY_CONFIG_H */
+191
View File
@@ -0,0 +1,191 @@
/**
* @file task_config.h
* @brief Task configuration for automotive applications
*/
#ifndef TASK_CONFIG_H
#define TASK_CONFIG_H
#include "kernel_config.h"
/* ============================================================================
* Task Priority Definitions
* ============================================================================ */
/* Critical safety tasks (highest priority) */
#define TASK_PRIORITY_SAFETY_CRITICAL 0
#define TASK_PRIORITY_ENGINE_CONTROL 1
#define TASK_PRIORITY_BRAKE_CONTROL 1
#define TASK_PRIORITY_ABS_CONTROL 2
#define TASK_PRIORITY_AIRBAG_CONTROL 2
/* Real-time control tasks */
#define TASK_PRIORITY_FUEL_INJECTION 3
#define TASK_PRIORITY_IGNITION_CONTROL 3
#define TASK_PRIORITY_TRANSMISSION 4
#define TASK_PRIORITY_STEERING_CONTROL 4
/* Communication tasks */
#define TASK_PRIORITY_CAN_COMM 5
#define TASK_PRIORITY_LIN_COMM 6
#define TASK_PRIORITY_DIAGNOSTICS 6
/* Sensor processing tasks */
#define TASK_PRIORITY_SENSOR_READING 7
#define TASK_PRIORITY_SENSOR_FUSION 7
#define TASK_PRIORITY_DATA_LOGGING 8
/* Body control tasks */
#define TASK_PRIORITY_BODY_CONTROL 8
#define TASK_PRIORITY_DOOR_CONTROL 9
#define TASK_PRIORITY_LIGHTING_CONTROL 9
/* User interface tasks */
#define TASK_PRIORITY_DISPLAY 10
#define TASK_PRIORITY_GAUGE_CONTROL 10
#define TASK_PRIORITY_INFOTAINMENT 11
/* Background tasks (lowest priority) */
#define TASK_PRIORITY_DIAGNOSTIC_MONITOR 12
#define TASK_PRIORITY_MAINTENANCE 13
#define TASK_PRIORITY_IDLE IDLE_TASK_PRIORITY
/* ============================================================================
* Task Period Definitions (in milliseconds)
* ============================================================================ */
/* Safety-critical periods */
#define TASK_PERIOD_AIRBAG_CONTROL 1
#define TASK_PERIOD_ABS_CONTROL 1
#define TASK_PERIOD_ENGINE_CONTROL 1
/* Control loop periods */
#define TASK_PERIOD_FUEL_INJECTION 5
#define TASK_PERIOD_IGNITION_CONTROL 5
#define TASK_PERIOD_BRAKE_CONTROL 5
#define TASK_PERIOD_STEERING_CONTROL 5
/* Communication periods */
#define TASK_PERIOD_CAN_COMM 10
#define TASK_PERIOD_LIN_COMM 20
#define TASK_PERIOD_DIAGNOSTICS 50
/* Sensor periods */
#define TASK_PERIOD_SENSOR_READING 2
#define TASK_PERIOD_SENSOR_FUSION 10
#define TASK_PERIOD_DATA_LOGGING 100
/* Body control periods */
#define TASK_PERIOD_BODY_CONTROL 50
#define TASK_PERIOD_DOOR_CONTROL 100
#define TASK_PERIOD_LIGHTING_CONTROL 100
/* Display periods */
#define TASK_PERIOD_DISPLAY 50
#define TASK_PERIOD_GAUGE_CONTROL 10
#define TASK_PERIOD_INFOTAINMENT 100
/* Background periods */
#define TASK_PERIOD_DIAGNOSTIC_MONITOR 500
#define TASK_PERIOD_MAINTENANCE 1000
/* ============================================================================
* Task Stack Sizes (in bytes)
* ============================================================================ */
/* Safety-critical task stacks */
#define TASK_STACK_AIRBAG_CONTROL 2048
#define TASK_STACK_ABS_CONTROL 2048
#define TASK_STACK_ENGINE_CONTROL 2048
/* Control task stacks */
#define TASK_STACK_FUEL_INJECTION 1024
#define TASK_STACK_IGNITION_CONTROL 1024
#define TASK_STACK_BRAKE_CONTROL 1024
#define TASK_STACK_STEERING_CONTROL 1024
/* Communication task stacks */
#define TASK_STACK_CAN_COMM 2048
#define TASK_STACK_LIN_COMM 1024
#define TASK_STACK_DIAGNOSTICS 2048
/* Sensor task stacks */
#define TASK_STACK_SENSOR_READING 1024
#define TASK_STACK_SENSOR_FUSION 2048
#define TASK_STACK_DATA_LOGGING 4096
/* Body control task stacks */
#define TASK_STACK_BODY_CONTROL 1024
#define TASK_STACK_DOOR_CONTROL 1024
#define TASK_STACK_LIGHTING_CONTROL 1024
/* Display task stacks */
#define TASK_STACK_DISPLAY 4096
#define TASK_STACK_GAUGE_CONTROL 1024
#define TASK_STACK_INFOTAINMENT 8192
/* Background task stacks */
#define TASK_STACK_DIAGNOSTIC_MONITOR 2048
#define TASK_STACK_MAINTENANCE 1024
/* ============================================================================
* Task Configuration Table
* ============================================================================ */
typedef struct {
const char* name;
uint8_t priority;
uint16_t period_ms;
uint32_t stack_size;
uint32_t deadline_ms;
bool is_periodic;
bool is_critical;
} TaskConfigEntry_t;
/* Task configuration table */
static const TaskConfigEntry_t task_config_table[] = {
/* Name Priority Period Stack Deadline Periodic Critical */
{"Airbag Control", 0, 1, 2048, 2, true, true},
{"ABS Control", 2, 1, 2048, 2, true, true},
{"Engine Control", 1, 1, 2048, 2, true, true},
{"Brake Control", 1, 5, 1024, 10, true, true},
{"Fuel Injection", 3, 5, 1024, 10, true, false},
{"Ignition Control", 3, 5, 1024, 10, true, false},
{"Steering Control", 4, 5, 1024, 10, true, false},
{"Transmission Control", 4, 10, 2048, 20, true, false},
{"CAN Communication", 5, 10, 2048, 20, true, false},
{"LIN Communication", 6, 20, 1024, 40, true, false},
{"Diagnostics", 6, 50, 2048, 100, true, false},
{"Sensor Reading", 7, 2, 1024, 4, true, false},
{"Sensor Fusion", 7, 10, 2048, 20, true, false},
{"Data Logging", 8, 100, 4096, 200, true, false},
{"Body Control", 8, 50, 1024, 100, true, false},
{"Door Control", 9, 100, 1024, 200, true, false},
{"Lighting Control", 9, 100, 1024, 200, true, false},
{"Display", 10, 50, 4096, 100, true, false},
{"Gauge Control", 10, 10, 1024, 20, true, false},
{"Infotainment", 11, 100, 8192, 200, true, false},
{"Diagnostic Monitor", 12, 500, 2048, 1000, true, false},
{"Maintenance", 13, 1000, 1024, 2000, true, false},
};
/* Number of tasks in configuration table */
#define TASK_CONFIG_COUNT (sizeof(task_config_table) / sizeof(TaskConfigEntry_t))
/* ============================================================================
* Task Supervision Configuration
* ============================================================================ */
/* Enable task supervision */
#define TASK_SUPERVISION_ENABLED 1
/* Default task timeout in milliseconds */
#define TASK_DEFAULT_TIMEOUT_MS 1000
/* Maximum alive counter before reset */
#define TASK_MAX_ALIVE_COUNT 5
/* Task supervision check period */
#define TASK_SUPERVISION_PERIOD_MS 100
#endif /* TASK_CONFIG_H */