interface: move interface header files to top level include folder.
[platform/core/api/peripheral-io.git] / include / interface / uart.h
1 /*
2  * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef __UART_H__
18 #define __UART_H__
19
20 #include <stdint.h>
21
22 /**
23  * @brief Enumeration for Baud Rate
24  */
25 typedef enum {
26         UART_BAUD_RATE_0 = 0,
27         UART_BAUD_RATE_50,
28         UART_BAUD_RATE_75,
29         UART_BAUD_RATE_110,
30         UART_BAUD_RATE_134,
31         UART_BAUD_RATE_150,
32         UART_BAUD_RATE_200,
33         UART_BAUD_RATE_300,
34         UART_BAUD_RATE_600,
35         UART_BAUD_RATE_1200,
36         UART_BAUD_RATE_1800,
37         UART_BAUD_RATE_2400,
38         UART_BAUD_RATE_4800,
39         UART_BAUD_RATE_9600,
40         UART_BAUD_RATE_19200,
41         UART_BAUD_RATE_38400,
42         UART_BAUD_RATE_57600,
43         UART_BAUD_RATE_115200,
44         UART_BAUD_RATE_230400
45 } uart_baud_rate_e;
46
47 /**
48  * @brief Enumeration for Byte Size
49  */
50 typedef enum {
51         UART_BYTE_SIZE_5BIT = 0,
52         UART_BYTE_SIZE_6BIT,
53         UART_BYTE_SIZE_7BIT,
54         UART_BYTE_SIZE_8BIT
55 } uart_byte_size_e;
56
57 /**
58  * @brief Enumeration of Parity Bit
59  */
60 typedef enum {
61         UART_PARITY_NONE = 0,
62         UART_PARITY_EVEN,
63         UART_PARITY_ODD
64 } uart_parity_e;
65
66 /**
67  * @brief Enumeration for Stop Bits
68  */
69 typedef enum {
70         UART_STOP_BITS_1BIT = 0,
71         UART_STOP_BITS_2BIT
72 } uart_stop_bits_e;
73
74 /**
75 * @brief uart_valid_baudrate() validation check of input baudrate
76 *
77 * @param[in] baudrate baudrate for uart
78 * @return On success, valid input. On failure, NULL is returned.
79 */
80 int uart_valid_baud_rate(unsigned int baud_rate);
81
82 /**
83 * @brief uart_open() initializes uart port.
84 *
85 * @param[in] port uart port
86 * @param[in] file_hndl handle of uart port
87 * @return On success, handle of uart_context is returned. On failure, NULL is returned.
88 */
89 int uart_open(int port, int *file_hndl);
90
91 /**
92 * @brief uart_close() closes uart port.
93 *
94 * @param[in] file_hndl handle of uart_context
95 * @return On success, 0 is returned. On failure, a negative value is returned.
96 */
97 int uart_close(int file_hndl);
98
99 /**
100 * @brief uart_flush() flushes uart buffer.
101 *
102 * @param[in] file_hndl handle of uart_context
103 * @return On success, 0 is returned. On failure, a negative value is returned.
104 */
105 int uart_flush(int file_hndl);
106
107 /**
108 * @brief uart_set_baudrate() sets uart baud rate.
109 *
110 * @param[in] file_hndl handle of uart_context
111 * @param[in] baud uart baud rate
112 * @return On success, 0 is returned. On failure, a negative value is returned.
113 */
114 int uart_set_baud_rate(int file_hndl, uart_baud_rate_e baud);
115
116 /**
117 * @brief uart_set_mode() sets byte size, parity bit and stop bits.
118 *
119 * @param[in] file_hndl handle of uart_context
120 * @param[in] byte_size uart byte size
121 * @param[in] parity uart parity type (even/odd/none)
122 * @param[in] stop_bits uart stop bits
123 * @return On success, 0 is returned. On failure, a negative value is returned.
124 */
125 int uart_set_mode(int file_hndl, uart_byte_size_e byte_size, uart_parity_e parity, uart_stop_bits_e stop_bits);
126
127 /**
128 * @brief peripheral_bus_uart_set_byte_size() set byte size.
129 *
130 * @param[in] file_hndl handle of uart_context
131 * @param[in] byte_size uart byte size
132 * @return On success, 0 is returned. On failure, a negative value is returned.
133 */
134 int uart_set_byte_size(int file_hndl, uart_byte_size_e byte_size);
135
136 /**
137 * @brief peripheral_bus_uart_set_parity() set parity bit.
138 *
139 * @param[in] file_hndl handle of uart_context
140 * @param[in] parity uart parity type (even/odd/none)
141 * @return On success, 0 is returned. On failure, a negative value is returned.
142 */
143 int uart_set_parity(int file_hndl, uart_parity_e parity);
144
145 /**
146 * @brief peripheral_bus_uart_set_stop_bits() set stop bits.
147 *
148 * @param[in] file_hndl handle of uart_context
149 * @param[in] stop_bits uart stop bits
150 * @return On success, 0 is returned. On failure, a negative value is returned.
151 */
152 int uart_set_stop_bits(int file_hndl, uart_stop_bits_e stop_bits);
153
154 /**
155 * @brief uart_set_flow_control() set flow control settings.
156 *
157 * @param[in] file_hndl handle of uart_context
158 * @param[in] xonxoff ixon/ixoff
159 * @param[in] rtscts rts/cts
160 * @return On success, 0 is returned. On failure, a negative value is returned.
161 */
162 int uart_set_flow_control(int file_hndl, bool xonxoff, bool rtscts);
163
164 /**
165 * @brief uart_read() reads data over uart bus.
166 *
167 * @param[in] file_hndl handle of uart_context
168 * @param[in] buf the pointer of data buffer
169 * @param[in] length size to read
170 * @return On success, 0 is returned. On failure, a negative value is returned.
171 */
172 int uart_read(int file_hndl, uint8_t *buf, unsigned int length);
173
174 /**
175 * @brief uart_write() writes data over uart bus.
176 *
177 * @param[in] file_hndl handle of uart_context
178 * @param[in] buf the pointer of data buffer
179 * @param[in] length size to write
180 * @return On success, 0 is returned. On failure, a negative value is returned.
181 */
182 int uart_write(int file_hndl, uint8_t *buf, unsigned int length);
183
184 #endif /* __UART_H__ */
185