when implementing safety-critical applications that need strict separation between user mode and supervisor mode. You've made a smart decision by switching to supervisor mode to access critical registers, but it would be great to explore other ways to handle this situation more efficiently while maintaining the security and integrity of your system.
One potential solution could be leveraging a memory protection unit (MPU) or a hardware-based access control mechanism, depending on the specific capabilities of the S32K144. Some microcontrollers support configurable regions where certain registers or memory blocks can be accessed in user mode under specific conditions, without needing to fully switch to supervisor mode. This could be done by defining access rules for specific registers or memory regions. Another approach is using safe wrappers or gateways for register access, where the user mode application would call predefined functions that perform the access checks and only allow register access when it is deemed safe. These functions could then manage the transition to supervisor mode only when absolutely necessary, rather than switching modes manually within critical sections of the application.
It’s also worth checking whether the S32K144 offers features like secure supervisor mode or privileged access registers which could allow more fine-grained control over what the user mode application can access. Using these hardware security features could help you limit the scope of what is accessible without compromising the safety requirements of your system.