Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / src / platform / cc13x2_26x2 / Logging.cpp
1 /* See Project CHIP LICENSE file for licensing information. */
2
3 #include <platform/logging/LogV.h>
4
5 #include <core/CHIPConfig.h>
6 #include <platform/CHIPDeviceConfig.h>
7
8 #if CHIP_DEVICE_CONFIG_ENABLE_THREAD
9 #include <openthread/platform/logging.h>
10 #endif
11
12 #include "ti_drivers_config.h"
13
14 #include <ti/drivers/UART.h>
15
16 #include <stdio.h>
17
18 UART_Handle sDebugUartHandle;
19 char sDebugUartBuffer[CHIP_CONFIG_LOG_MESSAGE_MAX_SIZE];
20
21 extern "C" int cc13x2_26x2LogInit(void)
22 {
23     UART_Params uartParams;
24
25     UART_init();
26
27     UART_Params_init(&uartParams);
28     // Most params can be default because we only send data, we don't receive
29     uartParams.baudRate = 115200;
30     // unclear why the UART driver sticks in writing sometimes
31     uartParams.writeTimeout = 10000; // ticks
32
33     sDebugUartHandle = UART_open(CONFIG_UART_DEBUG, &uartParams);
34     return 0;
35 }
36
37 extern "C" void cc13x2_26x2VLog(const char * msg, va_list v)
38 {
39     int ret;
40
41     ret = vsnprintf(sDebugUartBuffer, sizeof(sDebugUartBuffer), msg, v);
42     if (0 < ret)
43     {
44         // PuTTY likes \r\n
45         size_t len                = (ret + 2U) < sizeof(sDebugUartBuffer) ? (ret + 2) : sizeof(sDebugUartBuffer);
46         sDebugUartBuffer[len - 2] = '\r';
47         sDebugUartBuffer[len - 1] = '\n';
48         sDebugUartBuffer[len]     = '\0';
49
50         UART_write(sDebugUartHandle, sDebugUartBuffer, len);
51     }
52 }
53
54 namespace chip {
55 namespace DeviceLayer {
56
57 /**
58  * Called whenever a log message is emitted.
59  *
60  * Can be overriden by the device logging file
61  */
62 void __attribute__((weak)) OnLogOutput(void) {}
63
64 } // namespace DeviceLayer
65 } // namespace chip
66
67 namespace chip {
68 namespace Logging {
69 namespace Platform {
70
71 void LogV(const char * module, uint8_t category, const char * msg, va_list v)
72 {
73     (void) module;
74     (void) category;
75
76     cc13x2_26x2VLog(msg, v);
77
78     chip::DeviceLayer::OnLogOutput();
79 }
80
81 } // namespace Platform
82 } // namespace Logging
83 } // namespace chip
84
85 /**
86  * LwIP log output function.
87  */
88 extern "C" void LwIPLog(const char * msg, ...)
89 {
90     va_list v;
91
92     va_start(v, msg);
93
94     cc13x2_26x2VLog(msg, v);
95
96     chip::DeviceLayer::OnLogOutput();
97     va_end(v);
98 }
99
100 /**
101  * Platform log output function.
102  */
103 extern "C" void cc13x2_26x2Log(const char * msg, ...)
104 {
105     va_list v;
106
107     va_start(v, msg);
108
109     cc13x2_26x2VLog(msg, v);
110
111     chip::DeviceLayer::OnLogOutput();
112     va_end(v);
113 }
114
115 #if CHIP_DEVICE_CONFIG_ENABLE_THREAD
116 extern "C" void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char * aFormat, ...)
117 {
118     va_list v;
119
120     (void) aLogLevel;
121     (void) aLogRegion;
122
123     va_start(v, aFormat);
124
125     cc13x2_26x2VLog(aFormat, v);
126
127     chip::DeviceLayer::OnLogOutput();
128     va_end(v);
129 }
130 #endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD