1 /*
2 * Copyright : (C) 2022 Phytium Information Technology, Inc.
3 * All Rights Reserved.
4 *
5 * This program is OPEN SOURCE software: you can redistribute it and/or modify it
6 * under the terms of the Phytium Public License as published by the Phytium Technology Co.,Ltd,
7 * either version 1.0 of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY;
10 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 * See the Phytium Public License for more details.
12 *
13 *
14 * FilePath: early_uart.c
15 * Date: 2022-02-11 13:33:28
16 * LastEditTime: 2022-02-17 17:59:26
17 * Description: This file is for
18 *
19 * Modify History:
20 * Ver Who Date Changes
21 * ----- ------ -------- --------------------------------------
22 * 1.0 rtos 2022/6/25 init commit
23 * 1.1 zhangyan 2023/7/11 modify
24 */
25
26 /***************************** Include Files *********************************/
27 #include "rtconfig.h"
28 #ifdef RT_USING_SMART
29 #include <ioremap.h>
30 #endif
31
32 #include "fkernel.h"
33 #include "fio.h"
34 #include "fparameters.h"
35 #include "fearly_uart.h"
36
37
38 #if defined(BSP_USING_UART_MSG)
39
40
41 #include "fuart_msg.h"
42 #include "fio_mux.h"
43
44 static FUartMsg early_uart;
45
FEarlyUartProbe(void)46 void FEarlyUartProbe(void)
47 {
48 FUartMsgConfig config;
49 config = *FUartMsgLookupConfig(EARLY_UART_CTRL_ID);
50
51 #ifdef RT_USING_SMART
52 config.msg.regfile = (uintptr)rt_ioremap((void *)config.msg.regfile, 0x1000);
53 config.msg.shmem = (uintptr)rt_ioremap((void *)config.msg.shmem, 0x1000);
54 #endif
55
56 FIOPadSetUartMux(EARLY_UART_CTRL_ID);
57
58 FUartMsgCfgInitialize(&early_uart, &config);
59 FUartMsgSetStartUp(&early_uart);
60 return;
61 }
62
OutByte(s8 byte)63 void OutByte(s8 byte)
64 {
65 while(-1 == FUartMsgTxChar(&(early_uart), byte));
66 }
67
GetByte(void)68 char GetByte(void)
69 {
70 return (char)(FUartMsgBlockReceive(&early_uart));
71 }
72
73 #else
74 #include "fpl011.h"
75
76 /**************************** Type Definitions *******************************/
77 static FPl011 early_uart;
78
FEarlyUartProbe(void)79 void FEarlyUartProbe(void)
80 {
81 FPl011Config config;
82 config = *FPl011LookupConfig(EARLY_UART_CTRL_ID);
83
84
85 #ifdef RT_USING_SMART
86 config.base_address = (uintptr)rt_ioremap((void *)config.base_address, 0x2000);
87 #endif
88 FPl011CfgInitialize(&early_uart, &config);
89 return;
90 }
91 /************************** Constant Definitions *****************************/
92
93 /************************** Variable Definitions *****************************/
94
95 /***************** Macros (Inline Functions) Definitions *********************/
96
97 /*****************************************************************************/
98
99
OutByte(s8 byte)100 void OutByte(s8 byte)
101 {
102 FPl011BlockSend(&early_uart, (u8 *)&byte, 1);
103 }
104
GetByte(void)105 char GetByte(void)
106 {
107 return (char)(FPl011BlockReceive(&early_uart));
108 }
109 #endif