Skip to content

Commit b0c7539

Browse files
committed
[p2] fixes INTERRUPTS_01_isisr_willpreempt_servicedirqn test
1 parent 3672396 commit b0c7539

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

hal/inc/interrupts_hal.h

-6
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,6 @@ int hal_interrupt_set_direct_handler(IRQn_Type irqn, hal_interrupt_direct_handle
111111

112112
#ifdef USE_STDPERIPH_DRIVER
113113

114-
#if defined(STM32F10X_MD) || defined(STM32F10X_HD)
115-
#include "stm32f10x.h"
116-
#elif defined(STM32F2XX)
117-
#include "stm32f2xx.h"
118-
#endif // defined(STM32F10X_MD) || defined(STM32F10X_HD)
119-
120114
#ifdef nRF52840
121115
#include <nrf52840.h>
122116
#endif /* nRF52840 */

hal/src/rtl872x/interrupts_hal.cpp

+18-5
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ using namespace particle;
3636
#endif
3737

3838
extern uintptr_t link_ram_interrupt_vectors_location[];
39+
static uint32_t hal_interrupts_handler_backup[MAX_VECTOR_TABLE_NUM] = {};
3940

4041
namespace {
4142

@@ -258,20 +259,32 @@ int hal_interrupt_set_direct_handler(IRQn_Type irqn, hal_interrupt_direct_handle
258259
}
259260

260261
int32_t state = HAL_disable_irq();
261-
volatile uint32_t* isrs = (volatile uint32_t*)&link_ram_interrupt_vectors_location;
262262

263263
if (handler == nullptr && (flags & HAL_INTERRUPT_DIRECT_FLAG_RESTORE)) {
264264
// Restore
265-
// HAL_Core_Restore_Interrupt(irqn);
265+
uint32_t old_handler = hal_interrupts_handler_backup[IRQN_TO_IDX(irqn)];
266+
__NVIC_SetVector(irqn, (uint32_t)old_handler);
267+
268+
hal_interrupts_handler_backup[IRQN_TO_IDX(irqn)] = 0;
266269
} else {
267-
isrs[IRQN_TO_IDX(irqn)] = (uint32_t)handler;
270+
271+
// If there is currently a backup: Return error
272+
if(hal_interrupts_handler_backup[IRQN_TO_IDX(irqn)]){
273+
return 1;
274+
}
275+
276+
// If there is a current handler, back it up
277+
uint32_t current_handler = __NVIC_GetVector(irqn);
278+
if (current_handler) {
279+
hal_interrupts_handler_backup[IRQN_TO_IDX(irqn)] = current_handler;
280+
}
268281
}
269282

270283
if (flags & HAL_INTERRUPT_DIRECT_FLAG_DISABLE) {
271284
// Disable
272-
// sd_nvic_DisableIRQ(irqn);
285+
//__NVIC_DisableIRQ(irqn); // actually disable the interrupt (ie like systick!?)
273286
} else if (flags & HAL_INTERRUPT_DIRECT_FLAG_ENABLE) {
274-
// sd_nvic_EnableIRQ(irqn);
287+
__NVIC_SetVector(irqn, (uint32_t)handler);
275288
}
276289

277290
HAL_enable_irq(state);

0 commit comments

Comments
 (0)