home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff220.lzh / DNet / include / local / dio.h < prev    next >
C/C++ Source or Header  |  1989-06-04  |  5KB  |  127 lines

  1.  
  2. /*
  3.  * DIO.H
  4.  *
  5.  *  (C)Copyright 1987 Matthew Dillon, All Rights Reserved
  6.  *  Freely distributable.  Donations welcome, I guess.
  7.  *
  8.  *    Matthew Dillon
  9.  *    891 Regal Rd.
  10.  *    Berkeley, Ca.    94708
  11.  *
  12.  */
  13.  
  14. #ifndef LOCAL_DIO_H
  15. #define LOCAL_DIO_H
  16. #include <exec/types.h>
  17. #include <exec/io.h>
  18. #include <exec/memory.h>
  19. #include <exec/ports.h>
  20. #include <devices/timer.h>
  21. #ifndef LOCAL_TYPEDEFS_H
  22. #include <local/typedefs.h>
  23. #endif
  24.  
  25. typedef struct IORequest IOR;
  26. typedef struct IOStdReq  STD;
  27.  
  28. /*
  29.  *    'to' is in microsections.  The IO request structure
  30.  *  pointer is optional to dio_open().  If NULL, dio_open()
  31.  *  initializes it's own IO request (to mostly zero).  You have
  32.  *  to provide an IO request structure, for instance, if openning
  33.  *  a console device since the window pointer must be passed to
  34.  *  OpenDevice().
  35.  *
  36.  *    each DFD descriptor has it's own signal.
  37.  *
  38.  *    dio_isdone() returns 1 if the channel is clear, 0 otherwise.
  39.  */
  40.  
  41. extern long dio_open();         /* dfd    = dio_open(devname,unit,flags,req)*/
  42. extern long dio_dup();          /* newdfd = dio_dup(dfd)    */
  43. extern STD *dio_ctl();          /* req  = dio_ctl(dfd,com,buf,len)          */
  44. extern STD *dio_ctl_to();       /* req  = dio_ctl_to(dfd,com,buf,len,to)    */
  45. extern STD *dio_wait();         /* req  = dio_wait(dfd)     */
  46. extern STD *dio_abort();        /* req  = dio_abort(dfd)    */
  47. extern STD *dio_isdone();       /* req  = dio_isdone(dfd)   */
  48. extern int dio_signal();        /* signm= dio_signal(dfd)   */
  49. extern void dio_close();        /*  dio_close(dfd)          */
  50. extern void dio_cloesgroup();   /*  dio_closegroup(dfd)     */
  51. extern void dio_cact();         /*  dio_cact(dfd,bool)      */
  52.  
  53.  
  54.  
  55. /*
  56.  * dio_simple() and related macros return the !io_Error field. That
  57.  * is, 0=ERROR, 1=OK
  58.  *
  59.  * dio_actual() returns the io_Actual field.
  60.  *
  61.  * NOTE: the io_Actual field may not be set by the device if an
  62.  * error condition exists.  To make the io_ctl() and io_ctl_to()
  63.  * call automatically clear the io_Actual field before doing the
  64.  * io operation, use the DIO_CACT() call.  The reason this isn't
  65.  * done automatically by default is that some devices require
  66.  * parameters to be passed in the io_Actual field (like the
  67.  * timer.device).
  68.  *
  69.  *  Remember, Asyncronous IO is done by sending -com instead of com.
  70.  *
  71.  *    CALL                Syncronous IO   Asyncronous IO
  72.  *
  73.  *  dio_simple(dfd,com)             0=ERROR, 1=OK   undefined
  74.  *  dio_actual(dfd,com)             io_Actual       undefined
  75.  *  dio_reset(dfd)                  0=ERROR, 1=OK   n/a
  76.  *  dio_update(dfd)                 0=ERROR, 1=OK   n/a
  77.  *  dio_clear(dfd)                  0=ERROR, 1=OK   n/a
  78.  *  dio_stop(dfd)                   0=ERROR, 1=OK   n/a
  79.  *  dio_start(dfd)                  0=ERROR, 1=OK   n/a
  80.  *  dio_flush(dfd)                  0=ERROR, 1=OK   n/a
  81.  *  dio_getreq(dfd)                 returns a ptr to the IO
  82.  *                    request structure
  83.  *  NOTE: If you use the following, you probably want to have the
  84.  *  device library automatically clear the io_Actual field before
  85.  *  sending the request so you get 0 if an error occurs.  That
  86.  *  is: dio_cact(dfd,1);
  87.  *
  88.  *
  89.  *  dio_read(dfd,buf,len)           returns actual bytes read
  90.  *  dio_write(dfd,buf,len)          returns actual bytes written
  91.  *
  92.  *    The timeout argument for dio_readto() and dio_writeto()
  93.  *    is in MICROSECONDS, up to 2^31uS.
  94.  *
  95.  *  dio_readto(dfd,buf,len,to)      returns actual bytes read
  96.  *  dio_writeto(dfd,buf,len,to)     returns actual bytes written
  97.  *
  98.  *    The asyncronous dio_reada() and dio_writea() do not
  99.  *    return anything.
  100.  *
  101.  *  dio_reada(dfd,buf,len)          begin asyncronous read
  102.  *  dio_writea(dfd,buf,len)         begin asyncronous write
  103.  */
  104.  
  105. #define dio_mask(dfd)           (1 << dio_signal(dfd))
  106.  
  107. #define dio_simple(dfd,com)     (!dio_ctl(dfd,com,0,0)->io_Error)
  108. #define dio_actual(dfd,com)     ( dio_ctl(dfd,com,0,0)->io_Actual)
  109. #define dio_reset(dfd)          dio_simple(dfd,CMD_RESET)
  110. #define dio_update(dfd)         dio_simple(dfd,CMD_UPDATE)
  111. #define dio_clear(dfd)          dio_simple(dfd,CMD_CLEAR)
  112. #define dio_stop(dfd)           dio_simple(dfd,CMD_STOP)
  113. #define dio_start(dfd)          dio_simple(dfd,CMD_START)
  114. #define dio_flush(dfd)          dio_simple(dfd,CMD_FLUSH)
  115. #define dio_getreq(dfd)         dio_ctl(dfd,0,0,0)
  116.  
  117. #define dio_read(dfd,buf,len)       (dio_ctl(dfd,CMD_READ,buf,len)->io_Actual)
  118. #define dio_write(dfd,buf,len)      (dio_ctl(dfd,CMD_WRITE,buf,len)->io_Actual)
  119. #define dio_readto(dfd,buf,len,to)  (dio_ctl_to(dfd,CMD_READ,buf,len,to)->io_Actual)
  120. #define dio_writeto(dfd,buf,len,to) (dio_ctl_to(dfd,CMD_WRITE,buf,len,to)->io_Actual)
  121. #define dio_reada(dfd,buf,len)      ((void)dio_ctl(dfd,-CMD_READ,buf,len))
  122. #define dio_writea(dfd,buf,len)     ((void)dio_ctl(dfd,-CMD_WRITE,buf,len))
  123.  
  124. #endif
  125.  
  126.  
  127.