Hardware Design: SIE
Sign in or create your account | Project List | Help
Hardware Design: SIE Git Source Tree
Root/
Source at commit 9d578912b727722b22319832985451a79ec35747 created 13 years 27 days ago. By Juan64Bits, Updating prototype of SIE code generator. | |
---|---|
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_set_pin (JZ_PIO * pio, unsigned int o) |
48 | { |
49 | pio->PXDATS = (1 << (o)); |
50 | } |
51 | |
52 | void |
53 | jz_gpio_clear_pin (JZ_PIO * pio, unsigned int o) |
54 | { |
55 | pio->PXDATC = (1 << (o)); |
56 | } |
57 | |
58 | void |
59 | jz_gpio_out (JZ_PIO * pio, unsigned int o, unsigned int val) |
60 | { |
61 | if (val == 0) |
62 | pio->PXDATC = (1 << (o)); |
63 | else |
64 | pio->PXDATS = (1 << (o)); |
65 | } |
66 | |
67 | unsigned int |
68 | jz_gpio_get_pin (JZ_PIO * pio, unsigned int o) |
69 | { |
70 | return (pio->PXPIN & (1 << o)) ? 1 : 0; |
71 | } |
72 | |
73 | int |
74 | jz_gpio_as_func (JZ_PIO * pio, unsigned int o, int func) |
75 | { |
76 | switch (func) |
77 | { |
78 | case 0: |
79 | pio->PXFUNS = (1 << o); |
80 | pio->PXTRGC = (1 << o); |
81 | pio->PXSELC = (1 << o); |
82 | return 1; |
83 | |
84 | case 1: |
85 | pio->PXFUNS = (1 << o); |
86 | pio->PXTRGC = (1 << o); |
87 | pio->PXSELS = (1 << o); |
88 | return 1; |
89 | |
90 | case 2: |
91 | pio->PXFUNS = (1 << o); |
92 | pio->PXTRGS = (1 << o); |
93 | pio->PXSELC = (1 << o); |
94 | return 1; |
95 | } |
96 | return 0; |
97 | } |
98 | |
99 | JZ_PIO * |
100 | jz_gpio_map (int port) |
101 | { |
102 | JZ_PIO *pio; |
103 | |
104 | pio = (JZ_PIO *) jz_mmap (JZ_GPIO_BASE); |
105 | pio = (JZ_PIO *) ((unsigned int) pio + port * 0x100); |
106 | |
107 | return pio; |
108 | } |
109 |
Branches:
master