1 /*
2  * Copyright (c) 2020 Nordic Semiconductor ASA
3  * Copyright (c) 2020 Oticon A/S
4  *
5  * SPDX-License-Identifier: Apache-2.0
6  */
7 
8 #include <stdint.h>
9 #include "irq_ctrl.h"
10 #include "posix_core.h"
11 #include "posix_board_if.h"
12 #include "board_soc.h"
13 #include "bs_tracing.h"
14 
15 /*
16  *  Replacement for ARMs NVIC functions()
17  */
NVIC_SetPendingIRQ(IRQn_Type IRQn)18 void NVIC_SetPendingIRQ(IRQn_Type IRQn)
19 {
20 	hw_irq_ctrl_raise_im_from_sw(CONFIG_NATIVE_SIMULATOR_MCU_N, IRQn);
21 }
22 
NVIC_ClearPendingIRQ(IRQn_Type IRQn)23 void NVIC_ClearPendingIRQ(IRQn_Type IRQn)
24 {
25 	hw_irq_ctrl_clear_irq(CONFIG_NATIVE_SIMULATOR_MCU_N, IRQn);
26 }
27 
NVIC_DisableIRQ(IRQn_Type IRQn)28 void NVIC_DisableIRQ(IRQn_Type IRQn)
29 {
30 	hw_irq_ctrl_disable_irq(CONFIG_NATIVE_SIMULATOR_MCU_N, IRQn);
31 }
32 
NVIC_EnableIRQ(IRQn_Type IRQn)33 void NVIC_EnableIRQ(IRQn_Type IRQn)
34 {
35 	hw_irq_ctrl_enable_irq(CONFIG_NATIVE_SIMULATOR_MCU_N, IRQn);
36 }
37 
NVIC_SetPriority(IRQn_Type IRQn,uint32_t priority)38 void NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority)
39 {
40 	hw_irq_ctrl_prio_set(CONFIG_NATIVE_SIMULATOR_MCU_N, IRQn, priority);
41 }
42 
NVIC_GetPriority(IRQn_Type IRQn)43 uint32_t NVIC_GetPriority(IRQn_Type IRQn)
44 {
45 	return hw_irq_ctrl_get_prio(CONFIG_NATIVE_SIMULATOR_MCU_N, IRQn);
46 }
47 
NVIC_SystemReset(void)48 void NVIC_SystemReset(void)
49 {
50 	bs_trace_error_time_line("%s called. Exiting\n", __func__);
51 }
52 
53 /*
54  * Replacements for some other CMSIS functions
55  */
__enable_irq(void)56 void __enable_irq(void)
57 {
58 	hw_irq_ctrl_change_lock(CONFIG_NATIVE_SIMULATOR_MCU_N, false);
59 }
60 
__disable_irq(void)61 void __disable_irq(void)
62 {
63 	hw_irq_ctrl_change_lock(CONFIG_NATIVE_SIMULATOR_MCU_N, true);
64 }
65 
__get_PRIMASK(void)66 uint32_t __get_PRIMASK(void)
67 {
68 	return hw_irq_ctrl_get_current_lock(CONFIG_NATIVE_SIMULATOR_MCU_N);
69 }
70 
__set_PRIMASK(uint32_t primask)71 void __set_PRIMASK(uint32_t primask)
72 {
73 	hw_irq_ctrl_change_lock(CONFIG_NATIVE_SIMULATOR_MCU_N, primask != 0);
74 }
75 
__WFE(void)76 void __WFE(void)
77 {
78 	nrfbsim_WFE_model();
79 }
80 
__WFI(void)81 void __WFI(void)
82 {
83 	__WFE();
84 }
85 
__SEV(void)86 void __SEV(void)
87 {
88 	nrfbsim_SEV_model();
89 }
90