RTEMS: bsps/include/bsp/gpio.h Source File

| RTEMS 5.4-rc2

Loading...
Searching...
No Matches
gpio.h
Go to the documentation of this file.
1
9/*
10 * Copyright (c) 2014-2015 Andre Marques <andre.lousa.marques at gmail.com>
11 *
12 * The license and distribution terms for this file may be
13 * found in the file LICENSE in this distribution or at
14 * http://www.rtems.org/license/LICENSE.
15 */
16
17#ifndef LIBBSP_SHARED_GPIO_H
18#define LIBBSP_SHARED_GPIO_H
19
20#include <bsp.h>
21#include <rtems.h>
22
23#ifdef __cplusplus
24extern "C" {
25#endif /* __cplusplus */
26
27#if !defined(BSP_GPIO_PIN_COUNT) || !defined(BSP_GPIO_PINS_PER_BANK)
28 #error "BSP_GPIO_PIN_COUNT or BSP_GPIO_PINS_PER_BANK is not defined."
29#endif
30
31#if BSP_GPIO_PIN_COUNT <= 0 || BSP_GPIO_PINS_PER_BANK <= 0
32 #error "Invalid BSP_GPIO_PIN_COUNT or BSP_GPIO_PINS_PER_BANK."
33#endif
34
35#if BSP_GPIO_PINS_PER_BANK > 32
36 #error "Invalid BSP_GPIO_PINS_PER_BANK. Must be in the range of 1 to 32."
37#endif
38
39#define GPIO_LAST_BANK_PINS BSP_GPIO_PIN_COUNT % BSP_GPIO_PINS_PER_BANK
40
41#if GPIO_LAST_BANK_PINS > 0
42 #define GPIO_BANK_COUNT (BSP_GPIO_PIN_COUNT / BSP_GPIO_PINS_PER_BANK) + 1
43#else
44 #define GPIO_BANK_COUNT BSP_GPIO_PIN_COUNT / BSP_GPIO_PINS_PER_BANK
45 #undef GPIO_LAST_BANK_PINS
46 #define GPIO_LAST_BANK_PINS BSP_GPIO_PINS_PER_BANK
47#endif
48
49#if defined(BSP_GPIO_PINS_PER_SELECT_BANK) && BSP_GPIO_PINS_PER_SELECT_BANK > 32
50 #error "Invalid BSP_GPIO_PINS_PER_SELECT_BANK. Must under and including 32."
51#elif defined(BSP_GPIO_PINS_PER_SELECT_BANK) <= 32
52 #define GPIO_SELECT_BANK_COUNT \
53 BSP_GPIO_PINS_PER_BANK / BSP_GPIO_PINS_PER_SELECT_BANK
54#endif
55
56#define INTERRUPT_SERVER_PRIORITY 1
57#define INTERRUPT_SERVER_STACK_SIZE 2 * RTEMS_MINIMUM_STACK_SIZE
58#define INTERRUPT_SERVER_MODES RTEMS_TIMESLICE | RTEMS_PREEMPT
59#define INTERRUPT_SERVER_ATTRIBUTES RTEMS_DEFAULT_ATTRIBUTES
60
61#define GPIO_INPUT_ERROR ~0
62
75 typedef enum
76{
77 PULL_UP = 1,
78 PULL_DOWN,
79 NO_PULL_RESISTOR
80} rtems_gpio_pull_mode;
81
87 typedef enum
88{
89 DIGITAL_INPUT = 0,
90 DIGITAL_OUTPUT,
91 BSP_SPECIFIC,
92 NOT_USED
93} rtems_gpio_function;
94
100 typedef enum
101{
102 FALLING_EDGE = 0,
103 RISING_EDGE,
104 LOW_LEVEL,
105 HIGH_LEVEL,
106 BOTH_EDGES,
107 BOTH_LEVELS,
108 NONE
109} rtems_gpio_interrupt;
110
117 typedef enum
118{
119 IRQ_HANDLED,
120 IRQ_NONE
121} rtems_gpio_irq_state;
122
129 typedef enum
130{
131 SHARED_HANDLER,
132 UNIQUE_HANDLER
133} rtems_gpio_handler_flag;
134
141 typedef struct
142{
143 /* The BSP defined function code. */
144 uint32_t io_function;
145
146 void *pin_data;
147} rtems_gpio_specific_data;
148
153 typedef struct
154{
155 rtems_gpio_interrupt active_interrupt;
156
157 rtems_gpio_handler_flag handler_flag;
158
159 bool threaded_interrupts;
160
161 /* Interrupt handler function. */
162 rtems_gpio_irq_state (*handler) (void *arg);
163
164 /* Interrupt handler function arguments. */
165 void *arg;
166
167 /* Software switch debounce settings. It should contain the amount of clock
168 * ticks that must pass between interrupts to ensure that the interrupt
169 * was not caused by a switch bounce.
170 * If set to 0 this feature is disabled . */
171 uint32_t debounce_clock_tick_interval;
172} rtems_gpio_interrupt_configuration;
173
178 typedef struct
179{
180 /* Processor pin number. */
181 uint32_t pin_number;
182 rtems_gpio_function function;
183
184 /* Pull resistor setting. */
185 rtems_gpio_pull_mode pull_mode;
186
187 /* If digital out pin, set to TRUE to set the pin to logical high,
188 * or FALSE for logical low. If not a digital out then this
189 * is ignored. */
190 bool output_enabled;
191
192 /* If true inverts digital in/out applicational logic. */
193 bool logic_invert;
194
195 /* Pin interrupt configuration. Should be NULL if not used. */
196 rtems_gpio_interrupt_configuration *interrupt;
197
198 /* Structure with BSP specific data, to use during the pin request.
199 * If function == BSP_SPECIFIC this should have a pointer to
200 * a rtems_gpio_specific_data structure.
201 *
202 * If not this field may be NULL. This is passed to the BSP function
203 * so any BSP specific data can be passed to it through this pointer. */
204 void *bsp_specific;
205} rtems_gpio_pin_conf;
206
212 typedef struct
213{
214 /* Global GPIO pin number. */
215 uint32_t pin_number;
216
217 /* RTEMS GPIO pin function code. */
218 rtems_gpio_function function;
219
220 /* BSP specific function code. Only used if function == BSP_SPECIFIC */
221 uint32_t io_function;
222
223 /* BSP specific data. */
224 void *bsp_specific;
225} rtems_gpio_multiple_pin_select;
226
231 typedef struct
232{
233 const rtems_gpio_pin_conf *digital_inputs;
234 uint32_t input_count;
235
236 const rtems_gpio_pin_conf *digital_outputs;
237 uint32_t output_count;
238
239 const rtems_gpio_pin_conf *bsp_specifics;
240 uint32_t bsp_specific_pin_count;
241} rtems_gpio_group_definition;
242
246 typedef struct rtems_gpio_group rtems_gpio_group;
247
262extern rtems_status_code rtems_gpio_initialize(void);
263
270extern rtems_gpio_group *rtems_gpio_create_pin_group(void);
271
287extern rtems_status_code rtems_gpio_define_pin_group(
288 const rtems_gpio_group_definition *group_definition,
289 rtems_gpio_group *group
290);
291
303extern rtems_status_code rtems_gpio_write_group(
304 uint32_t data,
305 rtems_gpio_group *group
306);
307
318extern uint32_t rtems_gpio_read_group(rtems_gpio_group *group);
319
333extern rtems_status_code rtems_gpio_group_bsp_specific_operation(
334 rtems_gpio_group *group,
335 void *arg
336);
337
347extern rtems_status_code rtems_gpio_request_configuration(
348 const rtems_gpio_pin_conf *conf
349);
350
362extern rtems_status_code rtems_gpio_update_configuration(
363 const rtems_gpio_pin_conf *conf
364);
365
378extern rtems_status_code rtems_gpio_multi_set(
379 uint32_t *pin_numbers,
380 uint32_t pin_count
381);
382
395extern rtems_status_code rtems_gpio_multi_clear(
396 uint32_t *pin_numbers,
397 uint32_t pin_count
398);
399
410extern uint32_t rtems_gpio_multi_read(
411 uint32_t *pin_numbers,
412 uint32_t pin_count
413);
414
426extern rtems_status_code rtems_gpio_set(uint32_t pin_number);
427
439extern rtems_status_code rtems_gpio_clear(uint32_t pin_number);
440
450extern int rtems_gpio_get_value(uint32_t pin_number);
451
470extern rtems_status_code rtems_gpio_multi_select(
471 const rtems_gpio_pin_conf *pins,
472 uint8_t pin_count
473);
474
494extern rtems_status_code rtems_gpio_request_pin(
495 uint32_t pin_number,
496 rtems_gpio_function function,
497 bool output_enable,
498 bool logic_invert,
499 void *bsp_specific
500);
501
512extern rtems_status_code rtems_gpio_resistor_mode(
513 uint32_t pin_number,
514 rtems_gpio_pull_mode mode
515);
516
527extern rtems_status_code rtems_gpio_release_pin(uint32_t pin_number);
528
538extern rtems_status_code rtems_gpio_release_configuration(
539 const rtems_gpio_pin_conf *conf
540);
541
552extern rtems_status_code rtems_gpio_release_multiple_pins(
553 const rtems_gpio_pin_conf *pins,
554 uint32_t pin_count
555);
556
567extern rtems_status_code rtems_gpio_release_pin_group(
568 rtems_gpio_group *group
569);
570
589extern rtems_status_code rtems_gpio_debounce_switch(
590 uint32_t pin_number,
591 int ticks
592);
593
613extern rtems_status_code rtems_gpio_interrupt_handler_install(
614 uint32_t pin_number,
615 rtems_gpio_irq_state (*handler) (void *arg),
616 void *arg
617);
618
646extern rtems_status_code rtems_gpio_enable_interrupt(
647 uint32_t pin_number,
648 rtems_gpio_interrupt interrupt,
649 rtems_gpio_handler_flag flag,
650 bool threaded_handling,
651 rtems_gpio_irq_state (*handler) (void *arg),
652 void *arg
653);
654
669extern rtems_status_code rtems_gpio_interrupt_handler_remove(
670 uint32_t pin_number,
671 rtems_gpio_irq_state (*handler) (void *arg),
672 void *arg
673);
674
689extern rtems_status_code rtems_gpio_disable_interrupt(uint32_t pin_number);
690
701extern rtems_status_code rtems_gpio_bsp_multi_set(
702 uint32_t bank,
703 uint32_t bitmask
704);
705
716extern rtems_status_code rtems_gpio_bsp_multi_clear(
717 uint32_t bank,
718 uint32_t bitmask
719);
720
732extern uint32_t rtems_gpio_bsp_multi_read(uint32_t bank, uint32_t bitmask);
733
751extern rtems_status_code rtems_gpio_bsp_specific_group_operation(
752 uint32_t bank,
753 uint32_t *pins,
754 uint32_t pin_count,
755 void *arg
756);
757
775extern rtems_status_code rtems_gpio_bsp_multi_select(
776 rtems_gpio_multiple_pin_select *pins,
777 uint32_t pin_count,
778 uint32_t select_bank
779);
780
791extern rtems_status_code rtems_gpio_bsp_set(uint32_t bank, uint32_t pin);
792
803extern rtems_status_code rtems_gpio_bsp_clear(uint32_t bank, uint32_t pin);
804
816extern uint32_t rtems_gpio_bsp_get_value(uint32_t bank, uint32_t pin);
817
830extern rtems_status_code rtems_gpio_bsp_select_input(
831 uint32_t bank,
832 uint32_t pin,
833 void *bsp_specific
834);
835
848extern rtems_status_code rtems_gpio_bsp_select_output(
849 uint32_t bank,
850 uint32_t pin,
851 void *bsp_specific
852);
853
867extern rtems_status_code rtems_gpio_bsp_select_specific_io(
868 uint32_t bank,
869 uint32_t pin,
870 uint32_t function,
871 void *pin_data
872);
873
885extern rtems_status_code rtems_gpio_bsp_set_resistor_mode(
886 uint32_t bank,
887 uint32_t pin,
888 rtems_gpio_pull_mode mode
889);
890
903extern uint32_t rtems_gpio_bsp_interrupt_line(rtems_vector_number vector);
904
913extern rtems_vector_number rtems_gpio_bsp_get_vector(uint32_t bank);
914
926extern rtems_status_code rtems_gpio_bsp_enable_interrupt(
927 uint32_t bank,
928 uint32_t pin,
929 rtems_gpio_interrupt interrupt
930);
931
943extern rtems_status_code rtems_gpio_bsp_disable_interrupt(
944 uint32_t bank,
945 uint32_t pin,
946 rtems_gpio_interrupt interrupt
947);
948
951#ifdef __cplusplus
952}
953#endif /* __cplusplus */
954
955#endif /* LIBBSP_SHARED_GPIO_H */
rtems_gpio_resistor_mode
rtems_status_code rtems_gpio_resistor_mode(uint32_t pin_number, rtems_gpio_pull_mode mode)
Configures a single GPIO pin pull resistor.
Definition: gpio-support.c:1383
rtems_gpio_function
rtems_gpio_function
The set of possible functions a pin can have.
Definition: gpio.h:88
DIGITAL_OUTPUT
@ DIGITAL_OUTPUT
Assigns a certain function to a GPIO pin.
Definition: gpio.h:90
rtems_gpio_group_bsp_specific_operation
rtems_status_code rtems_gpio_group_bsp_specific_operation(rtems_gpio_group *group, void *arg)
Performs a BSP specific operation on a group of pins. The pins order is as defined in the group defin...
Definition: gpio-support.c:941
rtems_gpio_bsp_select_specific_io
rtems_status_code rtems_gpio_bsp_select_specific_io(uint32_t bank, uint32_t pin, uint32_t function, void *pin_data)
Assigns a BSP specific function to the given pin. This must be implemented by each BSP.
Definition: rpi-gpio.c:128
rtems_gpio_irq_state
rtems_gpio_irq_state
The set of possible handled states an user-defined interrupt handler can return.
Definition: gpio.h:118
rtems_gpio_bsp_select_input
rtems_status_code rtems_gpio_bsp_select_input(uint32_t bank, uint32_t pin, void *bsp_specific)
Assigns the digital input function to the given pin. This must be implemented by each BSP.
Definition: rpi-gpio.c:112
rtems_gpio_read_group
uint32_t rtems_gpio_read_group(rtems_gpio_group *group)
Reads the value/level of the group's digital inputs. The pins order is as defined in the group defini...
Definition: gpio-support.c:905
rtems_gpio_release_pin
rtems_status_code rtems_gpio_release_pin(uint32_t pin_number)
Releases a GPIO pin, making it available to be used again.
Definition: gpio-support.c:1428
rtems_gpio_disable_interrupt
rtems_status_code rtems_gpio_disable_interrupt(uint32_t pin_number)
Stops interrupts from being generated on a given GPIO pin and removes the corresponding handler.
Definition: gpio-support.c:1888
rtems_gpio_multi_set
rtems_status_code rtems_gpio_multi_set(uint32_t *pin_numbers, uint32_t pin_count)
Sets multiple output GPIO pins with the logical high.
Definition: gpio-support.c:1103
rtems_gpio_bsp_enable_interrupt
rtems_status_code rtems_gpio_bsp_enable_interrupt(uint32_t bank, uint32_t pin, rtems_gpio_interrupt interrupt)
Enables interrupts to be generated on a given GPIO pin. This must be implemented by each BSP.
Definition: rpi-gpio.c:192
rtems_gpio_initialize
rtems_status_code rtems_gpio_initialize(void)
Initializes the GPIO API.
Definition: gpio-support.c:640
rtems_gpio_bsp_clear
rtems_status_code rtems_gpio_bsp_clear(uint32_t bank, uint32_t pin)
Sets an output GPIO pin with the logical low. This must be implemented by each BSP.
Definition: rpi-gpio.c:100
rtems_gpio_handler_flag
rtems_gpio_handler_flag
The set of flags to specify an user-defined interrupt handler uniqueness on a GPIO pin.
Definition: gpio.h:130
rtems_gpio_interrupt_handler_remove
rtems_status_code rtems_gpio_interrupt_handler_remove(uint32_t pin_number, rtems_gpio_irq_state(*handler)(void *arg), void *arg)
Disconnects an user-defined interrupt handler from the given pin. If in the end there are no more use...
Definition: gpio-support.c:1826
rtems_gpio_get_value
int rtems_gpio_get_value(uint32_t pin_number)
Returns the value (level) of a GPIO input pin.
Definition: gpio-support.c:1253
rtems_gpio_bsp_get_value
uint32_t rtems_gpio_bsp_get_value(uint32_t bank, uint32_t pin)
Returns the value (level) of a GPIO input pin. This must be implemented by each BSP.
Definition: rpi-gpio.c:107
rtems_gpio_bsp_multi_set
rtems_status_code rtems_gpio_bsp_multi_set(uint32_t bank, uint32_t bitmask)
Sets multiple output GPIO pins with the logical high. This must be implemented by each BSP.
Definition: rpi-gpio.c:74
rtems_gpio_update_configuration
rtems_status_code rtems_gpio_update_configuration(const rtems_gpio_pin_conf *conf)
Updates the current configuration of a GPIO pin .
Definition: gpio-support.c:1008
rtems_gpio_bsp_set_resistor_mode
rtems_status_code rtems_gpio_bsp_set_resistor_mode(uint32_t bank, uint32_t pin, rtems_gpio_pull_mode mode)
Configures a single GPIO pin pull resistor. This must be implemented by each BSP.
Definition: rpi-gpio.c:137
rtems_gpio_create_pin_group
rtems_gpio_group * rtems_gpio_create_pin_group(void)
Instantiates a GPIO pin group. To define the group.
Definition: gpio-support.c:680
rtems_gpio_bsp_disable_interrupt
rtems_status_code rtems_gpio_bsp_disable_interrupt(uint32_t bank, uint32_t pin, rtems_gpio_interrupt interrupt)
Stops interrupts from being generated on a given GPIO pin. This must be implemented by each BSP.
Definition: rpi-gpio.c:236
rtems_gpio_interrupt
rtems_gpio_interrupt
The set of possible interrupts a GPIO pin can generate.
Definition: gpio.h:101
rtems_gpio_bsp_select_output
rtems_status_code rtems_gpio_bsp_select_output(uint32_t bank, uint32_t pin, void *bsp_specific)
Assigns the digital output function to the given pin. This must be implemented by each BSP.
Definition: rpi-gpio.c:120
rtems_gpio_bsp_multi_read
uint32_t rtems_gpio_bsp_multi_read(uint32_t bank, uint32_t bitmask)
Returns the value (level) of multiple GPIO input pins. This must be implemented by each BSP.
Definition: rpi-gpio.c:88
rtems_gpio_write_group
rtems_status_code rtems_gpio_write_group(uint32_t data, rtems_gpio_group *group)
Writes a value to the group's digital outputs. The pins order is as defined in the group definition.
Definition: gpio-support.c:840
rtems_gpio_bsp_interrupt_line
uint32_t rtems_gpio_bsp_interrupt_line(rtems_vector_number vector)
Reads and returns a vector/bank interrupt event line. The bitmask should indicate with a 1 if the cor...
Definition: rpi-gpio.c:179
rtems_gpio_debounce_switch
rtems_status_code rtems_gpio_debounce_switch(uint32_t pin_number, int ticks)
Attaches a debouncing function to a given pin/switch. Debouncing is done by requiring a certain numbe...
Definition: gpio-support.c:1567
rtems_gpio_release_pin_group
rtems_status_code rtems_gpio_release_pin_group(rtems_gpio_group *group)
Releases a GPIO pin group, making the pins used available to be repurposed.
Definition: gpio-support.c:1498
rtems_gpio_request_configuration
rtems_status_code rtems_gpio_request_configuration(const rtems_gpio_pin_conf *conf)
Requests a GPIO pin configuration.
Definition: gpio-support.c:980
rtems_gpio_multi_read
uint32_t rtems_gpio_multi_read(uint32_t *pin_numbers, uint32_t pin_count)
Returns the value (level) of multiple GPIO input pins.
Definition: gpio-support.c:1149
rtems_gpio_clear
rtems_status_code rtems_gpio_clear(uint32_t pin_number)
Sets an output GPIO pin with the logical low.
Definition: gpio-support.c:1213
rtems_gpio_interrupt_handler_install
rtems_status_code rtems_gpio_interrupt_handler_install(uint32_t pin_number, rtems_gpio_irq_state(*handler)(void *arg), void *arg)
Connects a new user-defined interrupt handler to a given pin.
Definition: gpio-support.c:1602
rtems_gpio_bsp_set
rtems_status_code rtems_gpio_bsp_set(uint32_t bank, uint32_t pin)
Sets an output GPIO pin with the logical high. This must be implemented by each BSP.
Definition: rpi-gpio.c:93
rtems_gpio_pull_mode
rtems_gpio_pull_mode
The set of possible configurations for a GPIO pull-up resistor.
Definition: gpio.h:76
rtems_gpio_release_configuration
rtems_status_code rtems_gpio_release_configuration(const rtems_gpio_pin_conf *conf)
Releases a GPIO pin, making it available to be used again.
Definition: gpio-support.c:1466
rtems_gpio_bsp_multi_clear
rtems_status_code rtems_gpio_bsp_multi_clear(uint32_t bank, uint32_t bitmask)
Sets multiple output GPIO pins with the logical low. This must be implemented by each BSP.
Definition: rpi-gpio.c:81
rtems_gpio_set
rtems_status_code rtems_gpio_set(uint32_t pin_number)
Sets an output GPIO pin with the logical high.
Definition: gpio-support.c:1173
rtems_gpio_bsp_get_vector
rtems_vector_number rtems_gpio_bsp_get_vector(uint32_t bank)
Calculates a vector number for a given GPIO bank. This must be implemented by each BSP.
Definition: rpi-gpio.c:174
rtems_gpio_multi_clear
rtems_status_code rtems_gpio_multi_clear(uint32_t *pin_numbers, uint32_t pin_count)
Sets multiple output GPIO pins with the logical low.
Definition: gpio-support.c:1126
rtems_vector_number
ISR_Vector_number rtems_vector_number
Control block type used to manage the vectors.
Definition: intr.h:47
rtems_status_code
rtems_status_code
Classic API Status.
Definition: status.h:43
rtems.h
rtems_gpio_group_definition
Object containing configuration information to request a GPIO pin group.
Definition: gpio.h:232
rtems_gpio_group
Object containing relevant information about a GPIO group.
Definition: gpio-support.c:56
rtems_gpio_interrupt_configuration
Object containing configuration information regarding interrupts.
Definition: gpio.h:154
rtems_gpio_multiple_pin_select
Object containing configuration information to assign GPIO functions to multiple pins at the same tim...
Definition: gpio.h:213
rtems_gpio_pin_conf
Object containing configuration information to request/update a GPIO pin.
Definition: gpio.h:179
rtems_gpio_specific_data
Object containing relevant information for assigning a BSP specific function to a pin.
Definition: gpio.h:142