【版权申明】未经博主同意,谢绝转载!(请尊重原创,博主保留追究权)
linux gpio_to_irq()源码分析
背景说明:
在Linux设备树(linux 3.x版本引入)中, 设备的中断号不再在"irq.h"中硬编码定义, 而是在需要时自己手动去申请获得对应的硬件中断的软件中断号.( 前提是GPIO的相关模块已经被编入内核 )
1. gpio_to_irq()的函数作用
/**
* include/linux/gpio.h
*
* @param gpio 为要操作的GPIO编号, 该编号等于GPIO组号*8 + 组内偏移号, 例如GPIO4_2的编号为4*8 + 2 = 34 (每组GPIO有8个GPIO管脚)
*/
static inline int gpio_to_irq(unsigned int gpio)
{
return __gpio_to_irq(gpio);
}
通过GPIO号得到对应的软件中断号, 该中断号是request_irq()函数的第一个参数.
2. gpio_to_irq()的源码分析
/**
* include/asm-generic/gpio.h
*/
static inline int __gpio_to_irq(unsigned gpio)
{
return gpiod_to_irq(gpio_to_desc(gpio));
}
2.1 首先, 我们来看看gpio_to_desc(gpio)的含义:
/**
* list_for_each_entry - iterate over list of given type
迭代给定类型的列表, head为typeof(*pos)结构体中的其中一员且为一个双向链表, 我们通过
遍历这个链表循环得到每一个typeof(*pos)结构体.
* @pos: the type * to use as a loop cursor.
用作循环游标, 每一次得到typeof(*pos)类型的变量.
* @head: the head for your list.
列表头, 该变量为typeof(*pos)结构体中的其中一员.
* @member: the name of the list_head within the struct.
在结构体中list_head的名称
*/
#define list_for_each_entry(pos, head, member) \
for (pos = list_first_entry(head, typeof(*pos), member); \
&pos->member != (head); \
pos = list_next_entry(pos, member))
/**
* Convert a GPIO number to its descriptor
*/

本文详细解析了Linux系统中从GPIO编号转换到软件中断号的机制,介绍了gpio_to_irq()函数的工作原理,深入分析了其内部实现过程,包括gpio_to_desc()和gpiod_to_irq()的调用流程。
最低0.47元/天 解锁文章
4922

被折叠的 条评论
为什么被折叠?



