k_sys_fatal_error_handler() and I2C interaction

Hello,

I'm trying to extend the k_sys_fatal_error_handler() function to shut down a power supply and turn on an LED in case of fatal error/exception. Unfortunately, these two actions require interacting with an I2C device, and I'm struggling to get this done properly.

From the docs: https://docs.zephyrproject.org/latest/kernel/services/other/fatal.html#fatal-error-handling

Applications are free to implement their own error handling policy by overriding the implementation of k_sys_fatal_error_handler(). If the implementation returns, the faulting thread will be aborted and the system will otherwise continue to function. See the documentation for this function for additional details and constraints.

I thought of using a work item to do the required I2C operations and finally call k_fatal_halt(), but this does not seem to work. After the function returns, the kernel tries to abort the main thread, which ends up in calling a k_panic and looping back into k_sys_fatal_error_handler().

What is the suggested approach in this case? I'm currently triggering the exception manually with k_oops(), but I'm trying to implement something that would work in case of unexpected errors, including stack overflows etc.

Thanks!

 

Parents Reply Children
No Data
Related