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
30/*============================ MACROS ========================================*/
31
38#ifndef VSF_USART_CFG_MULTI_CLASS
39# define VSF_USART_CFG_MULTI_CLASS ENABLED
40#endif
41
50#if defined(VSF_HW_USART_COUNT) && !defined(VSF_HW_USART_MASK)
51# define VSF_HW_USART_MASK VSF_HAL_COUNT_TO_MASK(VSF_HW_USART_COUNT)
52#endif
53
62#if defined(VSF_HW_USART_MASK) && !defined(VSF_HW_USART_COUNT)
63# define VSF_HW_USART_COUNT VSF_HAL_MASK_TO_COUNT(VSF_HW_USART_MASK)
64#endif
65
83#ifndef VSF_USART_CFG_PREFIX
84# if VSF_USART_CFG_MULTI_CLASS == ENABLED
85# define VSF_USART_CFG_PREFIX vsf
86# elif defined(VSF_HW_USART_COUNT) && (VSF_HW_USART_COUNT != 0)
87# define VSF_USART_CFG_PREFIX vsf_hw
88# else
89# define VSF_USART_CFG_PREFIX vsf
90# endif
91#endif
92
101#ifndef VSF_USART_CFG_FUNCTION_RENAME
102# define VSF_USART_CFG_FUNCTION_RENAME ENABLED
103#endif
104
113#ifndef VSF_USART_CFG_REIMPLEMENT_TYPE_MODE
114# define VSF_USART_CFG_REIMPLEMENT_TYPE_MODE DISABLED
115#endif
116
125#ifndef VSF_USART_CFG_REIMPLEMENT_TYPE_IRQ_MASK
126# define VSF_USART_CFG_REIMPLEMENT_TYPE_IRQ_MASK DISABLED
127#endif
128
137#ifndef VSF_USART_CFG_REIMPLEMENT_TYPE_STATUS
138# define VSF_USART_CFG_REIMPLEMENT_TYPE_STATUS DISABLED
139#endif
140
149#ifndef VSF_USART_CFG_REIMPLEMENT_TYPE_CTRL
150# define VSF_USART_CFG_REIMPLEMENT_TYPE_CTRL DISABLED
151#endif
152
162#ifndef VSF_USART_CFG_REIMPLEMENT_MODE_TO_DATA_BITS
163# define VSF_USART_CFG_REIMPLEMENT_MODE_TO_DATA_BITS \
164 DISABLED
165#endif
166
176#ifndef VSF_USART_CFG_REIMPLEMENT_TYPE_CFG
177# define VSF_USART_CFG_REIMPLEMENT_TYPE_CFG DISABLED
178#endif
179
190#ifndef VSF_USART_CFG_REIMPLEMENT_TYPE_CAPABILITY
191# define VSF_USART_CFG_REIMPLEMENT_TYPE_CAPABILITY DISABLED
192#endif
193
202#ifndef VSF_USART_CFG_REIMPLEMENT_TYPE_STATUS
203# define VSF_USART_CFG_REIMPLEMENT_TYPE_STATUS DISABLED
204#endif
205
214#ifndef VSF_USART_CFG_INHERIT_HAL_CAPABILITY
215# define VSF_USART_CFG_INHERIT_HAL_CAPABILITY ENABLED
216#endif
217
247#ifndef __VSF_USART_CFG_SUPPORT_STANDARD_OPTIONAL
248# define __VSF_USART_CFG_SUPPORT_STANDARD_OPTIONAL DISABLED
249#endif
250
251/*============================ MACROFIED FUNCTIONS ===========================*/
252
261#define VSF_USART_APIS(__prefix_name) \
262 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_err_t, usart, init, VSF_MCONNECT(__prefix_name, _t) *usart_ptr, vsf_usart_cfg_t *cfg_ptr) \
263 __VSF_HAL_TEMPLATE_API(__prefix_name, void, usart, fini, VSF_MCONNECT(__prefix_name, _t) *usart_ptr) \
264 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_err_t, usart, get_configuration, VSF_MCONNECT(__prefix_name, _t) *usart_ptr, vsf_usart_cfg_t *cfg_ptr) \
265 __VSF_HAL_TEMPLATE_API(__prefix_name, fsm_rt_t, usart, enable, VSF_MCONNECT(__prefix_name, _t) *usart_ptr) \
266 __VSF_HAL_TEMPLATE_API(__prefix_name, fsm_rt_t, usart, disable, VSF_MCONNECT(__prefix_name, _t) *usart_ptr) \
267 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_usart_capability_t, usart, capability, VSF_MCONNECT(__prefix_name, _t) *usart_ptr) \
268 __VSF_HAL_TEMPLATE_API(__prefix_name, void, usart, irq_enable, VSF_MCONNECT(__prefix_name, _t) *usart_ptr, vsf_usart_irq_mask_t irq_mask) \
269 __VSF_HAL_TEMPLATE_API(__prefix_name, void, usart, irq_disable, VSF_MCONNECT(__prefix_name, _t) *usart_ptr, vsf_usart_irq_mask_t irq_mask) \
270 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_usart_irq_mask_t, usart, irq_clear, VSF_MCONNECT(__prefix_name, _t) *usart_ptr, vsf_usart_irq_mask_t irq_mask) \
271 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_usart_status_t, usart, status, VSF_MCONNECT(__prefix_name, _t) *usart_ptr) \
272 __VSF_HAL_TEMPLATE_API(__prefix_name, uint_fast32_t, usart, rxfifo_get_data_count, VSF_MCONNECT(__prefix_name, _t) *usart_ptr) \
273 __VSF_HAL_TEMPLATE_API(__prefix_name, uint_fast32_t, usart, rxfifo_read, VSF_MCONNECT(__prefix_name, _t) *usart_ptr, void *buffer_ptr, uint_fast32_t count) \
274 __VSF_HAL_TEMPLATE_API(__prefix_name, uint_fast32_t, usart, txfifo_get_free_count, VSF_MCONNECT(__prefix_name, _t) *usart_ptr) \
275 __VSF_HAL_TEMPLATE_API(__prefix_name, uint_fast32_t, usart, txfifo_write, VSF_MCONNECT(__prefix_name, _t) *usart_ptr, void *buffer_ptr, uint_fast32_t count) \
276 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_err_t, usart, request_rx, VSF_MCONNECT(__prefix_name, _t) *usart_ptr, void *buffer_ptr, uint_fast32_t count) \
277 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_err_t, usart, request_tx, VSF_MCONNECT(__prefix_name, _t) *usart_ptr, void *buffer_ptr, uint_fast32_t count) \
278 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_err_t, usart, cancel_rx, VSF_MCONNECT(__prefix_name, _t) *usart_ptr) \
279 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_err_t, usart, cancel_tx, VSF_MCONNECT(__prefix_name, _t) *usart_ptr) \
280 __VSF_HAL_TEMPLATE_API(__prefix_name, int_fast32_t, usart, get_rx_count, VSF_MCONNECT(__prefix_name, _t) *usart_ptr) \
281 __VSF_HAL_TEMPLATE_API(__prefix_name, int_fast32_t, usart, get_tx_count, VSF_MCONNECT(__prefix_name, _t) *usart_ptr) \
282 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_err_t, usart, ctrl, VSF_MCONNECT(__prefix_name, _t) *usart_ptr, vsf_usart_ctrl_t ctrl, void* param)
283
284#define VSF_USART_ADDITIONAL_APIS(__prefix_name) \
285 static inline vsf_err_t VSF_MCONNECT(__prefix_name, _send_break) \
286 (VSF_MCONNECT(__prefix_name, _t) *usart_ptr) \
287 { \
288 return VSF_MCONNECT(__prefix_name, _ctrl)(usart_ptr, \
289 VSF_USART_CTRL_SEND_BREAK, NULL); \
290 } \
291 static inline vsf_err_t VSF_MCONNECT(__prefix_name, _set_break) \
292 (VSF_MCONNECT(__prefix_name, _t) *usart_ptr) \
293 { \
294 vsf_usart_capability_t cap = \
295 VSF_MCONNECT(__prefix_name, _capability)(usart_ptr); \
296 VSF_HAL_ASSERT(cap.support_set_and_clear_break); \
297 return VSF_MCONNECT(__prefix_name, _ctrl)(usart_ptr, \
298 VSF_USART_CTRL_SET_BREAK, NULL); \
299 } \
300 static inline vsf_err_t VSF_MCONNECT(__prefix_name, _clear_break) \
301 (VSF_MCONNECT(__prefix_name, _t) *usart_ptr) \
302 { \
303 vsf_usart_capability_t cap = \
304 VSF_MCONNECT(__prefix_name, _capability)(usart_ptr); \
305 VSF_HAL_ASSERT(cap.support_set_and_clear_break); \
306 return VSF_MCONNECT(__prefix_name, _ctrl)(usart_ptr, \
307 VSF_USART_CTRL_CLEAR_BREAK, NULL); \
308 }
309
310/*============================ TYPES =========================================*/
311
312#if VSF_USART_CFG_REIMPLEMENT_TYPE_MODE == DISABLED
384typedef enum vsf_usart_mode_t {
391 VSF_USART_NO_PARITY = (0x0ul << 0),
392 VSF_USART_EVEN_PARITY = (0x1ul << 0),
393 VSF_USART_ODD_PARITY = (0x2ul << 0),
395# define VSF_USART_FORCE_0_PARITY VSF_USART_FORCE_0_PARITY
398
405 VSF_USART_1_STOPBIT = (0x0ul << 3),
406 VSF_USART_1_5_STOPBIT = (0x1ul << 3),
408 VSF_USART_0_5_STOPBIT = (0x2ul << 3),
409# define VSF_USART_0_5_STOPBIT VSF_USART_0_5_STOPBIT
410 VSF_USART_2_STOPBIT = (0x3ul << 3),
412
419 VSF_USART_8_BIT_LENGTH = (0x0ul << 5),
420 VSF_USART_5_BIT_LENGTH = (0x1ul << 5),
422 VSF_USART_6_BIT_LENGTH = (0x2ul << 5),
423# define VSF_USART_6_BIT_LENGTH VSF_USART_6_BIT_LENGTH
424 VSF_USART_7_BIT_LENGTH = (0x3ul << 5),
426 VSF_USART_9_BIT_LENGTH = (0x4ul << 5),
427# define VSF_USART_9_BIT_LENGTH VSF_USART_9_BIT_LENGTH
428 VSF_USART_10_BIT_LENGTH = (0x5ul << 5),
430
437 VSF_USART_NO_HWCONTROL = (0x0ul << 8),
438 VSF_USART_RTS_HWCONTROL = (0x1ul << 8),
440 VSF_USART_CTS_HWCONTROL = (0x2ul << 8),
441# define VSF_USART_CTS_HWCONTROL VSF_USART_CTS_HWCONTROL
444
451 VSF_USART_TX_ENABLE = (0x0ul << 9),
452 VSF_USART_RX_ENABLE = (0x0ul << 10),
453 VSF_USART_TX_DISABLE = (0x1ul << 9),
454# define VSF_USART_TX_DISABLE VSF_USART_TX_DISABLE
455 VSF_USART_RX_DISABLE = (0x1ul << 10),
457
465# define VSF_USART_SYNC_CLOCK_ENABLE VSF_USART_SYNC_CLOCK_ENABLE
467
477
487# define VSF_USART_TX_FIFO_THRESHOLD_EMPTY VSF_USART_TX_FIFO_THRESHOLD_EMPTY
491# define VSF_USART_TX_FIFO_THRESHOLD_NOT_FULL VSF_USART_TX_FIFO_THRESHOLD_NOT_FULL
492
504# define VSF_USART_RX_FIFO_THRESHOLD_HALF_FULL VSF_USART_RX_FIFO_THRESHOLD_HALF_FULL
507
520 VSF_USART_SWAP = (0x1ul << 16),
521# define VSF_USART_SWAP VSF_USART_SWAP
522 VSF_USART_TX_INVERT = (0x1ul << 17),
524 VSF_USART_RX_INVERT = (0x1ul << 18),
525# define VSF_USART_RX_INVERT VSF_USART_RX_INVERT
526#endif
528#endif
529
541enum {
542#ifndef VSF_USART_PARITY_MASK
548#endif
549
550#ifndef VSF_USART_STOPBIT_MASK
555#endif
556
557#ifndef VSF_USART_BIT_LENGTH_MASK
564#endif
565
566#ifndef VSF_USART_TX_FIFO_THRESHOLD_MASK
570#endif
571
572#ifndef VSF_USART_RX_FIFO_THRESHOLD_MASK
576#endif
577
578#ifndef VSF_USART_HWCONTROL_MASK
583#endif
584
587
590
593
596
607#ifdef VSF_USART_SYNC_CLOCK_LAST_BIT_MASK
609#endif
610
611#ifdef VSF_USART_IRDA_PRESCALER_MASK
612 | VSF_USART_IRDA_PRESCALER_MASK
613#endif
614#ifdef VSF_USART_IRDA_MASK
615 | VSF_USART_IRDA_MASK
616#endif
617
618#ifdef VSF_USART_SMARTCARD_MASK
619 | VSF_USART_SMARTCARD_MASK
620#endif
622
623#if VSF_USART_CFG_REIMPLEMENT_TYPE_IRQ_MASK == DISABLED
661 VSF_USART_IRQ_MASK_TX = (0x1ul << 2),
662 VSF_USART_IRQ_MASK_RX = (0x1ul << 3),
663
678
692 VSF_USART_IRQ_MASK_CTS = (0x1ul << 5),
693# define VSF_USART_IRQ_MASK_CTS VSF_USART_IRQ_MASK_CTS
694
733# define VSF_USART_IRQ_MASK_BREAK_ERR VSF_USART_IRQ_MASK_BREAK_ERR
734
750
765# define VSF_USART_IRQ_MASK_RX_OVERFLOW_ERR VSF_USART_IRQ_MASK_RX_OVERFLOW_ERR
766
779
797 VSF_USART_IRQ_MASK_TX_OVERFLOW_ERR = (0x1ul << 10),
798# define VSF_USART_IRQ_MASK_TX_OVERFLOW_ERR VSF_USART_IRQ_MASK_TX_OVERFLOW_ERR
799
808 VSF_USART_IRQ_MASK_NOISE_ERR = (0x1UL << 13),
810#endif
812#endif
813
820enum {
823
824#ifndef VSF_USART_IRQ_MASK_ERR
828# ifdef VSF_USART_IRQ_MASK_TX_OVERFLOW_ERR
829 | VSF_USART_IRQ_MASK_TX_OVERFLOW_ERR
830# endif
832# ifdef VSF_USART_IRQ_MASK_NOISE_ERR
834# endif
836#endif
837
838#ifndef VSF_USART_IRQ_ALL_BITS_MASK
842#ifdef VSF_USART_IRQ_MASK_RX_IDLE
844#endif
845#ifdef VSF_USART_IRQ_MASK_TX_IDLE
847#endif
852# ifdef VSF_USART_IRQ_MASK_TX_HALF_CPL
853 | VSF_USART_IRQ_MASK_TX_HALF_CPL
854# endif
855# ifdef VSF_USART_IRQ_MASK_RX_HALF_CPL
856 | VSF_USART_IRQ_MASK_RX_HALF_CPL
857# endif
858# ifdef VSF_USART_IRQ_MASK_CANCEL_TX_CPL
859 | VSF_USART_IRQ_MASK_CANCEL_TX_CPL
860# endif
861# ifdef VSF_USART_IRQ_MASK_CANCEL_RX_CPL
862 | VSF_USART_IRQ_MASK_CANCEL_RX_CPL
863# endif
864#endif
865};
866
867#if VSF_USART_CFG_REIMPLEMENT_TYPE_CFG == DISABLED
875
919typedef void vsf_usart_isr_handler_t(void *target_ptr,
920 vsf_usart_t *usart_ptr,
922
931typedef struct vsf_usart_isr_t {
936
945typedef struct vsf_usart_cfg_t {
949# ifdef VSF_USART_IRQ_MASK_RX_IDLE
951# endif
954#endif
955
956#if VSF_USART_CFG_REIMPLEMENT_TYPE_CTRL == DISABLED
980typedef enum vsf_usart_ctrl_t {
991
1001# define VSF_USART_CTRL_SET_BREAK VSF_USART_CTRL_SET_BREAK
1002
1013
1023 VSF_USART_CTRL_REQUEST_RX_RESUME = (0x1ul << 3),
1024# define VSF_USART_CTRL_REQUEST_RX_RESUME VSF_USART_CTRL_REQUEST_RX_RESUME
1025 VSF_USART_CTRL_REQUEST_TX_RESUME = (0x1ul << 4),
1026# define VSF_USART_CTRL_REQUEST_TX_RESUME VSF_USART_CTRL_REQUEST_TX_RESUME
1027
1028 VSF_USART_CTRL_REQUEST_RX_PAUSE = (0x1ul << 5),
1029# define VSF_USART_CTRL_REQUEST_RX_PAUSE VSF_USART_CTRL_REQUEST_RX_PAUSE
1030 VSF_USART_CTRL_REQUEST_TX_PAUSE = (0x1ul << 6),
1031# define VSF_USART_CTRL_REQUEST_TX_PAUSE VSF_USART_CTRL_REQUEST_TX_PAUSE
1032
1041 VSF_USART_CTRL_HALF_DUPLEX_ENABLE_TRANSMITTER = (0x1ul << 7),
1042# define VSF_USART_CTRL_HALF_DUPLEX_ENABLE_TRANSMITTER VSF_USART_CTRL_HALF_DUPLEX_ENABLE_TRANSMITTER
1043
1044 VSF_USART_CTRL_HALF_DUPLEX_ENABLE_RECEIVER = (0x1ul << 8),
1045# define VSF_USART_CTRL_HALF_DUPLEX_ENABLE_RECEIVER VSF_USART_CTRL_HALF_DUPLEX_ENABLE_RECEIVER
1046#endif
1048#endif
1049
1058#if VSF_USART_CFG_REIMPLEMENT_TYPE_STATUS == DISABLED
1059typedef struct vsf_usart_status_t {
1060 union {
1063 struct {
1071 };
1072 };
1074#endif
1075
1084#if VSF_USART_CFG_REIMPLEMENT_TYPE_CAPABILITY == DISABLED
1086#if VSF_USART_CFG_INHERIT_HAL_CAPABILITY == ENABLED
1088#endif
1090
1093
1096
1099
1104# ifdef VSF_USART_IRQ_MASK_TX_IDLE
1106# endif
1107# ifdef VSF_USART_IRQ_MASK_RX_IDLE
1109# endif
1111#endif
1120typedef struct vsf_usart_op_t {
1122#undef __VSF_HAL_TEMPLATE_API
1123#define __VSF_HAL_TEMPLATE_API VSF_HAL_TEMPLATE_API_FP
1125
1126 VSF_USART_APIS(vsf_usart)
1128
1129#if VSF_USART_CFG_MULTI_CLASS == ENABLED
1140};
1141#endif
1142
1143/*============================ PROTOTYPES ====================================*/
1144
1162extern vsf_err_t vsf_usart_init(vsf_usart_t *usart_ptr, vsf_usart_cfg_t *cfg_ptr);
1163
1175extern void vsf_usart_fini(vsf_usart_t *usart_ptr);
1176
1195
1207extern fsm_rt_t vsf_usart_enable(vsf_usart_t *usart_ptr);
1208
1220extern fsm_rt_t vsf_usart_disable(vsf_usart_t *usart_ptr);
1221
1238
1253
1280
1293
1306
1319
1335extern uint_fast32_t vsf_usart_rxfifo_read(vsf_usart_t *usart_ptr, void *buffer_ptr, uint_fast32_t count);
1336
1349
1365extern uint_fast32_t vsf_usart_txfifo_write(vsf_usart_t *usart_ptr, void *buffer_ptr, uint_fast32_t count);
1366
1384extern vsf_err_t vsf_usart_request_rx(vsf_usart_t *usart_ptr, void *buffer_ptr, uint_fast32_t count);
1385
1403extern vsf_err_t vsf_usart_request_tx(vsf_usart_t *usart_ptr, void *buffer_ptr, uint_fast32_t count);
1404
1416extern vsf_err_t vsf_usart_cancel_rx(vsf_usart_t *usart_ptr);
1417
1429extern vsf_err_t vsf_usart_cancel_tx(vsf_usart_t *usart_ptr);
1430
1447
1464
1482extern vsf_err_t vsf_usart_ctrl(vsf_usart_t *usart_ptr, vsf_usart_ctrl_t ctrl, void *param);
1483
1484/*============================ INLINE FUNCTIONS ==============================*/
1485
1486#if VSF_USART_CFG_REIMPLEMENT_MODE_TO_DATA_BITS == DISABLED
1497static inline uint8_t vsf_usart_mode_to_data_bits(vsf_usart_mode_t mode)
1498{
1499 switch (mode & VSF_USART_BIT_LENGTH_MASK) {
1501 return 5;
1503 return 6;
1505 return 7;
1507 return 8;
1509 return 9;
1511 return 10;
1512 default:
1513 return 0;
1514 }
1515}
1516#endif
1517
1530static inline vsf_err_t vsf_usart_send_break(vsf_usart_t *usart_ptr)
1531{
1534
1535 return vsf_usart_ctrl(usart_ptr, VSF_USART_CTRL_SEND_BREAK, NULL);
1536}
1537
1549static inline vsf_err_t vsf_usart_set_break(vsf_usart_t *usart_ptr)
1550{
1553
1554 return vsf_usart_ctrl(usart_ptr, VSF_USART_CTRL_SET_BREAK, NULL);
1555}
1556
1568static inline vsf_err_t vsf_usart_clear_break(vsf_usart_t *usart_ptr)
1569{
1572
1574}
1575
1576/*============================ MACROFIED FUNCTIONS ===========================*/
1577
1579#if VSF_USART_CFG_FUNCTION_RENAME == ENABLED
1580# define __vsf_usart_t VSF_MCONNECT(VSF_USART_CFG_PREFIX, _usart_t)
1581# define vsf_usart_init(__USART, ...) VSF_MCONNECT(VSF_USART_CFG_PREFIX, _usart_init) ((__vsf_usart_t *)(__USART), ##__VA_ARGS__)
1582# define vsf_usart_fini(__USART) VSF_MCONNECT(VSF_USART_CFG_PREFIX, _usart_fini) ((__vsf_usart_t *)(__USART))
1583# define vsf_usart_get_configuration(__USART, ...) VSF_MCONNECT(VSF_USART_CFG_PREFIX, _usart_get_configuration) ((__vsf_usart_t *)(__USART), ##__VA_ARGS__)
1584# define vsf_usart_capability(__USART) VSF_MCONNECT(VSF_USART_CFG_PREFIX, _usart_capability) ((__vsf_usart_t *)(__USART))
1585# define vsf_usart_enable(__USART) VSF_MCONNECT(VSF_USART_CFG_PREFIX, _usart_enable) ((__vsf_usart_t *)(__USART))
1586# define vsf_usart_disable(__USART) VSF_MCONNECT(VSF_USART_CFG_PREFIX, _usart_disable) ((__vsf_usart_t *)(__USART))
1587# define vsf_usart_irq_enable(__USART, ...) VSF_MCONNECT(VSF_USART_CFG_PREFIX, _usart_irq_enable) ((__vsf_usart_t *)(__USART), ##__VA_ARGS__)
1588# define vsf_usart_irq_disable(__USART, ...) VSF_MCONNECT(VSF_USART_CFG_PREFIX, _usart_irq_disable) ((__vsf_usart_t *)(__USART), ##__VA_ARGS__)
1589# define vsf_usart_irq_clear(__USART, ...) VSF_MCONNECT(VSF_USART_CFG_PREFIX, _usart_irq_clear) ((__vsf_usart_t *)(__USART), ##__VA_ARGS__)
1590# define vsf_usart_status(__USART) VSF_MCONNECT(VSF_USART_CFG_PREFIX, _usart_status) ((__vsf_usart_t *)(__USART))
1591# 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__)
1592# define vsf_usart_rxfifo_read(__USART, ...) VSF_MCONNECT(VSF_USART_CFG_PREFIX, _usart_rxfifo_read) ((__vsf_usart_t *)(__USART), ##__VA_ARGS__)
1593# 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__)
1594# define vsf_usart_txfifo_write(__USART, ...) VSF_MCONNECT(VSF_USART_CFG_PREFIX, _usart_txfifo_write) ((__vsf_usart_t *)(__USART), ##__VA_ARGS__)
1595# define vsf_usart_request_rx(__USART, ...) VSF_MCONNECT(VSF_USART_CFG_PREFIX, _usart_request_rx) ((__vsf_usart_t *)(__USART), ##__VA_ARGS__)
1596# define vsf_usart_request_tx(__USART, ...) VSF_MCONNECT(VSF_USART_CFG_PREFIX, _usart_request_tx) ((__vsf_usart_t *)(__USART), ##__VA_ARGS__)
1597# define vsf_usart_cancel_rx(__USART) VSF_MCONNECT(VSF_USART_CFG_PREFIX, _usart_cancel_rx) ((__vsf_usart_t *)(__USART))
1598# define vsf_usart_cancel_tx(__USART) VSF_MCONNECT(VSF_USART_CFG_PREFIX, _usart_cancel_tx) ((__vsf_usart_t *)(__USART))
1599# define vsf_usart_get_rx_count(__USART) VSF_MCONNECT(VSF_USART_CFG_PREFIX, _usart_get_rx_count) ((__vsf_usart_t *)(__USART))
1600# define vsf_usart_get_tx_count(__USART) VSF_MCONNECT(VSF_USART_CFG_PREFIX, _usart_get_tx_count) ((__vsf_usart_t *)(__USART))
1601# define vsf_usart_send_break(__USART) VSF_MCONNECT(VSF_USART_CFG_PREFIX, _usart_send_break) ((__vsf_usart_t *)(__USART))
1602# define vsf_usart_set_break(__USART) VSF_MCONNECT(VSF_USART_CFG_PREFIX, _usart_set_break) ((__vsf_usart_t *)(__USART))
1603# define vsf_usart_clear_break(__USART) VSF_MCONNECT(VSF_USART_CFG_PREFIX, _usart_clear_break) ((__vsf_usart_t *)(__USART))
1604# define vsf_usart_ctrl(__USART, ...) VSF_MCONNECT(VSF_USART_CFG_PREFIX, _usart_ctrl) ((__vsf_usart_t *)(__USART), ##__VA_ARGS__)
1605#endif
1607
1608/*============================ INCLUDES ======================================*/
1609
1610#ifdef __cplusplus
1611}
1612#endif
1613
1614#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_SWAP
Definition usart.h:145
#define VSF_USART_SYNC_CLOCK_LAST_BIT_MASK
Definition usart.h:139
vsf_usart_ctrl_t
Definition usart.h:261
#define VSF_USART_IRQ_MASK_TX_IDLE
Definition usart.h:223
@ VSF_USART_TX_INVERT
Definition usart.h:144
@ VSF_USART_RX_INVERT
Definition usart.h:145
#define VSF_USART_IRQ_MASK_NOISE_ERR
Definition usart.h:276
vsf_arch_prio_t
Definition cortex_a_generic.h:88
#define NULL
Definition lvgl.h:26
const i_spi_t vsf_spi_irq_mask_t irq_mask
Definition spi_interface.h:38
unsigned uint32_t
Definition stdint.h:9
unsigned int uint_fast32_t
Definition stdint.h:27
int int_fast32_t
Definition stdint.h:26
unsigned char uint8_t
Definition stdint.h:5
Definition vsf_template_hal_driver.h:204
Definition vsf_template_hal_driver.h:197
USART capability structure Defines the hardware capabilities and limitations of the USART interface.
Definition vsf_template_usart.h:1085
uint8_t support_tx_idle
Definition usart.h:403
uint8_t max_data_bits
Maximum data bits per frame.
Definition vsf_template_usart.h:1097
uint8_t support_set_and_clear_break
Support set and clear break.
Definition vsf_template_usart.h:1102
inherit(vsf_peripheral_capability_t) vsf_usart_irq_mask_t irq_mask
Supported interrupt mask bits.
vsf_usart_irq_mask_t irq_mask
Definition usart.h:387
uint8_t support_rx_timeout
Support receive timeout.
Definition vsf_template_usart.h:1100
uint8_t rxfifo_depth
RX FIFO depth in data frames (0 means no FIFO)
Definition vsf_template_usart.h:1095
uint8_t support_rx_idle
Support RX idle interrupt.
Definition vsf_template_usart.h:1108
uint8_t support_send_break
Support send break.
Definition vsf_template_usart.h:1101
uint8_t txfifo_depth
TX FIFO depth in data frames (0 means no FIFO)
Definition vsf_template_usart.h:1094
uint8_t min_data_bits
Minimum data bits per frame.
Definition vsf_template_usart.h:1098
uint32_t min_baudrate
Minimum supported baudrate (bps) according to current clock configurations.
Definition vsf_template_usart.h:1092
uint32_t max_baudrate
Maximum supported baudrate (bps) according to current clock configurations.
Definition vsf_template_usart.h:1091
uint8_t support_sync_clock
Support Synchronous clock.
Definition vsf_template_usart.h:1103
USART configuration structure Contains all parameters needed to initialize and configure a USART inst...
Definition vsf_template_usart.h:945
vsf_usart_mode_t mode
USART working mode.
Definition vsf_template_usart.h:946
uint32_t baudrate
Baudrate in Hz.
Definition vsf_template_usart.h:947
uint32_t rx_timeout
RX timeout in microseconds.
Definition vsf_template_usart.h:948
uint32_t rx_idle_cnt
Definition vsf_template_usart.h:950
vsf_usart_isr_t isr
Interrupt configuration.
Definition vsf_template_usart.h:952
USART interrupt configuration structure Contains all necessary information for configuring USART inte...
Definition vsf_template_usart.h:931
vsf_usart_isr_handler_t * handler_fn
Interrupt handler function pointer.
Definition vsf_template_usart.h:932
vsf_arch_prio_t prio
Interrupt priority.
Definition vsf_template_usart.h:934
void * target_ptr
User target pointer.
Definition vsf_template_usart.h:933
USART operation interface structure Contains function pointers for all USART operations.
Definition vsf_template_usart.h:1120
USART status information structure Contains the current status of USART operations and FIFO threshold...
Definition uart.h:157
uint32_t __reserved
Reserved.
Definition vsf_template_usart.h:1068
uint32_t is_busy
USART is busy with any operation.
Definition vsf_template_usart.h:1064
uint32_t is_tx_busy
TX is busy transmitting data.
Definition vsf_template_usart.h:1065
uint32_t value
Definition usart.h:284
uint32_t break_sent
BREAK signal sent.
Definition vsf_template_usart.h:1067
uint32_t tx_fifo_level
TX FIFO current data level (0-255)
Definition vsf_template_usart.h:1069
uint32_t is_rx_busy
RX is busy receiving data.
Definition vsf_template_usart.h:1066
uint32_t rx_fifo_level
RX FIFO current data level (0-255)
Definition vsf_template_usart.h:1070
USART instance structure Used for USART Multi Class support.
Definition vsf_template_usart.h:1138
const vsf_usart_op_t * op
Operation functions.
Definition vsf_template_usart.h:1139
vsf_usart_mode_t
Definition usart.h:116
vsf_usart_irq_mask_t
Definition usart.h:169
void vsf_usart_isr_handler_t(void *target_ptr, vsf_usart_t *usart_ptr, vsf_usart_irq_mask_t irq_mask)
Definition usart.h:255
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_7_BIT_LENGTH
Definition vsf_template_usart.h:425
#define VSF_USART_IRQ_MASK_RX_TIMEOUT
Definition vsf_template_usart.h:677
fsm_rt_t vsf_usart_disable(vsf_usart_t *usart_ptr)
Disable a USART instance.
Definition usart_common.c:75
vsf_usart_status_t vsf_usart_status(vsf_usart_t *usart_ptr)
Get the status of USART instance.
Definition usart_common.c:111
struct vsf_usart_cfg_t vsf_usart_cfg_t
USART configuration structure Contains all parameters needed to initialize and configure a USART inst...
vsf_err_t vsf_usart_request_rx(vsf_usart_t *usart_ptr, void *buffer_ptr, uint_fast32_t count)
Request a DMA receive operation through the USART.
Definition usart_common.c:165
#define VSF_USART_CTS_HWCONTROL
Definition vsf_template_usart.h:441
struct vsf_usart_capability_t vsf_usart_capability_t
USART capability structure Defines the hardware capabilities and limitations of the USART interface.
vsf_err_t vsf_usart_cancel_rx(vsf_usart_t *usart_ptr)
Cancel an ongoing USART receive operation.
Definition usart_common.c:183
#define VSF_USART_HALF_DUPLEX_ENABLE
Definition vsf_template_usart.h:476
vsf_usart_mode_t
Predefined VSF USART modes that can be reimplemented in specific HAL drivers. Even if the hardware do...
Definition vsf_template_usart.h:384
@ VSF_USART_HALF_DUPLEX_DISABLE
USART Half-duplex configuration options.
Definition vsf_template_usart.h:474
@ VSF_USART_8_BIT_LENGTH
USART Data bit length configuration options.
Definition vsf_template_usart.h:419
@ VSF_USART_EVEN_PARITY
Even parity.
Definition vsf_template_usart.h:392
@ VSF_USART_ODD_PARITY
Odd parity.
Definition vsf_template_usart.h:393
@ VSF_USART_NO_PARITY
USART Parity configuration options.
Definition vsf_template_usart.h:391
@ VSF_USART_RX_ENABLE
RX enabled.
Definition vsf_template_usart.h:452
@ VSF_USART_TX_ENABLE
USART TX/RX enable/disable options.
Definition vsf_template_usart.h:451
@ VSF_USART_1_STOPBIT
USART Stop bit configuration options.
Definition vsf_template_usart.h:405
@ VSF_USART_SYNC_CLOCK_DISABLE
Sync clock disabled.
Definition vsf_template_usart.h:466
@ VSF_USART_NO_HWCONTROL
USART Hardware flow control configuration options.
Definition vsf_template_usart.h:437
#define VSF_USART_IRQ_MASK_FRAME_ERR
Definition vsf_template_usart.h:731
#define VSF_USART_IRQ_MASK_CTS
Definition vsf_template_usart.h:693
#define VSF_USART_5_BIT_LENGTH
Definition vsf_template_usart.h:421
uint_fast32_t vsf_usart_rxfifo_get_data_count(vsf_usart_t *usart_ptr)
Get the number of data currently received in the USART receive FIFO.
Definition usart_common.c:129
#define VSF_USART_9_BIT_LENGTH
Definition vsf_template_usart.h:427
uint_fast32_t vsf_usart_rxfifo_read(vsf_usart_t *usart_ptr, void *buffer_ptr, uint_fast32_t count)
Try to read the maximum length of data from the USART receive FIFO.
Definition usart_common.c:138
#define VSF_USART_CTRL_SET_BREAK
Definition vsf_template_usart.h:1001
#define VSF_USART_1_5_STOPBIT
Definition vsf_template_usart.h:407
#define VSF_USART_FORCE_1_PARITY
Definition vsf_template_usart.h:397
#define VSF_USART_CTRL_SEND_BREAK
Definition vsf_template_usart.h:990
fsm_rt_t vsf_usart_enable(vsf_usart_t *usart_ptr)
Enable a USART instance.
Definition usart_common.c:66
#define VSF_USART_RX_FIFO_THRESHOLD_HALF_FULL
Definition vsf_template_usart.h:504
#define VSF_USART_TX_FIFO_THRESHOLD_EMPTY
Definition vsf_template_usart.h:487
#define VSF_USART_TX_DISABLE
Definition vsf_template_usart.h:454
@ VSF_USART_BIT_LENGTH_MASK
Definition vsf_template_usart.h:558
@ VSF_USART_TX_FIFO_THRESHOLD_MASK
Definition vsf_template_usart.h:567
@ VSF_USART_PARITY_MASK
Definition vsf_template_usart.h:543
@ VSF_USART_MODE_ALL_BITS_MASK
Definition vsf_template_usart.h:597
@ VSF_USART_HALF_DUPLEX_MASK
Definition vsf_template_usart.h:594
@ VSF_USART_HWCONTROL_MASK
Definition vsf_template_usart.h:579
@ VSF_USART_RX_MASK
Definition vsf_template_usart.h:588
@ VSF_USART_STOPBIT_MASK
Definition vsf_template_usart.h:551
@ VSF_USART_RX_FIFO_THRESHOLD_MASK
Definition vsf_template_usart.h:573
@ VSF_USART_SYNC_CLOCK_MASK
Definition vsf_template_usart.h:591
@ VSF_USART_TX_MASK
Definition vsf_template_usart.h:585
struct vsf_usart_isr_t vsf_usart_isr_t
USART interrupt configuration structure Contains all necessary information for configuring USART inte...
#define VSF_USART_RX_FIFO_THRESHOLD_FULL
Definition vsf_template_usart.h:506
vsf_usart_irq_mask_t vsf_usart_irq_clear(vsf_usart_t *usart_ptr, vsf_usart_irq_mask_t irq_mask)
Clear interrupt flags of USART instance and return previous state.
Definition usart_common.c:102
#define VSF_USART_10_BIT_LENGTH
Definition vsf_template_usart.h:429
vsf_err_t vsf_usart_request_tx(vsf_usart_t *usart_ptr, void *buffer_ptr, uint_fast32_t count)
Request a DMA transmit operation through the USART.
Definition usart_common.c:174
#define VSF_USART_RTS_CTS_HWCONTROL
Definition vsf_template_usart.h:443
uint_fast32_t vsf_usart_txfifo_get_free_count(vsf_usart_t *usart_ptr)
Get the maximum number of data that can be sent through the USART send FIFO.
Definition usart_common.c:147
#define VSF_USART_IRQ_MASK_RX_OVERFLOW_ERR
Definition vsf_template_usart.h:765
vsf_err_t vsf_usart_cancel_tx(vsf_usart_t *usart_ptr)
Cancel an ongoing USART transmit operation.
Definition usart_common.c:192
vsf_usart_irq_mask_t
USART interrupt mask definitions These interrupts provide status and event notifications for USART op...
Definition vsf_template_usart.h:658
@ VSF_USART_IRQ_MASK_TX_CPL
TX complete(for request_tx API, data is written to TX FIFO) interrupt.
Definition vsf_template_usart.h:659
@ VSF_USART_IRQ_MASK_TX
TX FIFO threshold interrupt.
Definition vsf_template_usart.h:661
@ VSF_USART_IRQ_MASK_RX
RX FIFO threshold interrupt.
Definition vsf_template_usart.h:662
@ VSF_USART_IRQ_MASK_RX_CPL
RX complete(for request_rx API, data is read from RX FIFO) interrupt.
Definition vsf_template_usart.h:660
void vsf_usart_fini(vsf_usart_t *usart_ptr)
Finalize a USART instance.
Definition usart_common.c:47
#define VSF_USART_RTS_HWCONTROL
Definition vsf_template_usart.h:439
#define VSF_USART_APIS(__prefix_name)
USART API template, used to generate USART type, specific prefix function declarations,...
Definition vsf_template_usart.h:261
void vsf_usart_irq_enable(vsf_usart_t *usart_ptr, vsf_usart_irq_mask_t irq_mask)
Enable interrupt masks of USART instance.
Definition usart_common.c:84
void vsf_usart_irq_disable(vsf_usart_t *usart_ptr, vsf_usart_irq_mask_t irq_mask)
Disable interrupt masks of USART instance.
Definition usart_common.c:93
@ VSF_USART_IRQ_MASK_ERR
Combined error interrupt mask.
Definition vsf_template_usart.h:825
@ VSF_USART_IRQ_MASK_TX_FIFO_THRESHOLD
TX FIFO threshold interrupt mask.
Definition vsf_template_usart.h:821
@ VSF_USART_IRQ_ALL_BITS_MASK
All supported interrupt mask bits.
Definition vsf_template_usart.h:839
@ VSF_USART_IRQ_MASK_RX_FIFO_THRESHOLD
RX FIFO threshold interrupt mask.
Definition vsf_template_usart.h:822
#define VSF_USART_IRQ_MASK_BREAK_ERR
Definition vsf_template_usart.h:733
#define VSF_USART_FORCE_0_PARITY
Definition vsf_template_usart.h:395
struct vsf_usart_status_t vsf_usart_status_t
USART status information structure Contains the current status of USART operations and FIFO threshold...
#define VSF_USART_RX_FIFO_THRESHOLD_NOT_EMPTY
Definition vsf_template_usart.h:502
int_fast32_t vsf_usart_get_rx_count(vsf_usart_t *usart_ptr)
Get the number of bytes received in the current or last USART operation.
Definition usart_common.c:201
#define VSF_USART_0_5_STOPBIT
Definition vsf_template_usart.h:409
vsf_err_t vsf_usart_init(vsf_usart_t *usart_ptr, vsf_usart_cfg_t *cfg_ptr)
Initialize a USART instance.
Definition usart_common.c:38
#define VSF_USART_SYNC_CLOCK_ENABLE
Definition vsf_template_usart.h:465
#define VSF_USART_IRQ_MASK_PARITY_ERR
Definition vsf_template_usart.h:749
#define VSF_USART_2_STOPBIT
Definition vsf_template_usart.h:411
vsf_usart_capability_t vsf_usart_capability(vsf_usart_t *usart_ptr)
Get the capability of USART instance.
Definition usart_common.c:120
vsf_usart_ctrl_t
USART control commands Defines the available control operations for USART instances.
Definition vsf_template_usart.h:980
vsf_err_t vsf_usart_ctrl(vsf_usart_t *usart_ptr, vsf_usart_ctrl_t ctrl, void *param)
Execute a control command on the USART instance.
Definition usart_common.c:219
vsf_err_t vsf_usart_get_configuration(vsf_usart_t *usart_ptr, vsf_usart_cfg_t *cfg_ptr)
Get current configuration of a USART instance.
Definition usart_common.c:56
#define VSF_USART_CTRL_CLEAR_BREAK
Definition vsf_template_usart.h:1012
#define VSF_USART_RX_DISABLE
Definition vsf_template_usart.h:456
#define VSF_USART_IRQ_MASK_RX_IDLE
Definition vsf_template_usart.h:778
int_fast32_t vsf_usart_get_tx_count(vsf_usart_t *usart_ptr)
Get the number of bytes transmitted in the current or last USART operation.
Definition usart_common.c:210
#define VSF_USART_TX_FIFO_THRESHOLD_HALF_EMPTY
Definition vsf_template_usart.h:489
void vsf_usart_isr_handler_t(void *target_ptr, vsf_usart_t *usart_ptr, vsf_usart_irq_mask_t irq_mask)
USART interrupt handler function type declaration.
Definition vsf_template_usart.h:919
#define VSF_USART_TX_FIFO_THRESHOLD_NOT_FULL
Definition vsf_template_usart.h:491
uint_fast32_t vsf_usart_txfifo_write(vsf_usart_t *usart_ptr, void *buffer_ptr, uint_fast32_t count)
Try to write the maximum length of data to the USART send FIFO.
Definition usart_common.c:156
#define __VSF_USART_CFG_SUPPORT_STANDARD_OPTIONAL
Enable standard optional features support.
Definition vsf_template_usart.h:248
#define VSF_USART_6_BIT_LENGTH
Definition vsf_template_usart.h:423
Generated from commit: vsfteam/vsf@b2e9e8a