1
1
/*
2
2
* Copyright (c) 2020 Nordic Semiconductor ASA
3
+ * Copyright (c) 2025 Siemens Mobility GmbH
3
4
*
4
5
* SPDX-License-Identifier: Apache-2.0
5
6
*/
6
7
8
+ #include <stdint.h>
9
+ #include <zephyr/irq.h>
10
+ #include "zephyr/sys/util_macro.h"
7
11
#include <zephyr/toolchain.h>
8
12
13
+ #ifdef CONFIG_CPU_CORTEX_M
9
14
#include <cmsis_core.h>
15
+ #endif
10
16
#if CONFIG_CPU_HAS_NXP_MPU
11
17
#include <fsl_sysmpu.h>
12
18
#endif
13
19
14
- void cleanup_arm_nvic (void ) {
20
+ #ifndef CONFIG_CPU_CORTEX_M
21
+
22
+ #ifdef CONFIG_ARM_CUSTOM_INTERRUPT_CONTROLLER
23
+ extern void z_soc_irq_eoi (unsigned int irq );
24
+ #else
25
+ #include <zephyr/drivers/interrupt_controller/gic.h>
26
+ #endif
27
+
28
+ #endif /* CONFIG_CPU_CORTEX_M */
29
+
30
+ /* Macros for inline assembly to improve readability */
31
+ #ifdef CONFIG_CPU_CORTEX_R5
32
+
33
+ #define READ_COPROCESSOR_REGISTER (out , coproc , opc1 , crn , crm , opc2 ) \
34
+ __asm__ volatile("mrc " #coproc ", " #opc1 ", %0, " #crn ", " #crm ", " #opc2 "\n" : "=r" (out) ::);
35
+
36
+ #define WRITE_COPROCESSOR_REGISTER (in , coproc , opc1 , crn , crm , opc2 ) \
37
+ __asm__ volatile("mcr " #coproc ", " #opc1 ", %0, " #crn ", " #crm ", " #opc2 "\n" :: "r" (in) :)
38
+
39
+ #endif /* CONFIG_CPU_CORTEX_R5 */
40
+
41
+ void cleanup_arm_interrupts (void ) {
15
42
/* Allow any pending interrupts to be recognized */
16
43
__ISB ();
17
44
__disable_irq ();
18
45
46
+ #ifdef CONFIG_CPU_CORTEX_M
19
47
/* Disable NVIC interrupts */
20
48
for (uint8_t i = 0 ; i < ARRAY_SIZE (NVIC -> ICER ); i ++ ) {
21
49
NVIC -> ICER [i ] = 0xFFFFFFFF ;
@@ -24,11 +52,27 @@ void cleanup_arm_nvic(void) {
24
52
for (uint8_t i = 0 ; i < ARRAY_SIZE (NVIC -> ICPR ); i ++ ) {
25
53
NVIC -> ICPR [i ] = 0xFFFFFFFF ;
26
54
}
55
+ #else
56
+
57
+ for (unsigned int i = 0 ; i < CONFIG_NUM_IRQS ; ++ i ) {
58
+ irq_disable (i );
59
+ }
60
+
61
+ for (unsigned int i = 0 ; i < CONFIG_NUM_IRQS ; ++ i ) {
62
+ #ifdef CONFIG_ARM_CUSTOM_INTERRUPT_CONTROLLER
63
+ z_soc_irq_eoi (i );
64
+ #else
65
+ arm_gic_eoi (i );
66
+ #endif /* CONFIG_ARM_CUSTOM_INTERRUPT_CONTROLLER */
67
+ }
68
+
69
+ #endif /* CONFIG_CPU_CORTEX_M */
27
70
}
28
71
29
72
#if CONFIG_CPU_HAS_ARM_MPU
30
73
__weak void z_arm_clear_arm_mpu_config (void )
31
74
{
75
+ #ifdef CONFIG_CPU_CORTEX_M
32
76
int i ;
33
77
34
78
int num_regions =
@@ -37,6 +81,30 @@ __weak void z_arm_clear_arm_mpu_config(void)
37
81
for (i = 0 ; i < num_regions ; i ++ ) {
38
82
ARM_MPU_ClrRegion (i );
39
83
}
84
+ #else
85
+ uint8_t i ;
86
+ uint8_t num_regions ;
87
+ uint32_t mpu_type_register ;
88
+
89
+ /* Disable MPU */
90
+ uint32_t val ;
91
+ READ_COPROCESSOR_REGISTER (val , p15 , 0 , c1 , c0 , 0 );
92
+ val &= ~BIT (0 );
93
+ __DSB ();
94
+
95
+ WRITE_COPROCESSOR_REGISTER (val , p15 , 0 , c1 , c0 , 0 );
96
+ __ISB ();
97
+
98
+ /* The number of MPU regions is stored in bits 15:8 of the MPU type register */
99
+ READ_COPROCESSOR_REGISTER (mpu_type_register , p15 , 0 , c0 , c0 , 4 );
100
+ num_regions = (uint8_t ) ((mpu_type_register >> 8 ) & BIT_MASK (8 ));
101
+
102
+ for (i = 0 ; i < num_regions ; ++ i ) {
103
+ /* Select region in the MPU and clear the region size field */
104
+ WRITE_COPROCESSOR_REGISTER (i , p15 , 0 , c6 , c2 , 0 );
105
+ WRITE_COPROCESSOR_REGISTER (0 , p15 , 0 , c6 , c1 , 2 );
106
+ }
107
+ #endif /* CONFIG_CPU_CORTEX_M */
40
108
}
41
109
#elif CONFIG_CPU_HAS_NXP_MPU
42
110
__weak void z_arm_clear_arm_mpu_config (void )
0 commit comments