source: rtems/c/src/lib/libbsp/arm/lpc24xx/include/io.h @ 85893bc

4.104.115
Last change on this file since 85893bc was c468f18b, checked in by Thomas Doerfler <Thomas.Doerfler@…>, on 12/15/09 at 15:20:47

add support for LPC32xx

  • Property mode set to 100644
File size: 3.8 KB
Line 
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
30extern "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
53typedef enum {
54  LPC24XX_MODULE_ACF = 0,
55  LPC24XX_MODULE_ADC,
56  LPC24XX_MODULE_BAT_RAM,
57  LPC24XX_MODULE_CAN_0,
58  LPC24XX_MODULE_CAN_1,
59  LPC24XX_MODULE_DAC,
60  LPC24XX_MODULE_EMC,
61  LPC24XX_MODULE_ETHERNET,
62  LPC24XX_MODULE_GPDMA,
63  LPC24XX_MODULE_GPIO,
64  LPC24XX_MODULE_I2C_0,
65  LPC24XX_MODULE_I2C_1,
66  LPC24XX_MODULE_I2C_2,
67  LPC24XX_MODULE_I2S,
68  LPC24XX_MODULE_LCD,
69  LPC24XX_MODULE_MCI,
70  LPC24XX_MODULE_PCB,
71  LPC24XX_MODULE_PWM_0,
72  LPC24XX_MODULE_PWM_1,
73  LPC24XX_MODULE_RTC,
74  LPC24XX_MODULE_SPI,
75  LPC24XX_MODULE_SSP_0,
76  LPC24XX_MODULE_SSP_1,
77  LPC24XX_MODULE_SYSCON,
78  LPC24XX_MODULE_TIMER_0,
79  LPC24XX_MODULE_TIMER_1,
80  LPC24XX_MODULE_TIMER_2,
81  LPC24XX_MODULE_TIMER_3,
82  LPC24XX_MODULE_UART_0,
83  LPC24XX_MODULE_UART_1,
84  LPC24XX_MODULE_UART_2,
85  LPC24XX_MODULE_UART_3,
86  LPC24XX_MODULE_USB,
87  LPC24XX_MODULE_WDT
88} lpc24xx_module;
89
90#define LPC24XX_MODULE_FIRST LPC24XX_MODULE_ACF
91
92#define LPC24XX_MODULE_COUNT (LPC24XX_MODULE_WDT + 1)
93
94typedef enum {
95  LPC24XX_MODULE_PCLK_DEFAULT = 0x0U,
96  LPC24XX_MODULE_CCLK = 0x1U,
97  LPC24XX_MODULE_CCLK_2 = 0x2U,
98  LPC24XX_MODULE_CCLK_4 = 0x0U,
99  LPC24XX_MODULE_CCLK_6 = 0x3U,
100  LPC24XX_MODULE_CCLK_8 = 0x3U
101} lpc24xx_module_clock;
102
103#define LPC24XX_MODULE_CLOCK_MASK 0x3U
104
105typedef enum {
106  LPC24XX_GPIO_DEFAULT = 0x0U,
107  LPC24XX_GPIO_RESISTOR_DEFAULT = 0x0U,
108  LPC24XX_GPIO_RESISTOR_NONE = 0x1U,
109  LPC24XX_GPIO_RESISTOR_PULL_UP = 0x2U,
110  LPC24XX_GPIO_RESISTOR_PULL_DOWN = 0x3U,
111  LPC24XX_GPIO_INPUT = 0x0U,
112  LPC24XX_GPIO_OUTPUT = 0x8U
113} lpc24xx_gpio_settings;
114
115#define LPC24XX_GPIO_RESISTOR_MASK 0x3U
116
117rtems_status_code lpc24xx_module_enable(
118  lpc24xx_module module,
119  lpc24xx_module_clock clock
120);
121
122rtems_status_code lpc24xx_module_disable(
123  lpc24xx_module module
124);
125
126rtems_status_code lpc24xx_io_config(
127  lpc24xx_module module,
128  unsigned config
129);
130
131rtems_status_code lpc24xx_io_release(
132  lpc24xx_module module,
133  unsigned config
134);
135
136rtems_status_code lpc24xx_gpio_config(
137  unsigned index,
138  lpc24xx_gpio_settings settings
139);
140
141static inline void lpc24xx_gpio_set(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].set = 1U << bit;
148  }
149}
150
151static inline void lpc24xx_gpio_clear(unsigned index)
152{
153  if (index <= LPC24XX_IO_INDEX_MAX) {
154    unsigned port = LPC24XX_IO_PORT(index);
155    unsigned bit = LPC24XX_IO_PORT_BIT(index);
156
157    LPC24XX_FIO [port].clr = 1U << bit;
158  }
159}
160
161static inline void lpc24xx_gpio_write(unsigned index, bool value)
162{
163  if (value) {
164    lpc24xx_gpio_set(index);
165  } else {
166    lpc24xx_gpio_clear(index);
167  }
168}
169
170static inline bool lpc24xx_gpio_get(unsigned index)
171{
172  if (index <= LPC24XX_IO_INDEX_MAX) {
173    unsigned port = LPC24XX_IO_PORT(index);
174    unsigned bit = LPC24XX_IO_PORT_BIT(index);
175
176    return (LPC24XX_FIO [port].pin & (1U << bit)) != 0;
177  } else {
178    return false;
179  }
180}
181
182/** @} */
183
184#ifdef __cplusplus
185}
186#endif /* __cplusplus */
187
188#endif /* LIBBSP_ARM_LPC24XX_IO_H */
Note: See TracBrowser for help on using the repository browser.