Skip to content

Commit 1df36d5

Browse files
committed
arch: arm: cortex_m: Add include scb.h for scb.c
Add header file to export functions implemented in scb.c file. Signed-off-by: Michele Sardo <[email protected]>
1 parent 906f771 commit 1df36d5

File tree

1 file changed

+87
-0
lines changed
  • arch/arm/include/cortex_m

1 file changed

+87
-0
lines changed

arch/arm/include/cortex_m/scb.h

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* Copyright (c) 2020 STMicroelectronics
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/**
8+
* @file
9+
* @brief Exception/interrupt context helpers for Cortex-M CPUs
10+
*
11+
* Exception/interrupt context helpers.
12+
*/
13+
14+
#ifndef ARM_CORTEX_M_SCB_H_
15+
#define ARM_CORTEX_M_SCB_H_
16+
17+
#include <stdint.h>
18+
#include <cmsis_core.h>
19+
20+
/* Define macro for SHCSR presence, as it's not directly a Kconfig option.
21+
SHCSR is present in ARMv7-M (M3, M4, M7) and ARMv8-M (M23, M33) architectures. */
22+
#if defined(CONFIG_CPU_CORTEX_M3) || \
23+
defined(CONFIG_CPU_CORTEX_M4) || \
24+
defined(CONFIG_CPU_CORTEX_M7) || \
25+
defined(CONFIG_CPU_CORTEX_M23) || \
26+
defined(CONFIG_CPU_CORTEX_M33)
27+
#define CONFIG_CPU_CORTEX_M_HAS_SHCSR 1
28+
#endif
29+
30+
/**
31+
* @brief Structure to store essential, mutable SCB register values for backup/restore.
32+
*
33+
* This structure explicitly lists the SCB registers that are safe and meaningful
34+
* to backup and restore for common system state management. It avoids volatile,
35+
* read-only, or write-only status bits that should not be directly restored.
36+
*/
37+
typedef struct {
38+
#if defined(CONFIG_CPU_CORTEX_M_HAS_VTOR)
39+
uint32_t vtor; /*/< Vector Table Offset Register */
40+
#endif
41+
uint32_t aircr; /*/< Application Interrupt and Reset Control Register
42+
* (only modifiable bits)
43+
*/
44+
uint32_t scr; /*/< System Control Register */
45+
uint32_t ccr; /*/< Configuration Control Register */
46+
uint32_t shpr[4]; /*/< System Handler Priority Registers (SHPR1-SHPR4) */
47+
#if defined(CONFIG_CPU_CORTEX_M_HAS_SHCSR)
48+
uint32_t shcsr; /*/< System Handler Control and State Register */
49+
#endif
50+
} scb_context_t;
51+
52+
/**
53+
* @name SCB Register Backup/Restore Functions
54+
* @brief Functions for saving and restoring mutable SCB register state.
55+
* @{
56+
*/
57+
58+
/**
59+
* @brief Backs up essential SCB registers into a provided context structure.
60+
*
61+
* This function reads the current values of critical System Control Block (SCB)
62+
* registers that are safe to backup and stores them into the `context` structure.
63+
*
64+
* @param context Pointer to an `scb_context_t` structure where the register
65+
* values will be stored. Must not be NULL.
66+
*/
67+
void scb_backup_registers(scb_context_t *context);
68+
69+
/**
70+
* @brief Restores essential SCB registers from a provided context structure.
71+
*
72+
* This function writes the values from the `context` structure back to the
73+
* respective System Control Block (SCB) registers.
74+
*
75+
* @warning Extreme caution is advised when restoring SCB registers. Only
76+
* mutable registers are restored. Specifically, the ICSR register
77+
* is NOT restored directly due to its volatile nature and read-only/
78+
* write-only bits.
79+
*
80+
* @param context Pointer to a `scb_context_t` structure containing the
81+
* register values to be restored. Must not be NULL.
82+
*/
83+
void scb_restore_registers(const scb_context_t *context);
84+
85+
/** @} */
86+
87+
#endif /* ARM_CORTEX_M_SCB_H_ */

0 commit comments

Comments
 (0)