Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[K32W] Improve debugging + CPU speed #7717

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ void GenericPlatformManagerImpl<ImplClass>::_DispatchEvent(const ChipDeviceEvent
uint32_t delta = (static_cast<uint32_t>(System::Layer::GetClock_MonotonicHiRes() - 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
69 changes: 32 additions & 37 deletions src/platform/K32W/Logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,60 +21,54 @@
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)
void GetMessageString(char * buf, uint8_t bufLen, const char * module, uint8_t category)
{
if (chipCategory != kLogCategory_None)
int writtenLen = 0;
const char * categoryString;

writtenLen = snprintf(buf, bufLen, "[%lu]", otPlatAlarmMilliGetNow());
assert((writtenLen > 0) && (writtenLen < bufLen));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this assert valid? What guarantees that writtenLen >= bufLen can't happen here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this assert valid? What guarantees that writtenLen >= bufLen can't happen here?

We can calculate the minimum size and document this as a precondition?

bufLen -= 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);
categoryString = "D";
break;
case OT_LOG_LEVEL_WARN:
memcpy(buf, "[Warn]", 6);
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 + writtenLen, bufLen, "[%s]", categoryString);
assert((writtenLen > 0) && (writtenLen < bufLen));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, what guaratees the assert holds? I don't see anything.

bufLen -= writtenLen;
}

writtenLen = snprintf(buf + writtenLen, bufLen, "[%s]", module);
assert((writtenLen > 0) && (writtenLen < bufLen));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here.

}

} // 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 +85,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 +100,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 +130,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 +150,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 +165,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
1 change: 1 addition & 0 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