ptimer: Add new ptimer_set_period_from_clock() function
commitad140dadd591cdfd47959a7b4538e8133053b3c7
authorPeter Maydell <peter.maydell@linaro.org>
Thu, 28 Jan 2021 11:41:21 +0000 (28 11:41 +0000)
committerPeter Maydell <peter.maydell@linaro.org>
Fri, 29 Jan 2021 15:54:42 +0000 (29 15:54 +0000)
tree49668bb984275142dfd07f2c9b5112ac6ea0a63f
parentc0f82826a1cc52a2a038b12ccaa1c92bb7e2d4c0
ptimer: Add new ptimer_set_period_from_clock() function

The ptimer API currently provides two methods for setting the period:
ptimer_set_period(), which takes a period in nanoseconds, and
ptimer_set_freq(), which takes a frequency in Hz.  Neither of these
lines up nicely with the Clock API, because although both the Clock
and the ptimer track the frequency using a representation of whole
and fractional nanoseconds, conversion via either period-in-ns or
frequency-in-Hz will introduce a rounding error.

Add a new function ptimer_set_period_from_clock() which takes the
Clock object directly to avoid the rounding issues.  This includes a
facility for the user to specify that there is a frequency divider
between the Clock proper and the timer, as some timer devices like
the CMSDK APB dualtimer need this.

To avoid having to drag in clock.h from ptimer.h we add the Clock
type to typedefs.h.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Luc Michel <luc@lmichel.fr>
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Message-id: 20210128114145.20536-2-peter.maydell@linaro.org
Message-id: 20210121190622.22000-2-peter.maydell@linaro.org
hw/core/ptimer.c
include/hw/ptimer.h
include/qemu/typedefs.h