blob: 0fd59551f2a198c438979ed423e30c11389d476c (
plain)
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
|
/*
* Copyright (C) 2022-2024, Xiaohua Semiconductor Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2022-04-28 CDT first version
*/
#ifndef __DRV_USART_H__
#define __DRV_USART_H__
/*******************************************************************************
* Include files
******************************************************************************/
#include <rtthread.h>
#include "rtdevice.h"
#include "drv_irq.h"
#include "drv_dma.h"
/* C binding of definitions if building with C++ compiler */
#ifdef __cplusplus
extern "C" {
#endif
/*******************************************************************************
* Global type definitions ('typedef')
******************************************************************************/
struct hc32_uart_irq_config
{
struct hc32_irq_config irq_config;
func_ptr_t irq_callback;
};
/* HC32 config Rx timeout */
struct hc32_uart_rxto
{
CM_TMR0_TypeDef *TMR0_Instance;
rt_uint32_t channel;
rt_uint32_t clock;
rt_size_t timeout_bits;
#if defined(HC32F460) || defined(HC32F4A0) || defined(HC32F4A2) || defined(HC32F4A8) || defined(HC32F467)
struct hc32_irq_config irq_config;
func_ptr_t irq_callback;
#endif
};
/* HC32 config uart class */
struct hc32_uart_config
{
const char *name;
CM_USART_TypeDef *Instance;
rt_uint32_t clock;
#if defined(HC32F460) || defined(HC32F4A0) || defined(HC32F4A2) || defined(HC32F4A8) || defined(HC32F467)
struct hc32_uart_irq_config rxerr_irq;
struct hc32_uart_irq_config rx_irq;
struct hc32_uart_irq_config tx_irq;
#elif defined(HC32F448) || defined(HC32F472) || defined(HC32F334)
IRQn_Type irq_num;
en_int_src_t rxerr_int_src;
en_int_src_t tx_int_src;
en_int_src_t rx_int_src;
#ifdef RT_SERIAL_USING_DMA
en_int_src_t rxto_int_src;
#endif
#endif
#ifdef RT_SERIAL_USING_DMA
struct hc32_uart_rxto *rx_timeout;
stc_dma_llp_descriptor_t llp_desc[2U];
struct dma_config *dma_rx;
struct hc32_uart_irq_config *tc_irq;
struct dma_config *dma_tx;
#endif
};
/* HC32 uart driver class */
struct hc32_uart
{
struct hc32_uart_config *config;
#ifdef RT_SERIAL_USING_DMA
rt_size_t dma_rx_remaining_cnt;
#endif
rt_uint16_t uart_dma_flag;
struct rt_serial_device serial;
};
/*******************************************************************************
* Global pre-processor symbols/macros ('#define')
******************************************************************************/
/*******************************************************************************
* Global variable definitions ('extern')
******************************************************************************/
/*******************************************************************************
* Global function prototypes (definition in C source)
******************************************************************************/
int rt_hw_usart_init(void);
#ifdef __cplusplus
}
#endif
#endif /* __DRV_USART_H__ */
/*******************************************************************************
* EOF (not truncated)
******************************************************************************/
|