1 /*
2 * Copyright (c) 2022 FuZhou Lockzhiner Electronic 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 #include <stdio.h>
16 #include <stdint.h>
17 #include <stdarg.h>
18
19 #include "los_sem.h"
20
21 #include "lz_hardware.h"
22
23 /* uart debug */
24 #define UART_DEBUG_ID 1
25 /* uart baud rate */
26 #define UART_BAUD_RATE_DEFAULT 115200
27
28 static bool m_uart_debug_initialized = false;
29
uart_debug_init(void)30 void uart_debug_init(void)
31 {
32 unsigned int ret;
33 UartAttribute attr;
34
35 LzUartDeinit(UART_DEBUG_ID);
36
37 attr.baudRate = UART_BAUD_RATE_DEFAULT;
38 attr.dataBits = UART_DATA_BIT_8;
39 attr.pad = FLOW_CTRL_NONE;
40 attr.parity = UART_PARITY_NONE;
41 attr.rxBlock = UART_BLOCK_STATE_NONE_BLOCK;
42 attr.stopBits = UART_STOP_BIT_1;
43 attr.txBlock = UART_BLOCK_STATE_NONE_BLOCK;
44
45 if (UART_DEBUG_ID == 0) {
46 /* GPIO0_PB6 => UART1_RX */
47 PinctrlSet(GPIO0_PB6, MUX_FUNC3, PULL_KEEP, DRIVE_LEVEL3);
48 /* GPIO0_PB7 => UART1_TX */
49 PinctrlSet(GPIO0_PB7, MUX_FUNC3, PULL_KEEP, DRIVE_LEVEL3);
50 } else if (UART_DEBUG_ID == 1) {
51 /* GPIO0_PA6 => UART1_RX */
52 PinctrlSet(GPIO0_PA6, MUX_FUNC3, PULL_KEEP, DRIVE_LEVEL3);
53 /* GPIO0_PA7 => UART1_TX */
54 PinctrlSet(GPIO0_PA7, MUX_FUNC3, PULL_KEEP, DRIVE_LEVEL3);
55 }
56
57 ret = LzUartInit(UART_DEBUG_ID, &attr);
58 if (ret != LZ_HARDWARE_SUCCESS) {
59 printf("%s, %d: LzUartInit(%u) failed!\n", __FILE__, __LINE__, ret);
60 }
61
62 #if (LOSCFG_USE_SHELL == 1)
63 (void)LOS_EventWrite(&g_shellInputEvent, 0x1);
64 #endif
65
66 m_uart_debug_initialized = true;
67 }
68
uart_debug_getc(void)69 uint8_t uart_debug_getc(void)
70 {
71 uint8_t ch = 0;
72 LzUartRead(UART_DEBUG_ID, &ch, 1);
73 return ch;
74 }
75
uart_debug_putc(char character)76 void uart_debug_putc(char character)
77 {
78 DebugWrite(UART_DEBUG_ID, &character, 1);
79 }
80
_putchar(char charactor)81 void _putchar(char charactor)
82 {
83 uart_debug_putc(charactor);
84 }
85
86