@@ -258,7 +258,6 @@ int hal_interrupt_set_direct_handler(IRQn_Type irqn, hal_interrupt_direct_handle
258
258
return 1 ;
259
259
}
260
260
261
- int error = 0 ;
262
261
int32_t state = HAL_disable_irq ();
263
262
264
263
if (handler == nullptr && (flags & HAL_INTERRUPT_DIRECT_FLAG_RESTORE)) {
@@ -271,26 +270,25 @@ int hal_interrupt_set_direct_handler(IRQn_Type irqn, hal_interrupt_direct_handle
271
270
} else {
272
271
// If there is currently a handler backup: Return error
273
272
if (hal_interrupts_handler_backup[IRQN_TO_IDX (irqn)]) {
274
- error = SYSTEM_ERROR_NOT_SUPPORTED;
275
- } else {
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
- }
273
+ HAL_enable_irq (state);
274
+ return SYSTEM_ERROR_ALREADY_EXISTS;
281
275
}
276
+
277
+ // If there is a current handler, back it up
278
+ uint32_t current_handler = __NVIC_GetVector (irqn);
279
+ if (current_handler) {
280
+ hal_interrupts_handler_backup[IRQN_TO_IDX (irqn)] = current_handler;
281
+ }
282
282
}
283
283
284
- if (!error) {
285
- if (flags & HAL_INTERRUPT_DIRECT_FLAG_DISABLE) {
286
- // Disable
287
- __NVIC_DisableIRQ (irqn);
288
- } else if (flags & HAL_INTERRUPT_DIRECT_FLAG_ENABLE) {
289
- __NVIC_SetVector (irqn, (uint32_t )handler);
290
- }
284
+ if (flags & HAL_INTERRUPT_DIRECT_FLAG_DISABLE) {
285
+ // Disable
286
+ __NVIC_DisableIRQ (irqn);
287
+ } else if (flags & HAL_INTERRUPT_DIRECT_FLAG_ENABLE) {
288
+ __NVIC_SetVector (irqn, (uint32_t )handler);
291
289
}
292
290
293
291
HAL_enable_irq (state);
294
292
295
- return error ;
293
+ return 0 ;
296
294
}
0 commit comments