代码查看:
我们直接看代码
1. - #define S3C2410_GPBCON S3C2410_GPIOREG(0x10)
- #define S3C2410_GPBDAT S3C2410_GPIOREG(0x14)
- #define S3C2410_GPBUP S3C2410_GPIOREG(0x18)
等同于:
#define S3C2410_GPBCON (*(volatile unsigned long *)0x56000010)
#define S3C2410_GPBDAT (*(volatile unsigned long *)0x56000014)
#define S3C2410_GPBUP (*(volatile unsigned long *)0x56000018) 这里,我们自己定义 3 个寄存器的地址
S3C2410_GPIOREG定义在
- #define S3C2410_GPIOREG(x) ((x) + )
- #define S3C24XX_GPIOREG2(x) ((x) + S3C24XX_VA_GPIO2)
S3C24XX_VA_GPIO:定义在
- 72 #define S3C2410_PA_GPIO (0x56000000)
而在 S3C2440手册中,我们定义了
- 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
- #define S3C2410_GPBCON S3C2410_GPIOREG(0x10)
等同于
#define S3C2410_GPBCON (*volatile unsigned long *)(0x56000000+0x10) 2.设置管脚- #define S3C2410_GPB5 S3C2410_GPIONO(S3C2410_GPIO_BANKB, 5)
- #define S3C2410_GPB6 S3C2410_GPIONO(S3C2410_GPIO_BANKB, 6)
-
#define S3C2410_GPB7 S3C2410_GPIONO(S3C2410_GPIO_BANKB, 7)
-
#define S3C2410_GPB8 S3C2410_GPIONO(S3C2410_GPIO_BANKB, 8)
S3C2410_GPIONO 定义在:
- 17#define S3C2410_GPIONO(bank,offset) ((bank) + (offset))
- 18
- 19#define S3C2410_GPIO_BANKA (32*0)
- 20#define S3C2410_GPIO_BANKB (32*1) 有疑问??
3. 设置输出管脚- #define S3C2410_GPB5_OUTP (0x01 << 10)
-
#define S3C2410_GPB6_OUTP (0x01 << 12)
-
#define S3C2410_GPB7_OUTP (0x01 << 14)
-
#define S3C2410_GPB8_OUTP (0x01 << 16)
在 S3C2440 手册中定义了,
当为 01 时,表示输出功能- GPB8 [17:16] 00 = Input 01 = Output
-
10 = nXDREQ1 11 = Reserved
-
- GPB7 [15:14] 00 = Input 01 = Output
-
10 = nXDACK1 11 = Reserved
- GPB6 [13:12] 00 = Input 01 = Output
-
10 = nXBREQ 11 = reserved
- GPB5 [11:10] 00 = Input 01 = Output
-
10 = nXBACK 11 = reserved
4.设置 - static unsigned long gpio_table [] =
- {
-
S3C2410_GPB(5),
-
S3C2410_GPB(6),
-
S3C2410_GPB(7),
-
S3C2410_GPB(8),
-
};
在哪里定义了
S3C2410_GPB(5)呢??- 60 /* S3C2410 GPIO number definitions. */
- 61
- 62 #define S3C2410_GPA(_nr) (S3C2410_GPIO_A_START + (_nr))
- 63 #define S3C2410_GPB(_nr) (S3C2410_GPIO_B_START + (_nr))
- enum s3c_gpio_number {
- 48 S3C2410_GPIO_A_START = 0, ?? 是虚拟内存,映射实现?? 第一个地址 0
- 49 S3C2410_GPIO_B_START = S3C2410_GPIO_NEXT(S3C2410_GPIO_A), 32+0吗??
- 50 S3C2410_GPIO_C_START = S3C2410_GPIO_NEXT(S3C2410_GPIO_B),
S3C2410_GPB(5) () 0x56000010+
5 管脚设置- s3c2410_gpio_setpin(gpio_table[arg], 0);
::::
s3c2410_gpio_setpin(
S3C2410_GPB(5),0); s3c2410_gpio_setpin 定义在:- 99 extern int s3c2410_gpio_getpull(unsigned int pin);
-
100
-
101 extern void s3c2410_gpio_setpin(unsigned int pin, unsigned int to);
-
102
-
103 extern unsigned int s3c2410_gpio_getpin(unsigned int pin);
s3c2410_gpio_setpin 代码实现在:- void s3c2410_gpio_setpin(unsigned int pin, unsigned int to)
-
140 {
-
141 void __iomem *base = S3C24XX_GPIO_BASE(pin);
-
142 unsigned long offs = S3C2410_GPIO_OFFSET(pin);
-
143 unsigned long flags;
-
144 unsigned long dat;
-
145
-
146 local_irq_save(flags);
-
147
-
148 dat = __raw_readl(base + 0x04);
-
149 dat &= ~(1 << offs);
-
150 dat |= to << offs;
-
151 __raw_writel(dat, base + 0x04);
-
152
-
153 local_irq_restore(flags);
-
154 }
-
155
-
156 EXPORT_SYMBOL(s3c2410_gpio_setpin);
不知道 怎么实现的 ????
6 上网看看资料,以后补充
阅读(1816) | 评论(0) | 转发(1) |