162306a36Sopenharmony_ci/* SPDX-License-Identifier: BSD-3-Clause */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci	usa90msg.h
462306a36Sopenharmony_ci
562306a36Sopenharmony_ci	Copyright (c) 1998-2003 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 USA19HS
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-2003 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	Revisions:
4062306a36Sopenharmony_ci
4162306a36Sopenharmony_ci	2003feb14		add setTxMode/txMode  and cancelRxXoff to portControl
4262306a36Sopenharmony_ci	2003mar21		change name of PARITY_0/1 to add MARK/SPACE
4362306a36Sopenharmony_ci*/
4462306a36Sopenharmony_ci
4562306a36Sopenharmony_ci#ifndef	__USA90MSG__
4662306a36Sopenharmony_ci#define	__USA90MSG__
4762306a36Sopenharmony_ci
4862306a36Sopenharmony_cistruct keyspan_usa90_portControlMessage
4962306a36Sopenharmony_ci{
5062306a36Sopenharmony_ci	/*
5162306a36Sopenharmony_ci		there are three types of "commands" sent in the control message:
5262306a36Sopenharmony_ci
5362306a36Sopenharmony_ci		1.	configuration changes which must be requested by setting
5462306a36Sopenharmony_ci			the corresponding "set" flag (and should only be requested
5562306a36Sopenharmony_ci			when necessary, to reduce overhead on the device):
5662306a36Sopenharmony_ci	*/
5762306a36Sopenharmony_ci
5862306a36Sopenharmony_ci	u8	setClocking,	// host requests baud rate be set
5962306a36Sopenharmony_ci		baudLo,			// host does baud divisor calculation
6062306a36Sopenharmony_ci		baudHi,			// host does baud divisor calculation
6162306a36Sopenharmony_ci
6262306a36Sopenharmony_ci		setLcr,			// host requests lcr be set
6362306a36Sopenharmony_ci		lcr,			// use PARITY, STOPBITS, DATABITS below
6462306a36Sopenharmony_ci
6562306a36Sopenharmony_ci		setRxMode,		// set receive mode
6662306a36Sopenharmony_ci		rxMode,			// RXMODE_DMA or RXMODE_BYHAND
6762306a36Sopenharmony_ci
6862306a36Sopenharmony_ci		setTxMode,		// set transmit mode
6962306a36Sopenharmony_ci		txMode,			// TXMODE_DMA or TXMODE_BYHAND
7062306a36Sopenharmony_ci
7162306a36Sopenharmony_ci		setTxFlowControl,	// host requests tx flow control be set
7262306a36Sopenharmony_ci		txFlowControl	,	// use TX_FLOW... bits below
7362306a36Sopenharmony_ci		setRxFlowControl,	// host requests rx flow control be set
7462306a36Sopenharmony_ci		rxFlowControl,	// use RX_FLOW... bits below
7562306a36Sopenharmony_ci		sendXoff,		// host requests XOFF transmitted immediately
7662306a36Sopenharmony_ci		sendXon,		// host requests XON char transmitted
7762306a36Sopenharmony_ci		xonChar,		// specified in current character format
7862306a36Sopenharmony_ci		xoffChar,		// specified in current character format
7962306a36Sopenharmony_ci
8062306a36Sopenharmony_ci		sendChar,		// host requests char transmitted immediately
8162306a36Sopenharmony_ci		txChar,			// character to send
8262306a36Sopenharmony_ci
8362306a36Sopenharmony_ci		setRts,			// host requests RTS output be set
8462306a36Sopenharmony_ci		rts,			// 1=on, 0=off
8562306a36Sopenharmony_ci		setDtr, 		// host requests DTR output be set
8662306a36Sopenharmony_ci		dtr;			// 1=on, 0=off
8762306a36Sopenharmony_ci
8862306a36Sopenharmony_ci
8962306a36Sopenharmony_ci	/*
9062306a36Sopenharmony_ci		2.	configuration data which is simply used as is
9162306a36Sopenharmony_ci			and must be specified correctly in every host message.
9262306a36Sopenharmony_ci	*/
9362306a36Sopenharmony_ci
9462306a36Sopenharmony_ci	u8	rxForwardingLength,  // forward when this number of chars available
9562306a36Sopenharmony_ci		rxForwardingTimeout, // (1-31 in ms)
9662306a36Sopenharmony_ci		txAckSetting;	   // 0=don't ack, 1=normal, 2-255 TBD...
9762306a36Sopenharmony_ci	/*
9862306a36Sopenharmony_ci		3.	Firmware states which cause actions if they change
9962306a36Sopenharmony_ci		and must be specified correctly in every host message.
10062306a36Sopenharmony_ci	*/
10162306a36Sopenharmony_ci
10262306a36Sopenharmony_ci	u8	portEnabled,	// 0=disabled, 1=enabled
10362306a36Sopenharmony_ci		txFlush,		// 0=normal, 1=toss outbound data
10462306a36Sopenharmony_ci		txBreak,		// 0=break off, 1=break on
10562306a36Sopenharmony_ci		loopbackMode;	// 0=no loopback, 1=loopback enabled
10662306a36Sopenharmony_ci
10762306a36Sopenharmony_ci	/*
10862306a36Sopenharmony_ci		4.	commands which are flags only; these are processed in order
10962306a36Sopenharmony_ci			(so that, e.g., if rxFlush and rxForward flags are set, the
11062306a36Sopenharmony_ci			port will have no data to forward); any non-zero value
11162306a36Sopenharmony_ci			is respected
11262306a36Sopenharmony_ci	*/
11362306a36Sopenharmony_ci
11462306a36Sopenharmony_ci	u8	rxFlush,		// toss inbound data
11562306a36Sopenharmony_ci		rxForward,		// forward all inbound data, NOW (as if fwdLen==1)
11662306a36Sopenharmony_ci		cancelRxXoff,	// cancel any receive XOFF state (_txXoff)
11762306a36Sopenharmony_ci		returnStatus;	// return current status NOW
11862306a36Sopenharmony_ci};
11962306a36Sopenharmony_ci
12062306a36Sopenharmony_ci// defines for bits in lcr
12162306a36Sopenharmony_ci#define		USA_DATABITS_5		0x00
12262306a36Sopenharmony_ci#define		USA_DATABITS_6		0x01
12362306a36Sopenharmony_ci#define		USA_DATABITS_7		0x02
12462306a36Sopenharmony_ci#define		USA_DATABITS_8		0x03
12562306a36Sopenharmony_ci#define		STOPBITS_5678_1		0x00	// 1 stop bit for all byte sizes
12662306a36Sopenharmony_ci#define		STOPBITS_5_1p5		0x04	// 1.5 stop bits for 5-bit byte
12762306a36Sopenharmony_ci#define		STOPBITS_678_2		0x04	// 2 stop bits for 6-8 bit byte
12862306a36Sopenharmony_ci#define		USA_PARITY_NONE		0x00
12962306a36Sopenharmony_ci#define		USA_PARITY_ODD		0x08
13062306a36Sopenharmony_ci#define		USA_PARITY_EVEN		0x18
13162306a36Sopenharmony_ci#define		PARITY_MARK_1  		0x28   	// force parity MARK
13262306a36Sopenharmony_ci#define		PARITY_SPACE_0 		0x38	// force parity SPACE
13362306a36Sopenharmony_ci
13462306a36Sopenharmony_ci#define		TXFLOW_CTS			0x04
13562306a36Sopenharmony_ci#define		TXFLOW_DSR			0x08
13662306a36Sopenharmony_ci#define		TXFLOW_XOFF			0x01
13762306a36Sopenharmony_ci#define		TXFLOW_XOFF_ANY		0x02
13862306a36Sopenharmony_ci#define		TXFLOW_XOFF_BITS	(TXFLOW_XOFF | TXFLOW_XOFF_ANY)
13962306a36Sopenharmony_ci
14062306a36Sopenharmony_ci#define		RXFLOW_XOFF			0x10
14162306a36Sopenharmony_ci#define		RXFLOW_RTS			0x20
14262306a36Sopenharmony_ci#define		RXFLOW_DTR			0x40
14362306a36Sopenharmony_ci#define		RXFLOW_DSR_SENSITIVITY	0x80
14462306a36Sopenharmony_ci
14562306a36Sopenharmony_ci#define		RXMODE_BYHAND		0x00
14662306a36Sopenharmony_ci#define		RXMODE_DMA			0x02
14762306a36Sopenharmony_ci
14862306a36Sopenharmony_ci#define		TXMODE_BYHAND		0x00
14962306a36Sopenharmony_ci#define		TXMODE_DMA			0x02
15062306a36Sopenharmony_ci
15162306a36Sopenharmony_ci
15262306a36Sopenharmony_ci// all things called "StatusMessage" are sent on the status endpoint
15362306a36Sopenharmony_ci
15462306a36Sopenharmony_cistruct keyspan_usa90_portStatusMessage
15562306a36Sopenharmony_ci{
15662306a36Sopenharmony_ci	u8	msr,			// reports the actual MSR register
15762306a36Sopenharmony_ci		cts,			// reports CTS pin
15862306a36Sopenharmony_ci		dcd,			// reports DCD pin
15962306a36Sopenharmony_ci		dsr,			// reports DSR pin
16062306a36Sopenharmony_ci		ri,				// reports RI pin
16162306a36Sopenharmony_ci		_txXoff,		// port is in XOFF state (we received XOFF)
16262306a36Sopenharmony_ci		rxBreak,		// reports break state
16362306a36Sopenharmony_ci		rxOverrun,		// count of overrun errors (since last reported)
16462306a36Sopenharmony_ci		rxParity,		// count of parity errors (since last reported)
16562306a36Sopenharmony_ci		rxFrame,		// count of frame errors (since last reported)
16662306a36Sopenharmony_ci		portState,		// PORTSTATE_xxx bits (useful for debugging)
16762306a36Sopenharmony_ci		messageAck,		// message acknowledgement
16862306a36Sopenharmony_ci		charAck,		// character acknowledgement
16962306a36Sopenharmony_ci		controlResponse;	// (value = returnStatus) a control message has been processed
17062306a36Sopenharmony_ci};
17162306a36Sopenharmony_ci
17262306a36Sopenharmony_ci// bits in RX data message when STAT byte is included
17362306a36Sopenharmony_ci
17462306a36Sopenharmony_ci#define	RXERROR_OVERRUN		0x02
17562306a36Sopenharmony_ci#define	RXERROR_PARITY		0x04
17662306a36Sopenharmony_ci#define	RXERROR_FRAMING		0x08
17762306a36Sopenharmony_ci#define	RXERROR_BREAK		0x10
17862306a36Sopenharmony_ci
17962306a36Sopenharmony_ci#define	PORTSTATE_ENABLED	0x80
18062306a36Sopenharmony_ci#define	PORTSTATE_TXFLUSH	0x01
18162306a36Sopenharmony_ci#define	PORTSTATE_TXBREAK	0x02
18262306a36Sopenharmony_ci#define	PORTSTATE_LOOPBACK 	0x04
18362306a36Sopenharmony_ci
18462306a36Sopenharmony_ci// MSR bits
18562306a36Sopenharmony_ci
18662306a36Sopenharmony_ci#define USA_MSR_dCTS	  		0x01		// CTS has changed since last report
18762306a36Sopenharmony_ci#define USA_MSR_dDSR	  		0x02
18862306a36Sopenharmony_ci#define USA_MSR_dRI			0x04
18962306a36Sopenharmony_ci#define USA_MSR_dDCD	  		0x08
19062306a36Sopenharmony_ci
19162306a36Sopenharmony_ci#define USA_MSR_CTS			0x10	  	// current state of CTS
19262306a36Sopenharmony_ci#define USA_MSR_DSR			0x20
19362306a36Sopenharmony_ci#define USA_USA_MSR_RI			0x40
19462306a36Sopenharmony_ci#define MSR_DCD				0x80
19562306a36Sopenharmony_ci
19662306a36Sopenharmony_ci// ie: the maximum length of an endpoint buffer
19762306a36Sopenharmony_ci#define		MAX_DATA_LEN			64
19862306a36Sopenharmony_ci
19962306a36Sopenharmony_ci#endif
200