Skip to content

Conversation

@MatejGomboc-Claude-MCP
Copy link
Collaborator

Summary

This PR introduces a flat include interface for the library, allowing users to include headers using a clean, unified syntax:

#include "armcortex/mpu.hpp"
#include "armcortex/nvic.hpp"
#include "armcortex/barriers.hpp"
#include "armcortex/systick.hpp"

Instead of the previous architecture-specific paths like m0plus/mpu.hpp.

How it works

The include/armcortex/ directory contains thin forwarding headers that use preprocessor conditionals to include the correct architecture-specific implementation based on the ARM_CORTEX_Mx compile definition (which is already set by CMake).

For example, include/armcortex/mpu.hpp:

#pragma once

#if defined(ARM_CORTEX_M0PLUS)
#include "../../m0plus/mpu.hpp"
#elif defined(ARM_CORTEX_M3)
#include "../../m3/mpu.hpp"
#elif defined(ARM_CORTEX_M0) || defined(ARM_CORTEX_M1)
#error "MPU is not available on Cortex-M0 and Cortex-M1"
#else
#error "No ARM Cortex-M architecture defined..."
#endif

Benefits

  • Clean user experience: Simple, flat includes for end users
  • Clear error messages: Helpful compile-time errors if a feature isn't available for the target architecture
  • No restructuring: Original source files remain in their organized directories (m0/, m0plus/, m3/, intrinsics/)
  • No code generation: Forwarding headers are hand-written and version controlled
  • IDE friendly: All headers are listed in target_sources for visibility

Available headers

Header Description Architectures
armcortex/nvic.hpp Nested Vectored Interrupt Controller All
armcortex/scb.hpp System Control Block All
armcortex/systick.hpp SysTick Timer All
armcortex/exceptions.hpp Exception numbers All
armcortex/special_regs.hpp Special registers All
armcortex/mpu.hpp Memory Protection Unit M0+, M3+
armcortex/scnscb.hpp System Control (not in SCB) M1 only
armcortex/barriers.hpp Memory barriers All
armcortex/byte_reversing.hpp Byte swap intrinsics All
armcortex/debugging.hpp Debug intrinsics All
armcortex/hints.hpp Compiler hints All
armcortex/power_management.hpp Power management All
armcortex/bit_operations.hpp Bit manipulation M3+ (ARMv7-M)
armcortex/exclusive_access.hpp Exclusive load/store M3+ (ARMv7-M)
armcortex/saturation.hpp Saturating arithmetic M3+ (ARMv7-M)
armcortex/bit_utils.hpp Bit utilities All
armcortex/intrinsics.hpp All intrinsics (convenience) All

Testing

The CI should verify that the new include paths work correctly for all architecture configurations.

Users can now include headers using a flat structure:
  #include "armcortex/mpu.hpp"
  #include "armcortex/nvic.hpp"
  #include "armcortex/barriers.hpp"
  etc.

The forwarding headers automatically select the correct
architecture-specific implementation based on the
ARM_CORTEX_Mx compile definition.

Source files remain organized in their original directories
(m0/, m0plus/, m1/, m3/, intrinsics/) for maintainability.
Add include/armcortex/ to the include directories so users can use:
  #include "armcortex/mpu.hpp"

The forwarding headers in include/armcortex/ are also added to
target_sources for IDE visibility.
Only expose include/ directory - users must now use:
  #include "armcortex/mpu.hpp"

Removed legacy include paths:
  - ${CMAKE_CURRENT_SOURCE_DIR}
  - ${CMAKE_CURRENT_SOURCE_DIR}/intrinsics/common
  - ${CMAKE_CURRENT_SOURCE_DIR}/intrinsics/armv7m
Changed all implementation files to use relative paths for internal
dependencies instead of relying on include directories:
  - #include "barriers.hpp" -> #include "../intrinsics/common/barriers.hpp"

Updated test file to use the new flat include interface:
  - #include "barriers.hpp" -> #include "armcortex/barriers.hpp"

This ensures the library works with only include/ exposed.
Changed M3 implementation files to use relative paths:
  - #include "barriers.hpp" -> #include "../intrinsics/common/barriers.hpp"
- Add source root as include directory for tests in CMakeLists.txt
- Update intrinsics/common test files to use proper paths:
  - #include "intrinsics/common/barriers.hpp"
  - #include "intrinsics/common/byte_reversing.hpp"
  - #include "intrinsics/common/debugging.hpp"
  - #include "intrinsics/common/hints.hpp"
  - #include "intrinsics/common/power_management.hpp"
- Update intrinsics/armv7m test to use proper path:
  - #include "intrinsics/armv7m/bit_operations.hpp"

Tests use organized directory structure for maintainability while
end users get the flat include interface.
- tests/intrinsics/common/test_exceptions.cpp
- tests/intrinsics/armv7m/test_exclusive_access.cpp
- tests/intrinsics/armv7m/test_saturation.cpp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants