home *** CD-ROM | disk | FTP | other *** search
/ Amiga Elysian Archive / AmigaElysianArchive.iso / prog / utils / sercli.shr / sercli / src / ser_supp.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-16  |  8.0 KB  |  269 lines

  1. /*
  2. **  $Source: WB_2.1:homes/rkr/prog/sercli/src/RCS/ser_supp.h,v $
  3. **  $Author: rkr $
  4. **  $Revision: 1.6 $
  5. **  $Locker: rkr $
  6. **  $State: Exp $
  7. **  $Date: 1993/06/16 23:32:41 $
  8. **
  9. **  sercli (an Amiga .device <-> FIFO interface tool)
  10. **  Copyright (C) 1993  Richard Rauch
  11. **
  12. **  See /doc/sercli.doc and /COPYING for use and distribution license.
  13. **
  14. */
  15.  
  16. #include <devices/serial.h>
  17. #include <utility/tagitem.h>
  18.  
  19. #include <lists.h>    /*** DICE specific; based on Amiga Lists ***/
  20.  
  21. #include "defs.h"
  22. #include "errors.h"
  23.  
  24. /*
  25. **  Some typedefs...
  26. **
  27. */
  28. typedef struct IOExtSer     IOExtSer;
  29. typedef struct IORequest    IORequest;
  30.  
  31.  
  32. /*
  33. **  A {struct ser_buckt_s} and a {ser_bucket_t} are synonymous.
  34. **
  35. **  A {ser_bucket_t} consisits of
  36. **    - serial i/o request struct
  37. **    - buffer size
  38. **    - buffer pointer
  39. **
  40. **    - list node
  41. **    - pointer to itself
  42. **
  43. **  The last two elements form, implicitly, a {ser_bucket_keeper_t}.
  44. **
  45. **  Serial 'buckets' are linked together through their list nodes.  Since
  46. **  they must be tracked while they are pending, and since a variable
  47. **  number of writes may be pending, they must be linked through some other
  48. **  mechanism than what we could otherwise 'borrow' from their serial i/o
  49. **  request structure.
  50. **
  51. **  Thus, two different lists exist,
  52. **    - one of pending writes   ('in use' buckets)
  53. **    - one of completed writes ('free' buckets)
  54. **
  55. **  These are are perhaps best thought of as lists of {ser_bucket_keeper_t}
  56. **  entities; when they are fetched, their corresponding {ser_bucket_t} may
  57. **  be found through their {.sbk_alter_ego}
  58. **
  59. **  (This is the _same_ pointer as found in {ser_bucket_t.b_self}).
  60. **
  61. **
  62. **  This is a relatively efficient way of handling things, albeit a little
  63. **  confusing.
  64. **
  65. **  (NOTE to self, + CLARIFICATION: Instead of keeping the {sbk_alter_ego}
  66. **  ptr, it may be preferable to subtract {offsetof (ser_bucket_t, b_link)}
  67. **  from any given (valid) {ser_bucket_keeper_t *}; this would let us
  68. **  dispense with the "superfluous" pointer, and should be more efficient.
  69. **  It may also be clearer.  This would achieve the same net effect as the
  70. **  current dereferencing through {sbk_alter_ego}.)
  71. **
  72. */
  73. typedef struct ser_bucket_s
  74. {
  75.     IOExtSer        b_ior;
  76.     ULONG        b_size;
  77.     char        *b_buf;
  78.     Node        b_link;     /*** Ooo, ick, Chief..!  BLink! ***/
  79.     struct ser_bucket_s *b_self;
  80. } ser_bucket_t;
  81.  
  82.  
  83. typedef struct
  84. {
  85.     Node        sbk_link;
  86.     ser_bucket_t    *sbk_alter_ego;
  87. } ser_bucket_keeper_t;
  88.  
  89.  
  90.  
  91. /*
  92. **  The next few chunks represent an unfulfilled plan; I've been busy with
  93. **  other stuff...  IGNORE (for now) through {serial_tag_t}
  94. **
  95. */
  96.  
  97. /*
  98. **  The following 3 new definitions represent a change of philosophy for
  99. **  the serial support: The idea endorsed is still one of
  100. **  application-friendliness, but for the sake of generality, the serial
  101. **  routines will adopt a pointer-to-structure based configuration/control
  102. **  method (a'la OpenWindow() ), and will cease calling exit() under any
  103. **  conditions.
  104. **
  105. **  The configuration, as I presently see it, is to take place using
  106. **  TagItem arrays.  This is NOT fixed in stone; I may yet decide to do
  107. **  something like:
  108. **
  109. **    typedef struct
  110. **    {
  111. **        int bps;        //  BPS desired value
  112. **        int set_bps;    //  Boolean: use {bps}, or use default
  113. **                //
  114. **        int data_bits;    //  Read/Write bits desired
  115. **        int set_data_bits;    //  Boolean: Use {data_bits}?
  116. **
  117. **        ...
  118. **
  119. **    } new_serial_t;
  120. **
  121. **  Either way, however, the main thing is that open_ser() will soon take a
  122. **  {new_serial_t *}, while all other serial functions I've written will
  123. **  take a {serial_t *}.
  124. **
  125. **
  126. **  These structures are not in use as of this writing, but should be
  127. **  before, or shortly after, I move serial.c into a seperate .lib.
  128. **
  129. **    ---rkr (4-Dec-91).
  130. **
  131. */
  132.  
  133. /*
  134. **  Like {struct NewWindow}, {new_serial_t} is a "resource request"
  135. **  description.
  136. **
  137. **  A {new_serial_t *} is to be passed to open_ser();
  138. **
  139. **  {attributes} should be maintained by the caller.  If {attributes} is
  140. **  non-NULL, the caller is to be responsible for cleaning it up; any
  141. **  serial routines that can use {attributes} may assume that {attributes}
  142. **  is meaningful (and try to use it) if you don't put NULL in there when
  143. **  not in use.
  144. **
  145. **  Note that {name, unit} may be removed at a later date, and made instead
  146. **  a part of the {attributes} list.  If they do, the {name, unit} fields
  147. **  would be preserved somewhere else, pro'ly, to keep things on an even
  148. **  keel.  However, since {name, unit} are _required_ fields by
  149. **  OpenDevice(), one might as well toss them in here.
  150. **
  151. */
  152. typedef struct
  153. {
  154.     struct TagItem *attributes;     /*** Desired attributes        ***/
  155.     ULONG num_attributes;        /*** How many in array...        ***/
  156.     char *name;             /*** E.g., "serial.device"          ***/
  157.     ULONG unit;             /*** Device unit number        ***/
  158. } new_serial_t;
  159.  
  160.  
  161. /*
  162. **  {serial_t} is analogous to {struct Window}.
  163. **
  164. **  A {serial_t *} is to be returned by open_ser(), and passed to
  165. **  close_ser().
  166. **
  167. **  The members should not be touched.
  168. **
  169. **  Exception: {new_ser} should only be touched to change the {attributes}
  170. **  for setting the serial params.
  171. **
  172. */
  173. typedef struct
  174. {
  175.     new_serial_t new_ser;        /*** Configure + name/unit number    ***/
  176.  
  177.     IOExtSer read_req;            /*** Synch. read request        ***/
  178.     IOExtSer write_req;         /*** Synch. write request        ***/
  179.     List idle_buckets;            /*** List of idle buckets        ***/
  180.     List pending_writes;        /*** List of pending write buckets    ***/
  181.     MsgPort read_reply_port;        /*** Read request reply port    ***/
  182.     MsgPort write_reply_port;        /*** Write request reply port    ***/
  183.  
  184.     int bps;                /*** Current Bits Per Second    ***/
  185.     int data_bits;            /*** Current (read|write) bits      ***/
  186.     int exclusive;            /*** Current shared/exclusive mode    ***/
  187.     int parity;             /*** Current parity (none/odd/even) ***/
  188.     int rad_boogie;            /*** Current RAD_BOOGIE mode on/off ***/
  189.     int rts_cts;            /*** Current RTS/CTS (7wire mode)   ***/
  190.     int stop_bits;            /*** Current stop bits        ***/
  191.     int xon_xoff;            /*** Current xon/xoff status    ***/
  192. } serial_t;
  193.  
  194.  
  195. /*
  196. **  The set_<symbol> tags are part of {struct TagItem} entities to be
  197. **  planted into the {new_serial_t.attributes} array.  (Not quite as
  198. **  efficient as it could be, but easily expandable...)
  199. **
  200. **  Each set_<symbol>, below, corresponds to a <symbol> in {serial_t},
  201. **  above.
  202. **
  203. **  (My understanding from reading the comments in <utility/tagitem.h> is
  204. **  that {TAG_USER} is a flag, and no valid tag should consist of just the
  205. **  TAG_USER bit w/o any other bits set.  Presumably, if this were passed
  206. **  to some system function, it would `ignore' the {TAG_USER} `qualifier'
  207. **  flag and think it had a {TAG_DONE} tag...)
  208. **
  209. */
  210. typedef enum
  211. {
  212.     set_bps = TAG_USER + 1,
  213.     set_data_bits,
  214.     set_exclusive,
  215.     set_parity,
  216.     set_rad_boogie,
  217.     set_rts_cts,
  218.     set_stop_bits,
  219.     set_xon_xoff,
  220. } serial_tag_t;
  221.  
  222.  
  223.  
  224. /*
  225. **  Some globals
  226. **
  227. **  About the {ser_bucket_list} and {ser_writes_p_list} Lists:
  228. **
  229. **  **    {ser_writes_p_list} is used so we know how many outstanding asynch
  230. **    CMD_WRITE requests we have.
  231. **
  232. **  **    {ser_bucket_list} is used to store a list of available buffers/reqs
  233. **    that have been recycled after an asynch CMD_WRITE has completed.
  234. **
  235. */
  236. extern BYTE io_error_ser;
  237.  
  238. extern IOExtSer *ser_read_req;
  239. extern IOExtSer *ser_write_req;
  240.  
  241. extern List *ser_bucket_list;
  242. extern List *ser_writes_p_list;     /*** SERial WRITES Pending LIST ***/
  243.  
  244. extern MsgPort *ser_read_reply_port;
  245. extern MsgPort *ser_write_reply_port;
  246.  
  247. extern ULONG ser_dev;            /*** flag ***/
  248. extern ULONG ser_read_reply_mask;
  249. extern ULONG ser_write_reply_mask;
  250.  
  251.  
  252. char *read_ser_line (char *buf, ULONG max_len);
  253.  
  254. IOExtSer *query_ser (void);
  255.  
  256. void clear_write_replies (void);
  257. void close_ser (void);
  258. void open_ser (void);                           /*** controlled by config ***/
  259. void read_ser_asynch (char *buf, ULONG size);
  260. void write_ser_asynch (char *buf, ULONG size);
  261.  
  262. ULONG ser_chars_pending (void);
  263. ULONG set_ser_soft (void);                      /*** controlled by config ***/
  264. ULONG synch_read_ser_req (void);
  265. ULONG synch_write_ser_req (void);
  266. ULONG write_ser (char *str, ULONG len);
  267. ULONG write_ser_str (char *str);
  268.  
  269.