1*4882a593Smuzhiyun /* SPDX-License-Identifier: BSD-3-Clause */ 2*4882a593Smuzhiyun /* 3*4882a593Smuzhiyun usa26msg.h 4*4882a593Smuzhiyun 5*4882a593Smuzhiyun Copyright (C) 1998-2000 InnoSys Incorporated. All Rights Reserved 6*4882a593Smuzhiyun This file is available under a BSD-style copyright 7*4882a593Smuzhiyun 8*4882a593Smuzhiyun Keyspan USB Async Message Formats for the USA28X 9*4882a593Smuzhiyun 10*4882a593Smuzhiyun Redistribution and use in source and binary forms, with or without 11*4882a593Smuzhiyun modification, are permitted provided that the following conditions are 12*4882a593Smuzhiyun met: 13*4882a593Smuzhiyun 14*4882a593Smuzhiyun 1. Redistributions of source code must retain this licence text 15*4882a593Smuzhiyun without modification, this list of conditions, and the following 16*4882a593Smuzhiyun disclaimer. The following copyright notice must appear immediately at 17*4882a593Smuzhiyun the beginning of all source files: 18*4882a593Smuzhiyun 19*4882a593Smuzhiyun Copyright (C) 1998-2000 InnoSys Incorporated. All Rights Reserved 20*4882a593Smuzhiyun 21*4882a593Smuzhiyun This file is available under a BSD-style copyright 22*4882a593Smuzhiyun 23*4882a593Smuzhiyun 2. The name of InnoSys Incorporated may not be used to endorse or promote 24*4882a593Smuzhiyun products derived from this software without specific prior written 25*4882a593Smuzhiyun permission. 26*4882a593Smuzhiyun 27*4882a593Smuzhiyun THIS SOFTWARE IS PROVIDED BY INNOSYS CORP. ``AS IS'' AND ANY EXPRESS OR 28*4882a593Smuzhiyun IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 29*4882a593Smuzhiyun OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 30*4882a593Smuzhiyun NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 31*4882a593Smuzhiyun INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 32*4882a593Smuzhiyun (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 33*4882a593Smuzhiyun SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 34*4882a593Smuzhiyun CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 35*4882a593Smuzhiyun LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 36*4882a593Smuzhiyun OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 37*4882a593Smuzhiyun SUCH DAMAGE. 38*4882a593Smuzhiyun 39*4882a593Smuzhiyun Third revision: USA28X version (aka USA26) 40*4882a593Smuzhiyun 41*4882a593Smuzhiyun Buffer formats for RX/TX data messages are not defined by 42*4882a593Smuzhiyun a structure, but are described here: 43*4882a593Smuzhiyun 44*4882a593Smuzhiyun USB OUT (host -> USAxx, transmit) messages contain a 45*4882a593Smuzhiyun REQUEST_ACK indicator (set to 0xff to request an ACK at the 46*4882a593Smuzhiyun completion of transmit; 0x00 otherwise), followed by data: 47*4882a593Smuzhiyun 48*4882a593Smuzhiyun RQSTACK DAT DAT DAT ... 49*4882a593Smuzhiyun 50*4882a593Smuzhiyun with a total data length of 63. 51*4882a593Smuzhiyun 52*4882a593Smuzhiyun USB IN (USAxx -> host, receive) messages begin with a status 53*4882a593Smuzhiyun byte in which the 0x80 bit is either: 54*4882a593Smuzhiyun 55*4882a593Smuzhiyun (a) 0x80 bit clear 56*4882a593Smuzhiyun indicates that the bytes following it are all data 57*4882a593Smuzhiyun bytes: 58*4882a593Smuzhiyun 59*4882a593Smuzhiyun STAT DATA DATA DATA DATA DATA ... 60*4882a593Smuzhiyun 61*4882a593Smuzhiyun for a total of up to 63 DATA bytes, 62*4882a593Smuzhiyun 63*4882a593Smuzhiyun or: 64*4882a593Smuzhiyun 65*4882a593Smuzhiyun (b) 0x80 bit set 66*4882a593Smuzhiyun indicates that the bytes following alternate data and 67*4882a593Smuzhiyun status bytes: 68*4882a593Smuzhiyun 69*4882a593Smuzhiyun STAT DATA STAT DATA STAT DATA STAT DATA ... 70*4882a593Smuzhiyun 71*4882a593Smuzhiyun for a total of up to 32 DATA bytes. 72*4882a593Smuzhiyun 73*4882a593Smuzhiyun The valid bits in the STAT bytes are: 74*4882a593Smuzhiyun 75*4882a593Smuzhiyun OVERRUN 0x02 76*4882a593Smuzhiyun PARITY 0x04 77*4882a593Smuzhiyun FRAMING 0x08 78*4882a593Smuzhiyun BREAK 0x10 79*4882a593Smuzhiyun 80*4882a593Smuzhiyun Notes: 81*4882a593Smuzhiyun 82*4882a593Smuzhiyun (1) The OVERRUN bit can appear in either (a) or (b) format 83*4882a593Smuzhiyun messages, but the but the PARITY/FRAMING/BREAK bits 84*4882a593Smuzhiyun only appear in (b) format messages. 85*4882a593Smuzhiyun (2) For the host to determine the exact point at which the 86*4882a593Smuzhiyun overrun occurred (to identify the point in the data 87*4882a593Smuzhiyun stream at which the data was lost), it needs to count 88*4882a593Smuzhiyun 128 characters, starting at the first character of the 89*4882a593Smuzhiyun message in which OVERRUN was reported; the lost character(s) 90*4882a593Smuzhiyun would have been received between the 128th and 129th 91*4882a593Smuzhiyun characters. 92*4882a593Smuzhiyun (3) An RX data message in which the first byte has 0x80 clear 93*4882a593Smuzhiyun serves as a "break off" indicator. 94*4882a593Smuzhiyun 95*4882a593Smuzhiyun revision history: 96*4882a593Smuzhiyun 97*4882a593Smuzhiyun 1999feb10 add reportHskiaChanges to allow us to ignore them 98*4882a593Smuzhiyun 1999feb10 add txAckThreshold for fast+loose throughput enhancement 99*4882a593Smuzhiyun 1999mar30 beef up support for RX error reporting 100*4882a593Smuzhiyun 1999apr14 add resetDataToggle to control message 101*4882a593Smuzhiyun 2000jan04 merge with usa17msg.h 102*4882a593Smuzhiyun 2000jun01 add extended BSD-style copyright text 103*4882a593Smuzhiyun 2001jul05 change message format to improve OVERRUN case 104*4882a593Smuzhiyun 105*4882a593Smuzhiyun Note on shared names: 106*4882a593Smuzhiyun 107*4882a593Smuzhiyun In the case of fields which have been merged between the USA17 108*4882a593Smuzhiyun and USA26 definitions, the USA26 definition is the first part 109*4882a593Smuzhiyun of the name and the USA17 definition is the second part of the 110*4882a593Smuzhiyun name; both meanings are described below. 111*4882a593Smuzhiyun */ 112*4882a593Smuzhiyun 113*4882a593Smuzhiyun #ifndef __USA26MSG__ 114*4882a593Smuzhiyun #define __USA26MSG__ 115*4882a593Smuzhiyun 116*4882a593Smuzhiyun 117*4882a593Smuzhiyun struct keyspan_usa26_portControlMessage 118*4882a593Smuzhiyun { 119*4882a593Smuzhiyun /* 120*4882a593Smuzhiyun there are three types of "commands" sent in the control message: 121*4882a593Smuzhiyun 122*4882a593Smuzhiyun 1. configuration changes which must be requested by setting 123*4882a593Smuzhiyun the corresponding "set" flag (and should only be requested 124*4882a593Smuzhiyun when necessary, to reduce overhead on the USA26): 125*4882a593Smuzhiyun */ 126*4882a593Smuzhiyun u8 setClocking, // BOTH: host requests baud rate be set 127*4882a593Smuzhiyun baudLo, // BOTH: host does baud divisor calculation 128*4882a593Smuzhiyun baudHi, // BOTH: baudHi is only used for first port (gives lower rates) 129*4882a593Smuzhiyun externalClock_txClocking, 130*4882a593Smuzhiyun // USA26: 0=internal, other=external 131*4882a593Smuzhiyun // USA17: 0=internal, other=external/RI 132*4882a593Smuzhiyun rxClocking, // USA17: 0=internal, 1=external/RI, other=external/DSR 133*4882a593Smuzhiyun 134*4882a593Smuzhiyun 135*4882a593Smuzhiyun setLcr, // BOTH: host requests lcr be set 136*4882a593Smuzhiyun lcr, // BOTH: use PARITY, STOPBITS, DATABITS below 137*4882a593Smuzhiyun 138*4882a593Smuzhiyun setFlowControl, // BOTH: host requests flow control be set 139*4882a593Smuzhiyun ctsFlowControl, // BOTH: 1=use CTS flow control, 0=don't 140*4882a593Smuzhiyun xonFlowControl, // BOTH: 1=use XON/XOFF flow control, 0=don't 141*4882a593Smuzhiyun xonChar, // BOTH: specified in current character format 142*4882a593Smuzhiyun xoffChar, // BOTH: specified in current character format 143*4882a593Smuzhiyun 144*4882a593Smuzhiyun setTxTriState_setRts, 145*4882a593Smuzhiyun // USA26: host requests TX tri-state be set 146*4882a593Smuzhiyun // USA17: host requests RTS output be set 147*4882a593Smuzhiyun txTriState_rts, // BOTH: 1=active (normal), 0=tristate (off) 148*4882a593Smuzhiyun 149*4882a593Smuzhiyun setHskoa_setDtr, 150*4882a593Smuzhiyun // USA26: host requests HSKOA output be set 151*4882a593Smuzhiyun // USA17: host requests DTR output be set 152*4882a593Smuzhiyun hskoa_dtr, // BOTH: 1=on, 0=off 153*4882a593Smuzhiyun 154*4882a593Smuzhiyun setPrescaler, // USA26: host requests prescalar be set (default: 13) 155*4882a593Smuzhiyun prescaler; // BOTH: specified as N/8; values 8-ff are valid 156*4882a593Smuzhiyun // must be set any time internal baud rate is set; 157*4882a593Smuzhiyun // must not be set when external clocking is used 158*4882a593Smuzhiyun // note: in USA17, prescaler is applied whenever 159*4882a593Smuzhiyun // setClocking is requested 160*4882a593Smuzhiyun 161*4882a593Smuzhiyun /* 162*4882a593Smuzhiyun 3. configuration data which is simply used as is (no overhead, 163*4882a593Smuzhiyun but must be specified correctly in every host message). 164*4882a593Smuzhiyun */ 165*4882a593Smuzhiyun u8 forwardingLength, // BOTH: forward when this number of chars available 166*4882a593Smuzhiyun reportHskiaChanges_dsrFlowControl, 167*4882a593Smuzhiyun // USA26: 1=normal; 0=ignore external clock 168*4882a593Smuzhiyun // USA17: 1=use DSR flow control, 0=don't 169*4882a593Smuzhiyun txAckThreshold, // BOTH: 0=not allowed, 1=normal, 2-255 deliver ACK faster 170*4882a593Smuzhiyun loopbackMode; // BOTH: 0=no loopback, 1=loopback enabled 171*4882a593Smuzhiyun 172*4882a593Smuzhiyun /* 173*4882a593Smuzhiyun 4. commands which are flags only; these are processed in order 174*4882a593Smuzhiyun (so that, e.g., if both _txOn and _txOff flags are set, the 175*4882a593Smuzhiyun port ends in a TX_OFF state); any non-zero value is respected 176*4882a593Smuzhiyun */ 177*4882a593Smuzhiyun u8 _txOn, // BOTH: enable transmitting (and continue if there's data) 178*4882a593Smuzhiyun _txOff, // BOTH: stop transmitting 179*4882a593Smuzhiyun txFlush, // BOTH: toss outbound data 180*4882a593Smuzhiyun txBreak, // BOTH: turn on break (cleared by _txOn) 181*4882a593Smuzhiyun rxOn, // BOTH: turn on receiver 182*4882a593Smuzhiyun rxOff, // BOTH: turn off receiver 183*4882a593Smuzhiyun rxFlush, // BOTH: toss inbound data 184*4882a593Smuzhiyun rxForward, // BOTH: forward all inbound data, NOW (as if fwdLen==1) 185*4882a593Smuzhiyun returnStatus, // BOTH: return current status (even if it hasn't changed) 186*4882a593Smuzhiyun resetDataToggle;// BOTH: reset data toggle state to DATA0 187*4882a593Smuzhiyun 188*4882a593Smuzhiyun }; 189*4882a593Smuzhiyun 190*4882a593Smuzhiyun // defines for bits in lcr 191*4882a593Smuzhiyun #define USA_DATABITS_5 0x00 192*4882a593Smuzhiyun #define USA_DATABITS_6 0x01 193*4882a593Smuzhiyun #define USA_DATABITS_7 0x02 194*4882a593Smuzhiyun #define USA_DATABITS_8 0x03 195*4882a593Smuzhiyun #define STOPBITS_5678_1 0x00 // 1 stop bit for all byte sizes 196*4882a593Smuzhiyun #define STOPBITS_5_1p5 0x04 // 1.5 stop bits for 5-bit byte 197*4882a593Smuzhiyun #define STOPBITS_678_2 0x04 // 2 stop bits for 6/7/8-bit byte 198*4882a593Smuzhiyun #define USA_PARITY_NONE 0x00 199*4882a593Smuzhiyun #define USA_PARITY_ODD 0x08 200*4882a593Smuzhiyun #define USA_PARITY_EVEN 0x18 201*4882a593Smuzhiyun #define PARITY_1 0x28 202*4882a593Smuzhiyun #define PARITY_0 0x38 203*4882a593Smuzhiyun 204*4882a593Smuzhiyun // all things called "StatusMessage" are sent on the status endpoint 205*4882a593Smuzhiyun 206*4882a593Smuzhiyun struct keyspan_usa26_portStatusMessage // one for each port 207*4882a593Smuzhiyun { 208*4882a593Smuzhiyun u8 port, // BOTH: 0=first, 1=second, other=see below 209*4882a593Smuzhiyun hskia_cts, // USA26: reports HSKIA pin 210*4882a593Smuzhiyun // USA17: reports CTS pin 211*4882a593Smuzhiyun gpia_dcd, // USA26: reports GPIA pin 212*4882a593Smuzhiyun // USA17: reports DCD pin 213*4882a593Smuzhiyun dsr, // USA17: reports DSR pin 214*4882a593Smuzhiyun ri, // USA17: reports RI pin 215*4882a593Smuzhiyun _txOff, // port has been disabled (by host) 216*4882a593Smuzhiyun _txXoff, // port is in XOFF state (either host or RX XOFF) 217*4882a593Smuzhiyun rxEnabled, // as configured by rxOn/rxOff 1=on, 0=off 218*4882a593Smuzhiyun controlResponse;// 1=a control message has been processed 219*4882a593Smuzhiyun }; 220*4882a593Smuzhiyun 221*4882a593Smuzhiyun // bits in RX data message when STAT byte is included 222*4882a593Smuzhiyun #define RXERROR_OVERRUN 0x02 223*4882a593Smuzhiyun #define RXERROR_PARITY 0x04 224*4882a593Smuzhiyun #define RXERROR_FRAMING 0x08 225*4882a593Smuzhiyun #define RXERROR_BREAK 0x10 226*4882a593Smuzhiyun 227*4882a593Smuzhiyun struct keyspan_usa26_globalControlMessage 228*4882a593Smuzhiyun { 229*4882a593Smuzhiyun u8 sendGlobalStatus, // 2=request for two status responses 230*4882a593Smuzhiyun resetStatusToggle, // 1=reset global status toggle 231*4882a593Smuzhiyun resetStatusCount; // a cycling value 232*4882a593Smuzhiyun }; 233*4882a593Smuzhiyun 234*4882a593Smuzhiyun struct keyspan_usa26_globalStatusMessage 235*4882a593Smuzhiyun { 236*4882a593Smuzhiyun u8 port, // 3 237*4882a593Smuzhiyun sendGlobalStatus, // from request, decremented 238*4882a593Smuzhiyun resetStatusCount; // as in request 239*4882a593Smuzhiyun }; 240*4882a593Smuzhiyun 241*4882a593Smuzhiyun struct keyspan_usa26_globalDebugMessage 242*4882a593Smuzhiyun { 243*4882a593Smuzhiyun u8 port, // 2 244*4882a593Smuzhiyun a, 245*4882a593Smuzhiyun b, 246*4882a593Smuzhiyun c, 247*4882a593Smuzhiyun d; 248*4882a593Smuzhiyun }; 249*4882a593Smuzhiyun 250*4882a593Smuzhiyun // ie: the maximum length of an EZUSB endpoint buffer 251*4882a593Smuzhiyun #define MAX_DATA_LEN 64 252*4882a593Smuzhiyun 253*4882a593Smuzhiyun // update status approx. 60 times a second (16.6666 ms) 254*4882a593Smuzhiyun #define STATUS_UPDATE_INTERVAL 16 255*4882a593Smuzhiyun 256*4882a593Smuzhiyun // status rationing tuning value (each port gets checked each n ms) 257*4882a593Smuzhiyun #define STATUS_RATION 10 258*4882a593Smuzhiyun 259*4882a593Smuzhiyun #endif 260*4882a593Smuzhiyun 261*4882a593Smuzhiyun 262