i2pack.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. /*******************************************************************************
  2. *
  3. * (c) 1998 by Computone Corporation
  4. *
  5. ********************************************************************************
  6. *
  7. *
  8. * PACKAGE: Linux tty Device Driver for IntelliPort II family of multiport
  9. * serial I/O controllers.
  10. *
  11. * DESCRIPTION: Definitions of the packets used to transfer data and commands
  12. * Host <--> Board. Information provided here is only applicable
  13. * when the standard loadware is active.
  14. *
  15. *******************************************************************************/
  16. #ifndef I2PACK_H
  17. #define I2PACK_H 1
  18. //-----------------------------------------------
  19. // Revision History:
  20. //
  21. // 10 October 1991 MAG First draft
  22. // 24 February 1992 MAG Additions for 1.4.x loadware
  23. // 11 March 1992 MAG New status packets
  24. //
  25. //-----------------------------------------------
  26. //------------------------------------------------------------------------------
  27. // Packet Formats:
  28. //
  29. // Information passes between the host and board through the FIFO in packets.
  30. // These have headers which indicate the type of packet. Because the fifo data
  31. // path may be 16-bits wide, the protocol is constrained such that each packet
  32. // is always padded to an even byte count. (The lower-level interface routines
  33. // -- i2ellis.c -- are designed to do this).
  34. //
  35. // The sender (be it host or board) must place some number of complete packets
  36. // in the fifo, then place a message in the mailbox that packets are available.
  37. // Placing such a message interrupts the "receiver" (be it board or host), who
  38. // reads the mailbox message and determines that there are incoming packets
  39. // ready. Since there are no partial packets, and the length of a packet is
  40. // given in the header, the remainder of the packet can be read without checking
  41. // for FIFO empty condition. The process is repeated, packet by packet, until
  42. // the incoming FIFO is empty. Then the receiver uses the outbound mailbox to
  43. // signal the board that it has read the data. Only then can the sender place
  44. // additional data in the fifo.
  45. //------------------------------------------------------------------------------
  46. //
  47. //------------------------------------------------
  48. // Definition of Packet Header Area
  49. //------------------------------------------------
  50. //
  51. // Caution: these only define header areas. In actual use the data runs off
  52. // beyond the end of these structures.
  53. //
  54. // Since these structures are based on sequences of bytes which go to the board,
  55. // there cannot be ANY padding between the elements.
  56. #pragma pack(1)
  57. //----------------------------
  58. // DATA PACKETS
  59. //----------------------------
  60. typedef struct _i2DataHeader
  61. {
  62. unsigned char i2sChannel; /* The channel number: 0-255 */
  63. // -- Bitfields are allocated LSB first --
  64. // For incoming data, indicates whether this is an ordinary packet or a
  65. // special one (e.g., hot key hit).
  66. unsigned i2sId : 2 __attribute__ ((__packed__));
  67. // For tagging data packets. There are flush commands which flush only data
  68. // packets bearing a particular tag. (used in implementing IntelliView and
  69. // IntelliPrint). THE TAG VALUE 0xf is RESERVED and must not be used (it has
  70. // meaning internally to the loadware).
  71. unsigned i2sTag : 4;
  72. // These two bits determine the type of packet sent/received.
  73. unsigned i2sType : 2;
  74. // The count of data to follow: does not include the possible additional
  75. // padding byte. MAXIMUM COUNT: 4094. The top four bits must be 0.
  76. unsigned short i2sCount;
  77. } i2DataHeader, *i2DataHeaderPtr;
  78. // Structure is immediately followed by the data, proper.
  79. //----------------------------
  80. // NON-DATA PACKETS
  81. //----------------------------
  82. typedef struct _i2CmdHeader
  83. {
  84. unsigned char i2sChannel; // The channel number: 0-255 (Except where noted
  85. // - see below
  86. // Number of bytes of commands, status or whatever to follow
  87. unsigned i2sCount : 6;
  88. // These two bits determine the type of packet sent/received.
  89. unsigned i2sType : 2;
  90. } i2CmdHeader, *i2CmdHeaderPtr;
  91. // Structure is immediately followed by the applicable data.
  92. //---------------------------------------
  93. // Flow Control Packets (Outbound)
  94. //---------------------------------------
  95. // One type of outbound command packet is so important that the entire structure
  96. // is explicitly defined here. That is the flow-control packet. This is never
  97. // sent by user-level code (as would be the commands to raise/lower DTR, for
  98. // example). These are only sent by the library routines in response to reading
  99. // incoming data into the buffers.
  100. //
  101. // The parameters inside the command block are maintained in place, then the
  102. // block is sent at the appropriate time.
  103. typedef struct _flowIn
  104. {
  105. i2CmdHeader hd; // Channel #, count, type (see above)
  106. unsigned char fcmd; // The flow control command (37)
  107. unsigned short asof; // As of byte number "asof" (LSB first!) I have room
  108. // for "room" bytes
  109. unsigned short room;
  110. } flowIn, *flowInPtr;
  111. //----------------------------------------
  112. // (Incoming) Status Packets
  113. //----------------------------------------
  114. // Incoming packets which are non-data packets are status packets. In this case,
  115. // the channel number in the header is unimportant. What follows are one or more
  116. // sub-packets, the first word of which consists of the channel (first or low
  117. // byte) and the status indicator (second or high byte), followed by possibly
  118. // more data.
  119. #define STAT_CTS_UP 0 /* CTS raised (no other bytes) */
  120. #define STAT_CTS_DN 1 /* CTS dropped (no other bytes) */
  121. #define STAT_DCD_UP 2 /* DCD raised (no other bytes) */
  122. #define STAT_DCD_DN 3 /* DCD dropped (no other bytes) */
  123. #define STAT_DSR_UP 4 /* DSR raised (no other bytes) */
  124. #define STAT_DSR_DN 5 /* DSR dropped (no other bytes) */
  125. #define STAT_RI_UP 6 /* RI raised (no other bytes) */
  126. #define STAT_RI_DN 7 /* RI dropped (no other bytes) */
  127. #define STAT_BRK_DET 8 /* BRK detect (no other bytes) */
  128. #define STAT_FLOW 9 /* Flow control(-- more: see below */
  129. #define STAT_BMARK 10 /* Bookmark (no other bytes)
  130. * Bookmark is sent as a response to
  131. * a command 60: request for bookmark
  132. */
  133. #define STAT_STATUS 11 /* Special packet: see below */
  134. #define STAT_TXCNT 12 /* Special packet: see below */
  135. #define STAT_RXCNT 13 /* Special packet: see below */
  136. #define STAT_BOXIDS 14 /* Special packet: see below */
  137. #define STAT_HWFAIL 15 /* Special packet: see below */
  138. #define STAT_MOD_ERROR 0xc0
  139. #define STAT_MODEM 0xc0/* If status & STAT_MOD_ERROR:
  140. * == STAT_MODEM, then this is a modem
  141. * status packet, given in response to a
  142. * CMD_DSS_NOW command.
  143. * The low nibble has each data signal:
  144. */
  145. #define STAT_MOD_DCD 0x8
  146. #define STAT_MOD_RI 0x4
  147. #define STAT_MOD_DSR 0x2
  148. #define STAT_MOD_CTS 0x1
  149. #define STAT_ERROR 0x80/* If status & STAT_MOD_ERROR
  150. * == STAT_ERROR, then
  151. * sort of error on the channel.
  152. * The remaining seven bits indicate
  153. * what sort of error it is.
  154. */
  155. /* The low three bits indicate parity, framing, or overrun errors */
  156. #define STAT_E_PARITY 4 /* Parity error */
  157. #define STAT_E_FRAMING 2 /* Framing error */
  158. #define STAT_E_OVERRUN 1 /* (uxart) overrun error */
  159. //---------------------------------------
  160. // STAT_FLOW packets
  161. //---------------------------------------
  162. typedef struct _flowStat
  163. {
  164. unsigned short asof;
  165. unsigned short room;
  166. }flowStat, *flowStatPtr;
  167. // flowStat packets are received from the board to regulate the flow of outgoing
  168. // data. A local copy of this structure is also kept to track the amount of
  169. // credits used and credits remaining. "room" is the amount of space in the
  170. // board's buffers, "as of" having received a certain byte number. When sending
  171. // data to the fifo, you must calculate how much buffer space your packet will
  172. // use. Add this to the current "asof" and subtract it from the current "room".
  173. //
  174. // The calculation for the board's buffer is given by CREDIT_USAGE, where size
  175. // is the un-rounded count of either data characters or command characters.
  176. // (Which is to say, the count rounded up, plus two).
  177. #define CREDIT_USAGE(size) (((size) + 3) & ~1)
  178. //---------------------------------------
  179. // STAT_STATUS packets
  180. //---------------------------------------
  181. typedef struct _debugStat
  182. {
  183. unsigned char d_ccsr;
  184. unsigned char d_txinh;
  185. unsigned char d_stat1;
  186. unsigned char d_stat2;
  187. } debugStat, *debugStatPtr;
  188. // debugStat packets are sent to the host in response to a CMD_GET_STATUS
  189. // command. Each byte is bit-mapped as described below:
  190. #define D_CCSR_XON 2 /* Has received XON, ready to transmit */
  191. #define D_CCSR_XOFF 4 /* Has received XOFF, not transmitting */
  192. #define D_CCSR_TXENAB 8 /* Transmitter is enabled */
  193. #define D_CCSR_RXENAB 0x80 /* Receiver is enabled */
  194. #define D_TXINH_BREAK 1 /* We are sending a break */
  195. #define D_TXINH_EMPTY 2 /* No data to send */
  196. #define D_TXINH_SUSP 4 /* Output suspended via command 57 */
  197. #define D_TXINH_CMD 8 /* We are processing an in-line command */
  198. #define D_TXINH_LCD 0x10 /* LCD diagnostics are running */
  199. #define D_TXINH_PAUSE 0x20 /* We are processing a PAUSE command */
  200. #define D_TXINH_DCD 0x40 /* DCD is low, preventing transmission */
  201. #define D_TXINH_DSR 0x80 /* DSR is low, preventing transmission */
  202. #define D_STAT1_TXEN 1 /* Transmit INTERRUPTS enabled */
  203. #define D_STAT1_RXEN 2 /* Receiver INTERRUPTS enabled */
  204. #define D_STAT1_MDEN 4 /* Modem (data set sigs) interrupts enabled */
  205. #define D_STAT1_RLM 8 /* Remote loopback mode selected */
  206. #define D_STAT1_LLM 0x10 /* Local internal loopback mode selected */
  207. #define D_STAT1_CTS 0x20 /* CTS is low, preventing transmission */
  208. #define D_STAT1_DTR 0x40 /* DTR is low, to stop remote transmission */
  209. #define D_STAT1_RTS 0x80 /* RTS is low, to stop remote transmission */
  210. #define D_STAT2_TXMT 1 /* Transmit buffers are all empty */
  211. #define D_STAT2_RXMT 2 /* Receive buffers are all empty */
  212. #define D_STAT2_RXINH 4 /* Loadware has tried to inhibit remote
  213. * transmission: dropped DTR, sent XOFF,
  214. * whatever...
  215. */
  216. #define D_STAT2_RXFLO 8 /* Loadware can send no more data to host
  217. * until it receives a flow-control packet
  218. */
  219. //-----------------------------------------
  220. // STAT_TXCNT and STAT_RXCNT packets
  221. //----------------------------------------
  222. typedef struct _cntStat
  223. {
  224. unsigned short cs_time; // (Assumes host is little-endian!)
  225. unsigned short cs_count;
  226. } cntStat, *cntStatPtr;
  227. // These packets are sent in response to a CMD_GET_RXCNT or a CMD_GET_TXCNT
  228. // bypass command. cs_time is a running 1 Millisecond counter which acts as a
  229. // time stamp. cs_count is a running counter of data sent or received from the
  230. // uxarts. (Not including data added by the chip itself, as with CRLF
  231. // processing).
  232. //------------------------------------------
  233. // STAT_HWFAIL packets
  234. //------------------------------------------
  235. typedef struct _failStat
  236. {
  237. unsigned char fs_written;
  238. unsigned char fs_read;
  239. unsigned short fs_address;
  240. } failStat, *failStatPtr;
  241. // This packet is sent whenever the on-board diagnostic process detects an
  242. // error. At startup, this process is dormant. The host can wake it up by
  243. // issuing the bypass command CMD_HW_TEST. The process runs at low priority and
  244. // performs continuous hardware verification; writing data to certain on-board
  245. // registers, reading it back, and comparing. If it detects an error, this
  246. // packet is sent to the host, and the process goes dormant again until the host
  247. // sends another CMD_HW_TEST. It then continues with the next register to be
  248. // tested.
  249. //------------------------------------------------------------------------------
  250. // Macros to deal with the headers more easily! Note that these are defined so
  251. // they may be used as "left" as well as "right" expressions.
  252. //------------------------------------------------------------------------------
  253. // Given a pointer to the packet, reference the channel number
  254. //
  255. #define CHANNEL_OF(pP) ((i2DataHeaderPtr)(pP))->i2sChannel
  256. // Given a pointer to the packet, reference the Packet type
  257. //
  258. #define PTYPE_OF(pP) ((i2DataHeaderPtr)(pP))->i2sType
  259. // The possible types of packets
  260. //
  261. #define PTYPE_DATA 0 /* Host <--> Board */
  262. #define PTYPE_BYPASS 1 /* Host ---> Board */
  263. #define PTYPE_INLINE 2 /* Host ---> Board */
  264. #define PTYPE_STATUS 2 /* Host <--- Board */
  265. // Given a pointer to a Data packet, reference the Tag
  266. //
  267. #define TAG_OF(pP) ((i2DataHeaderPtr)(pP))->i2sTag
  268. // Given a pointer to a Data packet, reference the data i.d.
  269. //
  270. #define ID_OF(pP) ((i2DataHeaderPtr)(pP))->i2sId
  271. // The possible types of ID's
  272. //
  273. #define ID_ORDINARY_DATA 0
  274. #define ID_HOT_KEY 1
  275. // Given a pointer to a Data packet, reference the count
  276. //
  277. #define DATA_COUNT_OF(pP) ((i2DataHeaderPtr)(pP))->i2sCount
  278. // Given a pointer to a Data packet, reference the beginning of data
  279. //
  280. #define DATA_OF(pP) &((unsigned char *)(pP))[4] // 4 = size of header
  281. // Given a pointer to a Non-Data packet, reference the count
  282. //
  283. #define CMD_COUNT_OF(pP) ((i2CmdHeaderPtr)(pP))->i2sCount
  284. #define MAX_CMD_PACK_SIZE 62 // Maximum size of such a count
  285. // Given a pointer to a Non-Data packet, reference the beginning of data
  286. //
  287. #define CMD_OF(pP) &((unsigned char *)(pP))[2] // 2 = size of header
  288. //--------------------------------
  289. // MailBox Bits:
  290. //--------------------------------
  291. //--------------------------
  292. // Outgoing (host to board)
  293. //--------------------------
  294. //
  295. #define MB_OUT_STUFFED 0x80 // Host has placed output in fifo
  296. #define MB_IN_STRIPPED 0x40 // Host has read in all input from fifo
  297. //--------------------------
  298. // Incoming (board to host)
  299. //--------------------------
  300. //
  301. #define MB_IN_STUFFED 0x80 // Board has placed input in fifo
  302. #define MB_OUT_STRIPPED 0x40 // Board has read all output from fifo
  303. #define MB_FATAL_ERROR 0x20 // Board has encountered a fatal error
  304. #pragma pack() // Reset padding to command-line default
  305. #endif // I2PACK_H