irq.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #ifndef _HARDWARE_IRQ_H_
8 #define _HARDWARE_IRQ_H_
9 
10 // These two config items are also used by assembler, so keeping separate
11 // PICO_CONFIG: PICO_MAX_SHARED_IRQ_HANDLERS, Maximum number of shared IRQ handlers, default=4, advanced=true, group=hardware_irq
12 #ifndef PICO_MAX_SHARED_IRQ_HANDLERS
13 #define PICO_MAX_SHARED_IRQ_HANDLERS 4u
14 #endif
15 
16 // PICO_CONFIG: PICO_DISABLE_SHARED_IRQ_HANDLERS, Disable shared IRQ handlers, type=bool, default=0, group=hardware_irq
17 #ifndef PICO_DISABLE_SHARED_IRQ_HANDLERS
18 #define PICO_DISABLE_SHARED_IRQ_HANDLERS 0
19 #endif
20 
21 #ifndef __ASSEMBLER__
22 
23 #include "pico.h"
25 #include "hardware/regs/intctrl.h"
26 #include "hardware/regs/m0plus.h"
27 
93 // PICO_CONFIG: PICO_DEFAULT_IRQ_PRIORITY, Define the default IRQ priority, default=0x80, group=hardware_irq
94 #ifndef PICO_DEFAULT_IRQ_PRIORITY
95 #define PICO_DEFAULT_IRQ_PRIORITY 0x80
96 #endif
97 
98 #define PICO_LOWEST_IRQ_PRIORITY 0xff
99 #define PICO_HIGHEST_IRQ_PRIORITY 0x00
100 
101 // PICO_CONFIG: PICO_SHARED_IRQ_HANDLER_DEFAULT_ORDER_PRIORITY, Set default shared IRQ order priority, default=0x80, group=hardware_irq
102 #ifndef PICO_SHARED_IRQ_HANDLER_DEFAULT_ORDER_PRIORITY
103 #define PICO_SHARED_IRQ_HANDLER_DEFAULT_ORDER_PRIORITY 0x80
104 #endif
105 
106 #define PICO_SHARED_IRQ_HANDLER_HIGHEST_ORDER_PRIORITY 0xff
107 #define PICO_SHARED_IRQ_HANDLER_LOWEST_ORDER_PRIORITY 0x00
108 
109 // PICO_CONFIG: PARAM_ASSERTIONS_ENABLED_IRQ, Enable/disable assertions in the IRQ module, type=bool, default=0, group=hardware_irq
110 #ifndef PARAM_ASSERTIONS_ENABLED_IRQ
111 #define PARAM_ASSERTIONS_ENABLED_IRQ 0
112 #endif
113 
114 #ifdef __cplusplus
115 extern "C" {
116 #endif
117 
123 typedef void (*irq_handler_t)(void);
124 
125 static inline void check_irq_param(__unused uint num) {
126  invalid_params_if(IRQ, num >= NUM_IRQS);
127 }
128 
141 void irq_set_priority(uint num, uint8_t hardware_priority);
142 
156 uint irq_get_priority(uint num);
157 
164 void irq_set_enabled(uint num, bool enabled);
165 
172 bool irq_is_enabled(uint num);
173 
180 void irq_set_mask_enabled(uint32_t mask, bool enabled);
181 
196 void irq_set_exclusive_handler(uint num, irq_handler_t handler);
197 
210 
235 void irq_add_shared_handler(uint num, irq_handler_t handler, uint8_t order_priority);
236 
253 void irq_remove_handler(uint num, irq_handler_t handler);
254 
261 bool irq_has_shared_handler(uint num);
262 
271 
281 static inline void irq_clear(uint int_num) {
282  *((volatile uint32_t *) (PPB_BASE + M0PLUS_NVIC_ICPR_OFFSET)) = (1u << ((uint32_t) (int_num & 0x1F)));
283 }
284 
292 void irq_set_pending(uint num);
293 
294 
299 void irq_init_priorities(void);
300 
313 void user_irq_claim(uint irq_num);
314 
329 void user_irq_unclaim(uint irq_num);
330 
344 int user_irq_claim_unused(bool required);
345 
346 /*
347 *! \brief Check if a user IRQ is in use on the calling core
348  * \ingroup hardware_irq
349  *
350  * User IRQs are numbered 26-31 and are not connected to any hardware, but can be triggered by \ref irq_set_pending.
351  *
352  * \note User IRQs are a core local feature; they cannot be used to communicate between cores. Therfore all functions
353  * dealing with Uer IRQs affect only the calling core
354  *
355  * \param irq_num the irq irq_num
356  * \return true if the irq_num is claimed, false otherwise
357  * \sa user_irq_claim
358  * \sa user_irq_unclaim
359  * \sa user_irq_claim_unused
360  */
361 bool user_irq_is_claimed(uint irq_num);
362 
363 #ifdef __cplusplus
364 }
365 #endif
366 
367 #endif
368 #endif
bool irq_is_enabled(uint num)
Determine if a specific interrupt is enabled on the executing core.
Definition: irq.c:44
void user_irq_unclaim(uint irq_num)
Mark a user IRQ as no longer used on the calling core.
Definition: irq.c:441
static void irq_clear(uint int_num)
Clear a specific interrupt on the executing core.
Definition: irq.h:281
void irq_set_pending(uint num)
Force an interrupt to be pending on the executing core.
Definition: irq.c:60
irq_handler_t irq_get_exclusive_handler(uint num)
Get the exclusive interrupt handler for an interrupt on the executing core.
Definition: irq.c:131
irq_handler_t irq_get_vtable_handler(uint num)
Get the current IRQ handler for the specified IRQ from the currently installed hardware vector table ...
Definition: irq.c:113
uint irq_get_priority(uint num)
Get specified interrupt's priority.
Definition: irq.c:375
void irq_set_enabled(uint num, bool enabled)
Enable or disable a specific interrupt on the executing core.
Definition: irq.c:39
void(* irq_handler_t)(void)
Interrupt handler function type.
Definition: irq.h:123
void user_irq_claim(uint irq_num)
Claim ownership of a user IRQ on the calling core.
Definition: irq.c:437
int user_irq_claim_unused(bool required)
Claim ownership of a free user IRQ on the calling core.
Definition: irq.c:445
void irq_set_priority(uint num, uint8_t hardware_priority)
Set specified interrupt's priority.
Definition: irq.c:367
void irq_remove_handler(uint num, irq_handler_t handler)
Remove a specific interrupt handler for the given irq number on the executing core.
Definition: irq.c:270
bool irq_has_shared_handler(uint num)
Determine if the current handler for the given number is shared.
Definition: irq.c:99
void irq_set_mask_enabled(uint32_t mask, bool enabled)
Enable/disable multiple interrupts on the executing core.
Definition: irq.c:49
void irq_add_shared_handler(uint num, irq_handler_t handler, uint8_t order_priority)
Add a shared interrupt handler for an interrupt on the executing core.
Definition: irq.c:196
void irq_set_exclusive_handler(uint num, irq_handler_t handler)
Set an exclusive interrupt handler for an interrupt on the executing core.
Definition: irq.c:118
void irq_init_priorities(void)
Perform IRQ priority initialization for the current core.
Definition: irq.c:417