1 /* See Project CHIP LICENSE file for licensing information. */
2 #include <platform/logging/LogV.h>
6 #include <core/CHIPConfig.h>
7 #include <platform/CHIPDeviceConfig.h>
8 #include <support/CHIPPlatformMemory.h>
9 #include <support/logging/Constants.h>
14 #if CHIP_DEVICE_CONFIG_ENABLE_THREAD
15 #include <openthread/platform/logging.h>
16 #include <openthread/platform/memory.h>
17 #endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD
19 constexpr uint8_t kPrintfModuleLwip = 0x01;
20 constexpr uint8_t kPrintfModuleOpenThread = 0x02;
21 constexpr uint8_t kPrintfModuleLogging = 0x03;
24 namespace DeviceLayer {
27 * Called whenever a log message is emitted by chip or LwIP.
29 * This function is intended be overridden by the application to, e.g.,
30 * schedule output of queued log entries.
32 void __attribute__((weak)) OnLogOutput(void) {}
34 } // namespace DeviceLayer
42 * CHIP log output function.
45 void LogV(const char * module, uint8_t category, const char * msg, va_list v)
47 char formattedMsg[CHIP_CONFIG_LOG_MESSAGE_MAX_SIZE];
52 // No build-time switches in Qorvo logging module.
53 // Add small prefix to show logging category for now.
54 formattedMsg[prefixLen++] = '[';
57 case kLogCategory_Error:
58 formattedMsg[prefixLen++] = 'E';
60 case kLogCategory_Detail:
61 formattedMsg[prefixLen++] = 'D';
63 case kLogCategory_Progress:
65 formattedMsg[prefixLen++] = 'P';
68 snprintf(formattedMsg + prefixLen, sizeof(formattedMsg) - prefixLen, "][%s] ", module);
69 formattedMsg[sizeof(formattedMsg) - 2] = 0; // -2 to allow at least one char for the vsnprintf
70 prefixLen = strlen(formattedMsg);
72 vsnprintf(formattedMsg + prefixLen, sizeof(formattedMsg) - prefixLen, msg, v);
74 qvCHIP_Printf(kPrintfModuleLogging, formattedMsg);
76 // Let the application know that a log message has been emitted.
77 chip::DeviceLayer::OnLogOutput();
80 } // namespace Platform
81 } // namespace Logging
85 * LwIP log output function.
87 extern "C" void LwIPLog(const char * msg, ...)
89 char formattedMsg[CHIP_CONFIG_LOG_MESSAGE_MAX_SIZE];
94 size_t len = vsnprintf(formattedMsg, sizeof(formattedMsg), msg, v);
97 while (len > 0 && isspace(formattedMsg[len - 1]))
100 formattedMsg[len] = 0;
103 qvCHIP_Printf(kPrintfModuleLwip, formattedMsg);
105 // Let the application know that a log message has been emitted.
106 chip::DeviceLayer::OnLogOutput();
109 #if CHIP_DEVICE_CONFIG_ENABLE_THREAD
110 extern "C" void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char * aFormat, ...)
112 char formattedMsg[CHIP_CONFIG_LOG_MESSAGE_MAX_SIZE];
116 va_start(v, aFormat);
117 vsnprintf(formattedMsg, sizeof(formattedMsg), aFormat, v);
120 qvCHIP_Printf(kPrintfModuleOpenThread, formattedMsg);
122 // Let the application know that a log message has been emitted.
123 chip::DeviceLayer::OnLogOutput();
126 // TODO: have qpg6100 openthread platform implementation defines the APIs.
127 // It is not perfect to have the openthread platform calloc/free
128 // APIs defined here. If a dedicated source file (e.g. Memory.cpp)
129 // that includes only the two functions is used, the target file
130 // Memory.o will be thrown away whening linking the libary because
131 // there is no one referring the symbols (We are not linking
132 // the 'platform' library against openthread).
133 extern "C" void * otPlatCAlloc(size_t aNum, size_t aSize)
135 return CHIPPlatformMemoryCalloc(aNum, aSize);
138 extern "C" void otPlatFree(void * aPtr)
140 CHIPPlatformMemoryFree(aPtr);
142 #endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD