• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 ASR Microelectronics (Shanghai) Co., Ltd. All rights reserved.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifdef _UART_LITE_EN_
17 #include "uart_lite.h"
18 #else
19 #include <stdbool.h>
20 #include "duet_cm4.h"
21 #include "duet_uart.h"
22 #include "duet_pinmux.h"
23 #include "printf_uart.h"
24 
25 uint8_t g_printf_uart = UART_NUM;
printf_uart_register(uint8_t uart_idx)26 void printf_uart_register(uint8_t uart_idx)
27 {
28 #if 0
29     uint32_t uart_clk_reg = *(volatile uint32_t *)(UART_CLK_REG_ADDR);
30 
31     if (uart_idx == UART0_INDEX) {
32         if ((uart_clk_reg & UART0_SCLK_EN) == 0) {
33             goto ERR;
34         }
35     } else if (uart_idx == UART1_INDEX) {
36         if ((uart_clk_reg & UART1_SCLK_EN) == 0) {
37             goto ERR;
38         }
39     } else if (uart_idx == UART2_INDEX) {
40         if ((uart_clk_reg & UART2_SCLK_EN) == 0) {
41             goto ERR;
42         }
43     } else {
44         g_printf_uart = uart_idx;
45         return;
46     }
47 #endif
48     g_printf_uart = uart_idx;
49     // printf("printf use uart %d\n",uart_idx);
50     return;
51 #if 0
52 ERR:
53     g_printf_uart = UART_NUM;
54 #endif
55 }
56 #endif
57 extern bool lega_log_is_enable(void);
uart_put_char(char character)58 void uart_put_char(char character)
59 {
60 #ifndef _UART_LITE_EN_
61     if (lega_log_is_enable()) {
62         UART_SendData(getUartxViaIdx(g_printf_uart), (unsigned char)character);
63     }
64 #else
65     UART_SendData(UART_INDEX, (unsigned char)(character));
66 #endif
67 }
68 
printf_uart_log_init(uint8_t uart_idx)69 void printf_uart_log_init(uint8_t uart_idx)
70 {
71     duet_uart_dev_t uart_config_struct  = {0};
72     uart_config_struct.port = uart_idx;
73     switch (uart_idx) {
74         case UART0_INDEX:
75             duet_pinmux_config(PAD0, PF_UART0);
76             duet_pinmux_config(PAD1, PF_UART0);
77             break;
78         case UART1_INDEX:
79             duet_pinmux_config(PAD2, PF_UART1);
80             duet_pinmux_config(PAD3, PF_UART1);
81             break;
82         case UART2_INDEX:
83             duet_pinmux_config(PAD12, PF_UART2);
84             duet_pinmux_config(PAD13, PF_UART2);
85             break;
86         default:
87             break;
88     }
89 
90     duet_uart_struct_init(&uart_config_struct);
91     duet_uart_init(&uart_config_struct);
92     //    duet_uart_start(getUartxViaIdx(uart_idx));
93     printf_uart_register(uart_idx);
94     printf("set uart%d as printf log uart...\n", uart_idx);
95 }
96 #ifdef PRINTF2_SUPPORT
97 uint8_t g_printf2_uart = UART_NUM;
printf2_uart_register(uint8_t uart_idx)98 void printf2_uart_register(uint8_t uart_idx)
99 {
100     g_printf2_uart = uart_idx;
101 }
uart_put_char_2(char character)102 void uart_put_char_2(char character)
103 {
104     UART_SendData(getUartxViaIdx(g_printf2_uart), (unsigned char)character);
105 }
106 #endif