Hardware Design: SIE
Sign in or create your account | Project List | Help
Hardware Design: SIE Git Source Tree
Root/
Source at commit acf516e created 13 years 6 months ago. By Carlos Camargo, Fixing some examples, adding scripts for compiling xilinx libs with ghdl | |
---|---|
1 | /* |
2 | JZ47xx GPIO at userspace |
3 | |
4 | Copyright (C) 2010 Andres Calderon andres.calderon@emqbit.com |
5 | |
6 | This program is free software; you can redistribute it and/or modify |
7 | it under the terms of the GNU General Public License as published by |
8 | the Free Software Foundation; either version 2 of the License, or |
9 | (at your option) any later version. |
10 | |
11 | This program is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | GNU General Public License for more details. |
15 | |
16 | You should have received a copy of the GNU General Public License |
17 | along with this program; if not, write to the Free Software |
18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ |
19 | |
20 | #include <stdio.h> |
21 | #include <stdlib.h> |
22 | #include <unistd.h> |
23 | |
24 | #include <jz47xx_gpio.h> |
25 | #include <jz47xx_mmap.h> |
26 | |
27 | |
28 | #define JZ_GPIO_BASE 0x10010000 |
29 | |
30 | void |
31 | jz_gpio_as_output (JZ_PIO * pio, unsigned int o) |
32 | { |
33 | pio->PXFUNC = (1 << (o)); |
34 | pio->PXSELC = (1 << (o)); |
35 | pio->PXDIRS = (1 << (o)); |
36 | } |
37 | |
38 | void |
39 | jz_gpio_as_input (JZ_PIO * pio, unsigned int o) |
40 | { |
41 | pio->PXFUNC = (1 << (o)); |
42 | pio->PXSELC = (1 << (o)); |
43 | pio->PXDIRC = (1 << (o)); |
44 | } |
45 | |
46 | void |
47 | jz_gpio_as_irq (JZ_PIO * pio, unsigned int o) |
48 | { |
49 | pio->PXFUNC = (1 << (o)); |
50 | pio->PXSELS = (1 << (o)); |
51 | pio->PXDIRC = (1 << (o)); |
52 | } |
53 | |
54 | void |
55 | jz_gpio_set_pin (JZ_PIO * pio, unsigned int o) |
56 | { |
57 | pio->PXDATS = (1 << (o)); |
58 | } |
59 | |
60 | void |
61 | jz_gpio_clear_pin (JZ_PIO * pio, unsigned int o) |
62 | { |
63 | pio->PXDATC = (1 << (o)); |
64 | } |
65 | |
66 | void |
67 | jz_gpio_out (JZ_PIO * pio, unsigned int o, unsigned int val) |
68 | { |
69 | if (val == 0) |
70 | pio->PXDATC = (1 << (o)); |
71 | else |
72 | pio->PXDATS = (1 << (o)); |
73 | } |
74 | |
75 | unsigned int |
76 | jz_gpio_get_pin (JZ_PIO * pio, unsigned int o) |
77 | { |
78 | return (pio->PXPIN & (1 << o)) ? 1 : 0; |
79 | } |
80 | |
81 | int |
82 | jz_gpio_as_func (JZ_PIO * pio, unsigned int o, int func) |
83 | { |
84 | switch (func) |
85 | { |
86 | case 0: |
87 | pio->PXFUNS = (1 << o); |
88 | pio->PXTRGC = (1 << o); |
89 | pio->PXSELC = (1 << o); |
90 | pio->PXPES = (1 << o); |
91 | return 1; |
92 | |
93 | case 1: |
94 | pio->PXFUNS = (1 << o); |
95 | pio->PXTRGC = (1 << o); |
96 | pio->PXSELS = (1 << o); |
97 | pio->PXPES = (1 << o); |
98 | return 1; |
99 | |
100 | case 2: |
101 | pio->PXFUNS = (1 << o); |
102 | pio->PXTRGS = (1 << o); |
103 | pio->PXSELC = (1 << o); |
104 | pio->PXPES = (1 << o); |
105 | return 1; |
106 | } |
107 | return 0; |
108 | } |
109 | |
110 | JZ_PIO * |
111 | jz_gpio_map (int port) |
112 | { |
113 | JZ_PIO *pio; |
114 | |
115 | pio = (JZ_PIO *) jz_mmap (JZ_GPIO_BASE); |
116 | pio = (JZ_PIO *) ((unsigned int) pio + port * 0x100); |
117 | |
118 | return pio; |
119 | } |
120 |
Branches:
master