GadgetSeed  0.9.6
sound.c
[詳解]
1 /** @file
2  @brief サウンドドライバ
3 
4  @date 2007.07.15
5  @author Takashi SHUDO
6 
7  @info
8 
9  下位ドライバに圧電ブザーデバイスドライバが必要
10 
11  使用方法
12 
13  ioctl(周波数(Hz), 再生時間(x1ms))
14 */
15 
16 #include "sysconfig.h"
17 #include "device.h"
18 #include "device/buzzer_ioctl.h"
19 #include "timer.h"
20 #include "tkprintf.h"
21 
22 //#define DEBUGKBITS 0x03
23 #include "dkprintf.h"
24 
25 
26 #define TIMER_INTERVAL_TIME GSC_KERNEL_TIMER_INTERVAL_MSEC
27 
28 static struct st_device *buzzer_dev;
29 static int sound_cnt;
30 
31 static void sound_timer(void *sp, unsigned long long time)
32 {
33  if(sound_cnt > 0) {
34  DKPRINTF(0x01, ".");
35  sound_cnt -= TIMER_INTERVAL_TIME;
36  if(sound_cnt <= 0) {
37  ioctl_device(buzzer_dev, IOCMD_BUZZER_OFF, 0, 0);
38  DKPRINTF(0x01, "SND OFF : %d\n", (int)get_kernel_time());
39  }
40  }
41 }
42 
43 static int sound_register(struct st_device *dev, char *param)
44 {
45  // param = ブザードライバ名
46 
47  buzzer_dev = open_device(param);
48 
49  if(buzzer_dev == 0) {
50  SYSERR_PRINT("Cannot open device %s.\n", param);
51  return -1;
52  }
53 
54  if(register_timer_func(sound_timer, TIMER_INTERVAL_TIME)) {
55  SYSERR_PRINT("Cannot register buzzer timer func.\n");
56  return -1;
57  }
58 
59  sound_cnt = 0;
60 
61  return 0;
62 }
63 
64 static int sound_unregister(struct st_device *dev)
65 {
66  unregister_timer_func(sound_timer);
67 
68  return 0;
69 }
70 
71 static int sound_open(struct st_device *dev)
72 {
73  return 0;
74 }
75 
76 static int sound_close(struct st_device *dev)
77 {
78  return 0;
79 }
80 
81 static int sound_ioctl(struct st_device *dev, unsigned int com, unsigned int arg, void *param)
82 {
83  /*
84  * com : Hz
85  * arg : ms
86  */
87 
88  if(arg != 0) {
89  sound_cnt = arg;
90  DKPRINTF(0x01, "SND LEN : %d\n", (int)arg);
91  DKPRINTF(0x01, "SND ON : %d\n", (int)get_kernel_time());
92  ioctl_device(buzzer_dev, IOCMD_BUZZER_ON, com, 0);
93  } else {
94  ioctl_device(buzzer_dev, IOCMD_BUZZER_OFF, 0, 0);
95  }
96 
97  return 0;
98 }
99 
100 const struct st_device sound_device = {
101  .name = "sound",
102  .explan = "Buzzer sound control",
103  .register_dev = sound_register,
104  .unregister_dev = sound_unregister,
105  .open = sound_open,
106  .close = sound_close,
107  .ioctl = sound_ioctl,
108 };
Buzzerドライバ ioctl 用マクロ定義
struct st_device * open_device(char *name)
デバイスをオープンする
Definition: device.c:262
int register_timer_func(timer_func func, unsigned long interval)
周期処理を追加する
Definition: timer.c:274
カーネルタイマ
#define IOCMD_BUZZER_OFF
ブザー音声出力停止
Definition: buzzer_ioctl.h:18
カーネル用機能限定printf
int unregister_timer_func(timer_func func)
周期処理を削除する
Definition: timer.c:300
#define IOCMD_BUZZER_ON
ブザー音声出力開始
Definition: buzzer_ioctl.h:17
unsigned long long get_kernel_time(void)
カーネル時間を取得する
Definition: timer.c:192
デバイスドライバAPI
デバイスドライバ構造体
Definition: device.h:25
カーネル、ドライバ(非タスク)デバッグ用マクロ
int ioctl_device(struct st_device *dev, unsigned int com, unsigned int arg, void *param)
デバイスを制御する
Definition: device.c:525
char name[MAX_DEVNAMELRN]
デバイス名文字列
Definition: device.h:26