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

Re: /dev/gpiog ???? one bit ??




----- Original Message -----
From: "Antonio Redondo Mozos" <aredondomozos@xxxxxxx.com>
To: <dev-etrax@xxxxxxx.com>
Sent: den 21 november 2002 16:55
Subject: /dev/gpiog ???? one bit ??


> Hi,
>
> I test the next code:
>
> int main(int argc, char * argv[]) {
>  int fd;
>  unsigned long data, mask;
>
>   fd= open("/dev/gpiog",O_RDWR);
>   if(fd == -1){
>     perror("open");
>     return -1;
>   }
>
>   data = mask = 0xFF << 8;
>   ioctl(fd, _IO(ETRAXGPIO_IOCTYPE, IO_SETGET_OUTPUT), &mask);
>   if ((mask & data) != data)
>   printf("Check your kernel config\n");
>   data=0x33 << 8;
   ioctl(fd, _IO(ETRAXGPIO_IOCTYPE, IO_CLRBITS ),(~data & mask));
>   ioctl(fd, _IO(ETRAXGPIO_IOCTYPE, IO_SETBITS ),data);
>   close(fd);
>   return 1;
> }
>
> and haven't problem whith the line   if ((mask & data) != data) ....
>
> I think that must see 0x33 in lp0, but always see 0xff. always 0xff on
lp0.

Note that IO_SETBITS sets the high bits in data to 1, it doesn't clear
the rest.
Use something like:
   ioctl(fd, _IO(ETRAXGPIO_IOCTYPE, IO_CLRBITS ),(~data & mask));

Use
> please how can i change the bit 5 on Port G? what instruction?

Just use IO_SETBITS with bit 5 set:
   ioctl(fd, _IO(ETRAXGPIO_IOCTYPE, IO_SETBITS ),1 << 5);

> where is the manual for see the chapter 20?.
>
> Thanks.

/Johan