GPIO programming and Interrupts

View: New views
2 Messages — Rating Filter:   Alert me  

GPIO programming and Interrupts

by cruizbugs :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi, I have a few questions.

I have a task to make my gumstix to control a switch.

So, I am using a GPIO 28 to control the external device.
I understand that I can use
# echo "GPIO out set" > /proc/gpio/GPIO28
# echo "GPIO out clear" > /proc/gpio/GPIO28
to control the pin output manually, but what I have to do is to make an automatic on-off.
meaning,
I will have to read from a .txt file that contains all the day and time to on/off.
this text file will turn on-off the switch every few minutes, i.e.
Monday 01:00 am ON
Monday 01:02 am OFF
Monday 01:05 am ON
Monday 01:59 am OFF
etc..

So, regarding this task and since i'm still new to linux,
1. i was thinking what programming language I should use? C or C++ ? which one easier?

2. i found this http://docwiki.gumstix.org/index.php/Sample_code/C/gpregs
how to run this file ? does this work for verdex pro XL6P ? i'm using GPIO on consoleLCD16

3. Is there any idea on how to do this effectively?
I was being told to try to use interrupt, for example, for every minute i will receive an interrupt, then i will read the list of the timing and check out if I have to on or off the switch.
but the problem is, how to set this kind of interrupt? i heard about kernel programming, but i'm still quite lost here.
or is there any other better way to do this task?
I saw http://docwiki.gumstix.org/GPIO_event , but i dont think this is related to what I have to do, right ??

sorry I ask alot.
Thanks you in advance




Re: GPIO programming and Interrupts

by Dave Hylands :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

> So, I am using a GPIO 28 to control the external device.
> I understand that I can use
> # echo "GPIO out set" > /proc/gpio/GPIO28
> # echo "GPIO out clear" > /proc/gpio/GPIO28
> to control the pin output manually, but what I have to do is to make an
> automatic on-off.
> meaning,
> I will have to read from a .txt file that contains all the day and time to
> on/off.
> this text file will turn on-off the switch every few minutes, i.e.
> Monday 01:00 am ON
> Monday 01:02 am OFF
> Monday 01:05 am ON
> Monday 01:59 am OFF
> etc..
>
> So, regarding this task and since i'm still new to linux,
> 1. i was thinking what programming language I should use? C or C++ ? which
> one easier?

If you don't know either one, then C is a much simpler language, and
you pretty much need to know all of the C syntax in order to use C++.

> 2. i found this http://docwiki.gumstix.org/index.php/Sample_code/C/gpregs
> how to run this file ? does this work for verdex pro XL6P ? i'm using GPIO
> on consoleLCD16

If you're talking about toggling the GPIOs using minute markers, then
I wouldn't bother with that and just use something simple, like open
the /proc/gpio/GPIO28 file and writing the string

GPIO out set

to it (which is exactly what the echo command above does). To answer
your original question, yes - the gpregs example should work on the
verdex.

> 3. Is there any idea on how to do this effectively?
> I was being told to try to use interrupt, for example, for every minute i
> will receive an interrupt, then i will read the list of the timing and check
> out if I have to on or off the switch.
> but the problem is, how to set this kind of interrupt? i heard about kernel
> programming, but i'm still quite lost here.
> or is there any other better way to do this task?
> I saw http://docwiki.gumstix.org/GPIO_event , but i dont think this is
> related to what I have to do, right ??

The kernel already does this internally. So, for example you could use
the sleep API, and just do something like:

sleep( 30 or less - depends on when the next even expires).
Check the time and see if the next event has expired.

The sleep command will go away for 30 seconds and come back in
response the system timer tick, which is interrupt based.

This is actually a combined polling based/interrupt based system. In a
pure interrupt system, you'd sleep until the next timer expired. But
this would mean that you'd never wakeup if say, somebody changed the
time on the gumstix. By using a shorter sleep and checking
periodically, you'll adapt to the fact that somebody changed the time.

If you really really need to do an interrupt, then yeah you're going
to need to write a device driver which uses one of the system timers
and installs an interrupt handler to wake up an ioctl handler which
will wake up your task. Seems like alot of work just to do what sleep
already does.

--
Dave Hylands
Shuswap, BC, Canada
http://www.DaveHylands.com/

------------------------------------------------------------------------------
_______________________________________________
gumstix-users mailing list
gumstix-users@...
https://lists.sourceforge.net/lists/listinfo/gumstix-users