• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Talkweb Co., Ltd.
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 #include <stdarg.h>
17 #include "securec.h"
18 #include "los_debug.h"
19 #include "los_interrupt.h"
20 #include "uart.h"
21 
dputs(char const * s,int (* pFputc)(int n,FILE * cookie),void * cookie)22 static void dputs(char const *s, int (*pFputc)(int n, FILE *cookie), void *cookie)
23 {
24     unsigned int intSave;
25 
26     intSave = LOS_IntLock();
27     while (*s) {
28         pFputc(*s++, cookie);
29     }
30     LOS_IntRestore(intSave);
31 }
32 
hal_trace_printf(uint32_t attr,const char * fmt,...)33 int hal_trace_printf(uint32_t attr, const char *fmt, ...)
34 {
35     char buf[1024] = { 0 };
36     va_list ap;
37     va_start(ap, fmt);
38     int len = vsnprintf_s(buf, sizeof(buf), 1024 - 1, fmt, ap);
39     if (len > 0) {
40         dputs(buf, UartPutc, 0);
41     } else {
42         dputs("printf error!\n", UartPutc, 0);
43     }
44     va_end(ap);
45     return len;
46 }
47 
printf(char const * fmt,...)48 int printf(char const  *fmt, ...)
49 {
50     char buf[1024] = { 0 };
51     va_list ap;
52     va_start(ap, fmt);
53     int len = vsnprintf_s(buf, sizeof(buf), 1024 - 1, fmt, ap);
54     if (len > 0) {
55         dputs(buf, UartPutc, 0);
56     } else {
57         dputs("printf error!\n", UartPutc, 0);
58     }
59     va_end(ap);
60     return len;
61 }
62