#include #include #include #include #include static unsigned char PortData = 0; static unsigned char PortStatus = 0; static unsigned char PortCtl = 0; #define BASE 0x378 #define DATA (unsigned int)(BASE) /* Centronics data port */ #define STAT (BASE+1) /* Centronics status port */ #define CTRL (BASE+2) /* Centronics control port */ /* ----- local functions ---------------------------------------------- */ static void bit_mcselec_setscl(int data, int state) { if (state) { PortCtl |= 0x08; } else { PortCtl &= 0xf7; } outb(PortCtl, CTRL); } static void bit_mcselec_setsda(int data, int state) { if (state) { PortData &= 0x7f; } else { PortData |= 0x80; } outb(PortData, DATA); } static int bit_mcselec_getscl(int data) { return (inb(STAT) & 0x08); } static int bit_mcselec_getsda(int data) { return (inb(STAT) & 0x80); } main () { char tmp[3]; if (ioperm(BASE, 3, 1)) { perror("ioperm"); exit(1); } printf("Will test SDA\n"); printf("SDA High\n"); bit_mcselec_setsda(BASE, 1); sleep(1); printf("Reading SDA: %d\n", bit_mcselec_getsda(BASE)); printf("Press ENTER to continue"); fgets(tmp, 2, stdin); printf("SDA Low\n"); bit_mcselec_setsda(BASE, 0); sleep(1); printf("Reading SDA: %d\n", bit_mcselec_getsda(BASE)); printf("Press ENTER to continue"); fgets(tmp, 2, stdin); printf("Will test SCL\n"); printf("SCL High\n"); bit_mcselec_setscl(BASE, 1); sleep(1); printf("Reading SCL: %d\n", bit_mcselec_getscl(BASE)); printf("Press ENTER to continue"); fgets(tmp, 2, stdin); printf("SCL Low\n"); bit_mcselec_setscl(BASE, 0); sleep(1); printf("Reading SCL: %d\n", bit_mcselec_getscl(BASE)); printf("Press ENTER to continue"); fgets(tmp, 2, stdin); printf("Exit\n"); return 0; }