18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: BSD-3-Clause */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci	usa49msg.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 USA49W
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	4th revision: USA49W version
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci	Buffer formats for RX/TX data messages are not defined by
428c2ecf20Sopenharmony_ci	a structure, but are described here:
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci	USB OUT (host -> USAxx, transmit) messages contain a
458c2ecf20Sopenharmony_ci	REQUEST_ACK indicator (set to 0xff to request an ACK at the
468c2ecf20Sopenharmony_ci	completion of transmit; 0x00 otherwise), followed by data:
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci		RQSTACK DAT DAT DAT ...
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci	with a total data length of 63.
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci	USB IN (USAxx -> host, receive) messages begin with a status
538c2ecf20Sopenharmony_ci	byte in which the 0x80 bit is either:
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci		(a)	0x80 bit clear
568c2ecf20Sopenharmony_ci			indicates that the bytes following it are all data
578c2ecf20Sopenharmony_ci			bytes:
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci				STAT DATA DATA DATA DATA DATA ...
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ci			for a total of up to 63 DATA bytes,
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci	or:
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci		(b)	0x80 bit set
668c2ecf20Sopenharmony_ci			indiates that the bytes following alternate data and
678c2ecf20Sopenharmony_ci			status bytes:
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ci				STAT DATA STAT DATA STAT DATA STAT DATA ...
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ci			for a total of up to 32 DATA bytes.
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci	The valid bits in the STAT bytes are:
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ci		OVERRUN	0x02
768c2ecf20Sopenharmony_ci		PARITY	0x04
778c2ecf20Sopenharmony_ci		FRAMING	0x08
788c2ecf20Sopenharmony_ci		BREAK	0x10
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_ci	Notes:
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ci	(1) The OVERRUN bit can appear in either (a) or (b) format
838c2ecf20Sopenharmony_ci		messages, but the but the PARITY/FRAMING/BREAK bits
848c2ecf20Sopenharmony_ci		only appear in (b) format messages.
858c2ecf20Sopenharmony_ci	(2) For the host to determine the exact point at which the
868c2ecf20Sopenharmony_ci		overrun occurred (to identify the point in the data
878c2ecf20Sopenharmony_ci		stream at which the data was lost), it needs to count
888c2ecf20Sopenharmony_ci		128 characters, starting at the first character of the
898c2ecf20Sopenharmony_ci		message in which OVERRUN was reported; the lost character(s)
908c2ecf20Sopenharmony_ci		would have been received between the 128th and 129th
918c2ecf20Sopenharmony_ci		characters.
928c2ecf20Sopenharmony_ci	(3)	An RX data message in which the first byte has 0x80 clear
938c2ecf20Sopenharmony_ci		serves as a "break off" indicator.
948c2ecf20Sopenharmony_ci	(4)	a control message specifying disablePort will be answered
958c2ecf20Sopenharmony_ci		with a status message, but no further status will be sent
968c2ecf20Sopenharmony_ci		until a control messages with enablePort is sent
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_ci	revision history:
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ci	1999feb10	add reportHskiaChanges to allow us to ignore them
1018c2ecf20Sopenharmony_ci	1999feb10	add txAckThreshold for fast+loose throughput enhancement
1028c2ecf20Sopenharmony_ci	1999mar30	beef up support for RX error reporting
1038c2ecf20Sopenharmony_ci	1999apr14	add resetDataToggle to control message
1048c2ecf20Sopenharmony_ci	2000jan04	merge with usa17msg.h
1058c2ecf20Sopenharmony_ci	2000mar08	clone from usa26msg.h -> usa49msg.h
1068c2ecf20Sopenharmony_ci	2000mar09	change to support 4 ports
1078c2ecf20Sopenharmony_ci	2000may03	change external clocking to match USA-49W hardware
1088c2ecf20Sopenharmony_ci	2000jun01	add extended BSD-style copyright text
1098c2ecf20Sopenharmony_ci	2001jul05	change message format to improve OVERRUN case
1108c2ecf20Sopenharmony_ci*/
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ci#ifndef	__USA49MSG__
1138c2ecf20Sopenharmony_ci#define	__USA49MSG__
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_ci/*
1178c2ecf20Sopenharmony_ci	Host->device messages sent on the global control endpoint:
1188c2ecf20Sopenharmony_ci
1198c2ecf20Sopenharmony_ci	portNumber	message
1208c2ecf20Sopenharmony_ci	----------	--------------------
1218c2ecf20Sopenharmony_ci	0,1,2,3		portControlMessage
1228c2ecf20Sopenharmony_ci	0x80		globalControlMessage
1238c2ecf20Sopenharmony_ci*/
1248c2ecf20Sopenharmony_ci
1258c2ecf20Sopenharmony_cistruct keyspan_usa49_portControlMessage
1268c2ecf20Sopenharmony_ci{
1278c2ecf20Sopenharmony_ci	/*
1288c2ecf20Sopenharmony_ci		0.	0/1/2/3 	port control message follows
1298c2ecf20Sopenharmony_ci			0x80 set	non-port control message follows
1308c2ecf20Sopenharmony_ci	*/
1318c2ecf20Sopenharmony_ci	u8	portNumber,
1328c2ecf20Sopenharmony_ci
1338c2ecf20Sopenharmony_ci	/*
1348c2ecf20Sopenharmony_ci		there are three types of "commands" sent in the control message:
1358c2ecf20Sopenharmony_ci
1368c2ecf20Sopenharmony_ci		1.	configuration changes which must be requested by setting
1378c2ecf20Sopenharmony_ci			the corresponding "set" flag (and should only be requested
1388c2ecf20Sopenharmony_ci			when necessary, to reduce overhead on the USA26):
1398c2ecf20Sopenharmony_ci	*/
1408c2ecf20Sopenharmony_ci		setClocking,	// host requests baud rate be set
1418c2ecf20Sopenharmony_ci		baudLo,			// host does baud divisor calculation
1428c2ecf20Sopenharmony_ci		baudHi,			// baudHi is only used for first port (gives lower rates)
1438c2ecf20Sopenharmony_ci		prescaler,		// specified as N/8; values 8-ff are valid
1448c2ecf20Sopenharmony_ci						// must be set any time internal baud rate is set;
1458c2ecf20Sopenharmony_ci		txClocking,		// 0=internal, 1=external/DSR
1468c2ecf20Sopenharmony_ci		rxClocking,		// 0=internal, 1=external/DSR
1478c2ecf20Sopenharmony_ci
1488c2ecf20Sopenharmony_ci		setLcr,			// host requests lcr be set
1498c2ecf20Sopenharmony_ci		lcr,			// use PARITY, STOPBITS, DATABITS below
1508c2ecf20Sopenharmony_ci
1518c2ecf20Sopenharmony_ci		setFlowControl,	// host requests flow control be set
1528c2ecf20Sopenharmony_ci		ctsFlowControl,	// 1=use CTS flow control, 0=don't
1538c2ecf20Sopenharmony_ci		xonFlowControl,	// 1=use XON/XOFF flow control, 0=don't
1548c2ecf20Sopenharmony_ci		xonChar,		// specified in current character format
1558c2ecf20Sopenharmony_ci		xoffChar,		// specified in current character format
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_ci		setRts,			// host requests RTS output be set
1588c2ecf20Sopenharmony_ci		rts,			// 1=active, 0=inactive
1598c2ecf20Sopenharmony_ci
1608c2ecf20Sopenharmony_ci		setDtr,			// host requests DTR output be set
1618c2ecf20Sopenharmony_ci		dtr;			// 1=on, 0=off
1628c2ecf20Sopenharmony_ci
1638c2ecf20Sopenharmony_ci
1648c2ecf20Sopenharmony_ci	/*
1658c2ecf20Sopenharmony_ci		3.	configuration data which is simply used as is (no overhead,
1668c2ecf20Sopenharmony_ci			but must be specified correctly in every host message).
1678c2ecf20Sopenharmony_ci	*/
1688c2ecf20Sopenharmony_ci	u8	forwardingLength,  // forward when this number of chars available
1698c2ecf20Sopenharmony_ci		dsrFlowControl,	// 1=use DSR flow control, 0=don't
1708c2ecf20Sopenharmony_ci		txAckThreshold,	// 0=not allowed, 1=normal, 2-255 deliver ACK faster
1718c2ecf20Sopenharmony_ci		loopbackMode;	// 0=no loopback, 1=loopback enabled
1728c2ecf20Sopenharmony_ci
1738c2ecf20Sopenharmony_ci	/*
1748c2ecf20Sopenharmony_ci		4.	commands which are flags only; these are processed in order
1758c2ecf20Sopenharmony_ci			(so that, e.g., if both _txOn and _txOff flags are set, the
1768c2ecf20Sopenharmony_ci			port ends in a TX_OFF state); any non-zero value is respected
1778c2ecf20Sopenharmony_ci	*/
1788c2ecf20Sopenharmony_ci	u8	_txOn,			// enable transmitting (and continue if there's data)
1798c2ecf20Sopenharmony_ci		_txOff,			// stop transmitting
1808c2ecf20Sopenharmony_ci		txFlush,		// toss outbound data
1818c2ecf20Sopenharmony_ci		txBreak,		// turn on break (cleared by _txOn)
1828c2ecf20Sopenharmony_ci		rxOn,			// turn on receiver
1838c2ecf20Sopenharmony_ci		rxOff,			// turn off receiver
1848c2ecf20Sopenharmony_ci		rxFlush,		// toss inbound data
1858c2ecf20Sopenharmony_ci		rxForward,		// forward all inbound data, NOW (as if fwdLen==1)
1868c2ecf20Sopenharmony_ci		returnStatus,	// return current status (even if it hasn't changed)
1878c2ecf20Sopenharmony_ci		resetDataToggle,// reset data toggle state to DATA0
1888c2ecf20Sopenharmony_ci		enablePort,		// start servicing port (move data, check status)
1898c2ecf20Sopenharmony_ci		disablePort;	// stop servicing port (does implicit tx/rx flush/off)
1908c2ecf20Sopenharmony_ci
1918c2ecf20Sopenharmony_ci};
1928c2ecf20Sopenharmony_ci
1938c2ecf20Sopenharmony_ci// defines for bits in lcr
1948c2ecf20Sopenharmony_ci#define	USA_DATABITS_5		0x00
1958c2ecf20Sopenharmony_ci#define	USA_DATABITS_6		0x01
1968c2ecf20Sopenharmony_ci#define	USA_DATABITS_7		0x02
1978c2ecf20Sopenharmony_ci#define	USA_DATABITS_8		0x03
1988c2ecf20Sopenharmony_ci#define	STOPBITS_5678_1		0x00	// 1 stop bit for all byte sizes
1998c2ecf20Sopenharmony_ci#define	STOPBITS_5_1p5		0x04	// 1.5 stop bits for 5-bit byte
2008c2ecf20Sopenharmony_ci#define	STOPBITS_678_2		0x04	// 2 stop bits for 6/7/8-bit byte
2018c2ecf20Sopenharmony_ci#define	USA_PARITY_NONE		0x00
2028c2ecf20Sopenharmony_ci#define	USA_PARITY_ODD		0x08
2038c2ecf20Sopenharmony_ci#define	USA_PARITY_EVEN		0x18
2048c2ecf20Sopenharmony_ci#define	PARITY_1			0x28
2058c2ecf20Sopenharmony_ci#define	PARITY_0			0x38
2068c2ecf20Sopenharmony_ci
2078c2ecf20Sopenharmony_ci/*
2088c2ecf20Sopenharmony_ci	during normal operation, status messages are returned
2098c2ecf20Sopenharmony_ci	to the host whenever the board detects changes.  In some
2108c2ecf20Sopenharmony_ci	circumstances (e.g. Windows), status messages from the
2118c2ecf20Sopenharmony_ci	device cause problems; to shut them off, the host issues
2128c2ecf20Sopenharmony_ci	a control message with the disableStatusMessages flags
2138c2ecf20Sopenharmony_ci	set (to any non-zero value).  The device will respond to
2148c2ecf20Sopenharmony_ci	this message, and then suppress further status messages;
2158c2ecf20Sopenharmony_ci	it will resume sending status messages any time the host
2168c2ecf20Sopenharmony_ci	sends any control message (either global or port-specific).
2178c2ecf20Sopenharmony_ci*/
2188c2ecf20Sopenharmony_ci
2198c2ecf20Sopenharmony_cistruct keyspan_usa49_globalControlMessage
2208c2ecf20Sopenharmony_ci{
2218c2ecf20Sopenharmony_ci	u8	portNumber,			// 0x80
2228c2ecf20Sopenharmony_ci		sendGlobalStatus,	// 1/2=number of status responses requested
2238c2ecf20Sopenharmony_ci		resetStatusToggle,	// 1=reset global status toggle
2248c2ecf20Sopenharmony_ci		resetStatusCount,	// a cycling value
2258c2ecf20Sopenharmony_ci		remoteWakeupEnable,		// 0x10=P1, 0x20=P2, 0x40=P3, 0x80=P4
2268c2ecf20Sopenharmony_ci		disableStatusMessages;	// 1=send no status until host talks
2278c2ecf20Sopenharmony_ci};
2288c2ecf20Sopenharmony_ci
2298c2ecf20Sopenharmony_ci/*
2308c2ecf20Sopenharmony_ci	Device->host messages send on the global status endpoint
2318c2ecf20Sopenharmony_ci
2328c2ecf20Sopenharmony_ci	portNumber			message
2338c2ecf20Sopenharmony_ci	----------			--------------------
2348c2ecf20Sopenharmony_ci	0x00,0x01,0x02,0x03	portStatusMessage
2358c2ecf20Sopenharmony_ci	0x80				globalStatusMessage
2368c2ecf20Sopenharmony_ci	0x81				globalDebugMessage
2378c2ecf20Sopenharmony_ci*/
2388c2ecf20Sopenharmony_ci
2398c2ecf20Sopenharmony_cistruct keyspan_usa49_portStatusMessage	// one for each port
2408c2ecf20Sopenharmony_ci{
2418c2ecf20Sopenharmony_ci	u8	portNumber,		// 0,1,2,3
2428c2ecf20Sopenharmony_ci		cts,			// reports CTS pin
2438c2ecf20Sopenharmony_ci		dcd,			// reports DCD pin
2448c2ecf20Sopenharmony_ci		dsr,			// reports DSR pin
2458c2ecf20Sopenharmony_ci		ri,				// reports RI pin
2468c2ecf20Sopenharmony_ci		_txOff,			// transmit has been disabled (by host)
2478c2ecf20Sopenharmony_ci		_txXoff,		// transmit is in XOFF state (either host or RX XOFF)
2488c2ecf20Sopenharmony_ci		rxEnabled,		// as configured by rxOn/rxOff 1=on, 0=off
2498c2ecf20Sopenharmony_ci		controlResponse,// 1=a control message has been processed
2508c2ecf20Sopenharmony_ci		txAck,			// ACK (data TX complete)
2518c2ecf20Sopenharmony_ci		rs232valid;		// RS-232 signal valid
2528c2ecf20Sopenharmony_ci};
2538c2ecf20Sopenharmony_ci
2548c2ecf20Sopenharmony_ci// bits in RX data message when STAT byte is included
2558c2ecf20Sopenharmony_ci#define	RXERROR_OVERRUN	0x02
2568c2ecf20Sopenharmony_ci#define	RXERROR_PARITY	0x04
2578c2ecf20Sopenharmony_ci#define	RXERROR_FRAMING	0x08
2588c2ecf20Sopenharmony_ci#define	RXERROR_BREAK	0x10
2598c2ecf20Sopenharmony_ci
2608c2ecf20Sopenharmony_cistruct keyspan_usa49_globalStatusMessage
2618c2ecf20Sopenharmony_ci{
2628c2ecf20Sopenharmony_ci	u8	portNumber,			// 0x80=globalStatusMessage
2638c2ecf20Sopenharmony_ci		sendGlobalStatus,	// from request, decremented
2648c2ecf20Sopenharmony_ci		resetStatusCount;	// as in request
2658c2ecf20Sopenharmony_ci};
2668c2ecf20Sopenharmony_ci
2678c2ecf20Sopenharmony_cistruct keyspan_usa49_globalDebugMessage
2688c2ecf20Sopenharmony_ci{
2698c2ecf20Sopenharmony_ci	u8	portNumber,			// 0x81=globalDebugMessage
2708c2ecf20Sopenharmony_ci		n,					// typically a count/status byte
2718c2ecf20Sopenharmony_ci		b;					// typically a data byte
2728c2ecf20Sopenharmony_ci};
2738c2ecf20Sopenharmony_ci
2748c2ecf20Sopenharmony_ci// ie: the maximum length of an EZUSB endpoint buffer
2758c2ecf20Sopenharmony_ci#define	MAX_DATA_LEN			64
2768c2ecf20Sopenharmony_ci
2778c2ecf20Sopenharmony_ci// update status approx. 60 times a second (16.6666 ms)
2788c2ecf20Sopenharmony_ci#define	STATUS_UPDATE_INTERVAL	16
2798c2ecf20Sopenharmony_ci
2808c2ecf20Sopenharmony_ci// status rationing tuning value (each port gets checked each n ms)
2818c2ecf20Sopenharmony_ci#define	STATUS_RATION	10
2828c2ecf20Sopenharmony_ci
2838c2ecf20Sopenharmony_ci#endif
284