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

Re: Controlling pins



On Tuesday 12 November 2002 08.46, Martin Oberhammer wrote:
> I wrote two small C-Programms for reading and seting the pins.
>
> When i read the pins i get the value 118, setting this value is no problem.
> When i set the value 115 the system stands and i must reset.
> Why does this happen?

I haven't tested your code, but it look like it could be the following:
What do you mean by stands?
Does the network stop or just the serial output?
Since the value 115 = 1110011 you just disabled the serial output
when setting PA0 to 1.

> Can I controll all pins or only specific pins?

There are CONFIG options called what bits that are allowed to be changed 
from user mode using the gpio driver, e.g:
CONFIG_ETRAX_PA_CHANGEABLE_DIR=00
CONFIG_ETRAX_PA_CHANGEABLE_BITS=FF
CONFIG_ETRAX_PB_CHANGEABLE_DIR=00
CONFIG_ETRAX_PB_CHANGEABLE_BITS=FF

I guess the values supplied with the devboard allows you to
"shoot yourself in the foot".

> What are right arguments to use with ioctl()?

It looks ok, but you should consider using the "new" ioctl()'s
that are 32 bit safe (matters for gpiog) instead if IO_READBITS and takes a 
pointer argument instead of returning the value in the ioctl() function 
return value.

Also note that IO_SETBITS only sets the bits that are 1 in the mask,
it doesn't clear any bits - use IO_CLRBITS for that.

Best regards
/Johan

> /******************/
> /** setting bits **/
> /******************/
> int main (int argc, char* argv[])
> {
>   int gpioa; // filedescriptor for /dev/gpioa
>   long bits = atol (argv[1]);
>
>   gpioa = open("/dev/gpioa", O_RDWR);
>
>   if (ioctl (gpioa, _IO(ETRAXGPIO_IOCTYPE, IO_SETBITS), bits) == -1)
>   {
>     fprintf (stderr, "error setting pins: %s\n", strerror(errno));
>     exit (1);
>   }
>   else
>   {
>     printf ("set: %d\n", bits);
>   }
>   return 0;
> }
>
> /******************/
> /** reading bits **/
> /******************/
> int main (int argc, char* argv[])
> {
>   int gpioa; // filedescriptor for /dev/gpioa
>   long bits = -222;
>
>   gpioa = open("/dev/gpioa", O_RDWR);
>
>   bits = ioctl (gpioa, _IO(ETRAXGPIO_IOCTYPE, IO_READBITS), NULL);
>
>   if (bits == -1)
>   {
>     fprintf (stderr, "error reading pins: %s\n", strerror (errno));
>     exit (1);
>   }
>   else
>   {
>     printf ("read: %d\n", bits);
>   }
>   return 0;
> }
>
> Thank you.
>
> yours Martin
>
> On Fri, 8 Nov 2002 15:41:37 +0100
>
> Mikael Starvik <mikael.starvik@xxxxxxx.com> wrote:
> > Yes, you can control the value on each pin individually.
> > The direction of the pins is changed in groups (e.g. all
> > 8 data  pins on parallel port 0 must be in the same
> > direction).
> >
> > If you want to control the pins from user space you can
> > do so by writing to the gpio driver that exists in the
> > 2.4.19 kernel (refer to the thread about this a few days
> > ago).
> >
> > If you want to control them from a driver you will find
> > hints in the device driver example on www.axis.com.
> >
> > /Mikael
> >
> > -----Original Message-----
> > From: owner-dev-etrax@xxxxxxx.com]On">mailto:owner-dev-etrax@xxxxxxx.com]On
> > Behalf Of Martin Oberhammer
> > Sent: Friday, November 08, 2002 3:20 PM
> > To: dev-etrax
> > Subject: Controlling pins
> >
> >
> > There exists 2 parallel ports on the developer board (ETRAX 100LX). Is it
> > possible to controll each of the 52 pins serparately? For example sending
> > a signal over pin 8, 10, 20 and 48.
> >
> > yours Martin
> >
> > ----------------------------
> > Martin Oberhammer
> > ARS Electronica Futurelab
> > Hauptstrasse 2-4
> > 4040 Linz
> > AUSTRIA
>
> ----------------------------
> Martin Oberhammer
> ARS Electronica Futurelab
> Hauptstrasse 2-4
> 4040 Linz
> AUSTRIA
>
> Web: http://www.aec.at