diff --git a/src/adaptations/device-layer/EventLogging.cpp b/src/adaptations/device-layer/EventLogging.cpp index 30db32063e..d7619c0065 100644 --- a/src/adaptations/device-layer/EventLogging.cpp +++ b/src/adaptations/device-layer/EventLogging.cpp @@ -35,21 +35,22 @@ namespace Weave { namespace DeviceLayer { namespace Internal { +/* BSS segment is limited on some device, provides an option to allocate large memory buffer on heap */ +#ifdef WEAVE_DEVICE_CONFIG_EVENT_LOGGING_BUFFER_STATIC uint64_t gCritEventBuffer[RoundUp(WEAVE_DEVICE_CONFIG_EVENT_LOGGING_CRIT_BUFFER_SIZE, sizeof(uint64_t)) / sizeof(uint64_t)]; -static nl::Weave::PersistedCounter sCritEventIdCounter; - uint64_t gProdEventBuffer[RoundUp(WEAVE_DEVICE_CONFIG_EVENT_LOGGING_PROD_BUFFER_SIZE, sizeof(uint64_t)) / sizeof(uint64_t)]; -static nl::Weave::PersistedCounter sProdEventIdCounter; - #if WEAVE_DEVICE_CONFIG_EVENT_LOGGING_INFO_BUFFER_SIZE uint64_t gInfoEventBuffer[RoundUp(WEAVE_DEVICE_CONFIG_EVENT_LOGGING_INFO_BUFFER_SIZE, sizeof(uint64_t)) / sizeof(uint64_t)]; -static nl::Weave::PersistedCounter sInfoEventIdCounter; #endif - #if WEAVE_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE uint64_t gDebugEventBuffer[RoundUp(WEAVE_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE, sizeof(uint64_t)) / sizeof(uint64_t)]; -static nl::Weave::PersistedCounter sDebugEventIdCounter; #endif +#endif + +static nl::Weave::PersistedCounter sCritEventIdCounter; +static nl::Weave::PersistedCounter sProdEventIdCounter; +static nl::Weave::PersistedCounter sInfoEventIdCounter; +static nl::Weave::PersistedCounter sDebugEventIdCounter; WEAVE_ERROR InitWeaveEventLogging(void) { @@ -62,6 +63,7 @@ WEAVE_ERROR InitWeaveEventLogging(void) nl::Weave::Platform::PersistedStorage::Key debugEventIdCounterStorageKey = WEAVE_DEVICE_CONFIG_PERSISTED_STORAGE_DEBUG_EIDC_KEY; #endif +#ifdef WEAVE_DEVICE_CONFIG_EVENT_LOGGING_BUFFER_STATIC nl::Weave::Profiles::DataManagement::LogStorageResources logStorageResources[] = { { static_cast(&gCritEventBuffer[0]), sizeof(gCritEventBuffer), &critEventIdCounterStorageKey, @@ -88,6 +90,38 @@ WEAVE_ERROR InitWeaveEventLogging(void) nl::Weave::Profiles::DataManagement::ImportanceType::Debug }, #endif }; +#else + nl::Weave::Profiles::DataManagement::LogStorageResources logStorageResources[] = { + { static_cast(malloc(RoundUp(WEAVE_DEVICE_CONFIG_EVENT_LOGGING_CRIT_BUFFER_SIZE, sizeof(uint64_t)))), + RoundUp(WEAVE_DEVICE_CONFIG_EVENT_LOGGING_CRIT_BUFFER_SIZE, sizeof(uint64_t)), + &critEventIdCounterStorageKey, + WEAVE_DEVICE_CONFIG_EVENT_ID_COUNTER_EPOCH, + &sCritEventIdCounter, + nl::Weave::Profiles::DataManagement::ImportanceType::ProductionCritical }, + { static_cast(malloc(RoundUp(WEAVE_DEVICE_CONFIG_EVENT_LOGGING_PROD_BUFFER_SIZE, sizeof(uint64_t)))), + RoundUp(WEAVE_DEVICE_CONFIG_EVENT_LOGGING_PROD_BUFFER_SIZE, sizeof(uint64_t)), + &prodEventIdCounterStorageKey, + WEAVE_DEVICE_CONFIG_EVENT_ID_COUNTER_EPOCH, + &sProdEventIdCounter, + nl::Weave::Profiles::DataManagement::ImportanceType::Production }, +#if WEAVE_DEVICE_CONFIG_EVENT_LOGGING_INFO_BUFFER_SIZE + { static_cast(malloc(RoundUp(WEAVE_DEVICE_CONFIG_EVENT_LOGGING_INFO_BUFFER_SIZE, sizeof(uint64_t)))), + RoundUp(WEAVE_DEVICE_CONFIG_EVENT_LOGGING_INFO_BUFFER_SIZE, sizeof(uint64_t)), + &infoEventIdCounterStorageKey, + WEAVE_DEVICE_CONFIG_EVENT_ID_COUNTER_EPOCH, + &sInfoEventIdCounter, + nl::Weave::Profiles::DataManagement::ImportanceType::Info }, +#endif +#if WEAVE_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE + { static_cast(malloc(RoundUp(WEAVE_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE, sizeof(uint64_t)))), + RoundUp(WEAVE_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE, sizeof(uint64_t)), + &debugEventIdCounterStorageKey, + WEAVE_DEVICE_CONFIG_EVENT_ID_COUNTER_EPOCH, + &sDebugEventIdCounter, + nl::Weave::Profiles::DataManagement::ImportanceType::Debug }, +#endif + }; +#endif nl::Weave::Profiles::DataManagement::LoggingManagement::CreateLoggingManagement( &nl::Weave::DeviceLayer::ExchangeMgr, diff --git a/src/adaptations/device-layer/include/Weave/DeviceLayer/WeaveDeviceConfig.h b/src/adaptations/device-layer/include/Weave/DeviceLayer/WeaveDeviceConfig.h index f1dcdcdbcd..8bfe5af0d7 100644 --- a/src/adaptations/device-layer/include/Weave/DeviceLayer/WeaveDeviceConfig.h +++ b/src/adaptations/device-layer/include/Weave/DeviceLayer/WeaveDeviceConfig.h @@ -744,6 +744,17 @@ #endif // -------------------- Event Logging Configuration -------------------- +/** + * @def WEAVE_DEVICE_CONFIG_EVENT_LOGGING_BUFFER_STATIC + * + * @brief + * Allocate logging buffer on data segment if defined, or allocate on + * heap dynamically if not defined + */ +#ifndef WEAVE_DEVICE_CONFIG_EVENT_LOGGING_BUFFER_STATIC +#define WEAVE_DEVICE_CONFIG_EVENT_LOGGING_BUFFER_STATIC 1 +#endif + /** * @def WEAVE_DEVICE_CONFIG_EVENT_LOGGING_CRIT_BUFFER_SIZE