RTEMS 6.1-rc2
Loading...
Searching...
No Matches
gpiolib.h
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/* GPIO Library interface
4 *
5 * COPYRIGHT (c) 2009.
6 * Cobham Gaisler AB.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
28 */
29
30#ifndef __GPIOLIB_H__
31#define __GPIOLIB_H__
32
33#ifdef __cplusplus
34extern "C" {
35#endif
36
37/* GPIO Config of one GPIO port */
39 char mask; /* 0=Masked/1=Unmasked IRQ */
40 char irq_level; /* Edge or Level triggered IRQ */
41 char irq_polarity; /* Polarity of IRQ */
42};
43
44#define GPIOLIB_IRQ_EDGE 0
45#define GPIOLIB_IRQ_LEVEL 1
46
47#define GPIOLIB_IRQ_POL_LOW 0
48#define GPIOLIB_IRQ_POL_HIGH 1
49
50/* Libarary initialize function must be called befor any other */
51extern int gpiolib_initialize(void);
52
53/*** User Interface ***/
54
55extern void *gpiolib_open(int port);
56extern void *gpiolib_open_by_name(char *devName);
57extern void gpiolib_close(void *handle);
58
59/* Show the current status one or all GPIO ports in the system.
60 * Int port is port nunber, if port = -1 selects all ports.
61 *
62 * If port != -1, handle is used to get port.
63 * If port != -1, handle == NULL, then port is used as port number
64 */
65extern void gpiolib_show(int port, void *handle);
66
67extern int gpiolib_set_config(void *handle, struct gpiolib_config *cfg);
68extern int gpiolib_set(void *handle, int dir, int val);
69extern int gpiolib_get(void *handle, int *inval);
70extern int gpiolib_irq_clear(void *handle);
71extern int gpiolib_irq_enable(void *handle);
72extern int gpiolib_irq_disable(void *handle);
73extern int gpiolib_irq_mask(void *handle);
74extern int gpiolib_irq_unmask(void *handle);
75extern int gpiolib_irq_force(void *handle);
76extern int gpiolib_irq_register(void *handle, void *func, void *arg);
77
78/*** Driver Interface ***/
79
81 char devName[80];
82};
83
85 int (*config)(void *handle, struct gpiolib_config *cfg);
86 int (*get)(void *handle, int *val);
87 int (*irq_opts)(void *handle, unsigned int options);
88 int (*irq_register)(void *handle, void *func, void *arg);
89 int (*open)(void *handle);
90 int (*set)(void *handle, int dir, int outval);
91 int (*show)(void *handle);
92 int (*get_info)(void *handle, struct gpiolib_info *pinfo);
93};
94
95#define GPIOLIB_IRQ_ENABLE 0x01
96#define GPIOLIB_IRQ_DISABLE 0x02
97#define GPIOLIB_IRQ_CLEAR 0x04
98#define GPIOLIB_IRQ_FORCE 0x08
99#define GPIOLIB_IRQ_MASK 0x10
100#define GPIOLIB_IRQ_UNMASK 0x20
101
103 struct gpiolib_drv_ops *ops;
104};
105
106/* Register a GPIO port */
107extern int gpiolib_drv_register(struct gpiolib_drv *drv, void *handle);
108
109#ifdef __cplusplus
110}
111#endif
112
113#endif
int open(const char *path, int oflag,...)
Definition: open.c:171
Definition: deflate.c:114
Definition: gpiolib.h:38
Definition: gpiolib.h:84
Definition: gpiolib.h:102
Definition: gpiolib.h:80