Lines Matching +full:divider +full:- +full:int +full:- +full:0
4 * SPDX-License-Identifier: Apache-2.0
17 #define FWDGT_RELOAD_MAX (0xFFFU)
34 #define FWDGT_INITIAL_TIMEOUT DT_INST_PROP(0, initial_timeout_ms)
36 #if (FWDGT_INITIAL_TIMEOUT <= 0)
37 #error Must be initial-timeout > 0
41 #error Must be initial-timeout <= (256 * 4095 * 1000 / GD32_LOW_SPEED_IRC_FREQUENCY)
51 * @return 0 on success, -EINVAL if the timeout is out of range
53 static int gd32_fwdgt_calc_timeout(uint32_t timeout, uint32_t *prescaler, in gd32_fwdgt_calc_timeout()
56 uint16_t divider = 4U; in gd32_fwdgt_calc_timeout() local
57 uint8_t shift = 0U; in gd32_fwdgt_calc_timeout()
61 while ((ticks / divider) > FWDGT_RELOAD_MAX) { in gd32_fwdgt_calc_timeout()
63 divider = 4U << shift; in gd32_fwdgt_calc_timeout()
66 if (!IS_VALID_FWDGT_PRESCALER(PSC_PSC(shift)) || timeout == 0U) { in gd32_fwdgt_calc_timeout()
67 return -EINVAL; in gd32_fwdgt_calc_timeout()
72 *reload = (ticks / divider) - 1U; in gd32_fwdgt_calc_timeout()
74 return 0; in gd32_fwdgt_calc_timeout()
77 static int gd32_fwdgt_setup(const struct device *dev, uint8_t options) in gd32_fwdgt_setup()
81 if ((options & WDT_OPT_PAUSE_HALTED_BY_DBG) != 0U) { in gd32_fwdgt_setup()
86 return -ENOTSUP; in gd32_fwdgt_setup()
90 if ((options & WDT_OPT_PAUSE_IN_SLEEP) != 0U) { in gd32_fwdgt_setup()
92 return -ENOTSUP; in gd32_fwdgt_setup()
97 return 0; in gd32_fwdgt_setup()
100 static int gd32_fwdgt_disable(const struct device *dev) in gd32_fwdgt_disable()
105 return -EPERM; in gd32_fwdgt_disable()
108 static int gd32_fwdgt_install_timeout(const struct device *dev, in gd32_fwdgt_install_timeout()
111 uint32_t prescaler = 0U; in gd32_fwdgt_install_timeout()
112 uint32_t reload = 0U; in gd32_fwdgt_install_timeout()
116 if (config->callback != NULL) { in gd32_fwdgt_install_timeout()
118 return -ENOTSUP; in gd32_fwdgt_install_timeout()
122 if (gd32_fwdgt_calc_timeout(config->window.max, &prescaler, in gd32_fwdgt_install_timeout()
123 &reload) != 0) { in gd32_fwdgt_install_timeout()
125 return -EINVAL; in gd32_fwdgt_install_timeout()
133 return -EINVAL; in gd32_fwdgt_install_timeout()
137 return 0; in gd32_fwdgt_install_timeout()
140 static int gd32_fwdgt_feed(const struct device *dev, int channel_id) in gd32_fwdgt_feed()
146 return 0; in gd32_fwdgt_feed()
156 static int gd32_fwdgt_init(const struct device *dev) in gd32_fwdgt_init()
158 int ret = 0; in gd32_fwdgt_init()
176 DEVICE_DT_INST_DEFINE(0, gd32_fwdgt_init, NULL, NULL, NULL, POST_KERNEL,