Autosar OS Hook Error

Welcome to Autosar error world

Emirhan Çalışkan
3 min readJul 9, 2024

What Is Hook Error?

Error Hook

If selected, the ErrorHook routine is called, if an API function returns with an error code unequal to E_OK. It is also called if OS internal errors are detected.

The function ErrorHook has to be provided by the application.

Panic Hook

If selected, the PanicHook routine will be called by the operating system if an inconsistent OS state is detected and regular shutdown cannot be reached.

The function Os_PanicHook has to be provided by the application.

Post Task Hook

If selected, the PostTaskHook routine will be called any time the operating system interrupts or terminates a task.

The function PostTaskHook has to be provided by the application.

Pre Task Hook

If selected, the PreTaskHook routine will be called any time the operating system starts or resumes a task.

The function PreTaskHook has to be provided by the application.

Protection Hook

Switch to enable/disable the call to the (user supplied) protection hook.

Shutdown Hook

If selected, the ShutdownHook routine will be called, if the API-function ShutdownOS is either called by the application or by the operating system.

The function ShutdownHook has to be provided by the application.

Startup Hook

If selected, the StartupHook routine will be called by the operating system in the startup phase (after calling StartOS and before starting the first task).

The function StartupHook has to be provided by the application.

Error Hook

From Vector’s OS reference documentation, we can see that MICROSAR OS is able to detect and handle the following errors:

Application Errors:

> Are raised if the OS could not execute a requested OS API service correctly. Typically the OS API is used wrong (e.g. invalid object ID).

> Do not corrupt OS internal data.

> Will result in call of the global ErrorHook() for centralized error handling (if configured).

> Will result in call of an application specific ErrorHook (if configured).

> May not induce shutdown / terminate reactions. Instead the application may continue execution by simply returning from the ErrorHooks.

Protection Errors

> Are raised if the application violates its configured boundaries (e.g. memory access violations, timing violations).

> Do not corrupt OS internal data.

> Are raised upon occurrence of unhandled exceptions and interrupts.

> Will result in call of the ProtectionHook() where a shutdown or terminate handling (with or without restart) is induced.

> If Shutdown is induced the ShutdownHook() is called (if configured).

> If no ProtectionHook() is configured shutdown is induced.

Kernel Errors

> Are raised if the OS cannot longer assume the correctness of its internal data (e.g. memory access violation during ProtectionHook())

> The OS will disable all interrupts and call the Os_PanicHook() to inform the application.

> Afterwards the OS enters an infinite loop.

This is where ErrorHook comes in. Vector’s MicroSAR OS uses 8 bits, or a byte, to record and expand the Error Code. Some Errors have already been defined in AUTOSAR OS or OSEK OS.

Definition Error

Related Error Code and Type of Error

(0xF5) E_OS_SYS_OVERFLOW: An internal OS buffer used for cross core communication is full.

(0xF6) E_OS_SYS_KILL_KERNEL_OBJ: A forcible termination of a kernel object has been requested e.g. terminate system applications.

(0xF7) E_OS_SYS_NO_RESTARTTASK: An OS-Application has been terminated with requested restart but no restart task has been configured.

(0xF8) E_OS_SYS_CALL_NOT_ALLOWED: The application tries to use an API cross core, but the target core has not been configured for cross core API.

(0xF9) E_OS_SYS_FUNCTION_UNAVAILABLE: The triggered cross core function is not available on the target core.

(0xFA) E_OS_SYS_PROTECTION_SYSCALL: A syscall instruction has been executed with an invalid syscall number.

(0xFB) E_OS_SYS_PROTECTION_IRQ: An unhandled interrupt occurred.

(0xFC) E_OS_SYS_API_ERROR: The interrupt handling API is used wrong.

(0xFD) E_OS_SYS_ASSERTION: Internal OS assertion (not issued to customer).

(0xFE) E_OS_SYS_OVERLOAD: A system timer ISR was delayed too long.

For more detailed Error Code ID, please refer to the Os_StatusType definition in Os_Types.h.

Then, we can capture these Errors through the following functions, record or print them out to indicate what problems the current system has.

FUNC(void, OS_ERRORHOOK_CODE) ErrorHook(StatusType Error)
{
/*Customer source code implement here!*/
}

--

--