AVR SD Safety Framework 1.0.0
Loading...
Searching...
No Matches
Measurements

This page contains information regarding measurements.

WCET Estimation Methodology

This section describes how execution times are measured for functions in the AVR SD Safety Framework. The measurements are intended as input when selecting Task duration values. They are not formal WCET bounds.

Test conditions are selected by inspecting the source code and identifying a comparatively long relevant path through each function. Configuration-controlled functionality is enabled where it increases the executed work, and early-return paths are avoided unless they represent the relevant measured case.

Measurement Scope

The measurements cover all Tasks called by the Task Managers and all middleware diagnostic functions. The intervals corresponding to DUR_UNTIL_FIRST_SCHEDULE and DUR_UNTIL_NEXT_SCHEDULE are also measured.

Measurements are performed using the -O1, -O2, -O3 and -Os compiler optimization levels.

Measurement Setup

Two TCB peripherals configured in cascade mode count system-clock cycles. The timers are started immediately before the measured function and stopped immediately after it returns. The timer start and stop overhead is measured during initialization and subtracted from each result.

The target runs at a configured 20 MHz system clock and uses an explicit default fuse configuration. The compiler, DFP, target device and build environment are identified in the corresponding release notes.

Measurement Configuration

The measurement project is built with TEST. Several configuration options that are compile-time constants in a production build are variables in this build. Their checks are therefore evaluated at run time and may add a small amount of execution time.

The measurement configuration enables all optional startup diagnostics and all entries in the periodic latent-diagnostic queue. Periodic WDT and SWDT count diagnostics are enabled. Error reporting uses NOTIFICATION, and the notification log contains five entries.

Unless stated otherwise in the result table, underlying peripheral error flags are not set and state-dependent error-reporting paths are excluded. The result table identifies the relevant arranged state and any important exclusions.

Measurement Execution

Each function is called under the configured test conditions and measured once per compiler optimization level. Diagnostic return values and required setup or cleanup operations are checked. A failed diagnostic or measurement setup causes the measurement run to report FAIL.

Functions that intentionally reset the device or otherwise cannot provide a meaningful return measurement are reported as Not measured.

CRCSCAN Measurements

MW_DiagCrcScan is measured from function entry until return with global interrupts and the CRCSCAN ISR enabled. The result includes CRCSCAN setup, Idle sleep, CRC interrupt handling, result verification and cleanup under the fixed test configuration.

MW_ReportDiagCrcDone and T_HandleCrcInterrupt are measured inside the CRCSCAN ISR. ISR entry and exit are therefore excluded from these individual measurements. T_HandleCrcInterrupt is measured for regular Flash-scan completion and diagnostic completion, and the largest result is reported.

T_VerifyFlashIntegrity is not measured because its elapsed time depends on the configured Flash sections, CRC configuration, sleep and interrupt timing.

Measurement Results

The result table contains the measurements for -O1, -O2, -O3 and -Os, the maximum measured value and a comment describing the relevant test conditions.

The maximum is the largest valid measurement across the compiler optimization levels. Default Task durations are conservative overestimates based on this value. The selected defaults are provided in tasks_config.h, or in the corresponding example configuration where applicable. The System Integrator should adjust these values for the final application configuration and timing requirements.

Measurement Limitations

The results apply to the documented configuration and measured paths. They do not include application execution between Task Manager calls, unrelated interrupts, scheduling delays or state-dependent error handling unless explicitly stated.

Measurements that include waiting for a hardware diagnostic to complete can vary with peripheral-clock and analog operating conditions.

The measurements do not demonstrate that every feasible execution path has been exercised and must not be treated as formal WCET bounds.

Measurement Result Table

Measurement NameMeasured Cycles O1Measured Cycles O2Measured Cycles O3Measured Cycles OsMaximumComment
T_HandlePreStartupErrors11549269179981154All four persistent pre-startup error flags set.
T_InitSafetySystem30382728273130173038All optional initialization paths enabled.
T_RunStartupDiagnostics1383012237121821549815498All optional startup diagnostics enabled.
T_HandleResetReason407388377414414Valid software-reset information. Includes the reset callback.
T_StartMissionMode246236236241246Heartbeat and strict safe-state handling enabled.
T_RunNextLatentFaultDiag14941401152016311631Maximum of all 20 enabled diagnostics. Measures only the Begin call for diagnostics split into Begin and End.
T_EnterIdleSleep7472727777Global interrupts disabled so sleep is refused. Does not include sleep or wake-up.
T_HandleWatchdog147139139142147WDT count diagnostic enabled and completed successfully.
T_HandleSyncWatchdog347330330334347Called inside the open window. Intentional waiting is excluded.
T_HandleNotificationErrors67866644664473887388All 17 error channels set. Notification log full. Entries handled using an empty callback.
DUR_UNTIL_FIRST_SCHEDULE237208161212237From return of T_StartMissionMode to the first T_HandleSyncWatchdog call inside the first TM_Schedule.
DUR_UNTIL_NEXT_SCHEDULE362284237282362From return of the final T_HandleSyncWatchdog call in one TM_Schedule to the first T_HandleSyncWatchdog call in the next TM_Schedule.
T_EnsureSafeStateNot measuredNot measuredNot measuredNot measuredNot measuredPart of the reset-driven pre-startup sequence.
T_DetermineResetReasonNot measuredNot measuredNot measuredNot measuredNot measuredPart of the reset-driven pre-startup sequence.
T_RunResetDiagnosticFsmNot measuredNot measuredNot measuredNot measuredNot measuredIntentionally resets the device.
T_HandleNmiInterruptNot measuredNot measuredNot measuredNot measuredNot measuredHalts until a timeout resets the device.
T_HandleBodInterrupt3934343839
T_HandleClockInterrupt774758758833833
T_HandlePowerInterrupt522509509575575No VMON diagnostic completion pending.
T_HandleSwdtInterrupt425405405428428
T_HandleNvmInterrupt610601601667667
T_HandleRamInterrupt349342342389389
T_HandleCrcInterrupt220205205200220Regular CRC completion path. This was the longer path.
T_HandleBadInterrupt123112112110123
T_HandleErrorChInterrupt630608556624630Maximum of 17 measurements with one individual error channel set at a time. Underlying peripheral error flags not set.
MW_DiagClockCfd0Begin337309309356356Begin call only. The asynchronous diagnostic duration is excluded.
MW_IsDiagCfd0Ongoing1010101616Called while the CFD0 diagnostic is active.
MW_DiagClockCfd0End302273273328328Called after the CFD0 diagnostic has completed.
MW_DiagClockCfd1Begin338310310357357Begin call only. The asynchronous diagnostic duration is excluded.
MW_IsDiagCfd1Ongoing1010101616Called while the CFD1 diagnostic is active.
MW_DiagClockCfd1End302273273328328Called after the CFD1 diagnostic has completed.
MW_DiagClockCfm014441352145015791579
MW_DiagClockCfm114441352147115791579
MW_DiagCpuLockstepNot measuredNot measuredNot measuredNot measuredNot measuredIntentionally resets the device.
MW_DiagErrorChannelSplim409386346479479
MW_DiagErrorChannelCfd0409386356493493
MW_DiagErrorChannelCfd1409386356493493
MW_DiagErrorChannelCfm0409386356493493
MW_DiagErrorChannelCfm1409386356493493
MW_DiagErrorChannelEeprom409386356493493
MW_DiagErrorChannelEvsys0409386356493493
MW_DiagErrorChannelEvsys1409386356472472
MW_DiagRamParity90171171110771077
MW_DiagNvmParity134498598515811581
MW_DiagRamEcc97782382311081108
MW_DiagNvmFlashEcc114191491413191319
MW_DiagNvmEepromEcc92575475410811081
MW_DiagVmonOverBegin339326316339339Begin call only. The asynchronous diagnostic duration is excluded.
MW_IsDiagVmonOverDone3639394646Called while the overvoltage diagnostic is active.
MW_DiagVmonOverEnd294274273284294Called after overvoltage detection has completed.
MW_DiagVmonUnderBegin338323316338338Begin call only. The asynchronous diagnostic duration is excluded.
MW_IsDiagVmonUnderDone3839394646Called while the undervoltage diagnostic is active.
MW_DiagVmonUnderEnd293274270283293Called after undervoltage detection has completed.
MW_IsDiagVmonOngoing1010101616Called while a VMON diagnostic is active.
MW_DiagSwdtCount1009898110110
MW_DiagSwdtExpire489453453599599
MW_DiagWdtCountBegin8782828989Begin call only.
MW_IsDiagWdtCountOngoing1010101616Called while the WDT count diagnostic is active.
MW_DiagWdtCountEnd106105105112112Called after the WDT counter has incremented.
MW_DiagWdtExpireNot measuredNot measuredNot measuredNot measuredNot measuredIntentionally resets the device.
MW_IsDiagCrcOngoing1010101616Called while a CRC diagnostic is active.
MW_ReportDiagCrcDone2425252425Called while a CRC diagnostic is active.
MW_DiagCrcScan386370370387387Includes the complete error-injection scan, Idle sleep and CRC interrupt handling.
T_InitSafeShutdown11961105110511491196Safe-state entry and clock-monitor shutdown enabled.
T_HandleShutdownWatchdogs201174174179201Called after T_InitSafeShutdown has configured the watchdogs.
T_EnterShutdownSleepNot measuredNot measuredNot measuredNot measuredNot measuredDepends on sleep and wake-up conditions.
T_VerifyFlashIntegrityNot measuredNot measuredNot measuredNot measuredNot measuredDepends on configured Flash sections, CRC configuration, sleep and interrupt timing.
T_RestartDeviceNot measuredNot measuredNot measuredNot measuredNot measuredIntentionally resets the device.

Stack Depth Estimation Methodology

This section describes how the stack depth of the Safety Framework is estimated and how the measurement results should be interpreted.

The Safety Framework uses a layered call structure without recursion or run-time-sized stack allocation. Calls proceed from the Task Managers through Tasks, middleware and drivers without looping back through the call hierarchy. The normal call-chain depth is therefore bounded.

Interrupts can add further call chains on top of the interrupted code. The measurement calculates the deepest base call chain and the stack depth of each Interrupt Service Routine separately, then combines them according to the supported interrupt nesting.

Measurement Scope

The analysis covers the Safety Framework code reached from main, pre-startup, the Task Managers and the Framework Interrupt Service Routines. All optional startup diagnostics and all entries in the periodic latent-fault diagnostic queue are enabled.

Application code and Application Interrupt Service Routines are not included.

Measurements are performed using the -O1, -O2, -O3 and -Os XC8 compiler optimization levels.

Measurement Method

The Safety Framework is compiled using XC8 with the -fstack-usage option. The generated stack-usage information provides the stack frame size of each compiler-generated function.

The linked ELF file is disassembled using avr-objdump. The disassembly is used to determine the stack usage of assembly functions and reconstruct the calls between functions.

The stack depth of each call chain is calculated by adding the function stack frames and the two-byte return address added by each function call. Tail calls reuse the caller's stack frame and do not add a return address. Interrupt measurements also include the program counter stored by the interrupt hardware and the registers saved when entering the Interrupt Service Routine.

Calls through Schedules, callback tables and handler tables are resolved using the contents of the linked build. The analysis fails if a call cannot be resolved, a function has no calculated stack usage, or recursion or run-time-sized stack allocation is detected.

The XC8 -mchp-stack-usage analysis is also generated. It cannot calculate the complete Safety Framework stack depth because calls to functions written in assembly are reported as indeterminate stack adjustments. The measurement method has been verified against -mchp-stack-usage using call chains containing only compiler-generated functions, where both methods produce the same result.

Measurement Results

The result table contains one column for each compiler optimization level. The Max Stack Depth column contains the largest value across these optimization levels.

Base context is the deepest call chain reached from main or pre-startup without an interrupt.

Each ISR row contains the deepest call chain reached from that interrupt entry point.

Base context, deepest ISR and NMI combines the deepest base call chain, the deepest maskable ISR and the NMI. This applies when no interrupt vector is assigned to priority level 1, since two maskable interrupts cannot then be active at the same time.

Base context, two deepest ISRs and NMI also includes a second maskable ISR. This applies when an interrupt vector is assigned to priority level 1 using INIT_INT_LVL1. This result is used when defining the documented INIT_STACK_LIMIT.

Measurement Limitations

The results apply to the compiler, DFP, build configuration and Safety Framework version identified in the corresponding release notes.

The combined results are conservative overestimates because they assume that each interrupt occurs at the point of greatest stack usage in the preceding context, with the non-returning NMI occurring last, and do not account for critical sections or other states that may prevent the assumed nesting. The stack depth reached during normal execution is therefore likely to be significantly lower.

Measurement Result Table

Measurement NameMeasured Stack Depth O3Measured Stack Depth OsMeasured Stack Depth O1Measured Stack Depth O2Max Stack DepthComment
Base context6973736973Task Manager to Task to middleware to driver, without any interrupt. Deepest chain from main and from the Pre-startup hook.
ERRCTRL_INT ISR5250535253
RAMCTRL_INT ISR4746484748
NVMCTRL_ERROR ISR4746484748
CRCSCAN_INT ISR4542484548
Unhandled vector ISR4542484548
SWDT_INT ISR4746484748
BOD_VLM ISR4542484548
NMI ISR4744484748
SLPCTRL_INT ISR4746484748
CLKCTRL_INT ISR4744484748
Base context, deepest ISR and NMI168167174168174One maskable interrupt active. Applies when no vector is assigned to priority level 1.
Base context, two deepest ISRs and NMI215213222215222Two maskable interrupts active. Applies when a vector is assigned to priority level 1.