曲径通幽论坛

标题: S3C2410 GPIO端口号在 linux 中的定义 [打印本页]

作者: beyes    时间: 2009-11-1 17:16
标题: S3C2410 GPIO端口号在 linux 中的定义
定义文件
include/asm-arm/arch/S3C2410.h

S3C2410 的引脚共有 8 组,分别为
— Port A (GPA): 23-output port
— Port B (GPB): 11-input/output port
— Port C (GPC): 16-input/output port
— Port D (GPD): 16-input/output port
— Port E (GPE): 16-input/output port
— Port F (GPF):   8-input/output port
— Port G (GPG): 16-input/output port
— Port H (GPH): 11-input/output port

比如, GPIO 中的第 C 组 (GPC) 中的第 8 个引脚,可用如下宏来表示
#define GPIO_C8                 MAKE_GPIO_NUM(PORTC_OFS, 8)

上面,MAKE_GPIO_NUM 是这么定义的
#define MAKE_GPIO_NUM(p, o)     ((p << GPIO_PORT_SHIFTT) | (o << GPIO_OFS_SHIFT))

其中,GPIO_PORT_SHIFT 和 GPIO_OFS_SHIFT 的定义为
#define GPIO_OFS_SHIFT             0
#define GPIO_PORT_SHIFTT        8

而 PORTx_OFS 的定义为(x 为端口的组编号)
#define PORTA_OFS               0
#define PORTB_OFS               1
#define PORTC_OFS               2
#define PORTD_OFS               3
#define PORTE_OFS               4
#define PORTF_OFS               5
#define PORTG_OFS               6
#define PORTH_OFS               7

代入数字,展开 GPIO_C8 的定义为
MAKE_GPIO_NUM(2, 8) 即:
( 2 << 8 | 8 << 0)

由此可以看到,GPIO 的定义如下图所示:





欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) Powered by Discuz! X3.2