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 
14 /*
15  *  Replacement for ARMs NVIC functions()
16  */
NVIC_SetPendingIRQ(IRQn_Type IRQn)17 void NVIC_SetPendingIRQ(IRQn_Type IRQn)
18 {
19 	hw_irq_ctrl_raise_im_from_sw(IRQn);
20 }
21 
NVIC_ClearPendingIRQ(IRQn_Type IRQn)22 void NVIC_ClearPendingIRQ(IRQn_Type IRQn)
23 {
24 	hw_irq_ctrl_clear_irq(IRQn);
25 }
26 
NVIC_DisableIRQ(IRQn_Type IRQn)27 void NVIC_DisableIRQ(IRQn_Type IRQn)
28 {
29 	hw_irq_ctrl_disable_irq(IRQn);
30 }
31 
NVIC_EnableIRQ(IRQn_Type IRQn)32 void NVIC_EnableIRQ(IRQn_Type IRQn)
33 {
34 	hw_irq_ctrl_enable_irq(IRQn);
35 }
36 
NVIC_SetPriority(IRQn_Type IRQn,uint32_t priority)37 void NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority)
38 {
39 	hw_irq_ctrl_prio_set(IRQn, priority);
40 }
41 
NVIC_GetPriority(IRQn_Type IRQn)42 uint32_t NVIC_GetPriority(IRQn_Type IRQn)
43 {
44 	return hw_irq_ctrl_get_prio(IRQn);
45 }
46 
NVIC_SystemReset(void)47 void NVIC_SystemReset(void)
48 {
49 	posix_print_warning("%s called. Exiting\n", __func__);
50 	posix_exit(1);
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(false);
59 }
60 
__disable_irq(void)61 void __disable_irq(void)
62 {
63 	hw_irq_ctrl_change_lock(true);
64 }
65 
__get_PRIMASK(void)66 uint32_t __get_PRIMASK(void)
67 {
68 	return hw_irq_ctrl_get_current_lock();
69 }
70