/** * @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(); }