2 * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
23 * @brief Enumeration for Baud Rate
43 UART_BAUD_RATE_115200,
48 * @brief Enumeration for Byte Size
51 UART_BYTE_SIZE_5BIT = 0,
58 * @brief Enumeration of Parity Bit
67 * @brief Enumeration for Stop Bits
70 UART_STOP_BITS_1BIT = 0,
75 * @brief uart_valid_baudrate() validation check of input baudrate
77 * @param[in] baudrate baudrate for uart
78 * @return On success, valid input. On failure, NULL is returned.
80 int uart_valid_baud_rate(unsigned int baud_rate);
83 * @brief uart_open() initializes uart port.
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.
89 int uart_open(int port, int *file_hndl);
92 * @brief uart_close() closes uart port.
94 * @param[in] file_hndl handle of uart_context
95 * @return On success, 0 is returned. On failure, a negative value is returned.
97 int uart_close(int file_hndl);
100 * @brief uart_flush() flushes uart buffer.
102 * @param[in] file_hndl handle of uart_context
103 * @return On success, 0 is returned. On failure, a negative value is returned.
105 int uart_flush(int file_hndl);
108 * @brief uart_set_baudrate() sets uart baud rate.
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.
114 int uart_set_baud_rate(int file_hndl, uart_baud_rate_e baud);
117 * @brief uart_set_mode() sets byte size, parity bit and stop bits.
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.
125 int uart_set_mode(int file_hndl, uart_byte_size_e byte_size, uart_parity_e parity, uart_stop_bits_e stop_bits);
128 * @brief peripheral_bus_uart_set_byte_size() set byte size.
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.
134 int uart_set_byte_size(int file_hndl, uart_byte_size_e byte_size);
137 * @brief peripheral_bus_uart_set_parity() set parity bit.
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.
143 int uart_set_parity(int file_hndl, uart_parity_e parity);
146 * @brief peripheral_bus_uart_set_stop_bits() set stop bits.
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.
152 int uart_set_stop_bits(int file_hndl, uart_stop_bits_e stop_bits);
155 * @brief uart_set_flow_control() set flow control settings.
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.
162 int uart_set_flow_control(int file_hndl, bool xonxoff, bool rtscts);
165 * @brief uart_read() reads data over uart bus.
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.
172 int uart_read(int file_hndl, uint8_t *buf, unsigned int length);
175 * @brief uart_write() writes data over uart bus.
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.
182 int uart_write(int file_hndl, uint8_t *buf, unsigned int length);
184 #endif /* __UART_H__ */