timer.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. #ifndef __SOUND_TIMER_H
  2. #define __SOUND_TIMER_H
  3. /*
  4. * Timer abstract layer
  5. * Copyright (c) by Jaroslav Kysela <perex@perex.cz>,
  6. * Abramo Bagnara <abramo@alsa-project.org>
  7. *
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. *
  23. */
  24. #include <sound/asound.h>
  25. #include <linux/interrupt.h>
  26. #define snd_timer_chip(timer) ((timer)->private_data)
  27. #define SNDRV_TIMER_DEVICES 16
  28. #define SNDRV_TIMER_DEV_FLG_PCM 0x10000000
  29. #define SNDRV_TIMER_HW_AUTO 0x00000001 /* auto trigger is supported */
  30. #define SNDRV_TIMER_HW_STOP 0x00000002 /* call stop before start */
  31. #define SNDRV_TIMER_HW_SLAVE 0x00000004 /* only slave timer (variable resolution) */
  32. #define SNDRV_TIMER_HW_FIRST 0x00000008 /* first tick can be incomplete */
  33. #define SNDRV_TIMER_HW_TASKLET 0x00000010 /* timer is called from tasklet */
  34. #define SNDRV_TIMER_IFLG_SLAVE 0x00000001
  35. #define SNDRV_TIMER_IFLG_RUNNING 0x00000002
  36. #define SNDRV_TIMER_IFLG_START 0x00000004
  37. #define SNDRV_TIMER_IFLG_AUTO 0x00000008 /* auto restart */
  38. #define SNDRV_TIMER_IFLG_FAST 0x00000010 /* fast callback (do not use tasklet) */
  39. #define SNDRV_TIMER_IFLG_CALLBACK 0x00000020 /* timer callback is active */
  40. #define SNDRV_TIMER_IFLG_EXCLUSIVE 0x00000040 /* exclusive owner - no more instances */
  41. #define SNDRV_TIMER_IFLG_EARLY_EVENT 0x00000080 /* write early event to the poll queue */
  42. #define SNDRV_TIMER_FLG_CHANGE 0x00000001
  43. #define SNDRV_TIMER_FLG_RESCHED 0x00000002 /* need reschedule */
  44. struct snd_timer;
  45. struct snd_timer_hardware {
  46. /* -- must be filled with low-level driver */
  47. unsigned int flags; /* various flags */
  48. unsigned long resolution; /* average timer resolution for one tick in nsec */
  49. unsigned long resolution_min; /* minimal resolution */
  50. unsigned long resolution_max; /* maximal resolution */
  51. unsigned long ticks; /* max timer ticks per interrupt */
  52. /* -- low-level functions -- */
  53. int (*open) (struct snd_timer * timer);
  54. int (*close) (struct snd_timer * timer);
  55. unsigned long (*c_resolution) (struct snd_timer * timer);
  56. int (*start) (struct snd_timer * timer);
  57. int (*stop) (struct snd_timer * timer);
  58. int (*set_period) (struct snd_timer * timer, unsigned long period_num, unsigned long period_den);
  59. int (*precise_resolution) (struct snd_timer * timer, unsigned long *num, unsigned long *den);
  60. };
  61. struct snd_timer {
  62. int tmr_class;
  63. struct snd_card *card;
  64. struct module *module;
  65. int tmr_device;
  66. int tmr_subdevice;
  67. char id[64];
  68. char name[80];
  69. unsigned int flags;
  70. int running; /* running instances */
  71. unsigned long sticks; /* schedule ticks */
  72. void *private_data;
  73. void (*private_free) (struct snd_timer *timer);
  74. struct snd_timer_hardware hw;
  75. spinlock_t lock;
  76. struct list_head device_list;
  77. struct list_head open_list_head;
  78. struct list_head active_list_head;
  79. struct list_head ack_list_head;
  80. struct list_head sack_list_head; /* slow ack list head */
  81. struct tasklet_struct task_queue;
  82. int max_instances; /* upper limit of timer instances */
  83. int num_instances; /* current number of timer instances */
  84. };
  85. struct snd_timer_instance {
  86. struct snd_timer *timer;
  87. char *owner;
  88. unsigned int flags;
  89. void *private_data;
  90. void (*private_free) (struct snd_timer_instance *ti);
  91. void (*callback) (struct snd_timer_instance *timeri,
  92. unsigned long ticks, unsigned long resolution);
  93. void (*ccallback) (struct snd_timer_instance * timeri,
  94. int event,
  95. struct timespec * tstamp,
  96. unsigned long resolution);
  97. void (*disconnect)(struct snd_timer_instance *timeri);
  98. void *callback_data;
  99. unsigned long ticks; /* auto-load ticks when expired */
  100. unsigned long cticks; /* current ticks */
  101. unsigned long pticks; /* accumulated ticks for callback */
  102. unsigned long resolution; /* current resolution for tasklet */
  103. unsigned long lost; /* lost ticks */
  104. int slave_class;
  105. unsigned int slave_id;
  106. struct list_head open_list;
  107. struct list_head active_list;
  108. struct list_head ack_list;
  109. struct list_head slave_list_head;
  110. struct list_head slave_active_head;
  111. struct snd_timer_instance *master;
  112. };
  113. /*
  114. * Registering
  115. */
  116. int snd_timer_new(struct snd_card *card, char *id, struct snd_timer_id *tid, struct snd_timer **rtimer);
  117. void snd_timer_notify(struct snd_timer *timer, int event, struct timespec *tstamp);
  118. int snd_timer_global_new(char *id, int device, struct snd_timer **rtimer);
  119. int snd_timer_global_free(struct snd_timer *timer);
  120. int snd_timer_global_register(struct snd_timer *timer);
  121. int snd_timer_open(struct snd_timer_instance **ti, char *owner, struct snd_timer_id *tid, unsigned int slave_id);
  122. int snd_timer_close(struct snd_timer_instance *timeri);
  123. unsigned long snd_timer_resolution(struct snd_timer_instance *timeri);
  124. int snd_timer_start(struct snd_timer_instance *timeri, unsigned int ticks);
  125. int snd_timer_stop(struct snd_timer_instance *timeri);
  126. int snd_timer_continue(struct snd_timer_instance *timeri);
  127. int snd_timer_pause(struct snd_timer_instance *timeri);
  128. void snd_timer_interrupt(struct snd_timer *timer, unsigned long ticks_left);
  129. #endif /* __SOUND_TIMER_H */