2
* Purpose: Default MIDI timer (using system clock)
6
* This file is part of Open Sound System.
8
* Copyright (C) 4Front Technologies 1996-2008.
10
* This this source file is released under GPL v2 license (no other versions).
11
* See the COPYING file included in the main directory of this source
12
* distribution for the license terms and conditions.
16
#include "oss_config.h"
17
#include "midi_core.h"
21
unsigned long long start_time;
22
timeout_id_t timeout_id;
23
oss_midi_wait_callback_t timer_callback;
27
static unsigned long long tick_scale = 1;
30
deftmr_create_instance (int timer_dev, int driver_dev)
32
deftmr_timerc_t *timerc;
34
if ((timerc = KERNEL_MALLOC (sizeof (*timerc))) == NULL)
37
memset (timerc, 0, sizeof (*timerc));
39
oss_timer_devs[timer_dev]->timerc = timerc;
45
deftmr_free_instance (int timer_dev, int driver_dev)
47
deftmr_timerc_t *timerc;
49
timerc = oss_timer_devs[timer_dev]->timerc;
50
untimeout (timerc->timeout_id);
54
oss_timer_devs[timer_dev]->timerc = NULL;
58
deftmr_attach_client (int timer_dev, int mididev)
64
deftmr_detach_client (int timer_dev, int mididev)
69
deftmr_ioctl (int timer_dev, unsigned int cmd, ioctl_arg arg)
75
deftmr_set_source (int timer_dev, int source)
81
deftmr_set_tempo (int timer_dev, int tempo)
87
deftmr_set_timebase (int timer_dev, int timebase)
92
deftmr_start (int timer_dev, oss_uint64_t tick)
94
deftmr_timerc_t *timerc;
96
timerc = oss_timer_devs[timer_dev]->timerc;
100
cmn_err (CE_WARN, "deftmr_start: timerc==NULL\n");
104
timerc->start_time = GET_JIFFIES ();
109
deftmr_stop (int timer_dev)
111
deftmr_timerc_t *timerc;
113
timerc = oss_timer_devs[timer_dev]->timerc;
114
untimeout (timerc->timeout_id);
120
deftmr_cont (int timer_dev)
126
deftmr_wait (int timer_dev, unsigned long long time,
127
oss_midi_wait_callback_t callback, void *arg)
129
deftmr_timerc_t *timerc;
130
unsigned long long t;
132
timerc = oss_timer_devs[timer_dev]->timerc;
133
untimeout (timerc->timeout_id);
135
t = ((oss_uint64_t) time + (tick_scale / 2)) / tick_scale;
137
t += timerc->start_time;
146
timerc->timeout_id = timeout (callback, arg, t);
151
static unsigned long long
152
deftmr_get_current_time (int timer_dev)
154
unsigned long long t;
155
deftmr_timerc_t *timerc;
157
timerc = oss_timer_devs[timer_dev]->timerc;
159
* Compute time in system ticks since start of the timer
162
if (t < timerc->start_time)
164
t -= timerc->start_time;
166
return t * tick_scale; /* In microseconds */
169
oss_timer_driver_t default_midi_driver = {
170
deftmr_create_instance,
171
deftmr_free_instance,
172
deftmr_attach_client,
173
deftmr_detach_client,
176
deftmr_get_current_time,
186
attach_oss_default_timer (oss_device_t * osdev)
190
tick_scale = 1000000 / OSS_HZ;
191
if ((timer_dev = oss_install_timer (OSS_TIMER_DRIVER_VERSION, "System timer", &default_midi_driver, sizeof (oss_timer_driver_t), 0, /* Flags */
192
16, /* max_instances */
193
1000000 / OSS_HZ, /* Resolution */
196
cmn_err (CE_WARN, "Failed to install default MIDI timer\n");
202
detach_oss_default_timer ()