• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2009-2022 Huawei Technologies Co., Ltd. All rights reserved.
3  *
4  * UniProton is licensed under Mulan PSL v2.
5  * You can use this software according to the terms and conditions of the Mulan PSL v2.
6  * You may obtain a copy of Mulan PSL v2 at:
7  *          http://license.coscl.org.cn/MulanPSL2
8  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
9  * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
10  * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
11  * See the Mulan PSL v2 for more details.
12  * Create: 2009-12-22
13  * Description: UniProton hi3093 demo
14  */
15 #ifndef __SERIAL_H__
16 #define __SERIAL_H__
17 
18 #include "uart_regs.h"
19 #include "prt_typedef.h"
20 
21 #define SERIAL_SEL_UART_PORT       4
22 
23 #define SERIAL_TIMEOUT_MS          10
24 #define SERIAL_NAME_SIZE           32
25 #define SERIAL_FLUSH_TMOUT         0x100000
26 
27 typedef struct _serial_cfg {
28     char name[SERIAL_NAME_SIZE];
29     S32 init_done;
30     S32 hw_uart_no;
31     U32 uart_src_clk;
32     U8 data_bits;
33     U8 stop;
34     U8 pen;
35     U8 eps;
36     S32 baud_rate;
37 } serial_cfg;
38 
39 typedef struct {
40     S32 (*init)(serial_cfg *cfg);
41     void (*setbrg)(serial_cfg *cfg);
42     S32 (*put_char)(S32 hw_uart_no, const char ch);
43     S32 (*get_char)(S32 hw_uart_no);
44     S32 (*tx_ready)(S32 hw_uart_no);
45     S32 (*rx_ready)(S32 hw_uart_no);
46     S32 (*wait4idle)(S32 hw_uart_no, U32 time_out);
47 } uart_ops;
48 
49 typedef struct _serial {
50     serial_cfg cfg;
51     uart_ops *hw_ops;
52 } serial_t;
53 
54 extern uart_ops g_uart_ops;
55 extern serial_cfg g_uart_cfg;
56 
57 extern void serial_soft_init(serial_cfg *cfg, uart_ops *hw_ops);
58 extern void serial_init(serial_cfg *cfg, uart_ops *hw_ops);
59 extern serial_t *serial_get(void);
60 extern void serial_putc(const char ch);
61 extern S32 serial_getc(void);
62 extern void serial_puts(const char *s);
63 extern S32 serial_tstc(void);
64 extern void serial_flush(void);
65 extern void printf_resource_init(void);
66 extern S32 uart_init(serial_cfg *cfg);
67 extern void uart_raw_puts(S32 uart_no, const S8 *str);
68 extern S32 uart_busy_poll(S32 hw_uart_no);
69 
70 #endif /* __SERIAL_H__ */