/* outport.c -- An example of low-level io from userspace                                        */


#include <stdio.h>

#include <asm/types.h>   /* headers for architecture specific data types                         */
#include <unistd.h>      /* contains the prototype for i386 specific ioperm functioni            */
#include <asm/io.h>      /* obviously architecture specific (asm directory) for inb, outb macros */

#define LP_BASE 0x240

int main(int argc, char **argv) {

	__u8 portdata;

	if(argc < 2) {
		fprintf(stderr, "Must supply a value to send to port...\n");
		exit(1);
	}

	portdata = (__u8) atoi(argv[1]);


	/* let us know the value of portdata */
	printf("Value submitted for sending to hardware: %i\n", portdata);

	/* attempt to reserve region in io space */
	if(ioperm(LP_BASE, 3, 1) < 0) {
		fprintf(stderr, "Cannot reserve region in io space, aborting...\n");
		exit(1);
	}

	/* send data byte to io port */
	outb(portdata, LP_BASE);

	/* attempt to release reserved region in io space */
	if(ioperm(LP_BASE, 3, 0) < 0) {
		fprintf(stderr, "Cannot release region in io space, aborting...\n");
		exit(1);
	}

	return(0);  /* just to be nice ;) */

}
