Sag*_*ain 5 c linux interrupt linux-device-driver embedded-linux
在函数声明中
int request_irq(unsigned int irq,
irqreturn_t (*handler)(int, void *, struct pt_regs *),
unsigned long irqflags,
const char *devname,
void *dev_id);
Run Code Online (Sandbox Code Playgroud)
是dev_id“in”参数还是“out”参数?我们从哪里得到这个数字?
Dev_id是一个输入参数,并且必须是全局唯一的。通常使用设备数据结构的地址作为Dev_id。如果中断线不共享,则
它有价值。NULL仅当共享中断线时它才有意义。当共享时,该参数唯一标识interrupt handler共享IRQ。
但最近为了更快地处理中断,Linux 内核已迁移到request_threaded_irq.
例如,在 Linux 内核中,wm8903 音频编解码器的 i2c 驱动程序按以下方式使用此 API - 使用request_threaded_irq()但 dev_id 的使用是相同的。
设备结构是:
117 struct wm8903_priv {
118 struct wm8903_platform_data *pdata;
119 struct device *dev;
120 struct snd_soc_codec *codec;
121 struct regmap *regmap;
122
123 int sysclk;
124 int irq;
125
126 int fs;
127 int deemph;
128
129 int dcs_pending;
130 int dcs_cache[4];
131
132 /* Reference count */
133 int class_w_users;
134
135 struct snd_soc_jack *mic_jack;
136 int mic_det;
137 int mic_short;
138 int mic_last_report;
139 int mic_delay;
140
141 #ifdef CONFIG_GPIOLIB
142 struct gpio_chip gpio_chip;
143 #endif
144 };
Run Code Online (Sandbox Code Playgroud)
处理程序定义了一个指向该结构的指针:
2029 struct wm8903_priv *wm8903; //this is the dev_id parameter
Run Code Online (Sandbox Code Playgroud)
然后调用request_threaded_irq(),
ret = request_threaded_irq(i2c->irq, NULL, wm8903_irq,
2156 trigger | IRQF_ONESHOT,
2157 "wm8903", wm8903);
Run Code Online (Sandbox Code Playgroud)