/* * ikonex.c * hardcopy driver/board test and exercise program * based on IKONdma.c v2.7 by Interface Consultants * * Tahoma Technology (formerly Ikon Corporation) driver * 107 2nd Avenue North * Seattle, WA, USA 98109 * * 206.728.6465 * http://www.tahomatech.com * tahoma@tahomatech.com * * * 1 November, 2000 * * 10 February, 2001 define _IOC_SIZEMASK & _IOC_SIZESHIFT for Solaris * * 19 November, 2001 corrected errors in self documenting printfs * made "Tahoma" changes in comments * * 6 May, 2002 changed include file from ihcp_io.h to ikonex.h * added crlf and ff (ascii) commands * updated company info * * 14 June, 2002 changed back to including ihcp_io.h * * 8 July, 2002 corrected mode self doc printf * * 20 April, 2004 hack to try to make interactive * * 8 March, 2007 add endian ioctl support * move IkonRegStruct here and eliminate .h file */ #define _IOC_SIZEMASK 0xFF #define _IOC_SIZESHIFT 16 static char VersionString[] = { "ikonex - 8 March, 2007" }; static char IkonCorp[] = { "Tahoma Technology (formerly Ikon Corporation), Seattle, WA, USA" }; /* * this program outputs files in print or plot DMA mode * and allows issuing assorted commands to the board, * driver, and plotter */ #include #include #include #include #include #include #include #include #include "./ihcp_io.h" #define TRUE 1 #define FALSE 0 struct IkonRegStruct { uint DevandVendID; uint RevID; uint PlxIntControlandStatus; uint PlxEepromControl; uint PlxDmaMode; uint PlxDmaPciAddress; uint PlxDmaLocalAddress; uint PlxDmaTransferCount; uint PlxDmaDescriptorPointer; uint PlxDmaCommandStatusReg; uint InterruptMask; uint Mode; uint DeviceControl; uint InterfaceControl; uint InterfaceStatus; uint DeviceStatus; uint ReverseData; uint AutoLtrCountLow; uint AutoLtrCountHigh; } IkonReg; static int interactive; static int verbose; static char *plot_data; static ulong pd_cnt; static uint timeout; static uint cmd_arg; static int arg_set = 0; static int file_ptr = -1; /*************************************************************************/ void try_exit(void) { if(!interactive) exit(-1); } /*************************************************************************/ int dma_one_block(char *string, ulong byte_count) { ulong rc; if (file_ptr == -1) { printf("Error device not open - use -w<> at start of command\n"); return 1; } rc = write(file_ptr, string, byte_count); if (rc != byte_count) { perror("Error on write in dma_one_block"); return 1; } return 0; } /*************************************************************************/ int dma_file(char *file_name) { int file_handle; uint rc; char *buff1; char *buff2; char *buff; ulong buff_cnt; ulong rd_cnt; if (file_ptr == -1) { printf("Error device not open - use -w<> at start of command\n"); return 1; } /* open the file */ file_handle = open(file_name, O_RDONLY); if (file_handle == -1) { printf("Error - unable to open file: %s\n", file_name); perror(""); return 1; } /* allocate the data buffers */ buff1 = (char *) malloc(pd_cnt); if (buff1 == (char *) NULL) { printf("Error - unable to allocate 1st buffer: %ld bytes\n", pd_cnt); perror(""); return 1; } if (verbose == TRUE) printf("Allocated buff1 of %ld bytes\n", pd_cnt); buff2 = (char *) malloc(pd_cnt); if (buff2 == (char *) NULL) { printf("Error - unable to allocate 2nd buffer: %ld bytes\n", pd_cnt); perror(""); return 1; } if (verbose == TRUE) printf("Allocated buff2 of %ld bytes\n", pd_cnt); /* set the first buffer pointer */ plot_data = buff1; /* output the file */ /* * ikon note: Ikon's drivers do not return from write * until the dma buffer has been completely transferred * to the board's fifos. Double buffering is not required. */ while (1) { /* read a buffer full */ buff_cnt = 0; while (1) { rd_cnt = pd_cnt - buff_cnt; /* how many left to read */ if (rd_cnt > 65534L) { /* limit each read to max */ rd_cnt = 65534L; } buff = (char *) ((char *) plot_data + buff_cnt); rc = read(file_handle, buff, (uint) rd_cnt); /* can only read 64K */ if (rc == -1) { perror("Error on read file in dma_file"); return 1; } buff_cnt += rc; if (buff_cnt >= pd_cnt) { /*printf("Buffer Full\n"); */ break; } if (rc == 0) { /*printf("End of File rc==0\n"); */ break; } } /* output the buffer if there is anything in it */ if (buff_cnt != 0) { /*printf("Outputting one buffer cnt=%lu\n",buff_cnt); */ if(dma_one_block(plot_data, buff_cnt)) { printf("dma_one_block error!\n"); return 1; } } else { /*printf("Not Outputting one buffer cnt=%lu\n",buff_cnt); */ break; } /* toggle the buffer pointers */ if (plot_data == buff1) { plot_data = buff2; } else { plot_data = buff1; } } if (buff1 != (char *) NULL) { free(buff1); if (verbose == TRUE) printf("Freed buff1\n"); } if (buff2 != (char *) NULL) { free(buff2); if (verbose == TRUE) printf("Freed buff2\n"); } return 0; } /*************************************************************************/ int issue_cmd(char *cmd_str) { int rc; uint local_arg; if (verbose == TRUE) printf("issue_cmd cmd_str = %s\n", cmd_str); if (file_ptr == -1) { printf("Error device not open - use -w<> at start of command\n"); return 1; } /* SPEED COMMANDS */ if (!strcmp(cmd_str, "SPEED_0")) { if (verbose == TRUE) printf("cmd = SPEED_0\n"); local_arg = IHCPIO_SPEED0; rc = ioctl(file_ptr, IHCPIO_SET_CONFIG, &local_arg); if (rc != 0) { perror("Error on ioctl SPEED_0\n"); return 1; } return 0; } if (!strcmp(cmd_str, "SPEED_1")) { if (verbose == TRUE) printf("cmd = SPEED_1\n"); local_arg = IHCPIO_SPEED1; rc = ioctl(file_ptr, IHCPIO_SET_CONFIG, &local_arg); if (rc != 0) { perror("Error on ioctl SPEED_1\n"); return 1; } return 0; } if (!strcmp(cmd_str, "SPEED_2")) { if (verbose == TRUE) printf("cmd = SPEED_2\n"); local_arg = IHCPIO_SPEED2; rc = ioctl(file_ptr, IHCPIO_SET_CONFIG, &local_arg); if (rc != 0) { perror("Error on ioctl SPEED_2\n"); return 1; } return 0; } if (!strcmp(cmd_str, "SPEED_3")) { if (verbose == TRUE) printf("cmd = SPEED_3\n"); local_arg = IHCPIO_SPEED3; rc = ioctl(file_ptr, IHCPIO_SET_CONFIG, &local_arg); if (rc != 0) { perror("Error on ioctl SPEED_3\n"); return 1; } return 0; } /* MODE COMMANDS */ if (!strcmp(cmd_str, "VPRINT")) { if (verbose == TRUE) printf("cmd = VPRINT\n"); local_arg = IHCPIO_V_NPRINT;; rc = ioctl(file_ptr, IHCPIO_SET_VMODE, &local_arg); if (rc != 0) { perror("Error on ioctl VPRINT\n"); return 1; } return 0; } if (!strcmp(cmd_str, "VPLOT")) { if (verbose == TRUE) printf("cmd = VPLOT\n"); local_arg = IHCPIO_V_PLOT; rc = ioctl(file_ptr, IHCPIO_SET_VMODE, &local_arg); if (rc != 0) { perror("Error on ioctl VPLOT\n"); return 1; } return 0; } if (!strcmp(cmd_str, "VPRINTPLOT")) { if (verbose == TRUE) printf("cmd = VPRINTPLOT\n"); local_arg = IHCPIO_V_SPP; rc = ioctl(file_ptr, IHCPIO_SET_VMODE, &local_arg); if (rc != 0) { perror("Error on ioctl VPRINTPLOT\n"); return 1; } return 0; } if (!strcmp(cmd_str, "DEV_RESET")) { if (verbose == TRUE) printf("cmd = DEV_RESET\n"); rc = ioctl(file_ptr, IHCPIO_DEV_RESET, &local_arg); if (rc != 0) { perror("Error on ioctl DEV_RESET\n"); return 1; } return 0; } /* PULSED COMMANDS */ if (!strcmp(cmd_str, "VCLR")) { if (verbose == TRUE) printf("cmd = VCLR\n"); local_arg = IHCPIO_VCLR; rc = ioctl(file_ptr, IHCPIO_V_CMD, &local_arg); if (rc != 0) { perror("Error on ioctl VCLR\n"); return 1; } return 0; } if (!strcmp(cmd_str, "VFED")) { if (verbose == TRUE) printf("cmd = VFED\n"); local_arg = IHCPIO_VFED; rc = ioctl(file_ptr, IHCPIO_V_CMD, &local_arg); if (rc != 0) { perror("Error on ioctl VFED\n"); return 1; } return 0; } if (!strcmp(cmd_str, "VEOT")) { if (verbose == TRUE) printf("cmd = VEOT\n"); local_arg = IHCPIO_VEOT; rc = ioctl(file_ptr, IHCPIO_V_CMD, &local_arg); if (rc != 0) { perror("Error on ioctl VEOT\n"); return 1; } return 0; } if (!strcmp(cmd_str, "VLTR")) { if (verbose == TRUE) printf("cmd = VLTR\n"); local_arg = IHCPIO_VLTR; rc = ioctl(file_ptr, IHCPIO_V_CMD, &local_arg); if (rc != 0) { perror("Error on ioctl VLTR\n"); return 1; } return 0; } /* GET REGISTERS */ if (!strcmp(cmd_str, "GET_REGS")) { if (verbose == TRUE) printf("cmd = GET_REGS\n"); rc = ioctl(file_ptr, IHCPIO_GET_REGS, &IkonReg); if (rc != 0) { perror("Error on ioctl , GET_REGS\n"); return 1; } printf("\n"); printf("GET_REGS - Device & Vendor ID = 0x%x\n", IkonReg.DevandVendID); printf("GET_REGS - Revision ID = 0x%x\n", IkonReg.RevID); printf("GET_REGS - PLX Interrupt Control/Status = 0x%x\n", IkonReg.PlxIntControlandStatus); printf("GET_REGS - PLX EEPROM Control = 0x%x\n", IkonReg.PlxEepromControl); printf("GET_REGS - PLX DMA Mode = 0x%x\n", IkonReg.PlxDmaMode); printf("GET_REGS - PLX DMA Pci Address = 0x%x\n", IkonReg.PlxDmaPciAddress); printf("GET_REGS - PLX DMA Local Address = 0x%x\n", IkonReg.PlxDmaLocalAddress); printf("GET_REGS - PLX DMA Transfer Count = 0x%x\n", IkonReg.PlxDmaTransferCount); printf("GET_REGS - PLX DMA Descriptor Pointer = 0x%x\n", IkonReg.PlxDmaDescriptorPointer); printf("GET_REGS - PLX DMA Command/Status Reg. = 0x%x\n", IkonReg.PlxDmaCommandStatusReg); printf("GET_REGS - Interrupt Mask = 0x%x\n", IkonReg.InterruptMask & 0xFF); printf("GET_REGS - Mode = 0x%x\n", IkonReg.Mode & 0xFF); printf("GET_REGS - Device Control = 0x%x\n", IkonReg.DeviceControl & 0xFF); printf("GET_REGS - Interface Control = 0x%x\n", IkonReg.InterfaceControl & 0xFF); printf("GET_REGS - Interface Status = 0x%x\n", IkonReg.InterfaceStatus & 0xFF); printf("GET_REGS - Device Status = 0x%x\n", IkonReg.DeviceStatus & 0xFF); printf("GET_REGS - Reverse Data = 0x%x\n", IkonReg.ReverseData & 0xFF); printf("GET_REGS - Auto Ltr Count Low = 0x%x\n", IkonReg.AutoLtrCountLow & 0xFF); printf("GET_REGS - Auto Ltr Count High = 0x%x\n", IkonReg.AutoLtrCountHigh & 0xff); return 0; } /* GET STATUS */ if (!strcmp(cmd_str, "GET_STATUS")) { if (verbose == TRUE) printf("cmd = GET_STATUS\n"); rc = ioctl(file_ptr, IHCPIO_GET_STATUS, &local_arg); if (rc != 0) { perror("Error on ioctl GET_STATUS\n"); return 1; } printf("GET_STATUS - status = 0x%x\n", local_arg); if (local_arg & IHCPIO_DEV_RDY) printf("GET_STATUS - Device Ready\n"); if (local_arg & IHCPIO_DEV_BUSY) printf("GET_STATUS - Device Busy\n"); if (local_arg & IHCPIO_DEV_FAULT) printf("GET_STATUS - Device Fault\n"); if (local_arg & IHCPIO_DEV_POUT) printf("GET_STATUS - Device Paper Out\n"); if (local_arg & IHCPIO_DEV_SEL) printf("GET_STATUS - Device Online\n"); return 0; } /* GET BOARD */ if (!strcmp(cmd_str, "GET_BOARD")) { if (verbose == TRUE) printf("cmd = GET_BOARD\n"); rc = ioctl(file_ptr, IHCPIO_GET_BOARD, &local_arg); if (rc != 0) { perror("Error on ioctl GET_BOARD\n"); return 1; } printf("GET_BOARD - Board = 0x%x\n", local_arg); if (local_arg == IHCPIO_VERS_DIFF) printf("GET_BOARD - Strapping is Versatec Differential\n"); if (local_arg == IHCPIO_VERS_TTL) printf("GET_BOARD - Strapping is Versatec TTL\n"); if (local_arg == IHCPIO_CENT) printf("GET_BOARD - Strapping is Centronics\n"); return 0; } /* GET FLAGS */ if (!strcmp(cmd_str, "GET_FLAGS")) { if (verbose == TRUE) printf("cmd = GET_FLAGS\n"); rc = ioctl(file_ptr, IHCPIO_GET_FLAGS, &local_arg); if (rc != 0) { perror("Error on ioctl GET_FLAGS\n"); return 1; } printf("GET_FLAGS - Flags = 0x%x\n", local_arg); return 0; } /* GET FIFO */ if (!strcmp(cmd_str, "GET_FIFO")) { if (verbose == TRUE) printf("cmd = GET_FIFO\n"); rc = ioctl(file_ptr, IHCPIO_GET_FIFO, &local_arg); if (rc != 0) { perror("Error on ioctl GET_FIFO\n"); return 1; } printf("GET_FIFO - FIFO = 0x%x\n", local_arg); if (local_arg & IHCPIO_FIFO_FULL) printf("GET_FIFO - FIFO Full\n"); if (local_arg & IHCPIO_FIFO_HALF) printf("GET_FIFO - FIFO Half Full\n"); if (local_arg & IHCPIO_FIFO_EMPTY) printf("GET_FIFO - FIFO Empty\n"); return 0; } /* PCI_ID */ if (!strcmp(cmd_str, "PCI_ID")) { if (verbose == TRUE) printf("cmd = PCI_ID\n"); rc = ioctl(file_ptr, IHCPIO_DEV_AND_VEND_ID, &local_arg); if (rc != 0) { perror("Error on ioctl DEV_AND_VEND_ID\n"); return 1; } printf("PCI_ID - Device and Vendor IDs = 0x%x\n", local_arg); return 0; } /* INTERFACE STATUS */ if (!strcmp(cmd_str, "INT_STATUS")) { if (verbose == TRUE) printf("cmd = INT_STATUS\n"); rc = ioctl(file_ptr, IHCPIO_INTERFACE_STATUS, &local_arg); if (rc != 0) { perror("Error on ioctl INTERFACE_STATUS\n"); return 1; } printf("INT_STATUS - Status = 0x%x\n", local_arg); return 0; } /* DEVICE STATUS */ if (!strcmp(cmd_str, "DEV_STATUS")) { if (verbose == TRUE) printf("cmd = DEV_STATUS\n"); rc = ioctl(file_ptr, IHCPIO_DEVICE_STATUS, &local_arg); if (rc != 0) { perror("Error on ioctl DEVICE_STATUS\n"); return 1; } printf("DEV_STATUS - Status = 0x%x\n", local_arg); return 0; } /* REVERSE DATA */ if (!strcmp(cmd_str, "REV_DATA")) { if (verbose == TRUE) printf("cmd = REV_DATA\n"); rc = ioctl(file_ptr, IHCPIO_REVERSE_DATA, &local_arg); if (rc != 0) { perror("Error on ioctl REVERSE_DATA\n"); return 1; } printf("REV_DATA - Reverse Data = 0x%x\n", local_arg); return 0; } /* READY WAIT */ if (!strcmp(cmd_str, "RDY_WAIT")) { if (verbose == TRUE) printf("cmd = RDY_WAIT\n"); rc = ioctl(file_ptr, IHCPIO_RDY_WAIT, &local_arg); if (rc != 0) { perror("Error on ioctl RDY_WAIT\n"); return 1; } printf("RDY_WAIT - wait complete\n"); return 0; } /* HALF WAIT */ if (!strcmp(cmd_str, "HALF_WAIT")) { if (verbose == TRUE) printf("cmd = HALF_WAIT\n"); rc = ioctl(file_ptr, IHCPIO_HALF_WAIT, &local_arg); if (rc != 0) { perror("Error on ioctl HALF_WAIT\n"); return 1; } printf("HALF_WAIT - wait complete\n"); return 0; } /* STREAM ON */ if (!strcmp(cmd_str, "STREAM_ON")) { if (verbose == TRUE) printf("cmd = STREAM_ON\n"); rc = ioctl(file_ptr, IHCPIO_STREAM_ON, &local_arg); if (rc != 0) { perror("Error on ioctl STREAM_ON\n"); return 1; } return 0; } /* STREAM OFF */ if (!strcmp(cmd_str, "STREAM_OFF")) { if (verbose == TRUE) printf("cmd = STREAM_OFF\n"); rc = ioctl(file_ptr, IHCPIO_STREAM_OFF, &local_arg); if (rc != 0) { perror("Error on ioctl STREAM_OFF\n"); return 1; } return 0; } /* MASTER CLEAR */ if (!strcmp(cmd_str, "MASTER_CLEAR")) { if (verbose == TRUE) printf("cmd = MASTER_CLEAR\n"); rc = ioctl(file_ptr, IHCPIO_MASTER_CLEAR, &local_arg); if (rc != 0) { perror("Error on ioctl MASTER_CLEAR\n"); return 1; } return 0; } /* SOFT ACK */ if (!strcmp(cmd_str, "SOFT_ACK")) { if (verbose == TRUE) printf("cmd = SOFT_ACK\n"); rc = ioctl(file_ptr, IHCPIO_SOFT_ACK, &local_arg); if (rc != 0) { perror("Error on ioctl SOFT_ACK\n"); return 1; } return 0; } /* AUTO LTR ON */ if (!strcmp(cmd_str, "AUTO_LTR_ON")) { if (verbose == TRUE) printf("cmd = AUTO_LTR_ON\n"); rc = ioctl(file_ptr, IHCPIO_AUTO_LTR_ON, &local_arg); if (rc != 0) { perror("Error on ioctl AUTO_LTR_ON\n"); return 1; } return 0; } /* AUTO LTR OFF */ if (!strcmp(cmd_str, "AUTO_LTR_OFF")) { if (verbose == TRUE) printf("cmd = AUTO_LTR_OFF\n"); rc = ioctl(file_ptr, IHCPIO_AUTO_LTR_OFF, &local_arg); if (rc != 0) { perror("Error on ioctl AUTO_LTR_OFF\n"); return 1; } return 0; } /* BIG ENDIAN */ if (!strcmp(cmd_str, "BIG_ENDIAN")) { if (verbose == TRUE) printf("cmd = BIG_ENDIAN\n"); rc = ioctl(file_ptr, IHCPIO_BIG_ENDIAN, &local_arg); if (rc != 0) { perror("Error on ioctl BIG_ENDIAN\n"); return 1; } return 0; } /* LITTLE ENDIAN */ if (!strcmp(cmd_str, "LITTLE_ENDIAN")) { if (verbose == TRUE) printf("cmd = LITTLE_ENDIAN\n"); rc = ioctl(file_ptr, IHCPIO_LITTLE_ENDIAN, &local_arg); if (rc != 0) { perror("Error on ioctl LITTLE_ENDIAN\n"); return 1; } return 0; } /* SET CONFIG */ if (!strcmp(cmd_str, "SET_CONFIG")) { if (verbose == TRUE) printf("cmd = SET_CONFIG\n"); if (!arg_set) { printf("Error - SET_CONFIG requires argument\n"); exit(-1); } rc = ioctl(file_ptr, IHCPIO_SET_CONFIG, &cmd_arg); if (rc != 0) { perror("Error on ioctl SET_CONFIG\n"); return 1; } return 0; } /* AUTO LTR COUNT */ if (!strcmp(cmd_str, "AUTO_LTR_COUNT")) { if (verbose == TRUE) printf("cmd = AUTO_LTR_COUNT\n"); if (!arg_set) { printf("Error - AUTO_LTR_COUNT requires argument\n"); return 1; } rc = ioctl(file_ptr, IHCPIO_AUTO_LTR_COUNT, &cmd_arg); if (rc != 0) { perror("Error on ioctl AUTO_LTR_COUNT\n"); return 1; } return 0; } /* DIRECT MODE */ if (!strcmp(cmd_str, "DIRECT_MODE")) { if (verbose == TRUE) printf("cmd = DIRECT_MODE\n"); if (!arg_set) { printf("Error - DIRECT_MODE requires argument\n"); return 1; } rc = ioctl(file_ptr, IHCPIO_DIRECT_MODE, &cmd_arg); if (rc != 0) { perror("Error on ioctl DIRECT_MODE\n"); return 1; } return 0; } /* DEVICE CONTROL */ if (!strcmp(cmd_str, "DEV_CONTROL")) { if (verbose == TRUE) printf("cmd = DEV_CONTROL\n"); if (!arg_set) { printf("Error - DEV_CONTROL requires argument\n"); return 1; } rc = ioctl(file_ptr, IHCPIO_DEVICE_CONTROL, &cmd_arg); if (rc != 0) { perror("Error on ioctl DEVICE_CONTROL\n"); return 1; } return 0; } printf("Error - invalid command: %s\n", cmd_str); return 1; } /*************************************************************************/ void useage(void) { char dummystr[8]; printf("\nUsage: ikonex -w<> [-d<>] [-m<>] [-f<>] [-b<>] [-a<>] [-c<>] [-s<>] [-n] [-p] [-v] [-t<>] [-i] [-h] [-q]\n"); printf(" -w (required- e.g. /dev/ihcp0)\n"); printf(" -d (optional - default=16 max=128)\n"); printf(" -m mode for transfer, PRINT or PLOT\n"); printf(" -f data file to dma to port\n"); printf(" -b output single hex byte using p-i/o\n"); printf(" -a hex argument required (*) for some commands\n"); printf(" -c remote command to board/plotter, can be:\n"); printf(" \n"); printf(" SPEED_0 - slowest handshake speed\n"); printf(" SPEED_1\n"); printf(" SPEED_2\n"); printf(" SPEED_3 - fastest handshake speed\n"); printf(" VPRINT - set Versatec print mode\n"); printf(" VPLOT - set Versatec plot mode\n"); printf("\n--More-- (enter)\n"); fgets(dummystr, 2, stdin); printf(" VPRINTPLOT - set Versatec simultaneous print/plot mode\n"); printf(" DEV_RESET - send reset pulse to plotter\n"); printf(" VCLR - Versatec Remote Clear\n"); printf(" VFED - Versatec Remote Form Feed\n"); printf(" VEOT - Versatec End or Terminate\n"); printf(" VLTR - Versatec Remote Line Terminate\n"); printf(" GET_REGS - print board registers\n"); printf(" GET_STATUS - print formatted device status\n"); printf(" GET_BOARD - print board interface strapping\n"); printf(" GET_FLAGS - print driver internal flags\n"); printf(" GET_FIFO - print fifo status\n"); printf(" PCI_ID - print device and vendor IDs\n"); printf(" INT_STATUS - print interface status register\n"); printf("\n--More-- (enter)\n"); fgets(dummystr, 2, stdin); printf(" DEV_STATUS - print device status\n"); printf(" REV_DATA - print contents of reverse data register\n"); printf(" RDY_WAIT - wait for board and plotter ready\n"); printf(" HALF_WAIT - wait for fifo <1/2 full\n"); printf(" STREAM_ON - set Centronics data streaming mode\n"); printf(" STREAM_OFF - clear data streaming mode\n"); printf(" MASTER_CLEAR - the big hammer (use wisely)\n"); printf(" SOFT_ACK - issue software ack to board\n"); printf(" AUTO_LTR_ON enable auto line terminate (Versatec only)\n"); printf(" AUTO_LTR_OFF disable auto line terminate\n"); printf(" BIG_ENDIAN set byte ordering to big endian\n"); printf(" LITTLE_ENDIAN set byte ordering to little endian\n"); printf(" \n"); printf("\n--More-- (enter)\n"); fgets(dummystr, 2, stdin); printf(" * SET_CONFIG - set handshake speed and mode to \n"); printf(" * AUTO_LTR_COUNT - set auto line terminate count to \n"); printf(" * DIRECT_MODE - write to mode register\n"); printf(" * DEV_CONTROL - write to device control register\n"); printf(" \n"); printf(" -s output string to plotter (in current print/plot mode)\n"); printf(" **** strings must be in double quotes ****\n"); printf(" -n output carriage return/line feed pair of ascii characters (in current mode\n"); printf(" -p output carriage return/form feed pair of ascii characters (in current mode)\n"); printf(" \n"); printf(" -t set dma and ready wait timeouts in seconds\n"); printf(" -v toggle verbose mode\n"); printf(" -i enter interactive mode. once in interactive mode all above options may\n"); printf(" be entered **one per line** w/or w/out the leading -\n"); printf(" -h print this help info\n"); printf(" -q exit interactive mode\n"); printf("\n--More-- (enter)\n"); fgets(dummystr, 2, stdin); printf(" \n"); printf("Note: args are executed left to right as found, multiple files in \n"); printf(" different modes can be sent in a single command.\n"); printf(" e.g. ikonex -w/dev/ihcp0 -mPRINT -ffile1.prn -mPLOT -ffile2.plt\n"); printf(" sends file1.prn in print mode, and then file2.plt in plot mode\n"); printf(" commands requiring arguments MUST be preceded by -a\n"); printf(" \n"); printf(" In interactive mode, enter one cmd/value or a per line\n"); printf(" \n"); } /*************************************************************************/ int main(int argc, char **argv) { char *mode_str = NULL; char *file_str = NULL; char *cmd_str = NULL; char *dma_str = NULL; char *timeout_str = NULL; char *arg_str = NULL; uint ioctl_cmd; uint dma_size; uint local_arg; char linestr[132]; char *lineptr; int c; char cstr[32]; char *loptarg = NULL; char loptstr[132]; int rc; /*************************************************************/ /* print opening banner */ /*************************************************************/ printf("\nTahoma Technology driver exerciser and utility output program - %s\n", VersionString); printf(" %s\n\n", IkonCorp); if (argc == 1) { useage(); exit(-1); } interactive = 0; arg_set = 0; verbose = FALSE; pd_cnt = 16 * 1024; /* 16kb default */ /*****************************************************************/ /* get command line or interactive arguments */ /*****************************************************************/ while (1) { if(interactive) { /* * scan for the option flag and argument * avoid any leading '-' and if s (string) * scan for characters between double quotes */ printf("enter command (h = help, q = quit): "); strcpy(linestr,"z"); strcpy(cstr,"z"); strcpy(loptstr,"z"); fgets(linestr, 130, stdin); if((lineptr = strchr(linestr, '-')) != NULL) lineptr++; else lineptr = linestr; sscanf(lineptr, "%1s %130s", cstr, loptstr); c = cstr[0]; if(c == 's') sscanf(lineptr, "%1s \"%[^\"]", &c, loptstr); loptarg = loptstr; } else { c = getopt(argc, argv, "ihqw:d:m:f:b:a:c:s:t:vnp"); loptarg = optarg; } if (c != EOF) { c = tolower(c); switch (c) { case 'q': printf("goodbye...\n"); exit(0); break; case 'i': if (verbose == TRUE) printf("interactive mode set\n"); interactive = TRUE; break; case 'h': useage(); break; case 'w': file_str = loptarg; if(file_ptr > 0) { if(verbose) printf("closing previously open device\n"); close(file_ptr); } if (verbose == TRUE) printf("opening device = %s\n", loptarg); file_ptr = open(loptarg, O_WRONLY); if (file_ptr == -1) { printf("Error opening device %s: \n", loptarg); perror(""); try_exit(); } break; case 'c': cmd_str = loptarg; if (verbose == TRUE) printf("cmd_str = %s\n", cmd_str); if (issue_cmd(cmd_str)) try_exit(); arg_set = 0; break; case 'd': dma_str = loptarg; if (verbose == TRUE) printf("dma_str = %s\n", dma_str); dma_size = (uint) strtol(dma_str, (char **) NULL, 0); if (verbose == TRUE) printf("dma_size = %d\n", dma_size); if (dma_size > 128) { printf("Warning - DMA size of %d exceeds max using DMA size = 128\n", dma_size); dma_size = 128; } pd_cnt = (ulong) dma_size *1024L; break; case 'f': file_str = loptarg; if (verbose == TRUE) printf("file_str = %s\n", file_str); if(dma_file(file_str)) printf("dma_file error!\n"); break; case 'b': arg_str = loptarg; if (verbose == TRUE) printf("byte_str = %s\n", arg_str); local_arg = (uint) strtol(arg_str, (char **) NULL, 0); if (verbose == TRUE) printf("data byte = 0x%x\n", local_arg); if (file_ptr == -1) { printf("Error device not open - use -w<> at start of command\n"); try_exit(); } rc = ioctl(file_ptr, (IHCPIO_DATA_OUT | 1 << _IOC_SIZESHIFT), &local_arg); if (rc != 0) { perror("Error on ioctl DATA_OUT\n"); try_exit(); } break; case 'm': mode_str = loptarg; if (verbose == TRUE) printf("mode_str = %s\n", mode_str); if (file_ptr == -1) { printf("Error device not open - use -w<> at start of command\n"); try_exit(); } if (!strcmp(mode_str, "PLOT")) { if (verbose == TRUE) printf("mode = PLOT\n"); local_arg = IHCPIO_V_PLOT; rc = ioctl(file_ptr, IHCPIO_SET_VMODE, &local_arg); if (rc != 0) { perror("Error on ioctl SET_VMODE\n"); try_exit(); } } else if (!strcmp(mode_str, "PRINT")) { if (verbose == TRUE) printf("mode = PRINT\n"); local_arg = IHCPIO_V_NPRINT; rc = ioctl(file_ptr, IHCPIO_SET_VMODE, &local_arg); if (rc != 0) { perror("Error on ioctl SET_VMODE\n"); try_exit(); } } else { printf("Error: mode not PRINT or PLOT: %s \n", mode_str); try_exit(); } break; case 'v': if (verbose == TRUE) { printf("verbose = FALSE\n"); verbose = FALSE; } else { printf("verbose = TRUE\n"); verbose = TRUE; } break; case 't': timeout_str = loptarg; if (verbose == TRUE) printf("timeout_str = %s\n", timeout_str); if (file_ptr == -1) { printf("Error device not open - use -w<> at start of command\n"); try_exit(); } timeout = (uint) strtol(timeout_str, (char **) NULL, 0); if (verbose == TRUE) printf("timeout = %d\n", timeout); rc = ioctl(file_ptr, IHCPIO_SET_DMATIME, &timeout); if (rc != 0) { perror("Error on ioctl SET_DMATIME\n"); try_exit(); } rc = ioctl(file_ptr, IHCPIO_SET_FIFOTIME, &timeout); if (rc != 0) { perror("Error on ioctl SET_FIFOTIME\n"); try_exit(); } break; case 'a': arg_str = loptarg; if (verbose == TRUE) printf("arg_str = %s\n", arg_str); cmd_arg = (uint) strtol(arg_str, (char **) NULL, 0); if (verbose == TRUE) printf("cmd_arg = 0x%x\n", cmd_arg); arg_set = 1; break; case 's': arg_str = loptarg; if (verbose == TRUE) printf("arg_str = %s\n", arg_str); if (file_ptr == -1) { printf("Error device not open - use -w<> at start of command\n"); try_exit(); } ioctl_cmd = IHCPIO_DATA_OUT | ((strlen(arg_str) & _IOC_SIZEMASK) << _IOC_SIZESHIFT); rc = ioctl(file_ptr, ioctl_cmd, arg_str); if (rc != 0) { perror("Error on ioctl DATA_OUT\n"); try_exit(); } break; case 'n': if (verbose == TRUE) printf("sending CR/LF\n"); if (file_ptr == -1) { printf("Error device not open - use -w<> at start of command\n"); try_exit(); } ioctl_cmd = IHCPIO_DATA_OUT | ((2 & _IOC_SIZEMASK) << _IOC_SIZESHIFT); rc = ioctl(file_ptr, ioctl_cmd, "\r\n"); if (rc != 0) { perror("Error on ioctl DATA_OUT\n"); try_exit(); } break; case 'p': if (verbose == TRUE) printf("sending CR/FF\n"); if (file_ptr == -1) { printf("Error device not open - use -w<> at start of command\n"); try_exit(); } ioctl_cmd = IHCPIO_DATA_OUT | ((2 & _IOC_SIZEMASK) << _IOC_SIZESHIFT); rc = ioctl(file_ptr, ioctl_cmd, "\r\f"); if (rc != 0) { perror("Error on ioctl DATA_OUT\n"); try_exit(); } break; default: printf("Invalid option \"%c\"\n", c); break; } } else { if (verbose == TRUE) printf("End of arg list\n"); break; } } return (0); } /*************************************************************************/