home *** CD-ROM | disk | FTP | other *** search
/ Amiga Elysian Archive / AmigaElysianArchive.iso / prog / utils / sercli.shr / sercli / src / rcs / ser_supp.h,v < prev    next >
Encoding:
Text File  |  1993-06-16  |  12.1 KB  |  512 lines

  1. head    1.6;
  2. access;
  3. symbols
  4.     sercli_v1_10:1.6
  5.     sercli_v1_9:1.4
  6.     sercli_v1_8:1.4
  7.     sercli_v1_7:1.3
  8.     sercli_v1_6:1.2
  9.     sercli_v1_5:1.1;
  10. locks
  11.     rkr:1.6;
  12. comment    @**  @;
  13.  
  14.  
  15. 1.6
  16. date    93.06.16.23.32.41;    author rkr;    state Exp;
  17. branches;
  18. next    1.5;
  19.  
  20. 1.5
  21. date    93.06.10.16.41.21;    author rkr;    state Exp;
  22. branches;
  23. next    1.4;
  24.  
  25. 1.4
  26. date    91.12.20.09.44.01;    author rkr;    state Exp;
  27. branches;
  28. next    1.3;
  29.  
  30. 1.3
  31. date    91.12.10.02.48.28;    author rkr;    state Exp;
  32. branches;
  33. next    1.2;
  34.  
  35. 1.2
  36. date    91.12.02.10.51.45;    author rkr;    state Exp;
  37. branches;
  38. next    1.1;
  39.  
  40. 1.1
  41. date    91.11.28.08.25.27;    author rkr;    state Exp;
  42. branches;
  43. next    ;
  44.  
  45.  
  46. desc
  47. @sercli is a program to permit shell-like interface to the serial port,
  48. while also permitting easy config- and run-time-control over the way the
  49. serial port (or even _which_ serial port) is used.
  50.  
  51. @
  52.  
  53.  
  54. 1.6
  55. log
  56. @Added per-file copyright notice, as suggested by GPL.
  57. @
  58. text
  59. @/*
  60. **  $Source: WB_2.1:homes/rkr/prog/sercli/src/RCS/ser_supp.h,v $
  61. **  $Author: rkr $
  62. **  $Revision: 1.5 $
  63. **  $Locker:  $
  64. **  $State: Exp $
  65. **  $Date: 1993/06/10 16:41:21 $
  66. **
  67. **  sercli (an Amiga .device <-> FIFO interface tool)
  68. **  Copyright (C) 1993  Richard Rauch
  69. **
  70. **  See /doc/sercli.doc and /COPYING for use and distribution license.
  71. **
  72. */
  73.  
  74. #include <devices/serial.h>
  75. #include <utility/tagitem.h>
  76.  
  77. #include <lists.h>    /*** DICE specific; based on Amiga Lists ***/
  78.  
  79. #include "defs.h"
  80. #include "errors.h"
  81.  
  82. /*
  83. **  Some typedefs...
  84. **
  85. */
  86. typedef struct IOExtSer     IOExtSer;
  87. typedef struct IORequest    IORequest;
  88.  
  89.  
  90. /*
  91. **  A {struct ser_buckt_s} and a {ser_bucket_t} are synonymous.
  92. **
  93. **  A {ser_bucket_t} consisits of
  94. **    - serial i/o request struct
  95. **    - buffer size
  96. **    - buffer pointer
  97. **
  98. **    - list node
  99. **    - pointer to itself
  100. **
  101. **  The last two elements form, implicitly, a {ser_bucket_keeper_t}.
  102. **
  103. **  Serial 'buckets' are linked together through their list nodes.  Since
  104. **  they must be tracked while they are pending, and since a variable
  105. **  number of writes may be pending, they must be linked through some other
  106. **  mechanism than what we could otherwise 'borrow' from their serial i/o
  107. **  request structure.
  108. **
  109. **  Thus, two different lists exist,
  110. **    - one of pending writes   ('in use' buckets)
  111. **    - one of completed writes ('free' buckets)
  112. **
  113. **  These are are perhaps best thought of as lists of {ser_bucket_keeper_t}
  114. **  entities; when they are fetched, their corresponding {ser_bucket_t} may
  115. **  be found through their {.sbk_alter_ego}
  116. **
  117. **  (This is the _same_ pointer as found in {ser_bucket_t.b_self}).
  118. **
  119. **
  120. **  This is a relatively efficient way of handling things, albeit a little
  121. **  confusing.
  122. **
  123. **  (NOTE to self, + CLARIFICATION: Instead of keeping the {sbk_alter_ego}
  124. **  ptr, it may be preferable to subtract {offsetof (ser_bucket_t, b_link)}
  125. **  from any given (valid) {ser_bucket_keeper_t *}; this would let us
  126. **  dispense with the "superfluous" pointer, and should be more efficient.
  127. **  It may also be clearer.  This would achieve the same net effect as the
  128. **  current dereferencing through {sbk_alter_ego}.)
  129. **
  130. */
  131. typedef struct ser_bucket_s
  132. {
  133.     IOExtSer        b_ior;
  134.     ULONG        b_size;
  135.     char        *b_buf;
  136.     Node        b_link;     /*** Ooo, ick, Chief..!  BLink! ***/
  137.     struct ser_bucket_s *b_self;
  138. } ser_bucket_t;
  139.  
  140.  
  141. typedef struct
  142. {
  143.     Node        sbk_link;
  144.     ser_bucket_t    *sbk_alter_ego;
  145. } ser_bucket_keeper_t;
  146.  
  147.  
  148.  
  149. /*
  150. **  The next few chunks represent an unfulfilled plan; I've been busy with
  151. **  other stuff...  IGNORE (for now) through {serial_tag_t}
  152. **
  153. */
  154.  
  155. /*
  156. **  The following 3 new definitions represent a change of philosophy for
  157. **  the serial support: The idea endorsed is still one of
  158. **  application-friendliness, but for the sake of generality, the serial
  159. **  routines will adopt a pointer-to-structure based configuration/control
  160. **  method (a'la OpenWindow() ), and will cease calling exit() under any
  161. **  conditions.
  162. **
  163. **  The configuration, as I presently see it, is to take place using
  164. **  TagItem arrays.  This is NOT fixed in stone; I may yet decide to do
  165. **  something like:
  166. **
  167. **    typedef struct
  168. **    {
  169. **        int bps;        //  BPS desired value
  170. **        int set_bps;    //  Boolean: use {bps}, or use default
  171. **                //
  172. **        int data_bits;    //  Read/Write bits desired
  173. **        int set_data_bits;    //  Boolean: Use {data_bits}?
  174. **
  175. **        ...
  176. **
  177. **    } new_serial_t;
  178. **
  179. **  Either way, however, the main thing is that open_ser() will soon take a
  180. **  {new_serial_t *}, while all other serial functions I've written will
  181. **  take a {serial_t *}.
  182. **
  183. **
  184. **  These structures are not in use as of this writing, but should be
  185. **  before, or shortly after, I move serial.c into a seperate .lib.
  186. **
  187. **    ---rkr (4-Dec-91).
  188. **
  189. */
  190.  
  191. /*
  192. **  Like {struct NewWindow}, {new_serial_t} is a "resource request"
  193. **  description.
  194. **
  195. **  A {new_serial_t *} is to be passed to open_ser();
  196. **
  197. **  {attributes} should be maintained by the caller.  If {attributes} is
  198. **  non-NULL, the caller is to be responsible for cleaning it up; any
  199. **  serial routines that can use {attributes} may assume that {attributes}
  200. **  is meaningful (and try to use it) if you don't put NULL in there when
  201. **  not in use.
  202. **
  203. **  Note that {name, unit} may be removed at a later date, and made instead
  204. **  a part of the {attributes} list.  If they do, the {name, unit} fields
  205. **  would be preserved somewhere else, pro'ly, to keep things on an even
  206. **  keel.  However, since {name, unit} are _required_ fields by
  207. **  OpenDevice(), one might as well toss them in here.
  208. **
  209. */
  210. typedef struct
  211. {
  212.     struct TagItem *attributes;     /*** Desired attributes        ***/
  213.     ULONG num_attributes;        /*** How many in array...        ***/
  214.     char *name;             /*** E.g., "serial.device"          ***/
  215.     ULONG unit;             /*** Device unit number        ***/
  216. } new_serial_t;
  217.  
  218.  
  219. /*
  220. **  {serial_t} is analogous to {struct Window}.
  221. **
  222. **  A {serial_t *} is to be returned by open_ser(), and passed to
  223. **  close_ser().
  224. **
  225. **  The members should not be touched.
  226. **
  227. **  Exception: {new_ser} should only be touched to change the {attributes}
  228. **  for setting the serial params.
  229. **
  230. */
  231. typedef struct
  232. {
  233.     new_serial_t new_ser;        /*** Configure + name/unit number    ***/
  234.  
  235.     IOExtSer read_req;            /*** Synch. read request        ***/
  236.     IOExtSer write_req;         /*** Synch. write request        ***/
  237.     List idle_buckets;            /*** List of idle buckets        ***/
  238.     List pending_writes;        /*** List of pending write buckets    ***/
  239.     MsgPort read_reply_port;        /*** Read request reply port    ***/
  240.     MsgPort write_reply_port;        /*** Write request reply port    ***/
  241.  
  242.     int bps;                /*** Current Bits Per Second    ***/
  243.     int data_bits;            /*** Current (read|write) bits      ***/
  244.     int exclusive;            /*** Current shared/exclusive mode    ***/
  245.     int parity;             /*** Current parity (none/odd/even) ***/
  246.     int rad_boogie;            /*** Current RAD_BOOGIE mode on/off ***/
  247.     int rts_cts;            /*** Current RTS/CTS (7wire mode)   ***/
  248.     int stop_bits;            /*** Current stop bits        ***/
  249.     int xon_xoff;            /*** Current xon/xoff status    ***/
  250. } serial_t;
  251.  
  252.  
  253. /*
  254. **  The set_<symbol> tags are part of {struct TagItem} entities to be
  255. **  planted into the {new_serial_t.attributes} array.  (Not quite as
  256. **  efficient as it could be, but easily expandable...)
  257. **
  258. **  Each set_<symbol>, below, corresponds to a <symbol> in {serial_t},
  259. **  above.
  260. **
  261. **  (My understanding from reading the comments in <utility/tagitem.h> is
  262. **  that {TAG_USER} is a flag, and no valid tag should consist of just the
  263. **  TAG_USER bit w/o any other bits set.  Presumably, if this were passed
  264. **  to some system function, it would `ignore' the {TAG_USER} `qualifier'
  265. **  flag and think it had a {TAG_DONE} tag...)
  266. **
  267. */
  268. typedef enum
  269. {
  270.     set_bps = TAG_USER + 1,
  271.     set_data_bits,
  272.     set_exclusive,
  273.     set_parity,
  274.     set_rad_boogie,
  275.     set_rts_cts,
  276.     set_stop_bits,
  277.     set_xon_xoff,
  278. } serial_tag_t;
  279.  
  280.  
  281.  
  282. /*
  283. **  Some globals
  284. **
  285. **  About the {ser_bucket_list} and {ser_writes_p_list} Lists:
  286. **
  287. **  **    {ser_writes_p_list} is used so we know how many outstanding asynch
  288. **    CMD_WRITE requests we have.
  289. **
  290. **  **    {ser_bucket_list} is used to store a list of available buffers/reqs
  291. **    that have been recycled after an asynch CMD_WRITE has completed.
  292. **
  293. */
  294. extern BYTE io_error_ser;
  295.  
  296. extern IOExtSer *ser_read_req;
  297. extern IOExtSer *ser_write_req;
  298.  
  299. extern List *ser_bucket_list;
  300. extern List *ser_writes_p_list;     /*** SERial WRITES Pending LIST ***/
  301.  
  302. extern MsgPort *ser_read_reply_port;
  303. extern MsgPort *ser_write_reply_port;
  304.  
  305. extern ULONG ser_dev;            /*** flag ***/
  306. extern ULONG ser_read_reply_mask;
  307. extern ULONG ser_write_reply_mask;
  308.  
  309.  
  310. char *read_ser_line (char *buf, ULONG max_len);
  311.  
  312. IOExtSer *query_ser (void);
  313.  
  314. void clear_write_replies (void);
  315. void close_ser (void);
  316. void open_ser (void);                           /*** controlled by config ***/
  317. void read_ser_asynch (char *buf, ULONG size);
  318. void write_ser_asynch (char *buf, ULONG size);
  319.  
  320. ULONG ser_chars_pending (void);
  321. ULONG set_ser_soft (void);                      /*** controlled by config ***/
  322. ULONG synch_read_ser_req (void);
  323. ULONG synch_write_ser_req (void);
  324. ULONG write_ser (char *str, ULONG len);
  325. ULONG write_ser_str (char *str);
  326.  
  327. @
  328.  
  329.  
  330. 1.5
  331. log
  332. @Removed some redundant typedefs on Amiga OS stuff (I hate having
  333. to type `struct' everywhere...).
  334. @
  335. text
  336. @d2 1
  337. a2 1
  338. **  $Source: WB_2.1:ho/rcs/ser_supp.h,v $
  339. d4 1
  340. a4 1
  341. **  $Revision: 1.4 $
  342. d7 1
  343. a7 1
  344. **  $Date: 1991/12/20 09:44:01 $
  345. d9 5
  346. a30 10
  347. /*
  348. **  These data types are redundant...found to "defs.h"
  349. **
  350. **  typedef struct MsgPort    MsgPort;
  351. **  typedef struct Message    Message;
  352. **
  353. **  typedef struct Node     Node;
  354. **  typedef struct List     List;
  355. **
  356. */
  357. d90 6
  358. @
  359.  
  360.  
  361. 1.4
  362. log
  363. @*** empty log message ***
  364. @
  365. text
  366. @d2 1
  367. a2 1
  368. **  $Source: Workbench:personal/rkr/prog/sercli/src/rcs/ser_supp.h,v $
  369. d4 2
  370. a5 2
  371. **  $Revision: 1.3 $
  372. **  $Locker: rkr $
  373. d7 1
  374. a7 1
  375. **  $Date: 91/12/10 02:48:28 $
  376. d16 1
  377. a24 2
  378. typedef struct MsgPort        MsgPort;
  379. typedef struct Message        Message;
  380. d26 10
  381. a35 2
  382. typedef struct Node        Node;
  383. typedef struct List        List;
  384. @
  385.  
  386.  
  387. 1.3
  388. log
  389. @**  Added query_ser().
  390.  
  391. **  Added {new_serial_t, serial_t, serial_tag_t}.
  392.  
  393.  
  394. @
  395. text
  396. @d4 1
  397. a4 1
  398. **  $Revision: 1.2 $
  399. d7 1
  400. a7 1
  401. **  $Date: 91/12/02 10:51:45 $
  402. @
  403.  
  404.  
  405. 1.2
  406. log
  407. @**  Changed ser_soft_set() to set_ser_soft() (<verb>_<noun>_<modifier>).
  408.  
  409.  
  410. **  Made {ser_bucket_from_list_t} into {ser_bucket_keeper}, which is a
  411.     little more descriptive of what's going on (though not ideal).  Changed
  412.     internal structure member names accordingly.
  413.  
  414.  
  415. **  Change typedef names of Amiga OS structs (in ser_supp.h) back to names
  416.     w/o underscores.
  417.  
  418.  
  419. **  Cause the serial error-handler to do a hex-dump of the data it has been
  420.     passed...
  421. @
  422. text
  423. @d7 1
  424. a7 1
  425. **  $Date: 91/12/02 10:42:23 $
  426. d12 1
  427. d63 7
  428. d76 1
  429. a76 1
  430.     Node        b_link;     /*** no pun intended... ***/
  431. d88 65
  432. d154 6
  433. a159 1
  434. **  These are the old->new symbol names for {ser_bucket_keeper_t}.
  435. d161 2
  436. a162 1
  437. **  (DELETE THIS section, shortly.)
  438. d164 27
  439. d192 8
  440. a199 3
  441. **    ser_bucket_from_list_t    ser_bucket_keeper_t
  442. **    bfl_link        sbk_link
  443. **    bfl_alter_ego        sbk_alter_ego
  444. d202 12
  445. d245 2
  446. @
  447.  
  448.  
  449. 1.1
  450. log
  451. @Initial revision
  452. @
  453. text
  454. @d2 6
  455. a7 6
  456. **  $Source$
  457. **  $Author$
  458. **  $Revision$
  459. **  $Locker$
  460. **  $State$
  461. **  $Date$
  462. d21 3
  463. a23 3
  464. typedef struct IOExtSer     IO_Ext_Ser;
  465. typedef struct IORequest    IO_Request;
  466. typedef struct MsgPort        Msg_Port;
  467. d40 1
  468. a40 1
  469. **  The last two elements form, implicitly, a {ser_bucket_from_list_t}.
  470. d44 3
  471. a46 3
  472. **  number of writes may be pending, they must be linked through some
  473. **  other mechanism than what we could otherwise 'borrow' from their serial
  474. **  i/o request structure.
  475. d52 3
  476. a54 4
  477. **  These are are perhaps best thought of as lists of
  478. **  {ser_bucket_from_list_t} entities; when they are fetched, their
  479. **  corresponding {ser_bucket_t} may be found through their
  480. **  {.bfl_alter_ego}
  481. d65 1
  482. a65 1
  483.     IO_Ext_Ser        b_ior;
  484. d75 3
  485. a77 3
  486.     Node        bfl_link;
  487.     ser_bucket_t    *bfl_alter_ego;
  488. } ser_bucket_from_list_t;
  489. d80 11
  490. d92 1
  491. d98 2
  492. a99 3
  493. **    **  {ser_writes_p_list} is used so we know how many outstanding
  494. **        asynch CMD_WRITE requests we have.
  495. **
  496. d101 2
  497. a102 2
  498. **    **  {ser_bucket_list} is used to store a list of available buffers
  499. **        that are recycled when an asynch CMD_WRITE completes.
  500. d107 2
  501. a108 2
  502. extern IO_Ext_Ser *ser_read_req;
  503. extern IO_Ext_Ser *ser_write_req;
  504. d113 2
  505. a114 2
  506. extern Msg_Port *ser_read_reply_port;
  507. extern Msg_Port *ser_write_reply_port;
  508. d130 1
  509. a130 1
  510. ULONG ser_soft_set (void);                      /*** controlled by config ***/
  511. @
  512.