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 / sun4c / midiclock.c < prev    next >
C/C++ Source or Header  |  1991-08-20  |  3KB  |  128 lines

  1. /*
  2.  * Copyright (c) 1990 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. #include "bmd.h"
  19. #if NBMD > 0
  20.  
  21. #ifndef lint
  22. static char rcsid[] =
  23.     "@(#) $Header: midiclock.c,v 1.2 91/08/20 19:20:56 mccanne Exp $";
  24. #endif
  25.  
  26. #include <sys/types.h>
  27. #include <machine/clock.h>
  28. #include <machine/intreg.h>
  29.  
  30. #include <machine/midiclock.h>
  31.  
  32. struct miditime midiclk;
  33.  
  34. void bmdtrap();
  35. void bmdupdate();
  36.  
  37. #ifdef BMD_CTRAP
  38. /*
  39.  * Called by clock interrupt (level 14 on a sparc).
  40.  */
  41. void
  42. bmdtrap()
  43. {
  44.     int x;
  45.     register struct miditime *p;
  46.  
  47.     x = COUNTER->limit14;
  48.  
  49.     p = &midiclk;
  50.     if (p->mt_pause)
  51.         return;
  52.     if (++p->mt_now >= p->mt_work)
  53.         bmdupdate();
  54. }
  55. #endif
  56.  
  57. #ifndef BMDCLOCKGRAN
  58. #define BMDCLOCKGRAN 1000
  59. #endif
  60.  
  61. u_int midiclk_defrate = BMDCLOCKGRAN;
  62. u_int midiclk_rate;
  63. u_int midiclk_refcnt;
  64. extern void (*int_vector[])();
  65.  
  66. u_int
  67. midiclk_start()
  68. {
  69.     register int rate;
  70.  
  71.     if (midiclk_refcnt++)
  72.         return midiclk_rate;
  73.  
  74.     midiclk.mt_pause = 0;
  75.     midiclk.mt_now = 0;
  76.     midiclk.mt_work = ~0;
  77.  
  78. #ifdef BMD_CTRAP
  79.     int_vector[14] = bmdtrap;
  80. #else
  81.     int_vector[14] = bmdupdate;
  82.     settrap(14, (int (*)())bmdtrap);
  83. #endif
  84.     rate = midiclk_defrate;
  85.     midiclk_rate = rate;
  86.     COUNTER->limit14 = (rate << CTR_USEC_SHIFT) & CTR_USEC_MASK;
  87.     set_clk_mode(IR_ENA_CLK14, 0);
  88.  
  89.     return rate;
  90. }
  91.  
  92. void
  93. midiclk_stop()
  94. {
  95.     if (--midiclk_refcnt != 0)
  96.         return;
  97.     set_clk_mode(0, IR_ENA_CLK14);
  98.     int_vector[14] = 0;
  99. }
  100.  
  101. void
  102. midiclk_pause()
  103. {
  104.     if (midiclk.mt_pause == 0) {
  105.         set_clk_mode(0, IR_ENA_CLK14);
  106.         ++midiclk.mt_pause;
  107.     }
  108. }
  109.  
  110. void
  111. midiclk_resume()
  112. {
  113.     if (--midiclk.mt_pause == 0)
  114.         set_clk_mode(IR_ENA_CLK14, 0);
  115. }
  116.  
  117. void
  118. midiclk_setrate(usec)
  119.     int usec;
  120. {
  121.     if (midiclk_refcnt == 0)
  122.         panic("midiclk_setrate");
  123.     midiclk_rate = usec;
  124.     COUNTER->limit14 = (usec << CTR_USEC_SHIFT) & CTR_USEC_MASK;
  125. }
  126.  
  127. #endif
  128.