1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @ingroup lpc24xx_io |
---|
5 | * |
---|
6 | * @brief Input and output module. |
---|
7 | */ |
---|
8 | |
---|
9 | /* |
---|
10 | * Copyright (c) 2009 |
---|
11 | * embedded brains GmbH |
---|
12 | * Obere Lagerstr. 30 |
---|
13 | * D-82178 Puchheim |
---|
14 | * Germany |
---|
15 | * <rtems@embedded-brains.de> |
---|
16 | * |
---|
17 | * The license and distribution terms for this file may be |
---|
18 | * found in the file LICENSE in this distribution or at |
---|
19 | * http://www.rtems.com/license/LICENSE. |
---|
20 | */ |
---|
21 | |
---|
22 | #ifndef LIBBSP_ARM_LPC24XX_IO_H |
---|
23 | #define LIBBSP_ARM_LPC24XX_IO_H |
---|
24 | |
---|
25 | #include <rtems.h> |
---|
26 | |
---|
27 | #include <bsp/lpc24xx.h> |
---|
28 | |
---|
29 | #ifdef __cplusplus |
---|
30 | extern "C" { |
---|
31 | #endif /* __cplusplus */ |
---|
32 | |
---|
33 | /** |
---|
34 | * @defgroup lpc24xx_io IO Support and Configuration |
---|
35 | * |
---|
36 | * @ingroup lpc24xx |
---|
37 | * |
---|
38 | * @brief Input and output module. |
---|
39 | * |
---|
40 | * @{ |
---|
41 | */ |
---|
42 | |
---|
43 | #define LPC24XX_IO_PORT_COUNT 5U |
---|
44 | |
---|
45 | #define LPC24XX_IO_INDEX_MAX (LPC24XX_IO_PORT_COUNT * 32U) |
---|
46 | |
---|
47 | #define LPC24XX_IO_INDEX_BY_PORT( port, bit) (((port) << 5U) + (bit)) |
---|
48 | |
---|
49 | #define LPC24XX_IO_PORT( index) (index >> 5U) |
---|
50 | |
---|
51 | #define LPC24XX_IO_PORT_BIT( index) (index & 0x1fU) |
---|
52 | |
---|
53 | typedef enum { |
---|
54 | LPC24XX_MODULE_ACF, |
---|
55 | LPC24XX_MODULE_ADC, |
---|
56 | LPC24XX_MODULE_BAT_RAM, |
---|
57 | LPC24XX_MODULE_CAN, |
---|
58 | LPC24XX_MODULE_DAC, |
---|
59 | LPC24XX_MODULE_EMC, |
---|
60 | LPC24XX_MODULE_ETHERNET, |
---|
61 | LPC24XX_MODULE_GPDMA, |
---|
62 | LPC24XX_MODULE_GPIO, |
---|
63 | LPC24XX_MODULE_I2C, |
---|
64 | LPC24XX_MODULE_I2S, |
---|
65 | LPC24XX_MODULE_LCD, |
---|
66 | LPC24XX_MODULE_MCI, |
---|
67 | LPC24XX_MODULE_PCB, |
---|
68 | LPC24XX_MODULE_PWM, |
---|
69 | LPC24XX_MODULE_RTC, |
---|
70 | LPC24XX_MODULE_SPI, |
---|
71 | LPC24XX_MODULE_SSP, |
---|
72 | LPC24XX_MODULE_SYSCON, |
---|
73 | LPC24XX_MODULE_TIMER, |
---|
74 | LPC24XX_MODULE_UART, |
---|
75 | LPC24XX_MODULE_USB, |
---|
76 | LPC24XX_MODULE_WDT, |
---|
77 | LPC24XX_MODULE_COUNT |
---|
78 | } lpc24xx_module; |
---|
79 | |
---|
80 | typedef enum { |
---|
81 | LPC24XX_MODULE_PCLK_DEFAULT = 0x0U, |
---|
82 | LPC24XX_MODULE_CCLK = 0x1U, |
---|
83 | LPC24XX_MODULE_CCLK_2 = 0x2U, |
---|
84 | LPC24XX_MODULE_CCLK_4 = 0x0U, |
---|
85 | LPC24XX_MODULE_CCLK_6 = 0x3U, |
---|
86 | LPC24XX_MODULE_CCLK_8 = 0x3U |
---|
87 | } lpc24xx_module_clock; |
---|
88 | |
---|
89 | #define LPC24XX_MODULE_CLOCK_MASK 0x3U |
---|
90 | |
---|
91 | typedef enum { |
---|
92 | LPC24XX_GPIO_DEFAULT = 0x0U, |
---|
93 | LPC24XX_GPIO_RESISTOR_DEFAULT = 0x0U, |
---|
94 | LPC24XX_GPIO_RESISTOR_NONE = 0x1U, |
---|
95 | LPC24XX_GPIO_RESISTOR_PULL_UP = 0x2U, |
---|
96 | LPC24XX_GPIO_RESISTOR_PULL_DOWN = 0x3U, |
---|
97 | LPC24XX_GPIO_INPUT = 0x0U, |
---|
98 | LPC24XX_GPIO_OUTPUT = 0x8U |
---|
99 | } lpc24xx_gpio_settings; |
---|
100 | |
---|
101 | #define LPC24XX_GPIO_RESISTOR_MASK 0x3U |
---|
102 | |
---|
103 | rtems_status_code lpc24xx_module_enable( |
---|
104 | lpc24xx_module module, |
---|
105 | unsigned index, |
---|
106 | lpc24xx_module_clock clock |
---|
107 | ); |
---|
108 | |
---|
109 | rtems_status_code lpc24xx_module_disable( |
---|
110 | lpc24xx_module module, |
---|
111 | unsigned index |
---|
112 | ); |
---|
113 | |
---|
114 | rtems_status_code lpc24xx_io_config( |
---|
115 | lpc24xx_module module, |
---|
116 | unsigned index, |
---|
117 | unsigned config |
---|
118 | ); |
---|
119 | |
---|
120 | rtems_status_code lpc24xx_io_release( |
---|
121 | lpc24xx_module module, |
---|
122 | unsigned index, |
---|
123 | unsigned config |
---|
124 | ); |
---|
125 | |
---|
126 | rtems_status_code lpc24xx_gpio_config( |
---|
127 | unsigned index, |
---|
128 | lpc24xx_gpio_settings settings |
---|
129 | ); |
---|
130 | |
---|
131 | static inline void lpc24xx_gpio_set( unsigned index) |
---|
132 | { |
---|
133 | if (index <= LPC24XX_IO_INDEX_MAX) { |
---|
134 | unsigned port = LPC24XX_IO_PORT( index); |
---|
135 | unsigned bit = LPC24XX_IO_PORT_BIT( index); |
---|
136 | |
---|
137 | LPC24XX_FIO [port].set = 1U << bit; |
---|
138 | } |
---|
139 | } |
---|
140 | |
---|
141 | static inline void lpc24xx_gpio_clear( unsigned index) |
---|
142 | { |
---|
143 | if (index <= LPC24XX_IO_INDEX_MAX) { |
---|
144 | unsigned port = LPC24XX_IO_PORT( index); |
---|
145 | unsigned bit = LPC24XX_IO_PORT_BIT( index); |
---|
146 | |
---|
147 | LPC24XX_FIO [port].clr = 1U << bit; |
---|
148 | } |
---|
149 | } |
---|
150 | |
---|
151 | static inline void lpc24xx_gpio_write( unsigned index, bool value) |
---|
152 | { |
---|
153 | if (value) { |
---|
154 | lpc24xx_gpio_set( index); |
---|
155 | } else { |
---|
156 | lpc24xx_gpio_clear( index); |
---|
157 | } |
---|
158 | } |
---|
159 | |
---|
160 | static inline bool lpc24xx_gpio_get( unsigned index) |
---|
161 | { |
---|
162 | if (index <= LPC24XX_IO_INDEX_MAX) { |
---|
163 | unsigned port = LPC24XX_IO_PORT( index); |
---|
164 | unsigned bit = LPC24XX_IO_PORT_BIT( index); |
---|
165 | |
---|
166 | return (LPC24XX_FIO [port].pin & (1U << bit)) != 0; |
---|
167 | } else { |
---|
168 | return false; |
---|
169 | } |
---|
170 | } |
---|
171 | |
---|
172 | /** @} */ |
---|
173 | |
---|
174 | #ifdef __cplusplus |
---|
175 | } |
---|
176 | #endif /* __cplusplus */ |
---|
177 | |
---|
178 | #endif /* LIBBSP_ARM_LPC24XX_IO_H */ |
---|