162306a36Sopenharmony_ci/* SPDX-License-Identifier: BSD-3-Clause */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci	usa49msg.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 USA49W
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	4th revision: USA49W version
4062306a36Sopenharmony_ci
4162306a36Sopenharmony_ci	Buffer formats for RX/TX data messages are not defined by
4262306a36Sopenharmony_ci	a structure, but are described here:
4362306a36Sopenharmony_ci
4462306a36Sopenharmony_ci	USB OUT (host -> USAxx, transmit) messages contain a
4562306a36Sopenharmony_ci	REQUEST_ACK indicator (set to 0xff to request an ACK at the
4662306a36Sopenharmony_ci	completion of transmit; 0x00 otherwise), followed by data:
4762306a36Sopenharmony_ci
4862306a36Sopenharmony_ci		RQSTACK DAT DAT DAT ...
4962306a36Sopenharmony_ci
5062306a36Sopenharmony_ci	with a total data length of 63.
5162306a36Sopenharmony_ci
5262306a36Sopenharmony_ci	USB IN (USAxx -> host, receive) messages begin with a status
5362306a36Sopenharmony_ci	byte in which the 0x80 bit is either:
5462306a36Sopenharmony_ci
5562306a36Sopenharmony_ci		(a)	0x80 bit clear
5662306a36Sopenharmony_ci			indicates that the bytes following it are all data
5762306a36Sopenharmony_ci			bytes:
5862306a36Sopenharmony_ci
5962306a36Sopenharmony_ci				STAT DATA DATA DATA DATA DATA ...
6062306a36Sopenharmony_ci
6162306a36Sopenharmony_ci			for a total of up to 63 DATA bytes,
6262306a36Sopenharmony_ci
6362306a36Sopenharmony_ci	or:
6462306a36Sopenharmony_ci
6562306a36Sopenharmony_ci		(b)	0x80 bit set
6662306a36Sopenharmony_ci			indiates that the bytes following alternate data and
6762306a36Sopenharmony_ci			status bytes:
6862306a36Sopenharmony_ci
6962306a36Sopenharmony_ci				STAT DATA STAT DATA STAT DATA STAT DATA ...
7062306a36Sopenharmony_ci
7162306a36Sopenharmony_ci			for a total of up to 32 DATA bytes.
7262306a36Sopenharmony_ci
7362306a36Sopenharmony_ci	The valid bits in the STAT bytes are:
7462306a36Sopenharmony_ci
7562306a36Sopenharmony_ci		OVERRUN	0x02
7662306a36Sopenharmony_ci		PARITY	0x04
7762306a36Sopenharmony_ci		FRAMING	0x08
7862306a36Sopenharmony_ci		BREAK	0x10
7962306a36Sopenharmony_ci
8062306a36Sopenharmony_ci	Notes:
8162306a36Sopenharmony_ci
8262306a36Sopenharmony_ci	(1) The OVERRUN bit can appear in either (a) or (b) format
8362306a36Sopenharmony_ci		messages, but the but the PARITY/FRAMING/BREAK bits
8462306a36Sopenharmony_ci		only appear in (b) format messages.
8562306a36Sopenharmony_ci	(2) For the host to determine the exact point at which the
8662306a36Sopenharmony_ci		overrun occurred (to identify the point in the data
8762306a36Sopenharmony_ci		stream at which the data was lost), it needs to count
8862306a36Sopenharmony_ci		128 characters, starting at the first character of the
8962306a36Sopenharmony_ci		message in which OVERRUN was reported; the lost character(s)
9062306a36Sopenharmony_ci		would have been received between the 128th and 129th
9162306a36Sopenharmony_ci		characters.
9262306a36Sopenharmony_ci	(3)	An RX data message in which the first byte has 0x80 clear
9362306a36Sopenharmony_ci		serves as a "break off" indicator.
9462306a36Sopenharmony_ci	(4)	a control message specifying disablePort will be answered
9562306a36Sopenharmony_ci		with a status message, but no further status will be sent
9662306a36Sopenharmony_ci		until a control messages with enablePort is sent
9762306a36Sopenharmony_ci
9862306a36Sopenharmony_ci	revision history:
9962306a36Sopenharmony_ci
10062306a36Sopenharmony_ci	1999feb10	add reportHskiaChanges to allow us to ignore them
10162306a36Sopenharmony_ci	1999feb10	add txAckThreshold for fast+loose throughput enhancement
10262306a36Sopenharmony_ci	1999mar30	beef up support for RX error reporting
10362306a36Sopenharmony_ci	1999apr14	add resetDataToggle to control message
10462306a36Sopenharmony_ci	2000jan04	merge with usa17msg.h
10562306a36Sopenharmony_ci	2000mar08	clone from usa26msg.h -> usa49msg.h
10662306a36Sopenharmony_ci	2000mar09	change to support 4 ports
10762306a36Sopenharmony_ci	2000may03	change external clocking to match USA-49W hardware
10862306a36Sopenharmony_ci	2000jun01	add extended BSD-style copyright text
10962306a36Sopenharmony_ci	2001jul05	change message format to improve OVERRUN case
11062306a36Sopenharmony_ci*/
11162306a36Sopenharmony_ci
11262306a36Sopenharmony_ci#ifndef	__USA49MSG__
11362306a36Sopenharmony_ci#define	__USA49MSG__
11462306a36Sopenharmony_ci
11562306a36Sopenharmony_ci
11662306a36Sopenharmony_ci/*
11762306a36Sopenharmony_ci	Host->device messages sent on the global control endpoint:
11862306a36Sopenharmony_ci
11962306a36Sopenharmony_ci	portNumber	message
12062306a36Sopenharmony_ci	----------	--------------------
12162306a36Sopenharmony_ci	0,1,2,3		portControlMessage
12262306a36Sopenharmony_ci	0x80		globalControlMessage
12362306a36Sopenharmony_ci*/
12462306a36Sopenharmony_ci
12562306a36Sopenharmony_cistruct keyspan_usa49_portControlMessage
12662306a36Sopenharmony_ci{
12762306a36Sopenharmony_ci	/*
12862306a36Sopenharmony_ci		0.	0/1/2/3 	port control message follows
12962306a36Sopenharmony_ci			0x80 set	non-port control message follows
13062306a36Sopenharmony_ci	*/
13162306a36Sopenharmony_ci	u8	portNumber,
13262306a36Sopenharmony_ci
13362306a36Sopenharmony_ci	/*
13462306a36Sopenharmony_ci		there are three types of "commands" sent in the control message:
13562306a36Sopenharmony_ci
13662306a36Sopenharmony_ci		1.	configuration changes which must be requested by setting
13762306a36Sopenharmony_ci			the corresponding "set" flag (and should only be requested
13862306a36Sopenharmony_ci			when necessary, to reduce overhead on the USA26):
13962306a36Sopenharmony_ci	*/
14062306a36Sopenharmony_ci		setClocking,	// host requests baud rate be set
14162306a36Sopenharmony_ci		baudLo,			// host does baud divisor calculation
14262306a36Sopenharmony_ci		baudHi,			// baudHi is only used for first port (gives lower rates)
14362306a36Sopenharmony_ci		prescaler,		// specified as N/8; values 8-ff are valid
14462306a36Sopenharmony_ci						// must be set any time internal baud rate is set;
14562306a36Sopenharmony_ci		txClocking,		// 0=internal, 1=external/DSR
14662306a36Sopenharmony_ci		rxClocking,		// 0=internal, 1=external/DSR
14762306a36Sopenharmony_ci
14862306a36Sopenharmony_ci		setLcr,			// host requests lcr be set
14962306a36Sopenharmony_ci		lcr,			// use PARITY, STOPBITS, DATABITS below
15062306a36Sopenharmony_ci
15162306a36Sopenharmony_ci		setFlowControl,	// host requests flow control be set
15262306a36Sopenharmony_ci		ctsFlowControl,	// 1=use CTS flow control, 0=don't
15362306a36Sopenharmony_ci		xonFlowControl,	// 1=use XON/XOFF flow control, 0=don't
15462306a36Sopenharmony_ci		xonChar,		// specified in current character format
15562306a36Sopenharmony_ci		xoffChar,		// specified in current character format
15662306a36Sopenharmony_ci
15762306a36Sopenharmony_ci		setRts,			// host requests RTS output be set
15862306a36Sopenharmony_ci		rts,			// 1=active, 0=inactive
15962306a36Sopenharmony_ci
16062306a36Sopenharmony_ci		setDtr,			// host requests DTR output be set
16162306a36Sopenharmony_ci		dtr;			// 1=on, 0=off
16262306a36Sopenharmony_ci
16362306a36Sopenharmony_ci
16462306a36Sopenharmony_ci	/*
16562306a36Sopenharmony_ci		3.	configuration data which is simply used as is (no overhead,
16662306a36Sopenharmony_ci			but must be specified correctly in every host message).
16762306a36Sopenharmony_ci	*/
16862306a36Sopenharmony_ci	u8	forwardingLength,  // forward when this number of chars available
16962306a36Sopenharmony_ci		dsrFlowControl,	// 1=use DSR flow control, 0=don't
17062306a36Sopenharmony_ci		txAckThreshold,	// 0=not allowed, 1=normal, 2-255 deliver ACK faster
17162306a36Sopenharmony_ci		loopbackMode;	// 0=no loopback, 1=loopback enabled
17262306a36Sopenharmony_ci
17362306a36Sopenharmony_ci	/*
17462306a36Sopenharmony_ci		4.	commands which are flags only; these are processed in order
17562306a36Sopenharmony_ci			(so that, e.g., if both _txOn and _txOff flags are set, the
17662306a36Sopenharmony_ci			port ends in a TX_OFF state); any non-zero value is respected
17762306a36Sopenharmony_ci	*/
17862306a36Sopenharmony_ci	u8	_txOn,			// enable transmitting (and continue if there's data)
17962306a36Sopenharmony_ci		_txOff,			// stop transmitting
18062306a36Sopenharmony_ci		txFlush,		// toss outbound data
18162306a36Sopenharmony_ci		txBreak,		// turn on break (cleared by _txOn)
18262306a36Sopenharmony_ci		rxOn,			// turn on receiver
18362306a36Sopenharmony_ci		rxOff,			// turn off receiver
18462306a36Sopenharmony_ci		rxFlush,		// toss inbound data
18562306a36Sopenharmony_ci		rxForward,		// forward all inbound data, NOW (as if fwdLen==1)
18662306a36Sopenharmony_ci		returnStatus,	// return current status (even if it hasn't changed)
18762306a36Sopenharmony_ci		resetDataToggle,// reset data toggle state to DATA0
18862306a36Sopenharmony_ci		enablePort,		// start servicing port (move data, check status)
18962306a36Sopenharmony_ci		disablePort;	// stop servicing port (does implicit tx/rx flush/off)
19062306a36Sopenharmony_ci
19162306a36Sopenharmony_ci};
19262306a36Sopenharmony_ci
19362306a36Sopenharmony_ci// defines for bits in lcr
19462306a36Sopenharmony_ci#define	USA_DATABITS_5		0x00
19562306a36Sopenharmony_ci#define	USA_DATABITS_6		0x01
19662306a36Sopenharmony_ci#define	USA_DATABITS_7		0x02
19762306a36Sopenharmony_ci#define	USA_DATABITS_8		0x03
19862306a36Sopenharmony_ci#define	STOPBITS_5678_1		0x00	// 1 stop bit for all byte sizes
19962306a36Sopenharmony_ci#define	STOPBITS_5_1p5		0x04	// 1.5 stop bits for 5-bit byte
20062306a36Sopenharmony_ci#define	STOPBITS_678_2		0x04	// 2 stop bits for 6/7/8-bit byte
20162306a36Sopenharmony_ci#define	USA_PARITY_NONE		0x00
20262306a36Sopenharmony_ci#define	USA_PARITY_ODD		0x08
20362306a36Sopenharmony_ci#define	USA_PARITY_EVEN		0x18
20462306a36Sopenharmony_ci#define	PARITY_1			0x28
20562306a36Sopenharmony_ci#define	PARITY_0			0x38
20662306a36Sopenharmony_ci
20762306a36Sopenharmony_ci/*
20862306a36Sopenharmony_ci	during normal operation, status messages are returned
20962306a36Sopenharmony_ci	to the host whenever the board detects changes.  In some
21062306a36Sopenharmony_ci	circumstances (e.g. Windows), status messages from the
21162306a36Sopenharmony_ci	device cause problems; to shut them off, the host issues
21262306a36Sopenharmony_ci	a control message with the disableStatusMessages flags
21362306a36Sopenharmony_ci	set (to any non-zero value).  The device will respond to
21462306a36Sopenharmony_ci	this message, and then suppress further status messages;
21562306a36Sopenharmony_ci	it will resume sending status messages any time the host
21662306a36Sopenharmony_ci	sends any control message (either global or port-specific).
21762306a36Sopenharmony_ci*/
21862306a36Sopenharmony_ci
21962306a36Sopenharmony_cistruct keyspan_usa49_globalControlMessage
22062306a36Sopenharmony_ci{
22162306a36Sopenharmony_ci	u8	portNumber,			// 0x80
22262306a36Sopenharmony_ci		sendGlobalStatus,	// 1/2=number of status responses requested
22362306a36Sopenharmony_ci		resetStatusToggle,	// 1=reset global status toggle
22462306a36Sopenharmony_ci		resetStatusCount,	// a cycling value
22562306a36Sopenharmony_ci		remoteWakeupEnable,		// 0x10=P1, 0x20=P2, 0x40=P3, 0x80=P4
22662306a36Sopenharmony_ci		disableStatusMessages;	// 1=send no status until host talks
22762306a36Sopenharmony_ci};
22862306a36Sopenharmony_ci
22962306a36Sopenharmony_ci/*
23062306a36Sopenharmony_ci	Device->host messages send on the global status endpoint
23162306a36Sopenharmony_ci
23262306a36Sopenharmony_ci	portNumber			message
23362306a36Sopenharmony_ci	----------			--------------------
23462306a36Sopenharmony_ci	0x00,0x01,0x02,0x03	portStatusMessage
23562306a36Sopenharmony_ci	0x80				globalStatusMessage
23662306a36Sopenharmony_ci	0x81				globalDebugMessage
23762306a36Sopenharmony_ci*/
23862306a36Sopenharmony_ci
23962306a36Sopenharmony_cistruct keyspan_usa49_portStatusMessage	// one for each port
24062306a36Sopenharmony_ci{
24162306a36Sopenharmony_ci	u8	portNumber,		// 0,1,2,3
24262306a36Sopenharmony_ci		cts,			// reports CTS pin
24362306a36Sopenharmony_ci		dcd,			// reports DCD pin
24462306a36Sopenharmony_ci		dsr,			// reports DSR pin
24562306a36Sopenharmony_ci		ri,				// reports RI pin
24662306a36Sopenharmony_ci		_txOff,			// transmit has been disabled (by host)
24762306a36Sopenharmony_ci		_txXoff,		// transmit is in XOFF state (either host or RX XOFF)
24862306a36Sopenharmony_ci		rxEnabled,		// as configured by rxOn/rxOff 1=on, 0=off
24962306a36Sopenharmony_ci		controlResponse,// 1=a control message has been processed
25062306a36Sopenharmony_ci		txAck,			// ACK (data TX complete)
25162306a36Sopenharmony_ci		rs232valid;		// RS-232 signal valid
25262306a36Sopenharmony_ci};
25362306a36Sopenharmony_ci
25462306a36Sopenharmony_ci// bits in RX data message when STAT byte is included
25562306a36Sopenharmony_ci#define	RXERROR_OVERRUN	0x02
25662306a36Sopenharmony_ci#define	RXERROR_PARITY	0x04
25762306a36Sopenharmony_ci#define	RXERROR_FRAMING	0x08
25862306a36Sopenharmony_ci#define	RXERROR_BREAK	0x10
25962306a36Sopenharmony_ci
26062306a36Sopenharmony_cistruct keyspan_usa49_globalStatusMessage
26162306a36Sopenharmony_ci{
26262306a36Sopenharmony_ci	u8	portNumber,			// 0x80=globalStatusMessage
26362306a36Sopenharmony_ci		sendGlobalStatus,	// from request, decremented
26462306a36Sopenharmony_ci		resetStatusCount;	// as in request
26562306a36Sopenharmony_ci};
26662306a36Sopenharmony_ci
26762306a36Sopenharmony_cistruct keyspan_usa49_globalDebugMessage
26862306a36Sopenharmony_ci{
26962306a36Sopenharmony_ci	u8	portNumber,			// 0x81=globalDebugMessage
27062306a36Sopenharmony_ci		n,					// typically a count/status byte
27162306a36Sopenharmony_ci		b;					// typically a data byte
27262306a36Sopenharmony_ci};
27362306a36Sopenharmony_ci
27462306a36Sopenharmony_ci// ie: the maximum length of an EZUSB endpoint buffer
27562306a36Sopenharmony_ci#define	MAX_DATA_LEN			64
27662306a36Sopenharmony_ci
27762306a36Sopenharmony_ci// update status approx. 60 times a second (16.6666 ms)
27862306a36Sopenharmony_ci#define	STATUS_UPDATE_INTERVAL	16
27962306a36Sopenharmony_ci
28062306a36Sopenharmony_ci// status rationing tuning value (each port gets checked each n ms)
28162306a36Sopenharmony_ci#define	STATUS_RATION	10
28262306a36Sopenharmony_ci
28362306a36Sopenharmony_ci#endif
284