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,28 @@
|
||||
/**
|
||||
* @file engine_control.h
|
||||
* @brief Engine control module interface
|
||||
*/
|
||||
|
||||
#ifndef ENGINE_CONTROL_H
|
||||
#define ENGINE_CONTROL_H
|
||||
|
||||
#include "kernel.h"
|
||||
#include "engine_parameters.h"
|
||||
|
||||
/* Engine Control Functions */
|
||||
KernelStatus_t engine_control_init(void);
|
||||
KernelStatus_t engine_control_start(void);
|
||||
KernelStatus_t engine_control_stop(void);
|
||||
KernelStatus_t engine_control_get_sensor_data(EngineSensorData_t* data);
|
||||
KernelStatus_t engine_control_get_actuator_data(EngineActuatorData_t* data);
|
||||
KernelStatus_t engine_control_set_actuator_data(const EngineActuatorData_t* data);
|
||||
EngineState_t engine_control_get_state(void);
|
||||
KernelStatus_t engine_control_get_faults(EngineFaultCode_t* faults,
|
||||
uint8_t* count);
|
||||
KernelStatus_t engine_control_clear_faults(void);
|
||||
void engine_control_task(void* parameters);
|
||||
void fuel_injection_task(void* parameters);
|
||||
void ignition_control_task(void* parameters);
|
||||
void sensor_reading_task(void* parameters);
|
||||
|
||||
#endif /* ENGINE_CONTROL_H */
|
||||
@@ -0,0 +1,177 @@
|
||||
/**
|
||||
* @file engine_parameters.h
|
||||
* @brief Engine control parameters and calibration data
|
||||
*/
|
||||
|
||||
#ifndef ENGINE_PARAMETERS_H
|
||||
#define ENGINE_PARAMETERS_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/* Engine Operating Parameters */
|
||||
#define ENGINE_MAX_RPM 6500
|
||||
#define ENGINE_IDLE_RPM 800
|
||||
#define ENGINE_REDLINE_RPM 6000
|
||||
#define ENGINE_MAX_TORQUE_RPM 4000
|
||||
#define ENGINE_MAX_POWER_RPM 5500
|
||||
|
||||
/* Temperature Limits */
|
||||
#define ENGINE_MAX_COOLANT_TEMP 120 /* °C */
|
||||
#define ENGINE_MIN_COOLANT_TEMP -40 /* °C */
|
||||
#define ENGINE_OPTIMAL_TEMP 90 /* °C */
|
||||
#define ENGINE_MAX_OIL_TEMP 150 /* °C */
|
||||
#define ENGINE_MAX_INTAKE_TEMP 80 /* °C */
|
||||
|
||||
/* Pressure Limits */
|
||||
#define ENGINE_MAX_MANIFOLD_PRESSURE 250 /* kPa */
|
||||
#define ENGINE_MIN_OIL_PRESSURE 100 /* kPa */
|
||||
#define ENGINE_MAX_FUEL_PRESSURE 500 /* kPa */
|
||||
|
||||
/* Fuel System Parameters */
|
||||
#define FUEL_STOICHIOMETRIC_RATIO 14.7f
|
||||
#define FUEL_MAX_INJECTION_TIME 20.0f /* ms */
|
||||
#define FUEL_MIN_INJECTION_TIME 0.5f /* ms */
|
||||
#define FUEL_INJECTOR_FLOW_RATE 250.0f /* cc/min */
|
||||
|
||||
/* Ignition Parameters */
|
||||
#define IGNITION_MAX_ADVANCE 45.0f /* degrees BTDC */
|
||||
#define IGNITION_MIN_ADVANCE -10.0f /* degrees ATDC */
|
||||
#define IGNITION_BASE_ADVANCE 10.0f /* degrees BTDC */
|
||||
#define IGNITION_DWELL_TIME 3.5f /* ms */
|
||||
|
||||
/* Control Loop Parameters */
|
||||
#define ENGINE_CONTROL_PERIOD_MS 1 /* 1ms control loop */
|
||||
#define FUEL_CONTROL_PERIOD_MS 10 /* 10ms fuel update */
|
||||
#define IGNITION_CONTROL_PERIOD_MS 5 /* 5ms ignition update */
|
||||
#define SENSOR_READ_PERIOD_MS 2 /* 2ms sensor reading */
|
||||
|
||||
/* PID Controller Gains */
|
||||
typedef struct {
|
||||
float kp;
|
||||
float ki;
|
||||
float kd;
|
||||
float integral_limit;
|
||||
float output_limit;
|
||||
} PidGains_t;
|
||||
|
||||
/* Fuel Control PID */
|
||||
static const PidGains_t fuel_pid_gains = {
|
||||
.kp = 0.5f,
|
||||
.ki = 0.1f,
|
||||
.kd = 0.05f,
|
||||
.integral_limit = 100.0f,
|
||||
.output_limit = 100.0f
|
||||
};
|
||||
|
||||
/* Idle Control PID */
|
||||
static const PidGains_t idle_pid_gains = {
|
||||
.kp = 0.8f,
|
||||
.ki = 0.2f,
|
||||
.kd = 0.1f,
|
||||
.integral_limit = 50.0f,
|
||||
.output_limit = 100.0f
|
||||
};
|
||||
|
||||
/* Boost Control PID */
|
||||
static const PidGains_t boost_pid_gains = {
|
||||
.kp = 0.3f,
|
||||
.ki = 0.05f,
|
||||
.kd = 0.02f,
|
||||
.integral_limit = 200.0f,
|
||||
.output_limit = 250.0f
|
||||
};
|
||||
|
||||
/* Engine State Enumeration */
|
||||
typedef enum {
|
||||
ENGINE_STATE_OFF = 0,
|
||||
ENGINE_STATE_CRANKING = 1,
|
||||
ENGINE_STATE_RUNNING = 2,
|
||||
ENGINE_STATE_IDLE = 3,
|
||||
ENGINE_STATE_ACCELERATING = 4,
|
||||
ENGINE_STATE_DECELERATING = 5,
|
||||
ENGINE_STATE_FAULT = 6,
|
||||
ENGINE_STATE_LIMP_HOME = 7
|
||||
} EngineState_t;
|
||||
|
||||
/* Engine Sensor Data */
|
||||
typedef struct {
|
||||
uint16_t rpm;
|
||||
uint16_t vehicle_speed;
|
||||
int16_t coolant_temp;
|
||||
int16_t intake_air_temp;
|
||||
int16_t oil_temp;
|
||||
uint16_t manifold_pressure;
|
||||
uint16_t oil_pressure;
|
||||
uint16_t fuel_pressure;
|
||||
uint16_t throttle_position;
|
||||
uint16_t accelerator_pedal;
|
||||
float mass_air_flow;
|
||||
float lambda;
|
||||
float battery_voltage;
|
||||
} EngineSensorData_t;
|
||||
|
||||
/* Engine Actuator Data */
|
||||
typedef struct {
|
||||
uint16_t injector_pulse_width;
|
||||
float ignition_advance;
|
||||
uint16_t idle_air_control;
|
||||
uint16_t boost_control;
|
||||
uint16_t fuel_pump_duty;
|
||||
uint16_t cooling_fan_duty;
|
||||
} EngineActuatorData_t;
|
||||
|
||||
/* Engine Fault Codes */
|
||||
typedef enum {
|
||||
ENGINE_FAULT_NONE = 0,
|
||||
ENGINE_FAULT_COOLANT_TEMP_SENSOR = 1,
|
||||
ENGINE_FAULT_INTAKE_TEMP_SENSOR = 2,
|
||||
ENGINE_FAULT_MANIFOLD_PRESSURE_SENSOR = 3,
|
||||
ENGINE_FAULT_MAF_SENSOR = 4,
|
||||
ENGINE_FAULT_OXYGEN_SENSOR = 5,
|
||||
ENGINE_FAULT_KNOCK_SENSOR = 6,
|
||||
ENGINE_FAULT_CRANKSHAFT_SENSOR = 7,
|
||||
ENGINE_FAULT_CAMSHAFT_SENSOR = 8,
|
||||
ENGINE_FAULT_INJECTOR_1 = 9,
|
||||
ENGINE_FAULT_INJECTOR_2 = 10,
|
||||
ENGINE_FAULT_INJECTOR_3 = 11,
|
||||
ENGINE_FAULT_INJECTOR_4 = 12,
|
||||
ENGINE_FAULT_IGNITION_COIL = 13,
|
||||
ENGINE_FAULT_FUEL_PUMP = 14,
|
||||
ENGINE_FAULT_OVERHEAT = 15,
|
||||
ENGINE_FAULT_LOW_OIL_PRESSURE = 16
|
||||
} EngineFaultCode_t;
|
||||
|
||||
/* Lookup Tables */
|
||||
typedef struct {
|
||||
const uint16_t* rpm_points;
|
||||
const uint16_t* load_points;
|
||||
const uint16_t* values;
|
||||
uint8_t rpm_count;
|
||||
uint8_t load_count;
|
||||
} LookupTable2D_t;
|
||||
|
||||
/* Fuel Map (injection time in microseconds) */
|
||||
static const uint16_t fuel_map_rpm[] = {0, 500, 1000, 2000, 3000, 4000, 5000, 6000};
|
||||
static const uint16_t fuel_map_load[] = {0, 20, 40, 60, 80, 100};
|
||||
static const uint16_t fuel_map_values[][8] = {
|
||||
{0, 1000, 800, 700, 650, 600, 550, 500},
|
||||
{1000, 1500, 1300, 1200, 1100, 1000, 950, 900},
|
||||
{2000, 2500, 2200, 2000, 1800, 1700, 1600, 1500},
|
||||
{3000, 3500, 3200, 3000, 2800, 2600, 2400, 2200},
|
||||
{4000, 4500, 4200, 4000, 3800, 3600, 3400, 3200},
|
||||
{5000, 5500, 5200, 5000, 4800, 4600, 4400, 4200}
|
||||
};
|
||||
|
||||
/* Ignition Advance Map (degrees BTDC) */
|
||||
static const uint16_t ignition_map_rpm[] = {0, 500, 1000, 2000, 3000, 4000, 5000, 6000};
|
||||
static const uint16_t ignition_map_load[] = {0, 20, 40, 60, 80, 100};
|
||||
static const int16_t ignition_map_values[][8] = {
|
||||
{10, 12, 15, 18, 20, 22, 25, 28},
|
||||
{10, 12, 15, 18, 20, 22, 25, 28},
|
||||
{8, 10, 13, 16, 18, 20, 23, 26},
|
||||
{6, 8, 11, 14, 16, 18, 21, 24},
|
||||
{4, 6, 9, 12, 14, 16, 19, 22},
|
||||
{2, 4, 7, 10, 12, 14, 17, 20}
|
||||
};
|
||||
|
||||
#endif /* ENGINE_PARAMETERS_H */
|
||||
Reference in New Issue
Block a user