• 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 raspi4 demo
14  */
15 #include <stdarg.h>
16 #include "prt_typedef.h"
17 #include "cpu_config.h"
18 #include "securec.h"
19 
20 typedef U32 (*PrintFunc)(const char *format, va_list vaList);
21 #define OS_MAX_SHOW_LEN 0x200
22 
uart_poll_send(unsigned char ch)23 void uart_poll_send(unsigned char ch)
24 {
25     volatile int time = 100000;
26     *(unsigned int *)UART_BASE_ADDR = ch;
27     while (time--);
28 }
29 
TestPutc(unsigned char ch)30 void TestPutc(unsigned char ch)
31 {
32     uart_poll_send(ch);
33     if (ch == '\n') {
34         uart_poll_send('\r');
35     }
36 }
37 
TestPrintf(const char * format,va_list vaList)38 int TestPrintf(const char *format, va_list vaList)
39 {
40     int len;
41     char buff[OS_MAX_SHOW_LEN] = {0};
42     char *str = buff;
43 
44     len = vsnprintf_s(buff, OS_MAX_SHOW_LEN, OS_MAX_SHOW_LEN, format, vaList);
45     if (len == -1) {
46         return len;
47     }
48 
49     while (*str != '\0') {
50         TestPutc(*str);
51         str++;
52     }
53 
54     return OS_OK;
55 }
56 
PRT_Printf(const char * format,...)57 U32 PRT_Printf(const char *format, ...)
58 {
59     va_list vaList;
60     S32 count;
61 
62     va_start(vaList, format);
63     count = TestPrintf(format, vaList);
64     va_end(vaList);
65 
66     return count;
67 }
68