• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
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  * Description:  Basic DEBUG print
15  * Author:
16  * Create:  2020-11-6
17  */
18 #ifndef LIB_COMMON_HEADERS_DEBUG_PRINT_H
19 #define LIB_COMMON_HEADERS_DEBUG_PRINT_H
20 
21 #include "core.h"
22 #if defined(SW_RTT_DEBUG)
23 #include "SEGGER_RTT.h"
24 #endif
25 #if defined(MULTIPLEXING_UART) && defined(TEST_SUITE)
26 #include "test_suite_log.h"
27 #endif
28 
29 #ifndef NEWLINE
30 #define NEWLINE "\r\n"
31 #endif
32 #define PRINT_BT(fmt, arg...)
33 #define uapi_at_printf(fmt, arg...)
34 #if defined(SW_UART_DEBUG) || defined(FACTORY_TEST)
35 void sw_debug_uart_init(uint32_t baud_rate);
36 void sw_debug_uart_deinit(void);
37 void print_str(const char *str, ...);
38 void print_exc(const char *str, ...);
39 
40 #define print_init()
41 #if defined(BUILD_APPLICATION_ROM)
42 #if CORE == MASTER_BY_ALL
43     #define PRINT(fmt, arg...) print_str("ROM|" fmt, ##arg)
44 #elif CORE == SECURITY
45     #define PRINT(fmt, arg...) print_str("SEC ROM|" fmt, ##arg)
46 #endif
47 
48 #elif defined(BUILD_APPLICATION_SSB)
49 #if CORE == MASTER_BY_ALL
50     #define PRINT(fmt, arg...) print_str("SSB|" fmt, ##arg)
51 #elif CORE == SECURITY
52     #define PRINT(fmt, arg...) print_str("SEC SSB|" fmt, ##arg)
53 #endif
54 
55 #elif defined(MULTIPLEXING_UART) && defined(TEST_SUITE)
56     #define PRINT(fmt, arg...) test_suite_uart_sendf("TESTSUITE|" fmt, ##arg)
57 #elif defined(BUILD_APPLICATION_STANDARD) || defined(TEST_SUITE) || defined(UNIT_TEST)
58 #if CORE == BT
59     #define PRINT(fmt, arg...) print_str("BT|" fmt, ##arg)
60 #elif CORE == APPS
61     #define PRINT(fmt, arg...) print_str("APP|" fmt, ##arg)
62 #elif CORE == SECURITY
63     #define PRINT(fmt, arg...) print_str("SEC|" fmt, ##arg)
64 #elif CORE == GNSS
65     #define PRINT(fmt, arg...) print_str("GNSS|" fmt, ##arg)
66 #elif CORE == CONTROL_CORE
67     void test_suite_uart_sendf(const char *str, ...);
68     #define PRINT(fmt, arg...) test_suite_uart_sendf(fmt, ##arg)
69 #else
70     #define PRINT(fmt, arg...)
71 #endif
72 
73 #elif CORE == WIFI
74     #define PRINT(fmt, arg...)  print_str("WIFI|" fmt, ##arg)
75 #elif CORE == CONTROL_CORE
76     #define PRINT(fmt, arg...)  print_str("CCORE|" fmt, ##arg)
77 #else
78     #define PRINT(fmt, arg...)
79 #endif
80 
81 #elif BOOT_ROM_DFR_PRINT == YES
82 void sw_debug_uart_init(uint32_t baud_rate);
83 void print_str(const char *str, ...);
84 #define PRINT(fmt, arg...) print_str("ROM|" fmt, ##arg)
85 
86 #elif defined(SW_RTT_DEBUG)
87 #define LOG_PROTO(type, color, format, ...)            \
88         SEGGER_RTT_printf(0, "  %s%s"format"%s",   \
89                           color,                       \
90                           type,                        \
91                           ##__VA_ARGS__,               \
92                           RTT_CTRL_RESET)
93 
94 #define print_init() SEGGER_RTT_Init()
95 #define PRINT(fmt, arg...) LOG_PROTO("", "", fmt, ##arg)
96 
97 #elif defined(TEST_SUITE)
98 void test_suite_uart_sendf(const char *str, ...);
99 #define print_init()
100 #define PRINT(fmt, arg...)  test_suite_uart_sendf(fmt, ##arg)
101 
102 #else
103 #define print_init()
104 #define PRINT(fmt, arg...)
105 
106 #endif
107 #endif
108