Skip to content

Commit f56c70c

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 6c03a83 commit f56c70c

File tree

1 file changed

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

1 file changed

+86
-0
lines changed

arch/arm/include/cortex_m/scb.h

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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+
uint32_t scr; /*/< System Control Register */
44+
uint32_t ccr; /*/< Configuration Control Register */
45+
uint32_t shpr[4]; /*/< System Handler Priority Registers (SHPR1-SHPR4) */
46+
#if defined(CONFIG_CPU_CORTEX_M_HAS_SHCSR)
47+
uint32_t shcsr; /*/< System Handler Control and State Register */
48+
#endif
49+
} scb_context_t;
50+
51+
/**
52+
* @name SCB Register Backup/Restore Functions
53+
* @brief Functions for saving and restoring mutable SCB register state.
54+
* @{
55+
*/
56+
57+
/**
58+
* @brief Backs up essential SCB registers into a provided context structure.
59+
*
60+
* This function reads the current values of critical System Control Block (SCB)
61+
* registers that are safe to backup and stores them into the `context` structure.
62+
*
63+
* @param context Pointer to an `scb_context_t` structure where the register
64+
* values will be stored. Must not be NULL.
65+
*/
66+
void scb_backup_registers(scb_context_t *context);
67+
68+
/**
69+
* @brief Restores essential SCB registers from a provided context structure.
70+
*
71+
* This function writes the values from the `context` structure back to the
72+
* respective System Control Block (SCB) registers.
73+
*
74+
* @warning Extreme caution is advised when restoring SCB registers. Only
75+
* mutable registers are restored. Specifically, the ICSR register
76+
* is NOT restored directly due to its volatile nature and read-only/
77+
* write-only bits.
78+
*
79+
* @param context Pointer to a `scb_context_t` structure containing the
80+
* register values to be restored. Must not be NULL.
81+
*/
82+
void scb_restore_registers(const scb_context_t *context);
83+
84+
/** @} */
85+
86+
#endif // ARM_CORTEX_M_SCB_H_

0 commit comments

Comments
 (0)