18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: BSD-3-Clause */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci	usa28msg.h
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci	Copyright (C) 1998-2000 InnoSys Incorporated.  All Rights Reserved
68c2ecf20Sopenharmony_ci	This file is available under a BSD-style copyright
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci	Keyspan USB Async Message Formats for the USA26X
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci	Redistribution and use in source and binary forms, with or without
118c2ecf20Sopenharmony_ci	modification, are permitted provided that the following conditions are
128c2ecf20Sopenharmony_ci	met:
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci	1. Redistributions of source code must retain this licence text
158c2ecf20Sopenharmony_ci   	without modification, this list of conditions, and the following
168c2ecf20Sopenharmony_ci   	disclaimer.  The following copyright notice must appear immediately at
178c2ecf20Sopenharmony_ci   	the beginning of all source files:
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci        	Copyright (C) 1998-2000 InnoSys Incorporated.  All Rights Reserved
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci        	This file is available under a BSD-style copyright
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci	2. The name of InnoSys Incorporated may not be used to endorse or promote
248c2ecf20Sopenharmony_ci   	products derived from this software without specific prior written
258c2ecf20Sopenharmony_ci   	permission.
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci	THIS SOFTWARE IS PROVIDED BY INNOSYS CORP. ``AS IS'' AND ANY EXPRESS OR
288c2ecf20Sopenharmony_ci	IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
298c2ecf20Sopenharmony_ci	OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
308c2ecf20Sopenharmony_ci	NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
318c2ecf20Sopenharmony_ci	INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
328c2ecf20Sopenharmony_ci	(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
338c2ecf20Sopenharmony_ci	SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
348c2ecf20Sopenharmony_ci	CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
358c2ecf20Sopenharmony_ci	LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
368c2ecf20Sopenharmony_ci	OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
378c2ecf20Sopenharmony_ci	SUCH DAMAGE.
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci	Note: these message formats are common to USA18, USA19, and USA28;
408c2ecf20Sopenharmony_ci	(for USA28X, see usa26msg.h)
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci	Buffer formats for RX/TX data messages are not defined by
438c2ecf20Sopenharmony_ci	a structure, but are described here:
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci	USB OUT (host -> USA28, transmit) messages contain a
468c2ecf20Sopenharmony_ci	REQUEST_ACK indicator (set to 0xff to request an ACK at the
478c2ecf20Sopenharmony_ci	completion of transmit; 0x00 otherwise), followed by data.
488c2ecf20Sopenharmony_ci	If the port is configured for parity, the data will be an
498c2ecf20Sopenharmony_ci	alternating string of parity and data bytes, so the message
508c2ecf20Sopenharmony_ci	format will be:
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci		RQSTACK PAR DAT PAR DAT ...
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci	so the maximum length is 63 bytes (1 + 62, or 31 data bytes);
558c2ecf20Sopenharmony_ci	always an odd number for the total message length.
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci	If there is no parity, the format is simply:
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci		RQSTACK DAT DAT DAT ...
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ci	with a total data length of 63.
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci	USB IN (USA28 -> host, receive) messages contain data and parity
648c2ecf20Sopenharmony_ci	if parity is configred, thusly:
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ci		DAT PAR DAT PAR DAT PAR ...
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci	for a total of 32 data bytes;
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ci	If parity is not configured, the format is:
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_ci		DAT DAT DAT ...
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci	for a total of 64 data bytes.
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_ci	In the TX messages (USB OUT), the 0x01 bit of the PARity byte is
778c2ecf20Sopenharmony_ci	the parity bit.  In the RX messages (USB IN), the PARity byte is
788c2ecf20Sopenharmony_ci	the content of the 8051's status register; the parity bit
798c2ecf20Sopenharmony_ci	(RX_PARITY_BIT) is the 0x04 bit.
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ci	revision history:
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ci	1999may06	add resetDataToggle to control message
848c2ecf20Sopenharmony_ci	2000mar21	add rs232invalid to status response message
858c2ecf20Sopenharmony_ci	2000apr04	add 230.4Kb definition to setBaudRate
868c2ecf20Sopenharmony_ci	2000apr13	add/remove loopbackMode switch
878c2ecf20Sopenharmony_ci	2000apr13	change definition of setBaudRate to cover 115.2Kb, too
888c2ecf20Sopenharmony_ci	2000jun01	add extended BSD-style copyright text
898c2ecf20Sopenharmony_ci*/
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ci#ifndef	__USA28MSG__
928c2ecf20Sopenharmony_ci#define	__USA28MSG__
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_cistruct keyspan_usa28_portControlMessage
968c2ecf20Sopenharmony_ci{
978c2ecf20Sopenharmony_ci	/*
988c2ecf20Sopenharmony_ci		there are four types of "commands" sent in the control message:
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ci		1.	configuration changes which must be requested by setting
1018c2ecf20Sopenharmony_ci			the corresponding "set" flag (and should only be requested
1028c2ecf20Sopenharmony_ci			when necessary, to reduce overhead on the USA28):
1038c2ecf20Sopenharmony_ci	*/
1048c2ecf20Sopenharmony_ci	u8	setBaudRate,	// 0=don't set, 1=baudLo/Hi, 2=115.2K, 3=230.4K
1058c2ecf20Sopenharmony_ci		baudLo,			// host does baud divisor calculation
1068c2ecf20Sopenharmony_ci		baudHi;			// baudHi is only used for first port (gives lower rates)
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_ci	/*
1098c2ecf20Sopenharmony_ci		2.	configuration changes which are done every time (because it's
1108c2ecf20Sopenharmony_ci			hardly more trouble to do them than to check whether to do them):
1118c2ecf20Sopenharmony_ci	*/
1128c2ecf20Sopenharmony_ci	u8	parity,			// 1=use parity, 0=don't
1138c2ecf20Sopenharmony_ci		ctsFlowControl,	        // all except 19Q: 1=use CTS flow control, 0=don't
1148c2ecf20Sopenharmony_ci					// 19Q: 0x08:CTSflowControl 0x10:DSRflowControl
1158c2ecf20Sopenharmony_ci		xonFlowControl,	// 1=use XON/XOFF flow control, 0=don't
1168c2ecf20Sopenharmony_ci		rts,			// 1=on, 0=off
1178c2ecf20Sopenharmony_ci		dtr;			// 1=on, 0=off
1188c2ecf20Sopenharmony_ci
1198c2ecf20Sopenharmony_ci	/*
1208c2ecf20Sopenharmony_ci		3.	configuration data which is simply used as is (no overhead,
1218c2ecf20Sopenharmony_ci			but must be correct in every host message).
1228c2ecf20Sopenharmony_ci	*/
1238c2ecf20Sopenharmony_ci	u8	forwardingLength,  // forward when this number of chars available
1248c2ecf20Sopenharmony_ci		forwardMs,		// forward this many ms after last rx data
1258c2ecf20Sopenharmony_ci		breakThreshold,	// specified in ms, 1-255 (see note below)
1268c2ecf20Sopenharmony_ci		xonChar,		// specified in current character format
1278c2ecf20Sopenharmony_ci		xoffChar;		// specified in current character format
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_ci	/*
1308c2ecf20Sopenharmony_ci		4.	commands which are flags only; these are processed in order
1318c2ecf20Sopenharmony_ci			(so that, e.g., if both _txOn and _txOff flags are set, the
1328c2ecf20Sopenharmony_ci			port ends in a TX_OFF state); any non-zero value is respected
1338c2ecf20Sopenharmony_ci	*/
1348c2ecf20Sopenharmony_ci	u8	_txOn,			// enable transmitting (and continue if there's data)
1358c2ecf20Sopenharmony_ci		_txOff,			// stop transmitting
1368c2ecf20Sopenharmony_ci		txFlush,		// toss outbound data
1378c2ecf20Sopenharmony_ci		txForceXoff,	// pretend we've received XOFF
1388c2ecf20Sopenharmony_ci		txBreak,		// turn on break (leave on until txOn clears it)
1398c2ecf20Sopenharmony_ci		rxOn,			// turn on receiver
1408c2ecf20Sopenharmony_ci		rxOff,			// turn off receiver
1418c2ecf20Sopenharmony_ci		rxFlush,		// toss inbound data
1428c2ecf20Sopenharmony_ci		rxForward,		// forward all inbound data, NOW
1438c2ecf20Sopenharmony_ci		returnStatus,	// return current status n times (1 or 2)
1448c2ecf20Sopenharmony_ci		resetDataToggle;// reset data toggle state to DATA0
1458c2ecf20Sopenharmony_ci
1468c2ecf20Sopenharmony_ci};
1478c2ecf20Sopenharmony_ci
1488c2ecf20Sopenharmony_cistruct keyspan_usa28_portStatusMessage
1498c2ecf20Sopenharmony_ci{
1508c2ecf20Sopenharmony_ci	u8	port,			// 0=first, 1=second, 2=global (see below)
1518c2ecf20Sopenharmony_ci		cts,
1528c2ecf20Sopenharmony_ci		dsr,			// (not used in all products)
1538c2ecf20Sopenharmony_ci		dcd,
1548c2ecf20Sopenharmony_ci
1558c2ecf20Sopenharmony_ci		ri,				// (not used in all products)
1568c2ecf20Sopenharmony_ci		_txOff,			// port has been disabled (by host)
1578c2ecf20Sopenharmony_ci		_txXoff,		// port is in XOFF state (either host or RX XOFF)
1588c2ecf20Sopenharmony_ci		dataLost,		// count of lost chars; wraps; not guaranteed exact
1598c2ecf20Sopenharmony_ci
1608c2ecf20Sopenharmony_ci		rxEnabled,		// as configured by rxOn/rxOff 1=on, 0=off
1618c2ecf20Sopenharmony_ci		rxBreak,		// 1=we're in break state
1628c2ecf20Sopenharmony_ci		rs232invalid,	// 1=no valid signals on rs-232 inputs
1638c2ecf20Sopenharmony_ci		controlResponse;// 1=a control messages has been processed
1648c2ecf20Sopenharmony_ci};
1658c2ecf20Sopenharmony_ci
1668c2ecf20Sopenharmony_ci// bit defines in txState
1678c2ecf20Sopenharmony_ci#define	TX_OFF			0x01	// requested by host txOff command
1688c2ecf20Sopenharmony_ci#define	TX_XOFF			0x02	// either real, or simulated by host
1698c2ecf20Sopenharmony_ci
1708c2ecf20Sopenharmony_cistruct keyspan_usa28_globalControlMessage
1718c2ecf20Sopenharmony_ci{
1728c2ecf20Sopenharmony_ci	u8	sendGlobalStatus,	// 2=request for two status responses
1738c2ecf20Sopenharmony_ci		resetStatusToggle,	// 1=reset global status toggle
1748c2ecf20Sopenharmony_ci		resetStatusCount;	// a cycling value
1758c2ecf20Sopenharmony_ci};
1768c2ecf20Sopenharmony_ci
1778c2ecf20Sopenharmony_cistruct keyspan_usa28_globalStatusMessage
1788c2ecf20Sopenharmony_ci{
1798c2ecf20Sopenharmony_ci	u8	port,				// 3
1808c2ecf20Sopenharmony_ci		sendGlobalStatus,	// from request, decremented
1818c2ecf20Sopenharmony_ci		resetStatusCount;	// as in request
1828c2ecf20Sopenharmony_ci};
1838c2ecf20Sopenharmony_ci
1848c2ecf20Sopenharmony_cistruct keyspan_usa28_globalDebugMessage
1858c2ecf20Sopenharmony_ci{
1868c2ecf20Sopenharmony_ci	u8	port,				// 2
1878c2ecf20Sopenharmony_ci		n,					// typically a count/status byte
1888c2ecf20Sopenharmony_ci		b;					// typically a data byte
1898c2ecf20Sopenharmony_ci};
1908c2ecf20Sopenharmony_ci
1918c2ecf20Sopenharmony_ci// ie: the maximum length of an EZUSB endpoint buffer
1928c2ecf20Sopenharmony_ci#define	MAX_DATA_LEN			64
1938c2ecf20Sopenharmony_ci
1948c2ecf20Sopenharmony_ci// the parity bytes have only one significant bit
1958c2ecf20Sopenharmony_ci#define	RX_PARITY_BIT			0x04
1968c2ecf20Sopenharmony_ci#define	TX_PARITY_BIT			0x01
1978c2ecf20Sopenharmony_ci
1988c2ecf20Sopenharmony_ci// update status approx. 60 times a second (16.6666 ms)
1998c2ecf20Sopenharmony_ci#define	STATUS_UPDATE_INTERVAL	16
2008c2ecf20Sopenharmony_ci
2018c2ecf20Sopenharmony_ci#endif
2028c2ecf20Sopenharmony_ci
203