/* Copyright (C) Magna Carta Software, Inc. 1990, 1991. All Rights Reserved. CCT18.C -- NS16550A FIFO demonstration in polled mode. CAPABILITY: This is CCT00.C modified to support the NS16550A in polled mode with FIFO buffers enabled. Note that this program does not drop characters at 2400bps, although CCT00.C does. This illustrates the effectiveness of the FIFOs. On a port without a 16550A, this program behaves identically to CCT00.C. Note: The default port configuration is I/O address 0X3E8 and IRQ5 (you may change this for your 16550A). */ #include #include #include #include /* our communications routines */ /* MANIFEST CONSTANTS */ #define MENU ALT_M /* key for command summary */ /* FUNCTION PROTOTYPES */ void term(COMM_PORT *p); /* the main program loop */ short menu(void); /* the function that handles the menu */ /* GLOBAL VARIABLES */ COMM_PORT port1; /* the structure describing the port */ short vers = 18; /* the version number of "CCT-COMM" */ /* ------------------------ PROGRAM BEGINS HERE --------------------------- */ int main(void) { /* NOTE THAT WE USE PORT ADDRESS 0X3E8 HERE (YOU CAN CHANGE THIS( */ init_port(&port1, 0X3E8, 2400L, DATABITS8, PARITY_NONE, STOPBITS1); set_16550_threshold(&port1, 14); printf("CCT-COMM Version %d: Press Alt-M for a list of commands\n", vers); term(&port1); printf("\nEnd of CCT-COMM%d\n", vers); return (0); } /* TERM -- The terminal emulation routine. Simply polls the COM port and the keyboard alternately for characters. */ void term(COMM_PORT *p_port) { short c; /* must be int to detect a -1 return */ for (;;) { /* CHECK SERIAL PORT FOR BYTE */ if ( (c = c_inchar(p_port)) != EOF) putchar(c); /* CHECK KEYBOARD FOR A KEY PRESS */ if ((c = inkey()) != 0) { if (c == MENU) { if (menu() == 1) break; } else c_putc(p_port, c); } } } #define EXIT 'Q' /* key to exit from menu */ short menu(void) { short c, retval = 0, DONE = FALSE; static char *menus[] = { "\tQ. EXIT from TERM.", NULL }; char **menup; while (!DONE) { puts("\n\n"); for (menup = menus; *menup != NULL; menup++) printf("%s\n", *menup); printf("\n\t\t Enter selection (CR to quit menu) : "); c = getchar(); c = toupper(c); switch (c) { case EXIT: retval = 1; DONE = TRUE; break; default: DONE = TRUE; break; } } puts("\nExiting menu"); return (retval); /* will be zero except if EXIT */ }