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,77 @@
|
||||
/**
|
||||
* @file test_adc.c
|
||||
* @brief Hardware tests for ADC
|
||||
*/
|
||||
|
||||
#include "unity.h"
|
||||
#include "kernel.h"
|
||||
#include "adc_driver.h"
|
||||
#include "board.h"
|
||||
|
||||
/* Setup */
|
||||
void setUp(void) {
|
||||
kernel_init();
|
||||
board_init();
|
||||
}
|
||||
|
||||
/* Teardown */
|
||||
void tearDown(void) {
|
||||
kernel_stop();
|
||||
}
|
||||
|
||||
/* ============================================================================
|
||||
* Test Cases
|
||||
* ============================================================================ */
|
||||
|
||||
/**
|
||||
* @brief Test ADC initialization
|
||||
*/
|
||||
void test_adc_init(void) {
|
||||
AdcConfig_t config = {
|
||||
.resolution = ADC_RESOLUTION_12BIT,
|
||||
.mode = ADC_MODE_SINGLE,
|
||||
.trigger_source = ADC_TRIGGER_SOFTWARE,
|
||||
.reference = ADC_REFERENCE_VDD,
|
||||
.enable_dma = false,
|
||||
.conversion_frequency = 1000,
|
||||
.channel_count = 1,
|
||||
.channels = {
|
||||
{.channel = 0, .sampling_time = ADC_SAMPLING_28_5_CYCLES}
|
||||
}
|
||||
};
|
||||
|
||||
TEST_ASSERT_EQUAL(KERNEL_OK, adc_init(0, &config));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test ADC conversion
|
||||
*/
|
||||
void test_adc_conversion(void) {
|
||||
uint16_t value = 0;
|
||||
|
||||
TEST_ASSERT_EQUAL(KERNEL_OK, adc_read_channel(0, 0, &value, 1000));
|
||||
TEST_ASSERT_GREATER_OR_EQUAL(0, value);
|
||||
TEST_ASSERT_LESS_OR_EQUAL(4095, value); /* 12-bit resolution */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test ADC voltage conversion
|
||||
*/
|
||||
void test_adc_voltage_conversion(void) {
|
||||
/* Test voltage conversion */
|
||||
float voltage = adc_convert_to_voltage(2048, ADC_RESOLUTION_12BIT, 3.3f);
|
||||
TEST_ASSERT_FLOAT_WITHIN(0.1f, 1.65f, voltage);
|
||||
}
|
||||
|
||||
/* ============================================================================
|
||||
* Test Runner
|
||||
* ============================================================================ */
|
||||
int main(void) {
|
||||
UNITY_BEGIN();
|
||||
|
||||
RUN_TEST(test_adc_init);
|
||||
RUN_TEST(test_adc_conversion);
|
||||
RUN_TEST(test_adc_voltage_conversion);
|
||||
|
||||
return UNITY_END();
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
/**
|
||||
* @file test_gpio.c
|
||||
* @brief Hardware tests for GPIO
|
||||
*/
|
||||
|
||||
#include "unity.h"
|
||||
#include "kernel.h"
|
||||
#include "gpio_driver.h"
|
||||
#include "board.h"
|
||||
|
||||
/* Test pins */
|
||||
#define TEST_OUTPUT_PIN 0
|
||||
#define TEST_INPUT_PIN 1
|
||||
|
||||
/* Setup */
|
||||
void setUp(void) {
|
||||
kernel_init();
|
||||
board_init();
|
||||
}
|
||||
|
||||
/* Teardown */
|
||||
void tearDown(void) {
|
||||
kernel_stop();
|
||||
}
|
||||
|
||||
/* ============================================================================
|
||||
* Test Cases
|
||||
* ============================================================================ */
|
||||
|
||||
/**
|
||||
* @brief Test GPIO initialization
|
||||
*/
|
||||
void test_gpio_init(void) {
|
||||
GpioPinConfig_t config = {
|
||||
.port = 0,
|
||||
.pin = TEST_OUTPUT_PIN,
|
||||
.mode = GPIO_MODE_OUTPUT,
|
||||
.output_type = GPIO_OUTPUT_PUSH_PULL,
|
||||
.pull = GPIO_PULL_NONE,
|
||||
.speed = GPIO_SPEED_HIGH
|
||||
};
|
||||
|
||||
TEST_ASSERT_EQUAL(KERNEL_OK, gpio_init(&config));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test GPIO write and read
|
||||
*/
|
||||
void test_gpio_write_read(void) {
|
||||
/* Configure output pin */
|
||||
GpioPinConfig_t output_config = {
|
||||
.port = 0,
|
||||
.pin = TEST_OUTPUT_PIN,
|
||||
.mode = GPIO_MODE_OUTPUT,
|
||||
.output_type = GPIO_OUTPUT_PUSH_PULL,
|
||||
.pull = GPIO_PULL_NONE,
|
||||
.speed = GPIO_SPEED_HIGH
|
||||
};
|
||||
gpio_init(&output_config);
|
||||
|
||||
/* Write high */
|
||||
TEST_ASSERT_EQUAL(KERNEL_OK, gpio_write(0, TEST_OUTPUT_PIN, true));
|
||||
TEST_ASSERT_TRUE(gpio_read(0, TEST_OUTPUT_PIN));
|
||||
|
||||
/* Write low */
|
||||
TEST_ASSERT_EQUAL(KERNEL_OK, gpio_write(0, TEST_OUTPUT_PIN, false));
|
||||
TEST_ASSERT_FALSE(gpio_read(0, TEST_OUTPUT_PIN));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test GPIO toggle
|
||||
*/
|
||||
void test_gpio_toggle(void) {
|
||||
GpioPinConfig_t config = {
|
||||
.port = 0,
|
||||
.pin = TEST_OUTPUT_PIN,
|
||||
.mode = GPIO_MODE_OUTPUT,
|
||||
.output_type = GPIO_OUTPUT_PUSH_PULL,
|
||||
.pull = GPIO_PULL_NONE,
|
||||
.speed = GPIO_SPEED_HIGH
|
||||
};
|
||||
gpio_init(&config);
|
||||
|
||||
bool initial_state = gpio_read(0, TEST_OUTPUT_PIN);
|
||||
|
||||
TEST_ASSERT_EQUAL(KERNEL_OK, gpio_toggle(0, TEST_OUTPUT_PIN));
|
||||
TEST_ASSERT_NOT_EQUAL(initial_state, gpio_read(0, TEST_OUTPUT_PIN));
|
||||
}
|
||||
|
||||
/* ============================================================================
|
||||
* Test Runner
|
||||
* ============================================================================ */
|
||||
int main(void) {
|
||||
UNITY_BEGIN();
|
||||
|
||||
RUN_TEST(test_gpio_init);
|
||||
RUN_TEST(test_gpio_write_read);
|
||||
RUN_TEST(test_gpio_toggle);
|
||||
|
||||
return UNITY_END();
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
/**
|
||||
* @file test_pwm.c
|
||||
* @brief Hardware tests for PWM
|
||||
*/
|
||||
|
||||
#include "unity.h"
|
||||
#include "kernel.h"
|
||||
#include "pwm_driver.h"
|
||||
#include "board.h"
|
||||
|
||||
/* Setup */
|
||||
void setUp(void) {
|
||||
kernel_init();
|
||||
board_init();
|
||||
}
|
||||
|
||||
/* Teardown */
|
||||
void tearDown(void) {
|
||||
kernel_stop();
|
||||
}
|
||||
|
||||
/* ============================================================================
|
||||
* Test Cases
|
||||
* ============================================================================ */
|
||||
|
||||
/**
|
||||
* @brief Test PWM initialization
|
||||
*/
|
||||
void test_pwm_init(void) {
|
||||
PwmConfig_t config = {
|
||||
.frequency_hz = 1000,
|
||||
.alignment = PWM_ALIGNMENT_EDGE,
|
||||
.period_ticks = 1000,
|
||||
.prescaler = 100,
|
||||
.channel_count = 1,
|
||||
.channels = {
|
||||
{.channel = 0, .duty_cycle = 0}
|
||||
},
|
||||
.enable_fault_protection = false,
|
||||
.fault_action = PWM_FAULT_DISABLE
|
||||
};
|
||||
|
||||
TEST_ASSERT_EQUAL(KERNEL_OK, pwm_init(0, &config));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test PWM duty cycle
|
||||
*/
|
||||
void test_pwm_duty_cycle(void) {
|
||||
/* Set 50% duty cycle */
|
||||
TEST_ASSERT_EQUAL(KERNEL_OK, pwm_set_duty_cycle(0, 0, 5000));
|
||||
TEST_ASSERT_EQUAL(5000, pwm_get_duty_cycle(0, 0));
|
||||
|
||||
/* Set 0% duty cycle */
|
||||
TEST_ASSERT_EQUAL(KERNEL_OK, pwm_set_duty_cycle(0, 0, 0));
|
||||
TEST_ASSERT_EQUAL(0, pwm_get_duty_cycle(0, 0));
|
||||
|
||||
/* Set 100% duty cycle */
|
||||
TEST_ASSERT_EQUAL(KERNEL_OK, pwm_set_duty_cycle(0, 0, 10000));
|
||||
TEST_ASSERT_EQUAL(10000, pwm_get_duty_cycle(0, 0));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test PWM frequency
|
||||
*/
|
||||
void test_pwm_frequency(void) {
|
||||
/* Set frequency */
|
||||
TEST_ASSERT_EQUAL(KERNEL_OK, pwm_set_frequency(0, 2000));
|
||||
TEST_ASSERT_EQUAL(2000, pwm_get_frequency(0));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test PWM start/stop
|
||||
*/
|
||||
void test_pwm_start_stop(void) {
|
||||
TEST_ASSERT_EQUAL(KERNEL_OK, pwm_start(0));
|
||||
TEST_ASSERT_EQUAL(KERNEL_OK, pwm_stop(0));
|
||||
}
|
||||
|
||||
/* ============================================================================
|
||||
* Test Runner
|
||||
* ============================================================================ */
|
||||
int main(void) {
|
||||
UNITY_BEGIN();
|
||||
|
||||
RUN_TEST(test_pwm_init);
|
||||
RUN_TEST(test_pwm_duty_cycle);
|
||||
RUN_TEST(test_pwm_frequency);
|
||||
RUN_TEST(test_pwm_start_stop);
|
||||
|
||||
return UNITY_END();
|
||||
}
|
||||
Reference in New Issue
Block a user