timer.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. };
  83. struct snd_timer_instance {
  84. struct snd_timer *timer;
  85. char *owner;
  86. unsigned int flags;
  87. void *private_data;
  88. void (*private_free) (struct snd_timer_instance *ti);
  89. void (*callback) (struct snd_timer_instance *timeri,
  90. unsigned long ticks, unsigned long resolution);
  91. void (*ccallback) (struct snd_timer_instance * timeri,
  92. int event,
  93. struct timespec * tstamp,
  94. unsigned long resolution);
  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 tasklet */
  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. * Registering
  112. */
  113. int snd_timer_new(struct snd_card *card, char *id, struct snd_timer_id *tid, struct snd_timer **rtimer);
  114. void snd_timer_notify(struct snd_timer *timer, int event, struct timespec *tstamp);
  115. int snd_timer_global_new(char *id, int device, struct snd_timer **rtimer);
  116. int snd_timer_global_free(struct snd_timer *timer);
  117. int snd_timer_global_register(struct snd_timer *timer);
  118. int snd_timer_open(struct snd_timer_instance **ti, char *owner, struct snd_timer_id *tid, unsigned int slave_id);
  119. int snd_timer_close(struct snd_timer_instance *timeri);
  120. unsigned long snd_timer_resolution(struct snd_timer_instance *timeri);
  121. int snd_timer_start(struct snd_timer_instance *timeri, unsigned int ticks);
  122. int snd_timer_stop(struct snd_timer_instance *timeri);
  123. int snd_timer_continue(struct snd_timer_instance *timeri);
  124. int snd_timer_pause(struct snd_timer_instance *timeri);
  125. void snd_timer_interrupt(struct snd_timer *timer, unsigned long ticks_left);
  126. #endif /* __SOUND_TIMER_H */