NavHAL 0.1.0
NAVRobotec's architecture-agnostic HAL for embedded systems.
Loading...
Searching...
No Matches
test_timer.c File Reference

Timer unit test implementation for NAVHAL. More...

#include "core/cortex-m4/timer.h"
#include "core/cortex-m4/timer_reg.h"
#include "unity.h"
#include <stdint.h>
Include dependency graph for test_timer.c:

Macros

#define TEST_TIMER   TIM2
 Timer peripheral used for all tests (TIM2)
#define TEST_PSC   83
 Test prescaler value.
#define TEST_ARR   999
 Test auto-reload value.
#define TEST_CHANNEL   1
 Test channel number (Channel 1)
#define TEST_COMPARE_VALUE   500
 Test compare register value.

Functions

void test_timer_init_sets_prescaler_and_arr (void)
 Test timer initialization.
void test_timer_start_sets_CEN_bit (void)
 Test timer start functionality.
void test_timer_stop_clears_CEN_bit (void)
 Test timer stop functionality.
void test_timer_reset_clears_count (void)
 Test timer counter reset.
void test_timer_set_compare_and_get_compare (void)
 Test compare register operations.
void test_timer_enable_and_disable_channel (void)
 Test channel enable/disable.
void test_timer_enable_and_disable_interrupt (void)
 Test interrupt enable.
void test_timer_clear_interrupt_flag_clears_UIF (void)
 Test interrupt flag clearing.
void test_timer_get_arr_returns_arr_value (void)
 Test auto-reload register access.
void test_timer_get_count_returns_count_value (void)
 Test counter value access.

Detailed Description

Timer unit test implementation for NAVHAL.

This file implements the test cases for verifying Timer peripheral functionality in the NAVHAL hardware abstraction layer. It performs register-level verification of all timer operations using TIM2 as the test timer.

Tests cover:

  • Initialization (prescaler and auto-reload values)
  • Start/stop control
  • Counter operations
  • Compare register functionality
  • Channel enable/disable
  • Interrupt control
  • Register access functions
Note
Uses Unity test framework for assertions
All tests use TIM2 as the test timer

Macro Definition Documentation

◆ TEST_ARR

#define TEST_ARR   999

Test auto-reload value.

◆ TEST_CHANNEL

#define TEST_CHANNEL   1

Test channel number (Channel 1)

◆ TEST_COMPARE_VALUE

#define TEST_COMPARE_VALUE   500

Test compare register value.

◆ TEST_PSC

#define TEST_PSC   83

Test prescaler value.

◆ TEST_TIMER

#define TEST_TIMER   TIM2

Timer peripheral used for all tests (TIM2)

Function Documentation

◆ test_timer_clear_interrupt_flag_clears_UIF()

void test_timer_clear_interrupt_flag_clears_UIF ( void )

Test interrupt flag clearing.

Verifies that timer_clear_interrupt_flag() clears the Update Interrupt Flag (UIF) in the SR register

◆ test_timer_enable_and_disable_channel()

void test_timer_enable_and_disable_channel ( void )

Test channel enable/disable.

Verifies:

  1. timer_disable_channel() clears the channel enable bit in CCER register
  2. timer_enable_channel() sets the channel enable bit in CCER register

◆ test_timer_enable_and_disable_interrupt()

void test_timer_enable_and_disable_interrupt ( void )

Test interrupt enable.

Test interrupt control.

Verifies that timer_enable_interrupt() sets the Update Interrupt Enable (UIE) bit in the DIER register

◆ test_timer_get_arr_returns_arr_value()

void test_timer_get_arr_returns_arr_value ( void )

Test auto-reload register access.

Verifies that timer_get_arr() correctly returns the value from the ARR register

◆ test_timer_get_count_returns_count_value()

void test_timer_get_count_returns_count_value ( void )

Test counter value access.

Verifies that timer_get_count() correctly returns the current counter value from the CNT register

◆ test_timer_init_sets_prescaler_and_arr()

void test_timer_init_sets_prescaler_and_arr ( void )

Test timer initialization.

Verifies that timer_init() correctly sets:

  1. The prescaler value in PSC register
  2. The auto-reload value in ARR register

◆ test_timer_reset_clears_count()

void test_timer_reset_clears_count ( void )

Test timer counter reset.

Verifies that timer_reset() clears the counter value to zero by checking the CNT register

◆ test_timer_set_compare_and_get_compare()

void test_timer_set_compare_and_get_compare ( void )

Test compare register operations.

Verifies:

  1. timer_set_compare() correctly sets the compare value in CCR register
  2. timer_get_compare() correctly returns the compare value

◆ test_timer_start_sets_CEN_bit()

void test_timer_start_sets_CEN_bit ( void )

Test timer start functionality.

Verifies that timer_start() sets the Counter ENable (CEN) bit in the CR1 register

◆ test_timer_stop_clears_CEN_bit()

void test_timer_stop_clears_CEN_bit ( void )

Test timer stop functionality.

Verifies that timer_stop() clears the Counter ENable (CEN) bit in the CR1 register