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

GPIO unit test implementation for NAVHAL. More...

#include "core/cortex-m4/gpio.h"
#include "core/cortex-m4/gpio_reg.h"
#include "unity.h"
#include <stdint.h>
Include dependency graph for test_gpio.c:

Macros

#define CORTEX_M4
#define TEST_PIN   GPIO_PC09
 Test pin used for all GPIO tests (Port C, Pin 9)
#define TEST_AF   GPIO_AF07
 Alternate function used for testing (AF7)

Functions

void test_hal_gpio_setmode (void)
 Test GPIO mode configuration.
void test_hal_gpio_getmode (void)
 Test GPIO mode reading.
void test_hal_gpio_digitalwrite_sets_pin_high (void)
 Test digital write (high) operation.
void test_hal_gpio_digitalwrite_sets_pin_low (void)
 Test digital write (low) operation.
void test_gpio_set_alternate_function (void)
 Test alternate function configuration.

Detailed Description

GPIO unit test implementation for NAVHAL.

This file implements the test cases for verifying GPIO functionality in the NAVHAL hardware abstraction layer. It tests both the high-level HAL interface and the underlying register-level configurations.

Tests cover:

  • Mode configuration (input/output/alternate)
  • Digital write operations (high/low)
  • Alternate function setup
  • Register-level verification of all operations
Note
Uses Unity test framework for assertions
Tests use PC9 (TEST_PIN) as the test pin with AF7 (TEST_AF) for AF tests

Macro Definition Documentation

◆ CORTEX_M4

#define CORTEX_M4

◆ TEST_AF

#define TEST_AF   GPIO_AF07

Alternate function used for testing (AF7)

◆ TEST_PIN

#define TEST_PIN   GPIO_PC09

Test pin used for all GPIO tests (Port C, Pin 9)

Function Documentation

◆ test_gpio_set_alternate_function()

void test_gpio_set_alternate_function ( void )

Test alternate function configuration.

Verifies that hal_gpio_set_alternate_function():

  1. Correctly sets the alternate function number
  2. Handles both AFRL (pins 0-7) and AFRH (pins 8-15) registers

Test sequence:

  1. Configure pin for alternate function
  2. Verify correct AF number in appropriate register (AFRL/AFRH)

◆ test_hal_gpio_digitalwrite_sets_pin_high()

void test_hal_gpio_digitalwrite_sets_pin_high ( void )

Test digital write (high) operation.

Test digital write high.

Verifies that hal_gpio_digitalwrite() with GPIO_HIGH:

  1. Sets the correct bit in the ODR register
  2. Actually drives the pin high

Test sequence:

  1. Configure pin as output
  2. Write high
  3. Verify ODR register state

◆ test_hal_gpio_digitalwrite_sets_pin_low()

void test_hal_gpio_digitalwrite_sets_pin_low ( void )

Test digital write (low) operation.

Test digital write low.

Verifies that hal_gpio_digitalwrite() with GPIO_LOW:

  1. Clears the correct bit in the ODR register
  2. Actually drives the pin low

Test sequence:

  1. Configure pin as output
  2. Write low
  3. Verify ODR register state

◆ test_hal_gpio_getmode()

void test_hal_gpio_getmode ( void )

Test GPIO mode reading.

Verifies that hal_gpio_getmode() correctly returns:

  1. The current pin mode configuration
  2. Matches the actual hardware register state

Test sequence:

  1. Configure pin as output
  2. Compare getmode() return value with direct register read

◆ test_hal_gpio_setmode()

void test_hal_gpio_setmode ( void )

Test GPIO mode configuration.

Verifies that hal_gpio_setmode() correctly configures:

  1. The pin mode in the MODER register
  2. The pull-up/pull-down settings

Test sequence:

  1. Configure pin as output with no pull-up/pull-down
  2. Verify MODER register bits are set correctly