AVR SD Safety Framework 1.0.0
Loading...
Searching...
No Matches
Checksum Manager

Contains API prototypes for the Checksum Manager. More...

Files

file  midware_checksum_manager.c
 Implements APIs for the Checksum Manager.
file  midware_checksum_manager.h
 Contains API prototypes for the Checksum Manager.
file  midware_checksum_manager_diag.c
 Implements APIs for the Checksum Manager Diagnostic.
file  midware_checksum_manager_diag.h
 Contains API prototypes for the Checksum Manager Diagnostic.
file  midware_checksum_manager_diag_asm.h
 Contains assembly API for the Checksum Manager Diagnostic.

Enumerations

enum  flashSection_t
 Type defines for available Flash sections to select when enabling a CRC Scan of Flash. More...

Functions

void MW_ClearCrcPeriodInterrupt (void)
 Clears the flag indicating that a CRC Scan period is done.
errFlag_t MW_GetClearCrcDoneError (void)
 Reads and clears the flag indicating a CRC Scan of Flash is done and returns the scan result.
errFlag_t MW_SetCrcScanInterrupts (bool useNmi, bool usePeriod, bool useDone)
 Configures the interrupt settings for the next CRC Scan of a Flash section.
errFlag_t MW_EnableCrcScan (flashSection_t section, bool useCrc32)
 Enables a Cyclic Redundancy Check (CRC) Scan of the selected Flash section.
bool MW_IsCrcScanBusy (void)
 Checks if a CRC Scan of a Flash section is ongoing.
void MW_AbortCrcScan (void)
 Aborts an ongoing CRC Scan of a Flash section.
errFlag_t MW_StartCrcManualMode (bool useCrc32)
 Starts a Cyclic Redundancy Check (CRC) Manual Mode calculation for manual data feeding.
void MW_FeedCrcManualMode (uint8_t data)
 Feeds one byte into an ongoing CRC Manual Mode calculation.
uint32_t MW_EndCrcManualMode (void)
 Ends a CRC Manual Mode calculation and returns the computed CRC result.
bool MW_IsDiagCrcOngoing (void)
 Checks whether a CRC Scan error injection diagnostic is currently running.
void MW_ReportDiagCrcDone (void)
 Clears the Done interrupt flag and signals the CRC Scan diagnostic to complete and resume execution.
errFlag_t MW_DiagCrcScan (void)
 Performs an error injection diagnostic to detect faults in the CRC Memory Scan mechanism.
void ASM_DiagCrcSleepInstruction (void)
 Issues a SLEEP instruction to enter the configured device sleep mode as part of completing the MW_DiagCrcScan diagnostic.

Detailed Description

Contains API prototypes for the Checksum Manager.

The Checksum Manager provides services to Tasks to ensure correct interaction with features of the CRCSCAN peripheral.

UML Class Diagrams

UML Activity Diagrams

UML Sequence Diagrams

Enumeration Type Documentation

◆ flashSection_t

Type defines for available Flash sections to select when enabling a CRC Scan of Flash.

Warning
The available Flash sections are only valid if enabled in the Flash partitioning configuration of the Fuse settings.
Enumerator
FLASH_SECTION_BOOT 

Boot section

FLASH_SECTION_APPCODE 

Application code section

FLASH_SECTION_APPDATA 

Application data section

FLASH_SECTION_MAX 

Reserved/invalid, used as sentinel value for Flash section.

Function Documentation

◆ ASM_DiagCrcSleepInstruction()

void ASM_DiagCrcSleepInstruction ( void )

Issues a SLEEP instruction to enter the configured device sleep mode as part of completing the MW_DiagCrcScan diagnostic.

◆ MW_AbortCrcScan()

void MW_AbortCrcScan ( void )

Aborts an ongoing CRC Scan of a Flash section.

This function aborts any pending, ongoing or completed CRC Scan of a Flash section by setting the RESET bit. This clears all CRCSCAN interrupt settings and discards the result of the CRC Scan. See MW_EnableCrcScan and MW_IsCrcScanBusy.

Note
This function has no effect while a CRC Manual Mode calculation is ongoing. To abort an ongoing CRC Manual Mode calculation, use MW_EndCrcManualMode and discard the result.

◆ MW_ClearCrcPeriodInterrupt()

void MW_ClearCrcPeriodInterrupt ( void )

Clears the flag indicating that a CRC Scan period is done.

Note
If the periodic interrupt is enabled, the PERIOD flag must be cleared in order to continue the CRC Scan after re-entering the Idle sleep mode.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ MW_DiagCrcScan()

errFlag_t MW_DiagCrcScan ( void )

Performs an error injection diagnostic to detect faults in the CRC Memory Scan mechanism.

This function configures the CRCSCAN to start an error injection diagnostic and enables a scan of the Boot Flash section. The error injection scan only runs while the device is in the Idle sleep mode and will pause when exiting Idle sleep. For this reason, the diagnostic enables the Done interrupt, enters Idle sleep, and depends on MW_ReportDiagCrcDone being called in the CRCSCAN Done interrupt handler whenever MW_IsDiagCrcOngoing returns true in order to complete the diagnostic. Otherwise, the diagnostic will assume another wake-up source interrupt occurred and re-enters sleep. Once completion of the error injection is reported, the error injection result is evaluated before the CRCSCAN configuration is reset.

Note

When error injection is enabled, only the last four words of the Boot section are scanned. This ensures the scan completes in a fixed number of Idle sleep cycles.

Note

While this diagnostic is active, the CRCSCAN module cannot be used for any other purpose.

Warning

This function enters the Idle sleep mode. When enabled, the Synchronous Watchdog Timer (SWDT) is halted during all sleep modes and resumes after wake-up.

Warning

This function assumes that global interrupts are enabled. If global interrupts are disabled, the SLEEP instruction is ignored and the Sleep Error status bit is automatically set in hardware. In such a scenario, the Done interrupt will not occur and the diagnostic will never return unless the scenario is explicitly handled.

Warning

If MW_ReportDiagCrcDone is not called in the Done interrupt handler, but the Done flag is cleared, the diagnostic will continue to re-enter Idle sleep indefinitely and the function will not return.

Warning

This function resets the CRCSCAN configuration after completion. The CRCSCAN must be reconfigured before starting any subsequent scan.

Warning

This function aborts and returns ERROR if a CRC Flash section scan or Manual Mode CRC calculation is already in progress or the result of the previous CRC Flash scan has not been handled to avoid discarding any results.

Warning

This function aborts and returns ERROR if the diagnostic is already in progress.

Warning

This diagnostic is configured to read from the Boot section to complete the error injection, which avoids having to consider Flash partitioning in the User Fuses. If the Boot Section Read Protection (BOOTRP) bit is set in NVMCTRL and this diagnostic is executed while running from either the Application Code or Application Data section, the CRCSCAN is refused read access and the error injection is automatically aborted. However, the Error status is still set, so the diagnostic returns a passing result, even though no error was injected. The BOOTRP bit is only readable when executing in the Boot section, making this condition impossible to detect at run time.

Return values
ERRORFault detected in the CRC Memory Scan mechanism or diagnostic not started.
NO_ERRORNo fault detected in the CRC Memory Scan mechanism.
Here is the caller graph for this function:

◆ MW_EnableCrcScan()

errFlag_t MW_EnableCrcScan ( flashSection_t section,
bool useCrc32 )

Enables a Cyclic Redundancy Check (CRC) Scan of the selected Flash section.

This function configures the CRCSCAN to use the selected CRC algorithm (bit width) and enables a scan of the selected Flash section. The scan only runs while the device is in the Idle sleep mode and will pause when exiting Idle sleep. This function does not enter sleep. The scan duration depends on the configured Flash section length. The result of the scan is checked by calling MW_GetClearCrcDoneError.

Note

Configure CRCSCAN interrupt settings using MW_SetCrcScanInterrupts before enabling a scan. The interrupts can be used as wake-up sources from Idle sleep.

Note

Enabling a scan will lock the CRCSCAN until it is done. Use MW_IsCrcScanBusy to check if a scan is ongoing. An ongoing scan can be aborted by calling MW_AbortCrcScan.

Note

After a scan of a section is complete, starting a new scan of the same section requires calling this function again.

Parameters
sectionThe Flash section to scan.
Warning

The selected Flash section must be valid according to the configured Flash partitioning in the Fuse settings. See the device data sheet for more information. Selecting a section that is not enabled in the Fuse setting will result in the DONE flag being set immediately with an error result and this function will return ERROR.

Warning

If the Boot Section Read Protection (BOOTRP) bit is set in NVMCTRL and a CRC Scan of the Boot section is started while executing from either the Application Code or Application Data section, the CRCSCAN is refused read access and reports an Error status. The BOOTRP bit is only readable when executing from the Boot section, making this condition impossible to detect at run time.

Parameters
useCrc32Selects between using 32-bit CRC width (true) or 16-bit CRC width (false).
Warning

For a CRC Scan to complete successfully, the last 4 (for CRC-32) or 2 (for CRC-16) bytes of the Flash section must contain the stored CRC checksum for comparison with the calculated value. See the device data sheet for more information.

Return values
ERRORInvalid Flash section or CRCSCAN already in use, CRC Scan not enabled.
NO_ERRORCRC Scan successfully enabled.
Warning

This function aborts and returns ERROR if a CRC Flash section scan or Manual Mode CRC calculation is already in progress or the result of the previous CRC Flash scan has not been handled to avoid discarding any results. See MW_IsCrcScanBusy, MW_GetClearCrcDoneError and MW_EndCrcManualMode for more information.

Warning
This function returns ERROR if the BUSY flag is not set after enabling the scan, indicating that the enabling failed. This may result in the CRCSCAN not running after entering Idle sleep and the DONE interrupt never triggering, which could result in the device not waking up from Idle sleep.

◆ MW_EndCrcManualMode()

uint32_t MW_EndCrcManualMode ( void )

Ends a CRC Manual Mode calculation and returns the computed CRC result.

This function reads the current CRC result and exits Manual Mode by setting the RESET bit, which clears the CRC result register for the next calculation. If Manual Mode is not active, no reset is performed and the function returns 0x0.

Note

Ending a Manual Mode calculation clears all CRC Scan interrupt settings. These settings must be reconfigured before starting the next CRC Scan of a Flash section.

Note
This function does not interrupt an ongoing CRC Scan of Flash. To abort a Flash scan, use

MW_AbortCrcScan.

Returns
Computed CRC result as a 16-bit or 32-bit value. Returns 0x0 if Manual Mode is not active.
Note
The result width matches the mode selected when starting Manual Mode in

MW_StartCrcManualMode. For CRC-16, only the lower 16 bits of the 32-bit return value are valid. For CRC-32, all 32 bits are valid.

Note
A CRC value of 0x0 is a valid result and does not necessarily indicate that the function was unsuccessful.
Here is the call graph for this function:

◆ MW_FeedCrcManualMode()

void MW_FeedCrcManualMode ( uint8_t data)

Feeds one byte into an ongoing CRC Manual Mode calculation.

This function passes the provided byte to the CRC calculation in Manual Mode. The CRC value is updated on the next clock cycle according to the active CRC bit width and algorithm. End the calculation and read the result using MW_EndCrcManualMode.

Note

The data can be fed in multiple steps over time and does not need to be supplied in one sequence.

Note

Status checks are skipped to minimize overhead. This function has no effect if Manual Mode is not active. See MW_StartCrcManualMode.

Parameters
dataThe next byte to add to the ongoing CRC calculation.
Here is the call graph for this function:

◆ MW_GetClearCrcDoneError()

errFlag_t MW_GetClearCrcDoneError ( void )

Reads and clears the flag indicating a CRC Scan of Flash is done and returns the scan result.

This function checks if a CRC Scan has been completed and evaluates the result after a scan. If the DONE flag is not set, it returns NO_ERROR. When the DONE flag is set, the status register is read to check the result. An error is returned if either the ERROR or BUSY status flag is set. The DONE flag being set while the status is BUSY could indicate that a previous result was not checked before a new scan was initiated. Moreover, the OK status flag is invalid while BUSY is set.

Return values
ERRORCRC Scan of Flash detected an error or previous scan result lost.
NO_ERRORCRC Scan of Flash not done or scan of Flash detected no errors.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ MW_IsCrcScanBusy()

bool MW_IsCrcScanBusy ( void )

Checks if a CRC Scan of a Flash section is ongoing.

This function reads the CRCSCAN BUSY status flag to determine if a CRC Scan of a Flash section is currently active. While the BUSY flag is set, the CRCSCAN is locked and reconfiguration is limited. See MW_EnableCrcScan and MW_AbortCrcScan.

Note

This check is only applicable to a CRC Scan of Flash and does not indicate whether a CRC Manual Mode calculation is ongoing. See MW_StartCrcManualMode and MW_EndCrcManualMode.

Return values
trueBUSY flag is set, CRC Scan of Flash is ongoing.
falseBUSY flag is not set, CRC Scan of Flash is not ongoing.

◆ MW_IsDiagCrcOngoing()

bool MW_IsDiagCrcOngoing ( void )

Checks whether a CRC Scan error injection diagnostic is currently running.

This function is intended to be called from the CRCSCAN Done interrupt handler to determine whether the interrupt was triggered by completing a normal CRC Scan of Flash or an error injection initiated in MW_DiagCrcScan.

If the diagnostic is ongoing, call MW_ReportDiagCrcDone to complete the diagnostic after returning from the ISR instead of performing normal Done interrupt handling and error reporting.

Return values
trueThe diagnostic is ongoing, handle the Done interrupt with MW_ReportDiagCrcDone.
falseThe diagnostic is not ongoing, handle the Done interrupt normally.
Here is the caller graph for this function:

◆ MW_ReportDiagCrcDone()

void MW_ReportDiagCrcDone ( void )

Clears the Done interrupt flag and signals the CRC Scan diagnostic to complete and resume execution.

This function is intended to be called in the CRCSCAN Done interrupt handler while the diagnostic initiated by MW_DiagCrcScan is ongoing. If the diagnostic is active, the Done flag is cleared to exit the ISR before signaling the diagnostic function to continue and verify the error injection result.

Warning
This function is only intended to be called after calling MW_IsDiagCrcOngoing and it returns true. This function has no effect if MW_IsDiagCrcOngoing returns false. Clear the Done flag normally instead.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ MW_SetCrcScanInterrupts()

errFlag_t MW_SetCrcScanInterrupts ( bool useNmi,
bool usePeriod,
bool useDone )

Configures the interrupt settings for the next CRC Scan of a Flash section.

This function configures which interrupt settings to enable or disable before a Cyclic Redundancy Check (CRC) scan of a Flash section. The settings must be applied before enabling a CRC Scan with MW_EnableCrcScan.

Note

The interrupt settings have no effect when using the CRC Manual Mode.

Warning
Starting and ending Manual Mode calculation using MW_StartCrcManualMode and

MW_EndCrcManualMode, or aborting an ongoing CRC Scan using MW_AbortCrcScan, resets the interrupt settings. The settings must be reconfigured before starting the next CRC Scan of a Flash section.

Parameters
useNmiEnables or disables the non-maskable interrupt (NMI) when a CRC Scan results in an error.
usePeriodEnables or disables the periodic timer feature to generate an interrupt each time 32 Flash words have been processed during a CRC Scan.
useDoneEnables or disables the interrupt that triggers when a CRC Scan is complete, allowing the result to be checked.
Note

When the periodic interrupt feature is enabled, the PERIOD interrupt flag must be cleared before the CRC Scan can continue. See MW_ClearCrcPeriodInterrupt.

Note

When enabled, the PERIOD and DONE interrupts can be used as wake-up sources from Idle sleep.

Return values
ERRORCRC Scan already ongoing or in Manual Mode, CRC Scan interrupts not configured.
NO_ERRORCRC Scan interrupts successfully configured.
Warning
This function aborts and returns ERROR if a CRC Scan of a Flash section or Manual Mode CRC calculation is already in progress, as the settings would have no effect.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ MW_StartCrcManualMode()

errFlag_t MW_StartCrcManualMode ( bool useCrc32)

Starts a Cyclic Redundancy Check (CRC) Manual Mode calculation for manual data feeding.

This function configures the CRCSCAN hardware accelerator to use the selected CRC algorithm (bit width) and enables the Manual Mode. In this mode, an arbitrary amount of data can be fed one byte at a time using MW_FeedCrcManualMode, where the newly calculated CRC value is updated on the following clock cycle. Once all the data is fed, the calculated CRC result is retrieved using MW_EndCrcManualMode, which also ends the CRC Manual Mode calculation.

Note

The data can be fed in multiple steps over time and does not need to be supplied in one sequence.

Note

This function does not reset the previous CRC calculation result, but relies on MW_EndCrcManualMode to do so.

Note

The hardware CRC engine implements:

  • CRC-16/CCITT-FALSE: poly=0x1021, init=0xFFFF, refin=false, refout=false, xorout=0x0000
  • CRC-32/ISO-HDLC (IEEE 802.3): poly=0x04C11DB7, init=0xFFFFFFFF, refin=true, refout=true, xorout=0xFFFFFFFF

Parameters
useCrc32Selects between using 32-bit CRC width (true) or 16-bit CRC width (false).
Note

The selected 'useCrc32' setting determines the valid bit width when reading the output returned from MW_EndCrcManualMode.

Return values
ERRORCRCSCAN already in use, Manual Mode not started.
NO_ERRORManual Mode started successfully.
Warning
This function aborts and returns ERROR if a CRC Flash section scan or Manual Mode CRC calculation is already in progress or the result of the previous CRC Flash scan has not been handled to avoid discarding any results. See MW_IsCrcScanBusy, MW_GetClearCrcDoneError and MW_EndCrcManualMode for more information.