FuSa 8-Bit Libraries Safety Framework
Loading...
Searching...
No Matches
midware_checksum_manager.c
Go to the documentation of this file.
1
22
23// Standard Library Includes
24#include <stdbool.h>
25
26// Framework Includes
27#include <driver_crcscan.h>
29
30// Device-specific Includes
31#include <xc.h>
32
34{
35 // Flag is cleared by writing the bitmask
36 CRCSCAN_WriteIntFlags((uint8_t)CRCSCAN_PERIOD_bm);
37}
38
40{
41 const uint8_t intFlagsRegVal = CRCSCAN_ReadIntFlags();
42 const uint8_t doneMask = (uint8_t)CRCSCAN_DONE_bm;
43 const bool isDoneSet = ((intFlagsRegVal & doneMask) == doneMask);
44
45 errFlag_t flag = NO_ERROR;
46 if (isDoneSet)
47 {
48 const uint8_t statusRegVal = CRCSCAN_ReadStatus();
49 const uint8_t errorMask = (uint8_t)CRCSCAN_ERROR_bm;
50 const uint8_t busyMask = (uint8_t)CRCSCAN_BUSY_bm;
51 const bool isStatusError = ((statusRegVal & errorMask) == errorMask);
52 const bool isStatusBusy = ((statusRegVal & busyMask) == busyMask);
53
54 // If status is busy, the previous result was not checked before starting a new scan
55 if (isStatusError || isStatusBusy)
56 {
57 flag = ERROR;
58 }
59
60 CRCSCAN_WriteIntFlags(doneMask); // Clear DONE flag
61 }
62
63 return flag;
64}
errFlag_t
Defines the error flag used by Middleware services to indicate error detection.
@ NO_ERROR
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.
uint8_t CRCSCAN_ReadStatus(void)
Reads the STATUSA register value.
void CRCSCAN_WriteIntFlags(uint8_t value)
Overwrites the INTFLAGS register value.
uint8_t CRCSCAN_ReadIntFlags(void)
Reads the INTFLAGS register value.