HAL
Hardware Abstraction Layer
Interrupts
Handlers
Registering interrupts can be done with the HAL through the following function:
int hal_registerInterruptHandler(uintptr_t int_number, hal_interrupt_handler_t handler, void *context);
int_number: The target interrupt number to usehandler: The handler to usecontext: The context to pass to the handler
The interrupt handler is declared as:
typedef int (*hal_interrupt_handler_t)(void *context);
danger
Returning nonzero from an interrupt handler will cause IRQ_HANDLER_FAILED to be thrown.
You can unregister interrupt handlers using the following function:
void hal_unregisterInterruptHandler(uintptr_t int_no);
Check if a handler is in use with the following function:
int hal_interruptHandlerInUse(uintptr_t int_number);
Controlling interrupts on the CPU
You can use the following functions to get/set the interrupt state:
void hal_setInterruptState(int state);
int hal_getInterruptState();
Possible values:
HAL_INTERRUPTS_ENABLEDHAL_INTERRUPTS_DISABLED
Power
caution
To perform a safe shutdown, you should inform the kernel of the shutdown. See the example
Available HAL power states include:
HAL_POWER_REBOOT: Reboot the computerHAL_POWER_SHUTDOWN: Shutdown the computerHAL_POWER_HIBERNATE: Hibernate the computer
Prepare the computer to change to a power state with hal_changePowerState (note that kernel_prepareForPowerState does this for you)
void hal_prepareForPowerState(int state);
Set the power state with hal_setPowerState:
int hal_setPowerState(int state);
Power Example
void shutdown() {
kernel_prepareForPowerState(HAL_POWER_SHUTDOWN);
hal_setPowerState(HAL_POWER_SHUTDOWN);
__builtin_unreachable();
}