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_MAX32672_NVIC_TABLE_H_
27 #define LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32672_NVIC_TABLE_H_
28 
29 #include "max32672.h"
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 /**
36  * @brief Set an IRQ hander callback function.  If the IRQ table is in
37  * flash, this will copy it to RAM and set NVIC to RAM based table.
38  *
39  * @param irqn          ARM external IRQ number
40  * @param irq_callback  Function to be called at IRQ context
41  *
42  */
43 void MXC_NVIC_SetVector(IRQn_Type irqn, void (*irq_callback)(void));
44 
45 #if defined(__GNUC__)
46 #if __CM4_CMSIS_VERSION_MAIN == 0x03
47 // NVIC_SetVector was custom-implemented in the PeriphDrivers library for
48 // CMSIS version 3.  Newer versions of CMSIS provide an implementation of
49 // NVIC_SetVector with different functionality, so the Maxim implementation
50 // has been moved to MXC_NVIC_SetVector (above).
51 
52 // The MSDK will move to CMSIS version 5 in the future.
53 
54 // For CMSIS version 3, use MXC_NVIC_SetVector instead.
55 // For CMSIS version 5, you have the choice of using either.  However, only
56 // MXC_NVIC_SetVector will work with legacy code.
57 inline __attribute__((
58     deprecated("Use MXC_NVIC_SetVector instead.  See nvic_table.h for more details."))) void
NVIC_SetVector(IRQn_Type irqn,void (* irq_callback)(void))59 NVIC_SetVector(IRQn_Type irqn, void (*irq_callback)(void))
60 {
61     MXC_NVIC_SetVector(irqn, irq_callback);
62 }
63 #endif
64 #endif
65 
66 /**
67  * @brief Copy NVIC vector table to RAM and set NVIC to RAM based table.
68  *
69  */
70 void NVIC_SetRAM(void);
71 
72 /**
73  * @brief      Get Interrupt Vector
74  * @details    Reads an interrupt vector from interrupt vector table. The
75  *             interrupt number can be positive to specify a device specific
76  *             interrupt, or negative to specify a processor exception.
77  * @param[in]  IRQn  Interrupt number.
78  * @return     Address of interrupt handler function
79  */
80 uint32_t MXC_NVIC_GetVector(IRQn_Type IRQn);
81 
82 #if defined(__GNUC__)
83 #if __CM4_CMSIS_VERSION_MAIN == 0x03
84 // NVIC_GetVector was custom-implemented in the PeriphDrivers library for
85 // CMSIS version 3.  Newer versions of CMSIS provide an implementation of
86 // NVIC_GetVector with different functionality, so the Maxim implementation
87 // has been moved to MXC_NVIC_GetVector (above).
88 
89 // The MSDK will move to CMSIS version 5 in the future.
90 
91 // For CMSIS version 3, use MXC_NVIC_SetVector instead.
92 // For CMSIS version 5, you have the choice of using either.  However, only
93 // MXC_NVIC_GetVector will work with legacy code.
94 inline __attribute__((
95     deprecated("Use MXC_NVIC_GetVector instead.  See nvic_table.h for more details."))) void
NVIC_GetVector(IRQn_Type irqn)96 NVIC_GetVector(IRQn_Type irqn)
97 {
98     MXC_NVIC_GetVector(irqn);
99 }
100 #endif
101 #endif
102 
103 #ifdef __cplusplus
104 }
105 #endif
106 
107 #endif // LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32672_NVIC_TABLE_H_
108