Skip to content

Commit 7dedcee

Browse files
aescolarnordic-krch
authored andcommitted
nrf52_bsim: irq handling: Add function z_arm_irq_can_preempt
Added a simulation replacement for NVIC_GetPriority() + Added a function (like for ARM) to check if current context can be preempted by given interrupt. Signed-off-by: Alberto Escolar Piedras <[email protected]>
1 parent 0b28658 commit 7dedcee

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-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+
bool z_arm_irq_can_preempt(u32_t irq_line);
23+
unsigned int NVIC_GetPriority(IRQn_Type IRQn);
2124

2225
/**
2326
* Configure a static interrupt.

boards/posix/nrf52_bsim/irq_handler.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,25 @@ 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+
static int z_arm_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+
344+
bool z_arm_irq_can_preempt(u32_t irq_line)
345+
{
346+
return z_arm_irq_current_prio() > NVIC_GetPriority((IRQn_Type)irq_line);
347+
}
348+
330349
/**
331350
* Similar to ARM's NVIC_SetPendingIRQ
332351
* set a pending IRQ from SW
@@ -402,6 +421,15 @@ void NVIC_ClearPendingIRQ(IRQn_Type IRQn)
402421
hw_irq_ctrl_clear_irq(IRQn);
403422
}
404423

424+
/*
425+
* Replacement for ARMs NVIC_GetPriority()
426+
* Return the programmed priority of IRQn
427+
*/
428+
unsigned int NVIC_GetPriority(IRQn_Type IRQn)
429+
{
430+
return hw_irq_ctrl_get_prio(IRQn);
431+
}
432+
405433
/*
406434
* Very simple model of the WFE and SEV ARM instructions
407435
* which seems good enough for the Nordic controller

0 commit comments

Comments
 (0)