Skip to content

Commit

Permalink
Matter TE4 fixes
Browse files Browse the repository at this point in the history
* decrease stack size (allocated dinamically) for most of the tasks
(by using the Stack Water Mark feature in FreeRTOS);
* improve debugging by adding more logging related to timestamps and
increase the CPU speed to 48Mhz
(see #7717)

Signed-off-by: Doru Gucea <[email protected]>

[THREADIP-3532] Improve debugging + CPU speed
  • Loading branch information
doru91 authored and restyled-io[bot] committed Jul 15, 2021
1 parent 1f020c5 commit 1428066
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ void GenericPlatformManagerImpl<ImplClass>::_DispatchEvent(const ChipDeviceEvent
uint32_t delta = (static_cast<uint32_t>(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
}
Expand Down
2 changes: 1 addition & 1 deletion src/lwip/k32w/lwipopts.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/platform/K32W/CHIPDevicePlatformConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
80 changes: 40 additions & 40 deletions src/platform/K32W/Logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@

#include <cstring>

#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 <openthread/platform/logging.h>
Expand All @@ -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 {
Expand All @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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();

Expand All @@ -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);
}

Expand All @@ -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);
}

Expand Down
7 changes: 4 additions & 3 deletions third_party/k32w_sdk/k32w_sdk.gni
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ template("k32w_sdk") {
]

defines = [
"gPWR_CpuClk_48MHz=1",
"gMainThreadPriority_c=6",
"CPU_K32W061HN",
"CPU_JN518X",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down

0 comments on commit 1428066

Please sign in to comment.