Lines Matching +full:positive +full:- +full:cs

5  * SPDX-License-Identifier: Apache-2.0
51 const struct mcux_pwt_config *config = dev->config; in mcux_pwt_is_active()
53 return !!(config->base->CS & PWT_CS_PWTEN_MASK); in mcux_pwt_is_active()
68 return -ENOTSUP; in mcux_pwt_set_cycles()
76 const struct mcux_pwt_config *config = dev->config; in mcux_pwt_configure_capture()
77 struct mcux_pwt_data *data = dev->data; in mcux_pwt_configure_capture()
81 return -EINVAL; in mcux_pwt_configure_capture()
86 return -EBUSY; in mcux_pwt_configure_capture()
92 return -ENOTSUP; in mcux_pwt_configure_capture()
97 LOG_ERR("Cannot capture period in normal polarity (active-high pulse)"); in mcux_pwt_configure_capture()
98 return -ENOTSUP; in mcux_pwt_configure_capture()
102 data->callback = cb; in mcux_pwt_configure_capture()
103 data->user_data = user_data; in mcux_pwt_configure_capture()
105 data->pwt_config.inputSelect = channel; in mcux_pwt_configure_capture()
107 data->continuous = in mcux_pwt_configure_capture()
109 data->inverted = in mcux_pwt_configure_capture()
112 PWT_Init(config->base, &data->pwt_config); in mcux_pwt_configure_capture()
113 PWT_EnableInterrupts(config->base, in mcux_pwt_configure_capture()
122 const struct mcux_pwt_config *config = dev->config; in mcux_pwt_enable_capture()
123 struct mcux_pwt_data *data = dev->data; in mcux_pwt_enable_capture()
127 return -EINVAL; in mcux_pwt_enable_capture()
130 if (!data->callback) { in mcux_pwt_enable_capture()
132 return -EINVAL; in mcux_pwt_enable_capture()
137 return -EBUSY; in mcux_pwt_enable_capture()
140 data->overflowed = false; in mcux_pwt_enable_capture()
141 data->high_overflows = 0; in mcux_pwt_enable_capture()
142 data->low_overflows = 0; in mcux_pwt_enable_capture()
143 PWT_StartTimer(config->base); in mcux_pwt_enable_capture()
150 const struct mcux_pwt_config *config = dev->config; in mcux_pwt_disable_capture()
154 return -EINVAL; in mcux_pwt_disable_capture()
157 PWT_StopTimer(config->base); in mcux_pwt_disable_capture()
171 return -ERANGE; in mcux_pwt_calc_period()
176 return -ERANGE; in mcux_pwt_calc_period()
179 /* Add positive pulse width */ in mcux_pwt_calc_period()
181 return -ERANGE; in mcux_pwt_calc_period()
186 return -ERANGE; in mcux_pwt_calc_period()
201 return -ERANGE; in mcux_pwt_calc_pulse()
206 return -ERANGE; in mcux_pwt_calc_pulse()
216 const struct mcux_pwt_config *config = dev->config; in mcux_pwt_isr()
217 struct mcux_pwt_data *data = dev->data; in mcux_pwt_isr()
225 flags = PWT_GetStatusFlags(config->base); in mcux_pwt_isr()
228 if (config->base->CR & PWT_CR_LVL_MASK) { in mcux_pwt_isr()
229 data->overflowed |= u32_add_overflow(1, in mcux_pwt_isr()
230 data->high_overflows, &data->high_overflows); in mcux_pwt_isr()
232 data->overflowed |= u32_add_overflow(1, in mcux_pwt_isr()
233 data->low_overflows, &data->low_overflows); in mcux_pwt_isr()
236 PWT_ClearStatusFlags(config->base, kPWT_CounterOverflowFlag); in mcux_pwt_isr()
240 ppw = PWT_ReadPositivePulseWidth(config->base); in mcux_pwt_isr()
241 npw = PWT_ReadNegativePulseWidth(config->base); in mcux_pwt_isr()
243 if (!data->continuous) { in mcux_pwt_isr()
244 PWT_StopTimer(config->base); in mcux_pwt_isr()
247 if (data->inverted) { in mcux_pwt_isr()
248 err = mcux_pwt_calc_pulse(npw, data->low_overflows, in mcux_pwt_isr()
251 err = mcux_pwt_calc_pulse(ppw, data->high_overflows, in mcux_pwt_isr()
257 data->high_overflows, in mcux_pwt_isr()
258 data->low_overflows, in mcux_pwt_isr()
262 if (data->overflowed) { in mcux_pwt_isr()
263 err = -ERANGE; in mcux_pwt_isr()
269 if (data->callback) { in mcux_pwt_isr()
270 data->callback(dev, data->pwt_config.inputSelect, in mcux_pwt_isr()
271 period, pulse, err, data->user_data); in mcux_pwt_isr()
274 data->overflowed = false; in mcux_pwt_isr()
275 data->high_overflows = 0; in mcux_pwt_isr()
276 data->low_overflows = 0; in mcux_pwt_isr()
277 PWT_ClearStatusFlags(config->base, kPWT_PulseWidthValidFlag); in mcux_pwt_isr()
284 const struct mcux_pwt_config *config = dev->config; in mcux_pwt_get_cycles_per_sec()
285 struct mcux_pwt_data *data = dev->data; in mcux_pwt_get_cycles_per_sec()
289 *cycles = data->clock_freq >> config->prescale; in mcux_pwt_get_cycles_per_sec()
296 const struct mcux_pwt_config *config = dev->config; in mcux_pwt_init()
297 struct mcux_pwt_data *data = dev->data; in mcux_pwt_init()
298 pwt_config_t *pwt_config = &data->pwt_config; in mcux_pwt_init()
301 if (!device_is_ready(config->clock_dev)) { in mcux_pwt_init()
303 return -ENODEV; in mcux_pwt_init()
306 if (clock_control_get_rate(config->clock_dev, config->clock_subsys, in mcux_pwt_init()
307 &data->clock_freq)) { in mcux_pwt_init()
309 return -EINVAL; in mcux_pwt_init()
313 pwt_config->clockSource = config->pwt_clock_source; in mcux_pwt_init()
314 pwt_config->prescale = config->prescale; in mcux_pwt_init()
315 pwt_config->enableFirstCounterLoad = true; in mcux_pwt_init()
316 PWT_Init(config->base, pwt_config); in mcux_pwt_init()
318 err = pinctrl_apply_state(config->pincfg, PINCTRL_STATE_DEFAULT); in mcux_pwt_init()
323 config->irq_config_func(dev); in mcux_pwt_init()