summaryrefslogtreecommitdiffstats
path: root/bsps/arm/lpc176x/include/bsp/gpio-defs.h
blob: 31155bf597bcb6a3a9078999aa66f1a620b7b04f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/**
 * @file
 *
 * @ingroup lpc176x
 *
 * @brief API definitions of the GPIO driver for the lpc176x bsp in RTEMS.
 */

/*
 * Copyright (c) 2014 Taller Technologies.
 *
 * @author  Boretto Martin    (martin.boretto@tallertechnologies.com)
 * @author  Diaz Marcos (marcos.diaz@tallertechnologies.com)
 * @author  Lenarduzzi Federico  (federico.lenarduzzi@tallertechnologies.com)
 * @author  Daniel Chicco  (daniel.chicco@tallertechnologies.com)
 *
 * The license and distribution terms for this file may be
 * found in the file LICENSE in this distribution or at
 * http://www.rtems.org/license/LICENSE.
 */

#ifndef LIBBSP_ARM_LPC176X_GPIO_DEFS_H
#define LIBBSP_ARM_LPC176X_GPIO_DEFS_H

#include <bsp/common-types.h>

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

/* General Purpose Input/Output (GPIO) */
#define LPC176X_GPIO_BASE_ADDR 0x40028000U
#define LPC176X_GPIO_INTERRUPT_STATUS 0x40028080U

#define LPC176X_IOPIN0 ( *(volatile uint32_t *) ( LPC176X_GPIO_BASE_ADDR + \
                                                  0x00U ) )
#define LPC176X_IOSET0 ( *(volatile uint32_t *) ( LPC176X_GPIO_BASE_ADDR + \
                                                  0x04U ) )
#define LPC176X_IODIR0 ( *(volatile uint32_t *) ( LPC176X_GPIO_BASE_ADDR + \
                                                  0x08U ) )
#define LPC176X_IOCLR0 ( *(volatile uint32_t *) ( LPC176X_GPIO_BASE_ADDR + \
                                                  0x0CU ) )
#define LPC176X_IOPIN1 ( *(volatile uint32_t *) ( LPC176X_GPIO_BASE_ADDR + \
                                                  0x10U ) )
#define LPC176X_IOSET1 ( *(volatile uint32_t *) ( LPC176X_GPIO_BASE_ADDR + \
                                                  0x14U ) )
#define LPC176X_IODIR1 ( *(volatile uint32_t *) ( LPC176X_GPIO_BASE_ADDR + \
                                                  0x18U ) )
#define LPC176X_IOCLR1 ( *(volatile uint32_t *) ( LPC176X_GPIO_BASE_ADDR + \
                                                  0x1CU ) )

/* GPIO Interrupt Registers */
#define LPC176X_IO0_INT_EN_R ( *(volatile uint32_t *) ( LPC176X_GPIO_BASE_ADDR \
                                                        + 0x90U ) )
#define LPC176X_IO0_INT_EN_F ( *(volatile uint32_t *) ( LPC176X_GPIO_BASE_ADDR \
                                                        + 0x94U ) )
#define LPC176X_IO0_INT_STAT_R ( *(volatile uint32_t *) ( \
                                   LPC176X_GPIO_BASE_ADDR \
                                   + 0x84U ) )
#define LPC176X_IO0_INT_STAT_F ( *(volatile uint32_t *) ( \
                                   LPC176X_GPIO_BASE_ADDR \
                                   + 0x88U ) )
#define LPC176X_IO0_INT_CLR ( *(volatile uint32_t *) ( LPC176X_GPIO_BASE_ADDR \
                                                       + 0x8CU ) )
#define LPC176X_IO2_INT_EN_R ( *(volatile uint32_t *) ( LPC176X_GPIO_BASE_ADDR \
                                                        + 0xB0U ) )
#define LPC176X_IO2_INT_EN_F ( *(volatile uint32_t *) ( LPC176X_GPIO_BASE_ADDR \
                                                        + 0xB4U ) )
#define LPC176X_IO2_INT_STAT_R ( *(volatile uint32_t *) ( \
                                   LPC176X_GPIO_BASE_ADDR \
                                   + 0xA4U ) )
#define LPC176X_IO2_INT_STAT_F ( *(volatile uint32_t *) ( \
                                   LPC176X_GPIO_BASE_ADDR \
                                   + 0xA8U ) )
#define LPC176X_IO2_INT_CLR ( *(volatile uint32_t *) ( LPC176X_GPIO_BASE_ADDR \
                                                       + 0xACU ) )
#define LPC176X_IO_INT_STAT ( *(volatile uint32_t *) ( LPC176X_GPIO_BASE_ADDR \
                                                       + 0x80U ) )

#define LPC176X_RESERVED_ISR_FUNCT_SIZE 2U
#define LPC176X_RESERVED_ISR_FUNCT_MAX_SIZE 5U

#define LPC176X_MAX_PORT_NUMBER 160U
#define LPC176X_SET_BIT( reg, pin, value ) \
  reg = ( reg & ~( 1U << pin ) ) | ( ( value & 1U ) << pin )

#define LPC176X_INT_STATUS ( *(volatile uint32_t *) \
                             ( LPC176X_GPIO_INTERRUPT_STATUS ) )
#define LPC176X_INT_STATUS_P0 1U
#define LPC176X_INT_STATUS_P2 ( 1U << 2U )
#define LPC176X_INT_ENABLE 1U
#define LPC176X_INT_DISABLE 0U

#define LPC176X_IRQ_EINT_3 21U

#define LPC176X_PIN_BIT( pin ) ( 1U << pin )

/**
 * @brief The direction of the GPIO port (input or output).
 *
 * Enumerated type to define the set of function types for a gpio device.
 */
typedef enum {
  LPC176X_GPIO_FUNCTION_INPUT,
  LPC176X_GPIO_FUNCTION_OUTPUT,
  LPC176X_GPIO_FUNCTION_COUNT
}
lpc176x_gpio_direction;

/**
 * @brief The interrupt sources edge for a GPIO.
 *
 * Enumerated type to define the set of interrupt types for a gpio device.
 */
typedef enum {
  LPC176X_GPIO_INTERRUPT_DISABLE,
  LPC176X_GPIO_INTERRUPT_RISING,
  LPC176X_GPIO_INTERRUPT_FALLING,
  LPC176X_GPIO_INTERRUPT_BOTH,
  LPC176X_GPIO_INTERRUPT_COUNT
} lpc176x_gpio_interrupt;

/**
 * @brief The ports for a GPIO.
 *
 * Enumerated type to define the set of ports for a gpio device.
 */
typedef enum {
  LPC176X_GPIO_PORT_0,
  LPC176X_GPIO_PORT_1,
  LPC176X_GPIO_PORT_2,
  LPC176X_GPIO_PORT_3,
  LPC176X_GPIO_PORT_4,
  LPC176X_GPIO_PORTS_COUNT
} lpc176x_gpio_ports;

/**
 * @brief Addresses for a GPIO.
 *
 * Enumerated type to define the set of fio bases addresses
 *     for a gpio device.
 */
typedef enum {
  LPC176X_FIO0_BASE_ADDRESS = 0x2009C000U,
  LPC176X_FIO1_BASE_ADDRESS = 0x2009C020U,
  LPC176X_FIO2_BASE_ADDRESS = 0x2009C040U,
  LPC176X_FIO3_BASE_ADDRESS = 0x2009C060U,
  LPC176X_FIO4_BASE_ADDRESS = 0x2009C080U,
} lpc176x_gpio_address;

/**
 * @brief Addresses for the two interrupts.
 *
 * Enumerated type to define the set of interrupt addresses
 *     for a gpio device.
 */
typedef enum {
  LPC176X_IO0_INT_BASE_ADDRESS = 0x40028084U,
  LPC176X_IO2_INT_BASE_ADDRESS = 0x400280A4U,
} lpc176x_interrupt_address;

/**
 * @brief GPIO Interrupt register map.
 */
typedef struct {
  /**
   * @brief Interrupt Enable for Rising edge.
   */
  volatile uint32_t StatR;
  /**
   * @brief Interrupt Enable for Falling edge.
   */
  volatile uint32_t StatF;
  /**
   * @brief Interrupt Clear.
   */
  volatile uint32_t Clr;
  /**
   * @brief Interrupt Enable for Rising edge.
   */
  volatile uint32_t EnR;
  /**
   * @brief Interrupt Enable for Falling edge.
   */
  volatile uint32_t EnF;
} lpc176x_interrupt_control;

/**
 * @brief A function that attends an interrupt for GPIO.
 *
 * @param  pin Pin number.
 * @param edge Interrupt.
 * @return Pointer to the interrupt function.
 */
typedef void (*lpc176x_gpio_interrupt_function) (
  const lpc176x_pin_number     pin,
  const lpc176x_gpio_interrupt edge
);

/**
 * @brief A registered interrupt function for the pin 'pin'.
 */
typedef struct {
  /**
   * @brief Pin board.
   */
  lpc176x_pin_number pin;
  /**
   * @brief A function that attends an interrupt for 'pin'.
   */
  lpc176x_gpio_interrupt_function function;
} lpc176x_registered_interrupt_function;

#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif /* LIBBSP_ARM_LPC176X_GPIO_DEFS_H */