1 #ifndef __SOUND_TIMER_H
2 #define __SOUND_TIMER_H
6 * Copyright (c) by Jaroslav Kysela <perex@suse.cz>,
7 * Abramo Bagnara <abramo@alsa-project.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include <sound/asound.h>
27 #include <linux/interrupt.h>
29 typedef enum sndrv_timer_class snd_timer_class_t
;
30 typedef enum sndrv_timer_slave_class snd_timer_slave_class_t
;
31 typedef enum sndrv_timer_global snd_timer_global_t
;
32 typedef struct sndrv_timer_id snd_timer_id_t
;
33 typedef struct sndrv_timer_ginfo snd_timer_ginfo_t
;
34 typedef struct sndrv_timer_gparams snd_timer_gparams_t
;
35 typedef struct sndrv_timer_gstatus snd_timer_gstatus_t
;
36 typedef struct sndrv_timer_select snd_timer_select_t
;
37 typedef struct sndrv_timer_info snd_timer_info_t
;
38 typedef struct sndrv_timer_params snd_timer_params_t
;
39 typedef struct sndrv_timer_status snd_timer_status_t
;
40 typedef struct sndrv_timer_read snd_timer_read_t
;
41 typedef struct sndrv_timer_tread snd_timer_tread_t
;
43 #define snd_timer_chip(timer) ((timer)->private_data)
45 #define SNDRV_TIMER_DEVICES 16
47 #define SNDRV_TIMER_DEV_FLG_PCM 0x10000000
49 #define SNDRV_TIMER_HW_AUTO 0x00000001 /* auto trigger is supported */
50 #define SNDRV_TIMER_HW_STOP 0x00000002 /* call stop before start */
51 #define SNDRV_TIMER_HW_SLAVE 0x00000004 /* only slave timer (variable resolution) */
52 #define SNDRV_TIMER_HW_FIRST 0x00000008 /* first tick can be incomplete */
53 #define SNDRV_TIMER_HW_TASKLET 0x00000010 /* timer is called from tasklet */
55 #define SNDRV_TIMER_IFLG_SLAVE 0x00000001
56 #define SNDRV_TIMER_IFLG_RUNNING 0x00000002
57 #define SNDRV_TIMER_IFLG_START 0x00000004
58 #define SNDRV_TIMER_IFLG_AUTO 0x00000008 /* auto restart */
59 #define SNDRV_TIMER_IFLG_FAST 0x00000010 /* fast callback (do not use tasklet) */
60 #define SNDRV_TIMER_IFLG_CALLBACK 0x00000020 /* timer callback is active */
61 #define SNDRV_TIMER_IFLG_EXCLUSIVE 0x00000040 /* exclusive owner - no more instances */
62 #define SNDRV_TIMER_IFLG_EARLY_EVENT 0x00000080 /* write early event to the poll queue */
64 #define SNDRV_TIMER_FLG_CHANGE 0x00000001
65 #define SNDRV_TIMER_FLG_RESCHED 0x00000002 /* need reschedule */
67 typedef void (*snd_timer_callback_t
) (snd_timer_instance_t
* timeri
, unsigned long ticks
, unsigned long resolution
);
68 typedef void (*snd_timer_ccallback_t
) (snd_timer_instance_t
* timeri
, enum sndrv_timer_event event
,
69 struct timespec
* tstamp
, unsigned long resolution
);
71 struct _snd_timer_hardware
{
72 /* -- must be filled with low-level driver */
73 unsigned int flags
; /* various flags */
74 unsigned long resolution
; /* average timer resolution for one tick in nsec */
75 unsigned long resolution_min
; /* minimal resolution */
76 unsigned long resolution_max
; /* maximal resolution */
77 unsigned long ticks
; /* max timer ticks per interrupt */
78 /* -- low-level functions -- */
79 int (*open
) (snd_timer_t
* timer
);
80 int (*close
) (snd_timer_t
* timer
);
81 unsigned long (*c_resolution
) (snd_timer_t
* timer
);
82 int (*start
) (snd_timer_t
* timer
);
83 int (*stop
) (snd_timer_t
* timer
);
84 int (*set_period
) (snd_timer_t
* timer
, unsigned long period_num
, unsigned long period_den
);
85 int (*precise_resolution
) (snd_timer_t
* timer
, unsigned long *num
, unsigned long *den
);
89 snd_timer_class_t tmr_class
;
96 int running
; /* running instances */
97 unsigned long sticks
; /* schedule ticks */
99 void (*private_free
) (snd_timer_t
*timer
);
100 struct _snd_timer_hardware hw
;
102 struct list_head device_list
;
103 struct list_head open_list_head
;
104 struct list_head active_list_head
;
105 struct list_head ack_list_head
;
106 struct list_head sack_list_head
; /* slow ack list head */
107 struct tasklet_struct task_queue
;
110 struct _snd_timer_instance
{
115 void (*private_free
) (snd_timer_instance_t
*ti
);
116 snd_timer_callback_t callback
;
117 snd_timer_ccallback_t ccallback
;
119 unsigned long ticks
; /* auto-load ticks when expired */
120 unsigned long cticks
; /* current ticks */
121 unsigned long pticks
; /* accumulated ticks for callback */
122 unsigned long resolution
; /* current resolution for tasklet */
123 unsigned long lost
; /* lost ticks */
124 snd_timer_slave_class_t slave_class
;
125 unsigned int slave_id
;
126 struct list_head open_list
;
127 struct list_head active_list
;
128 struct list_head ack_list
;
129 struct list_head slave_list_head
;
130 struct list_head slave_active_head
;
131 snd_timer_instance_t
*master
;
138 extern int snd_timer_new(snd_card_t
*card
, char *id
, snd_timer_id_t
*tid
, snd_timer_t
** rtimer
);
139 extern void snd_timer_notify(snd_timer_t
*timer
, enum sndrv_timer_event event
, struct timespec
*tstamp
);
140 extern int snd_timer_global_new(char *id
, int device
, snd_timer_t
**rtimer
);
141 extern int snd_timer_global_free(snd_timer_t
*timer
);
142 extern int snd_timer_global_register(snd_timer_t
*timer
);
143 extern int snd_timer_global_unregister(snd_timer_t
*timer
);
145 extern int snd_timer_open(snd_timer_instance_t
** ti
, char *owner
, snd_timer_id_t
*tid
, unsigned int slave_id
);
146 extern int snd_timer_close(snd_timer_instance_t
* timeri
);
147 extern unsigned long snd_timer_resolution(snd_timer_instance_t
* timeri
);
148 extern int snd_timer_start(snd_timer_instance_t
* timeri
, unsigned int ticks
);
149 extern int snd_timer_stop(snd_timer_instance_t
* timeri
);
150 extern int snd_timer_continue(snd_timer_instance_t
* timeri
);
151 extern int snd_timer_pause(snd_timer_instance_t
* timeri
);
153 extern void snd_timer_interrupt(snd_timer_t
* timer
, unsigned long ticks_left
);
155 extern unsigned int snd_timer_system_resolution(void);
157 #endif /* __SOUND_TIMER_H */