Linux I/O port programming mini-HOWTO: Example code
9. Example codeHere's a piece of simple example code for I/O port access:
/*
* example.c: very simple example of port I/O
*
* This code does nothing useful, just a port write, a pause,
* and a port read. Compile with `gcc -O2 -o example example.c',
* and run as root with `./example'.
*/
#include <stdio.h>
#include <unistd.h>
#include <asm/io.h>
#define BASEPORT 0x378 /* lp1 */
int main()
{
/* Get access to the ports */
if (ioperm(BASEPORT, 3, 1)) {perror("ioperm"); exit(1);}
/* Set the data signals (D0-7) of the port to all low (0) */
outb(0, BASEPORT);
/* Sleep for a while (100 ms) */
usleep(100000);
/* Read from the status port (BASE+1) and display the result */
printf("status: %d\n", inb(BASEPORT + 1));
/* We don't need the ports anymore */
if (ioperm(BASEPORT, 3, 0)) {perror("ioperm"); exit(1);}
exit(0);
}
/* end of example.c */
.
Wyszukiwarka
Podobne podstrony:
io port programming 3ogqzy3bscrrpgv753q3uywjfexgwwoiiffd46a 3ogqzy3bscrrpgv753q3uywjfexgwwoiiffd46aio port programming 3 qy2fcczvezn6os2r4msukcj6sj3wb2c66g52tqa qy2fcczvezn6os2r4msukcj6sj3wb2c66g52tqio port programming 4 g663ndzpyars5zgt4bwhjhckiymx7v2jb25jzty g663ndzpyars5zgt4bwhjhckiymx7v2jb25jztio port programming 2 aob45svpsjh4idgeh6zm2erfyrgapt5u3bvnrry aob45svpsjh4idgeh6zm2erfyrgapt5u3bvnrrio port programming 5 eudg6ob6aa23wgf3psn55ug2wapp6nwmdmz2liq eudg6ob6aa23wgf3psn55ug2wapp6nwmdmz2liio port programming 8 kfkr3yd2ttnqzyo6fab47vs6kqduy2bk6adhpoa kfkr3yd2ttnqzyo6fab47vs6kqduy2bk6adhpoio port programming 8 kfkr3yd2ttnqzyo6fab47vs6kqduy2bk6adhpoa kfkr3yd2ttnqzyo6fab47vs6kqduy2bk6adhpoio port programming 1 wkqbqwnae5anupch4hacfas7n2bjo7fkiedj4ga wkqbqwnae5anupch4hacfas7n2bjo7fkiedj4gio port programming 7 vt6et7vbhj5d2moglnxb7rbnttgey5fviyfjajy vt6et7vbhj5d2moglnxb7rbnttgey5fviyfjajIO Port Programmingio port programming 6 fottyb2eobrw7za26dggcajjim4gtl6p2ubx7yy fottyb2eobrw7za26dggcajjim4gtl6p2ubx7yio programming pl 11io programming pl 1io programming pl 2IO Programming pl (3)IO Programming pl (2)io programming pl 10więcej podobnych podstron