162306a36Sopenharmony_ci/* SPDX-License-Identifier: BSD-3-Clause */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci usa28msg.h 462306a36Sopenharmony_ci 562306a36Sopenharmony_ci Copyright (C) 1998-2000 InnoSys Incorporated. All Rights Reserved 662306a36Sopenharmony_ci This file is available under a BSD-style copyright 762306a36Sopenharmony_ci 862306a36Sopenharmony_ci Keyspan USB Async Message Formats for the USA26X 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ci Redistribution and use in source and binary forms, with or without 1162306a36Sopenharmony_ci modification, are permitted provided that the following conditions are 1262306a36Sopenharmony_ci met: 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_ci 1. Redistributions of source code must retain this licence text 1562306a36Sopenharmony_ci without modification, this list of conditions, and the following 1662306a36Sopenharmony_ci disclaimer. The following copyright notice must appear immediately at 1762306a36Sopenharmony_ci the beginning of all source files: 1862306a36Sopenharmony_ci 1962306a36Sopenharmony_ci Copyright (C) 1998-2000 InnoSys Incorporated. All Rights Reserved 2062306a36Sopenharmony_ci 2162306a36Sopenharmony_ci This file is available under a BSD-style copyright 2262306a36Sopenharmony_ci 2362306a36Sopenharmony_ci 2. The name of InnoSys Incorporated may not be used to endorse or promote 2462306a36Sopenharmony_ci products derived from this software without specific prior written 2562306a36Sopenharmony_ci permission. 2662306a36Sopenharmony_ci 2762306a36Sopenharmony_ci THIS SOFTWARE IS PROVIDED BY INNOSYS CORP. ``AS IS'' AND ANY EXPRESS OR 2862306a36Sopenharmony_ci IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 2962306a36Sopenharmony_ci OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 3062306a36Sopenharmony_ci NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 3162306a36Sopenharmony_ci INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 3262306a36Sopenharmony_ci (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 3362306a36Sopenharmony_ci SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 3462306a36Sopenharmony_ci CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3562306a36Sopenharmony_ci LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3662306a36Sopenharmony_ci OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3762306a36Sopenharmony_ci SUCH DAMAGE. 3862306a36Sopenharmony_ci 3962306a36Sopenharmony_ci Note: these message formats are common to USA18, USA19, and USA28; 4062306a36Sopenharmony_ci (for USA28X, see usa26msg.h) 4162306a36Sopenharmony_ci 4262306a36Sopenharmony_ci Buffer formats for RX/TX data messages are not defined by 4362306a36Sopenharmony_ci a structure, but are described here: 4462306a36Sopenharmony_ci 4562306a36Sopenharmony_ci USB OUT (host -> USA28, transmit) messages contain a 4662306a36Sopenharmony_ci REQUEST_ACK indicator (set to 0xff to request an ACK at the 4762306a36Sopenharmony_ci completion of transmit; 0x00 otherwise), followed by data. 4862306a36Sopenharmony_ci If the port is configured for parity, the data will be an 4962306a36Sopenharmony_ci alternating string of parity and data bytes, so the message 5062306a36Sopenharmony_ci format will be: 5162306a36Sopenharmony_ci 5262306a36Sopenharmony_ci RQSTACK PAR DAT PAR DAT ... 5362306a36Sopenharmony_ci 5462306a36Sopenharmony_ci so the maximum length is 63 bytes (1 + 62, or 31 data bytes); 5562306a36Sopenharmony_ci always an odd number for the total message length. 5662306a36Sopenharmony_ci 5762306a36Sopenharmony_ci If there is no parity, the format is simply: 5862306a36Sopenharmony_ci 5962306a36Sopenharmony_ci RQSTACK DAT DAT DAT ... 6062306a36Sopenharmony_ci 6162306a36Sopenharmony_ci with a total data length of 63. 6262306a36Sopenharmony_ci 6362306a36Sopenharmony_ci USB IN (USA28 -> host, receive) messages contain data and parity 6462306a36Sopenharmony_ci if parity is configred, thusly: 6562306a36Sopenharmony_ci 6662306a36Sopenharmony_ci DAT PAR DAT PAR DAT PAR ... 6762306a36Sopenharmony_ci 6862306a36Sopenharmony_ci for a total of 32 data bytes; 6962306a36Sopenharmony_ci 7062306a36Sopenharmony_ci If parity is not configured, the format is: 7162306a36Sopenharmony_ci 7262306a36Sopenharmony_ci DAT DAT DAT ... 7362306a36Sopenharmony_ci 7462306a36Sopenharmony_ci for a total of 64 data bytes. 7562306a36Sopenharmony_ci 7662306a36Sopenharmony_ci In the TX messages (USB OUT), the 0x01 bit of the PARity byte is 7762306a36Sopenharmony_ci the parity bit. In the RX messages (USB IN), the PARity byte is 7862306a36Sopenharmony_ci the content of the 8051's status register; the parity bit 7962306a36Sopenharmony_ci (RX_PARITY_BIT) is the 0x04 bit. 8062306a36Sopenharmony_ci 8162306a36Sopenharmony_ci revision history: 8262306a36Sopenharmony_ci 8362306a36Sopenharmony_ci 1999may06 add resetDataToggle to control message 8462306a36Sopenharmony_ci 2000mar21 add rs232invalid to status response message 8562306a36Sopenharmony_ci 2000apr04 add 230.4Kb definition to setBaudRate 8662306a36Sopenharmony_ci 2000apr13 add/remove loopbackMode switch 8762306a36Sopenharmony_ci 2000apr13 change definition of setBaudRate to cover 115.2Kb, too 8862306a36Sopenharmony_ci 2000jun01 add extended BSD-style copyright text 8962306a36Sopenharmony_ci*/ 9062306a36Sopenharmony_ci 9162306a36Sopenharmony_ci#ifndef __USA28MSG__ 9262306a36Sopenharmony_ci#define __USA28MSG__ 9362306a36Sopenharmony_ci 9462306a36Sopenharmony_ci 9562306a36Sopenharmony_cistruct keyspan_usa28_portControlMessage 9662306a36Sopenharmony_ci{ 9762306a36Sopenharmony_ci /* 9862306a36Sopenharmony_ci there are four types of "commands" sent in the control message: 9962306a36Sopenharmony_ci 10062306a36Sopenharmony_ci 1. configuration changes which must be requested by setting 10162306a36Sopenharmony_ci the corresponding "set" flag (and should only be requested 10262306a36Sopenharmony_ci when necessary, to reduce overhead on the USA28): 10362306a36Sopenharmony_ci */ 10462306a36Sopenharmony_ci u8 setBaudRate, // 0=don't set, 1=baudLo/Hi, 2=115.2K, 3=230.4K 10562306a36Sopenharmony_ci baudLo, // host does baud divisor calculation 10662306a36Sopenharmony_ci baudHi; // baudHi is only used for first port (gives lower rates) 10762306a36Sopenharmony_ci 10862306a36Sopenharmony_ci /* 10962306a36Sopenharmony_ci 2. configuration changes which are done every time (because it's 11062306a36Sopenharmony_ci hardly more trouble to do them than to check whether to do them): 11162306a36Sopenharmony_ci */ 11262306a36Sopenharmony_ci u8 parity, // 1=use parity, 0=don't 11362306a36Sopenharmony_ci ctsFlowControl, // all except 19Q: 1=use CTS flow control, 0=don't 11462306a36Sopenharmony_ci // 19Q: 0x08:CTSflowControl 0x10:DSRflowControl 11562306a36Sopenharmony_ci xonFlowControl, // 1=use XON/XOFF flow control, 0=don't 11662306a36Sopenharmony_ci rts, // 1=on, 0=off 11762306a36Sopenharmony_ci dtr; // 1=on, 0=off 11862306a36Sopenharmony_ci 11962306a36Sopenharmony_ci /* 12062306a36Sopenharmony_ci 3. configuration data which is simply used as is (no overhead, 12162306a36Sopenharmony_ci but must be correct in every host message). 12262306a36Sopenharmony_ci */ 12362306a36Sopenharmony_ci u8 forwardingLength, // forward when this number of chars available 12462306a36Sopenharmony_ci forwardMs, // forward this many ms after last rx data 12562306a36Sopenharmony_ci breakThreshold, // specified in ms, 1-255 (see note below) 12662306a36Sopenharmony_ci xonChar, // specified in current character format 12762306a36Sopenharmony_ci xoffChar; // specified in current character format 12862306a36Sopenharmony_ci 12962306a36Sopenharmony_ci /* 13062306a36Sopenharmony_ci 4. commands which are flags only; these are processed in order 13162306a36Sopenharmony_ci (so that, e.g., if both _txOn and _txOff flags are set, the 13262306a36Sopenharmony_ci port ends in a TX_OFF state); any non-zero value is respected 13362306a36Sopenharmony_ci */ 13462306a36Sopenharmony_ci u8 _txOn, // enable transmitting (and continue if there's data) 13562306a36Sopenharmony_ci _txOff, // stop transmitting 13662306a36Sopenharmony_ci txFlush, // toss outbound data 13762306a36Sopenharmony_ci txForceXoff, // pretend we've received XOFF 13862306a36Sopenharmony_ci txBreak, // turn on break (leave on until txOn clears it) 13962306a36Sopenharmony_ci rxOn, // turn on receiver 14062306a36Sopenharmony_ci rxOff, // turn off receiver 14162306a36Sopenharmony_ci rxFlush, // toss inbound data 14262306a36Sopenharmony_ci rxForward, // forward all inbound data, NOW 14362306a36Sopenharmony_ci returnStatus, // return current status n times (1 or 2) 14462306a36Sopenharmony_ci resetDataToggle;// reset data toggle state to DATA0 14562306a36Sopenharmony_ci 14662306a36Sopenharmony_ci}; 14762306a36Sopenharmony_ci 14862306a36Sopenharmony_cistruct keyspan_usa28_portStatusMessage 14962306a36Sopenharmony_ci{ 15062306a36Sopenharmony_ci u8 port, // 0=first, 1=second, 2=global (see below) 15162306a36Sopenharmony_ci cts, 15262306a36Sopenharmony_ci dsr, // (not used in all products) 15362306a36Sopenharmony_ci dcd, 15462306a36Sopenharmony_ci 15562306a36Sopenharmony_ci ri, // (not used in all products) 15662306a36Sopenharmony_ci _txOff, // port has been disabled (by host) 15762306a36Sopenharmony_ci _txXoff, // port is in XOFF state (either host or RX XOFF) 15862306a36Sopenharmony_ci dataLost, // count of lost chars; wraps; not guaranteed exact 15962306a36Sopenharmony_ci 16062306a36Sopenharmony_ci rxEnabled, // as configured by rxOn/rxOff 1=on, 0=off 16162306a36Sopenharmony_ci rxBreak, // 1=we're in break state 16262306a36Sopenharmony_ci rs232invalid, // 1=no valid signals on rs-232 inputs 16362306a36Sopenharmony_ci controlResponse;// 1=a control messages has been processed 16462306a36Sopenharmony_ci}; 16562306a36Sopenharmony_ci 16662306a36Sopenharmony_ci// bit defines in txState 16762306a36Sopenharmony_ci#define TX_OFF 0x01 // requested by host txOff command 16862306a36Sopenharmony_ci#define TX_XOFF 0x02 // either real, or simulated by host 16962306a36Sopenharmony_ci 17062306a36Sopenharmony_cistruct keyspan_usa28_globalControlMessage 17162306a36Sopenharmony_ci{ 17262306a36Sopenharmony_ci u8 sendGlobalStatus, // 2=request for two status responses 17362306a36Sopenharmony_ci resetStatusToggle, // 1=reset global status toggle 17462306a36Sopenharmony_ci resetStatusCount; // a cycling value 17562306a36Sopenharmony_ci}; 17662306a36Sopenharmony_ci 17762306a36Sopenharmony_cistruct keyspan_usa28_globalStatusMessage 17862306a36Sopenharmony_ci{ 17962306a36Sopenharmony_ci u8 port, // 3 18062306a36Sopenharmony_ci sendGlobalStatus, // from request, decremented 18162306a36Sopenharmony_ci resetStatusCount; // as in request 18262306a36Sopenharmony_ci}; 18362306a36Sopenharmony_ci 18462306a36Sopenharmony_cistruct keyspan_usa28_globalDebugMessage 18562306a36Sopenharmony_ci{ 18662306a36Sopenharmony_ci u8 port, // 2 18762306a36Sopenharmony_ci n, // typically a count/status byte 18862306a36Sopenharmony_ci b; // typically a data byte 18962306a36Sopenharmony_ci}; 19062306a36Sopenharmony_ci 19162306a36Sopenharmony_ci// ie: the maximum length of an EZUSB endpoint buffer 19262306a36Sopenharmony_ci#define MAX_DATA_LEN 64 19362306a36Sopenharmony_ci 19462306a36Sopenharmony_ci// the parity bytes have only one significant bit 19562306a36Sopenharmony_ci#define RX_PARITY_BIT 0x04 19662306a36Sopenharmony_ci#define TX_PARITY_BIT 0x01 19762306a36Sopenharmony_ci 19862306a36Sopenharmony_ci// update status approx. 60 times a second (16.6666 ms) 19962306a36Sopenharmony_ci#define STATUS_UPDATE_INTERVAL 16 20062306a36Sopenharmony_ci 20162306a36Sopenharmony_ci#endif 20262306a36Sopenharmony_ci 203