-
Notifications
You must be signed in to change notification settings - Fork 364
/
hal_uart.h
155 lines (132 loc) · 4.06 KB
/
hal_uart.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* @addtogroup HAL
* @{
* @defgroup HALUart HAL UART
* @{
*/
#ifndef H_HAL_UART_H_
#define H_HAL_UART_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <inttypes.h>
/**
* Function prototype for UART driver to ask for more data to send.
* Returns -1 if no more data is available for TX.
* Driver must call this with interrupts disabled.
*/
typedef int (*hal_uart_tx_char)(void *arg);
/**
* Function prototype for UART driver to report that transmission is
* complete. This should be called when transmission of last byte is
* finished.
* Driver must call this with interrupts disabled.
*/
typedef void (*hal_uart_tx_done)(void *arg);
/**
* Function prototype for UART driver to report incoming byte of data.
* Returns -1 if data was dropped.
* Driver must call this with interrupts disabled.
*/
typedef int (*hal_uart_rx_char)(void *arg, uint8_t byte);
/**
* Initializes given uart. Mapping of logical UART number to physical
* UART/GPIO pins is in BSP.
*/
int hal_uart_init_cbs(int uart, hal_uart_tx_char tx_func,
hal_uart_tx_done tx_done, hal_uart_rx_char rx_func, void *arg);
enum hal_uart_parity {
/** No Parity */
HAL_UART_PARITY_NONE = 0,
/** Odd parity */
HAL_UART_PARITY_ODD = 1,
/** Even parity */
HAL_UART_PARITY_EVEN = 2
};
enum hal_uart_flow_ctl {
/** No Flow Control */
HAL_UART_FLOW_CTL_NONE = 0,
/** RTS/CTS */
HAL_UART_FLOW_CTL_RTS_CTS = 1
};
/**
* Initialize the HAL uart.
*
* @param uart The uart number to configure
* @param cfg Hardware specific uart configuration. This is passed from BSP
* directly to the MCU specific driver.
*
* @return 0 on success, non-zero error code on failure
*/
int hal_uart_init(int uart, void *cfg);
/**
* Applies given configuration to UART.
*
* @param uart The UART number to configure
* @param speed The baudrate in bps to configure
* @param databits The number of databits to send per byte
* @param stopbits The number of stop bits to send
* @param parity The UART parity
* @param flow_ctl Flow control settings on the UART
*
* @return 0 on success, non-zero error code on failure
*/
int hal_uart_config(int uart, int32_t speed, uint8_t databits, uint8_t stopbits,
enum hal_uart_parity parity, enum hal_uart_flow_ctl flow_ctl);
/**
* Close UART port. Can call hal_uart_config() with different settings after
* calling this.
*
* @param uart The UART number to close
*/
int hal_uart_close(int uart);
/**
* More data queued for transmission. UART driver will start asking for that
* data.
*
* @param uart The UART number to start TX on
*/
void hal_uart_start_tx(int uart);
/**
* Upper layers have consumed some data, and are now ready to receive more.
* This is meaningful after uart_rx_char callback has returned -1 telling
* that no more data can be accepted.
*
* @param uart The UART number to begin RX on
*/
void hal_uart_start_rx(int uart);
/**
* This is type of write where UART has to block until character has been sent.
* Used when printing diag output from system crash.
* Must be called with interrupts disabled.
*
* @param uart The UART number to TX on
* @param byte The byte to TX on the UART
*/
void hal_uart_blocking_tx(int uart, uint8_t byte);
#ifdef __cplusplus
}
#endif
#endif /* H_HAL_UART_H_ */
/**
* @} HALUart
* @} HAL
*/