Chinaunix首页 | 论坛 | 博客
  • 博客访问: 692307
  • 博文数量: 182
  • 博客积分: 2088
  • 博客等级: 大尉
  • 技术积分: 1698
  • 用 户 组: 普通用户
  • 注册时间: 2009-12-16 15:09
个人简介

.

文章分类

全部博文(182)

文章存档

2016年(1)

2015年(18)

2014年(14)

2013年(20)

2012年(129)

分类: 嵌入式

2012-06-15 20:29:32

/*************************************************************************
* GPIO (General-Purpose I/O Ports)
*************************************************************************/
#define MAX_GPIO_NUM 128
//n = 0,1,2,3
#define GPIO_PXPIN(n) (GPIO_BASE + (0x00 + (n)*0x100)) /* PIN Level Register */
#define GPIO_PXDAT(n) (GPIO_BASE + (0x10 + (n)*0x100)) /* Port Data Register */
#define GPIO_PXDATS(n) (GPIO_BASE + (0x14 + (n)*0x100)) /* Port Data Set Register */
#define GPIO_PXDATC(n) (GPIO_BASE + (0x18 + (n)*0x100)) /* Port Data Clear Register */
#define GPIO_PXIM(n) (GPIO_BASE + (0x20 + (n)*0x100)) /* Interrupt Mask Register */
#define GPIO_PXIMS(n) (GPIO_BASE + (0x24 + (n)*0x100)) /* Interrupt Mask Set Reg */
#define GPIO_PXIMC(n) (GPIO_BASE + (0x28 + (n)*0x100)) /* Interrupt Mask Clear Reg */
#define GPIO_PXPE(n) (GPIO_BASE + (0x30 + (n)*0x100)) /* Pull Enable Register */
#define GPIO_PXPES(n) (GPIO_BASE + (0x34 + (n)*0x100)) /* Pull Enable Set Reg. */
#define GPIO_PXPEC(n) (GPIO_BASE + (0x38 + (n)*0x100)) /* Pull Enable Clear Reg. */
#define GPIO_PXFUN(n) (GPIO_BASE + (0x40 + (n)*0x100)) /* Function Register */
#define GPIO_PXFUNS(n) (GPIO_BASE + (0x44 + (n)*0x100)) /* Function Set Register */
#define GPIO_PXFUNC(n) (GPIO_BASE + (0x48 + (n)*0x100)) /* Function Clear Register */
#define GPIO_PXSEL(n) (GPIO_BASE + (0x50 + (n)*0x100)) /* Select Register */
#define GPIO_PXSELS(n) (GPIO_BASE + (0x54 + (n)*0x100)) /* Select Set Register */
#define GPIO_PXSELC(n) (GPIO_BASE + (0x58 + (n)*0x100)) /* Select Clear Register */
#define GPIO_PXDIR(n) (GPIO_BASE + (0x60 + (n)*0x100)) /* Direction Register */
#define GPIO_PXDIRS(n) (GPIO_BASE + (0x64 + (n)*0x100)) /* Direction Set Register */
#define GPIO_PXDIRC(n) (GPIO_BASE + (0x68 + (n)*0x100)) /* Direction Clear Register */
#define GPIO_PXTRG(n) (GPIO_BASE + (0x70 + (n)*0x100)) /* Trigger Register */
#define GPIO_PXTRGS(n) (GPIO_BASE + (0x74 + (n)*0x100)) /* Trigger Set Register */
#define GPIO_PXTRGC(n) (GPIO_BASE + (0x78 + (n)*0x100)) /* Trigger Set Register */
#define GPIO_PXFLG(n) (GPIO_BASE + (0x80 + (n)*0x100)) /* Port Flag Register */
#define GPIO_PXFLGC(n) (GPIO_BASE + (0x14 + (n)*0x100)) /* Port Flag Clear Register */
#define REG_GPIO_PXPIN(n) REG32(GPIO_PXPIN((n))) /* PIN level */
#define REG_GPIO_PXDAT(n) REG32(GPIO_PXDAT((n))) /* 1: interrupt pending */
#define REG_GPIO_PXDATS(n) REG32(GPIO_PXDATS((n)))
#define REG_GPIO_PXDATC(n) REG32(GPIO_PXDATC((n)))
#define REG_GPIO_PXIM(n) REG32(GPIO_PXIM((n)))   /* 1: mask pin interrupt */
#define REG_GPIO_PXIMS(n) REG32(GPIO_PXIMS((n)))
#define REG_GPIO_PXIMC(n) REG32(GPIO_PXIMC((n)))
#define REG_GPIO_PXPE(n) REG32(GPIO_PXPE((n)))   /* 1: disable pull up/down */
#define REG_GPIO_PXPES(n) REG32(GPIO_PXPES((n)))
#define REG_GPIO_PXPEC(n) REG32(GPIO_PXPEC((n)))
#define REG_GPIO_PXFUN(n) REG32(GPIO_PXFUN((n))) /* 0:GPIO or intr, 1:FUNC */
#define REG_GPIO_PXFUNS(n) REG32(GPIO_PXFUNS((n)))
#define REG_GPIO_PXFUNC(n) REG32(GPIO_PXFUNC((n)))
#define REG_GPIO_PXSEL(n) REG32(GPIO_PXSEL((n))) /* 0:GPIO/Fun0,1:intr/fun1*/
#define REG_GPIO_PXSELS(n) REG32(GPIO_PXSELS((n)))
#define REG_GPIO_PXSELC(n) REG32(GPIO_PXSELC((n)))
#define REG_GPIO_PXDIR(n) REG32(GPIO_PXDIR((n))) /* 0:input/low-level-trig/falling-edge-trig, 1:output/high-level-trig/rising-edge-trig */
#define REG_GPIO_PXDIRS(n) REG32(GPIO_PXDIRS((n)))
#define REG_GPIO_PXDIRC(n) REG32(GPIO_PXDIRC((n)))
#define REG_GPIO_PXTRG(n) REG32(GPIO_PXTRG((n))) /* 0:level-trigger, 1:edge-trigger */
#define REG_GPIO_PXTRGS(n) REG32(GPIO_PXTRGS((n)))
#define REG_GPIO_PXTRGC(n) REG32(GPIO_PXTRGC((n)))
#define REG_GPIO_PXFLG(n) REG32(GPIO_PXFLG((n))) /* interrupt flag */
#define REG_GPIO_PXFLGC(n) REG32(GPIO_PXFLGC((n))) /* interrupt flag */

其中,REG_GPIO_PXPIN(port)
如果获得对于port2当中的某个pin的状态,如第6pin,那么第6pin的level为:
mask = 0x1UL<<6;
level = REG_GPIO_PXPIN(2) & mask;
另__gpio_get_pin(PIN_VALUE)是对上面操作的简化,则level = __gpio_get_pin(32*2+6);
(一些通用的gpio操作宏在ops.h内定义, 如:__gpio_as_input(n),__gpio_as_irq_fall_edge(n)等等)
在设置一些pin为输入时,如果其状态默认为high,可能还需要disable pull,则为:
__gpio_as_input(x);
__gpio_disable_pull(x);
阅读(1816) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~