forked from nrfconnect/sdk-mcuboot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
arm_cleanup.c
55 lines (45 loc) · 1.11 KB
/
arm_cleanup.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
* Copyright (c) 2020 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <arch/arm/aarch32/cortex_m/cmsis.h>
#include <toolchain.h>
#if CONFIG_CPU_HAS_NXP_MPU
#include <fsl_sysmpu.h>
#endif
void cleanup_arm_nvic(void) {
/* Allow any pending interrupts to be recognized */
__ISB();
__disable_irq();
/* Disable NVIC interrupts */
for (uint8_t i = 0; i < ARRAY_SIZE(NVIC->ICER); i++) {
NVIC->ICER[i] = 0xFFFFFFFF;
}
/* Clear pending NVIC interrupts */
for (uint8_t i = 0; i < ARRAY_SIZE(NVIC->ICPR); i++) {
NVIC->ICPR[i] = 0xFFFFFFFF;
}
}
#if CONFIG_CPU_HAS_ARM_MPU
__weak void z_arm_clear_arm_mpu_config(void)
{
int i;
int num_regions =
((MPU->TYPE & MPU_TYPE_DREGION_Msk) >> MPU_TYPE_DREGION_Pos);
for (i = 0; i < num_regions; i++) {
ARM_MPU_ClrRegion(i);
}
}
#elif CONFIG_CPU_HAS_NXP_MPU
__weak void z_arm_clear_arm_mpu_config(void)
{
int i;
int num_regions = FSL_FEATURE_SYSMPU_DESCRIPTOR_COUNT;
SYSMPU_Enable(SYSMPU, false);
/* NXP MPU region 0 is reserved for the debugger */
for (i = 1; i < num_regions; i++) {
SYSMPU_RegionEnable(SYSMPU, i, false);
}
}
#endif