44#define UINT24_MAX 0x00FFFFFFUL
47static volatile bool isWdtCountOngoing =
false;
48static volatile uint16_t beginWdtCount = 0U;
51static bool BackupDisableGlobalInterrupts(
void);
52static void RestoreGlobalInterrupts(
bool wasInterruptsEnabled);
53static void DisableSwdtChannel(
void);
54static void RestoreSwdtChannelConfigs(uint8_t swdtChBackup);
55static bool InjectSwdtExpireError(
void);
70 if (firstCountSample == secondCountSample)
80 bool invalidNewReset = ((newReset >
UINT24_MAX) || (newReset == 0U));
87 const uint32_t swdtChMask = 1UL << ERRCTRL_ESF_13_bp;
96 const bool wasInterruptsEnabled = BackupDisableGlobalInterrupts();
100 DisableSwdtChannel();
108 bool isDiagPassed = InjectSwdtExpireError();
110 RestoreSwdtChannelConfigs(swdtChBackup);
113 RestoreGlobalInterrupts(wasInterruptsEnabled);
130 isWdtCountOngoing =
true;
138 return isWdtCountOngoing;
143 if (isWdtCountOngoing ==
false)
153 isWdtCountOngoing =
false;
159 if (beginWdtCount == endWdtCount)
170 const uint8_t diagWindowConfig = (uint8_t)WDT_WINDOW_OFF_gc;
171 const uint8_t diagPeriodConfig = (uint8_t)WDT_PERIOD_8CLK_gc;
174 bool waitForReset =
true;
179 const uint16_t expireCount = 8U;
180 if (currentCount > expireCount)
182 waitForReset =
false;
190static bool BackupDisableGlobalInterrupts(
void)
192 const uint8_t gieMask = (uint8_t)CPU_I_bm;
194 const bool wasInterruptsEnabled = ((cpuStatusRegVal & gieMask) == gieMask);
198 return wasInterruptsEnabled;
202static void RestoreGlobalInterrupts(
bool wasInterruptsEnabled)
204 if (wasInterruptsEnabled)
211static void DisableSwdtChannel(
void)
213 const uint8_t stateMask = (uint8_t)ERRCTRL_STATE_gm;
214 const uint8_t floatConfig = (uint8_t)(0U << ERRCTRL_FLOAT_bp);
215 const uint8_t severityConfig = (uint8_t)(ERRCTRL_ERRLVL_NOTIFICATION_gc);
216 const uint8_t disabledChConfig = (floatConfig | severityConfig);
224static void RestoreSwdtChannelConfigs(uint8_t swdtChBackup)
226 const uint8_t stateMask = (uint8_t)ERRCTRL_STATE_gm;
233static bool InjectSwdtExpireError(
void)
238 volatile uint8_t waitCount = 0U;
242 const uint8_t expFlagMask = (uint8_t)SWDT_EXP_bm;
244 const bool isExpFlagSet = ((intFlags & expFlagMask) == expFlagMask);
247 const uint32_t swdtChMask = (1UL << ERRCTRL_ESF_13_bp);
249 const bool isSwdtChSet = ((chStatus & swdtChMask) == swdtChMask);
255 bool isDiagPassed = (isExpFlagSet && isSwdtChSet);
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.
uint8_t CPUCTRL_ReadStatusRegister(void)
Reads the SREG register value.
void CPUCTRL_ClearStatusRegister(uint8_t bitmask)
Clears specific bits in the SREG register.
void CPUCTRL_SetStatusRegister(uint8_t bitmask)
Sets specific bits in the SREG register.
uint8_t ERRCTRL_ReadConfigSwdt(void)
Reads the ESCSWDT register value.
uint32_t ERRCTRL_ReadChannelStatus(void)
Reads the ESF register value.
void ERRCTRL_WriteConfigSwdt(uint8_t value)
Overwrites the ESCSWDT register value.
void ERRCTRL_WriteChannelStatus(uint32_t value)
Overwrites the ESF register value.
void ERRCTRL_ModifyControlA(uint8_t groupMask, uint8_t groupConfig)
Modifies specific bit field(s) in the CTRLA register.
void AtomicSectionStart(void)
Backup and disable global interrupts.
void AtomicSectionEnd(void)
Restore global interrupts if previously enabled.
bool IsErrChConfigurable(uint32_t channelMask)
Check Error Controller state and error channels indicated by the channel mask input.
uint8_t SWDT_ReadIntFlags(void)
Reads the INTFLAGS register value.
void SWDT_WriteIntFlags(uint8_t value)
Overwrites the INTFLAGS register value.
void SWDT_WriteResetValue(uint32_t value)
Overwrites the RESET register value.
void SWDT_SetControlA(uint8_t bitmask)
Sets specific bits in the CTRLA register.
void SWDT_WriteControlB(uint8_t value)
Overwrites the CTRLB register value.
uint8_t SWDT_ReadCounterLsb(void)
Reads the CNT0 register value.
errFlag_t MW_DiagWdtExpire(void)
Performs error injection diagnostic to detect faults in the Watchdog Timer (WDT) Expire mechanism.
errFlag_t MW_DiagSwdtExpire(uint32_t newReset)
Performs error injection diagnostic to detect faults in the Synchronous Watchdog Timer (SWDT) Expire ...
#define UINT24_MAX
Defines max value for 24-bit registers.
void MW_DiagWdtCountBegin(void)
Begins diagnostic to detect faults in the Watchdog Timer (WDT) Counter mechanism.
errFlag_t MW_DiagSwdtCount(void)
Performs diagnostic to detect faults in the Synchronous Watchdog Timer (SWDT) Counter mechanism.
bool MW_IsDiagWdtCountOngoing(void)
Checks whether the Watchdog Timer (WDT) Count diagnostic is ongoing.
errFlag_t MW_DiagWdtCountEnd(void)
Completes diagnostic to detect faults in the Watchdog Timer (WDT) Counter mechanism.
uint16_t WDT_ReadCounter(void)
Reads the CNT register value.
void WDT_WriteControlA(uint8_t value)
Overwrites the CTRLA register value.
Contains API prototypes for the Watchdog Manager diagnostics.