/* Copyright (C) Magna Carta Software, Inc. 1990,1991. All Rights Reserved. CCT19.C -- NS16550A FIFO demonstration in interrupt mode. CAPABILITY: This is CCT01.C modified to support the NS16550A in interrupt mode with FIFO buffers enabled. 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). COMPATIBILITY: TURBOC v1.5+, POWERC v1.2+, MSC 5.0+/QUICK C, WATCOM C; */ #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 = 19; /* the version number of "CCT-COMM" */ BYTE rxbuf[2048]; /* receive buffer */ /* ------------------------ PROGRAM BEGINS HERE --------------------------- */ int main(void) { init_port(&port1, 0X3E8, 2400L, DATABITS8, PARITY_NONE, STOPBITS1); install_ipr(&port1, RECEIVE, NULL, rxbuf, sizeof(rxbuf)); install_isr(&port1, 5, NULL); /* Using IRQ5 */ 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 */ }