Linux Audio

Check our new training course

Loading...
v3.1
 
  1#ifndef __SOUND_TIMER_H
  2#define __SOUND_TIMER_H
  3
  4/*
  5 *  Timer abstract layer
  6 *  Copyright (c) by Jaroslav Kysela <perex@perex.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#define snd_timer_chip(timer) ((timer)->private_data)
 30
 31#define SNDRV_TIMER_DEVICES	16
 32
 33#define SNDRV_TIMER_DEV_FLG_PCM	0x10000000
 34
 35#define SNDRV_TIMER_HW_AUTO	0x00000001	/* auto trigger is supported */
 36#define SNDRV_TIMER_HW_STOP	0x00000002	/* call stop before start */
 37#define SNDRV_TIMER_HW_SLAVE	0x00000004	/* only slave timer (variable resolution) */
 38#define SNDRV_TIMER_HW_FIRST	0x00000008	/* first tick can be incomplete */
 39#define SNDRV_TIMER_HW_TASKLET	0x00000010	/* timer is called from tasklet */
 40
 41#define SNDRV_TIMER_IFLG_SLAVE	  0x00000001
 42#define SNDRV_TIMER_IFLG_RUNNING  0x00000002
 43#define SNDRV_TIMER_IFLG_START	  0x00000004
 44#define SNDRV_TIMER_IFLG_AUTO	  0x00000008	/* auto restart */
 45#define SNDRV_TIMER_IFLG_FAST	  0x00000010	/* fast callback (do not use tasklet) */
 46#define SNDRV_TIMER_IFLG_CALLBACK 0x00000020	/* timer callback is active */
 47#define SNDRV_TIMER_IFLG_EXCLUSIVE 0x00000040	/* exclusive owner - no more instances */
 48#define SNDRV_TIMER_IFLG_EARLY_EVENT 0x00000080	/* write early event to the poll queue */
 49
 50#define SNDRV_TIMER_FLG_CHANGE	0x00000001
 51#define SNDRV_TIMER_FLG_RESCHED	0x00000002	/* need reschedule */
 52
 53struct snd_timer;
 54
 55struct snd_timer_hardware {
 56	/* -- must be filled with low-level driver */
 57	unsigned int flags;		/* various flags */
 58	unsigned long resolution;	/* average timer resolution for one tick in nsec */
 59	unsigned long resolution_min;	/* minimal resolution */
 60	unsigned long resolution_max;	/* maximal resolution */
 61	unsigned long ticks;		/* max timer ticks per interrupt */
 62	/* -- low-level functions -- */
 63	int (*open) (struct snd_timer * timer);
 64	int (*close) (struct snd_timer * timer);
 65	unsigned long (*c_resolution) (struct snd_timer * timer);
 66	int (*start) (struct snd_timer * timer);
 67	int (*stop) (struct snd_timer * timer);
 68	int (*set_period) (struct snd_timer * timer, unsigned long period_num, unsigned long period_den);
 69	int (*precise_resolution) (struct snd_timer * timer, unsigned long *num, unsigned long *den);
 70};
 71
 72struct snd_timer {
 73	int tmr_class;
 74	struct snd_card *card;
 75	struct module *module;
 76	int tmr_device;
 77	int tmr_subdevice;
 78	char id[64];
 79	char name[80];
 80	unsigned int flags;
 81	int running;			/* running instances */
 82	unsigned long sticks;		/* schedule ticks */
 83	void *private_data;
 84	void (*private_free) (struct snd_timer *timer);
 85	struct snd_timer_hardware hw;
 86	spinlock_t lock;
 87	struct list_head device_list;
 88	struct list_head open_list_head;
 89	struct list_head active_list_head;
 90	struct list_head ack_list_head;
 91	struct list_head sack_list_head; /* slow ack list head */
 92	struct tasklet_struct task_queue;
 
 
 93};
 94
 95struct snd_timer_instance {
 96	struct snd_timer *timer;
 97	char *owner;
 98	unsigned int flags;
 99	void *private_data;
100	void (*private_free) (struct snd_timer_instance *ti);
101	void (*callback) (struct snd_timer_instance *timeri,
102			  unsigned long ticks, unsigned long resolution);
103	void (*ccallback) (struct snd_timer_instance * timeri,
104			   int event,
105			   struct timespec * tstamp,
106			   unsigned long resolution);
 
107	void *callback_data;
108	unsigned long ticks;		/* auto-load ticks when expired */
109	unsigned long cticks;		/* current ticks */
110	unsigned long pticks;		/* accumulated ticks for callback */
111	unsigned long resolution;	/* current resolution for tasklet */
112	unsigned long lost;		/* lost ticks */
113	int slave_class;
114	unsigned int slave_id;
115	struct list_head open_list;
116	struct list_head active_list;
117	struct list_head ack_list;
118	struct list_head slave_list_head;
119	struct list_head slave_active_head;
120	struct snd_timer_instance *master;
121};
122
123/*
124 *  Registering
125 */
126
127int snd_timer_new(struct snd_card *card, char *id, struct snd_timer_id *tid, struct snd_timer **rtimer);
128void snd_timer_notify(struct snd_timer *timer, int event, struct timespec *tstamp);
129int snd_timer_global_new(char *id, int device, struct snd_timer **rtimer);
130int snd_timer_global_free(struct snd_timer *timer);
131int snd_timer_global_register(struct snd_timer *timer);
132
133int snd_timer_open(struct snd_timer_instance **ti, char *owner, struct snd_timer_id *tid, unsigned int slave_id);
134int snd_timer_close(struct snd_timer_instance *timeri);
 
 
135unsigned long snd_timer_resolution(struct snd_timer_instance *timeri);
136int snd_timer_start(struct snd_timer_instance *timeri, unsigned int ticks);
137int snd_timer_stop(struct snd_timer_instance *timeri);
138int snd_timer_continue(struct snd_timer_instance *timeri);
139int snd_timer_pause(struct snd_timer_instance *timeri);
140
141void snd_timer_interrupt(struct snd_timer *timer, unsigned long ticks_left);
142
143#endif /* __SOUND_TIMER_H */
v6.13.7
  1/* SPDX-License-Identifier: GPL-2.0-or-later */
  2#ifndef __SOUND_TIMER_H
  3#define __SOUND_TIMER_H
  4
  5/*
  6 *  Timer abstract layer
  7 *  Copyright (c) by Jaroslav Kysela <perex@perex.cz>,
  8 *		     Abramo Bagnara <abramo@alsa-project.org>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  9 */
 10
 11#include <sound/asound.h>
 12#include <linux/interrupt.h>
 13
 14#define snd_timer_chip(timer) ((timer)->private_data)
 15
 16#define SNDRV_TIMER_DEVICES	16
 17
 18#define SNDRV_TIMER_DEV_FLG_PCM	0x10000000
 19
 20#define SNDRV_TIMER_HW_AUTO	0x00000001	/* auto trigger is supported */
 21#define SNDRV_TIMER_HW_STOP	0x00000002	/* call stop before start */
 22#define SNDRV_TIMER_HW_SLAVE	0x00000004	/* only slave timer (variable resolution) */
 23#define SNDRV_TIMER_HW_FIRST	0x00000008	/* first tick can be incomplete */
 24#define SNDRV_TIMER_HW_WORK	0x00000010	/* timer is called from work */
 25
 26#define SNDRV_TIMER_IFLG_SLAVE	  0x00000001
 27#define SNDRV_TIMER_IFLG_RUNNING  0x00000002
 28#define SNDRV_TIMER_IFLG_START	  0x00000004
 29#define SNDRV_TIMER_IFLG_AUTO	  0x00000008	/* auto restart */
 30#define SNDRV_TIMER_IFLG_FAST	  0x00000010	/* fast callback (do not use work) */
 31#define SNDRV_TIMER_IFLG_CALLBACK 0x00000020	/* timer callback is active */
 32#define SNDRV_TIMER_IFLG_EXCLUSIVE 0x00000040	/* exclusive owner - no more instances */
 33#define SNDRV_TIMER_IFLG_EARLY_EVENT 0x00000080	/* write early event to the poll queue */
 34
 35#define SNDRV_TIMER_FLG_CHANGE	0x00000001
 36#define SNDRV_TIMER_FLG_RESCHED	0x00000002	/* need reschedule */
 37
 38struct snd_timer;
 39
 40struct snd_timer_hardware {
 41	/* -- must be filled with low-level driver */
 42	unsigned int flags;		/* various flags */
 43	unsigned long resolution;	/* average timer resolution for one tick in nsec */
 44	unsigned long resolution_min;	/* minimal resolution */
 45	unsigned long resolution_max;	/* maximal resolution */
 46	unsigned long ticks;		/* max timer ticks per interrupt */
 47	/* -- low-level functions -- */
 48	int (*open) (struct snd_timer * timer);
 49	int (*close) (struct snd_timer * timer);
 50	unsigned long (*c_resolution) (struct snd_timer * timer);
 51	int (*start) (struct snd_timer * timer);
 52	int (*stop) (struct snd_timer * timer);
 53	int (*set_period) (struct snd_timer * timer, unsigned long period_num, unsigned long period_den);
 54	int (*precise_resolution) (struct snd_timer * timer, unsigned long *num, unsigned long *den);
 55};
 56
 57struct snd_timer {
 58	int tmr_class;
 59	struct snd_card *card;
 60	struct module *module;
 61	int tmr_device;
 62	int tmr_subdevice;
 63	char id[64];
 64	char name[80];
 65	unsigned int flags;
 66	int running;			/* running instances */
 67	unsigned long sticks;		/* schedule ticks */
 68	void *private_data;
 69	void (*private_free) (struct snd_timer *timer);
 70	struct snd_timer_hardware hw;
 71	spinlock_t lock;
 72	struct list_head device_list;
 73	struct list_head open_list_head;
 74	struct list_head active_list_head;
 75	struct list_head ack_list_head;
 76	struct list_head sack_list_head; /* slow ack list head */
 77	struct work_struct task_work;
 78	int max_instances;	/* upper limit of timer instances */
 79	int num_instances;	/* current number of timer instances */
 80};
 81
 82struct snd_timer_instance {
 83	struct snd_timer *timer;
 84	char *owner;
 85	unsigned int flags;
 86	void *private_data;
 87	void (*private_free) (struct snd_timer_instance *ti);
 88	void (*callback) (struct snd_timer_instance *timeri,
 89			  unsigned long ticks, unsigned long resolution);
 90	void (*ccallback) (struct snd_timer_instance * timeri,
 91			   int event,
 92			   struct timespec64 * tstamp,
 93			   unsigned long resolution);
 94	void (*disconnect)(struct snd_timer_instance *timeri);
 95	void *callback_data;
 96	unsigned long ticks;		/* auto-load ticks when expired */
 97	unsigned long cticks;		/* current ticks */
 98	unsigned long pticks;		/* accumulated ticks for callback */
 99	unsigned long resolution;	/* current resolution for work */
100	unsigned long lost;		/* lost ticks */
101	int slave_class;
102	unsigned int slave_id;
103	struct list_head open_list;
104	struct list_head active_list;
105	struct list_head ack_list;
106	struct list_head slave_list_head;
107	struct list_head slave_active_head;
108	struct snd_timer_instance *master;
109};
110
111/*
112 *  Registering
113 */
114
115int snd_timer_new(struct snd_card *card, char *id, struct snd_timer_id *tid, struct snd_timer **rtimer);
116void snd_timer_notify(struct snd_timer *timer, int event, struct timespec64 *tstamp);
117int snd_timer_global_new(char *id, int device, struct snd_timer **rtimer);
118int snd_timer_global_free(struct snd_timer *timer);
119int snd_timer_global_register(struct snd_timer *timer);
120
121struct snd_timer_instance *snd_timer_instance_new(const char *owner);
122void snd_timer_instance_free(struct snd_timer_instance *timeri);
123int snd_timer_open(struct snd_timer_instance *timeri, struct snd_timer_id *tid, unsigned int slave_id);
124void snd_timer_close(struct snd_timer_instance *timeri);
125unsigned long snd_timer_resolution(struct snd_timer_instance *timeri);
126int snd_timer_start(struct snd_timer_instance *timeri, unsigned int ticks);
127int snd_timer_stop(struct snd_timer_instance *timeri);
128int snd_timer_continue(struct snd_timer_instance *timeri);
129int snd_timer_pause(struct snd_timer_instance *timeri);
130
131void snd_timer_interrupt(struct snd_timer *timer, unsigned long ticks_left);
132
133#endif /* __SOUND_TIMER_H */