patch-2.1.67 linux/drivers/sound/sys_timer.c
Next file: linux/drivers/sound/trix.c
Previous file: linux/drivers/sound/sscape.c
Back to the patch index
Back to the overall index
- Lines: 505
- Date:
Sat Nov 29 10:33:21 1997
- Orig file:
v2.1.66/linux/drivers/sound/sys_timer.c
- Orig date:
Tue Mar 4 10:25:25 1997
diff -u --recursive --new-file v2.1.66/linux/drivers/sound/sys_timer.c linux/drivers/sound/sys_timer.c
@@ -16,7 +16,7 @@
#include "sound_config.h"
-#ifdef CONFIG_SEQUENCER
+#if defined(CONFIG_SEQUENCER) || defined(MODULE)
static volatile int opened = 0, tmr_running = 0;
static volatile time_t tmr_offs, tmr_ctr;
@@ -26,281 +26,279 @@
static volatile unsigned long next_event_time;
static unsigned long prev_event_time;
-static void poll_def_tmr (unsigned long dummy);
+static void poll_def_tmr(unsigned long dummy);
static struct timer_list def_tmr =
{NULL, NULL, 0, 0, poll_def_tmr};
static unsigned long
-tmr2ticks (int tmr_value)
+tmr2ticks(int tmr_value)
{
- /*
- * Convert system timer ticks (HZ) to MIDI ticks
- * (divide # of MIDI ticks/minute by # of system ticks/minute).
- */
+ /*
+ * Convert system timer ticks (HZ) to MIDI ticks
+ * (divide # of MIDI ticks/minute by # of system ticks/minute).
+ */
- return ((tmr_value * curr_tempo * curr_timebase) + (30 * 100)) / (60 * HZ);
+ return ((tmr_value * curr_tempo * curr_timebase) + (30 * 100)) / (60 * HZ);
}
static void
-poll_def_tmr (unsigned long dummy)
+poll_def_tmr(unsigned long dummy)
{
- if (opened)
- {
-
- {
- def_tmr.expires = (1) + jiffies;
- add_timer (&def_tmr);
- };
-
- if (tmr_running)
- {
- tmr_ctr++;
- curr_ticks = ticks_offs + tmr2ticks (tmr_ctr);
+ if (opened)
+ {
- if (curr_ticks >= next_event_time)
- {
- next_event_time = (unsigned long) -1;
- sequencer_timer (0);
- }
- }
- }
+ {
+ def_tmr.expires = (1) + jiffies;
+ add_timer(&def_tmr);
+ };
+
+ if (tmr_running)
+ {
+ tmr_ctr++;
+ curr_ticks = ticks_offs + tmr2ticks(tmr_ctr);
+
+ if (curr_ticks >= next_event_time)
+ {
+ next_event_time = (unsigned long) -1;
+ sequencer_timer(0);
+ }
+ }
+ }
}
static void
-tmr_reset (void)
+tmr_reset(void)
{
- unsigned long flags;
+ unsigned long flags;
- save_flags (flags);
- cli ();
- tmr_offs = 0;
- ticks_offs = 0;
- tmr_ctr = 0;
- next_event_time = (unsigned long) -1;
- prev_event_time = 0;
- curr_ticks = 0;
- restore_flags (flags);
+ save_flags(flags);
+ cli();
+ tmr_offs = 0;
+ ticks_offs = 0;
+ tmr_ctr = 0;
+ next_event_time = (unsigned long) -1;
+ prev_event_time = 0;
+ curr_ticks = 0;
+ restore_flags(flags);
}
static int
-def_tmr_open (int dev, int mode)
+def_tmr_open(int dev, int mode)
{
- if (opened)
- return -EBUSY;
+ if (opened)
+ return -EBUSY;
+
+ tmr_reset();
+ curr_tempo = 60;
+ curr_timebase = 100;
+ opened = 1;
+
+ ;
- tmr_reset ();
- curr_tempo = 60;
- curr_timebase = 100;
- opened = 1;
-
- ;
-
- {
- def_tmr.expires = (1) + jiffies;
- add_timer (&def_tmr);
- };
+ {
+ def_tmr.expires = (1) + jiffies;
+ add_timer(&def_tmr);
+ };
- return 0;
+ return 0;
}
static void
-def_tmr_close (int dev)
+def_tmr_close(int dev)
{
- opened = tmr_running = 0;
- del_timer (&def_tmr);;
+ opened = tmr_running = 0;
+ del_timer(&def_tmr);;
}
static int
-def_tmr_event (int dev, unsigned char *event)
+def_tmr_event(int dev, unsigned char *event)
{
- unsigned char cmd = event[1];
- unsigned long parm = *(int *) &event[4];
-
- switch (cmd)
- {
- case TMR_WAIT_REL:
- parm += prev_event_time;
- case TMR_WAIT_ABS:
- if (parm > 0)
- {
- long time;
-
- if (parm <= curr_ticks) /* It's the time */
- return TIMER_NOT_ARMED;
-
- time = parm;
- next_event_time = prev_event_time = time;
-
- return TIMER_ARMED;
- }
- break;
-
- case TMR_START:
- tmr_reset ();
- tmr_running = 1;
- break;
+ unsigned char cmd = event[1];
+ unsigned long parm = *(int *) &event[4];
- case TMR_STOP:
- tmr_running = 0;
- break;
-
- case TMR_CONTINUE:
- tmr_running = 1;
- break;
-
- case TMR_TEMPO:
- if (parm)
- {
- if (parm < 8)
- parm = 8;
- if (parm > 360)
- parm = 360;
- tmr_offs = tmr_ctr;
- ticks_offs += tmr2ticks (tmr_ctr);
- tmr_ctr = 0;
- curr_tempo = parm;
- }
- break;
-
- case TMR_ECHO:
- seq_copy_to_input (event, 8);
- break;
+ switch (cmd)
+ {
+ case TMR_WAIT_REL:
+ parm += prev_event_time;
+ case TMR_WAIT_ABS:
+ if (parm > 0)
+ {
+ long time;
+
+ if (parm <= curr_ticks) /* It's the time */
+ return TIMER_NOT_ARMED;
+
+ time = parm;
+ next_event_time = prev_event_time = time;
+
+ return TIMER_ARMED;
+ }
+ break;
+
+ case TMR_START:
+ tmr_reset();
+ tmr_running = 1;
+ break;
+
+ case TMR_STOP:
+ tmr_running = 0;
+ break;
+
+ case TMR_CONTINUE:
+ tmr_running = 1;
+ break;
+
+ case TMR_TEMPO:
+ if (parm)
+ {
+ if (parm < 8)
+ parm = 8;
+ if (parm > 360)
+ parm = 360;
+ tmr_offs = tmr_ctr;
+ ticks_offs += tmr2ticks(tmr_ctr);
+ tmr_ctr = 0;
+ curr_tempo = parm;
+ }
+ break;
+
+ case TMR_ECHO:
+ seq_copy_to_input(event, 8);
+ break;
- default:;
- }
+ default:;
+ }
- return TIMER_NOT_ARMED;
+ return TIMER_NOT_ARMED;
}
static unsigned long
-def_tmr_get_time (int dev)
+def_tmr_get_time(int dev)
{
- if (!opened)
- return 0;
+ if (!opened)
+ return 0;
- return curr_ticks;
+ return curr_ticks;
}
static int
-def_tmr_ioctl (int dev,
- unsigned int cmd, caddr_t arg)
+def_tmr_ioctl(int dev,
+ unsigned int cmd, caddr_t arg)
{
- switch (cmd)
- {
- case SNDCTL_TMR_SOURCE:
- return (*(int *) arg = TMR_INTERNAL);
- break;
-
- case SNDCTL_TMR_START:
- tmr_reset ();
- tmr_running = 1;
- return 0;
- break;
-
- case SNDCTL_TMR_STOP:
- tmr_running = 0;
- return 0;
- break;
-
- case SNDCTL_TMR_CONTINUE:
- tmr_running = 1;
- return 0;
- break;
-
- case SNDCTL_TMR_TIMEBASE:
- {
- int val;
-
- val = *(int *) arg;
-
- if (val)
+ switch (cmd)
{
- if (val < 1)
- val = 1;
- if (val > 1000)
- val = 1000;
- curr_timebase = val;
- }
-
- return (*(int *) arg = curr_timebase);
- }
- break;
-
- case SNDCTL_TMR_TEMPO:
- {
- int val;
-
- val = *(int *) arg;
+ case SNDCTL_TMR_SOURCE:
+ return (*(int *) arg = TMR_INTERNAL);
+ break;
+
+ case SNDCTL_TMR_START:
+ tmr_reset();
+ tmr_running = 1;
+ return 0;
+ break;
+
+ case SNDCTL_TMR_STOP:
+ tmr_running = 0;
+ return 0;
+ break;
+
+ case SNDCTL_TMR_CONTINUE:
+ tmr_running = 1;
+ return 0;
+ break;
+
+ case SNDCTL_TMR_TIMEBASE:
+ {
+ int val;
+
+ val = *(int *) arg;
+
+ if (val)
+ {
+ if (val < 1)
+ val = 1;
+ if (val > 1000)
+ val = 1000;
+ curr_timebase = val;
+ }
+ return (*(int *) arg = curr_timebase);
+ }
+ break;
+
+ case SNDCTL_TMR_TEMPO:
+ {
+ int val;
+
+ val = *(int *) arg;
+
+ if (val)
+ {
+ if (val < 8)
+ val = 8;
+ if (val > 250)
+ val = 250;
+ tmr_offs = tmr_ctr;
+ ticks_offs += tmr2ticks(tmr_ctr);
+ tmr_ctr = 0;
+ curr_tempo = val;
+ }
+ return (*(int *) arg = curr_tempo);
+ }
+ break;
+
+ case SNDCTL_SEQ_CTRLRATE:
+ {
+ int val;
+
+ val = *(int *) arg;
+ if (val != 0) /* Can't change */
+ return -EINVAL;
+
+ return (*(int *) arg = ((curr_tempo * curr_timebase) + 30) / 60);
+ }
+ break;
+
+ case SNDCTL_SEQ_GETTIME:
+ return (*(int *) arg = curr_ticks);
+ break;
+
+ case SNDCTL_TMR_METRONOME:
+ /* NOP */
+ break;
- if (val)
- {
- if (val < 8)
- val = 8;
- if (val > 250)
- val = 250;
- tmr_offs = tmr_ctr;
- ticks_offs += tmr2ticks (tmr_ctr);
- tmr_ctr = 0;
- curr_tempo = val;
+ default:;
}
- return (*(int *) arg = curr_tempo);
- }
- break;
-
- case SNDCTL_SEQ_CTRLRATE:
- {
- int val;
-
- val = *(int *) arg;
- if (val != 0) /* Can't change */
- return -EINVAL;
-
- return (*(int *) arg = ((curr_tempo * curr_timebase) + 30) / 60);
- }
- break;
-
- case SNDCTL_SEQ_GETTIME:
- return (*(int *) arg = curr_ticks);
- break;
-
- case SNDCTL_TMR_METRONOME:
- /* NOP */
- break;
-
- default:;
- }
-
- return -EINVAL;
+ return -EINVAL;
}
static void
-def_tmr_arm (int dev, long time)
+def_tmr_arm(int dev, long time)
{
- if (time < 0)
- time = curr_ticks + 1;
- else if (time <= curr_ticks) /* It's the time */
- return;
+ if (time < 0)
+ time = curr_ticks + 1;
+ else if (time <= curr_ticks) /* It's the time */
+ return;
- next_event_time = prev_event_time = time;
+ next_event_time = prev_event_time = time;
- return;
+ return;
}
struct sound_timer_operations default_sound_timer =
{
- {"System clock", 0},
- 0, /* Priority */
- 0, /* Local device link */
- def_tmr_open,
- def_tmr_close,
- def_tmr_event,
- def_tmr_get_time,
- def_tmr_ioctl,
- def_tmr_arm
+ {"System clock", 0},
+ 0, /* Priority */
+ 0, /* Local device link */
+ def_tmr_open,
+ def_tmr_close,
+ def_tmr_event,
+ def_tmr_get_time,
+ def_tmr_ioctl,
+ def_tmr_arm
};
#endif
FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov