keyspan_usa67msg.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. /*
  2. usa67msg.h
  3. Copyright (c) 1998-2007 InnoSys Incorporated. All Rights Reserved
  4. This file is available under a BSD-style copyright
  5. Keyspan USB Async Firmware to run on Anchor FX1
  6. Redistribution and use in source and binary forms, with or without
  7. modification, are permitted provided that the following conditions are
  8. met:
  9. 1. Redistributions of source code must retain this licence text
  10. without modification, this list of conditions, and the following
  11. disclaimer. The following copyright notice must appear immediately at
  12. the beginning of all source files:
  13. Copyright (c) 1998-2007 InnoSys Incorporated. All Rights Reserved
  14. This file is available under a BSD-style copyright
  15. 2. Redistributions in binary form must reproduce the above copyright
  16. notice, this list of conditions and the following disclaimer in the
  17. documentation and/or other materials provided with the distribution.
  18. 3. The name of InnoSys Incorprated may not be used to endorse or promote
  19. products derived from this software without specific prior written
  20. permission.
  21. THIS SOFTWARE IS PROVIDED BY INNOSYS CORP. ``AS IS'' AND ANY EXPRESS OR
  22. IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  23. OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  24. NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  25. INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  26. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  27. SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  28. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  29. LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  30. OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  31. SUCH DAMAGE.
  32. Fourth revision: This message format supports the USA28XG
  33. Buffer formats for RX/TX data messages are not defined by
  34. a structure, but are described here:
  35. USB OUT (host -> USAxx, transmit) messages contain a
  36. REQUEST_ACK indicator (set to 0xff to request an ACK at the
  37. completion of transmit; 0x00 otherwise), followed by data:
  38. RQSTACK DAT DAT DAT ...
  39. with a total data length of up to 63.
  40. USB IN (USAxx -> host, receive) messages begin with a status
  41. byte in which the 0x80 bit is either:
  42. (a) 0x80 bit clear
  43. indicates that the bytes following it are all data
  44. bytes:
  45. STAT DATA DATA DATA DATA DATA ...
  46. for a total of up to 63 DATA bytes,
  47. or:
  48. (b) 0x80 bit set
  49. indiates that the bytes following alternate data and
  50. status bytes:
  51. STAT DATA STAT DATA STAT DATA STAT DATA ...
  52. for a total of up to 32 DATA bytes.
  53. The valid bits in the STAT bytes are:
  54. OVERRUN 0x02
  55. PARITY 0x04
  56. FRAMING 0x08
  57. BREAK 0x10
  58. Notes:
  59. (1) The OVERRUN bit can appear in either (a) or (b) format
  60. messages, but the but the PARITY/FRAMING/BREAK bits
  61. only appear in (b) format messages.
  62. (2) For the host to determine the exact point at which the
  63. overrun occurred (to identify the point in the data
  64. stream at which the data was lost), it needs to count
  65. 128 characters, starting at the first character of the
  66. message in which OVERRUN was reported; the lost character(s)
  67. would have been received between the 128th and 129th
  68. characters.
  69. (3) An RX data message in which the first byte has 0x80 clear
  70. serves as a "break off" indicator.
  71. revision history:
  72. 1999feb10 add reportHskiaChanges to allow us to ignore them
  73. 1999feb10 add txAckThreshold for fast+loose throughput enhancement
  74. 1999mar30 beef up support for RX error reporting
  75. 1999apr14 add resetDataToggle to control message
  76. 2000jan04 merge with usa17msg.h
  77. 2000jun01 add extended BSD-style copyright text
  78. 2001jul05 change message format to improve OVERRUN case
  79. 2002jun05 update copyright date, improve comments
  80. 2006feb06 modify for FX1 chip
  81. */
  82. #ifndef __USA67MSG__
  83. #define __USA67MSG__
  84. // all things called "ControlMessage" are sent on the 'control' endpoint
  85. typedef struct keyspan_usa67_portControlMessage
  86. {
  87. u8 port; // 0 or 1 (selects port)
  88. /*
  89. there are three types of "commands" sent in the control message:
  90. 1. configuration changes which must be requested by setting
  91. the corresponding "set" flag (and should only be requested
  92. when necessary, to reduce overhead on the device):
  93. */
  94. u8 setClocking, // host requests baud rate be set
  95. baudLo, // host does baud divisor calculation
  96. baudHi, // baudHi is only used for first port (gives lower rates)
  97. externalClock_txClocking,
  98. // 0=internal, other=external
  99. setLcr, // host requests lcr be set
  100. lcr, // use PARITY, STOPBITS, DATABITS below
  101. setFlowControl, // host requests flow control be set
  102. ctsFlowControl, // 1=use CTS flow control, 0=don't
  103. xonFlowControl, // 1=use XON/XOFF flow control, 0=don't
  104. xonChar, // specified in current character format
  105. xoffChar, // specified in current character format
  106. setTxTriState_setRts,
  107. // host requests TX tri-state be set
  108. txTriState_rts, // 1=active (normal), 0=tristate (off)
  109. setHskoa_setDtr,
  110. // host requests HSKOA output be set
  111. hskoa_dtr, // 1=on, 0=off
  112. setPrescaler, // host requests prescalar be set (default: 13)
  113. prescaler; // specified as N/8; values 8-ff are valid
  114. // must be set any time internal baud rate is set;
  115. // must not be set when external clocking is used
  116. /*
  117. 3. configuration data which is simply used as is (no overhead,
  118. but must be specified correctly in every host message).
  119. */
  120. u8 forwardingLength, // forward when this number of chars available
  121. reportHskiaChanges_dsrFlowControl,
  122. // 1=normal; 0=ignore external clock
  123. // 1=use DSR flow control, 0=don't
  124. txAckThreshold, // 0=not allowed, 1=normal, 2-255 deliver ACK faster
  125. loopbackMode; // 0=no loopback, 1=loopback enabled
  126. /*
  127. 4. commands which are flags only; these are processed in order
  128. (so that, e.g., if both _txOn and _txOff flags are set, the
  129. port ends in a TX_OFF state); any non-zero value is respected
  130. */
  131. u8 _txOn, // enable transmitting (and continue if there's data)
  132. _txOff, // stop transmitting
  133. txFlush, // toss outbound data
  134. txBreak, // turn on break (cleared by _txOn)
  135. rxOn, // turn on receiver
  136. rxOff, // turn off receiver
  137. rxFlush, // toss inbound data
  138. rxForward, // forward all inbound data, NOW (as if fwdLen==1)
  139. returnStatus, // return current status (even if it hasn't changed)
  140. resetDataToggle;// reset data toggle state to DATA0
  141. } keyspan_usa67_portControlMessage;
  142. // defines for bits in lcr
  143. #define USA_DATABITS_5 0x00
  144. #define USA_DATABITS_6 0x01
  145. #define USA_DATABITS_7 0x02
  146. #define USA_DATABITS_8 0x03
  147. #define STOPBITS_5678_1 0x00 // 1 stop bit for all byte sizes
  148. #define STOPBITS_5_1p5 0x04 // 1.5 stop bits for 5-bit byte
  149. #define STOPBITS_678_2 0x04 // 2 stop bits for 6/7/8-bit byte
  150. #define USA_PARITY_NONE 0x00
  151. #define USA_PARITY_ODD 0x08
  152. #define USA_PARITY_EVEN 0x18
  153. #define PARITY_1 0x28
  154. #define PARITY_0 0x38
  155. // all things called "StatusMessage" are sent on the status endpoint
  156. typedef struct keyspan_usa67_portStatusMessage // one for each port
  157. {
  158. u8 port, // 0=first, 1=second, other=see below
  159. hskia_cts, // reports HSKIA pin
  160. gpia_dcd, // reports GPIA pin
  161. _txOff, // port has been disabled (by host)
  162. _txXoff, // port is in XOFF state (either host or RX XOFF)
  163. txAck, // indicates a TX message acknowledgement
  164. rxEnabled, // as configured by rxOn/rxOff 1=on, 0=off
  165. controlResponse;// 1=a control message has been processed
  166. } keyspan_usa67_portStatusMessage;
  167. // bits in RX data message when STAT byte is included
  168. #define RXERROR_OVERRUN 0x02
  169. #define RXERROR_PARITY 0x04
  170. #define RXERROR_FRAMING 0x08
  171. #define RXERROR_BREAK 0x10
  172. typedef struct keyspan_usa67_globalControlMessage
  173. {
  174. u8 port, // 3
  175. sendGlobalStatus, // 2=request for two status responses
  176. resetStatusToggle, // 1=reset global status toggle
  177. resetStatusCount; // a cycling value
  178. } keyspan_usa67_globalControlMessage;
  179. typedef struct keyspan_usa67_globalStatusMessage
  180. {
  181. u8 port, // 3
  182. sendGlobalStatus, // from request, decremented
  183. resetStatusCount; // as in request
  184. } keyspan_usa67_globalStatusMessage;
  185. typedef struct keyspan_usa67_globalDebugMessage
  186. {
  187. u8 port, // 2
  188. a,
  189. b,
  190. c,
  191. d;
  192. } keyspan_usa67_globalDebugMessage;
  193. // ie: the maximum length of an FX1 endpoint buffer
  194. #define MAX_DATA_LEN 64
  195. // update status approx. 60 times a second (16.6666 ms)
  196. #define STATUS_UPDATE_INTERVAL 16
  197. // status rationing tuning value (each port gets checked each n ms)
  198. #define STATUS_RATION 10
  199. #endif