Lines Matching +full:timestamp +full:- +full:prescaler

4  * SPDX-License-Identifier: Apache-2.0
18 * +---------------------+ +-----------------+
19 * LFCLK --->| T0 Prescale Counter |-+->| 16-Bit T0 Timer |--------> T0 Timer
21 * +---------------------+ | +-----------------+
22 * +---------------------------------+
24 * | +-------------------+ +-----------------+
25 * +--->| Watchdog Prescale |--->| 8-Bit Watchdog |-----> Watchdog Event/Reset
27 * +-------------------+ +-----------------+
49 * Maximum watchdog window time. Keep the timer and watchdog clock prescaler
50 * (TWCP) to 0x5. Since the watchdog counter is 8-bits, maximum time supported
73 /* t0 timer wake-up input source configuration */
79 /* Timestamp of touching watchdog last time */
92 #define HAL_INSTANCE(dev) ((struct twd_reg *)((const struct wdt_npcx_config *)(dev)->config)->base)
101 inst->T0CSR = (inst->T0CSR & ~BIT(NPCX_T0CSR_WDRST_STS)) | in wdt_t0out_reload()
105 while (IS_BIT_SET(inst->T0CSR, NPCX_T0CSR_RST)) { in wdt_t0out_reload()
106 if (k_uptime_get() - st > NPCX_T0CSR_RST_TIMEOUT) { in wdt_t0out_reload()
108 if (IS_BIT_SET(inst->T0CSR, NPCX_T0CSR_RST)) { in wdt_t0out_reload()
110 return -ETIMEDOUT; in wdt_t0out_reload()
125 while (IS_BIT_SET(inst->T0CSR, NPCX_T0CSR_WD_RUN)) { in wdt_wait_stopped()
126 if (k_uptime_get() - st > NPCX_WATCHDOG_STOP_TIMEOUT) { in wdt_wait_stopped()
128 if (IS_BIT_SET(inst->T0CSR, NPCX_T0CSR_WD_RUN)) { in wdt_wait_stopped()
130 return -ETIMEDOUT; in wdt_wait_stopped()
141 struct wdt_npcx_data *const data = dev->data; in wdt_t0out_isr()
145 CONFIG_WDT_NPCX_WARNING_LEADING_TIME_MS, wui->table, wui->group, wui->bit); in wdt_t0out_isr()
148 if (data->cb) { in wdt_t0out_isr()
149 data->cb(dev, 0); in wdt_t0out_isr()
155 const struct wdt_npcx_config *const config = dev->config; in wdt_config_t0out_interrupt()
158 npcx_miwu_init_dev_callback(&miwu_cb, &config->t0out, wdt_t0out_isr, in wdt_config_t0out_interrupt()
163 * Configure the T0 wake-up event triggered from a rising edge in wdt_config_t0out_interrupt()
166 npcx_miwu_interrupt_configure(&config->t0out, in wdt_config_t0out_interrupt()
174 struct wdt_npcx_data *const data = dev->data; in wdt_npcx_install_timeout()
178 if (IS_BIT_SET(inst->T0CSR, NPCX_T0CSR_WD_RUN)) { in wdt_npcx_install_timeout()
179 return -EBUSY; in wdt_npcx_install_timeout()
183 if (cfg->window.min != 0) { in wdt_npcx_install_timeout()
184 data->timeout_installed = false; in wdt_npcx_install_timeout()
185 return -EINVAL; in wdt_npcx_install_timeout()
189 * Since the watchdog counter in npcx series is 8-bits, maximum time in wdt_npcx_install_timeout()
191 * allowed range of 1-8000 in milliseconds. Check if the provided value in wdt_npcx_install_timeout()
194 if (cfg->window.max > NPCX_WDT_MAX_WND_TIME || cfg->window.max == 0) { in wdt_npcx_install_timeout()
195 data->timeout_installed = false; in wdt_npcx_install_timeout()
196 return -EINVAL; in wdt_npcx_install_timeout()
200 data->timeout = cfg->window.max; in wdt_npcx_install_timeout()
203 data->cb = cfg->callback; in wdt_npcx_install_timeout()
204 data->timeout_installed = true; in wdt_npcx_install_timeout()
212 const struct wdt_npcx_config *const config = dev->config; in wdt_npcx_setup()
213 struct wdt_npcx_data *const data = dev->data; in wdt_npcx_setup()
219 /* Disable irq of t0-out expired event first */ in wdt_npcx_setup()
220 npcx_miwu_irq_disable(&config->t0out); in wdt_npcx_setup()
222 if (!data->timeout_installed) { in wdt_npcx_setup()
224 return -EINVAL; in wdt_npcx_setup()
227 if (IS_BIT_SET(inst->T0CSR, NPCX_T0CSR_WD_RUN)) { in wdt_npcx_setup()
229 return -EBUSY; in wdt_npcx_setup()
234 return -ENOTSUP; in wdt_npcx_setup()
246 * Then the counter value is timeout/0.976 - 1. in wdt_npcx_setup()
248 inst->TWDT0 = MAX(DIV_ROUND_UP(data->timeout * NPCX_WDT_CLK, in wdt_npcx_setup()
249 32 * 1000) - 1, 1); in wdt_npcx_setup()
251 /* Configure 8-bit watchdog counter in wdt_npcx_setup()
252 * Change the prescaler of watchdog clock for larger timeout in wdt_npcx_setup()
254 wd_cnt = DIV_ROUND_UP((data->timeout + CONFIG_WDT_NPCX_WARNING_LEADING_TIME_MS) * in wdt_npcx_setup()
262 * prescaler in wdt_npcx_setup()
264 wdcp = LOG2(pre_scal - 1) + 1; in wdt_npcx_setup()
267 inst->WDCP = wdcp; in wdt_npcx_setup()
268 inst->WDCNT = wd_cnt / pre_scal; in wdt_npcx_setup()
270 LOG_DBG("WDT setup: TWDT0, WDCNT are %d, %d", inst->TWDT0, inst->WDCNT); in wdt_npcx_setup()
278 /* Enable irq of t0-out expired event */ in wdt_npcx_setup()
279 npcx_miwu_irq_enable(&config->t0out); in wdt_npcx_setup()
286 const struct wdt_npcx_config *const config = dev->config; in wdt_npcx_disable()
287 struct wdt_npcx_data *const data = dev->data; in wdt_npcx_disable()
295 min_wnd_t = DIV_ROUND_UP(3 * NPCX_WDT_CLK, 32 * (1 << inst->WDCP)); in wdt_npcx_disable()
296 while (k_uptime_get() - data->last_watchdog_touch < min_wnd_t) { in wdt_npcx_disable()
304 inst->WDSDM = 0x87; in wdt_npcx_disable()
305 inst->WDSDM = 0x61; in wdt_npcx_disable()
306 inst->WDSDM = 0x63; in wdt_npcx_disable()
308 /* Disable irq of t0-out expired event and mark it uninstalled */ in wdt_npcx_disable()
309 npcx_miwu_irq_disable(&config->t0out); in wdt_npcx_disable()
310 data->timeout_installed = false; in wdt_npcx_disable()
319 struct wdt_npcx_data *const data = dev->data; in wdt_npcx_feed()
323 inst->WDSDM = 0x5C; in wdt_npcx_feed()
324 data->last_watchdog_touch = k_uptime_get(); in wdt_npcx_feed()
348 * [7:6]- Reserved = 0 in wdt_npcx_init()
349 * [5] - WDSDME = 1: Feed watchdog by writing 5Ch to WDSDM in wdt_npcx_init()
350 * [4] - WDCT0I = 1: Select T0IN as watchdog prescaler clock in wdt_npcx_init()
351 * [3] - LWDCNT = 0: Don't lock WDCNT register in wdt_npcx_init()
352 * [2] - LTWDT0 = 0: Don't lock TWDT0 register in wdt_npcx_init()
353 * [1] - LTWCP = 0: Don't lock TWCP register in wdt_npcx_init()
354 * [0] - LTWCFG = 0: Don't lock TWCFG register in wdt_npcx_init()
356 inst->TWCFG = BIT(NPCX_TWCFG_WDSDME) | BIT(NPCX_TWCFG_WDCT0I); in wdt_npcx_init()
359 inst->T0CSR = (inst->T0CSR & ~BIT(NPCX_T0CSR_WDRST_STS)) | in wdt_npcx_init()
363 * - T0 Timer freq is LFCLK/32 Hz in wdt_npcx_init()
364 * - Watchdog freq is T0CLK/32 Hz (ie. LFCLK/1024 Hz) in wdt_npcx_init()
366 inst->WDCP = 0x05; /* Prescaler is 32 in Watchdog Timer */ in wdt_npcx_init()
367 inst->TWCP = 0x05; /* Prescaler is 32 in T0 Timer */ in wdt_npcx_init()