keyspan_usa49msg.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. /* SPDX-License-Identifier: BSD-3-Clause */
  2. /*
  3. usa49msg.h
  4. Copyright (C) 1998-2000 InnoSys Incorporated. All Rights Reserved
  5. This file is available under a BSD-style copyright
  6. Keyspan USB Async Message Formats for the USA49W
  7. Redistribution and use in source and binary forms, with or without
  8. modification, are permitted provided that the following conditions are
  9. met:
  10. 1. Redistributions of source code must retain this licence text
  11. without modification, this list of conditions, and the following
  12. disclaimer. The following copyright notice must appear immediately at
  13. the beginning of all source files:
  14. Copyright (C) 1998-2000 InnoSys Incorporated. All Rights Reserved
  15. This file is available under a BSD-style copyright
  16. 2. The name of InnoSys Incorporated may not be used to endorse or promote
  17. products derived from this software without specific prior written
  18. permission.
  19. THIS SOFTWARE IS PROVIDED BY INNOSYS CORP. ``AS IS'' AND ANY EXPRESS OR
  20. IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  21. OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  22. NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  23. INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  24. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  25. SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  26. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  27. LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  28. OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  29. SUCH DAMAGE.
  30. 4th revision: USA49W version
  31. Buffer formats for RX/TX data messages are not defined by
  32. a structure, but are described here:
  33. USB OUT (host -> USAxx, transmit) messages contain a
  34. REQUEST_ACK indicator (set to 0xff to request an ACK at the
  35. completion of transmit; 0x00 otherwise), followed by data:
  36. RQSTACK DAT DAT DAT ...
  37. with a total data length of 63.
  38. USB IN (USAxx -> host, receive) messages begin with a status
  39. byte in which the 0x80 bit is either:
  40. (a) 0x80 bit clear
  41. indicates that the bytes following it are all data
  42. bytes:
  43. STAT DATA DATA DATA DATA DATA ...
  44. for a total of up to 63 DATA bytes,
  45. or:
  46. (b) 0x80 bit set
  47. indiates that the bytes following alternate data and
  48. status bytes:
  49. STAT DATA STAT DATA STAT DATA STAT DATA ...
  50. for a total of up to 32 DATA bytes.
  51. The valid bits in the STAT bytes are:
  52. OVERRUN 0x02
  53. PARITY 0x04
  54. FRAMING 0x08
  55. BREAK 0x10
  56. Notes:
  57. (1) The OVERRUN bit can appear in either (a) or (b) format
  58. messages, but the but the PARITY/FRAMING/BREAK bits
  59. only appear in (b) format messages.
  60. (2) For the host to determine the exact point at which the
  61. overrun occurred (to identify the point in the data
  62. stream at which the data was lost), it needs to count
  63. 128 characters, starting at the first character of the
  64. message in which OVERRUN was reported; the lost character(s)
  65. would have been received between the 128th and 129th
  66. characters.
  67. (3) An RX data message in which the first byte has 0x80 clear
  68. serves as a "break off" indicator.
  69. (4) a control message specifying disablePort will be answered
  70. with a status message, but no further status will be sent
  71. until a control messages with enablePort is sent
  72. revision history:
  73. 1999feb10 add reportHskiaChanges to allow us to ignore them
  74. 1999feb10 add txAckThreshold for fast+loose throughput enhancement
  75. 1999mar30 beef up support for RX error reporting
  76. 1999apr14 add resetDataToggle to control message
  77. 2000jan04 merge with usa17msg.h
  78. 2000mar08 clone from usa26msg.h -> usa49msg.h
  79. 2000mar09 change to support 4 ports
  80. 2000may03 change external clocking to match USA-49W hardware
  81. 2000jun01 add extended BSD-style copyright text
  82. 2001jul05 change message format to improve OVERRUN case
  83. */
  84. #ifndef __USA49MSG__
  85. #define __USA49MSG__
  86. /*
  87. Host->device messages sent on the global control endpoint:
  88. portNumber message
  89. ---------- --------------------
  90. 0,1,2,3 portControlMessage
  91. 0x80 globalControlMessage
  92. */
  93. struct keyspan_usa49_portControlMessage
  94. {
  95. /*
  96. 0. 0/1/2/3 port control message follows
  97. 0x80 set non-port control message follows
  98. */
  99. u8 portNumber,
  100. /*
  101. there are three types of "commands" sent in the control message:
  102. 1. configuration changes which must be requested by setting
  103. the corresponding "set" flag (and should only be requested
  104. when necessary, to reduce overhead on the USA26):
  105. */
  106. setClocking, // host requests baud rate be set
  107. baudLo, // host does baud divisor calculation
  108. baudHi, // baudHi is only used for first port (gives lower rates)
  109. prescaler, // specified as N/8; values 8-ff are valid
  110. // must be set any time internal baud rate is set;
  111. txClocking, // 0=internal, 1=external/DSR
  112. rxClocking, // 0=internal, 1=external/DSR
  113. setLcr, // host requests lcr be set
  114. lcr, // use PARITY, STOPBITS, DATABITS below
  115. setFlowControl, // host requests flow control be set
  116. ctsFlowControl, // 1=use CTS flow control, 0=don't
  117. xonFlowControl, // 1=use XON/XOFF flow control, 0=don't
  118. xonChar, // specified in current character format
  119. xoffChar, // specified in current character format
  120. setRts, // host requests RTS output be set
  121. rts, // 1=active, 0=inactive
  122. setDtr, // host requests DTR output be set
  123. dtr; // 1=on, 0=off
  124. /*
  125. 3. configuration data which is simply used as is (no overhead,
  126. but must be specified correctly in every host message).
  127. */
  128. u8 forwardingLength, // forward when this number of chars available
  129. dsrFlowControl, // 1=use DSR flow control, 0=don't
  130. txAckThreshold, // 0=not allowed, 1=normal, 2-255 deliver ACK faster
  131. loopbackMode; // 0=no loopback, 1=loopback enabled
  132. /*
  133. 4. commands which are flags only; these are processed in order
  134. (so that, e.g., if both _txOn and _txOff flags are set, the
  135. port ends in a TX_OFF state); any non-zero value is respected
  136. */
  137. u8 _txOn, // enable transmitting (and continue if there's data)
  138. _txOff, // stop transmitting
  139. txFlush, // toss outbound data
  140. txBreak, // turn on break (cleared by _txOn)
  141. rxOn, // turn on receiver
  142. rxOff, // turn off receiver
  143. rxFlush, // toss inbound data
  144. rxForward, // forward all inbound data, NOW (as if fwdLen==1)
  145. returnStatus, // return current status (even if it hasn't changed)
  146. resetDataToggle,// reset data toggle state to DATA0
  147. enablePort, // start servicing port (move data, check status)
  148. disablePort; // stop servicing port (does implicit tx/rx flush/off)
  149. };
  150. // defines for bits in lcr
  151. #define USA_DATABITS_5 0x00
  152. #define USA_DATABITS_6 0x01
  153. #define USA_DATABITS_7 0x02
  154. #define USA_DATABITS_8 0x03
  155. #define STOPBITS_5678_1 0x00 // 1 stop bit for all byte sizes
  156. #define STOPBITS_5_1p5 0x04 // 1.5 stop bits for 5-bit byte
  157. #define STOPBITS_678_2 0x04 // 2 stop bits for 6/7/8-bit byte
  158. #define USA_PARITY_NONE 0x00
  159. #define USA_PARITY_ODD 0x08
  160. #define USA_PARITY_EVEN 0x18
  161. #define PARITY_1 0x28
  162. #define PARITY_0 0x38
  163. /*
  164. during normal operation, status messages are returned
  165. to the host whenever the board detects changes. In some
  166. circumstances (e.g. Windows), status messages from the
  167. device cause problems; to shut them off, the host issues
  168. a control message with the disableStatusMessages flags
  169. set (to any non-zero value). The device will respond to
  170. this message, and then suppress further status messages;
  171. it will resume sending status messages any time the host
  172. sends any control message (either global or port-specific).
  173. */
  174. struct keyspan_usa49_globalControlMessage
  175. {
  176. u8 portNumber, // 0x80
  177. sendGlobalStatus, // 1/2=number of status responses requested
  178. resetStatusToggle, // 1=reset global status toggle
  179. resetStatusCount, // a cycling value
  180. remoteWakeupEnable, // 0x10=P1, 0x20=P2, 0x40=P3, 0x80=P4
  181. disableStatusMessages; // 1=send no status until host talks
  182. };
  183. /*
  184. Device->host messages send on the global status endpoint
  185. portNumber message
  186. ---------- --------------------
  187. 0x00,0x01,0x02,0x03 portStatusMessage
  188. 0x80 globalStatusMessage
  189. 0x81 globalDebugMessage
  190. */
  191. struct keyspan_usa49_portStatusMessage // one for each port
  192. {
  193. u8 portNumber, // 0,1,2,3
  194. cts, // reports CTS pin
  195. dcd, // reports DCD pin
  196. dsr, // reports DSR pin
  197. ri, // reports RI pin
  198. _txOff, // transmit has been disabled (by host)
  199. _txXoff, // transmit is in XOFF state (either host or RX XOFF)
  200. rxEnabled, // as configured by rxOn/rxOff 1=on, 0=off
  201. controlResponse,// 1=a control message has been processed
  202. txAck, // ACK (data TX complete)
  203. rs232valid; // RS-232 signal valid
  204. };
  205. // bits in RX data message when STAT byte is included
  206. #define RXERROR_OVERRUN 0x02
  207. #define RXERROR_PARITY 0x04
  208. #define RXERROR_FRAMING 0x08
  209. #define RXERROR_BREAK 0x10
  210. struct keyspan_usa49_globalStatusMessage
  211. {
  212. u8 portNumber, // 0x80=globalStatusMessage
  213. sendGlobalStatus, // from request, decremented
  214. resetStatusCount; // as in request
  215. };
  216. struct keyspan_usa49_globalDebugMessage
  217. {
  218. u8 portNumber, // 0x81=globalDebugMessage
  219. n, // typically a count/status byte
  220. b; // typically a data byte
  221. };
  222. // ie: the maximum length of an EZUSB endpoint buffer
  223. #define MAX_DATA_LEN 64
  224. // update status approx. 60 times a second (16.6666 ms)
  225. #define STATUS_UPDATE_INTERVAL 16
  226. // status rationing tuning value (each port gets checked each n ms)
  227. #define STATUS_RATION 10
  228. #endif