watchdog: cmsdk_apb: fix period calculation

The previous calculation was multiplying the timeout in milliseconds
by the clock frequency, giving a cycle count 1000x larger than it should
be.

Fix the calculation and rename `reload_s` to `reload_cycles`, as the
cycle count is what this actually contains.

Signed-off-by: Jordan Yates <jordan@embeint.com>
This commit is contained in:
Jordan Yates 2024-07-05 11:32:38 +10:00 committed by Alberto Escolar
parent 6c71a88ef3
commit 74f3b587fc

View file

@ -65,8 +65,8 @@ struct wdog_cmsdk_apb {
/* Keep reference of the device to pass it to the callback */
const struct device *wdog_r;
/* watchdog reload value in sec */
static unsigned int reload_s = CMSDK_APB_WDOG_RELOAD;
/* watchdog reload value in clock cycles */
static unsigned int reload_cycles = CMSDK_APB_WDOG_RELOAD;
static uint8_t flags;
static void (*user_cb)(const struct device *dev, int channel_id);
@ -109,15 +109,15 @@ static int wdog_cmsdk_apb_install_timeout(const struct device *dev,
const struct wdt_timeout_cfg *config)
{
volatile struct wdog_cmsdk_apb *wdog = WDOG_STRUCT;
uint32_t clk_freq_khz = DT_INST_PROP_BY_PHANDLE(0, clocks, clock_frequency) / 1000;
ARG_UNUSED(dev);
/* Reload value */
reload_s = config->window.max *
DT_INST_PROP_BY_PHANDLE(0, clocks, clock_frequency);
reload_cycles = config->window.max * clk_freq_khz;
flags = config->flags;
wdog->load = reload_s;
wdog->load = reload_cycles;
/* Configure only the callback */
user_cb = config->callback;
@ -136,7 +136,7 @@ static int wdog_cmsdk_apb_feed(const struct device *dev, int channel_id)
wdog->intclr = CMSDK_APB_WDOG_INTCLR;
/* Reload */
wdog->load = reload_s;
wdog->load = reload_cycles;
return 0;
}
@ -185,7 +185,7 @@ static int wdog_cmsdk_apb_init(const struct device *dev)
wdog_cmsdk_apb_unlock(dev);
/* set default reload value */
wdog->load = reload_s;
wdog->load = reload_cycles;
#ifdef CONFIG_RUNTIME_NMI
/* Configure the interrupts */