VSF Documented
vsf_template_usart.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Copyright(C)2009-2022 by VSF Team *
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
18#ifndef __VSF_TEMPLATE_USART_H__
19#define __VSF_TEMPLATE_USART_H__
20
21/*============================ INCLUDES ======================================*/
22
24#include "hal/arch/vsf_arch.h"
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29/*============================ MACROS ========================================*/
30
31// multi-class support enabled by default for maximum availability.
32#ifndef VSF_USART_CFG_MULTI_CLASS
33# define VSF_USART_CFG_MULTI_CLASS ENABLED
34#endif
35
36#if defined(VSF_HW_USART_COUNT) && !defined(VSF_HW_USART_MASK)
37# define VSF_HW_USART_MASK VSF_HAL_COUNT_TO_MASK(VSF_HW_USART_COUNT)
38#endif
39
40#if defined(VSF_HW_USART_MASK) && !defined(VSF_HW_USART_COUNT)
41# define VSF_HW_USART_COUNT VSF_HAL_MASK_TO_COUNT(VSF_HW_USART_MASK)
42#endif
43
53#ifndef VSF_USART_CFG_PREFIX
54# if VSF_USART_CFG_MULTI_CLASS == ENABLED
55# define VSF_USART_CFG_PREFIX vsf
56# elif defined(VSF_HW_USART_COUNT) && (VSF_HW_USART_COUNT != 0)
57# define VSF_USART_CFG_PREFIX vsf_hw
58# else
59# define VSF_USART_CFG_PREFIX vsf
60# endif
61#endif
62
65#ifndef VSF_USART_CFG_FUNCTION_RENAME
66# define VSF_USART_CFG_FUNCTION_RENAME ENABLED
67#endif
68
71#ifndef VSF_USART_CFG_REIMPLEMENT_TYPE_MODE
72# define VSF_USART_CFG_REIMPLEMENT_TYPE_MODE DISABLED
73#endif
74
77#ifndef VSF_USART_CFG_REIMPLEMENT_TYPE_IRQ_MASK
78# define VSF_USART_CFG_REIMPLEMENT_TYPE_IRQ_MASK DISABLED
79#endif
80
83#ifndef VSF_USART_CFG_REIMPLEMENT_TYPE_STATUS
84# define VSF_USART_CFG_REIMPLEMENT_TYPE_STATUS DISABLED
85#endif
86
89#ifndef VSF_USART_CFG_REIMPLEMENT_TYPE_CMD
90# define VSF_USART_CFG_REIMPLEMENT_TYPE_CMD DISABLED
91#endif
92
93#ifndef VSF_USART_CFG_REIMPLEMENT_MODE_TO_DATA_BITS
94# define VSF_USART_CFG_REIMPLEMENT_MODE_TO_DATA_BITS \
95 DISABLED
96#endif
97
101#if VSF_USART_CFG_REIMPLEMENT_TYPE_CFG == DISABLED
102# define VSF_USART_CFG_REIMPLEMENT_TYPE_CFG DISABLED
103#endif
104
108#if VSF_USART_CFG_REIMPLEMENT_TYPE_CAPABILITY == DISABLED
109# define VSF_USART_CFG_REIMPLEMENT_TYPE_CAPABILITY DISABLED
110#endif
111
112#ifndef VSF_USART_CFG_INHERT_HAL_CAPABILITY
113# define VSF_USART_CFG_INHERT_HAL_CAPABILITY ENABLED
114#endif
115
116#ifndef VSF_USART_CFG_REQUEST_API
117# define VSF_USART_CFG_REQUEST_API ENABLED
118#endif
119
120#ifndef VSF_USART_CFG_FIFO_API
121# define VSF_USART_CFG_FIFO_API ENABLED
122#endif
123
124/*============================ MACROFIED FUNCTIONS ===========================*/
125
126#define __VSF_USART_BASE_APIS(__prefix_name) \
127 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_err_t, usart, init, VSF_MCONNECT(__prefix_name, _usart_t) *usart_ptr, vsf_usart_cfg_t *cfg_ptr) \
128 __VSF_HAL_TEMPLATE_API(__prefix_name, void, usart, fini, VSF_MCONNECT(__prefix_name, _usart_t) *usart_ptr) \
129 __VSF_HAL_TEMPLATE_API(__prefix_name, fsm_rt_t, usart, enable, VSF_MCONNECT(__prefix_name, _usart_t) *usart_ptr) \
130 __VSF_HAL_TEMPLATE_API(__prefix_name, fsm_rt_t, usart, disable, VSF_MCONNECT(__prefix_name, _usart_t) *usart_ptr) \
131 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_usart_capability_t, usart, capability, VSF_MCONNECT(__prefix_name, _usart_t) *usart_ptr) \
132 __VSF_HAL_TEMPLATE_API(__prefix_name, void, usart, irq_enable, VSF_MCONNECT(__prefix_name, _usart_t) *usart_ptr, vsf_usart_irq_mask_t irq_mask) \
133 __VSF_HAL_TEMPLATE_API(__prefix_name, void, usart, irq_disable, VSF_MCONNECT(__prefix_name, _usart_t) *usart_ptr, vsf_usart_irq_mask_t irq_mask) \
134 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_usart_status_t, usart, status, VSF_MCONNECT(__prefix_name, _usart_t) *usart_ptr)
135
136#if VSF_USART_CFG_FIFO_API == ENABLED
137# define __VSF_USART_FIFO_APIS(__prefix_name) \
138 __VSF_HAL_TEMPLATE_API(__prefix_name, uint_fast16_t, usart, rxfifo_get_data_count, VSF_MCONNECT(__prefix_name, _usart_t) *usart_ptr) \
139 __VSF_HAL_TEMPLATE_API(__prefix_name, uint_fast16_t, usart, rxfifo_read, VSF_MCONNECT(__prefix_name, _usart_t) *usart_ptr, void *buffer_ptr, uint_fast16_t count) \
140 __VSF_HAL_TEMPLATE_API(__prefix_name, uint_fast16_t, usart, txfifo_get_free_count, VSF_MCONNECT(__prefix_name, _usart_t) *usart_ptr) \
141 __VSF_HAL_TEMPLATE_API(__prefix_name, uint_fast16_t, usart, txfifo_write, VSF_MCONNECT(__prefix_name, _usart_t) *usart_ptr, void *buffer_ptr, uint_fast16_t count)
142#else
143# define __VSF_USART_FIFO_APIS(__prefix_name)
144#endif
145
146#if VSF_USART_CFG_REQUEST_API == ENABLED
147# define __VSF_USART_REQUEST_APIS(__prefix_name) \
148 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_err_t, usart, request_rx, VSF_MCONNECT(__prefix_name, _usart_t) *usart_ptr, void *buffer_ptr, uint_fast32_t count) \
149 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_err_t, usart, request_tx, VSF_MCONNECT(__prefix_name, _usart_t) *usart_ptr, void *buffer_ptr, uint_fast32_t count) \
150 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_err_t, usart, cancel_rx, VSF_MCONNECT(__prefix_name, _usart_t) *usart_ptr) \
151 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_err_t, usart, cancel_tx, VSF_MCONNECT(__prefix_name, _usart_t) *usart_ptr) \
152 __VSF_HAL_TEMPLATE_API(__prefix_name, int_fast32_t, usart, get_rx_count, VSF_MCONNECT(__prefix_name, _usart_t) *usart_ptr) \
153 __VSF_HAL_TEMPLATE_API(__prefix_name, int_fast32_t, usart, get_tx_count, VSF_MCONNECT(__prefix_name, _usart_t) *usart_ptr)
154#else
155# define __VSF_USART_REQUEST_APIS(__prefix_name)
156#endif
157
158#define __VSF_USART_REQUEST_EXTRA_APIS(__prefix_name) \
159 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_err_t, usart, cmd, VSF_MCONNECT(__prefix_name, _usart_t) *usart_ptr, vsf_usart_cmd_t cmd, void* param)
160
161#define VSF_USART_ADDITIONAL_APIS(__prefix_name) \
162 static inline vsf_err_t VSF_MCONNECT(__prefix_name, _usart_send_break) \
163 (VSF_MCONNECT(__prefix_name, _usart_t) *usart_ptr) \
164 { \
165 return VSF_MCONNECT(__prefix_name, _usart_cmd)(usart_ptr, \
166 VSF_USART_CMD_SEND_BREAK, NULL); \
167 } \
168 static inline vsf_err_t VSF_MCONNECT(__prefix_name, _usart_set_break) \
169 (VSF_MCONNECT(__prefix_name, _usart_t) *usart_ptr) \
170 { \
171 vsf_usart_capability_t cap = \
172 VSF_MCONNECT(__prefix_name, _usart_capability)(usart_ptr); \
173 VSF_HAL_ASSERT(cap.support_set_and_clear_break); \
174 return VSF_MCONNECT(__prefix_name, _usart_cmd)(usart_ptr, \
175 VSF_USART_CMD_SET_BREAK, NULL); \
176 } \
177 static inline vsf_err_t VSF_MCONNECT(__prefix_name, _usart_clear_break) \
178 (VSF_MCONNECT(__prefix_name, _usart_t) *usart_ptr) \
179 { \
180 vsf_usart_capability_t cap = \
181 VSF_MCONNECT(__prefix_name, _usart_capability)(usart_ptr); \
182 VSF_HAL_ASSERT(cap.support_set_and_clear_break); \
183 return VSF_MCONNECT(__prefix_name, _usart_cmd)(usart_ptr, \
184 VSF_USART_CMD_CLEAR_BREAK, NULL); \
185 }
186
187#define VSF_USART_APIS(__prefix_name) \
188 __VSF_USART_BASE_APIS(__prefix_name) \
189 __VSF_USART_FIFO_APIS(__prefix_name) \
190 __VSF_USART_REQUEST_APIS(__prefix_name) \
191 __VSF_USART_REQUEST_EXTRA_APIS(__prefix_name)
192
193/*============================ TYPES =========================================*/
194
195#if VSF_USART_CFG_REIMPLEMENT_TYPE_MODE == DISABLED
270typedef enum vsf_usart_mode_t {
272 VSF_USART_NO_PARITY = (0x0ul << 0),
273 VSF_USART_EVEN_PARITY = (0x1ul << 0),
274 VSF_USART_ODD_PARITY = (0x2ul << 0),
277
279 VSF_USART_1_STOPBIT = (0x0ul << 3),
280 VSF_USART_1_5_STOPBIT = (0x1ul << 3),
281 VSF_USART_0_5_STOPBIT = (0x2ul << 3),
282 VSF_USART_2_STOPBIT = (0x3ul << 3),
283
285 VSF_USART_5_BIT_LENGTH = (0x0ul << 5),
286 VSF_USART_6_BIT_LENGTH = (0x1ul << 5),
287 VSF_USART_7_BIT_LENGTH = (0x2ul << 5),
288 VSF_USART_8_BIT_LENGTH = (0x3ul << 5),
289 VSF_USART_9_BIT_LENGTH = (0x4ul << 5),
290 VSF_USART_10_BIT_LENGTH = (0x5ul << 5),
291
297
298 VSF_USART_TX_ENABLE = (0x0ul << 9),
299 VSF_USART_TX_DISABLE = (0x1ul << 9),
300
301 VSF_USART_RX_ENABLE = (0x0ul << 10),
302 VSF_USART_RX_DISABLE = (0x1ul << 10),
303
306
312
315
318 /*
319 // Here are some examples of fifo implementations
320
321 // Example A of driver-specific threshold
322 VSF_USART_TX_FIFO_THRESHOLD_1_8 = (0x0ul << 15), //!< TX FIFO reaches 1/8 of its depth
323 VSF_USART_TX_FIFO_THRESHOLD_1_4 = (0x1ul << 15), //!< TX FIFO reaches 1/4 of its depth
324 VSF_USART_TX_FIFO_THRESHOLD_1_2 = (0x2ul << 15), //!< TX FIFO reaches 1/2 of its depth
325 VSF_USART_TX_FIFO_THRESHOLD_3_4 = (0x3ul << 15), //!< TX FIFO reaches 3/4 of its depth
326 VSF_USART_TX_FIFO_THRESHOLD_7_8 = (0x4ul << 15), //!< TX FIFO reaches 7/8 of its depth
327 VSF_USART_TX_FIFO_THRESHOLD_EMPTY = (0x5ul << 15), //!< TX FIFO becoms empty
328 VSF_USART_TX_FIFO_THRESHOLD_HALF_EMPTY = VSF_USART_TX_FIFO_THRESHOLD_1_2,
329 VSF_USART_TX_FIFO_THRESHOLD_NOT_FULL = (0x6ul << 15),
330
331 // Example B of driver-specific threshold
332 VSF_USART_TX_FIFO_THRESHOLD_1 = (0x0ul << 15), //!< Triggers VSF_USART_IRQ_MASK_TX interrupt when the data in TX FIFO is less than 1
333 VSF_USART_TX_FIFO_THRESHOLD_2 = (0x1ul << 15), //!< Triggers VSF_USART_IRQ_MASK_TX interrupt when the data in TX FIFO is less than 2
334 VSF_USART_TX_FIFO_THRESHOLD_3 = (0x2ul << 15), //!< Triggers VSF_USART_IRQ_MASK_TX interrupt when the data in TX FIFO is less than 3
335 VSF_USART_TX_FIFO_THRESHOLD_4 = (0x3ul << 15), //!< Triggers VSF_USART_IRQ_MASK_TX interrupt when the data in TX FIFO is less than 4
336 VSF_USART_TX_FIFO_THRESHOLD_5 = (0x4ul << 15), //!< Triggers VSF_USART_IRQ_MASK_TX interrupt when the data in TX FIFO is less than 5
337 VSF_USART_TX_FIFO_THRESHOLD_6 = (0x5ul << 15), //!< Triggers VSF_USART_IRQ_MASK_TX interrupt when the data in TX FIFO is less than 6
338 VSF_USART_TX_FIFO_THRESHOLD_7 = (0x6ul << 15), //!< Triggers VSF_USART_IRQ_MASK_TX interrupt when the data in TX FIFO is less than 7
339 VSF_USART_TX_FIFO_THRESHOLD_8 = (0x7ul << 15), //!< Triggers VSF_USART_IRQ_MASK_TX interrupt when the data in TX FIFO is less than 8
340 VSF_USART_TX_FIFO_THRESHOLD_EMPTY = VSF_USART_TX_FIFO_THRESHOLD_1,
341 VSF_USART_TX_FIFO_THRESHOLD_HALF_EMPTY = VSF_USART_TX_FIFO_THRESHOLD_4,
342 VSF_USART_TX_FIFO_THRESHOLD_NOT_FULL = VSF_USART_TX_FIFO_THRESHOLD_8,
343 */
350
351 /*
352 // Here are some examples of fifo implementations
353
354 // Example A of driver-specific threshold
355 VSF_USART_RX_FIFO_THRESHOLD_1_8 = (0x0ul << 17), //!< RX FIFO reaches 1/8 of its depth
356 VSF_USART_RX_FIFO_THRESHOLD_1_4 = (0x1ul << 17), //!< RX FIFO reaches 1/4 of its depth
357 VSF_USART_RX_FIFO_THRESHOLD_1_2 = (0x2ul << 17), //!< RX FIFO reaches 1/2 of its depth
358 VSF_USART_RX_FIFO_THRESHOLD_3_4 = (0x3ul << 17), //!< RX FIFO reaches 3/4 of its depth
359 VSF_USART_RX_FIFO_THRESHOLD_7_8 = (0x4ul << 17), //!< RX FIFO reaches 7/8 of its depth
360 VSF_USART_RX_FIFO_THRESHOLD_NOT_EMPTY = VSF_USART_RX_FIFO_THRESHOLD_1_8,
361 VSF_USART_RX_FIFO_THRESHOLD_HALF_FULL = VSF_USART_RX_FIFO_THRESHOLD_1_2,
362 VSF_USART_RX_FIFO_THRESHOLD_FULL = (0x5ul << 17), //!< RX FIFO becomes full
363
364 // Example B of driver-specific threshold
366 VSF_USART_RX_FIFO_THRESHOLD_1 = (0x0ul << 17),
368 VSF_USART_RX_FIFO_THRESHOLD_2 = (0x1ul << 17),
370 VSF_USART_RX_FIFO_THRESHOLD_3 = (0x2ul << 17),
372 VSF_USART_RX_FIFO_THRESHOLD_4 = (0x3ul << 17),
374 VSF_USART_RX_FIFO_THRESHOLD_5 = (0x4ul << 17),
376 VSF_USART_RX_FIFO_THRESHOLD_6 = (0x5ul << 17),
378 VSF_USART_RX_FIFO_THRESHOLD_7 = (0x6ul << 17),
380 VSF_USART_RX_FIFO_THRESHOLD_8 = (0x7ul << 17),
381 VSF_USART_RX_FIFO_THRESHOLD_NOT_EMPTY = VSF_USART_RX_FIFO_THRESHOLD_1,
382 VSF_USART_RX_FIFO_THRESHOLD_HALF_FULL = VSF_USART_RX_FIFO_THRESHOLD_4,
383 VSF_USART_RX_FIFO_THRESHOLD_FULL = VSF_USART_RX_FIFO_THRESHOLD_8,
384 */
390
391 /* Optional mode
393 VSF_USART_IRDA_ENABLE = (0x1ul << 18),
394 VSF_USART_IRDA_DISABLE = (0x0ul << 18),
395 #define VSF_USART_IRDA_ENABLE VSF_USART_IRDA_ENABLE
396 #define VSF_USART_IRDA_DISABLE VSF_USART_IRDA_DISABLE
397 #define VSF_USART_IRDA_MASK VSF_USART_IRDA_ENABLE | VSF_USART_IRDA_DISABLE
398
399 VSF_USART_SMARTCARD_ENABLE = (0x1ul << 19),
400 VSF_USART_SMARTCARD_DISABLE = (0x0ul << 19),
401 #define VSF_USART_SMARTCARD_ENABLE VSF_USART_SMARTCARD_ENABLE
402 #define VSF_USART_SMARTCARD_DISABLE VSF_USART_SMARTCARD_DISABLE
403 #define VSF_USART_SMARTCARD_MASK VSF_USART_SMARTCARDENABLE | VSF_USART_SMARTCARD_DISABLE
404
405 // whether the clock pulse corresponding to the last transmitted
406 VSF_USART_SYNC_CLOCK_LAST_BIT_ENABLE = (0x0ul << 20),
407 VSF_USART_SYNC_CLOCK_LAST_BIT_DISABLE = (0x0ul << 20),
408 #define VSF_USART_SYNC_CLOCK_LAST_BIT_ENABLE VSF_USART_SYNC_CLOCK_LAST_BIT_ENABLE
409 #define VSF_USART_SYNC_CLOCK_LAST_BIT_DISABLE VSF_USART_SYNC_CLOCK_LAST_BIT_DISABLE
410 #define VSF_USART_SYNC_CLOCK_LAST_BIT_MASK VSF_USART_SYNC_CLOCK_LAST_BIT_ENABLE | \
411 VSF_USART_SYNC_CLOCK_LAST_BIT_DISABLE
412
413 // divisor of IRDA clock
414 VSF_USART_IRDA_PRESCALER_BIT_OFFSET = (21),
415 VSF_USART_IRDA_PRESCALER_MASK = (0xFul << VSF_USART_IRDA_PRESCALER_BIT_OFFSET),
416 #define VSF_USART_IRDA_PRESCALER_BIT_OFFSET VSF_USART_IRDA_PRESCALER_BIT_OFFSET
417 #define VSF_USART_IRDA_PRESCALER_MASK VSF_USART_IRDA_PRESCALER_MASK
418 */
420#endif
421
422enum {
423#ifndef VSF_USART_PARITY_MASK
429#endif
430
431#ifndef VSF_USART_STOPBIT_MASK
436#endif
437
438#ifndef VSF_USART_BIT_LENGTH_MASK
445#endif
446
447#ifndef VSF_USART_TX_FIFO_THRESHOLD_MASK
451#endif
452
453#ifndef VSF_USART_RX_FIFO_THRESHOLD_MASK
457#endif
458
459#ifndef VSF_USART_HWCONTROL_MASK
464#endif
465
468
471
474
477
480
483
484
485
498#ifdef VSF_USART_SYNC_CLOCK_LAST_BIT_MASK
500#endif
501
502#ifdef VSF_USART_IRDA_PRESCALER_MASK
503 | VSF_USART_IRDA_PRESCALER_MASK
504#endif
505#ifdef VSF_USART_IRDA_MASK
506 | VSF_USART_IRDA_MASK
507#endif
508
509#ifdef VSF_USART_SMARTCARD_MASK
510 | VSF_USART_SMARTCARD_MASK
511#endif
513
514#if VSF_USART_CFG_REIMPLEMENT_TYPE_IRQ_MASK == DISABLED
538 // request_rx/request_tx complete
541
542 // TX/RX reach fifo threshold, threshold on some devices is bound to 1
543 VSF_USART_IRQ_MASK_TX = (0x1ul << 2),
544 VSF_USART_IRQ_MASK_RX = (0x1ul << 3),
546
547 // clear to send interrupt
549
550 // Error interrupt
555
556 /*
557 VSF_USART_IRQ_MASK_TX_HALF_CPL = (0x1ul << 10),
558 #define VSF_USART_IRQ_MASK_TX_HALF_CPL VSF_USART_IRQ_MASK_TX_HALF_CPL
559 VSF_USART_IRQ_MASK_RX_HALF_CPL = (0x1ul << 11),
560 #define VSF_USART_IRQ_MASK_RX_HALF_CPL VSF_USART_IRQ_MASK_RX_HALF_CPL
561
562 VSF_USART_IRQ_MASK_CANCEL_TX_CPL = (0x1ul << 12),
563 #define VSF_USART_IRQ_MASK_CANCEL_TX_CPL VSF_USART_IRQ_MASK_CANCEL_TX_CPL
564 VSF_USART_IRQ_MASK_CANCEL_RX_CPL = (0x1ul << 13),
565 #define VSF_USART_IRQ_MASK_CANCEL_RX_CPL VSF_USART_IRQ_MASK_CANCEL_RX_CPL
566
567 VSF_USART_IRQ_MASK_NOISE_ERR = (0x1ul << 14),
568 #define VSF_USART_IRQ_MASK_NOISE_ERR VSF_USART_IRQ_MASK_NOISE_ERR
569 */
571#endif
572
573enum {
577
578#ifndef VSF_USART_IRQ_MASK_ERR
583#endif
584
585#ifndef VSF_USART_IRQ_ALL_BITS_MASK
593# ifdef VSF_USART_IRQ_MASK_TX_HALF_CPL
594 | VSF_USART_IRQ_MASK_TX_HALF_CPL
595# endif
596# ifdef VSF_USART_IRQ_MASK_RX_HALF_CPL
597 | VSF_USART_IRQ_MASK_RX_HALF_CPL
598# endif
599# ifdef VSF_USART_IRQ_MASK_CANCEL_TX_CPL
600 | VSF_USART_IRQ_MASK_CANCEL_TX_CPL
601# endif
602# ifdef VSF_USART_IRQ_MASK_CANCEL_RX_CPL
603 | VSF_USART_IRQ_MASK_CANCEL_RX_CPL
604# endif
605#endif
606};
607
608#if VSF_USART_CFG_REIMPLEMENT_TYPE_CFG == DISABLED
610
611typedef void vsf_usart_isr_handler_t(void *target_ptr,
612 vsf_usart_t *usart_ptr,
614
615typedef struct vsf_usart_isr_t {
620
621typedef struct vsf_usart_cfg_t {
627#endif
628
629#if VSF_USART_CFG_REIMPLEMENT_TYPE_CMD == DISABLED
647typedef enum vsf_usart_cmd_t {
652
654 VSF_USART_CMD_SET_BREAK = (0x01ul << 1),
657
658 /*
659 VSF_USART_CMD_REQUEST_RX_RESUME = (0x1ul << 3),
660 #define VSF_USART_CMD_REQUEST_RX_RESUME VSF_USART_CMD_REQUEST_RX_RESUME
661 VSF_USART_CMD_REQUEST_TX_RESUME = (0x1ul << 4),
662 #define VSF_USART_CMD_REQUEST_TX_RESUME VSF_USART_CMD_REQUEST_TX_RESUME
663
664 VSF_USART_CMD_REQUEST_RX_PAUSE = (0x1ul << 5),
665 #define VSF_USART_CMD_REQUEST_RX_PAUSE VSF_USART_CMD_REQUEST_RX_PAUSE
666 VSF_USART_CMD_REQUEST_TX_PAUSE = (0x1ul << 6),
667 #define VSF_USART_CMD_REQUEST_TX_PAUSE VSF_USART_CMD_REQUEST_TX_PAUSE
668
669 VSF_USART_CMD_HALF_DUPLEX_ENABLE_TRANSMITTER = (0x1ul << 7),
670 #define VSF_USART_CMD_HALF_DUPLEX_ENABLE_TRANSMITTER VSF_USART_CMD_HALF_DUPLEX_ENABLE_TRANSMITTER
671
672 VSF_USART_CMD_HALF_DUPLEX_ENABLE_RECEIVER = (0x1ul << 8),
673 #define VSF_USART_CMD_HALF_DUPLEX_ENABLE_RECEIVER VSF_USART_CMD_HALF_DUPLEX_ENABLE_RECEIVER
674 */
676#endif
677
678#if VSF_USART_CFG_REIMPLEMENT_TYPE_STATUS == DISABLED
679typedef struct vsf_usart_status_t {
680 union {
682 struct {
683 uint32_t is_busy : 1;
684 uint32_t is_tx_busy : 1;
685 uint32_t is_rx_busy : 1;
686 // TX FIFO threshold in bytes
687 uint32_t tx_fifo_thresh : 8;
688 // RX FIFO threshold in bytes
689 uint32_t rx_fifo_thresh : 8;
690 };
691 };
693#endif
694
696#if VSF_USART_CFG_INHERT_HAL_CAPABILITY == ENABLED
698#endif
700
701 // baudrate range
704
705 // TX FIFO depth, in data count (frame)
707 // RX FIFO depth, in data count (frame)
709
712
717
718typedef struct vsf_usart_op_t {
719#undef __VSF_HAL_TEMPLATE_API
720#define __VSF_HAL_TEMPLATE_API VSF_HAL_TEMPLATE_API_FP
721
722 VSF_USART_APIS(vsf)
724
725#if VSF_USART_CFG_MULTI_CLASS == ENABLED
728};
729#endif
730
731/*============================ PROTOTYPES ====================================*/
732
752extern vsf_err_t vsf_usart_init(vsf_usart_t *usart_ptr, vsf_usart_cfg_t *cfg_ptr);
753
765extern void vsf_usart_fini(vsf_usart_t *usart_ptr);
766
778extern fsm_rt_t vsf_usart_enable(vsf_usart_t *usart_ptr);
779
791extern fsm_rt_t vsf_usart_disable(vsf_usart_t *usart_ptr);
792
809
824
837
850
863
879extern uint_fast16_t vsf_usart_rxfifo_read(vsf_usart_t *usart_ptr, void *buffer_ptr, uint_fast16_t count);
880
899
915extern uint_fast16_t vsf_usart_txfifo_write(vsf_usart_t *usart_ptr, void *buffer_ptr, uint_fast16_t count);
916
932extern vsf_err_t vsf_usart_request_rx(vsf_usart_t *usart_ptr, void *buffer_ptr, uint_fast32_t count);
933
951extern vsf_err_t vsf_usart_request_tx(vsf_usart_t *usart_ptr, void *buffer_ptr, uint_fast32_t count);
952
964extern vsf_err_t vsf_usart_cancel_rx(vsf_usart_t *usart_ptr);
965
976extern vsf_err_t vsf_usart_cancel_tx(vsf_usart_t *usart_ptr);
977
991
1005
1021extern vsf_err_t vsf_usart_cmd(vsf_usart_t *usart_ptr, vsf_usart_cmd_t cmd, void * param);
1022
1023/*============================ INLINE FUNCTIONS ==============================*/
1024
1025#if VSF_USART_CFG_REIMPLEMENT_MODE_TO_DATA_BITS == DISABLED
1026static inline uint8_t vsf_usart_mode_to_data_bits(vsf_usart_mode_t mode)
1027{
1028 switch (mode & VSF_USART_BIT_LENGTH_MASK) {
1030 return 5;
1032 return 6;
1034 return 7;
1036 return 8;
1038 return 9;
1040 return 10;
1041 default:
1042 return 0;
1043 }
1044}
1045#endif
1046
1059static inline vsf_err_t vsf_usart_send_break(vsf_usart_t *usart_ptr)
1060{
1063
1064 return vsf_usart_cmd(usart_ptr, VSF_USART_CMD_SEND_BREAK, NULL);
1065}
1066
1078static inline vsf_err_t vsf_usart_set_break(vsf_usart_t *usart_ptr)
1079{
1082
1083 return vsf_usart_cmd(usart_ptr, VSF_USART_CMD_SET_BREAK, NULL);
1084}
1085
1097static inline vsf_err_t vsf_usart_clear_break(vsf_usart_t *usart_ptr)
1098{
1101
1102 return vsf_usart_cmd(usart_ptr, VSF_USART_CMD_CLEAR_BREAK, NULL);
1103}
1104
1105/*============================ MACROFIED FUNCTIONS ===========================*/
1106
1107#if VSF_USART_CFG_FUNCTION_RENAME == ENABLED
1108# define __vsf_usart_t VSF_MCONNECT(VSF_USART_CFG_PREFIX, _usart_t)
1109# define vsf_usart_init(__USART, ...) VSF_MCONNECT(VSF_USART_CFG_PREFIX, _usart_init) ((__vsf_usart_t *)(__USART), ##__VA_ARGS__)
1110# define vsf_usart_fini(__USART) VSF_MCONNECT(VSF_USART_CFG_PREFIX, _usart_fini) ((__vsf_usart_t *)(__USART))
1111# define vsf_usart_capability(__USART) VSF_MCONNECT(VSF_USART_CFG_PREFIX, _usart_capability) ((__vsf_usart_t *)(__USART))
1112# define vsf_usart_enable(__USART) VSF_MCONNECT(VSF_USART_CFG_PREFIX, _usart_enable) ((__vsf_usart_t *)(__USART))
1113# define vsf_usart_disable(__USART) VSF_MCONNECT(VSF_USART_CFG_PREFIX, _usart_disable) ((__vsf_usart_t *)(__USART))
1114# define vsf_usart_irq_enable(__USART, ...) VSF_MCONNECT(VSF_USART_CFG_PREFIX, _usart_irq_enable) ((__vsf_usart_t *)(__USART), ##__VA_ARGS__)
1115# define vsf_usart_irq_disable(__USART, ...) VSF_MCONNECT(VSF_USART_CFG_PREFIX, _usart_irq_disable) ((__vsf_usart_t *)(__USART), ##__VA_ARGS__)
1116# define vsf_usart_status(__USART) VSF_MCONNECT(VSF_USART_CFG_PREFIX, _usart_status) ((__vsf_usart_t *)(__USART))
1117# define vsf_usart_rxfifo_get_data_count(__USART, ...) VSF_MCONNECT(VSF_USART_CFG_PREFIX, _usart_rxfifo_get_data_count) ((__vsf_usart_t *)(__USART), ##__VA_ARGS__)
1118# define vsf_usart_rxfifo_read(__USART, ...) VSF_MCONNECT(VSF_USART_CFG_PREFIX, _usart_rxfifo_read) ((__vsf_usart_t *)(__USART), ##__VA_ARGS__)
1119# define vsf_usart_txfifo_get_free_count(__USART, ...) VSF_MCONNECT(VSF_USART_CFG_PREFIX, _usart_txfifo_get_free_count) ((__vsf_usart_t *)(__USART), ##__VA_ARGS__)
1120# define vsf_usart_txfifo_write(__USART, ...) VSF_MCONNECT(VSF_USART_CFG_PREFIX, _usart_txfifo_write) ((__vsf_usart_t *)(__USART), ##__VA_ARGS__)
1121# define vsf_usart_request_rx(__USART, ...) VSF_MCONNECT(VSF_USART_CFG_PREFIX, _usart_request_rx) ((__vsf_usart_t *)(__USART), ##__VA_ARGS__)
1122# define vsf_usart_request_tx(__USART, ...) VSF_MCONNECT(VSF_USART_CFG_PREFIX, _usart_request_tx) ((__vsf_usart_t *)(__USART), ##__VA_ARGS__)
1123# define vsf_usart_cancel_rx(__USART) VSF_MCONNECT(VSF_USART_CFG_PREFIX, _usart_cancel_rx) ((__vsf_usart_t *)(__USART))
1124# define vsf_usart_cancel_tx(__USART) VSF_MCONNECT(VSF_USART_CFG_PREFIX, _usart_cancel_tx) ((__vsf_usart_t *)(__USART))
1125# define vsf_usart_get_rx_count(__USART) VSF_MCONNECT(VSF_USART_CFG_PREFIX, _usart_get_rx_count) ((__vsf_usart_t *)(__USART))
1126# define vsf_usart_get_tx_count(__USART) VSF_MCONNECT(VSF_USART_CFG_PREFIX, _usart_get_tx_count) ((__vsf_usart_t *)(__USART))
1127# define vsf_usart_send_break(__USART, ...) VSF_MCONNECT(VSF_USART_CFG_PREFIX, _usart_send_break) ((__vsf_usart_t *)(__USART))
1128# define vsf_usart_set_break(__USART) VSF_MCONNECT(VSF_USART_CFG_PREFIX, _usart_send_break) ((__vsf_usart_t *)(__USART))
1129# define vsf_usart_clear_break(__USART) VSF_MCONNECT(VSF_USART_CFG_PREFIX, _usart_send_break) ((__vsf_usart_t *)(__USART))
1130# define vsf_usart_cmd(__USART, ...) VSF_MCONNECT(VSF_USART_CFG_PREFIX, _usart_cmd) ((__vsf_usart_t *)(__USART), ##__VA_ARGS__)
1131#endif
1132
1133/*============================ INCLUDES ======================================*/
1134
1135#ifdef __cplusplus
1136}
1137#endif
1138
1139#endif
vsf_err_t
Definition __type.h:42
vsf_usart_mode_t
Definition uart.h:32
vsf_usart_irq_mask_t
Definition uart.h:106
#define VSF_USART_SYNC_CLOCK_LAST_BIT_MASK
Definition usart.h:129
vsf_arch_prio_t
Definition cortex_a_generic.h:88
#define NULL
Definition lvgl.h:26
unsigned int uint32_t
Definition lvgl.h:43
unsigned char uint8_t
Definition lvgl.h:40
const i_spi_t vsf_spi_irq_mask_t irq_mask
Definition spi_interface.h:38
unsigned int uint_fast32_t
Definition stdint.h:27
int int_fast32_t
Definition stdint.h:26
unsigned short uint_fast16_t
Definition stdint.h:25
Definition vsf_template_hal_driver.h:203
Definition vsf_template_hal_driver.h:196
Definition vsf_template_usart.h:695
uint8_t max_data_bits
Definition vsf_template_usart.h:710
uint8_t support_set_and_clear_break
Definition vsf_template_usart.h:715
inherit(vsf_peripheral_capability_t) vsf_usart_irq_mask_t irq_mask
uint8_t support_rx_timeout
Definition vsf_template_usart.h:713
uint8_t rxfifo_depth
Definition vsf_template_usart.h:708
uint8_t support_send_break
Definition vsf_template_usart.h:714
uint8_t txfifo_depth
Definition vsf_template_usart.h:706
uint8_t min_data_bits
Definition vsf_template_usart.h:711
uint32_t min_baudrate
Definition vsf_template_usart.h:703
uint32_t max_baudrate
Definition vsf_template_usart.h:702
Definition vsf_template_usart.h:621
uint32_t mode
Definition vsf_template_usart.h:622
uint32_t baudrate
Definition vsf_template_usart.h:623
uint32_t rx_timeout
Definition vsf_template_usart.h:624
vsf_usart_isr_t isr
Definition vsf_template_usart.h:625
Definition vsf_template_usart.h:615
vsf_arch_prio_t prio
Definition vsf_template_usart.h:618
vsf_usart_isr_handler_t * handler_fn
Definition vsf_template_usart.h:616
void * target_ptr
Definition vsf_template_usart.h:617
Definition vsf_template_usart.h:718
Definition uart.h:156
uint32_t is_busy
Definition usart.h:280
Definition vsf_template_usart.h:726
const vsf_usart_op_t * op
Definition vsf_template_usart.h:727
fsm_rt_t
Definition vsf_fsm.h:315
#define VSF_HAL_ASSERT(__CON)
all hal modules use this configuration file
Definition vsf_hal_cfg.h:36
#define vsf_usart_send_break(__USART,...)
Definition vsf_template_usart.h:1127
#define vsf_usart_txfifo_get_free_count(__USART,...)
Definition vsf_template_usart.h:1119
#define vsf_usart_disable(__USART)
Definition vsf_template_usart.h:1113
@ VSF_USART_IRQ_MASK_ERR
Definition vsf_template_usart.h:579
@ VSF_USART_IRQ_MASK_TX_FIFO_THRESHOLD
Definition vsf_template_usart.h:575
@ VSF_USART_IRQ_ALL_BITS_MASK
Definition vsf_template_usart.h:586
@ VSF_USART_IRQ_MASK_RX_IDLE
Definition vsf_template_usart.h:574
@ VSF_USART_IRQ_MASK_RX_FIFO_THRESHOLD
Definition vsf_template_usart.h:576
#define vsf_usart_init(__USART,...)
Definition vsf_template_usart.h:1109
#define vsf_usart_capability(__USART)
Definition vsf_template_usart.h:1111
vsf_usart_mode_t
Predefined VSF USART modes that can be reimplemented in specific hal drivers.
Definition vsf_template_usart.h:270
@ VSF_USART_TX_FIFO_THRESHOLD_EMPTY
TX FIFO becomes emtpy.
Definition vsf_template_usart.h:344
@ VSF_USART_HALF_DUPLEX_DISABLE
Definition vsf_template_usart.h:313
@ VSF_USART_8_BIT_LENGTH
data bits : 8,
Definition vsf_template_usart.h:288
@ VSF_USART_SYNC_CLOCK_ENABLE
Definition vsf_template_usart.h:304
@ VSF_USART_EVEN_PARITY
Definition vsf_template_usart.h:273
@ VSF_USART_RX_FIFO_THRESHOLD_NOT_EMPTY
Definition vsf_template_usart.h:387
@ VSF_USART_ODD_PARITY
Definition vsf_template_usart.h:274
@ VSF_USART_SYNC_CLOCK_PHASE_1_EDGE
Definition vsf_template_usart.h:310
@ VSF_USART_NO_PARITY
USART Parity.
Definition vsf_template_usart.h:272
@ VSF_USART_10_BIT_LENGTH
data bits : 10,
Definition vsf_template_usart.h:290
@ VSF_USART_RTS_HWCONTROL
Definition vsf_template_usart.h:294
@ VSF_USART_RX_FIFO_THRESHOLD_HALF_FULL
Half of the threshold for RX FIFO.
Definition vsf_template_usart.h:388
@ VSF_USART_RX_ENABLE
Definition vsf_template_usart.h:301
@ VSF_USART_FORCE_0_PARITY
Definition vsf_template_usart.h:275
@ VSF_USART_TX_FIFO_THRESHOLD_NOT_FULL
Definition vsf_template_usart.h:349
@ VSF_USART_TX_ENABLE
Definition vsf_template_usart.h:298
@ VSF_USART_SYNC_CLOCK_POLARITY_HIGH
Definition vsf_template_usart.h:309
@ VSF_USART_9_BIT_LENGTH
data bits : 9,
Definition vsf_template_usart.h:289
@ VSF_USART_7_BIT_LENGTH
data bits : 7,
Definition vsf_template_usart.h:287
@ VSF_USART_1_STOPBIT
USART Stopbit.
Definition vsf_template_usart.h:279
@ VSF_USART_FORCE_1_PARITY
Definition vsf_template_usart.h:276
@ VSF_USART_SYNC_CLOCK_POLARITY_LOW
USART SYNC Mode Clock.
Definition vsf_template_usart.h:308
@ VSF_USART_RX_DISABLE
Definition vsf_template_usart.h:302
@ VSF_USART_2_STOPBIT
stopbit: 2 bit
Definition vsf_template_usart.h:282
@ VSF_USART_CTS_HWCONTROL
Definition vsf_template_usart.h:295
@ VSF_USART_5_BIT_LENGTH
USART Databit Lenght.
Definition vsf_template_usart.h:285
@ VSF_USART_SYNC_CLOCK_DISABLE
Definition vsf_template_usart.h:305
@ VSF_USART_RTS_CTS_HWCONTROL
Definition vsf_template_usart.h:296
@ VSF_USART_SYNC_CLOCK_PHASE_2_EDGE
Definition vsf_template_usart.h:311
@ VSF_USART_HALF_DUPLEX_ENABLE
Definition vsf_template_usart.h:314
@ VSF_USART_TX_DISABLE
Definition vsf_template_usart.h:299
@ VSF_USART_RX_FIFO_THRESHOLD_FULL
Full of the threshold for RX FIFO.
Definition vsf_template_usart.h:389
@ VSF_USART_6_BIT_LENGTH
data bits : 6,
Definition vsf_template_usart.h:286
@ VSF_USART_0_5_STOPBIT
stopbit: 0.5 bit
Definition vsf_template_usart.h:281
@ VSF_USART_TX_FIFO_THRESHOLD_HALF_EMPTY
Definition vsf_template_usart.h:345
@ VSF_USART_NO_HWCONTROL
USART Hardware Control.
Definition vsf_template_usart.h:293
@ VSF_USART_1_5_STOPBIT
stopbit: 1.5 bit
Definition vsf_template_usart.h:280
#define vsf_usart_request_tx(__USART,...)
Definition vsf_template_usart.h:1122
#define vsf_usart_clear_break(__USART)
Definition vsf_template_usart.h:1129
#define vsf_usart_rxfifo_read(__USART,...)
Definition vsf_template_usart.h:1118
#define vsf_usart_irq_disable(__USART,...)
Definition vsf_template_usart.h:1115
#define vsf_usart_rxfifo_get_data_count(__USART,...)
Definition vsf_template_usart.h:1117
#define vsf_usart_cmd(__USART,...)
Definition vsf_template_usart.h:1130
#define vsf_usart_cancel_tx(__USART)
Definition vsf_template_usart.h:1124
#define vsf_usart_request_rx(__USART,...)
Definition vsf_template_usart.h:1121
vsf_usart_cmd_t
Predefined VSF USART command that can be reimplemented in specific hal drivers.
Definition vsf_template_usart.h:647
@ VSF_USART_CMD_SET_BREAK
usart set break condition
Definition vsf_template_usart.h:654
@ VSF_USART_CMD_CLEAR_BREAK
usart clean break condition
Definition vsf_template_usart.h:656
@ VSF_USART_CMD_SEND_BREAK
Definition vsf_template_usart.h:651
@ VSF_USART_BIT_LENGTH_MASK
Definition vsf_template_usart.h:439
@ VSF_USART_SYNC_CLOCK_POLARITY_MASK
Definition vsf_template_usart.h:478
@ VSF_USART_TX_FIFO_THRESHOLD_MASK
Definition vsf_template_usart.h:448
@ VSF_USART_PARITY_MASK
Definition vsf_template_usart.h:424
@ VSF_USART_MODE_ALL_BITS_MASK
Definition vsf_template_usart.h:486
@ VSF_USART_HALF_DUPLEX_MASK
Definition vsf_template_usart.h:475
@ VSF_USART_HWCONTROL_MASK
Definition vsf_template_usart.h:460
@ VSF_USART_RX_MASK
Definition vsf_template_usart.h:469
@ VSF_USART_SYNC_CLOCK_PHASE_MASK
Definition vsf_template_usart.h:481
@ VSF_USART_STOPBIT_MASK
Definition vsf_template_usart.h:432
@ VSF_USART_RX_FIFO_THRESHOLD_MASK
Definition vsf_template_usart.h:454
@ VSF_USART_SYNC_CLOCK_MASK
Definition vsf_template_usart.h:472
@ VSF_USART_TX_MASK
Definition vsf_template_usart.h:466
#define vsf_usart_txfifo_write(__USART,...)
Definition vsf_template_usart.h:1120
#define vsf_usart_cancel_rx(__USART)
Definition vsf_template_usart.h:1123
vsf_usart_irq_mask_t
Predefined VSF USART interrupt that can be reimplemented in specific hal drivers.
Definition vsf_template_usart.h:537
@ VSF_USART_IRQ_MASK_TX_CPL
Definition vsf_template_usart.h:539
@ VSF_USART_IRQ_MASK_OVERFLOW_ERR
Definition vsf_template_usart.h:554
@ VSF_USART_IRQ_MASK_CTS
Definition vsf_template_usart.h:548
@ VSF_USART_IRQ_MASK_TX
Definition vsf_template_usart.h:543
@ VSF_USART_IRQ_MASK_BREAK_ERR
Definition vsf_template_usart.h:553
@ VSF_USART_IRQ_MASK_RX
Definition vsf_template_usart.h:544
@ VSF_USART_IRQ_MASK_RX_TIMEOUT
Definition vsf_template_usart.h:545
@ VSF_USART_IRQ_MASK_RX_CPL
Definition vsf_template_usart.h:540
@ VSF_USART_IRQ_MASK_PARITY_ERR
Definition vsf_template_usart.h:552
@ VSF_USART_IRQ_MASK_FRAME_ERR
Definition vsf_template_usart.h:551
#define vsf_usart_get_tx_count(__USART)
Definition vsf_template_usart.h:1126
#define vsf_usart_status(__USART)
Definition vsf_template_usart.h:1116
#define vsf_usart_get_rx_count(__USART)
Definition vsf_template_usart.h:1125
#define VSF_USART_APIS(__prefix_name)
Definition vsf_template_usart.h:187
struct vsf_usart_status_t vsf_usart_status_t
#define vsf_usart_enable(__USART)
Definition vsf_template_usart.h:1112
#define vsf_usart_fini(__USART)
Definition vsf_template_usart.h:1110
void vsf_usart_isr_handler_t(void *target_ptr, vsf_usart_t *usart_ptr, vsf_usart_irq_mask_t irq_mask)
Definition vsf_template_usart.h:611
#define vsf_usart_irq_enable(__USART,...)
Definition vsf_template_usart.h:1114
#define vsf_usart_set_break(__USART)
Definition vsf_template_usart.h:1128