[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [microblaze-uclinux] Questions about the uClinux GPIO-Driver
Hello all !
I've compiled and tested this user-program to test the
GPIO driver for the petalinux 2.6.2 kernel:
#include <stdio.h> /* Standard input/output
definitions */
#include <fcntl.h> /* File control definitions */
#include <errno.h> /* Error number definitions */
#include <linux/xgpio_ioctl.h>
//#include <string.h> /* String function definitions
*/
//#include <linux/types.h>
//#include <linux/ioctl.h>
//#include <linux/ibm_ocp_gpio.h>
#define GPIO_DEV "/dev/gpio1"
/* function prototypes */
int main(void)
{
//char GPIO_DEV[11] = "/dev/gpio1";
int fd;/* The file descriptor of GPIO_DEV */
/* Open the device */
fd = open(GPIO_DEV, O_RDWR);
if(fd==-1)
{
printf("\n\nUnable to open %s\nContinuing
anyway...", GPIO_DEV);
}
printf("\n\nTrying to read samples from %s ",
GPIO_DEV);
//int j;
char result[8]; /* The pointer which will hold the
result */
struct xgpio_ioctl_data ioctl_data; /* For
ioctl-based input sample*/
ioctl_data.chan = 1;
ioctl_data.data = 0;
ioctl_data.mask = ~0;
//for(j=0; j<5; j++)
for( ;; )
{
int rd = read(fd, result, 8);/* Read from GPIO_DEV
-- The read operation is interrupt-based */
if ( ioctl(fd, XGPIO_IN, &ioctl_data) == -1 )
{
printf("\n\nioctl read error\nContinuing
anyway...");
fflush(stdout);
}
else
{
printf("\n\nioctl sample is 0x%016X\n",
ioctl_data.data);
}
/* We only read one sample which is 8 bytes (64-bit)
*/
if (rd < 0)
{
printf("\n\nread error %d %s\nContinuing
anyway...", errno, strerror(errno));
fflush(stdout);
}
else
{
int k;
printf("\n\nRead one sample successfully\nThe
sample is:\n");
for(k=0; k<8; k++)
{
printf(" Byte # %d is %02X\n", k, (unsigned char)
result[k]);
}
fflush(stdout);
}
}
printf("\nAll Done ! Goodbye...\n");
return 0;
}
To try it: compile using "microblaze-uclinux-gcc" then
copy the executable file into
$PETALINUX/softwre/petalinux-dist/romfs/bin/
then inside the directory
$PETALINUX/softwre/petalinux-dist/
type: "make image"
this will add the compiled application into your
image.bin file and update it.
Please note that the new XGPIO driver in the petalinux
2.6.2 kernel suuports the "read" function to read from
"/dev/gpio*" where '*' is the number of your GPIO
instance. The implementation of the GPIO read()
function is "interrupt-based" and this requires you to
enable the interrupts for GPIO instance in the Xilinx
EDK. The kernel 2.4 driver doesn't handle GPIO
interrupts.
Note that calling the function read() on a non
interrupt-based GPIO will NEVER return !! So, to read
the GPIO in non-interrupt based applications, use the
IOCTL commands.
____________________________________________________________________________________
Fussy? Opinionated? Impossible to please? Perfect. Join Yahoo!'s user panel and lay it on us. http://surveylink.yahoo.com/gmrs/yahoo_panel_invite.asp?a=7
___________________________
microblaze-uclinux mailing list
microblaze-uclinux@xxxxxxxxxxxxxx
Project Home Page : http://www.itee.uq.edu.au/~jwilliams/mblaze-uclinux
Mailing List Archive : http://www.itee.uq.edu.au/~listarch/microblaze-uclinux/