home *** CD-ROM | disk | FTP | other *** search
/ ftp.ee.lbl.gov / 2014.05.ftp.ee.lbl.gov.tar / ftp.ee.lbl.gov / bmd-1.0beta.tar.Z / bmd-1.0beta.tar / bmd-1.0beta / sundev / bmdvar.h < prev    next >
C/C++ Source or Header  |  1991-08-27  |  4KB  |  125 lines

  1. /*
  2.  * Copyright (c) 1991 Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms are permitted
  6.  * provided that the above copyright notice and this paragraph are
  7.  * duplicated in all such forms and that any documentation,
  8.  * advertising materials, and other materials related to such
  9.  * distribution and use acknowledge that the software was developed
  10.  * by the University of California, Lawrence Berkeley Laboratory,
  11.  * Berkeley, CA.  The name of the University may not be used to
  12.  * endorse or promote products derived from this software without
  13.  * specific prior written permission.
  14.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  15.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  16.  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  17.  */
  18.  
  19. /*
  20.  * A midi-data-queue (mdq) holds a single midi message which will be
  21.  * output atomically.  On the write side, we link together messages
  22.  * with identical timestamps using the mq_tail field (this is so we
  23.  * can transfer potentially large chains of messages from the midi
  24.  * driver to the serial driver in a single operation, necessary to
  25.  * shorten this high ipl lock-out).  The invariant for this field is
  26.  * that the head of a group points to the tail; all others are undefined.
  27.  * In essence, we have a queue of queues.
  28.  */
  29. struct mdq {
  30.     struct mdq *mq_next;
  31.     struct mdq *mq_tail;
  32.     short mq_qlen;
  33.     short mq_len;
  34.     u_char *mq_cp;
  35.     u_long mq_time;
  36.     u_char mq_data[BMD_MAXMSGLEN];
  37. };
  38.  
  39. /*
  40.  * Below is the per interface structure.  Sparcs have two usable serial 
  41.  * ports (A and B), reflected in NPORTS.
  42.  *
  43.  * Since data to be output is timestamped, consecutive writes can cause
  44.  * interspersed midi messages and alter their meaning (i.e., midi streams
  45.  * have a running state).  Outbound midi messages must be atomic.  Hence,
  46.  * entire midi messages are stored in a single struct. 
  47.  *
  48.  * There are three levels of interrupts.  The midi clock comes in at level 14,
  49.  * which locks at just about everything (including hardclock).  The zs chip
  50.  * interrupts at level 12, which is also very high (above hardclock).
  51.  * Software level 4 is used to synchronize wakeups with the process
  52.  * queues.
  53.  *
  54.  */
  55. struct midi_softc {
  56.     u_char    sc_unit;    /* port number (i.e., A or B) */
  57.     u_char    sc_refcnt;    /* number of opens on this device */
  58.     u_long    sc_clkrate;    /* microseconds per midi clock tick */
  59.     void *    sc_msl;
  60.     struct midid *sc_readers; /* list of readers */
  61.     struct midid *sc_writers; /* list of writers */
  62.     struct mdq sc_sp;    /* place to construct inbound message */
  63.     struct mdq sc_sf;    /* place to construct inbound message */
  64.     struct mdq *sc_p;
  65.     struct mdq *sc_f;
  66.     int    sc_stat;
  67. };
  68.  
  69. struct sleepchan {
  70.     int want;
  71.     int have;
  72. };
  73.  
  74. /*
  75.  * The midi file descriptor.  Each open file has one of these.  Note
  76.  * that there can be multiple files with the same interface opened.
  77.  * A descriptor is free if the points to itself (via md_nxtr).
  78.  */
  79. struct midid {
  80.     struct midid *md_nxtr;    /* next reader */
  81.     struct midid *md_nxtw;    /* next writer */
  82.     struct midid *md_nxti;    /* next in interrupt list */
  83.     struct midi_softc *md_sc; /* midi port attached */
  84.  
  85.     u_long md_tz;        /* time zero */
  86.     int md_flag;
  87.     u_char md_pause;
  88.     u_char md_nbio;
  89.     u_char md_echo;
  90.     u_int md_echan;
  91.     u_long md_filter;
  92. #define MS_IDLE        ((u_int)-1)
  93. #define MS_WAITING    0
  94. #define MS_DATAREADY    1
  95. #define MS_TIMEDOUT    2
  96. #define MS_PAUSED    3
  97.     u_int md_nbuf;        /* number of input messages to buffer */
  98.     u_int md_wlo;        /* output low water mark */
  99.     int md_idrops;        /* number of input messages dropped */
  100.     /*
  101.      * Input/output buffering.
  102.      */
  103.     u_int md_rcnt;        /* number of inbound messages queued */
  104.     struct mdq *md_rh;    /* inbound message queue */
  105.     struct mdq *md_rt;    /* inbound message queue */
  106.     u_int md_wcnt;        /* number of outbound messages queued */
  107.     struct mdq *md_wh;    /* outbound message queue */
  108.     struct mdq *md_wt;    /* outbound message queue */
  109.  
  110.     struct proc *md_sigioproc;
  111.     struct sleepchan md_rchan;
  112.     struct sleepchan md_wchan;
  113.     struct sleepchan md_rsel;
  114.     struct sleepchan md_wsel;
  115.     struct sleepchan md_sigio;
  116.     int md_rcol;
  117.     int md_wcol;
  118. };
  119.  
  120. /*
  121.  * XXX There is no spl for the level 14 clock so we use spl8.
  122.  */
  123. #define splmidi spl8
  124.  
  125.