AVR SD Safety Framework 1.0.0
Loading...
Searching...
No Matches
main_example.c File Reference

Example main file for demonstrating usage of the Framework Task Managers. More...

#include <stdbool.h>
#include <stdlib.h>
#include <define_memory_sections.h>
#include <main_example.h>
#include <task_manager_interrupts.h>
#include <task_manager_pre_startup.h>
#include <task_manager_scheduler.h>
#include <task_manager_shutdown.h>
#include <task_manager_startup.h>
#include <tasks_config.h>
#include <avr/interrupt.h>
#include <xc.h>

Functions

void PreMain (void)
 Runs the Pre-startup Task Manager before entering Main.
int main (void)
 Runs the Startup, Scheduler and optionally Shutdown Task Managers.
 ISR_BADISR_vect ()
 Runs the Interrupts Task Manager to handle interrupt requests without a dedicated ISR.
 ISR_NMI_vect ()
 Runs the Interrupts Task Manager to handle a Non-maskable Interrupt (NMI).
 ISR_BOD_VLM_vect ()
 Runs the Interrupts Task Manager to handle a Brown-out Detector (BOD) interrupt.
 ISR_ERRCTRL_INT_vect ()
 Runs the Interrupts Task Manager to handle a Error Controller (ERRCTRL) channel interrupt.
 ISR_CLKCTRL_INT_vect ()
 Runs the Interrupts Task Manager to handle a Clock Controller (CLKCTRL) interrupt.
 ISR_SLPCTRL_INT_vect ()
 Runs the Interrupts Task Manager to handle a Sleep Controller (SLPCTRL) interrupt.
 ISR_SWDT_INT_vect ()
 Runs the Interrupts Task Manager to handle a Synchronous Watchdog Timer (SWDT) interrupt.
 ISR_NVMCTRL_ERROR_vect ()
 Runs the Interrupts Task Manager to handle a NVM Controller (NVMCTRL) error interrupt.
 ISR_RAMCTRL_INT_vect ()
 Runs the Interrupts Task Manager to handle a RAM Controller (RAMCTRL) error interrupt.
 ISR_CRCSCAN_INT_vect ()
 Runs the Interrupts Task Manager to handle a CRC Scan (CRCSCAN) interrupt.

Variables

 FUSES
 Sets a Framework compatible User Fuses configuration.
 LOCKBITS = LOCKBITS_DEFAULT
 Sets a Memory Sections Access Protection (Lock) Configuration.
volatile bool suspendScheduler = false
 Defines an example boolean for the Application to optionally start the Shutdown sequence.

Detailed Description

Example main file for demonstrating usage of the Framework Task Managers.

Version
1.0.0
Attention
This example file is intended to be modified by the system integrator according to development requirements.

This file is used as an example to demonstrate how the Task Managers can be invoked from the main-file level. The PreMain function is responsible for running the Pre-startup Task Manager, resulting in multiple device resets before completing the Pre-startup sequence and entering the main function. The main function is responsible for calling the Startup Task Manager, which initializes both the Safety System and the Application, before exiting the Safe State and starting Mission Mode. In Mission Mode, the Scheduler Task Manager is called each Fault Detection Time Interval (FDTI) to manage system Watchdogs and run the Application defined schedule, with optional Tasks provided by the Framework. The Application can optionally suspend the Scheduler to run the Shutdown Task Manager, which will re-enter Safe State and maintain safe deep sleep modes (Standby or Power-Down) until the Application requests ending the Shutdown sequence with a system reset. Any Interrupt Requests (IRQs) related to interrupt vectors regarding errors reported by hardware safety mechanisms have dedicated Interrupt Service Routines (ISRs) that call the appropriate Interrupt Task Manager to handle them. Finally, a Framework compliant configuration for User Fuses are provided, with an interface for locking the device with the Lock Fuse.

Note

To configure the compile-time behaviour of Task Managers and the Tasks they are calling, see tasks_config.h.

Note

To configure the compile-time system error handling behaviour and the Error Handler called by Tasks, see error_handler_config.h.

Note

To more easily demonstrate usage without concrete knowledge of Application requirements and to provide a straightforward overview, this example file and main_example.h are intentionally not MISRA C:2025-compliant. These files are considered out of scope for the deviation record, but the violations are listed here for completeness:

  • The headerfile defines global static arrays for scheduling instead of at block scope, when they are only used inside the main function, violating Rule 8.9, but improves readability in the example. Moreover, it ensures that an accidentally empty schedule array task pointer is initialized to NULL, ensuring well defined behavior.
  • This file uses the standard approach for setting the User Fuses and Lock Fuse on AVR, which is compiler-specific and inherently violates Directive 4.6 and Rules 2.8, 8.4, 8.7 and 21.2.
  • This file defines a file scope boolean that is only used inside the main function, which violates Rules 8.4, 8.7 and 8.9. However, an extern declaration can be added in an Application specific header for testing the example, which would eliminate these violations.
  • This file places a function in a special memory section using compiler-specific language extensions (attribute) which is inherently non-compliant and specifically violates Rule 2.1.
  • This file uses the standard approach for defining ISRs on AVR, which is compiler-specific and inherently violates Rules 2.7, 8.2, 8.4, 8.7 and 21.2.