MCPcopy Create free account
hub / github.com/F-Stack/f-stack / ti_adc_clockdiv_proc

Function ti_adc_clockdiv_proc

freebsd/arm/ti/ti_adc.c:258–295  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

256}
257
258static int
259ti_adc_clockdiv_proc(SYSCTL_HANDLER_ARGS)
260{
261 int error, reg;
262 struct ti_adc_softc *sc;
263
264 sc = (struct ti_adc_softc *)arg1;
265
266 TI_ADC_LOCK(sc);
267 reg = (int)ADC_READ4(sc, ADC_CLKDIV) + 1;
268 TI_ADC_UNLOCK(sc);
269
270 error = sysctl_handle_int(oidp, &reg, sizeof(reg), req);
271 if (error != 0 || req->newptr == NULL)
272 return (error);
273
274 /*
275 * The actual written value is the prescaler setting - 1.
276 * Enforce a minimum value of 10 (i.e. 9) which limits the maximum
277 * ADC clock to ~2.4Mhz (CLK_M_OSC / 10).
278 */
279 reg--;
280 if (reg < 9)
281 reg = 9;
282 if (reg > USHRT_MAX)
283 reg = USHRT_MAX;
284
285 TI_ADC_LOCK(sc);
286 /* Disable the ADC. */
287 ti_adc_disable(sc);
288 /* Update the ADC prescaler setting. */
289 ADC_WRITE4(sc, ADC_CLKDIV, reg);
290 /* Enable the ADC again. */
291 ti_adc_setup(sc);
292 TI_ADC_UNLOCK(sc);
293
294 return (0);
295}
296
297static int
298ti_adc_enable_proc(SYSCTL_HANDLER_ARGS)

Callers

nothing calls this directly

Calls 3

sysctl_handle_intFunction · 0.85
ti_adc_disableFunction · 0.85
ti_adc_setupFunction · 0.85

Tested by

no test coverage detected