-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathhal_ll_uart.h
355 lines (321 loc) · 9.23 KB
/
hal_ll_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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
/****************************************************************************
**
** Copyright (C) ${COPYRIGHT_YEAR} MikroElektronika d.o.o.
** Contact: https://www.mikroe.com/contact
**
** This file is part of the mikroSDK package
**
** Commercial License Usage
**
** Licensees holding valid commercial NECTO compilers AI licenses may use this
** file in accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The MikroElektronika Company.
** For licensing terms and conditions see
** https://www.mikroe.com/legal/software-license-agreement.
** For further information use the contact form at
** https://www.mikroe.com/contact.
**
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used for
** non-commercial projects under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation: https://www.gnu.org/licenses/lgpl-3.0.html.
**
** The above copyright notice and this permission notice shall be
** included in all copies or substantial portions of the Software.
**
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** OF MERCHANTABILITY, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
** TO THE WARRANTIES FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
** OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
**
****************************************************************************/
/*!
* @file hal_ll_uart.h
* @brief API for UART HAL LOW LEVEL layer.
*/
#ifndef _HAL_LL_UART_H_
#define _HAL_LL_UART_H_
#include "hal_ll_target.h"
#ifdef __cplusplus
extern "C"{
#endif
/**
* @brief Interrupt request type enum.
*/
typedef enum
{
HAL_LL_UART_IRQ_RX, /**< RX INT */
HAL_LL_UART_IRQ_TX /**< TX INT */
} hal_ll_uart_irq_t;
/**
* @brief Pointer to interrupt handler function.
*/
typedef void ( *hal_ll_uart_isr_t )( handle_t handle, hal_ll_uart_irq_t event );
/**
* @brief Predefined enum values for parity selection.
*/
typedef enum
{
HAL_LL_UART_PARITY_NONE = 0,
HAL_LL_UART_PARITY_EVEN,
HAL_LL_UART_PARITY_ODD,
HAL_LL_UART_PARITY_DEFAULT = HAL_LL_UART_PARITY_NONE
} hal_ll_uart_parity_t;
/**
* @brief Predefined enum values for stop bit selection.
*/
typedef enum
{
HAL_LL_UART_STOP_BITS_HALF = 0,
HAL_LL_UART_STOP_BITS_ONE,
HAL_LL_UART_STOP_BITS_ONE_AND_A_HALF,
HAL_LL_UART_STOP_BITS_TWO,
HAL_LL_UART_STOP_BITS_DEFAULT = HAL_LL_UART_STOP_BITS_ONE
} hal_ll_uart_stop_bits_t;
/**
* @brief Predefined enum values for data bit selection.
*/
typedef enum
{
HAL_LL_UART_DATA_BITS_7 = 0,
HAL_LL_UART_DATA_BITS_8,
HAL_LL_UART_DATA_BITS_9,
HAL_LL_UART_DATA_BITS_DEFAULT = HAL_LL_UART_DATA_BITS_8
} hal_ll_uart_data_bits_t;
/**
* @brief UART low level pins config structure.
*
* The context structure for storing low level pin configuration
* for both TX and RX pins.
*
*/
typedef struct
{
hal_ll_pin_af_t tx_pin;
hal_ll_pin_af_t rx_pin;
} hal_ll_uart_pins_t;
/**
* @brief UART low level handle.
*
* The context for storing low level object handler.
* User is not to change these values or unexpected behaviour
* may occur.
*/
typedef struct
{
handle_t *hal_ll_uart_handle;
handle_t *hal_drv_uart_handle;
bool init_ll_state;
} hal_ll_uart_handle_register_t;
/**
* @brief Interrupt handler.
*
* Handles UART RBNE and TBE interrupt requests.
*
* @param[in] void none.
*
* @return void None.
*/
void USART0_IRQn_handler(void) __attribute__ ((interrupt));
/**
* @brief Interrupt handler.
*
* Handles UART RBNE and TBE interrupt requests.
*
* @param[in] void none.
*
* @return void None.
*/
void USART1_IRQn_handler(void) __attribute__ ((interrupt));
/**
* @brief Interrupt handler.
*
* Handles UART RBNE and TBE interrupt requests.
*
* @param[in] void none.
*
* @return void None.
*/
void USART2_IRQn_handler(void) __attribute__ ((interrupt));
/**
* @brief Interrupt handler.
*
* Handles UART RBNE and TBE interrupt requests.
*
* @param[in] void none.
*
* @return void None.
*/
void UART3_IRQn_handler(void) __attribute__ ((interrupt));
/**
* @brief Interrupt handler.
*
* Handles UART RBNE and TBE interrupt requests.
*
* @param[in] void none.
*
* @return void None.
*/
void UART4_IRQn_handler(void) __attribute__ ((interrupt));
/**
* @brief Registers handler for future use.
*
* Registers low level and hal level handlers
* for use with appropriate functions.
*
* @param[in] tx_pin UART TX pin.
* @param[in] rx_pin UART RX pin.
* @param[in] *handle_map HAL layer local handle map.
* @param[in] *hal_module_id HAL layer module number.
* @return hal_ll_err_t Module specific error.
*
* Returns one of pre-defined values.
* Take into consideration that this is hardware specific.
*/
hal_ll_err_t hal_ll_uart_register_handle( hal_ll_pin_name_t tx_pin, hal_ll_pin_name_t rx_pin, hal_ll_uart_handle_register_t *handle_map, uint8_t *hal_module_id );
/**
* @brief Configures specified module.
*
* Performs module configuration on the hardware
* level. Enables module specific clock gate and
* sets adequate alternate function values.
*
* @param[in] *handle HAL context object handle.
*
* @return hal_ll_err_t Module specific error.
*
* Returns one of pre-defined values.
* Take into consideration that this is hardware specific.
*/
hal_ll_err_t hal_ll_module_configure_uart( handle_t *handle );
/**
* @brief Registers interrupt handlers for future use.
*
* Registers low level interrupt handlers
* for use with appropriate functions.
*
* @param[in] handle HAL context object handle.
* @param[in] handler Predefined pointer function.
* @param[in] obj HAL context handle address.
* @return None.
*/
void hal_ll_uart_register_irq_handler( handle_t *handle, hal_ll_uart_isr_t handler, handle_t obj );
/**
* @brief Sets desired baud rate.
*
* Initializes module with specified baud rate value.
* Take into consideration that if the difference
* between desired baud rate and actual baud
* rate the hw was initialized to is greater than
* 1%, baud rate shall not be set.
* If this occurs, return value shall be
* the error percentage.
*
* @param[in] handle HAL context object handle.
* @param[in] baud Desired baud rate value in Bits/s.
*
* @return Actual baud rate value the hw module was initialized to,
* or module specific error value if init failed.
*/
hal_ll_err_t hal_ll_uart_set_baud( handle_t *handle, uint32_t baud );
/**
* @brief Sets desired parity.
*
* Initializes module with specified parity value.
*
* @param[in] handle HAL context object handle.
* @param[in] parity One of pre-defined values.
*
* @return Re-init module state. If neccessary.
*/
hal_ll_err_t hal_ll_uart_set_parity( handle_t *handle, hal_ll_uart_parity_t parity );
/**
* @brief Sets desired stop bits.
*
* Initializes module with specified stop bits value.
*
* @param[in] handle HAL context object handle.
* @param[in] stop_bit One of pre-defined values.
*
* @return Re-init module state. If neccessary.
*/
hal_ll_err_t hal_ll_uart_set_stop_bits( handle_t *handle, hal_ll_uart_stop_bits_t stop_bit );
/**
* @brief Sets desired data bits.
*
* Initializes module with specified data bits value.
*
* @param[in] handle HAL context object handle.
* @param[in] data_bit One of pre-defined values.
*
* @return Re-init module state. If neccessary.
*/
hal_ll_err_t hal_ll_uart_set_data_bits( handle_t *handle, hal_ll_uart_data_bits_t data_bit );
/**
* @brief Enables module specific interrupt.
*
* Enables module specific interrupt and registers
* interrupt on hardware level and enables it.
*
* @param[in] handle HAL context object handle.
* @param[in] irq Chip interrupt IRQ value.
*
* @return void None.
*/
void hal_ll_uart_irq_enable( handle_t *handle, hal_ll_uart_irq_t irq );
/**
* @brief Disables module specific interrupt.
*
* Disables module specific interrupt.
*
* @param[in] handle HAL context object handle.
* @param[in] irq Chip interrupt IRQ value.
*
* @return void None.
*/
void hal_ll_uart_irq_disable( handle_t *handle, hal_ll_uart_irq_t irq );
/**
* @brief Performs read operation.
*
* Reads one byte on a hardware level.
*
* @param[in] handle HAL context object handle.
*
* @return uint8_t Data read from hw register.
*/
uint8_t hal_ll_uart_read( handle_t *handle );
/**
* @brief Performs write operation.
*
* Accesses hardware data registers and
* writes data directly to it.
*
* @param[in] handle HAL context object handle.
* @param[in] wr_data Data to be written.
*
* @return void None.
*/
void hal_ll_uart_write( handle_t *handle, uint8_t wr_data);
/**
* @brief Closes UART HAL and HAL_LOW_LEVEL context object.
*
* De-allocates hardware resources for specific driver object and
* de-initializes the module on a hardware level.
*
* @param[in] *handle HAL context object handle.
*
* @return void None.
*/
void hal_ll_uart_close( handle_t *handle );
#ifdef __cplusplus
}
#endif
#endif // _HAL_LL_UART_H_
// ------------------------------------------------------------------------- END