C8051F32x firmware infrastructure
Sign in or create your account | Project List | Help
C8051F32x firmware infrastructure Git Source Tree
Root/
1 | /* |
2 | * f32x/gpio-xburst.h - Really primitive XBurst GPIO access |
3 | * |
4 | * Written 2010 by Werner Almesberger |
5 | * Copyright 2010 Werner Almesberger |
6 | * |
7 | * This program is free software; you can redistribute it and/or modify |
8 | * it under the terms of the GNU General Public License as published by |
9 | * the Free Software Foundation; either version 2 of the License, or |
10 | * (at your option) any later version. |
11 | */ |
12 | |
13 | /* |
14 | * Ports are numbered 0 = A, 1 = B, ... |
15 | */ |
16 | |
17 | |
18 | #ifndef GPIO_XBURST_H |
19 | #define GPIO_XBURST_H |
20 | |
21 | |
22 | #include <stdint.h> |
23 | |
24 | |
25 | volatile void *mem; |
26 | |
27 | |
28 | #define REG(off) (*(volatile uint32_t *) (mem+(off))) |
29 | |
30 | #define port_pin(port) REG(port*0x100) |
31 | #define port_dats(port) REG(port*0x100+0x14) |
32 | #define port_datc(port) REG(port*0x100+0x18) |
33 | #define port_func(port) REG(port*0x100+0x48) |
34 | #define port_dirs(port) REG(port*0x100+0x64) |
35 | #define port_dirc(port) REG(port*0x100+0x68) |
36 | |
37 | |
38 | static inline void gpio_high(unsigned port, unsigned bit) |
39 | { |
40 | port_dats(port) = 1 << bit; |
41 | } |
42 | |
43 | |
44 | static inline void gpio_low(unsigned port, unsigned bit) |
45 | { |
46 | port_datc(port) = 1 << bit; |
47 | } |
48 | |
49 | |
50 | static inline void gpio_set(unsigned port, unsigned bit, int value) |
51 | { |
52 | if (value) |
53 | gpio_high(port, bit); |
54 | else |
55 | gpio_low(port, bit); |
56 | } |
57 | |
58 | |
59 | static inline int gpio_get(unsigned port, unsigned bit) |
60 | { |
61 | return (port_pin(port) >> bit) & 1; |
62 | } |
63 | |
64 | |
65 | static inline void gpio_output(unsigned port, unsigned bit) |
66 | { |
67 | port_dirs(port) = 1 << bit; |
68 | } |
69 | |
70 | |
71 | static inline void gpio_input(unsigned port, unsigned bit) |
72 | { |
73 | port_dirc(port) = 1 << bit; |
74 | } |
75 | |
76 | |
77 | void gpio_init(void); |
78 | |
79 | |
80 | #endif /* !GPIO_XBURST_H */ |
81 |
Branches:
master