GPIO ????? - PowerPoint PPT Presentation

About This Presentation
Title:

GPIO ?????

Description:

gpio pxa270 gpio gpio gpio pxa270 gpio – PowerPoint PPT presentation

Number of Views:50
Avg rating:3.0/5.0
Slides: 22
Provided by: JwJo
Category:
Tags: gpio | gpcr

less

Transcript and Presenter's Notes

Title: GPIO ?????


1
GPIO ?????
  • PXA270? GPIO
  • GPIO ??? GPIO ???? ??
  • PXA270? ????
  • ???? ?? ??
  • GPIO? ??? ???? ????

2
PXA270? GPIO
  • PXA270? GPIO ??
  • GPIO(General Purpose Input Output)? ??? ?? ???
    ???? ???? ????? ?? ????? ??? ? ?? ???? ?? ?? ???
    ??
  • PXA270? 121?? GPIO ??? ???? ? ? 119?? ??.
  • ? ??? ?? ?? ???? ????? ?? ??? ?? ????? ??. 32??
    ???? 36?? ???? ??.
  • GPIO ??? ???? ?????? ???? ??? ?? ??
  • ?? GPIO ??? ????? ?? ???? ??? ??(event)? ??

3
GPIO ???? 36?
4
GPIO ??? GPIO ????? ??

5
  • GPIO? ???? ?? ??

6
  • GPIO ????? ??
  • ??? ?? ?? ????(GPDR, GPIO Pin Direction Register)
  • GPIO port pins? ??? ?? ?? ?? ??? ??
  • ?? ??? 0?? ??, 1?? ??
  • ???? ?? ??? ?? ??? 0? ??
  • ?? ?? ????(GPSR, GPIO Pin Set Register) ? ?? ??
    ????(GPCR, GPIO Pin Clear Register)
  • GPDR? ??? ???? ??? ???? ??
  • ?? GPDR? ?? ??? 0?? ???? ?? ?? ???
  • GPSR ?? GPCR? ?? ??? 1? ?? ?? output pin? set ??
    clear
  • GPSR ?? GPCR? ??? ??? 0? ?? ?? ???
  • write-only register
  • ?? ?? ?? ?? ????(GRER, GPIO Rising Edge Detect
    Enable Register) ? ?? ?? ?? ?? ????(GFER, GPIO
    Falling Edge Detect Enable Register)
  • ? GPIO port? ????(rising edge) ?? ????(falling
    edge)? ??? ??? ? ??? ???? ??
  • GPIO ?? ??(transition) ??? ??
  • edge? ???? status bit? set
  • status bits ? ??? set? ? ????? CPU? ??? ?? ????
    ??? ???????? ????? ? ??

7
  • GPIO ????? ??(??)
  • ?? ?? ?? ????(GEDR, GPIO Edge Detect Status
    Register)
  • GRER ?? GFER? ????? ? ??
  • ?? ??? 1?? GRER ?? GFER? ?? ???? ?? ????? ???
    ????? ??
  • ?? ?? ?? ?? ????(GAFR, GPIO Alternate Function
    Register)
  • ?? ??? 0?? ???? pin? ???? I/O, 1?? ????
  • ?? ??? ??? ??? Intel?, PXA27x Processor Family
    Developers Manual, 2004 ??
  • ?? ?? ?? ????(GPLR, GPIO Pin Level Register)
  • ??? GPIO port pin? ?? ?? ??? ??, ? ?? pin? ???
    low ?? high?? ??
  • read-only register

8
???? ???? ?? ??
  • ???? ???? ?? ??

9
PXA270? ???? ??
  • PXA270? ???? ??

10
  1. ICCR? ?? ???? ????? IDLE ???? ??. ?? ICMR? ?? ???
    ????? ????? ??. ?, ???? ???? ???? ???? ??? ????
    ?.
  2. ????? ???? ICPR? ? ??? ???. ???? ??? ????? ???
    ??? ????? ??.
  3. ??? ????? ?? ??? ????? AND ??? ??. ?, ??? ?????
    ?? ?? ???? ??? ?.
  4. ICLR? ??? ??? ????? IRQ ?? FIQ?? ??.
  5. ??? ????? IRQ ???? ICIP, FIQ ???? ICFP? ?? ???
    ??. ??? ICIP? ICFP? ??? ??? ????? ??? ? ? ??.
  6. ???? ???? ???(peripheral priority processor)?
    IPR? ???? ?? ????? ????? ???? ???? ???? ????? ??
    ICHP? ??.
  7. ???? ??? ICHP? ???? ?? ?? ????? ????? ??

11
  • ???? ?? ????(CPSR, Current Program Status
    Register)
  • IRQ ???? ??? ??? ?? ?? ??

01 R14_irq lt?? ??? ??gt 4 02 SPSR_irq CPSR 03 CPSR05 0b010010 04 CPSR6 unchanged 05 CPSR7 1 06 PC 0x18
12
  • ??? ??? IRQ ???? ??

13
  • ICPR ????? IRQ ?? ??(ltlinuxgt/include/asm-arm/arch-
    pxa/irqs.h)

define IRQ_SSP3 PXA_IRQ(0) / SSP3 service request / define IRQ_MSL PXA_IRQ(1) / MSL Interface interrupt / define IRQ_USBH2 PXA_IRQ(2) / USB Host interrupt 1 (OHCI) / define IRQ_USBH1 PXA_IRQ(3) / USB Host interrupt 2 (non-OHCI) / define IRQ_KEYPAD PXA_IRQ(4) / Key pad controller / define IRQ_MEMSTK PXA_IRQ(5) / Memory Stick interrupt / define IRQ_PWRI2C PXA_IRQ(6) / Power I2C interrupt / define IRQ_HWUART PXA_IRQ(7) / HWUART Transmit/Receive/Error(PXA26x) / define IRQ_OST_4_11 PXA_IRQ(7) / OS timer 4-11 matches (PXA27x) / define IRQ_GPIO0 PXA_IRQ(8) / GPIO0 Edge Detect / define IRQ_GPIO1 PXA_IRQ(9) / GPIO1 Edge Detect / define IRQ_GPIO_2_x PXA_IRQ(10) / GPIO2-x Edge Detect / define IRQ_USB PXA_IRQ(11) / USB Service /
14
???? ?? ??
  • ???? ??? ??
  • ???? ?? ? ???

include ltlinux/interrupt.hgt int
request_irq(unsigned int irq, irqreturn_t
(handler)(int, void , struct pt_regs ),
unsigned long flags, const char device, void
dev_id) void free_irq(unsigned int irq, void
dev_id)
include ltlinux/sched.hgt // ?? ??? ??? ?? void
interruptible_sleep_on(struct wait_queue
q) void sleep_on(struct wait_queue q) //
?? ??? ????? ??? ?? void wake_up_interruptible(str
uct wait_queue q) void wake_up(struct
wait_queue q)
15
  • ???(wait queue) ??
  • ???? ??? ??
  • ?? ???? ?? ??
  • set_GPIO_IRQ_edge() GPIO ??? ??? ???? ?? ? ???
    ??? ??
  • set_irq_type() ???? ??? ??
  • pxa_gpio_mode() GPIO ?? ??
  • set_trap_gate() ????? ????? ??? ??
  • set_system_gate(), set_intr_gate() ?? ????? ??

DECLARE_WAIT_QUEUE_HEAD(wq)
include ltasm/irq.hgt void disable_irq(int irq) // ???? ?? void enable_irq(int irq) // ???? ??
16
  • ?? ??? X-HYPER270-TKU?? GPIO 35, 41, 36, 37? ???
    ???? 4?? GPIO ??? ?????? ??

17
?? GPIO ???? ???? ? ??? ???? ??
001 include ltlinux/module.hgt 016 define
IRQ_KEY1 IRQ_GPIO(35) 017 define IRQ_KEY2
IRQ_GPIO(41) 018 define IRQ_KEY3
IRQ_GPIO(36) 019 define IRQ_KEY4
IRQ_GPIO(37) 020 021 define LED_PHYS
0x12400000 022 023 static void mem_base 024
unsigned long mem_addr, mem_len 025 026 define
GPIO_MAJOR 241 027 define GPIO_NAME
"GPIO" 028 029 define GPIO_KEY_READ
0x1000 030 031 define GPIO_LED1_ON 0x2000 032
define GPIO_LED2_ON 0x2100 033 define
GPIO_LED3_ON 0x2200 034 define GPIO_LED4_ON
0x2300 038 char key_buf 039 char
led_on0xff 040 041 DECLARE_WAIT_QUEUE_HEAD(key_q
ueue) 042 043 int gpio_open(struct inode inode,
struct file filp) 044 045 printk("s\n",
__func__) 046 return 0 047 048 049 int
gpio_release(struct inode inode, struct file
filp) 050 051 printk("s\n", __func__) 052
return 0 053
18
?? GPIO ???? ???? ? ??? ???? ??
060 ssize_t gpio_read (struct file filp, char
buf, size_t count, loff_t f_pos) 061 062
interruptible_sleep_on ( key_queue) 063
copy_to_user( buf, key_buf, sizeof(key_buf)) 06
4 return 0 065 066 067 int gpio_ioctl(struct
inode inode, struct file filp, unsigned int
cmd, unsigned long arg) 068 069 int data
0 070 071 switch (cmd) 072 case
GPIO_LED1_ON 073 copy_from_user(data, (void
)arg, sizeof(data)) 074 if( data 0) 075
led_on 0x01 076 (((volatile
unsigned char )(mem_base))) led_on 077
else 078 led_on 0xfe 079
(((volatile unsigned char )(mem_base)))
led_on 080 break 081 case
GPIO_LED2_ON 110 111 return 0 112
113 114 static irqreturn_t key_interrupt(int
irq, void dev_id, struct pt_regs regs) 115
116 if(GPLR1 GPIO_bit(35)) 117 key_buf
1 118 if(GPLR1 GPIO_bit(41)) 119 key_buf
2 120 if(GPLR1 GPIO_bit(36)) 121 key_buf
3 122 if(GPLR1 GPIO_bit(37)) 123 key_buf
4 124 wake_up_interruptible(key_queue) 125
return IRQ_HANDLED 126 127
19
?? GPIO ???? ???? ? ??? ???? ??
128 struct file_operations gpio_fops 129
.owner THIS_MODULE, 130 .open
gpio_open, 131 .read gpio_read, 132 .write
gpio_write, 133 .ioctl gpio_ioctl, 134
.release gpio_release, 135 136 137 static
int __init gpio_init(void) 138 139 int
result, ret 140 141 result
register_chrdev(GPIO_MAJOR, GPIO_NAME,
gpio_fops) 142 mem_addr LED_PHYS 143
mem_len 0x1000 144 mem_base
ioremap_nocache ( mem_addr, mem_len) 145 if(
!mem_base) 146 printk("Error mapping OHCI
memery\n") 147 release_mem_region(mem_addr,
mem_len) 148 return -EBUSY 149
(((volatile unsigned char )(mem_base)))
(0xFF) 150 set_irq_type(IRQ_KEY1,
IRQT_RISING) 153 set_irq_type(IRQ_KEY4,
IRQT_RISING) 154 if ((ret request_irq(IRQ_KEY
1, key_interrupt, SA_INTERRUPT, "GPIO35_KEY1",
NULL))) 155 printk("failed to register IRQ
KEY1\n") 156 return ret 157 166 if
((ret request_irq(IRQ_KEY4, key_interrupt,
SA_INTERRUPT, "GPIO37_KEY4", NULL))) 169
170 key_buf 0 171 printk("s MAJOR
d\n", GPIO_NAME, GPIO_MAJOR) 172 173 return
0 174
20
?? GPIO ???? ???? ? ??? ???? ??
176 static void __exit gpio_exit(void) 177 178
disable_irq(IRQ_KEY1) 179 free_irq(IRQ_KEY1,
NULL) 184 disable_irq(IRQ_KEY4) 185
free_irq(IRQ_KEY4, NULL) 186
unregister_chrdev(GPIO_MAJOR, GPIO_NAME) 187
188 MODULE_LICENSE("GPL") 189
module_init(gpio_init) 190 module_exit(gpio_exit)

21
?? GPIO ???? ???? ??? ???? ??
01 include ltstdio.hgt 06 define
GPIO_KEY_READ 0x1000 07 define GPIO_LED1_ON
0x2000 08 define GPIO_LED2_ON 0x2100 09 define
GPIO_LED3_ON 0x2200 10 define GPIO_LED4_ON
0x2300 11 12 static char gpio_testDev
"/dev/GPIO" 13 static int gpio_testFd -1 14
int ON 1 17 int main() 18 19 char
buf 20 21 if((gpio_testFd open(gpio_testDev,
O_RDWR )) lt 0) 22 perror("open failed
/dev/GPIO_TEST\n") 23 exit(-1) 24 25 26
while(1) 27 read(gpio_testFd , buf,
sizeof(buf)) 28 printf("KEY x PUSH
\n",buf) 29 ON 0x0001 30 switch(buf)
31 case 1 32 ioctl(gpio_testFd ,
GPIO_LED1_ON, ON) 33 break 34 case
2 43 default break 44 45 46
return 0 47
Write a Comment
User Comments (0)
About PowerShow.com