1 | #ifndef __SOUND_TIMER_H
|
---|
2 | #define __SOUND_TIMER_H
|
---|
3 |
|
---|
4 | /*
|
---|
5 | * Timer abstract layer
|
---|
6 | * Copyright (c) by Jaroslav Kysela <perex@suse.cz>,
|
---|
7 | * Abramo Bagnara <abramo@alsa-project.org>
|
---|
8 | *
|
---|
9 | *
|
---|
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.
|
---|
14 | *
|
---|
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.
|
---|
19 | *
|
---|
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
|
---|
23 | *
|
---|
24 | */
|
---|
25 |
|
---|
26 | #include <sound/asound.h>
|
---|
27 | #include <linux/interrupt.h>
|
---|
28 |
|
---|
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;
|
---|
42 |
|
---|
43 | #define snd_timer_chip(timer) ((timer)->private_data)
|
---|
44 |
|
---|
45 | #define SNDRV_TIMER_DEVICES 16
|
---|
46 |
|
---|
47 | #define SNDRV_TIMER_DEV_FLG_PCM 0x10000000
|
---|
48 |
|
---|
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 */
|
---|
54 |
|
---|
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 */
|
---|
63 |
|
---|
64 | #define SNDRV_TIMER_FLG_CHANGE 0x00000001
|
---|
65 | #define SNDRV_TIMER_FLG_RESCHED 0x00000002 /* need reschedule */
|
---|
66 |
|
---|
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);
|
---|
70 |
|
---|
71 | struct timespec1 {
|
---|
72 | long tv_sec; /* seconds */
|
---|
73 | long tv_usec; /* and microseconds */
|
---|
74 | };
|
---|
75 |
|
---|
76 | #define timespec timespec1
|
---|
77 |
|
---|
78 | struct _snd_timer_hardware {
|
---|
79 | /* -- must be filled with low-level driver */
|
---|
80 | unsigned int flags; /* various flags */
|
---|
81 | unsigned long resolution; /* average timer resolution for one tick in nsec */
|
---|
82 | unsigned long resolution_min; /* minimal resolution */
|
---|
83 | unsigned long resolution_max; /* maximal resolution */
|
---|
84 | unsigned long ticks; /* max timer ticks per interrupt */
|
---|
85 | /* -- low-level functions -- */
|
---|
86 | int (*open) (snd_timer_t * timer);
|
---|
87 | int (*close) (snd_timer_t * timer);
|
---|
88 | unsigned long (*c_resolution) (snd_timer_t * timer);
|
---|
89 | int (*start) (snd_timer_t * timer);
|
---|
90 | int (*stop) (snd_timer_t * timer);
|
---|
91 | int (*set_period) (snd_timer_t * timer, unsigned long period_num, unsigned long period_den);
|
---|
92 | int (*precise_resolution) (snd_timer_t * timer, unsigned long *num, unsigned long *den);
|
---|
93 | };
|
---|
94 |
|
---|
95 | struct _snd_timer {
|
---|
96 | snd_timer_class_t tmr_class;
|
---|
97 | snd_card_t *card;
|
---|
98 | int tmr_device;
|
---|
99 | int tmr_subdevice;
|
---|
100 | char id[64];
|
---|
101 | char name[80];
|
---|
102 | unsigned int flags;
|
---|
103 | int running; /* running instances */
|
---|
104 | unsigned long sticks; /* schedule ticks */
|
---|
105 | void *private_data;
|
---|
106 | void (*private_free) (snd_timer_t *timer);
|
---|
107 | struct _snd_timer_hardware hw;
|
---|
108 | spinlock_t lock;
|
---|
109 | struct list_head device_list;
|
---|
110 | struct list_head open_list_head;
|
---|
111 | struct list_head active_list_head;
|
---|
112 | struct list_head ack_list_head;
|
---|
113 | struct list_head sack_list_head; /* slow ack list head */
|
---|
114 | struct tasklet_struct task_queue;
|
---|
115 | };
|
---|
116 |
|
---|
117 | struct _snd_timer_instance {
|
---|
118 | snd_timer_t * timer;
|
---|
119 | char *owner;
|
---|
120 | unsigned int flags;
|
---|
121 | void *private_data;
|
---|
122 | void (*private_free) (snd_timer_instance_t *ti);
|
---|
123 | snd_timer_callback_t callback;
|
---|
124 | snd_timer_ccallback_t ccallback;
|
---|
125 | void *callback_data;
|
---|
126 | unsigned long ticks; /* auto-load ticks when expired */
|
---|
127 | unsigned long cticks; /* current ticks */
|
---|
128 | unsigned long pticks; /* accumulated ticks for callback */
|
---|
129 | unsigned long resolution; /* current resolution for tasklet */
|
---|
130 | unsigned long lost; /* lost ticks */
|
---|
131 | snd_timer_slave_class_t slave_class;
|
---|
132 | unsigned int slave_id;
|
---|
133 | struct list_head open_list;
|
---|
134 | struct list_head active_list;
|
---|
135 | struct list_head ack_list;
|
---|
136 | struct list_head slave_list_head;
|
---|
137 | struct list_head slave_active_head;
|
---|
138 | snd_timer_instance_t *master;
|
---|
139 | };
|
---|
140 |
|
---|
141 | /*
|
---|
142 | * Registering
|
---|
143 | */
|
---|
144 |
|
---|
145 | extern int snd_timer_new(snd_card_t *card, char *id, snd_timer_id_t *tid, snd_timer_t ** rtimer);
|
---|
146 | extern void snd_timer_notify(snd_timer_t *timer, enum sndrv_timer_event event, struct timespec *tstamp);
|
---|
147 | extern int snd_timer_global_new(char *id, int device, snd_timer_t **rtimer);
|
---|
148 | extern int snd_timer_global_free(snd_timer_t *timer);
|
---|
149 | extern int snd_timer_global_register(snd_timer_t *timer);
|
---|
150 | extern int snd_timer_global_unregister(snd_timer_t *timer);
|
---|
151 |
|
---|
152 | extern int snd_timer_open(snd_timer_instance_t ** ti, char *owner, snd_timer_id_t *tid, unsigned int slave_id);
|
---|
153 | extern int snd_timer_close(snd_timer_instance_t * timeri);
|
---|
154 | extern unsigned long snd_timer_resolution(snd_timer_instance_t * timeri);
|
---|
155 | extern int snd_timer_start(snd_timer_instance_t * timeri, unsigned int ticks);
|
---|
156 | extern int snd_timer_stop(snd_timer_instance_t * timeri);
|
---|
157 | extern int snd_timer_continue(snd_timer_instance_t * timeri);
|
---|
158 | extern int snd_timer_pause(snd_timer_instance_t * timeri);
|
---|
159 |
|
---|
160 | extern void snd_timer_interrupt(snd_timer_t * timer, unsigned long ticks_left);
|
---|
161 |
|
---|
162 | extern unsigned int snd_timer_system_resolution(void);
|
---|
163 |
|
---|
164 | #endif /* __SOUND_TIMER_H */
|
---|