From 3c4c25a3f158f9cdc64490f1d0275846d51ac95d Mon Sep 17 00:00:00 2001 From: MatejGomboc-Claude-MCP <201144475+MatejGomboc-Claude-MCP@users.noreply.github.com> Date: Sun, 30 Nov 2025 17:08:58 +0100 Subject: [PATCH 1/8] feat: add flat include interface via forwarding headers 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. --- include/armcortex/barriers.hpp | 20 +++++++++++++++ include/armcortex/bit_operations.hpp | 26 ++++++++++++++++++++ include/armcortex/bit_utils.hpp | 20 +++++++++++++++ include/armcortex/byte_reversing.hpp | 20 +++++++++++++++ include/armcortex/debugging.hpp | 20 +++++++++++++++ include/armcortex/exceptions.hpp | 32 ++++++++++++++++++++++++ include/armcortex/exclusive_access.hpp | 26 ++++++++++++++++++++ include/armcortex/hints.hpp | 20 +++++++++++++++ include/armcortex/intrinsics.hpp | 34 ++++++++++++++++++++++++++ include/armcortex/mpu.hpp | 30 +++++++++++++++++++++++ include/armcortex/nvic.hpp | 32 ++++++++++++++++++++++++ include/armcortex/power_management.hpp | 20 +++++++++++++++ include/armcortex/saturation.hpp | 26 ++++++++++++++++++++ include/armcortex/scb.hpp | 32 ++++++++++++++++++++++++ include/armcortex/scnscb.hpp | 28 +++++++++++++++++++++ include/armcortex/special_regs.hpp | 32 ++++++++++++++++++++++++ include/armcortex/systick.hpp | 32 ++++++++++++++++++++++++ 17 files changed, 450 insertions(+) create mode 100644 include/armcortex/barriers.hpp create mode 100644 include/armcortex/bit_operations.hpp create mode 100644 include/armcortex/bit_utils.hpp create mode 100644 include/armcortex/byte_reversing.hpp create mode 100644 include/armcortex/debugging.hpp create mode 100644 include/armcortex/exceptions.hpp create mode 100644 include/armcortex/exclusive_access.hpp create mode 100644 include/armcortex/hints.hpp create mode 100644 include/armcortex/intrinsics.hpp create mode 100644 include/armcortex/mpu.hpp create mode 100644 include/armcortex/nvic.hpp create mode 100644 include/armcortex/power_management.hpp create mode 100644 include/armcortex/saturation.hpp create mode 100644 include/armcortex/scb.hpp create mode 100644 include/armcortex/scnscb.hpp create mode 100644 include/armcortex/special_regs.hpp create mode 100644 include/armcortex/systick.hpp diff --git a/include/armcortex/barriers.hpp b/include/armcortex/barriers.hpp new file mode 100644 index 0000000..524eec5 --- /dev/null +++ b/include/armcortex/barriers.hpp @@ -0,0 +1,20 @@ +/* + Copyright (C) 2025 Matej Gomboc + + Licensed under the Apache Licence, Version 2.0 (the "Licence"); + you may not use this file except in compliance with the Licence. + You may obtain a copy of the Licence at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the Licence is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the Licence for the specific language governing permissions and + limitations under the Licence. +*/ + +#pragma once + +// Forwarding header for flat include interface +#include "../../intrinsics/common/barriers.hpp" diff --git a/include/armcortex/bit_operations.hpp b/include/armcortex/bit_operations.hpp new file mode 100644 index 0000000..0b5826f --- /dev/null +++ b/include/armcortex/bit_operations.hpp @@ -0,0 +1,26 @@ +/* + Copyright (C) 2025 Matej Gomboc + + Licensed under the Apache Licence, Version 2.0 (the "Licence"); + you may not use this file except in compliance with the Licence. + You may obtain a copy of the Licence at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the Licence is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the Licence for the specific language governing permissions and + limitations under the Licence. +*/ + +#pragma once + +// Forwarding header for flat include interface +// Only available on ARMv7-M architectures (Cortex-M3 and above) + +#if defined(ARM_CORTEX_M3) || defined(ARM_CORTEX_M4) || defined(ARM_CORTEX_M7) +#include "../../intrinsics/armv7m/bit_operations.hpp" +#else +#error "bit_operations.hpp is only available on ARMv7-M architectures (Cortex-M3 and above)" +#endif diff --git a/include/armcortex/bit_utils.hpp b/include/armcortex/bit_utils.hpp new file mode 100644 index 0000000..082221d --- /dev/null +++ b/include/armcortex/bit_utils.hpp @@ -0,0 +1,20 @@ +/* + Copyright (C) 2025 Matej Gomboc + + Licensed under the Apache Licence, Version 2.0 (the "Licence"); + you may not use this file except in compliance with the Licence. + You may obtain a copy of the Licence at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the Licence is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the Licence for the specific language governing permissions and + limitations under the Licence. +*/ + +#pragma once + +// Forwarding header for flat include interface +#include "../../bit_utils.hpp" diff --git a/include/armcortex/byte_reversing.hpp b/include/armcortex/byte_reversing.hpp new file mode 100644 index 0000000..06bdfba --- /dev/null +++ b/include/armcortex/byte_reversing.hpp @@ -0,0 +1,20 @@ +/* + Copyright (C) 2025 Matej Gomboc + + Licensed under the Apache Licence, Version 2.0 (the "Licence"); + you may not use this file except in compliance with the Licence. + You may obtain a copy of the Licence at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the Licence is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the Licence for the specific language governing permissions and + limitations under the Licence. +*/ + +#pragma once + +// Forwarding header for flat include interface +#include "../../intrinsics/common/byte_reversing.hpp" diff --git a/include/armcortex/debugging.hpp b/include/armcortex/debugging.hpp new file mode 100644 index 0000000..3ee4a9e --- /dev/null +++ b/include/armcortex/debugging.hpp @@ -0,0 +1,20 @@ +/* + Copyright (C) 2025 Matej Gomboc + + Licensed under the Apache Licence, Version 2.0 (the "Licence"); + you may not use this file except in compliance with the Licence. + You may obtain a copy of the Licence at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the Licence is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the Licence for the specific language governing permissions and + limitations under the Licence. +*/ + +#pragma once + +// Forwarding header for flat include interface +#include "../../intrinsics/common/debugging.hpp" diff --git a/include/armcortex/exceptions.hpp b/include/armcortex/exceptions.hpp new file mode 100644 index 0000000..87c9241 --- /dev/null +++ b/include/armcortex/exceptions.hpp @@ -0,0 +1,32 @@ +/* + Copyright (C) 2025 Matej Gomboc + + Licensed under the Apache Licence, Version 2.0 (the "Licence"); + you may not use this file except in compliance with the Licence. + You may obtain a copy of the Licence at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the Licence is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the Licence for the specific language governing permissions and + limitations under the Licence. +*/ + +#pragma once + +// Forwarding header for flat include interface +// Selects architecture-specific implementation based on compile definitions + +#if defined(ARM_CORTEX_M0) +#include "../../m0/exceptions.hpp" +#elif defined(ARM_CORTEX_M0PLUS) +#include "../../m0plus/exceptions.hpp" +#elif defined(ARM_CORTEX_M1) +#include "../../m1/exceptions.hpp" +#elif defined(ARM_CORTEX_M3) +#include "../../m3/exceptions.hpp" +#else +#error "No ARM Cortex-M architecture defined. Define one of: ARM_CORTEX_M0, ARM_CORTEX_M0PLUS, ARM_CORTEX_M1, ARM_CORTEX_M3" +#endif diff --git a/include/armcortex/exclusive_access.hpp b/include/armcortex/exclusive_access.hpp new file mode 100644 index 0000000..34e0c95 --- /dev/null +++ b/include/armcortex/exclusive_access.hpp @@ -0,0 +1,26 @@ +/* + Copyright (C) 2025 Matej Gomboc + + Licensed under the Apache Licence, Version 2.0 (the "Licence"); + you may not use this file except in compliance with the Licence. + You may obtain a copy of the Licence at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the Licence is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the Licence for the specific language governing permissions and + limitations under the Licence. +*/ + +#pragma once + +// Forwarding header for flat include interface +// Only available on ARMv7-M architectures (Cortex-M3 and above) + +#if defined(ARM_CORTEX_M3) || defined(ARM_CORTEX_M4) || defined(ARM_CORTEX_M7) +#include "../../intrinsics/armv7m/exclusive_access.hpp" +#else +#error "exclusive_access.hpp is only available on ARMv7-M architectures (Cortex-M3 and above)" +#endif diff --git a/include/armcortex/hints.hpp b/include/armcortex/hints.hpp new file mode 100644 index 0000000..ab88f99 --- /dev/null +++ b/include/armcortex/hints.hpp @@ -0,0 +1,20 @@ +/* + Copyright (C) 2025 Matej Gomboc + + Licensed under the Apache Licence, Version 2.0 (the "Licence"); + you may not use this file except in compliance with the Licence. + You may obtain a copy of the Licence at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the Licence is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the Licence for the specific language governing permissions and + limitations under the Licence. +*/ + +#pragma once + +// Forwarding header for flat include interface +#include "../../intrinsics/common/hints.hpp" diff --git a/include/armcortex/intrinsics.hpp b/include/armcortex/intrinsics.hpp new file mode 100644 index 0000000..bfa43ab --- /dev/null +++ b/include/armcortex/intrinsics.hpp @@ -0,0 +1,34 @@ +/* + Copyright (C) 2025 Matej Gomboc + + Licensed under the Apache Licence, Version 2.0 (the "Licence"); + you may not use this file except in compliance with the Licence. + You may obtain a copy of the Licence at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the Licence is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the Licence for the specific language governing permissions and + limitations under the Licence. +*/ + +#pragma once + +// Convenience header that includes all intrinsics for the target architecture + +// Common intrinsics (all architectures) +#include "../../intrinsics/common/barriers.hpp" +#include "../../intrinsics/common/byte_reversing.hpp" +#include "../../intrinsics/common/debugging.hpp" +#include "../../intrinsics/common/exceptions.hpp" +#include "../../intrinsics/common/hints.hpp" +#include "../../intrinsics/common/power_management.hpp" + +// ARMv7-M specific intrinsics (Cortex-M3 and above) +#if defined(ARM_CORTEX_M3) || defined(ARM_CORTEX_M4) || defined(ARM_CORTEX_M7) +#include "../../intrinsics/armv7m/bit_operations.hpp" +#include "../../intrinsics/armv7m/exclusive_access.hpp" +#include "../../intrinsics/armv7m/saturation.hpp" +#endif diff --git a/include/armcortex/mpu.hpp b/include/armcortex/mpu.hpp new file mode 100644 index 0000000..43c0d04 --- /dev/null +++ b/include/armcortex/mpu.hpp @@ -0,0 +1,30 @@ +/* + Copyright (C) 2025 Matej Gomboc + + Licensed under the Apache Licence, Version 2.0 (the "Licence"); + you may not use this file except in compliance with the Licence. + You may obtain a copy of the Licence at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the Licence is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the Licence for the specific language governing permissions and + limitations under the Licence. +*/ + +#pragma once + +// Forwarding header for flat include interface +// MPU is only available on Cortex-M0+, M3, and above + +#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. Define one of: ARM_CORTEX_M0, ARM_CORTEX_M0PLUS, ARM_CORTEX_M1, ARM_CORTEX_M3" +#endif diff --git a/include/armcortex/nvic.hpp b/include/armcortex/nvic.hpp new file mode 100644 index 0000000..145bdc3 --- /dev/null +++ b/include/armcortex/nvic.hpp @@ -0,0 +1,32 @@ +/* + Copyright (C) 2025 Matej Gomboc + + Licensed under the Apache Licence, Version 2.0 (the "Licence"); + you may not use this file except in compliance with the Licence. + You may obtain a copy of the Licence at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the Licence is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the Licence for the specific language governing permissions and + limitations under the Licence. +*/ + +#pragma once + +// Forwarding header for flat include interface +// Selects architecture-specific implementation based on compile definitions + +#if defined(ARM_CORTEX_M0) +#include "../../m0/nvic.hpp" +#elif defined(ARM_CORTEX_M0PLUS) +#include "../../m0plus/nvic.hpp" +#elif defined(ARM_CORTEX_M1) +#include "../../m1/nvic.hpp" +#elif defined(ARM_CORTEX_M3) +#include "../../m3/nvic.hpp" +#else +#error "No ARM Cortex-M architecture defined. Define one of: ARM_CORTEX_M0, ARM_CORTEX_M0PLUS, ARM_CORTEX_M1, ARM_CORTEX_M3" +#endif diff --git a/include/armcortex/power_management.hpp b/include/armcortex/power_management.hpp new file mode 100644 index 0000000..a516072 --- /dev/null +++ b/include/armcortex/power_management.hpp @@ -0,0 +1,20 @@ +/* + Copyright (C) 2025 Matej Gomboc + + Licensed under the Apache Licence, Version 2.0 (the "Licence"); + you may not use this file except in compliance with the Licence. + You may obtain a copy of the Licence at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the Licence is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the Licence for the specific language governing permissions and + limitations under the Licence. +*/ + +#pragma once + +// Forwarding header for flat include interface +#include "../../intrinsics/common/power_management.hpp" diff --git a/include/armcortex/saturation.hpp b/include/armcortex/saturation.hpp new file mode 100644 index 0000000..81b28a9 --- /dev/null +++ b/include/armcortex/saturation.hpp @@ -0,0 +1,26 @@ +/* + Copyright (C) 2025 Matej Gomboc + + Licensed under the Apache Licence, Version 2.0 (the "Licence"); + you may not use this file except in compliance with the Licence. + You may obtain a copy of the Licence at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the Licence is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the Licence for the specific language governing permissions and + limitations under the Licence. +*/ + +#pragma once + +// Forwarding header for flat include interface +// Only available on ARMv7-M architectures (Cortex-M3 and above) + +#if defined(ARM_CORTEX_M3) || defined(ARM_CORTEX_M4) || defined(ARM_CORTEX_M7) +#include "../../intrinsics/armv7m/saturation.hpp" +#else +#error "saturation.hpp is only available on ARMv7-M architectures (Cortex-M3 and above)" +#endif diff --git a/include/armcortex/scb.hpp b/include/armcortex/scb.hpp new file mode 100644 index 0000000..1e46cf3 --- /dev/null +++ b/include/armcortex/scb.hpp @@ -0,0 +1,32 @@ +/* + Copyright (C) 2025 Matej Gomboc + + Licensed under the Apache Licence, Version 2.0 (the "Licence"); + you may not use this file except in compliance with the Licence. + You may obtain a copy of the Licence at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the Licence is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the Licence for the specific language governing permissions and + limitations under the Licence. +*/ + +#pragma once + +// Forwarding header for flat include interface +// Selects architecture-specific implementation based on compile definitions + +#if defined(ARM_CORTEX_M0) +#include "../../m0/scb.hpp" +#elif defined(ARM_CORTEX_M0PLUS) +#include "../../m0plus/scb.hpp" +#elif defined(ARM_CORTEX_M1) +#include "../../m1/scb.hpp" +#elif defined(ARM_CORTEX_M3) +#include "../../m3/scb.hpp" +#else +#error "No ARM Cortex-M architecture defined. Define one of: ARM_CORTEX_M0, ARM_CORTEX_M0PLUS, ARM_CORTEX_M1, ARM_CORTEX_M3" +#endif diff --git a/include/armcortex/scnscb.hpp b/include/armcortex/scnscb.hpp new file mode 100644 index 0000000..c2bf0b7 --- /dev/null +++ b/include/armcortex/scnscb.hpp @@ -0,0 +1,28 @@ +/* + Copyright (C) 2025 Matej Gomboc + + Licensed under the Apache Licence, Version 2.0 (the "Licence"); + you may not use this file except in compliance with the Licence. + You may obtain a copy of the Licence at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the Licence is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the Licence for the specific language governing permissions and + limitations under the Licence. +*/ + +#pragma once + +// Forwarding header for flat include interface +// SCNSCB (System Control Not in SCB) is only available on Cortex-M1 + +#if defined(ARM_CORTEX_M1) +#include "../../m1/scnscb.hpp" +#elif defined(ARM_CORTEX_M0) || defined(ARM_CORTEX_M0PLUS) || defined(ARM_CORTEX_M3) +#error "SCNSCB is only available on Cortex-M1" +#else +#error "No ARM Cortex-M architecture defined. Define one of: ARM_CORTEX_M0, ARM_CORTEX_M0PLUS, ARM_CORTEX_M1, ARM_CORTEX_M3" +#endif diff --git a/include/armcortex/special_regs.hpp b/include/armcortex/special_regs.hpp new file mode 100644 index 0000000..3907e9d --- /dev/null +++ b/include/armcortex/special_regs.hpp @@ -0,0 +1,32 @@ +/* + Copyright (C) 2025 Matej Gomboc + + Licensed under the Apache Licence, Version 2.0 (the "Licence"); + you may not use this file except in compliance with the Licence. + You may obtain a copy of the Licence at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the Licence is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the Licence for the specific language governing permissions and + limitations under the Licence. +*/ + +#pragma once + +// Forwarding header for flat include interface +// Selects architecture-specific implementation based on compile definitions + +#if defined(ARM_CORTEX_M0) +#include "../../m0/special_regs.hpp" +#elif defined(ARM_CORTEX_M0PLUS) +#include "../../m0plus/special_regs.hpp" +#elif defined(ARM_CORTEX_M1) +#include "../../m1/special_regs.hpp" +#elif defined(ARM_CORTEX_M3) +#include "../../m3/special_regs.hpp" +#else +#error "No ARM Cortex-M architecture defined. Define one of: ARM_CORTEX_M0, ARM_CORTEX_M0PLUS, ARM_CORTEX_M1, ARM_CORTEX_M3" +#endif diff --git a/include/armcortex/systick.hpp b/include/armcortex/systick.hpp new file mode 100644 index 0000000..e1f0a46 --- /dev/null +++ b/include/armcortex/systick.hpp @@ -0,0 +1,32 @@ +/* + Copyright (C) 2025 Matej Gomboc + + Licensed under the Apache Licence, Version 2.0 (the "Licence"); + you may not use this file except in compliance with the Licence. + You may obtain a copy of the Licence at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the Licence is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the Licence for the specific language governing permissions and + limitations under the Licence. +*/ + +#pragma once + +// Forwarding header for flat include interface +// Selects architecture-specific implementation based on compile definitions + +#if defined(ARM_CORTEX_M0) +#include "../../m0/systick.hpp" +#elif defined(ARM_CORTEX_M0PLUS) +#include "../../m0plus/systick.hpp" +#elif defined(ARM_CORTEX_M1) +#include "../../m1/systick.hpp" +#elif defined(ARM_CORTEX_M3) +#include "../../m3/systick.hpp" +#else +#error "No ARM Cortex-M architecture defined. Define one of: ARM_CORTEX_M0, ARM_CORTEX_M0PLUS, ARM_CORTEX_M1, ARM_CORTEX_M3" +#endif From af96934af65e28c86c193db3d72a6f498d4f782f Mon Sep 17 00:00:00 2001 From: MatejGomboc-Claude-MCP <201144475+MatejGomboc-Claude-MCP@users.noreply.github.com> Date: Sun, 30 Nov 2025 17:09:27 +0100 Subject: [PATCH 2/8] feat: update CMakeLists.txt to expose flat include interface 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. --- CMakeLists.txt | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 77dbc29..0438483 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,6 +47,12 @@ add_library(${PROJECT_NAME} INTERFACE) target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_20) +# Primary include directory for flat "armcortex/..." includes +target_include_directories(${PROJECT_NAME} INTERFACE + "${CMAKE_CURRENT_SOURCE_DIR}/include" +) + +# Legacy include directories (for internal header resolution) target_include_directories(${PROJECT_NAME} INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}" ) @@ -55,6 +61,28 @@ target_include_directories(${PROJECT_NAME} INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/intrinsics/common" ) +# Forwarding headers for flat include interface (IDE visibility) +target_sources(${PROJECT_NAME} INTERFACE + "${CMAKE_CURRENT_SOURCE_DIR}/include/armcortex/barriers.hpp" + "${CMAKE_CURRENT_SOURCE_DIR}/include/armcortex/bit_operations.hpp" + "${CMAKE_CURRENT_SOURCE_DIR}/include/armcortex/bit_utils.hpp" + "${CMAKE_CURRENT_SOURCE_DIR}/include/armcortex/byte_reversing.hpp" + "${CMAKE_CURRENT_SOURCE_DIR}/include/armcortex/debugging.hpp" + "${CMAKE_CURRENT_SOURCE_DIR}/include/armcortex/exceptions.hpp" + "${CMAKE_CURRENT_SOURCE_DIR}/include/armcortex/exclusive_access.hpp" + "${CMAKE_CURRENT_SOURCE_DIR}/include/armcortex/hints.hpp" + "${CMAKE_CURRENT_SOURCE_DIR}/include/armcortex/intrinsics.hpp" + "${CMAKE_CURRENT_SOURCE_DIR}/include/armcortex/mpu.hpp" + "${CMAKE_CURRENT_SOURCE_DIR}/include/armcortex/nvic.hpp" + "${CMAKE_CURRENT_SOURCE_DIR}/include/armcortex/power_management.hpp" + "${CMAKE_CURRENT_SOURCE_DIR}/include/armcortex/saturation.hpp" + "${CMAKE_CURRENT_SOURCE_DIR}/include/armcortex/scb.hpp" + "${CMAKE_CURRENT_SOURCE_DIR}/include/armcortex/scnscb.hpp" + "${CMAKE_CURRENT_SOURCE_DIR}/include/armcortex/special_regs.hpp" + "${CMAKE_CURRENT_SOURCE_DIR}/include/armcortex/systick.hpp" +) + +# Common implementation sources target_sources(${PROJECT_NAME} INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/bit_utils.hpp" "${CMAKE_CURRENT_SOURCE_DIR}/intrinsics/common/barriers.hpp" @@ -95,6 +123,7 @@ elseif(ARM_CORTEX_M_ARCH STREQUAL "M1") "${CMAKE_CURRENT_SOURCE_DIR}/m1/exceptions.hpp" "${CMAKE_CURRENT_SOURCE_DIR}/m1/nvic.hpp" "${CMAKE_CURRENT_SOURCE_DIR}/m1/scb.hpp" + "${CMAKE_CURRENT_SOURCE_DIR}/m1/scnscb.hpp" "${CMAKE_CURRENT_SOURCE_DIR}/m1/special_regs.hpp" "${CMAKE_CURRENT_SOURCE_DIR}/m1/systick.hpp" ) From e58d79c20704b51def060a65c3321546b73d1daf Mon Sep 17 00:00:00 2001 From: MatejGomboc-Claude-MCP <201144475+MatejGomboc-Claude-MCP@users.noreply.github.com> Date: Sun, 30 Nov 2025 17:13:28 +0100 Subject: [PATCH 3/8] refactor: remove legacy include directories 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 --- CMakeLists.txt | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0438483..dda0eff 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,20 +47,11 @@ add_library(${PROJECT_NAME} INTERFACE) target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_20) -# Primary include directory for flat "armcortex/..." includes +# Include directory for flat "armcortex/..." includes target_include_directories(${PROJECT_NAME} INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include" ) -# Legacy include directories (for internal header resolution) -target_include_directories(${PROJECT_NAME} INTERFACE - "${CMAKE_CURRENT_SOURCE_DIR}" -) - -target_include_directories(${PROJECT_NAME} INTERFACE - "${CMAKE_CURRENT_SOURCE_DIR}/intrinsics/common" -) - # Forwarding headers for flat include interface (IDE visibility) target_sources(${PROJECT_NAME} INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include/armcortex/barriers.hpp" @@ -82,7 +73,7 @@ target_sources(${PROJECT_NAME} INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include/armcortex/systick.hpp" ) -# Common implementation sources +# Implementation sources (IDE visibility) target_sources(${PROJECT_NAME} INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/bit_utils.hpp" "${CMAKE_CURRENT_SOURCE_DIR}/intrinsics/common/barriers.hpp" @@ -132,9 +123,6 @@ elseif(ARM_CORTEX_M_ARCH STREQUAL "M1") target_link_options(${PROJECT_NAME} INTERFACE -mcpu=cortex-m1) elseif(ARM_CORTEX_M_ARCH STREQUAL "M3") - target_include_directories(${PROJECT_NAME} INTERFACE - "${CMAKE_CURRENT_SOURCE_DIR}/intrinsics/armv7m" - ) target_sources(${PROJECT_NAME} INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/intrinsics/armv7m/bit_operations.hpp" "${CMAKE_CURRENT_SOURCE_DIR}/intrinsics/armv7m/exclusive_access.hpp" From 5d014792e92ef5ce6948c6299d9c9ba1edb87c2e Mon Sep 17 00:00:00 2001 From: MatejGomboc-Claude-MCP <201144475+MatejGomboc-Claude-MCP@users.noreply.github.com> Date: Sun, 30 Nov 2025 17:17:41 +0100 Subject: [PATCH 4/8] fix: update internal includes to use relative paths 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. --- m0/scb.hpp | 2 +- m0/special_regs.hpp | 2 +- m0plus/mpu.hpp | 2 +- m0plus/scb.hpp | 21 +++++++++++++++++++-- m0plus/special_regs.hpp | 8 +------- m1/scb.hpp | 2 +- m1/special_regs.hpp | 2 +- tests/intrinsics/common/test_barriers.cpp | 2 +- 8 files changed, 26 insertions(+), 15 deletions(-) diff --git a/m0/scb.hpp b/m0/scb.hpp index cb353f0..3a43e80 100644 --- a/m0/scb.hpp +++ b/m0/scb.hpp @@ -16,7 +16,7 @@ #pragma once -#include "barriers.hpp" +#include "../intrinsics/common/barriers.hpp" #include namespace ArmCortex::Scb { diff --git a/m0/special_regs.hpp b/m0/special_regs.hpp index f9afff1..4c80208 100644 --- a/m0/special_regs.hpp +++ b/m0/special_regs.hpp @@ -16,7 +16,7 @@ #pragma once -#include "barriers.hpp" +#include "../intrinsics/common/barriers.hpp" #include namespace ArmCortex { diff --git a/m0plus/mpu.hpp b/m0plus/mpu.hpp index 85551a8..e5c941e 100644 --- a/m0plus/mpu.hpp +++ b/m0plus/mpu.hpp @@ -16,7 +16,7 @@ #pragma once -#include "barriers.hpp" +#include "../intrinsics/common/barriers.hpp" #include namespace ArmCortex::Mpu { diff --git a/m0plus/scb.hpp b/m0plus/scb.hpp index ae7eb5b..b44da8b 100644 --- a/m0plus/scb.hpp +++ b/m0plus/scb.hpp @@ -16,7 +16,7 @@ #pragma once -#include "barriers.hpp" +#include "../intrinsics/common/barriers.hpp" #include namespace ArmCortex::Scb { @@ -30,7 +30,7 @@ namespace ArmCortex::Scb { volatile uint32_t AIRCR; //!< Application interrupt and reset control register. volatile uint32_t SCR; //!< Low power state control. volatile uint32_t CCR; //!< Configuration and control register (read-only). - volatile uint32_t RESERVED1; + volatile uint32_t RESERVED0; volatile uint32_t SHPR2; //!< System handler priority register (SVCall). volatile uint32_t SHPR3; //!< System handler priority register (PendSV, SysTick). volatile uint32_t SHCSR; //!< System handler control and state register. @@ -87,6 +87,23 @@ namespace ArmCortex::Scb { } }; + //! Vector table offset register. + union VTOR { + struct Bits { + uint32_t RESERVED: 8; + uint32_t TBLOFF: 24; //!< Vector table base offset field. + } bits; + + uint32_t value = 0; + + VTOR() = default; + + VTOR(uint32_t new_value) + { + value = new_value; + } + }; + //! Application interrupt and reset control register. union AIRCR { static constexpr uint16_t VECTKEY_VALUE = 0x05FA; //!< Write key to enable AIRCR writes. diff --git a/m0plus/special_regs.hpp b/m0plus/special_regs.hpp index 48d42d6..e3833fb 100644 --- a/m0plus/special_regs.hpp +++ b/m0plus/special_regs.hpp @@ -16,7 +16,7 @@ #pragma once -#include "barriers.hpp" +#include "../intrinsics/common/barriers.hpp" #include namespace ArmCortex { @@ -66,12 +66,6 @@ namespace ArmCortex { }; union CONTROL { - //! Thread mode privilege level. - enum class nPRIV : bool { - PRIVILEGED = false, //!< Privileged thread mode. - UNPRIVILEGED = true //!< Unprivileged thread mode. - }; - //! Active stack pointer selection. enum class SPSEL : bool { MSP = false, //!< Main stack pointer. diff --git a/m1/scb.hpp b/m1/scb.hpp index 141e149..1eb2af4 100644 --- a/m1/scb.hpp +++ b/m1/scb.hpp @@ -16,7 +16,7 @@ #pragma once -#include "barriers.hpp" +#include "../intrinsics/common/barriers.hpp" #include namespace ArmCortex::Scb { diff --git a/m1/special_regs.hpp b/m1/special_regs.hpp index f9afff1..4c80208 100644 --- a/m1/special_regs.hpp +++ b/m1/special_regs.hpp @@ -16,7 +16,7 @@ #pragma once -#include "barriers.hpp" +#include "../intrinsics/common/barriers.hpp" #include namespace ArmCortex { diff --git a/tests/intrinsics/common/test_barriers.cpp b/tests/intrinsics/common/test_barriers.cpp index 01004fe..4728019 100644 --- a/tests/intrinsics/common/test_barriers.cpp +++ b/tests/intrinsics/common/test_barriers.cpp @@ -1,4 +1,4 @@ -#include "barriers.hpp" +#include "armcortex/barriers.hpp" extern "C" [[gnu::naked]] void test_dsb() { ArmCortex::asmDsb(); From 7ce4bd0f4f202e5075a372ea7badc2c29992da1e Mon Sep 17 00:00:00 2001 From: MatejGomboc-Claude-MCP <201144475+MatejGomboc-Claude-MCP@users.noreply.github.com> Date: Sun, 30 Nov 2025 17:20:54 +0100 Subject: [PATCH 5/8] fix: update m3/mpu.hpp to use relative include path --- m3/mpu.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/m3/mpu.hpp b/m3/mpu.hpp index b6cf3ab..4bfd35c 100644 --- a/m3/mpu.hpp +++ b/m3/mpu.hpp @@ -16,7 +16,7 @@ #pragma once -#include "barriers.hpp" +#include "../intrinsics/common/barriers.hpp" #include namespace ArmCortex::Mpu { From 9db369b4a490335d3e666e7340518b70fad8ed29 Mon Sep 17 00:00:00 2001 From: MatejGomboc-Claude-MCP <201144475+MatejGomboc-Claude-MCP@users.noreply.github.com> Date: Sun, 30 Nov 2025 17:24:27 +0100 Subject: [PATCH 6/8] fix: update M3 internal includes to use relative paths Changed M3 implementation files to use relative paths: - #include "barriers.hpp" -> #include "../intrinsics/common/barriers.hpp" --- m3/scb.hpp | 2 +- m3/special_regs.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/m3/scb.hpp b/m3/scb.hpp index 2d57710..ff31385 100644 --- a/m3/scb.hpp +++ b/m3/scb.hpp @@ -16,7 +16,7 @@ #pragma once -#include "barriers.hpp" +#include "../intrinsics/common/barriers.hpp" #include namespace ArmCortex::Scb { diff --git a/m3/special_regs.hpp b/m3/special_regs.hpp index 5d8bf1e..6768387 100644 --- a/m3/special_regs.hpp +++ b/m3/special_regs.hpp @@ -16,7 +16,7 @@ #pragma once -#include "barriers.hpp" +#include "../intrinsics/common/barriers.hpp" #include namespace ArmCortex { From 8a59f98be47a2c0ee6c2a40b2fb8d0747660e052 Mon Sep 17 00:00:00 2001 From: MatejGomboc-Claude-MCP <201144475+MatejGomboc-Claude-MCP@users.noreply.github.com> Date: Sun, 30 Nov 2025 17:42:23 +0100 Subject: [PATCH 7/8] fix: update tests to use organized directory paths - 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/CMakeLists.txt | 8 ++++++++ tests/intrinsics/armv7m/test_bit_operations.cpp | 2 +- tests/intrinsics/common/test_barriers.cpp | 2 +- tests/intrinsics/common/test_byte_reversing.cpp | 2 +- tests/intrinsics/common/test_debugging.cpp | 2 +- tests/intrinsics/common/test_hints.cpp | 2 +- tests/intrinsics/common/test_power_management.cpp | 2 +- 7 files changed, 14 insertions(+), 6 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 24d8649..216ef24 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -26,6 +26,9 @@ endif() set(CMAKE_EXPORT_COMPILE_COMMANDS ON) +# Add source root as include directory for tests (organized directory structure) +set(ARMCORTEXM_SOURCE_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/..") + function(add_asm_test TEST_NAME) add_library(${TEST_NAME} STATIC ${TEST_NAME}.cpp @@ -35,6 +38,11 @@ function(add_asm_test TEST_NAME) ARMCortexM ) + # Tests use organized directory paths, not flat interface + target_include_directories(${TEST_NAME} PRIVATE + "${ARMCORTEXM_SOURCE_ROOT}" + ) + add_custom_target(${TEST_NAME}_asm ALL WORKING_DIRECTORY "$" diff --git a/tests/intrinsics/armv7m/test_bit_operations.cpp b/tests/intrinsics/armv7m/test_bit_operations.cpp index 5f69482..545b332 100644 --- a/tests/intrinsics/armv7m/test_bit_operations.cpp +++ b/tests/intrinsics/armv7m/test_bit_operations.cpp @@ -1,4 +1,4 @@ -#include "bit_operations.hpp" +#include "intrinsics/armv7m/bit_operations.hpp" extern "C" [[gnu::naked]] uint32_t test_clz(uint32_t value) { return ArmCortex::asmClz(value); diff --git a/tests/intrinsics/common/test_barriers.cpp b/tests/intrinsics/common/test_barriers.cpp index 4728019..eb58267 100644 --- a/tests/intrinsics/common/test_barriers.cpp +++ b/tests/intrinsics/common/test_barriers.cpp @@ -1,4 +1,4 @@ -#include "armcortex/barriers.hpp" +#include "intrinsics/common/barriers.hpp" extern "C" [[gnu::naked]] void test_dsb() { ArmCortex::asmDsb(); diff --git a/tests/intrinsics/common/test_byte_reversing.cpp b/tests/intrinsics/common/test_byte_reversing.cpp index 4959646..4262f57 100644 --- a/tests/intrinsics/common/test_byte_reversing.cpp +++ b/tests/intrinsics/common/test_byte_reversing.cpp @@ -1,4 +1,4 @@ -#include "byte_reversing.hpp" +#include "intrinsics/common/byte_reversing.hpp" extern "C" [[gnu::naked]] uint32_t test_rev(uint32_t value) { return ArmCortex::asmRev(value); diff --git a/tests/intrinsics/common/test_debugging.cpp b/tests/intrinsics/common/test_debugging.cpp index 9498f9d..b03cf83 100644 --- a/tests/intrinsics/common/test_debugging.cpp +++ b/tests/intrinsics/common/test_debugging.cpp @@ -1,4 +1,4 @@ -#include "debugging.hpp" +#include "intrinsics/common/debugging.hpp" extern "C" [[gnu::naked]] void test_bkpt_0() { ArmCortex::asmBkpt<0>(); diff --git a/tests/intrinsics/common/test_hints.cpp b/tests/intrinsics/common/test_hints.cpp index 28a8bd5..40b4eb3 100644 --- a/tests/intrinsics/common/test_hints.cpp +++ b/tests/intrinsics/common/test_hints.cpp @@ -1,4 +1,4 @@ -#include "hints.hpp" +#include "intrinsics/common/hints.hpp" extern "C" [[gnu::naked]] void test_nop() { ArmCortex::asmNop(); diff --git a/tests/intrinsics/common/test_power_management.cpp b/tests/intrinsics/common/test_power_management.cpp index 73f1dce..4a2d90e 100644 --- a/tests/intrinsics/common/test_power_management.cpp +++ b/tests/intrinsics/common/test_power_management.cpp @@ -1,4 +1,4 @@ -#include "power_management.hpp" +#include "intrinsics/common/power_management.hpp" extern "C" [[gnu::naked]] void test_sev() { ArmCortex::asmSev(); From de1ea330dead8773c8561f0b7ee921c20e1c7fe7 Mon Sep 17 00:00:00 2001 From: MatejGomboc-Claude-MCP <201144475+MatejGomboc-Claude-MCP@users.noreply.github.com> Date: Sun, 30 Nov 2025 17:44:00 +0100 Subject: [PATCH 8/8] fix: update remaining test files to use organized directory paths - tests/intrinsics/common/test_exceptions.cpp - tests/intrinsics/armv7m/test_exclusive_access.cpp - tests/intrinsics/armv7m/test_saturation.cpp --- tests/intrinsics/armv7m/test_exclusive_access.cpp | 2 +- tests/intrinsics/armv7m/test_saturation.cpp | 2 +- tests/intrinsics/common/test_exceptions.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/intrinsics/armv7m/test_exclusive_access.cpp b/tests/intrinsics/armv7m/test_exclusive_access.cpp index f662578..a5aff4e 100644 --- a/tests/intrinsics/armv7m/test_exclusive_access.cpp +++ b/tests/intrinsics/armv7m/test_exclusive_access.cpp @@ -1,4 +1,4 @@ -#include "exclusive_access.hpp" +#include "intrinsics/armv7m/exclusive_access.hpp" extern "C" [[gnu::naked]] uint32_t test_ldrex(volatile uint32_t* addr) { return ArmCortex::asmLdrex(addr); diff --git a/tests/intrinsics/armv7m/test_saturation.cpp b/tests/intrinsics/armv7m/test_saturation.cpp index 8af444b..4a1caad 100644 --- a/tests/intrinsics/armv7m/test_saturation.cpp +++ b/tests/intrinsics/armv7m/test_saturation.cpp @@ -1,4 +1,4 @@ -#include "saturation.hpp" +#include "intrinsics/armv7m/saturation.hpp" extern "C" [[gnu::naked]] int32_t test_ssat_8(int32_t value) { return ArmCortex::asmSsat<8>(value); diff --git a/tests/intrinsics/common/test_exceptions.cpp b/tests/intrinsics/common/test_exceptions.cpp index ab42f0b..fec8f8c 100644 --- a/tests/intrinsics/common/test_exceptions.cpp +++ b/tests/intrinsics/common/test_exceptions.cpp @@ -1,4 +1,4 @@ -#include "exceptions.hpp" +#include "intrinsics/common/exceptions.hpp" extern "C" [[gnu::naked]] void test_cpsie() { ArmCortex::asmCpsie();