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_GetEnableIRQ(IRQn_Type IRQn)38 uint32_t NVIC_GetEnableIRQ(IRQn_Type IRQn)
39 {
40 	return hw_irq_ctrl_is_irq_enabled(CONFIG_NATIVE_SIMULATOR_MCU_N, IRQn);
41 }
42 
NVIC_SetPriority(IRQn_Type IRQn,uint32_t priority)43 void NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority)
44 {
45 	hw_irq_ctrl_prio_set(CONFIG_NATIVE_SIMULATOR_MCU_N, IRQn, priority);
46 }
47 
NVIC_GetPriority(IRQn_Type IRQn)48 uint32_t NVIC_GetPriority(IRQn_Type IRQn)
49 {
50 	return hw_irq_ctrl_get_prio(CONFIG_NATIVE_SIMULATOR_MCU_N, IRQn);
51 }
52 
NVIC_SystemReset(void)53 void NVIC_SystemReset(void)
54 {
55 	bs_trace_error_time_line("%s called. Exiting\n", __func__);
56 }
57 
58 /*
59  * Replacements for some other CMSIS functions
60  */
__enable_irq(void)61 void __enable_irq(void)
62 {
63 	hw_irq_ctrl_change_lock(CONFIG_NATIVE_SIMULATOR_MCU_N, false);
64 }
65 
__disable_irq(void)66 void __disable_irq(void)
67 {
68 	hw_irq_ctrl_change_lock(CONFIG_NATIVE_SIMULATOR_MCU_N, true);
69 }
70 
__get_PRIMASK(void)71 uint32_t __get_PRIMASK(void)
72 {
73 	return hw_irq_ctrl_get_current_lock(CONFIG_NATIVE_SIMULATOR_MCU_N);
74 }
75 
__set_PRIMASK(uint32_t primask)76 void __set_PRIMASK(uint32_t primask)
77 {
78 	hw_irq_ctrl_change_lock(CONFIG_NATIVE_SIMULATOR_MCU_N, primask != 0);
79 }
80 
__WFE(void)81 void __WFE(void)
82 {
83 	nrfbsim_WFE_model();
84 }
85 
__WFI(void)86 void __WFI(void)
87 {
88 	__WFE();
89 }
90 
__SEV(void)91 void __SEV(void)
92 {
93 	nrfbsim_SEV_model();
94 }
95