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

[microblaze-uclinux] gpio_test



hello,

1. When I build the gpio_test application I always get the same output:
DIP SW: 00000000
Why?

2. My microblaze has 5 different GPIOs: DIP switches, 7Segments, Push
buttons, etc. Should I access these with only one node /dev/gpio?
How?

Thank you,
Raul

Am Do, den 24.11.2005 schrieb Vijai.S.Kumar@xxxxxxxxxxxxxxxx um 16:36:
> hello
>         u have to specify the root of romfs in make file of ur hello
> program.
>         and also include ur program in romfs make file as well.
>          so after make clean dep  all
>         u have to make seprate ur hello program
>        then run make romfs command in user proram
>        then goto uclinux dist again and run make image command
>       rthen u will see in bin directory ur program name.
>       the actual procedure u can get on net eaisly
> 
> vijai
> 
> 
> 
> 
> 
>                                                                                                                                                   
>                       Paul Hartke                                                                                                                 
>                       <phartke@xxxxxxxxxxxx>              To:       microblaze-uclinux@xxxxxxxxxxxxxx, Raul Camaras                               
>                       Sent by:                             <raul.camaras@xxxxxxxxxxxxxxxx>                                                        
>                       owner-microblaze-uclinux@ite        cc:       microblaze-uclinux@xxxxxxxxxxxxxx, (bcc: Vijai S Kumar/Services/INFOCOMM/RIL) 
>                       e.uq.edu.au                         Subject:  Re: [microblaze-uclinux] uClinux hello world                                  
>                                                     Importance: Normal  Sender's OU: Reliance |------------------|                                
>                                                                                               | [ ] Confidential |                                
>                       11/24/2005 07:49 PM                                                     |------------------|                                
>                       Please respond to                                                                                                           
>                       microblaze-uclinux                                                                                                          
>                                                                                                                                                   
> 
> 
> 
> 
> Raul,
> 
> See
> http://cvs.uclinux.org/cgi-bin/cvsweb.cgi/uClinux-dist/Documentation/Adding-User-Apps-HOWTO?rev=1.1.1.1
> 
> and
> http://www.itee.uq.edu.au/~jwilliams/mblaze-uclinux/wiki/index.php/OutOfTreeCompile
> 
> 
> Hope this helps.
> 
> Paul
> 
> Quoting Raul Camaras <raul.camaras@xxxxxxxxxxxxxxxx>:
> > Hello,
> >
> > I would like to write a simple program: printf("Hello world!\n");
> > to be able to execute under uClinux. I have to include it in the kernel
> > compilation somehow.
> > What are the steps I must follow to achieve it?
> >
> > Thanks,
> >          - raul
> >
> ___________________________
> 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/
> 
> 
> 
> ___________________________
> 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/
> 
 #include <stdio.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>

#include <linux/types.h>
#include <linux/ioctl.h>

#include <linux/ibm_ocp_gpio.h>

#define GPIO_DEV "/dev/gpio"

void usage(int argc, char *argv[])
{
	fprintf(stderr,"usage: %s hexval\n\n", argv[0]);
	fprintf(stderr,"\n");
	fprintf(stderr,"Puts the input hexval onto the LEDs, and\n");
	fprintf(stderr,"displays the current value on the DIP switches\n");
	fprintf(stderr,"\n");
	fprintf(stderr,"try  gpio_test FC\n\n");

}

void dump_dipsw(int val)
{
	int i;
	val = (val & 0x0000FF00) >> 8;

	printf("DIP SW: ");
	for(i=0;i<8;i++)
	{
		printf("%i",val & 0x01);
		val >>= 1;
	}
	printf("\n");
}

/* Turn 4 LSB of X into 8 bit LED segment code */
unsigned char nyb_hex2led(int x)
{
	unsigned char led_tab[] = {
		0xFC, 0x60, 0xDA, 0xF2,
		0x66, 0xB6, 0xBE, 0xE0,
		0xFE, 0xF6, 0xEE, 0x3E,
		0x9C, 0x7A, 0x9E, 0x8E};

	return led_tab[x & 0xF];
}

/* Turn 8 LSB of x into 2 times 8 bit LED segment codes */
unsigned short hex2led(int x)
{
	return (nyb_hex2led(x & 0xF) << 8) | (nyb_hex2led((x >> 4) & 0xF));
}

int main(int argc, char *argv[])
{
	/* Open the device */
	int fd = open("/dev/gpio", O_RDWR);

	struct ibm_gpio_ioctl_data gpio_ioctl;
	int	result;
	int command;

	if(fd==-1) {
		fprintf(stderr,"Unable to open /dev/gpio\n");
		exit(1);
	}

/*
	if(argc!=2)
	{
		usage();
		exit(1);
	}
*/
	gpio_ioctl.device=0;

	/* Set the tristates */
	gpio_ioctl.mask=0x0000FF00;
	ioctl(fd,IBMGPIO_TRISTATE,(void *)&gpio_ioctl);

	/* Get output data from command line if provided */
	
	if(argc==2)
		sscanf(argv[1],"%x",&(gpio_ioctl.data));
	else
		gpio_ioctl.data=time(NULL);

	/* Convert binary (16 LSB) into LED segment codes and shift into
	   position on gpio */
	gpio_ioctl.data=hex2led(gpio_ioctl.data & 0xFF)<<16;

	ioctl(fd,IBMGPIO_OUT,(void *)&gpio_ioctl);
	
	/* Read some data */
	ioctl(fd,IBMGPIO_IN,(void *)&gpio_ioctl);

	dump_dipsw(gpio_ioctl.data);

	return 0;
}