FuSa 8-Bit Libraries Safety Framework
Loading...
Searching...
No Matches
main_example.c
Go to the documentation of this file.
1
64
65// Standard Library Includes
66#include <stdbool.h>
67#include <stdlib.h>
68
69// Framework Includes
71#include <main_example.h>
77#include <tasks_config.h>
78
79// Device-specific Includes
80#include <avr/interrupt.h>
81#include <xc.h>
82
117 .WDTCFG = WINDOW_OFF_gc | PERIOD_OFF_gc,
118 .BODCFG = LVL_BODLEVEL1_gc | SAMPFREQ_128HZ_gc | ACTIVE_ENABLE_gc | SLEEP_ENABLE_gc,
119 .SYSCFG0 = FUSE_SYSCFG0_DEFAULT,
120 .SYSCFG1 = WDTMON_ON_gc | MVSYSCFG_DUAL_gc | SUT_0MS_gc,
121 .CODESIZE = FUSE_CODESIZE_DEFAULT,
122 .BOOTSIZE = FUSE_BOOTSIZE_DEFAULT,
123 .PDICFG = FUSE_PDICFG_DEFAULT,
124};
125
140LOCKBITS = LOCKBITS_DEFAULT;
141
154bool suspendScheduler = false;
155
180static void INIT3_SECTION PreMain(void)
181{
182 // Execute the Pre-startup sequence
183 TM_PreStartup(); // Results in multiple device resets, returns when sequence is completed
184}
185
204int main(void)
205{
206 // Initialize Safety System and run all Tasks in Startup Schedule with fixed execution time
208
209 while (suspendScheduler == false) // Managed by the Application
210 {
211 // Manage Watchdogs and run all Tasks in Schedule with fixed execution time
213 }
214
215 // Enter Safe State and maintain safe deep sleep, ending in a system reset
216 TM_Shutdown(appShutdownTask); // Optional Task Manager depending on the Application requirements
217
218 return EXIT_FAILURE; // Never expect to reach this point
219}
220
225ISR(BADISR_vect)
226{
228}
229
234ISR(NMI_vect)
235{
237}
238
243ISR(BOD_VLM_vect)
244{
246}
247
252ISR(ERRCTRL_INT_vect)
253{
255}
256
261ISR(CLKCTRL_INT_vect)
262{
264}
265
270ISR(SLPCTRL_INT_vect)
271{
273}
274
279ISR(SWDT_INT_vect)
280{
282}
283
288ISR(NVMCTRL_ERROR_vect)
289{
291}
292
297ISR(RAMCTRL_INT_vect)
298{
300}
301
306ISR(CRCSCAN_INT_vect)
307{
309}
Defines for placing functions in specific memory sections.
#define INIT3_SECTION
Defines compiler-specific attributes for placing a function in the .init3 memory section.
void TM_InterruptsBod(void)
Executes the task responsible for handling a Brown-out Detector (BOD) interrupt.
void TM_InterruptsPower(void)
Executes the task responsible for handling a Sleep Controller (SLPCTRL) interrupt.
void TM_InterruptsSwdt(void)
Executes the task responsible for handling a Synchronous Watchdog Timer (SWDT) interrupt.
void TM_InterruptsNvm(void)
Executes the task responsible for handling a NVM Controller (NVMCTRL) error interrupt.
void TM_InterruptsClock(void)
Executes the task responsible for handling a Clock Controller (CLKCTRL) interrupt.
void TM_InterruptsDefault(void)
Executes the default task responsible for handling accidental (bad) interrupts.
void TM_InterruptsCrc(void)
Executes the task responsible for handling a CRC Scan (CRCSCAN) interrupt.
void TM_InterruptsRam(void)
Executes the task responsible for handling a RAM Controller (RAMCTRL) error interrupt.
void TM_InterruptsErrorCh(void)
Executes the task responsible for handling a Error Controller (ERRCTRL) channel interrupt.
void TM_InterruptsNmi(void)
Executes the task responsible for handling a Non-maskable Interrupt (NMI).
bool suspendScheduler
Defines an example boolean for the Application to optionally start the Shutdown sequence.
#define DUR_UNTIL_NEXT_SCHEDULE
Configures the duration in system clock cycles until the first Task in the next example Application s...
static const scheduleEntry_t appSchedule[SCHEDULE_LEN]
Defines an example Application Schedule with optional Tasks.
int main(void)
Runs the Startup, Scheduler and optionally Shutdown Task Managers.
FUSES
Sets a Framework compatible User Fuses configuration.
static const scheduleEntry_t appStartupSchedule[STARTUP_SCHEDULE_LEN]
Defines an example Application Startup Schedule with optional Tasks.
static const scheduleEntry_t appShutdownTask
Defines an example Application Shutdown Task schedule entry.
static void INIT3_SECTION PreMain(void)
Runs the Pre-startup Task Manager before entering Main.
LOCKBITS
Sets a Memory Sections Access Protection (Lock) Configuration.
#define SCHEDULE_LEN
Configures the schedule length of the example Application Schedule.
#define STARTUP_SCHEDULE_LEN
Configures the schedule length of the example Application Startup Schedule.
void TM_PreStartup(void)
Manages safety system Pre-startup Tasks.
void TM_Scheduler(const scheduleEntry_t schedule[], uint8_t scheduleLength, uint32_t nextScheduleDeadline)
Manages and synchronizes safety system and application Tasks from a user defined schedule.
void TM_Shutdown(const scheduleEntry_t appShutdownTask)
Manages Tasks that ensure safe execution of device sleeping in Standby and Power-Down.
void TM_Startup(const scheduleEntry_t appStartupSchedule[], uint8_t scheduleLength)
Manages and synchronizes safety system and application startup Tasks.
Defines configurations used in main_example.c.