![]() |
AVR SD Safety Framework 1.0.0
|
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. | |
Contains API prototypes for the Checksum Manager.
The Checksum Manager provides services to Tasks to ensure correct interaction with features of the CRCSCAN peripheral.
| enum flashSection_t |
Type defines for available Flash sections to select when enabling a CRC Scan of Flash.
| void ASM_DiagCrcSleepInstruction | ( | void | ) |
Issues a SLEEP instruction to enter the configured device sleep mode as part of completing the MW_DiagCrcScan diagnostic.
| 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.
| void MW_ClearCrcPeriodInterrupt | ( | void | ) |
Clears the flag indicating that a CRC Scan period is done.
| 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.
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.
While this diagnostic is active, the CRCSCAN module cannot be used for any other purpose.
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.
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.
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.
This function resets the CRCSCAN configuration after completion. The CRCSCAN must be reconfigured before starting any subsequent scan.
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.
This function aborts and returns ERROR if the diagnostic is already in progress.
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.
| ERROR | Fault detected in the CRC Memory Scan mechanism or diagnostic not started. |
| NO_ERROR | No fault detected in the CRC Memory Scan mechanism. |
| 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.
Configure CRCSCAN interrupt settings using MW_SetCrcScanInterrupts before enabling a scan. The interrupts can be used as wake-up sources from Idle sleep.
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.
After a scan of a section is complete, starting a new scan of the same section requires calling this function again.
| section | The Flash section to scan. |
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.
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.
| useCrc32 | Selects between using 32-bit CRC width (true) or 16-bit CRC width (false). |
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.
| ERROR | Invalid Flash section or CRCSCAN already in use, CRC Scan not enabled. |
| NO_ERROR | CRC Scan successfully enabled. |
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.
| 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.
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.
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.
| 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.
The data can be fed in multiple steps over time and does not need to be supplied in one sequence.
Status checks are skipped to minimize overhead. This function has no effect if Manual Mode is not active. See MW_StartCrcManualMode.
| data | The next byte to add to the ongoing CRC calculation. |
| 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.
| ERROR | CRC Scan of Flash detected an error or previous scan result lost. |
| NO_ERROR | CRC Scan of Flash not done or scan of Flash detected no errors. |
| 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.
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.
| true | BUSY flag is set, CRC Scan of Flash is ongoing. |
| false | BUSY flag is not set, CRC Scan of Flash is not ongoing. |
| 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.
| true | The diagnostic is ongoing, handle the Done interrupt with MW_ReportDiagCrcDone. |
| false | The diagnostic is not ongoing, handle the Done interrupt normally. |
| 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.
| 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.
The interrupt settings have no effect when using the CRC Manual Mode.
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.
| useNmi | Enables or disables the non-maskable interrupt (NMI) when a CRC Scan results in an error. |
| usePeriod | Enables or disables the periodic timer feature to generate an interrupt each time 32 Flash words have been processed during a CRC Scan. |
| useDone | Enables or disables the interrupt that triggers when a CRC Scan is complete, allowing the result to be checked. |
When the periodic interrupt feature is enabled, the PERIOD interrupt flag must be cleared before the CRC Scan can continue. See MW_ClearCrcPeriodInterrupt.
When enabled, the PERIOD and DONE interrupts can be used as wake-up sources from Idle sleep.
| ERROR | CRC Scan already ongoing or in Manual Mode, CRC Scan interrupts not configured. |
| NO_ERROR | CRC Scan interrupts successfully configured. |
| 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.
The data can be fed in multiple steps over time and does not need to be supplied in one sequence.
This function does not reset the previous CRC calculation result, but relies on MW_EndCrcManualMode to do so.
The hardware CRC engine implements:
| useCrc32 | Selects between using 32-bit CRC width (true) or 16-bit CRC width (false). |
The selected 'useCrc32' setting determines the valid bit width when reading the output returned from MW_EndCrcManualMode.
| ERROR | CRCSCAN already in use, Manual Mode not started. |
| NO_ERROR | Manual Mode started successfully. |