Skip to content

Commit acfb1e1

Browse files
committed
[p2] simplify error condition handling
1 parent 028dcbc commit acfb1e1

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

hal/src/rtl872x/interrupts_hal.cpp

+14-16
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,6 @@ int hal_interrupt_set_direct_handler(IRQn_Type irqn, hal_interrupt_direct_handle
258258
return 1;
259259
}
260260

261-
int error = 0;
262261
int32_t state = HAL_disable_irq();
263262

264263
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
271270
} else {
272271
// If there is currently a handler backup: Return error
273272
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;
281275
}
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+
}
282282
}
283283

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);
291289
}
292290

293291
HAL_enable_irq(state);
294292

295-
return error;
293+
return 0;
296294
}

0 commit comments

Comments
 (0)