timer.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. #ifndef __SOUND_TIMER_H
  2. #define __SOUND_TIMER_H
  3. /*
  4. * Timer abstract layer
  5. * Copyright (c) by Jaroslav Kysela <perex@suse.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. typedef enum sndrv_timer_class snd_timer_class_t;
  27. typedef enum sndrv_timer_slave_class snd_timer_slave_class_t;
  28. typedef enum sndrv_timer_global snd_timer_global_t;
  29. typedef struct sndrv_timer_id snd_timer_id_t;
  30. typedef struct sndrv_timer_ginfo snd_timer_ginfo_t;
  31. typedef struct sndrv_timer_gparams snd_timer_gparams_t;
  32. typedef struct sndrv_timer_gstatus snd_timer_gstatus_t;
  33. typedef struct sndrv_timer_select snd_timer_select_t;
  34. typedef struct sndrv_timer_info snd_timer_info_t;
  35. typedef struct sndrv_timer_params snd_timer_params_t;
  36. typedef struct sndrv_timer_status snd_timer_status_t;
  37. typedef struct sndrv_timer_read snd_timer_read_t;
  38. typedef struct sndrv_timer_tread snd_timer_tread_t;
  39. #define snd_timer_chip(timer) ((timer)->private_data)
  40. #define SNDRV_TIMER_DEVICES 16
  41. #define SNDRV_TIMER_DEV_FLG_PCM 0x10000000
  42. #define SNDRV_TIMER_HW_AUTO 0x00000001 /* auto trigger is supported */
  43. #define SNDRV_TIMER_HW_STOP 0x00000002 /* call stop before start */
  44. #define SNDRV_TIMER_HW_SLAVE 0x00000004 /* only slave timer (variable resolution) */
  45. #define SNDRV_TIMER_HW_FIRST 0x00000008 /* first tick can be incomplete */
  46. #define SNDRV_TIMER_HW_TASKLET 0x00000010 /* timer is called from tasklet */
  47. #define SNDRV_TIMER_IFLG_SLAVE 0x00000001
  48. #define SNDRV_TIMER_IFLG_RUNNING 0x00000002
  49. #define SNDRV_TIMER_IFLG_START 0x00000004
  50. #define SNDRV_TIMER_IFLG_AUTO 0x00000008 /* auto restart */
  51. #define SNDRV_TIMER_IFLG_FAST 0x00000010 /* fast callback (do not use tasklet) */
  52. #define SNDRV_TIMER_IFLG_CALLBACK 0x00000020 /* timer callback is active */
  53. #define SNDRV_TIMER_IFLG_EXCLUSIVE 0x00000040 /* exclusive owner - no more instances */
  54. #define SNDRV_TIMER_IFLG_EARLY_EVENT 0x00000080 /* write early event to the poll queue */
  55. #define SNDRV_TIMER_FLG_CHANGE 0x00000001
  56. #define SNDRV_TIMER_FLG_RESCHED 0x00000002 /* need reschedule */
  57. typedef void (*snd_timer_callback_t) (snd_timer_instance_t * timeri, unsigned long ticks, unsigned long resolution);
  58. typedef void (*snd_timer_ccallback_t) (snd_timer_instance_t * timeri, enum sndrv_timer_event event,
  59. struct timespec * tstamp, unsigned long resolution);
  60. struct _snd_timer_hardware {
  61. /* -- must be filled with low-level driver */
  62. unsigned int flags; /* various flags */
  63. unsigned long resolution; /* average timer resolution for one tick in nsec */
  64. unsigned long resolution_min; /* minimal resolution */
  65. unsigned long resolution_max; /* maximal resolution */
  66. unsigned long ticks; /* max timer ticks per interrupt */
  67. /* -- low-level functions -- */
  68. int (*open) (snd_timer_t * timer);
  69. int (*close) (snd_timer_t * timer);
  70. unsigned long (*c_resolution) (snd_timer_t * timer);
  71. int (*start) (snd_timer_t * timer);
  72. int (*stop) (snd_timer_t * timer);
  73. int (*set_period) (snd_timer_t * timer, unsigned long period_num, unsigned long period_den);
  74. int (*precise_resolution) (snd_timer_t * timer, unsigned long *num, unsigned long *den);
  75. };
  76. struct _snd_timer {
  77. snd_timer_class_t tmr_class;
  78. snd_card_t *card;
  79. struct module *module;
  80. int tmr_device;
  81. int tmr_subdevice;
  82. char id[64];
  83. char name[80];
  84. unsigned int flags;
  85. int running; /* running instances */
  86. unsigned long sticks; /* schedule ticks */
  87. void *private_data;
  88. void (*private_free) (snd_timer_t *timer);
  89. struct _snd_timer_hardware hw;
  90. spinlock_t lock;
  91. struct list_head device_list;
  92. struct list_head open_list_head;
  93. struct list_head active_list_head;
  94. struct list_head ack_list_head;
  95. struct list_head sack_list_head; /* slow ack list head */
  96. struct tasklet_struct task_queue;
  97. };
  98. struct _snd_timer_instance {
  99. snd_timer_t * timer;
  100. char *owner;
  101. unsigned int flags;
  102. void *private_data;
  103. void (*private_free) (snd_timer_instance_t *ti);
  104. snd_timer_callback_t callback;
  105. snd_timer_ccallback_t ccallback;
  106. void *callback_data;
  107. unsigned long ticks; /* auto-load ticks when expired */
  108. unsigned long cticks; /* current ticks */
  109. unsigned long pticks; /* accumulated ticks for callback */
  110. unsigned long resolution; /* current resolution for tasklet */
  111. unsigned long lost; /* lost ticks */
  112. snd_timer_slave_class_t slave_class;
  113. unsigned int slave_id;
  114. struct list_head open_list;
  115. struct list_head active_list;
  116. struct list_head ack_list;
  117. struct list_head slave_list_head;
  118. struct list_head slave_active_head;
  119. snd_timer_instance_t *master;
  120. };
  121. /*
  122. * Registering
  123. */
  124. extern int snd_timer_new(snd_card_t *card, char *id, snd_timer_id_t *tid, snd_timer_t ** rtimer);
  125. extern void snd_timer_notify(snd_timer_t *timer, enum sndrv_timer_event event, struct timespec *tstamp);
  126. extern int snd_timer_global_new(char *id, int device, snd_timer_t **rtimer);
  127. extern int snd_timer_global_free(snd_timer_t *timer);
  128. extern int snd_timer_global_register(snd_timer_t *timer);
  129. extern int snd_timer_global_unregister(snd_timer_t *timer);
  130. extern int snd_timer_open(snd_timer_instance_t ** ti, char *owner, snd_timer_id_t *tid, unsigned int slave_id);
  131. extern int snd_timer_close(snd_timer_instance_t * timeri);
  132. extern unsigned long snd_timer_resolution(snd_timer_instance_t * timeri);
  133. extern int snd_timer_start(snd_timer_instance_t * timeri, unsigned int ticks);
  134. extern int snd_timer_stop(snd_timer_instance_t * timeri);
  135. extern int snd_timer_continue(snd_timer_instance_t * timeri);
  136. extern int snd_timer_pause(snd_timer_instance_t * timeri);
  137. extern void snd_timer_interrupt(snd_timer_t * timer, unsigned long ticks_left);
  138. #endif /* __SOUND_TIMER_H */