]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lib.git/blob - rpp/include/rpp/gio.h
Make the RPP layer thread safe
[pes-rpp/rpp-lib.git] / rpp / include / rpp / gio.h
1 /*
2  * Copyright (C) 2015 Czech Technical University in Prague
3  *
4  * Authors:
5  *     - Michal Sojka <sojkam1@fel.cvut.cz>
6  *     - Michal Horn
7  *
8  * This document contains proprietary information belonging to Czech
9  * Technical University in Prague. Passing on and copying of this
10  * document, and communication of its contents is not permitted
11  * without prior written authorization.
12  *
13  */
14
15 #ifndef RPP_GIO_H
16 #define RPP_GIO_H
17
18 #include "types.h"
19 #include "drv/gio_names.h"
20
21 #define RPP_GIO_PORT_GIOA   0x2
22 #define RPP_GIO_PORT_GIOB   0x4
23 #define RPP_GIO_PORT_NHET1  0x8
24 #define RPP_GIO_PORT_ALL    (RPP_GIO_PORT_GIOA|RPP_GIO_PORT_GIOB|RPP_GIO_PORT_NHET1)
25
26 /**
27  * Intialize GIO ports.
28  *
29  * The ports are initialized according to the definition in gio_def.h.
30  *
31  * @param[in] init_ports Specifies which ports to initialize.
32  * RPP_GIO_PORT_ALL causes all ports to be initialized.
33  *
34  * This function is not thread safe. Do not call it from multiple
35  * threads.
36  *
37  * @return SUCCESS if successful, FAILURE otherwise.
38  */
39 int8_t rpp_gio_init(uint32_t init_ports);
40
41 /**
42  * Sets GIO output pin to a value.
43  *
44  * The function is thread safe.
45  *
46  * @param pin Pin to set
47  * @param value Value to the pin to.
48  *
49  * @return SUCCESS if successful, FAILURE otherwise.
50  */
51 int8_t rpp_gio_set(enum pin_name pin, boolean_t value);
52
53 /**
54  * Reads the value of a GIO pin.
55  *
56  * The function is thread safe.
57  *
58  * @param pin Pin to read.
59  *
60  * @return Pin value (0 or 1) in case of success, FAILURE otherwise.
61  */
62 int8_t rpp_gio_get(enum pin_name pin);
63
64 /** GIO pin input mode */
65 enum rpp_gio_in_mode {
66         RPP_GIO_MODE_PULLDIS,       /**< Disable pull resistor */
67         RPP_GIO_MODE_PULLUP,
68         RPP_GIO_MODE_PULLDOWN,
69 };
70
71 /** GIO pin direction */
72 enum rpp_gio_io {
73         RPP_GIO_IN,
74         RPP_GIO_OUT,
75 };
76
77 /**
78  * Configure GIO pin.
79  *
80  * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0.
81  *
82  * @param pin Pin to configure
83  * @param io Configure the pin as input or output.
84  * @param in_mode Input settings. Ignored when pin is configured as
85  *                output.
86  * @param open_drain Output is open drain when TRUE, pull/push when
87  *                   FALSE. Ignored when pin is configured as input.
88  *
89  * @return SUCCESS or FAILURE.
90  */
91 int8_t rpp_gio_setup(enum pin_name pin,
92                                          enum rpp_gio_io io,
93                                          enum rpp_gio_in_mode in_mode,
94                                          boolean_t open_drain);
95
96 int8_t rpp_gio_port_set(int port, uint32_t bits);
97 int8_t rpp_gio_port_get(int port, uint32_t *bits);
98
99 #endif /* GIO_H_ */