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 _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); 86 }; 87 88 struct _snd_timer { 89 snd_timer_class_t tmr_class; 90 snd_card_t *card; 91 struct module *module; 92 int tmr_device; 93 int tmr_subdevice; 94 char id[64]; 95 char name[80]; 96 unsigned int flags; 97 int running; /* running instances */ 98 unsigned long sticks; /* schedule ticks */ 99 void *private_data; 100 void (*private_free) (snd_timer_t *timer); 101 struct _snd_timer_hardware hw; 102 spinlock_t lock; 103 struct list_head device_list; 104 struct list_head open_list_head; 105 struct list_head active_list_head; 106 struct list_head ack_list_head; 107 struct list_head sack_list_head; /* slow ack list head */ 108 struct tasklet_struct task_queue; 109 }; 110 111 struct _snd_timer_instance { 112 snd_timer_t * timer; 113 char *owner; 114 unsigned int flags; 115 void *private_data; 116 void (*private_free) (snd_timer_instance_t *ti); 117 snd_timer_callback_t callback; 118 snd_timer_ccallback_t ccallback; 119 void *callback_data; 120 unsigned long ticks; /* auto-load ticks when expired */ 121 unsigned long cticks; /* current ticks */ 122 unsigned long pticks; /* accumulated ticks for callback */ 123 unsigned long resolution; /* current resolution for tasklet */ 124 unsigned long lost; /* lost ticks */ 125 snd_timer_slave_class_t slave_class; 126 unsigned int slave_id; 127 struct list_head open_list; 128 struct list_head active_list; 129 struct list_head ack_list; 130 struct list_head slave_list_head; 131 struct list_head slave_active_head; 132 snd_timer_instance_t *master; 133 }; 134 135 /* 136 * Registering 137 */ 138 139 extern int snd_timer_new(snd_card_t *card, char *id, snd_timer_id_t *tid, snd_timer_t ** rtimer); 140 extern void snd_timer_notify(snd_timer_t *timer, enum sndrv_timer_event event, struct timespec *tstamp); 141 extern int snd_timer_global_new(char *id, int device, snd_timer_t **rtimer); 142 extern int snd_timer_global_free(snd_timer_t *timer); 143 extern int snd_timer_global_register(snd_timer_t *timer); 144 extern int snd_timer_global_unregister(snd_timer_t *timer); 145 146 extern int snd_timer_open(snd_timer_instance_t ** ti, char *owner, snd_timer_id_t *tid, unsigned int slave_id); 147 extern int snd_timer_close(snd_timer_instance_t * timeri); 148 extern unsigned long snd_timer_resolution(snd_timer_instance_t * timeri); 149 extern int snd_timer_start(snd_timer_instance_t * timeri, unsigned int ticks); 150 extern int snd_timer_stop(snd_timer_instance_t * timeri); 151 extern int snd_timer_continue(snd_timer_instance_t * timeri); 152 extern int snd_timer_pause(snd_timer_instance_t * timeri); 153 154 extern void snd_timer_interrupt(snd_timer_t * timer, unsigned long ticks_left); 155 156 #endif /* __SOUND_TIMER_H */ 157