aboutsummaryrefslogtreecommitdiff
path: root/lib/chibios/os/hal/ports/common/ARMCMx/nvic.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chibios/os/hal/ports/common/ARMCMx/nvic.c')
-rw-r--r--lib/chibios/os/hal/ports/common/ARMCMx/nvic.c114
1 files changed, 114 insertions, 0 deletions
diff --git a/lib/chibios/os/hal/ports/common/ARMCMx/nvic.c b/lib/chibios/os/hal/ports/common/ARMCMx/nvic.c
new file mode 100644
index 000000000..4da25eeab
--- /dev/null
+++ b/lib/chibios/os/hal/ports/common/ARMCMx/nvic.c
@@ -0,0 +1,114 @@
1/*
2 ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
17/**
18 * @file common/ARMCMx/nvic.c
19 * @brief Cortex-Mx NVIC support code.
20 *
21 * @addtogroup COMMON_ARMCMx_NVIC
22 * @{
23 */
24
25#include "hal.h"
26
27/*===========================================================================*/
28/* Driver local definitions. */
29/*===========================================================================*/
30
31/*===========================================================================*/
32/* Driver exported variables. */
33/*===========================================================================*/
34
35/*===========================================================================*/
36/* Driver local types. */
37/*===========================================================================*/
38
39/*===========================================================================*/
40/* Driver local variables. */
41/*===========================================================================*/
42
43/*===========================================================================*/
44/* Driver local functions. */
45/*===========================================================================*/
46
47/*===========================================================================*/
48/* Driver exported functions. */
49/*===========================================================================*/
50
51/**
52 * @brief Sets the priority of an interrupt handler and enables it.
53 *
54 * @param[in] n the interrupt number
55 * @param[in] prio the interrupt priority
56 */
57void nvicEnableVector(uint32_t n, uint32_t prio) {
58
59#if defined(__CORE_CM0_H_GENERIC) || defined(__CORE_CM0PLUS_H_GENERIC)
60 NVIC->IP[_IP_IDX(n)] = (NVIC->IP[_IP_IDX(n)] & ~(0xFFU << _BIT_SHIFT(n))) |
61 (NVIC_PRIORITY_MASK(prio) << _BIT_SHIFT(n));
62#else
63 NVIC->IP[n] = NVIC_PRIORITY_MASK(prio);
64#endif
65 NVIC->ICPR[n >> 5U] = 1U << (n & 0x1FU);
66 NVIC->ISER[n >> 5U] = 1U << (n & 0x1FU);
67}
68
69/**
70 * @brief Disables an interrupt handler.
71 *
72 * @param[in] n the interrupt number
73 */
74void nvicDisableVector(uint32_t n) {
75
76 NVIC->ICER[n >> 5U] = 1U << (n & 0x1FU);
77#if defined(__CORE_CM0_H_GENERIC) || defined(__CORE_CM0PLUS_H_GENERIC)
78 NVIC->IP[_IP_IDX(n)] = NVIC->IP[_IP_IDX(n)] & ~(0xFFU << _BIT_SHIFT(n));
79#else
80 NVIC->IP[n] = 0U;
81#endif
82}
83
84/**
85 * @brief Changes the priority of a system handler.
86 *
87 * @param[in] handler the system handler number
88 * @param[in] prio the system handler priority
89 */
90void nvicSetSystemHandlerPriority(uint32_t handler, uint32_t prio) {
91
92 osalDbgCheck(handler < 12U);
93
94#if defined(__CORE_CM0_H_GENERIC) || defined(__CORE_CM0PLUS_H_GENERIC)
95 SCB->SHP[_SHP_IDX(handler)] = (SCB->SHP[_SHP_IDX(handler)] & ~(0xFFU << _BIT_SHIFT(handler))) |
96 (NVIC_PRIORITY_MASK(prio) << _BIT_SHIFT(handler));
97#elif defined(__CORE_CM7_H_GENERIC)
98 SCB->SHPR[handler] = NVIC_PRIORITY_MASK(prio);
99#else
100 SCB->SHP[handler] = NVIC_PRIORITY_MASK(prio);
101#endif
102}
103
104/**
105 * @brief Clears a pending interrupt source.
106 *
107 * @param[in] n the interrupt number
108 */
109void nvicClearPending(uint32_t n) {
110
111 NVIC->ICPR[n >> 5] = 1 << (n & 0x1F);
112}
113
114/** @} */