ARM Linux下访问GPIO端口
0(0x02 < 0)
#define S3C2400_GPB0_DATA16(0x02 < 0)
*******************************************************************************
#define S3C2410_GPCCON S3C2410_GPIOREG(0x20)
#define S3C2410_GPCDAT S3C2410_GPIOREG(0x24)
#define S3C2410_GPCUP S3C2410_GPIOREG(0x28)
#define S3C2410_GPC0S3C2410_GPIONO(S3C2410_GPIO_BANKC, 0)
#define S3C2410_GPC0_INP (0x00< 0)
#define S3C2410_GPC0_OUTP (0x01< 0)
#define S3C2410_GPC0_LEND (0x02< 0)
#define S3C2400_GPC0_VD0 (0x02< 0)
*******************************************************************************
#define S3C2410_GPDCON S3C2410_GPIOREG(0x30)
#define S3C2410_GPDDAT S3C2410_GPIOREG(0x34)
#define S3C2410_GPDUP S3C2410_GPIOREG(0x38)
— Port A(GPA): 25-output port — Port B(GPB): 11-input/out 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): 9-input/output port — Port J(GPJ): 13-input/output port Register Address R/W Description Reset Value GPACON 0x56000000 R/W Configures the pins of port A 0xffffff GPADAT 0x56000004 R/W The data register for port A Undef. Reserved 0x56000008 – Reserved Undef Reserved 0x5600000c – Reserved Undef Register Address R/W Description Reset Value GPBCON 0x56000010 R/W Configures the pins of port B 0x0 GPBDAT 0x56000014 R/W The data register for port B Undef. GPBUP 0x56000018 R/W Pull-up disable register for port B 0x0 Reserved 0x5600001c Register Address R/W Description Reset Value GPCCON 0x56000020 R/W Configures the pins of port C 0x0 GPCDAT 0x56000024 R/W The data register for port C Undef. GPCUP 0x56000028 R/W Pull-up disable register for port C 0x0 Reserved 0x5600002c – – – Register Address R/W Description Reset Value GPDCON 0x56000030 R/W Configures the pins of port D 0x0 GPDDAT 0x56000034 R/W The data register for port D Undef. GPDUP 0x56000038 R/W Pull-up disable register for port D 0xf000 Reserved 0x5600003c – – – |
*******************************************************************************
void s3c2410_gpio_cfgpin(unsignedint pin, unsigned int function)// 其中参数pin是要配置的GPIO引脚,参数function是要配置的功能
{
void __iomem *base = S3C24XX_GPIO_BASE(pin);
unsignedlong mask;
unsignedlong con;
unsignedlong flags;
if(pin < S3C2410_GPIO_BANKB){
mask= 1 < S3C2410_GPIO_OFFSET(pin);
}else {
mask= 3 < S3C2410_GPIO_OFFSET(pin)*2;
}
//如果引脚为A端口之外GPIO端口时,它是用两位来配置具体的引脚,故掩码为2位
switch(function) {
caseS3C2410_GPIO_LEAVE:
mask= 0;
function= 0;
break;
caseS3C2410_GPIO_INPUT:
caseS3C2410_GPIO_OUTPUT:
caseS3C2410_GPIO_SFN2:
caseS3C2410_GPIO_SFN3:
if(pin < S3C2410_GPIO_BANKB){
function-= 1;
function&= 1;
function<= S3C2410_GPIO_OFFSET(pin);
}else {
function&= 3;
function<= S3C2410_GPIO_OFFSET(pin)*2;
}
}
/* modify thespecified register wwith IRQs off */
local_irq_save(flags);// 关中断
con= __raw_readl(base + 0x00);
con &= ~mask;
con |= function;
__raw_writel(con, base + 0x00);
local_irq_restore(flags);// 开中断
}
arch/arm/mach-s3c2410/include/mach/regs-gpio.h
#define S3C2410_GPIO_BASE(pin)((((pin) & ~31) >> 1) + S3C24XX_VA_GPIO)
//每组GPIO的虚拟基地址(要先屏蔽最低的5位)根据端口编号pin,算出端口所在组的虚拟基址。((pin) & ~31)是去掉pin当中小于等于31的零头(清0低5位),>>1的原因是每组GPIO中最多可以有32个端口,控制这些端口需要4个寄存器空间,4个寄存器空间就需要4*4=16个字节进行编址,32/16=2,左移一位刚好满足。也就是说,上一组端口和下一组端口的编号相差32,而控制寄存器的地址相差16。
#define S3C2410_GPIO_OFFSET(pin) ((pin) & 31)
//根据端口编号pin,算出端口所在组的偏移量。((pin) & 31)即去掉比31大的数
linux/arch
ARMLinuxGPIO端 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)