Skip to content

Commit 9950efb

Browse files
committed
nrf52_bsim: irq handling: Add function to get IRQ priorities
Added a simulation replacement for NVIC_GetPriority() + Added a function (like for ARM) to get the current IRQ priority (or INT_MAX if not in interrupt) Signed-off-by: Alberto Escolar Piedras <[email protected]>
1 parent 2bf1877 commit 9950efb

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

boards/posix/nrf52_bsim/board_irq.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include "sw_isr_table.h"
1212
#include "zephyr/types.h"
13+
#include "NRF_regs.h"
1314

1415
#ifdef __cplusplus
1516
extern "C" {
@@ -18,6 +19,8 @@ extern "C" {
1819
void z_isr_declare(unsigned int irq_p, int flags, void isr_p(void *),
1920
void *isr_param_p);
2021
void z_irq_priority_set(unsigned int irq, unsigned int prio, u32_t flags);
22+
int z_arch_irq_current_prio(void);
23+
unsigned int NVIC_GetPriority(IRQn_Type IRQn);
2124

2225
/**
2326
* Configure a static interrupt.

boards/posix/nrf52_bsim/irq_handler.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,20 @@ void z_irq_priority_set(unsigned int irq, unsigned int prio, uint32_t flags)
327327
hw_irq_ctrl_prio_set(irq, prio);
328328
}
329329

330+
/**
331+
* @brief Return current context priority.
332+
*
333+
* @return Interrupt priority or INT_MAX if in thread mode.
334+
*/
335+
int z_arch_irq_current_prio(void)
336+
{
337+
if (_kernel.nested == 0) {
338+
return INT_MAX;
339+
} else {
340+
return hw_irq_ctrl_get_cur_prio();
341+
}
342+
}
343+
330344
/**
331345
* Similar to ARM's NVIC_SetPendingIRQ
332346
* set a pending IRQ from SW
@@ -402,6 +416,15 @@ void NVIC_ClearPendingIRQ(IRQn_Type IRQn)
402416
hw_irq_ctrl_clear_irq(IRQn);
403417
}
404418

419+
/*
420+
* Replacement for ARMs NVIC_GetPriority()
421+
* Return the programmed priority of IRQn
422+
*/
423+
unsigned int NVIC_GetPriority(IRQn_Type IRQn)
424+
{
425+
return hw_irq_ctrl_get_prio(IRQn);
426+
}
427+
405428
/*
406429
* Very simple model of the WFE and SEV ARM instructions
407430
* which seems good enough for the Nordic controller

0 commit comments

Comments
 (0)