#include #include #include #define POST_ADDR 0x80 void usage( void ); void printLEDs( int x ); main( int argc, char* argv[] ) { int fd; int x, y; char s[ 128 ]; if ( (fd = open( "/dev/io", O_RDWR )) < 0 ) { perror( "can't open IO" ); exit( 1 ); } if ( argc > 1 ) { if ( argv[1][1] == 'a' ) { fprintf( stderr, "testing lower LED\n" ); for ( x = 0; x <= 0x0f; ++x ) { outb( POST_ADDR, x ); printLEDs( x ); sleep( 1 ); } fprintf( stderr, "\ntesting upper LED\n" ); for ( x = 0x00; x <= 0xf0; x += 0x10 ) { outb( POST_ADDR, x ); printLEDs( x ); sleep( 1 ); } exit( 0 ); } else { usage(); exit( 1 ); } } fprintf( stderr, "test pattern (00 thru FF)? " ); while ( fgets( s, 127, stdin ) ) { x = strtol( s, NULL, 16 ); outb( POST_ADDR, x ); printLEDs( x ); fprintf( stderr, "? " ); } } void printLEDs( int x ) { int y; /* LEDs print: AbCdEF */ fprintf( stderr, " You should see: " ); y = (x & 0xf0) >> 4; if ( (y == 0xb) || (y == 0xd) ) fprintf( stderr, "%1x", y ); else fprintf( stderr, "%1X", y ); y = x & 0x0f; if ( (y == 0xb) || (y == 0xd) ) fprintf( stderr, "%1x\n", y ); else fprintf( stderr, "%1X\n", y ); } void usage( void ) { fprintf( stderr, "\ntestpost [-a]\n" ); fprintf( stderr, " -a: cycle each digit from 0 thru F\n" ); }