linux gpio_to_irq()源码分析

本文详细解析了Linux系统中从GPIO编号转换到软件中断号的机制,介绍了gpio_to_irq()函数的工作原理,深入分析了其内部实现过程,包括gpio_to_desc()和gpiod_to_irq()的调用流程。
【版权申明】未经博主同意,谢绝转载!(请尊重原创,博主保留追究权) 

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
 */
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

安河桥

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值