I am having issues in handling the Watchdog fast test in the S32K116 EVB.
I do not perform the disable watchdog in system init, because if I disable it it clears the flags il WDOG_CS_TST and overwrites the content of the TOVAL register.
Saving the to a global variable is not going to work fine because then I lost the content during the INIT_bss(), so I want to use my own function just at the start of the main();
I edited the WDOG_Config from the SDK in order to set also test modes from the config structure; furthermore I start with cs variable set to zero instead of unsetting parameters because bitmasks then don't allow me to set the "user" configuration (see sample):
status_t WDOG_Config(WDOG_Type * const base,
const wdog_user_config_t * wdogUserConfig)
status_t status = STATUS_SUCCESS;
uint32_t cs = base->CS;
bool tmp1 = WDOG_IsEnabled(base);
bool tmp2 = WDOG_IsUpdateEnabled(base);
if ((tmp1 == false) && (tmp2 == true))
/* Clear the bits used for configuration */
cs &= ~(WDOG_CS_WIN_MASK | WDOG_CS_PRES_MASK | WDOG_CS_CLK_MASK | WDOG_CS_INT_MASK |
WDOG_CS_UPDATE_MASK | WDOG_CS_DBG_MASK | WDOG_CS_WAIT_MASK | WDOG_CS_STOP_MASK);
cs = 0;
/* Construct CS register new value */
cs |= WDOG_CS_WIN(wdogUserConfig->winEnable ? 1UL : 0UL);
cs |= WDOG_CS_PRES(wdogUserConfig->prescalerEnable ? 1UL : 0UL);
cs |= WDOG_CS_CLK(wdogUserConfig->clkSource);
cs |= WDOG_CS_INT(wdogUserConfig->intEnable ? 1UL : 0UL);
cs |= WDOG_CS_UPDATE(wdogUserConfig->updateEnable ? 1UL : 0UL);
cs |= WDOG_CS_TST(wdogUserConfig->testMode);
cs |= WDOG_CS_DBG_MASK;
cs |= WDOG_CS_WAIT_MASK;
cs |= WDOG_CS_STOP_MASK;
/* Reset interrupt flags */
cs |= WDOG_CS_FLG_MASK;
/* Enable WDOG in 32-bit mode */
cs |= WDOG_CS_EN_MASK | WDOG_CS_CMD32EN_MASK;
/* The comment LDRA_NOANALYSIS only use to run code coverage */
/* Wait until registers are unlocked */
base->CS = cs;
base->TOVAL = wdogUserConfig->timeoutValue;
base->WIN = wdogUserConfig->windowValue;
/* The comment LDRA_ANALYSIS only use to run code coverage */
/* Wait until the unlock window closes */
/* Wait until the reconfiguration successful */
status = STATUS_ERROR;
Using this function looks like my values are never updated, even if inspecting with embsysregs the values look fine.
I have read and read again the RM and look to the examples, still can't figure what's wrong.
Many questions here:
1) when I unlock the wdog writing to CNT, does the WDOG stop?
2) Do I have to disable the wdog and then update the configuration since I am not disabiling the wdog in system init?
3) DO I have to perform a complete initialization of the watchdog AFTER reset for each test case?
4) What happens when into the WDOG both test case and disable flag are written to the register?
5) What happens if I unlock the WDOG after the POR writing to CNT?
6) To disable the WDOG do I need to write CS AND TOVAL? Section 23.5.1 and 23.5.2 are not helping me in understanding this point.
7) let's assume the first wdog reset happens because of the fast test. Do I need to reconfigure the update flag?I'ts not a POR so I suppose it shall keep the conf value?
8) let's assume both wdog reset went fine and the update is still set to 1.Now I have to set the test register to USER. Do I need to perform a full configuration of the wdog? Can I set back the update flag to 0?