Zephyr API Documentation  3.6.0
A Scalable Open Source RTOS
3.6.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
arcv2_irq_unit.h
Go to the documentation of this file.
1/* arcv2_irq_unit.h - ARCv2 Interrupt Unit device driver */
2
3/*
4 * Copyright (c) 2014 Wind River Systems, Inc.
5 * Copyright (c) 2020 Synopsys.
6 *
7 * SPDX-License-Identifier: Apache-2.0
8 */
9
10#ifndef ZEPHYR_INCLUDE_ARCH_ARC_V2_ARCV2_IRQ_UNIT_H_
11#define ZEPHYR_INCLUDE_ARCH_ARC_V2_ARCV2_IRQ_UNIT_H_
12
13#ifdef __cplusplus
14extern "C" {
15#endif
16
17/* configuration flags for interrupt unit */
18#define _ARC_V2_INT_PRIO_MASK 0xf
19#define _ARC_V2_INT_DISABLE 0
20#define _ARC_V2_INT_ENABLE 1
21
22#define _ARC_V2_INT_LEVEL 0
23#define _ARC_V2_INT_PULSE 1
24
25#ifndef _ASMLANGUAGE
26
27/*
28 * NOTE:
29 *
30 * All APIs provided by this file are protected with INTERRUPTS LOCKED. The
31 * APIs themselves are writing the IRQ_SELECT, selecting which IRQ's registers
32 * it wants to write to, then write to them: THIS IS NOT AN ATOMIC OPERATION.
33 *
34 * Locking the interrupts inside of the APIs are some kind of self-protection
35 * to guarantee the correctness of operation if the callers don't lock
36 * the interrupt.
37 *
38 */
39
46static ALWAYS_INLINE
47void z_arc_v2_irq_unit_irq_enable_set(
48 int irq,
49 unsigned char enable
50 )
51{
52 unsigned int key = arch_irq_lock();
53
54 z_arc_v2_aux_reg_write(_ARC_V2_IRQ_SELECT, irq);
55 z_arc_v2_aux_reg_write(_ARC_V2_IRQ_ENABLE, enable);
56
57 arch_irq_unlock(key);
58}
59
66static ALWAYS_INLINE
67void z_arc_v2_irq_unit_int_enable(int irq)
68{
69 z_arc_v2_irq_unit_irq_enable_set(irq, _ARC_V2_INT_ENABLE);
70}
71
78static ALWAYS_INLINE
79void z_arc_v2_irq_unit_int_disable(int irq)
80{
81 z_arc_v2_irq_unit_irq_enable_set(irq, _ARC_V2_INT_DISABLE);
82}
83
92static ALWAYS_INLINE
93bool z_arc_v2_irq_unit_int_enabled(int irq)
94{
95 bool ret;
96 unsigned int key = arch_irq_lock();
97
98 z_arc_v2_aux_reg_write(_ARC_V2_IRQ_SELECT, irq);
99 ret = z_arc_v2_aux_reg_read(_ARC_V2_IRQ_ENABLE) & 0x1;
100
101 arch_irq_unlock(key);
102
103 return ret;
104}
105
106
113static ALWAYS_INLINE
114void z_arc_v2_irq_unit_prio_set(int irq, unsigned char prio)
115{
116
117 unsigned int key = arch_irq_lock();
118
119 z_arc_v2_aux_reg_write(_ARC_V2_IRQ_SELECT, irq);
120#if defined(CONFIG_ARC_SECURE_FIRMWARE)
121 z_arc_v2_aux_reg_write(_ARC_V2_IRQ_PRIORITY,
122 (z_arc_v2_aux_reg_read(_ARC_V2_IRQ_PRIORITY) & (~_ARC_V2_INT_PRIO_MASK))
123 | prio);
124#else
125 z_arc_v2_aux_reg_write(_ARC_V2_IRQ_PRIORITY, prio);
126#endif
127 arch_irq_unlock(key);
128}
129
130#if defined(CONFIG_ARC_SECURE_FIRMWARE)
136static ALWAYS_INLINE
137void z_arc_v2_irq_uinit_secure_set(int irq, bool secure)
138{
139 unsigned int key = arch_irq_lock();
140
141 z_arc_v2_aux_reg_write(_ARC_V2_IRQ_SELECT, irq);
142
143 if (secure) {
144 z_arc_v2_aux_reg_write(_ARC_V2_IRQ_PRIORITY,
145 z_arc_v2_aux_reg_read(_ARC_V2_IRQ_PRIORITY) |
146 _ARC_V2_IRQ_PRIORITY_SECURE);
147 } else {
148 z_arc_v2_aux_reg_write(_ARC_V2_IRQ_PRIORITY,
149 z_arc_v2_aux_reg_read(_ARC_V2_IRQ_PRIORITY) &
150 _ARC_V2_INT_PRIO_MASK);
151 }
152
153 arch_irq_unlock(key);
154}
155#endif
156
166static ALWAYS_INLINE
167void z_arc_v2_irq_unit_sensitivity_set(int irq, int s)
168{
169 unsigned int key = arch_irq_lock();
170
171 z_arc_v2_aux_reg_write(_ARC_V2_IRQ_SELECT, irq);
172 z_arc_v2_aux_reg_write(_ARC_V2_IRQ_TRIGGER, s);
173
174 arch_irq_unlock(key);
175}
176
177/*
178 * @brief Check whether processor in interrupt/exception state
179 *
180 * Check whether processor in interrupt/exception state
181 *
182 * @return 1 in interrupt/exception state; 0 not in
183 */
184static ALWAYS_INLINE
185bool z_arc_v2_irq_unit_is_in_isr(void)
186{
187 uint32_t act = z_arc_v2_aux_reg_read(_ARC_V2_AUX_IRQ_ACT);
188
189 /* in exception ?*/
190 if (z_arc_v2_aux_reg_read(_ARC_V2_STATUS32) & _ARC_V2_STATUS32_AE) {
191 return true;
192 }
193
194 return ((act & 0xffff) != 0U);
195}
196
204static ALWAYS_INLINE
205void z_arc_v2_irq_unit_trigger_set(int irq, unsigned int trigger)
206{
207 unsigned int key = arch_irq_lock();
208
209 z_arc_v2_aux_reg_write(_ARC_V2_IRQ_SELECT, irq);
210 z_arc_v2_aux_reg_write(_ARC_V2_IRQ_TRIGGER, trigger);
211
212 arch_irq_unlock(key);
213}
214
223static ALWAYS_INLINE
224unsigned int z_arc_v2_irq_unit_trigger_get(int irq)
225{
226 unsigned int ret;
227 unsigned int key = arch_irq_lock();
228
229 z_arc_v2_aux_reg_write(_ARC_V2_IRQ_SELECT, irq);
230 ret = z_arc_v2_aux_reg_read(_ARC_V2_IRQ_TRIGGER);
231
232 arch_irq_unlock(key);
233
234 return ret;
235}
236
243static ALWAYS_INLINE
244void z_arc_v2_irq_unit_int_eoi(int irq)
245{
246 unsigned int key = arch_irq_lock();
247
248 z_arc_v2_aux_reg_write(_ARC_V2_IRQ_SELECT, irq);
249 z_arc_v2_aux_reg_write(_ARC_V2_IRQ_PULSE_CANCEL, 1);
250
251 arch_irq_unlock(key);
252}
253
254#endif /* _ASMLANGUAGE */
255
256#ifdef __cplusplus
257}
258#endif
259
260#endif /* ZEPHYR_INCLUDE_ARCH_ARC_V2_ARCV2_IRQ_UNIT_H_ */
irp nz macro MOVR cc s mov cc s endm endr irp aw macro LDR aa s
Definition: asm-macro-32-bit-gnu.h:17
#define ALWAYS_INLINE
Definition: common.h:129
static unsigned int arch_irq_lock(void)
Lock interrupts on the current CPU.
static void arch_irq_unlock(unsigned int key)
Unlock interrupts on the current CPU.
__UINT32_TYPE__ uint32_t
Definition: stdint.h:90