diff --git a/src/include/platform/internal/GenericPlatformManagerImpl.cpp b/src/include/platform/internal/GenericPlatformManagerImpl.cpp index 4df138169d2b12..ccdd93173413a9 100644 --- a/src/include/platform/internal/GenericPlatformManagerImpl.cpp +++ b/src/include/platform/internal/GenericPlatformManagerImpl.cpp @@ -241,7 +241,7 @@ void GenericPlatformManagerImpl::_DispatchEvent(const ChipDeviceEvent uint32_t delta = (static_cast(System::Clock::GetMonotonicMicroseconds() - startUS)) / 1000; if (delta > 100) { - ChipLogError(DeviceLayer, "Long dispatch time: %" PRId32 " ms", delta); + ChipLogError(DeviceLayer, "Long dispatch time: %" PRId32 " ms, for event type %d", delta, event->Type); } #endif // CHIP_PROGRESS_LOGGING } diff --git a/src/lwip/k32w/lwipopts.h b/src/lwip/k32w/lwipopts.h index bb41df46c96e07..3aa8308ec12f7d 100644 --- a/src/lwip/k32w/lwipopts.h +++ b/src/lwip/k32w/lwipopts.h @@ -107,7 +107,7 @@ #define SUB_ETHERNET_HEADER_SPACE (0) #define PBUF_LINK_HLEN (0) -#define TCPIP_THREAD_STACKSIZE (4096) +#define TCPIP_THREAD_STACKSIZE (2048) #define TCPIP_THREAD_PRIO (2) #define NETIF_MAX_HWADDR_LEN 8U diff --git a/src/platform/K32W/CHIPDevicePlatformConfig.h b/src/platform/K32W/CHIPDevicePlatformConfig.h index 6d3478341d9d78..a7f7f79282e26f 100644 --- a/src/platform/K32W/CHIPDevicePlatformConfig.h +++ b/src/platform/K32W/CHIPDevicePlatformConfig.h @@ -77,11 +77,11 @@ // ========== Platform-specific Configuration Overrides ========= #ifndef CHIP_DEVICE_CONFIG_CHIP_TASK_STACK_SIZE -#define CHIP_DEVICE_CONFIG_CHIP_TASK_STACK_SIZE 9216 +#define CHIP_DEVICE_CONFIG_CHIP_TASK_STACK_SIZE (5 * 1024) #endif // CHIP_DEVICE_CONFIG_CHIP_TASK_STACK_SIZE #ifndef CHIP_DEVICE_CONFIG_THREAD_TASK_STACK_SIZE -#define CHIP_DEVICE_CONFIG_THREAD_TASK_STACK_SIZE 8192 +#define CHIP_DEVICE_CONFIG_THREAD_TASK_STACK_SIZE 3072 #endif // CHIP_DEVICE_CONFIG_THREAD_TASK_STACK_SIZE #ifndef CHIP_DEVICE_CONFIG_BLE_APP_TASK_NAME diff --git a/src/platform/K32W/Logging.cpp b/src/platform/K32W/Logging.cpp index 9878fc5e741355..518afe94341e4c 100644 --- a/src/platform/K32W/Logging.cpp +++ b/src/platform/K32W/Logging.cpp @@ -9,9 +9,12 @@ #include -#define K32W_LOG_MODULE_NAME chip -#define EOL_CHARS "\r\n" /* End of Line Characters */ -#define EOL_CHARS_LEN 2 /* Length of EOL */ +#define K32W_LOG_MODULE_NAME chip +#define EOL_CHARS "\r\n" /* End of Line Characters */ +#define EOL_CHARS_LEN 2 /* Length of EOL */ + +#define TIMESTAMP_MAX_LEN_BYTES 10 +#define CATEGORY_MAX_LEN_BYTES 1 #if CHIP_DEVICE_CONFIG_ENABLE_THREAD #include @@ -21,60 +24,56 @@ static bool isLogInitialized; extern uint8_t gOtLogUartInstance; extern "C" void K32WWriteBlocking(const uint8_t * aBuf, uint32_t len); +extern "C" uint32_t otPlatAlarmMilliGetNow(void); namespace chip { namespace Logging { namespace Platform { -void GetMessageString(char * buf, uint8_t chipCategory, uint8_t otLevelLog) +/* bufLen must have at least 4 (miliseconds timestamp) + 1 (category) + */ +void GetMessageString(char * buf, uint8_t bufLen, const char * module, uint8_t category) { - if (chipCategory != kLogCategory_None) + int writtenLen = 0; + const char * categoryString; + + assert(bufLen >= (TIMESTAMP_MAX_LEN_BYTES + CATEGORY_MAX_LEN_BYTES + strlen(module) + 1)); + + writtenLen = snprintf(buf, bufLen, "[%lu]", otPlatAlarmMilliGetNow()); + bufLen -= writtenLen; + buf += writtenLen; + + if (category != kLogCategory_None) { - switch (chipCategory) + switch (category) { case kLogCategory_Error: - memcpy(buf, "[Error]", 7); + categoryString = "E"; break; case kLogCategory_Progress: - default: - memcpy(buf, "[Progress]", 10); + categoryString = "P"; break; case kLogCategory_Detail: - memcpy(buf, "[Debug]", 7); - break; - } - } - - if (otLevelLog != OT_LOG_LEVEL_NONE) - { - switch (otLevelLog) - { - case OT_LOG_LEVEL_CRIT: - memcpy(buf, "[Error]", 7); - break; - case OT_LOG_LEVEL_WARN: - memcpy(buf, "[Warn]", 6); + categoryString = "D"; break; - case OT_LOG_LEVEL_NOTE: - case OT_LOG_LEVEL_INFO: default: - memcpy(buf, "[Info]", 6); - break; - case OT_LOG_LEVEL_DEBG: - memcpy(buf, "[Debug]", 7); - break; + categoryString = "U"; } + + writtenLen = snprintf(buf, bufLen, "[%s]", categoryString); + bufLen -= writtenLen; + buf += writtenLen; } + + writtenLen = snprintf(buf + writtenLen, bufLen, "[%s]", module); } } // namespace Platform } // namespace Logging } // namespace chip -void FillPrefix(char * buf, uint8_t bufLen, uint8_t chipCategory, uint8_t otLevelLog) +void FillPrefix(char * buf, uint8_t bufLen, const char * module, uint8_t category) { - /* add the error string */ - chip::Logging::Platform::GetMessageString(buf, chipCategory, otLevelLog); + chip::Logging::Platform::GetMessageString(buf, bufLen, module, category); } namespace chip { @@ -91,7 +90,7 @@ void __attribute__((weak)) OnLogOutput(void) {} } // namespace DeviceLayer } // namespace chip -void GenericLog(const char * format, va_list arg) +void GenericLog(const char * format, va_list arg, const char * module, uint8_t category) { #if K32W_LOG_ENABLED @@ -106,9 +105,8 @@ void GenericLog(const char * format, va_list arg) otPlatUartEnable(); } - /* Prefix is composed of [Debug String][MOdule Name String] */ - FillPrefix(formattedMsg, CHIP_CONFIG_LOG_MESSAGE_MAX_SIZE - 1, chip::Logging::kLogCategory_None, - chip::Logging::kLogCategory_Detail); + /* Prefix is composed of [Time Reference][Debug String][Module Name String] */ + FillPrefix(formattedMsg, CHIP_CONFIG_LOG_MESSAGE_MAX_SIZE - 1, module, category); prefixLen = strlen(formattedMsg); // Append the log message. @@ -137,7 +135,7 @@ void LogV(const char * module, uint8_t category, const char * msg, va_list v) (void) category; #if K32W_LOG_ENABLED - GenericLog(msg, v); + GenericLog(msg, v, module, category); // Let the application know that a log message has been emitted. DeviceLayer::OnLogOutput(); @@ -157,9 +155,10 @@ void LogV(const char * module, uint8_t category, const char * msg, va_list v) extern "C" void LwIPLog(const char * msg, ...) { va_list v; + const char * module = "LWIP"; va_start(v, msg); - GenericLog(msg, v); + GenericLog(msg, v, module, chip::Logging::kLogCategory_None); va_end(v); } @@ -171,12 +170,13 @@ extern "C" void LwIPLog(const char * msg, ...) extern "C" void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char * aFormat, ...) { va_list v; + const char * module = "OT"; (void) aLogLevel; (void) aLogRegion; va_start(v, aFormat); - GenericLog(aFormat, v); + GenericLog(aFormat, v, module, chip::Logging::kLogCategory_None); va_end(v); } diff --git a/third_party/k32w_sdk/k32w_sdk.gni b/third_party/k32w_sdk/k32w_sdk.gni index 0a210ec8f32654..445c4ed6d3ee47 100644 --- a/third_party/k32w_sdk/k32w_sdk.gni +++ b/third_party/k32w_sdk/k32w_sdk.gni @@ -114,6 +114,7 @@ template("k32w_sdk") { ] defines = [ + "gPWR_CpuClk_48MHz=1", "gMainThreadPriority_c=6", "CPU_K32W061HN", "CPU_JN518X", @@ -155,6 +156,7 @@ template("k32w_sdk") { "SUPPORT_FOR_BLE=1", "gEnableBleInactivityTimeNotify=1", "DUAL_MODE_APP=1", + "gMainThreadStackSize_c=3096", #TODO: move OT defines in an OT specific GN file "OPENTHREAD_CONFIG_HEAP_EXTERNAL_ENABLE=1", @@ -174,11 +176,10 @@ template("k32w_sdk") { if (chip_with_se05x == 1) { defines += [ "MBEDTLS_FREESCALE_FREERTOS_CALLOC_ALT=1", - "gMainThreadStackSize_c=14048", + "CHIP_DEVICE_CONFIG_CHIP_TASK_STACK_SIZE=9216", ] - } else { - defines += [ "gMainThreadStackSize_c=6024" ] } + if (chip_with_OM15082 == 1) { defines += [ "gKBD_KeysCount_c=4",