tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: gpio(4) and pulsing pins in software

On 09/25/11 16:50, Jachym Holecek wrote:
# Marc Balmer 2011-09-25:
I recently added code to gpio(4) on jak's request to pulse a pin in
software.  The idea is, that when the hardware supports it, a pin is
pulsed by the hardware, if the underlying hardware has no pulsate
support, it can be done in software.  While the current code works, I
think it is done wrong, or at the wrong level, and I'd like to change
that. Comments welcome.

Nice aspect is that presence of HW support is transparent to the user.
Doesn't your proposal mean this property is removed and the user has to
use gpioctl(8) for HW support and gpiopwm(4) for SW implementation (it
is not clear enough from you message)?

Yes it means that. I do think that people that use gpio(4) are very well aware of their hardware and that such trickery has no business in gpio(4).

I think gpio(4) should only be used to configure and control pins, but
not to do any magic with them, like pulsing in software.  We have the
possibility to attach device drivers to individual pins which can then
do the "magic".  So I am suggesting removing the software pulsing
support in gpio(4) and replacing it by a gpiopwm(4) driver that can be
attached to an individual pin.  gpioctl(8) will keep the pulse keyword,
as this is needed for hardware pulsating devices.  The interface to the
gpiopwm(4) driver could be realized using three sysctl variables:

hw.gpiopwm0.running=0 # Set to 1 to start pwm
hw.gpiopwm0.ticks_on=n1 # Number of ticks the pin is 1
hw.gpiopwm0.ticks_off=n2 # Number of ticks the pin is 0

Doesn't sysctl(3) interface mean one can't change lo+hi periods atomically?
Wouldn't it be better to specify hi/lo values in absolute units (current
implementation uses timeval) instead of relative ticks?

The current implementation already uses ticks, the timevals are converted to ticks (gpioctl(8) converts frequency and duty cycle to timevals, gpio(4) converst timevals to ticks). Whereas hardware could use timevals, a software implementation using callouts can have no finer granularity than one tick.

The usage pattern with sysctls to get 1 Hz blinking on a machine with hz == 100 would probably be:

sysctl -w hw.gpiopwm0.running=0
sysctl -w hw.gpiopwm0.ticks_on=50
sysctl -w hw.gpiopwm0.ticks_off=50
sysctl -w hw.gpiopwm0.running=1

        -- Jachym

Home | Main Index | Thread Index | Old Index