59#define GPR_ERRINJRSN_GP 6U
60#define GPR_ERRINJRSN_GM 0xC0U
63#define GPR_RSTRSN_GP 0U
64#define GPR_RSTRSN_GM 0x3FU
67#define GPR_CHECKSUM_GP 4U
68#define GPR_CHECKSUM_GM 0xF0U
71#define GPR_IS_ERRINJ0_BM 0x80U
72#define GPR_IS_ERRINJ1_BM 0x01U
75#define GPR_CPU_FAULT0_BM 0x04U
76#define GPR_CPU_FAULT1_BM 0x10U
79#define GPR_SWDT_FAULT0_BM 0x02U
80#define GPR_SWDT_FAULT1_BM 0x08U
83#define GPR_WDT_FAULT0_BM 0x01U
84#define GPR_WDT_FAULT1_BM 0x04U
87#define GPR_IO_FAULT0_BM 0x08U
88#define GPR_IO_FAULT1_BM 0x20U
91#define GPR_INV_INPUT0_BM 0x40U
92#define GPR_INV_INPUT1_BM 0x02U
98static void SetErrInjFlag(
void);
99static void SetCpuInjFlag(
void);
100static void SetWdtInjFlag(
void);
101static void SetSwdtInjFlag(
void);
102static void SetIoFloatFlag(
void);
103static void SetInvalidInputFlag(
void);
105static void ClearErrInjFlag(
void);
106static void ClearCpuInjFlag(
void);
107static void ClearWdtInjFlag(
void);
108static void ClearSwdtInjFlag(
void);
109static void ClearIoFloatFlag(
void);
111static bool GetErrInjFlag(
void);
112static bool GetCpuInjFlag(
void);
113static bool GetWdtInjFlag(
void);
114static bool GetSwdtInjFlag(
void);
115static bool GetIoFloatFlag(
void);
116static bool GetInvalidInputFlag(
void);
118static bool IsErrInjFlagCorrupt(
void);
119static bool IsCpuInjFlagCorrupt(
void);
120static bool IsWdtInjFlagCorrupt(
void);
121static bool IsSwdtInjFlagCorrupt(
void);
122static bool IsIoFloatFlagCorrupt(
void);
123static bool IsInvalidInputFlagCorrupt(
void);
125static bool IsChecksumCorrupt(
void);
126static void UpdateValsChecksum(
void);
127static uint8_t CalculateChecksum(uint16_t value);
128static uint16_t ConcatPersistentVals(
void);
133 const uint8_t busErrMask = (uint8_t)CPU_BUSERR_bm;
134 const bool isBusError = ((regVal & busErrMask) == busErrMask);
149 const uint8_t dataParityMask = (uint8_t)CPU_PARITYD_bm;
150 const bool isParityError = ((regVal & dataParityMask) == dataParityMask);
165 const uint8_t instrParityMask = (uint8_t)CPU_PARITYI_bm;
166 const bool isParityError = ((regVal & instrParityMask) == instrParityMask);
181 const uint8_t opcodeMask = (uint8_t)CPU_OPC_bm;
182 const bool isOpcodeError = ((regVal & opcodeMask) == opcodeMask);
197 const uint8_t stackLimitMask = (uint8_t)CPU_SPLIM_bm;
198 const bool isStackError = ((regVal & stackLimitMask) == stackLimitMask);
213 const uint8_t eccCompMask = (uint8_t)RAMCTRL_COMP_bm;
214 const bool isEccError = ((regVal & eccCompMask) == eccCompMask);
229 const uint8_t ecc1Mask = (uint8_t)RAMCTRL_ECC1_bm;
230 const bool isEcc1Error = ((regVal & ecc1Mask) == ecc1Mask);
245 const uint8_t ecc2Mask = (uint8_t)RAMCTRL_ECC2_bm;
246 const bool isEcc2Error = ((regVal & ecc2Mask) == ecc2Mask);
261 const uint8_t controlMask = (uint8_t)RAMCTRL_PARITYC_bm;
262 const uint8_t addressMask = (uint8_t)RAMCTRL_PARITYA_bm;
263 const uint8_t dataMask = (uint8_t)RAMCTRL_PARITYD_bm;
264 const uint8_t parityMask = (controlMask | addressMask | dataMask);
265 const bool isControlError = ((regVal & controlMask) == controlMask);
266 const bool isAddressError = ((regVal & addressMask) == addressMask);
267 const bool isDataError = ((regVal & dataMask) == dataMask);
270 if (isControlError || isAddressError || isDataError)
282 const uint8_t eccCompMask = (uint8_t)NVMCTRL_COMP_bm;
283 const bool isCompError = ((regVal & eccCompMask) == eccCompMask);
298 const uint8_t flashEcc1Mask = (uint8_t)NVMCTRL_FECC1_bm;
299 const bool isEcc1Error = ((regVal & flashEcc1Mask) == flashEcc1Mask);
314 const uint8_t flashEcc2Mask = (uint8_t)NVMCTRL_FECC2_bm;
315 const bool isEcc2Error = ((regVal & flashEcc2Mask) == flashEcc2Mask);
330 const uint8_t controlMask = (uint8_t)NVMCTRL_PARITYC_bm;
331 const uint8_t addressMask = (uint8_t)NVMCTRL_PARITYA_bm;
332 const uint8_t dataMask = (uint8_t)NVMCTRL_PARITYD_bm;
333 const uint8_t parityMask = (controlMask | addressMask | dataMask);
334 const bool isControlError = ((regVal & controlMask) == controlMask);
335 const bool isAddressError = ((regVal & addressMask) == addressMask);
336 const bool isDataError = ((regVal & dataMask) == dataMask);
339 if (isControlError || isAddressError || isDataError)
351 const uint8_t eepromEcc1Mask = (uint8_t)NVMCTRL_EECC1_bm;
352 const bool isEcc1Error = ((regVal & eepromEcc1Mask) == eepromEcc1Mask);
367 const uint8_t eepromEcc2Mask = (uint8_t)NVMCTRL_EECC2_bm;
368 const bool isEcc2Error = ((regVal & eepromEcc2Mask) == eepromEcc2Mask);
388 const uint8_t eccAllOnesMask = (uint8_t)NVMCTRL_ECCALL1_gm;
389 const uint8_t groupConfig = ((uint8_t)config << NVMCTRL_ECCALL1_gp);
397 const uint16_t ramAddrStart = INTERNAL_SRAM_START;
398 const uint16_t ramAddrEnd = INTERNAL_SRAM_START + INTERNAL_SRAM_SIZE - 1U;
399 const bool isInvalidRamAddr = ((splimAddr < ramAddrStart) || (splimAddr > ramAddrEnd));
400 if (isInvalidRamAddr)
421 SetInvalidInputFlag();
429 SetFlagType(flagType);
433 ClearFlagType(flagType);
442 SetInvalidInputFlag();
448 if (IsChecksumCorrupt())
472 UpdateValsChecksum();
477 bool isFlagSet =
false;
482 isFlagSet = GetErrInjFlag();
485 isFlagSet = GetCpuInjFlag();
488 isFlagSet = GetWdtInjFlag();
491 isFlagSet = GetSwdtInjFlag();
494 isFlagSet = GetIoFloatFlag();
497 SetInvalidInputFlag();
506 uint8_t persistentVal = 0xFFU;
511 SetInvalidInputFlag();
514 return persistentVal;
533 return persistentVal;
539 bool wasInvalidInput = IsInvalidInputFlagCorrupt() || GetInvalidInputFlag();
546 if (IsIoFloatFlagCorrupt())
552 if (IsErrInjFlagCorrupt())
558 if (IsCpuInjFlagCorrupt())
564 if (IsWdtInjFlagCorrupt())
570 if (IsSwdtInjFlagCorrupt())
582 bool wasInvalidInput = GetInvalidInputFlag();
583 bool isValsCorrupted = IsChecksumCorrupt();
584 bool isCorrupted = wasInvalidInput || isValsCorrupted;
591 const uint8_t clearValue = 0x00U;
592 const uint8_t clearMask
601 const uint8_t clearValue = 0x00U;
657static void SetErrInjFlag(
void)
664static void SetCpuInjFlag(
void)
671static void SetWdtInjFlag(
void)
678static void SetSwdtInjFlag(
void)
685static void SetIoFloatFlag(
void)
692static void SetInvalidInputFlag(
void)
699static void ClearErrInjFlag(
void)
706static void ClearCpuInjFlag(
void)
713static void ClearWdtInjFlag(
void)
720static void ClearSwdtInjFlag(
void)
727static void ClearIoFloatFlag(
void)
734static bool GetErrInjFlag(
void)
738 bool isBothBitsSet = ((gprRegVal3 & combinedMask) == combinedMask);
740 return isBothBitsSet;
744static bool GetCpuInjFlag(
void)
751 return (cpuInjFlag0 && cpuInjFlag1) ==
true;
755static bool GetWdtInjFlag(
void)
762 return (wdtInjFlag0 && wdtInjFlag1) ==
true;
766static bool GetSwdtInjFlag(
void)
773 return (swdtInjFlag0 && swdtInjFlag1) ==
true;
777static bool GetIoFloatFlag(
void)
784 return (ioFloatFlag0 && ioFloatFlag1) ==
true;
788static bool GetInvalidInputFlag(
void)
792 bool isBothBitsSet = ((gprRegVal3 & combinedMask) == combinedMask);
794 return isBothBitsSet;
798static bool IsErrInjFlagCorrupt(
void)
804 bool isCorrupt =
true;
805 if (isFlagBit0Set == isFlagBit1Set)
814static bool IsCpuInjFlagCorrupt(
void)
821 bool isCorrupt =
true;
822 if (cpuInjFlag0 == cpuInjFlag1)
831static bool IsWdtInjFlagCorrupt(
void)
838 bool isCorrupt =
true;
839 if (wdtInjFlag0 == wdtInjFlag1)
848static bool IsSwdtInjFlagCorrupt(
void)
855 bool isCorrupt =
true;
856 if (swdtInjFlag0 == swdtInjFlag1)
865static bool IsIoFloatFlagCorrupt(
void)
872 bool isCorrupt =
true;
873 if (ioFloatFlag0 == ioFloatFlag1)
882static bool IsInvalidInputFlagCorrupt(
void)
888 bool isCorrupt =
true;
889 if (invalidFlag0 == invalidFlag1)
898static bool IsChecksumCorrupt(
void)
900 uint16_t persistentVals = ConcatPersistentVals();
902 uint8_t currentChecksum = CalculateChecksum(persistentVals);
906 bool isCorrupt = (currentChecksum != storedChecksum);
912static void UpdateValsChecksum(
void)
914 uint16_t persistentVals = ConcatPersistentVals();
916 uint8_t newChecksum = CalculateChecksum(persistentVals);
923static uint8_t CalculateChecksum(uint16_t value)
925 uint16_t shiftedVal = value;
926 uint8_t numOnes = 0U;
928 while (shiftedVal != 0U)
930 numOnes += (uint8_t)(shiftedVal & 1U);
931 shiftedVal = shiftedVal >> 1;
938static uint16_t ConcatPersistentVals(
void)
Defines error flag type for indicating detected errors in Middleware services.
errFlag_t
Defines the error flag used by Middleware services to indicate error detection.
void CPUCTRL_WriteSplim(uint16_t value)
Overwrites the SPLIM register value.
void CPUCTRL_SetControlA(uint8_t bitmask)
Sets specific bits in the CTRLA register.
uint8_t CPUCTRL_ReadIntFlags(void)
Reads the INTFLAGS register value.
void CPUCTRL_WriteIntFlags(uint8_t value)
Overwrites the INTFLAGS register value.
uint8_t GPR_ReadRegister2(void)
Reads the GPR2 register value.
void GPR_ModifyRegister1(uint8_t groupMask, uint8_t groupConfig)
Modifies specific bit field(s) in the GPR1 register.
void GPR_ClearRegister2(uint8_t bitmask)
Clears specific bits in the GPR2 register.
void GPR_ModifyRegister2(uint8_t groupMask, uint8_t groupConfig)
Modifies specific bit field(s) in the GPR2 register.
uint8_t GPR_ReadRegister1(void)
Reads the GPR1 register value.
void GPR_WriteRegister0(uint8_t value)
Overwrites the GPR0 register value.
void GPR_ClearRegister3(uint8_t bitmask)
Clears specific bits in the GPR3 register.
void GPR_WriteRegister3(uint8_t value)
Overwrites the GPR3 register value.
void GPR_SetRegister2(uint8_t bitmask)
Sets specific bits in the GPR2 register.
uint8_t GPR_ReadRegister3(void)
Reads the GPR3 register value.
uint8_t GPR_ReadRegister0(void)
Reads the GPR0 register value.
void GPR_SetRegister3(uint8_t bitmask)
Sets specific bits in the GPR3 register.
void GPR_WriteRegister1(uint8_t value)
Overwrites the GPR1 register value.
void MW_ClearPersistentVals(void)
Clears all stored persistent values in GPR.
void MW_StorePersistentVal(persistentVal_t valueType, uint8_t value)
Stores a value in General Purpose Registers (GPR) for perserving data between resets.
errFlag_t MW_SetRamStackLimit(uint16_t splimAddr, bool lockEnable)
Sets the Stack Pointer Limit value and optionally locks the value to prevent modification.
persistentVal_t
Enum for persistent values used to store data between non-POR/BOR device resets.
errFlag_t MW_GetClearRamParityError(void)
Reads and clears the flag indicating a bus parity error detected in the RAM controller.
errFlag_t MW_GetClearNvmEepromEcc2Error(void)
Reads and clears the flag indicating an ECC multi-bit error in EEPROM.
errFlag_t MW_GetClearNvmFlashEcc1Error(void)
Reads and clears the flag indicating a ECC single-bit error in Flash.
void MW_StorePersistentFlag(persistentFlag_t flagType, bool flag)
Stores two redundant boolean flags in General Purpose Registers (GPR) for perserving data between res...
bool MW_GetPersistentFlag(persistentFlag_t flagType)
Reads two redundant bits for each boolean flags in General Purpose Registers (GPR) that is stored for...
bool MW_IsPersistentFlagsCorrupt(void)
Compares two redundant bits for each boolean flags in General Purpose Registers (GPR) and checks if a...
errFlag_t MW_GetClearCpuDataParityError(void)
Reads and clears the flag indicating a data bus parity error in the CPU.
persistentFlag_t
Enum for persistent flags used to store data between non-POR/BOR device resets.
errFlag_t MW_GetClearNvmEccCompError(void)
Reads and clears the flag indicating a ECC comparator error in the NVM controller.
errFlag_t MW_SetNvmEccAllOnes(eccAllOnes_t config)
Sets ECC all Ones (ECCALL1) scheme.
void MW_ClearPersistentFlags(void)
Clears all stored persistent flags in GPR.
errFlag_t MW_GetClearCpuInstrParityError(void)
Reads and clears the flag indicating a instruction bus parity error in the CPU.
uint8_t MW_GetPersistentVal(persistentVal_t valueType)
Reads a value in General Purpose Registers (GPR) that is stored for preserving data between resets.
bool MW_IsPersistentValsCorrupt(void)
Checks if any of the stored persistent values are corrupted.
eccAllOnes_t
Type defines for available "ECC all ones" (ECCALL1) options.
errFlag_t MW_GetClearNvmEepromEcc1Error(void)
Reads and clears the flag indicating an ECC single-bit error in EEPROM.
errFlag_t MW_GetClearNvmParityError(void)
Reads and clears the flag indicating a bus parity error detected in the NVM controller.
errFlag_t MW_GetClearNvmFlashEcc2Error(void)
Reads and clears the flag indicating a ECC multi-bit error in Flash.
errFlag_t MW_GetClearCpuOpcodeError(void)
Reads and clears the flag indicating an illegal opcode error in the CPU.
errFlag_t MW_GetClearRamStackError(void)
Reads and clears the flag indicating a stack pointer limit error in SRAM.
errFlag_t MW_GetClearRamEccCompError(void)
Reads and clears the flag indicating a ECC comparator error in the RAM controller.
errFlag_t MW_GetClearRamEcc1Error(void)
Reads and clears the flag indicating an ECC single-bit error in SRAM.
errFlag_t MW_GetClearBusError(void)
Reads and clears the flag indicating an error in the Bus Matrix.
errFlag_t MW_GetClearRamEcc2Error(void)
Reads and clears the flag indicating an ECC multi-bit error in SRAM.
uint8_t NVMCTRL_ReadIntFlagsB(void)
Reads the INTFLAGSB register value.
void NVMCTRL_WriteIntFlagsB(uint8_t value)
Overwrites the INTFLAGSB register value.
void NVMCTRL_ModifyControlC(uint8_t groupMask, uint8_t groupConfig)
Modifies specific bit field(s) in the CTRLC register.
uint8_t RAMCTRL_ReadIntFlags(void)
Reads the INTFLAGS register value.
void RAMCTRL_WriteIntFlags(uint8_t value)
Overwrites the INTFLAGS register value.
#define GPR_INV_INPUT0_BM
#define GPR_CPU_FAULT1_BM
#define GPR_WDT_FAULT1_BM
#define GPR_IS_ERRINJ0_BM
#define GPR_INV_INPUT1_BM
#define GPR_IS_ERRINJ1_BM
#define GPR_WDT_FAULT0_BM
#define GPR_CPU_FAULT0_BM
#define GPR_SWDT_FAULT0_BM
#define GPR_SWDT_FAULT1_BM