#include #include #include #include #define coma 0x300 #define comb 0x308 #define comc 0x310 #define comd 0x318 #define come 0x320 #define comf 0x328 #define comg 0x330 #define comh 0x338 #define irq 0x5 unsigned int base = 0x200; unsigned int AskForBaseAddress(unsigned int OldOne){ char msg[4]; unsigned int NewOne = 0; int index = 0; int letter; puts("Please enter Base Address of 104-COM-8SM Board"); puts("Input should be 4 HEX numbers: 0350, 0200, etc"); puts("Then press ENTER"); while((letter = getchar())!='\n') msg[index++] = letter; sscanf(msg, "%x", &NewOne); return((NewOne>=0x1000)&&(NewOne<=0xf3f0)) ? NewOne : OldOne; }//Ask void IOPermission() { if(iopl(3)<0) { fprintf(stderr, "NO IO PERMISSION (Are you logged in as Root?)\n"); exit(EXIT_FAILURE); }else puts("Write permission granted to I/O Ports"); }//IOPermission void eepromWrite(int x, int y) { long int pause; outb(x, base + 1); for (pause = 0; pause < 1000000; pause++); outb(y, base + 2); for (pause = 0; pause < 1000000; pause++); } int main(void) { printf("This program will set the base addresses of the com ports in the eeprom.\n"); base = AskForBaseAddress(base); IOPermission(); eepromWrite(1, coma >> 3); printf("COMA set to 0x%X\n", coma); eepromWrite(2, comb >> 3); printf("COMB set to 0x%X\n", comb); eepromWrite(3, comc >> 3); printf("COMC set to 0x%X\n", comc); eepromWrite(4, comd >> 3); printf("COMD set to 0x%X\n", comd); eepromWrite(5, come >> 3); printf("COME set to 0x%X\n", come); eepromWrite(6, comf >> 3); printf("COMF set to 0x%X\n", comf); eepromWrite(7, comg >> 3); printf("COMG set to 0x%X\n", comg); eepromWrite(8, comh >> 3); printf("COMH set to 0x%X\n", comh); eepromWrite(9, irq); printf("IRQ set to 0x%X\n\n", irq); printf("To change these values, please edit the #defined values in sample0.c\n"); printf("\nDone.\nReboot to use.\n"); iopl(0); return 0; }//main