GadgetSeed  0.9.6
device.h
[詳解]
1 /** @file
2  @brief デバイスドライバAPI
3 
4  @date 2007.03.18
5  @author Takashi SHUDO
6 */
7 
8 #ifndef DEVICE_H
9 #define DEVICE_H
10 
11 #include "task/mutex.h"
12 
13 // 推奨デバイス名
14 #define DEF_DEV_NAME_INPUT "input" // キーボード、ボタン等入力デバイス
15 #define DEF_DEV_NAME_LED "led" // LED等
16 #define DEF_DEV_NAME_EEPRMOM "eeprom" // EEPROM
17 
18 #define MAX_DEVNAMELRN 10
19 
20 // seek() whence の値
21 #define SEEK_SET 0 ///< 設定
22 #define SEEK_CUR 1 ///< 現在値に加算
23 #define SEEK_END 2 ///< ファイルサイズに加算
24 
25 struct st_device {
26  char name[MAX_DEVNAMELRN]; ///< デバイス名文字列
27  char explan[32]; ///< デバイス説明文字列
28  void *info; ///< デバイス情報データポインタ
29  void *private_data; ///< ドライバ固有データポインタ
30  struct st_mutex *mutex; ///< デバイス排他アクセス用MUTEX
31  int (* register_dev)(struct st_device *dev, char *param);
32  int (* unregister_dev)(struct st_device *dev);
33  int (* lock)(struct st_device *dev, unsigned int timeout);
34  int (* unlock)(struct st_device *dev);
35  int (* open)(struct st_device *dev);
36  int (* close)(struct st_device *dev);
37  int (* read)(struct st_device *dev, void *buf, unsigned int count);
38  int (* getc)(struct st_device *dev, unsigned char *buf);
39  int (* write)(struct st_device *dev, const void *buf, unsigned int count);
40  int (* putc)(struct st_device *dev, unsigned char data);
41  int (* ioctl)(struct st_device *dev, unsigned int com, unsigned int arg, void *param);
42  int (* seek)(struct st_device *dev, int offset, int whence);
43  int (* block_read)(struct st_device *dev, void *buf, unsigned int sector, unsigned int blkcount);
44  int (* block_write)(struct st_device *dev, const void *buf, unsigned int sector, unsigned int blkcount);
45  int (* sync)(struct st_device *dev);
46  int (* select)(struct st_device *dev, unsigned int timeout);
47  int (* suspend)(struct st_device *dev);
48  int (* resume)(struct st_device *dev);
49 }; ///< デバイスドライバ構造体
50 
51 void init_device_list(void);
52 extern int device_num(void);
53 extern const char * device_name(int num);
54 extern const char * device_explan(int num);
55 extern int register_device(const struct st_device *dev, char *param);
56 extern int unregister_device(const struct st_device *dev);
57 extern int lock_device(struct st_device *dev, unsigned int timeout);
58 extern int unlock_device(struct st_device *dev);
59 extern struct st_device * open_device(char *name);
60 extern int close_device(struct st_device *dev);
61 extern int read_device(struct st_device *dev, void *buf, unsigned int count);
62 extern int getc_device(struct st_device *dev, unsigned char *data);
63 extern int write_device(struct st_device *dev, const void *buf, unsigned int count);
64 extern int putc_device(struct st_device *dev, unsigned char data);
65 extern int ioctl_device(struct st_device *dev, unsigned int com, unsigned int arg, void *param);
66 extern int seek_device(struct st_device *dev, int offset, int whence);
67 extern int block_read_device(struct st_device *dev, void *buf, unsigned int sector, unsigned int blkcount);
68 extern int block_write_device(struct st_device *dev, const void *buf, unsigned int sector, unsigned int blkcount);
69 extern int sync_device(struct st_device *dev);
70 extern int select_device(struct st_device *dev, unsigned int timeout);
71 extern int suspend_device(struct st_device *dev);
72 extern int resume_device(struct st_device *dev);
73 
74 extern int suspend(void);
75 extern int resume(void);
76 
77 #endif // DEVICE_H
void * info
デバイス情報データポインタ
Definition: device.h:28
struct st_mutex * mutex
デバイス排他アクセス用MUTEX
Definition: device.h:30
int block_write_device(struct st_device *dev, const void *buf, unsigned int sector, unsigned int blkcount)
デバイスにブロックデータを書き込む
Definition: device.c:483
void init_device_list(void)
デバイスドライバリストを初期化する
Definition: device.c:99
struct st_device * open_device(char *name)
デバイスをオープンする
Definition: device.c:262
void * private_data
ドライバ固有データポインタ
Definition: device.h:29
int write_device(struct st_device *dev, const void *buf, unsigned int count)
デバイスにデータを書き込む
Definition: device.c:451
int read_device(struct st_device *dev, void *buf, unsigned int count)
デバイスよりデータを読み出す
Definition: device.c:378
const char * device_name(int num)
デバイス名を取得する
Definition: device.c:132
int seek_device(struct st_device *dev, int offset, int whence)
デバイスのアクセスポイントを設定する
Definition: device.c:545
int unregister_device(const struct st_device *dev)
デバイスを削除する
Definition: device.c:225
int resume_device(struct st_device *dev)
デバイスを活性化する
Definition: device.c:618
int sync_device(struct st_device *dev)
デバイスの書き込みデータの同期をとる
Definition: device.c:563
const char * device_explan(int num)
デバイス説明を取得する
Definition: device.c:154
int unlock_device(struct st_device *dev)
デバイスをアンロックする
Definition: device.c:343
int getc_device(struct st_device *dev, unsigned char *data)
デバイスよりデータを1バイト読み出す
Definition: device.c:429
MUTEX
Definition: mutex.h:13
int putc_device(struct st_device *dev, unsigned char data)
デバイスにデータを1バイト書き込む
Definition: device.c:502
int suspend_device(struct st_device *dev)
デバイスを休止状態にする
Definition: device.c:600
char explan[32]
デバイス説明文字列
Definition: device.h:27
int device_num(void)
登録されているデバイス数を取得する
Definition: device.c:113
MUTEX制御
int select_device(struct st_device *dev, unsigned int timeout)
デバイスのアクセス準備完了を待つ
Definition: device.c:582
int close_device(struct st_device *dev)
デバイスをクローズする
Definition: device.c:291
デバイスドライバ構造体
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
int block_read_device(struct st_device *dev, void *buf, unsigned int sector, unsigned int blkcount)
デバイスよりブロックデータを読み出す
Definition: device.c:410
int lock_device(struct st_device *dev, unsigned int timeout)
デバイスをロックする
Definition: device.c:310