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();
|
||||
}
|
||||
Reference in New Issue
Block a user