📄 spiftest.c
字号:
# ifndef lint [static char sccsid[] = "@(#)spiftest.c 1.1 7/30/92 Copyright 1992 Sun Microsystems,Inc.";#endif ]/* * spiftest.c - * */#include <stdio.h>#include <strings.h>#include <ctype.h>#include <sys/errno.h>#include <sys/types.h>#include <sys/termios.h>#include <sys/fcntl.h>#include <sys/ttold.h>#include <sys/file.h>#include <sys/wait.h>#include <sys/mman.h>#include <signal.h>#include "sdrtns.h" /* should always be included */#include "../../../lib/include/libonline.h" /* online library include *//* * SPC/S device driver include files - if SPC/S is installed, * they will be in /usr/sys/sbusdev, but since spiftest will be * released from stomper, or another server, they may not be there. */#include "stcio.h"#include "stcreg.h"#include "spiftest.h"#include "spif_dev.h"#include "spif_msg.h"extern int process_spif_args();extern int routine_usage();extern int errno;/* SPC/S test related */static void wait_pid_update();void enable_softcar();void probe_spif();void int_loopback();void data_loopback();void modem_loopback();void sigint_handler();void print_pp_file();void print_sp_file();void echo_tty();void get_modem_bits();void data_timeout();void rw_loop();void flush_io();int get_brd_num();#define DTR_MASK \(TIOCM_LE|TIOCM_RTS|TIOCM_ST|TIOCM_SR|TIOCM_CTS|TIOCM_CD|TIOCM_RI|TIOCM_DSR)main(argc, argv)int argc;char *argv[];{ int i, fd; versionid = "%I"; /* SCCS version id */ /* Initialize tests arguments */ signal(SIGINT, sigint_handler); /* Default values */ baud = 9600; csize = 8; sbit = 1; parity = 0; flow = 1; data = 0xaaaaaaaa; strcpy(parity_str, "none"); strcpy(flow_str, "rtscts"); for (i = 0; i < MAX_BOARDS; i++) { spif[i] = OFF; } /* parallel = FALSE; */ strcpy(test_name, "spiftest"); /* termios values are not actually set with TCSETS yet */ for (i = 0; i < TOTAL_IO_PORTS; i++) { sp_ports[i].selected = OFF; sp_ports[i].fd = 0; sp_ports[i].termios.c_iflag = BRKINT; sp_ports[i].termios.c_oflag = 0; sp_ports[i].termios.c_lflag = 0; sp_ports[i].termios.c_cflag = CLOCAL|CREAD|HUPCL; } /* Always start with test_init to enter sundiag environment */ test_init(argc, argv, process_spif_args, routine_usage, test_usage_msg); dev_test(); clean_up(); /* Always end with test_end to close up sundiag environment */ test_end();} /* main *//* * Process_spif_args - * * Processes test-specific command line aguments. * For termios related arguments (baud rate, character size, etc.), * the argument is verified to be valid only. No actual assigment * to the serial port termios is done. It is deferred until dev_test * to take default values into account. */process_spif_args(argv, index)char *argv[];int index;{ int match = FALSE; u_int i, brd, tmask, smask; tmask = smask = 0; if (!strncmp(argv[index],"D=",2)) { /* Get device name from sundiag - * Can be any installed board, board in slot 1-3, or * or specific serial port. If individual device is * specified, seach for serial port device first, * then parallel port. */ if (!strncmp(&argv[index][2], "any",3)) { probe_spif(); strcpy(dev_name, "any SPC/S board"); match = TRUE; } else if (!strncmp(&argv[index][2], "sb1",3)) { for (i=0; i < MAX_TERMS; i++) sp_ports[i].selected = ON; spif[0] = ON; strcpy(dev_name, spif_dev_name[0]); match = TRUE; } else if (!strncmp(&argv[index][2], "sb2",3)) { for (i=MAX_TERMS; i < (2*MAX_TERMS); i++) sp_ports[i].selected = ON; spif[1] = ON; strcpy(dev_name, spif_dev_name[1]); match = TRUE; } else if (!strncmp(&argv[index][2], "sb3",3)) { for (i=2*MAX_TERMS; i < (3*MAX_TERMS); i++) sp_ports[i].selected = ON; spif[2] = ON; strcpy(dev_name, spif_dev_name[2]); match = TRUE; } else if (!strncmp(&argv[index][2], "sb4",3)) { for (i=3*MAX_TERMS; i < TOTAL_IO_PORTS; i++) sp_ports[i].selected = ON; spif[3] = ON; strcpy(dev_name, spif_dev_name[3]); match = TRUE; } else { for (i=0; (i < TOTAL_IO_PORTS) && (!match); i++) { if (!strcmp(sp_dev_name[i], &argv[index][2])) { brd = get_brd_num(i); spif[brd] = ON; strcpy(dev_name, sp_dev_name[i]); sp_ports[i].selected = ON; match = TRUE; } } } /* search for parallel device */ if (!match) { for (i=0; i < MAX_BOARDS; i++) { if (!strcmp(pp_dev_name[i], &argv[index][2])) { strcpy(dev_name, &argv[index][2]); match = TRUE; /* parallel = TRUE; */ spif[i] = ON; } } } /* still no device selected */ if (!match) return(FALSE); } else if (!strncmp(argv[index],"q",1)) { /* Enable internal test if quick test is selected */ testid[INTERNAL] = ON; } else if (!strncmp(argv[index],"T=",2)) { /* Get test mask from sundiag, a five-bit binary value * to specify a combination of test selected. * if bit 0 = ON, internal test is selected * 1 = ON, printer test is selected * 2 = ON, spif 96-pin loopback * 3 = ON, DB-25 loopback * 4 = ON, echo tty test */ tmask = atoi(&argv[index][2]); if ((tmask < 1) || (tmask > 31)) return(FALSE); for (i = 0; i < MAX_TESTS; i++) testid[i] = ON; /* turn on all tests initially */ for (i = 0; i < MAX_TESTS; i++) { smask = 1 << i; /* create select mask */ if (!(tmask & smask)) testid[i] = OFF; } } else if (!strncmp(argv[index],"B=",2)) { baud = atoi(&argv[index][2]); switch(baud) { case 110 : case 300 : case 600 : case 1200 : case 2400 : case 4800 : case 9600 : case 19200 : case 38400 : break; default : return(FALSE); } } else if (!strncmp(argv[index],"C=",2)) { csize = atoi(&argv[index][2]); switch (csize) { case 5 : case 6 : case 7 : case 8 : break; default : return(FALSE); } } else if (!strncmp(argv[index],"S=",2)) { sbit = atoi(&argv[index][2]); if ((sbit != 2) && (sbit != 1)) return(FALSE); } else if (!strncmp(argv[index],"P=",2)) { strcpy(parity_str,&argv[index][2]); if (!strcmp(&argv[index][2], "none")) parity = 0; if (!strcmp(&argv[index][2], "odd")) parity = 1; if (!strcmp(&argv[index][2], "even")) parity = 2; switch (parity) { case 0 : case 1 : case 2 : break; default : return(FALSE); } } else if (!strncmp(argv[index],"F=",2)) { strcpy(flow_str,&argv[index][2]); if (!strcmp(&argv[index][2], "xonoff")) flow = 0; if (!strcmp(&argv[index][2], "rtscts")) flow = 1; if (!strcmp(&argv[index][2], "both")) flow = 2; switch (flow) { case 0 : case 1 : case 2 : break; default : return(FALSE); } } else if (!strncmp(argv[index],"I=",2)) { switch(argv[index][2]) { case '5' : data = 0x55555555; break; case 'a' : data = 0xaaaaaaaa; break; case 'r' : data = random(); break; default : return(FALSE); } } else return(FALSE); return(TRUE);} /* process_spif_args *//* * routine_usage() explains the meaning of each test-specific command * argument. */routine_usage(){ send_message(0, CONSOLE, routine_msg, test_name);}/* * The probing function should check that the specified device is available * to be tested(optional if run by Sundiag). Usually, this involves opening * the device file, and using an appropriate ioctl to check the status of the * device, and then closing the device file. */voidprobe_spif(){ struct stcregs_t *sr; int i, j, fd, offset, flag = FALSE; func_name = "probe_spif"; TRACE_IN for (i = 0; i < MAX_BOARDS; i++) { send_message(0, TRACE, "%s: ", spif_dev_name[i]); if ((fd=open(spif_dev_name[i],O_RDWR)) != FAIL) { flag++; spif[i] = ON; for (j = i*MAX_TERMS; j < (i+1)*MAX_TERMS; j++) sp_ports[j].selected = ON; send_message(0, TRACE, "Board %d installed\n", i); close(fd); } } if (!flag) { send_message(0, ERROR, probe_err_msg); exit(PROBE_ERROR); } TRACE_OUT} /* probe_spif *//* * set_termios - * * Assign termios value for each serial port selected. */voidset_termios(port)int port;{ int i, fd; func_name = "set_termios"; TRACE_IN switch(baud) { case 110 : sp_ports[port].termios.c_cflag |= B110; break; case 300 : sp_ports[port].termios.c_cflag |= B300; break; case 600 : sp_ports[port].termios.c_cflag |= B600; break; case 1200 : sp_ports[port].termios.c_cflag |= B1200; break; case 2400 : sp_ports[port].termios.c_cflag |= B2400; break; case 4800 : sp_ports[port].termios.c_cflag |= B4800; break; case 9600 : sp_ports[port].termios.c_cflag |= B9600; break; case 19200 : sp_ports[port].termios.c_cflag |= B19200; break; case 38400 : sp_ports[port].termios.c_cflag |= B38400; break; default : send_message(UNEXP_ERROR, ERROR, routine_msg); } switch (csize) { case 5 : sp_ports[port].termios.c_cflag |= CS5; break; case 6 : sp_ports[port].termios.c_cflag |= CS6; break; case 7 : sp_ports[port].termios.c_cflag |= CS7; break; case 8 : sp_ports[port].termios.c_cflag |= CS8; break; default : send_message(UNEXP_ERROR, ERROR, routine_msg); } if (sbit == 2) sp_ports[port].termios.c_cflag |= CSTOPB; switch (parity) { case 0 : break; case 1 : sp_ports[port].termios.c_cflag |= PARENB | PARODD; break; case 2 : sp_ports[port].termios.c_cflag |= PARENB; break; default : send_message(UNEXP_ERROR, ERROR, routine_msg); } switch (flow) { case 0 : sp_ports[port].termios.c_iflag |= IXON | IXOFF; break; case 1 : if ((testid[SP_96]) || (testid[DB_25])) sp_ports[port].termios.c_cflag |= CRTSCTS; break; case 2 : sp_ports[port].termios.c_iflag |= IXON | IXOFF; if ((testid[SP_96]) || (testid[DB_25])) sp_ports[port].termios.c_cflag |= CRTSCTS; break; default :
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -