Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4523747
  • 博文数量: 1148
  • 博客积分: 25453
  • 博客等级: 上将
  • 技术积分: 11949
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-06 21:14
文章分类

全部博文(1148)

文章存档

2012年(15)

2011年(1078)

2010年(58)

分类: 嵌入式

2011-04-24 14:30:13


代码查看:
我们直接看代码

1.

  1. #define S3C2410_GPBCON S3C2410_GPIOREG(0x10)
  2. #define S3C2410_GPBDAT S3C2410_GPIOREG(0x14)
  3. #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定义在    

  1. #define S3C2410_GPIOREG(x) ((x) + )
  2. #define S3C24XX_GPIOREG2(x) ((x) + S3C24XX_VA_GPIO2)
S3C24XX_VA_GPIO:定义在linux/include/asm-arm/plat-s3c24xx/map.h
  1. 72 #define S3C2410_PA_GPIO (0x56000000)

而在 S3C2440手册中,我们定义了

  1. Register Address R/W Description Reset Value

  2. GPBCON 0x56000010 R/W Configures the pins of port B 0x0

  3. GPBDAT 0x56000014 R/W The data register for port B Undef.

  4. GPBUP 0x56000018 R/W Pull-up disable register for port B
  1. #define S3C2410_GPBCON S3C2410_GPIOREG(0x10)
等同于
  #define S3C2410_GPBCON (*volatile unsigned long *)(0x56000000+0x10)



2.设置管脚

  1. #define S3C2410_GPB5 S3C2410_GPIONO(S3C2410_GPIO_BANKB, 5)
  2. #define S3C2410_GPB6 S3C2410_GPIONO(S3C2410_GPIO_BANKB, 6)
  3. #define S3C2410_GPB7 S3C2410_GPIONO(S3C2410_GPIO_BANKB, 7)
  4. #define S3C2410_GPB8 S3C2410_GPIONO(S3C2410_GPIO_BANKB, 8)
S3C2410_GPIONO 定义在:

  1. 17#define S3C2410_GPIONO(bank,offset) ((bank) + (offset))
  2. 18
  3. 19#define S3C2410_GPIO_BANKA (32*0)
  4. 20#define S3C2410_GPIO_BANKB (32*1)   有疑问??



3. 设置输出管脚
  1. #define S3C2410_GPB5_OUTP (0x01 << 10)
  2. #define S3C2410_GPB6_OUTP (0x01 << 12)
  3. #define S3C2410_GPB7_OUTP (0x01 << 14)
  4. #define S3C2410_GPB8_OUTP (0x01 << 16)
在 S3C2440 手册中定义了,当为 01 时,表示输出功能
  1. GPB8 [17:16] 00 = Input 01 = Output
  2.              10 = nXDREQ1 11 = Reserved

  3. GPB7 [15:14] 00 = Input 01 = Output
  4.              10 = nXDACK1 11 = Reserved

  5. GPB6 [13:12] 00 = Input 01 = Output
  6.              10 = nXBREQ 11 = reserved

  7. GPB5 [11:10] 00 = Input 01 = Output
  8.              10 = nXBACK 11 = reserved

4.设置
  1. static unsigned long gpio_table [] =
  2. {
  3.     S3C2410_GPB(5),
  4.     S3C2410_GPB(6),
  5.     S3C2410_GPB(7),
  6.     S3C2410_GPB(8),
  7. };
在哪里定义了 S3C2410_GPB(5)呢??
  1. 60    /* S3C2410 GPIO number definitions. */
  2. 61
  3. 62    #define S3C2410_GPA(_nr) (S3C2410_GPIO_A_START + (_nr))
  4. 63    #define S3C2410_GPB(_nr) (S3C2410_GPIO_B_START + (_nr))
  1.      enum s3c_gpio_number {
  2. 48   S3C2410_GPIO_A_START = 0,  ?? 是虚拟内存,映射实现?? 第一个地址 0
  3. 49   S3C2410_GPIO_B_START = S3C2410_GPIO_NEXT(S3C2410_GPIO_A),  32+0吗??
  4. 50   S3C2410_GPIO_C_START = S3C2410_GPIO_NEXT(S3C2410_GPIO_B),

 S3C2410_GPB(5) () 0x56000010+


5 管脚设置

  1. s3c2410_gpio_setpin(gpio_table[arg], 0);
::::
  s3c2410_gpio_setpin( S3C2410_GPB(5),0);
s3c2410_gpio_setpin 定义在:
  1. 99   extern int s3c2410_gpio_getpull(unsigned int pin);
  2. 100
  3. 101  extern void s3c2410_gpio_setpin(unsigned int pin, unsigned int to);
  4. 102
  5. 103  extern unsigned int s3c2410_gpio_getpin(unsigned int pin);
s3c2410_gpio_setpin 代码实现在:

  1.        void s3c2410_gpio_setpin(unsigned int pin, unsigned int to)
  2.  140   {
  3.  141      void __iomem *base = S3C24XX_GPIO_BASE(pin);
  4.  142      unsigned long offs = S3C2410_GPIO_OFFSET(pin);
  5.  143      unsigned long flags;
  6.  144      unsigned long dat;
  7.  145
  8.  146      local_irq_save(flags);
  9.  147
  10.  148      dat = __raw_readl(base + 0x04);
  11.  149      dat &= ~(1 << offs);
  12.  150      dat |= to << offs;
  13.  151      __raw_writel(dat, base + 0x04);
  14.  152
  15.  153     local_irq_restore(flags);
  16.  154  }
  17.  155
  18.  156  EXPORT_SYMBOL(s3c2410_gpio_setpin);

不知道 怎么实现的 ????





6 上网看看资料,以后补充


阅读(1816) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~