1 /**
2  * @file  nvic_table.h
3  * @brief Interrupt vector table manipulation functions.
4  */
5 
6 /******************************************************************************
7  *
8  * Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by
9  * Analog Devices, Inc.),
10  * Copyright (C) 2023-2024 Analog Devices, Inc.
11  *
12  * Licensed under the Apache License, Version 2.0 (the "License");
13  * you may not use this file except in compliance with the License.
14  * You may obtain a copy of the License at
15  *
16  *     http://www.apache.org/licenses/LICENSE-2.0
17  *
18  * Unless required by applicable law or agreed to in writing, software
19  * distributed under the License is distributed on an "AS IS" BASIS,
20  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21  * See the License for the specific language governing permissions and
22  * limitations under the License.
23  *
24  ******************************************************************************/
25 
26 #ifndef LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX78000_NVIC_TABLE_H_
27 #define LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX78000_NVIC_TABLE_H_
28 
29 #ifndef __riscv
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 #include "max78000.h"
36 
37 /**
38  * @brief Set an IRQ hander callback function.  If the IRQ table is in
39  * flash, this will copy it to RAM and set NVIC to RAM based table.
40  *
41  * @param irqn          ARM external IRQ number
42  * @param irq_callback  Function to be called at IRQ context
43  *
44  */
45 void MXC_NVIC_SetVector(IRQn_Type irqn, void (*irq_callback)(void));
46 
47 #if defined(__GNUC__)
48 #if __CM4_CMSIS_VERSION_MAIN == 0x03
49 // NVIC_SetVector was custom-implemented in the PeriphDrivers library for
50 // CMSIS version 3.  Newer versions of CMSIS provide an implementation of
51 // NVIC_SetVector with different functionality, so the Maxim implementation
52 // has been moved to MXC_NVIC_SetVector (above).
53 
54 // The MSDK will move to CMSIS version 5 in the future.
55 
56 // For CMSIS version 3, use MXC_NVIC_SetVector instead.
57 // For CMSIS version 5, you have the choice of using either.  However, only
58 // MXC_NVIC_SetVector will work with legacy code.
59 inline __attribute__((
60     deprecated("Use MXC_NVIC_SetVector instead.  See nvic_table.h for more details."))) void
NVIC_SetVector(IRQn_Type irqn,void (* irq_callback)(void))61 NVIC_SetVector(IRQn_Type irqn, void (*irq_callback)(void))
62 {
63     MXC_NVIC_SetVector(irqn, irq_callback);
64 }
65 #endif
66 #endif
67 
68 /**
69  * @brief Copy NVIC vector table to RAM and set NVIC to RAM based table.
70  *
71  */
72 void NVIC_SetRAM(void);
73 
74 /**
75  * @brief      Get Interrupt Vector
76  * @details    Reads an interrupt vector from interrupt vector table. The
77  *             interrupt number can be positive to specify a device specific
78  *             interrupt, or negative to specify a processor exception.
79  * @param[in]  IRQn  Interrupt number.
80  * @return     Address of interrupt handler function
81  */
82 uint32_t MXC_NVIC_GetVector(IRQn_Type IRQn);
83 
84 #if defined(__GNUC__)
85 #if __CM4_CMSIS_VERSION_MAIN == 0x03
86 // NVIC_GetVector was custom-implemented in the PeriphDrivers library for
87 // CMSIS version 3.  Newer versions of CMSIS provide an implementation of
88 // NVIC_GetVector with different functionality, so the Maxim implementation
89 // has been moved to MXC_NVIC_GetVector (above).
90 
91 // The MSDK will move to CMSIS version 5 in the future.
92 
93 // For CMSIS version 3, use MXC_NVIC_SetVector instead.
94 // For CMSIS version 5, you have the choice of using either.  However, only
95 // MXC_NVIC_GetVector will work with legacy code.
96 inline __attribute__((
97     deprecated("Use MXC_NVIC_GetVector instead.  See nvic_table.h for more details."))) void
NVIC_GetVector(IRQn_Type irqn)98 NVIC_GetVector(IRQn_Type irqn)
99 {
100     MXC_NVIC_GetVector(irqn);
101 }
102 #endif
103 #endif
104 
105 #ifdef __cplusplus
106 }
107 #endif
108 
109 #endif /* !__riscv */
110 
111 #endif // LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX78000_NVIC_TABLE_H_
112