4 * The default timer for the Level 2 sequencer interface.
5 * Uses the (100hz) timer of kernel.
7 * Copyright by Hannu Savolainen 1993
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are
11 * met: 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer. 2.
13 * Redistributions in binary form must reproduce the above copyright notice,
14 * this list of conditions and the following disclaimer in the documentation
15 * and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
21 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * $DragonFly: src/sys/dev/sound/isa/i386/Attic/sys_timer.c,v 1.2 2003/08/07 21:17:12 dillon Exp $
33 #include "sound_config.h"
37 #if defined(CONFIG_SEQUENCER)
39 static volatile int opened = 0, tmr_running = 0;
40 static volatile time_t tmr_offs, tmr_ctr;
41 static volatile u_long ticks_offs;
42 static volatile int curr_tempo, curr_timebase;
43 static volatile u_long curr_ticks;
44 static volatile u_long next_event_time;
45 static u_long prev_event_time;
47 static void poll_def_tmr(void *dummy);
50 tmr2ticks(int tmr_value)
53 * Convert system timer ticks (hz) to MIDI ticks (divide # of MIDI
54 * ticks/minute by # of system ticks/minute).
57 return ((tmr_value * curr_tempo * curr_timebase) + (30 * hz)) / (60 * hz);
61 poll_def_tmr(void *dummy)
66 timeout( poll_def_tmr, 0, 1);;
70 curr_ticks = ticks_offs + tmr2ticks(tmr_ctr);
72 if (curr_ticks >= next_event_time) {
73 next_event_time = 0xffffffff;
89 next_event_time = 0xffffffff;
96 def_tmr_open(int dev, int mode)
106 timeout( poll_def_tmr, 0, 1);;
112 def_tmr_close(int dev)
114 opened = tmr_running = 0;
118 def_tmr_event(int dev, u_char *event)
120 u_char cmd = event[1];
121 u_long parm = *(int *) &event[4];
125 parm += prev_event_time;
130 if (parm <= curr_ticks) /* It's the time */
131 return TIMER_NOT_ARMED;
134 next_event_time = prev_event_time = time;
155 RANGE (parm, 8, 360) ;
157 ticks_offs += tmr2ticks(tmr_ctr);
164 seq_copy_to_input(event, 8);
170 return TIMER_NOT_ARMED;
174 def_tmr_get_time(int dev)
183 def_tmr_ioctl(int dev, u_int cmd, ioctl_arg arg)
186 case SNDCTL_TMR_SOURCE:
187 return *(int *) arg = TMR_INTERNAL;
190 case SNDCTL_TMR_START:
196 case SNDCTL_TMR_STOP:
201 case SNDCTL_TMR_CONTINUE:
206 case SNDCTL_TMR_TIMEBASE:
208 int val = (*(int *) arg);
211 RANGE (val, 1, 1000) ;
214 return *(int *) arg = curr_timebase;
218 case SNDCTL_TMR_TEMPO:
220 int val = (*(int *) arg);
223 RANGE (val, 8, 250) ;
225 ticks_offs += tmr2ticks(tmr_ctr);
229 return *(int *) arg = curr_tempo;
233 case SNDCTL_SEQ_CTRLRATE:
234 if ((*(int *) arg) != 0) /* Can't change */
237 return *(int *) arg = ((curr_tempo * curr_timebase) + 30) / 60;
240 case SNDCTL_TMR_METRONOME:
251 def_tmr_arm(int dev, long time)
254 time = curr_ticks + 1;
255 else if (time <= curr_ticks) /* It's the time */
258 next_event_time = prev_event_time = time;
263 struct sound_timer_operations default_sound_timer =
267 0, /* Local device link */
277 #endif /* NSND > 0 */