2008-04-08 13:32:01     Using a gpio pin to grab pulse width

Document created by Aaronwu Employee on Aug 6, 2013
Version 1Show Document
  • View in full screen mode

2008-04-08 13:32:01     Using a gpio pin to grab pulse width

John Zalfer (UNITED STATES)

Message: 53854    Hi, I don't have any timer pins available to me, but I need to grab a pulse width.  My plan is to just register two IRQs, one for EDGE_RISING and one for EDGE_FALLING, record the timestamp at both interrupts and subtract the latter from the former.  I think this should work, given that I only need accuracy of the width I'm recording within the dozens of microseconds range.  What function should I call for the timestamp?

 

Also, if I call request_irq() twice on the same pin, like so:

 

        result = request_irq(IRQ_PH10, start_pulse_irq1,

                IRQF_SHARED | IRQF_TRIGGER_RISING, DRIVER_NAME, &sonar_devices[0]);

        result |= request_irq(IRQ_PH10, end_pulse_irq1,

                IRQF_SHARED | IRQF_TRIGGER_FALLING, DRIVER_NAME, &sonar_devices[0]);

 

will a simple  free_irq(IRQ_PH10, &sonar_devices[0]); clear both of them?

 

 

-John

QuoteReplyEditDelete

 

 

2008-04-08 14:11:42     Re: Using a gpio pin to grab pulse width

Mike Frysinger (UNITED STATES)

Message: 53856    that wont really work, nor do what you expect.  the cookie given to request_irq needs to be unique.  you're using the same cookie both times, so that part is wrong.  you also cant configure the pin in multiple states as that doesnt work at the hardware level.  if you review how shared irqs work, when the irq fires, every handler gets called.

 

you're probably also going to run into the limitation on most Blackfins where a gpio used as an interrupt source on both rising and falling edges does not allow you to read the value and figure out what the source was: rising or falling.

QuoteReplyEditDelete

 

 

2008-04-08 15:33:11     Re: Using a gpio pin to grab pulse width

John Zalfer (UNITED STATES)

Message: 53858    Thanks Mike.

 

Would it work if I toggled the interrupt for both edges and then kept track of the previous state (say, as a bool) in my device struct?  Then I wouldn't need to figure out the source from the interrupt itself, as I'd already be keeping track of it.

 

-John

QuoteReplyEditDelete

 

 

2008-04-08 15:54:14     Re: Using a gpio pin to grab pulse width

Mike Frysinger (UNITED STATES)

Message: 53859    that would work so long as you dont have to worry about missing an interrupt and then falling out of sync ...

QuoteReplyEditDelete

 

 

2008-04-08 18:26:22     Re: Using a gpio pin to grab pulse width

John Zalfer (UNITED STATES)

Message: 53860    Well, I can do a bit of boundary checking to make sure the value is sane.

 

Some googling suggests I would want to use get_cycles() to measure something at this resolution, but when I look at timex.h, get_cycles() always returns 0.  Should I be looking for some register to read directly to figure out the elapsed time?

QuoteReplyEditDelete

 

 

2008-04-08 18:55:09     Re: Using a gpio pin to grab pulse width

Mike Frysinger (UNITED STATES)

Message: 53861    cycles does not give you elapsed time.  if you want that, use gettimeofday().  that function has nanosecond resolution.

QuoteReplyEditDelete

 

 

2008-04-09 09:57:48     Re: Using a gpio pin to grab pulse width

John Zalfer (UNITED STATES)

Message: 53924    Where is gettimeofday defined?  I'm in linux-2.6.x/drivers/char/ and #include <linux/time.h> doesn't do the trick.

QuoteReplyEditDelete

 

 

2008-04-09 11:56:49     Re: Using a gpio pin to grab pulse width

Mike Frysinger (UNITED STATES)

Message: 53935    grep says:

include/linux/time.h:extern void do_gettimeofday(struct timeval *tv);

Attachments

    Outcomes