From 3346aa71d6fefa8810bc21e5c7802c8f6cc3ca20 Mon Sep 17 00:00:00 2001 From: Thomas Langewouters <82949801+q-thla@users.noreply.github.com> Date: Wed, 11 Jan 2023 16:59:32 +0100 Subject: [PATCH] qpg: align examples with QMatter SDK (#24095) * qpg: align examples with QMatter SDK - Add light fixes (ColorFormat.cpp) - introduce powercycle counting to trigger factory reset - run code formatters * use c++ style cast * Fix error while trying to set Level to 0xff --- .../lighting-common/src/ColorFormat.cpp | 26 ++-- examples/lighting-app/qpg/BUILD.gn | 4 +- examples/lighting-app/qpg/src/AppTask.cpp | 68 +++++++++- .../lighting-app/qpg/src/LightingManager.cpp | 12 +- .../lighting-app/qpg/src/ZclCallbacks.cpp | 10 +- examples/lock-app/qpg/BUILD.gn | 1 + examples/lock-app/qpg/src/AppTask.cpp | 47 +++++-- examples/lock-app/qpg/src/BoltLockManager.cpp | 2 +- examples/platform/qpg/app/main.cpp | 15 ++- examples/platform/qpg/powercycle_counting.c | 125 ++++++++++++++++++ examples/platform/qpg/powercycle_counting.h | 35 +++++ third_party/qpg_sdk/BUILD.gn | 14 ++ 12 files changed, 316 insertions(+), 43 deletions(-) create mode 100644 examples/platform/qpg/powercycle_counting.c create mode 100644 examples/platform/qpg/powercycle_counting.h diff --git a/examples/lighting-app/lighting-common/src/ColorFormat.cpp b/examples/lighting-app/lighting-common/src/ColorFormat.cpp index 0b71b35d4a1ccb..d45d8cdc693291 100644 --- a/examples/lighting-app/lighting-common/src/ColorFormat.cpp +++ b/examples/lighting-app/lighting-common/src/ColorFormat.cpp @@ -90,33 +90,29 @@ RgbColor_t XYToRgb(uint8_t Level, uint16_t currentX, uint16_t currentY) float X, Y, Z; float r, g, b; - x = ((float) currentX) / 65535.0f; - y = ((float) currentY) / 65535.0f; + x = (static_cast(currentX)) / 65535.0f; + y = (static_cast(currentY)) / 65535.0f; z = 1.0f - x - y; // Calculate XYZ values // Y - given brightness in 0 - 1 range - Y = ((float) Level) / 254.0f; + Y = (static_cast(Level)) / 254.0f; X = (Y / y) * x; Z = (Y / y) * z; // X, Y and Z input refer to a D65/2° standard illuminant. // sR, sG and sB (standard RGB) output range = 0 ÷ 255 // convert XYZ to RGB - CIE XYZ to sRGB - X = X / 100.0f; - Y = Y / 100.0f; - Z = Z / 100.0f; - - r = (X * 3.2406f) - (Y * 1.5372f) - (Z * 0.4986f); - g = -(X * 0.9689f) + (Y * 1.8758f) + (Z * 0.0415f); - b = (X * 0.0557f) - (Y * 0.2040f) + (Z * 1.0570f); + r = (X * 3.2410f) - (Y * 1.5374f) - (Z * 0.4986f); + g = -(X * 0.9692f) + (Y * 1.8760f) + (Z * 0.0416f); + b = (X * 0.0556f) - (Y * 0.2040f) + (Z * 1.0570f); // apply gamma 2.2 correction - r = (r <= 0.0031308f ? 12.92f * r : (1.055f) * pow(r, (1.0f / 2.4f)) - 0.055f); - g = (g <= 0.0031308f ? 12.92f * g : (1.055f) * pow(g, (1.0f / 2.4f)) - 0.055f); - b = (b <= 0.0031308f ? 12.92f * b : (1.055f) * pow(b, (1.0f / 2.4f)) - 0.055f); + r = (r <= 0.00304f ? 12.92f * r : (1.055f) * pow(r, (1.0f / 2.4f)) - 0.055f); + g = (g <= 0.00304f ? 12.92f * g : (1.055f) * pow(g, (1.0f / 2.4f)) - 0.055f); + b = (b <= 0.00304f ? 12.92f * b : (1.055f) * pow(b, (1.0f / 2.4f)) - 0.055f); // Round off r = clamp(r, 0, 1); @@ -139,7 +135,7 @@ RgbColor_t CTToRgb(CtColor_t ct) // Algorithm credits to Tanner Helland: https://tannerhelland.com/2012/09/18/convert-temperature-rgb-algorithm-code.html // Convert Mireds to centiKelvins. k = 1,000,000/mired - float ctCentiKelvin = 10000 / ct.ctMireds; + float ctCentiKelvin = 10000 / static_cast(ct.ctMireds); // Red if (ctCentiKelvin <= 66) @@ -174,7 +170,7 @@ RgbColor_t CTToRgb(CtColor_t ct) } else { - b = 138.5177312231 * log(ctCentiKelvin - 10) - 305.0447927307; + b = 138.5177312231f * log(ctCentiKelvin - 10) - 305.0447927307f; } } rgb.r = (uint8_t) clamp(r, 0, 255); diff --git a/examples/lighting-app/qpg/BUILD.gn b/examples/lighting-app/qpg/BUILD.gn index 4e36f0c761ee00..479231f210d67e 100644 --- a/examples/lighting-app/qpg/BUILD.gn +++ b/examples/lighting-app/qpg/BUILD.gn @@ -56,6 +56,7 @@ qpg_executable("lighting_app") { "${chip_root}/src/app/clusters/general-diagnostics-server/GenericFaultTestEventTriggerDelegate.cpp", "${examples_plat_dir}/app/main.cpp", "${examples_plat_dir}/ota/ota.cpp", + "${examples_plat_dir}/powercycle_counting.c", "include/LightingManager.h", "src/AppTask.cpp", "src/LightingManager.cpp", @@ -85,8 +86,7 @@ qpg_executable("lighting_app") { "${examples_plat_dir}/ota", ] - defines = [] - + defines = [ "GP_APP_DIVERSITY_POWERCYCLECOUNTING" ] if (chip_enable_pw_rpc) { defines += [ "PW_RPC_ENABLED", diff --git a/examples/lighting-app/qpg/src/AppTask.cpp b/examples/lighting-app/qpg/src/AppTask.cpp index 145bee65d6c6be..b2878cfd371ea9 100644 --- a/examples/lighting-app/qpg/src/AppTask.cpp +++ b/examples/lighting-app/qpg/src/AppTask.cpp @@ -16,12 +16,19 @@ * limitations under the License. */ +#if !defined(GP_APP_DIVERSITY_POWERCYCLECOUNTING) +#error This application requires powercycle counting. +#endif + +#include "gpSched.h" +#include "powercycle_counting.h" #include "qvIO.h" #include "AppConfig.h" #include "AppEvent.h" #include "AppTask.h" #include "ota.h" +#include "powercycle_counting.h" #include @@ -61,13 +68,16 @@ using namespace ::chip::DeviceLayer; #define APP_EVENT_QUEUE_SIZE 10 #define QPG_LIGHT_ENDPOINT_ID (1) +static uint8_t countdown = 0; + namespace { TaskHandle_t sAppTaskHandle; QueueHandle_t sAppEventQueue; -bool sIsThreadProvisioned = false; -bool sIsThreadEnabled = false; -bool sHaveBLEConnections = false; +bool sIsThreadProvisioned = false; +bool sIsThreadEnabled = false; +bool sHaveBLEConnections = false; +bool sIsBLEAdvertisingEnabled = false; // NOTE! This key is for test/certification only and should not be available in production devices! uint8_t sTestEventTriggerEnableKey[TestEventTriggerDelegate::kEnableKeyLength] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, @@ -137,6 +147,7 @@ Identify gIdentify = { /********************************************************** * OffWithEffect Callbacks *********************************************************/ + void OnTriggerOffWithEffect(OnOffEffect * effect) { chip::app::Clusters::OnOff::OnOffEffectIdentifier effectId = effect->mEffectIdentifier; @@ -259,6 +270,8 @@ CHIP_ERROR AppTask::Init() { CHIP_ERROR err = CHIP_NO_ERROR; + gpAppFramework_Reset_Init(); + PlatformMgr().AddEventHandler(MatterEventHandler, 0); ChipLogProgress(NotSpecified, "Current Software Version: %s", CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING); @@ -331,7 +344,7 @@ void AppTask::LightingActionEventHandler(AppEvent * aEvent) { // Toggle Dimming of light between 2 fixed levels uint8_t val = 0x0; - val = LightingMgr().GetLevel() == 0x7f ? 0x1 : 0x7f; + val = LightingMgr().GetLevel() == 0x40 ? 0xfe : 0x40; action = LightingManager::LEVEL_ACTION; sAppTask.mSyncClusterToButtonAction = true; @@ -530,7 +543,7 @@ void AppTask::ActionCompleted(LightingManager::Action_t aAction) void AppTask::PostEvent(const AppEvent * aEvent) { - if (sAppEventQueue != NULL) + if (sAppEventQueue != nullptr) { if (!xQueueSend(sAppEventQueue, aEvent, 1)) { @@ -539,7 +552,7 @@ void AppTask::PostEvent(const AppEvent * aEvent) } else { - ChipLogError(NotSpecified, "Event Queue is NULL should never happen"); + ChipLogError(NotSpecified, "Event Queue is nullptr should never happen"); } } @@ -564,6 +577,7 @@ void AppTask::UpdateClusterState(void) // Write the new on/off value EmberAfStatus status = Clusters::OnOff::Attributes::OnOff::Set(QPG_LIGHT_ENDPOINT_ID, LightingMgr().IsTurnedOn()); + if (status != EMBER_ZCL_STATUS_SUCCESS) { ChipLogError(NotSpecified, "ERR: updating on/off %x", status); @@ -591,14 +605,19 @@ void AppTask::UpdateLEDs(void) // Otherwise, blink the LED ON for a very short time. if (sIsThreadProvisioned && sIsThreadEnabled) { - qvIO_LedBlink(SYSTEM_STATE_LED, 950, 50); + qvIO_LedSet(SYSTEM_STATE_LED, true); } else if (sHaveBLEConnections) { qvIO_LedBlink(SYSTEM_STATE_LED, 100, 100); } + else if (sIsBLEAdvertisingEnabled) + { + qvIO_LedBlink(SYSTEM_STATE_LED, 50, 50); + } else { + // not commisioned yet qvIO_LedBlink(SYSTEM_STATE_LED, 50, 950); } } @@ -631,7 +650,42 @@ void AppTask::MatterEventHandler(const ChipDeviceEvent * event, intptr_t) break; } + case DeviceEventType::kCHIPoBLEAdvertisingChange: { + sIsBLEAdvertisingEnabled = (event->CHIPoBLEAdvertisingChange.Result == kActivity_Started); + UpdateLEDs(); + break; + } + default: break; } } + +static void NextCountdown(void) +{ + if (countdown > 0) + { + LightingMgr().InitiateAction((countdown % 2 == 0) ? LightingManager::ON_ACTION : LightingManager::OFF_ACTION, 0, 0, 0); + countdown--; + gpSched_ScheduleEvent(1000000UL, NextCountdown); + } + else + { + ConfigurationMgr().InitiateFactoryReset(); + } +} + +extern "C" { +void gpAppFramework_Reset_cbTriggerResetCountCompleted(void) +{ + uint8_t resetCount = gpAppFramework_Reset_GetResetCount(); + + ChipLogProgress(NotSpecified, "%d resets so far", resetCount); + if (resetCount == 10) + { + ChipLogProgress(NotSpecified, "Factory Reset Triggered!"); + countdown = 5; + NextCountdown(); + } +} +} diff --git a/examples/lighting-app/qpg/src/LightingManager.cpp b/examples/lighting-app/qpg/src/LightingManager.cpp index 9f00b25db45927..a107285b280a2c 100644 --- a/examples/lighting-app/qpg/src/LightingManager.cpp +++ b/examples/lighting-app/qpg/src/LightingManager.cpp @@ -22,13 +22,15 @@ #include // initialization values for Blue in XY color space -constexpr XyColor_t kBlueXY = { 9830, 3932 }; +constexpr XyColor_t kBlueXY = { 9830, 3932 }; +constexpr XyColor_t kWhiteXY = { 20495, 21563 }; // initialization values for Blue in HSV color space -constexpr HsvColor_t kBlueHSV = { 240, 100, 255 }; +constexpr HsvColor_t kBlueHSV = { 240, 100, 255 }; +constexpr HsvColor_t kWhiteHSV = { 0, 0, 255 }; // default initialization value for the light level after start -constexpr uint8_t kDefaultLevel = 64; +constexpr uint8_t kDefaultLevel = 1; LightingManager LightingManager::sLight; @@ -36,8 +38,8 @@ CHIP_ERROR LightingManager::Init() { mState = kState_Off; mLevel = kDefaultLevel; - mXY = kBlueXY; - mHSV = kBlueHSV; + mXY = kWhiteXY; + mHSV = kWhiteHSV; mRGB = XYToRgb(mLevel, mXY.x, mXY.y); return CHIP_NO_ERROR; diff --git a/examples/lighting-app/qpg/src/ZclCallbacks.cpp b/examples/lighting-app/qpg/src/ZclCallbacks.cpp index 9faedea78dcec3..6b42b38c7f1b1c 100644 --- a/examples/lighting-app/qpg/src/ZclCallbacks.cpp +++ b/examples/lighting-app/qpg/src/ZclCallbacks.cpp @@ -160,5 +160,13 @@ void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath & */ void emberAfOnOffClusterInitCallback(EndpointId endpoint) { - // No additional init currently - startup state handled by cluster. + bool onOffValue = false; + + EmberAfStatus status = OnOff::Attributes::OnOff::Get(1, &onOffValue); + + if (status == EMBER_ZCL_STATUS_SUCCESS) + { + LightingMgr().InitiateAction(onOffValue ? LightingManager::ON_ACTION : LightingManager::OFF_ACTION, 0, 1, + (uint8_t *) onOffValue); + } } diff --git a/examples/lock-app/qpg/BUILD.gn b/examples/lock-app/qpg/BUILD.gn index ac901678db266c..1d4ac784b672a1 100644 --- a/examples/lock-app/qpg/BUILD.gn +++ b/examples/lock-app/qpg/BUILD.gn @@ -53,6 +53,7 @@ qpg_executable("lock_app") { output_name = "chip-${qpg_target_ic}-lock-example.out" sources = [ + "${chip_root}/src/app/clusters/general-diagnostics-server/GenericFaultTestEventTriggerDelegate.cpp", "${examples_plat_dir}/app/main.cpp", "${examples_plat_dir}/ota/ota.cpp", "src/AppTask.cpp", diff --git a/examples/lock-app/qpg/src/AppTask.cpp b/examples/lock-app/qpg/src/AppTask.cpp index 3306379bbe41da..09aca7a146589d 100644 --- a/examples/lock-app/qpg/src/AppTask.cpp +++ b/examples/lock-app/qpg/src/AppTask.cpp @@ -28,6 +28,8 @@ #include #include #include +#include +#include #include #include #include @@ -43,9 +45,9 @@ using namespace ::chip; using namespace ::chip::app; -using namespace chip::TLV; -using namespace chip::Credentials; -using namespace chip::DeviceLayer; +using namespace ::chip::TLV; +using namespace ::chip::Credentials; +using namespace ::chip::DeviceLayer; #include @@ -53,7 +55,7 @@ using namespace chip::DeviceLayer; #define FACTORY_RESET_CANCEL_WINDOW_TIMEOUT 3000 #define OTA_START_TRIGGER_TIMEOUT 1500 -#define APP_TASK_STACK_SIZE (2 * 1024) +#define APP_TASK_STACK_SIZE (3 * 1024) #define APP_TASK_PRIORITY 2 #define APP_EVENT_QUEUE_SIZE 10 #define QPG_LOCK_ENDPOINT_ID (1) @@ -62,9 +64,14 @@ namespace { TaskHandle_t sAppTaskHandle; QueueHandle_t sAppEventQueue; -bool sIsThreadProvisioned = false; -bool sIsThreadEnabled = false; -bool sHaveBLEConnections = false; +bool sIsThreadProvisioned = false; +bool sIsThreadEnabled = false; +bool sHaveBLEConnections = false; +bool sIsBLEAdvertisingEnabled = false; + +// NOTE! This key is for test/certification only and should not be available in production devices! +uint8_t sTestEventTriggerEnableKey[TestEventTriggerDelegate::kEnableKeyLength] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, + 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff }; uint8_t sAppEventQueueBuffer[APP_EVENT_QUEUE_SIZE * sizeof(AppEvent)]; @@ -124,6 +131,12 @@ void AppTask::InitServer(intptr_t arg) nativeParams.unlockCb = UnlockOpenThreadTask; nativeParams.openThreadInstancePtr = chip::DeviceLayer::ThreadStackMgrImpl().OTInstance(); initParams.endpointNativeParams = static_cast(&nativeParams); + + // Use GenericFaultTestEventTriggerDelegate to inject faults + static GenericFaultTestEventTriggerDelegate testEventTriggerDelegate{ ByteSpan(sTestEventTriggerEnableKey) }; + (void) initParams.InitializeStaticResourcesBeforeServerInit(); + initParams.testEventTriggerDelegate = &testEventTriggerDelegate; + chip::Server::GetInstance().Init(initParams); #if CHIP_DEVICE_CONFIG_ENABLE_EXTENDED_DISCOVERY @@ -469,7 +482,7 @@ void AppTask::PostLockActionRequest(int32_t aActor, BoltLockManager::Action_t aA void AppTask::PostEvent(const AppEvent * aEvent) { - if (sAppEventQueue != NULL) + if (sAppEventQueue != nullptr) { if (!xQueueSend(sAppEventQueue, aEvent, 1)) { @@ -478,7 +491,7 @@ void AppTask::PostEvent(const AppEvent * aEvent) } else { - ChipLogError(NotSpecified, "Event Queue is NULL should never happen"); + ChipLogError(NotSpecified, "Event Queue is nullptr should never happen"); } } @@ -504,7 +517,8 @@ void AppTask::UpdateClusterState(void) ChipLogProgress(NotSpecified, "UpdateClusterState"); - EmberAfStatus status = DoorLock::Attributes::LockState::Set(DOOR_LOCK_SERVER_ENDPOINT, newValue); + EmberAfStatus status = DoorLock::Attributes::LockState::Set(QPG_LOCK_ENDPOINT_ID, newValue); + if (status != EMBER_ZCL_STATUS_SUCCESS) { ChipLogError(NotSpecified, "ERR: updating DoorLock %x", status); @@ -525,14 +539,19 @@ void AppTask::UpdateLEDs(void) // Otherwise, blink the LED ON for a very short time. if (sIsThreadProvisioned && sIsThreadEnabled) { - qvIO_LedBlink(SYSTEM_STATE_LED, 950, 50); + qvIO_LedSet(SYSTEM_STATE_LED, true); } else if (sHaveBLEConnections) { qvIO_LedBlink(SYSTEM_STATE_LED, 100, 100); } + else if (sIsBLEAdvertisingEnabled) + { + qvIO_LedBlink(SYSTEM_STATE_LED, 50, 50); + } else { + // not commisioned yet qvIO_LedBlink(SYSTEM_STATE_LED, 50, 950); } } @@ -565,6 +584,12 @@ void AppTask::MatterEventHandler(const ChipDeviceEvent * event, intptr_t) break; } + case DeviceEventType::kCHIPoBLEAdvertisingChange: { + sIsBLEAdvertisingEnabled = (event->CHIPoBLEAdvertisingChange.Result == kActivity_Started); + UpdateLEDs(); + break; + } + default: break; } diff --git a/examples/lock-app/qpg/src/BoltLockManager.cpp b/examples/lock-app/qpg/src/BoltLockManager.cpp index 5799916274219d..f407648b4166a9 100644 --- a/examples/lock-app/qpg/src/BoltLockManager.cpp +++ b/examples/lock-app/qpg/src/BoltLockManager.cpp @@ -52,7 +52,7 @@ CHIP_ERROR BoltLockManager::Init() TimerEventHandler // timer callback handler ); #endif - if (sLockTimer == NULL) + if (sLockTimer == nullptr) { ChipLogProgress(NotSpecified, "sLockTimer timer create failed"); return APP_ERROR_CREATE_TIMER_FAILED; diff --git a/examples/platform/qpg/app/main.cpp b/examples/platform/qpg/app/main.cpp index 3c21833f1362b6..673dc29b83284b 100644 --- a/examples/platform/qpg/app/main.cpp +++ b/examples/platform/qpg/app/main.cpp @@ -28,6 +28,12 @@ // FreeRTOS #include "FreeRTOS.h" #include "task.h" +#if defined(GP_APP_DIVERSITY_POWERCYCLECOUNTING) +#include "powercycle_counting.h" +#endif +#if defined(GP_APP_DIVERSITY_CLEARBOX_TESTING_HOOK_APPLICATION_INIT) +#include "clearbox_testing_hooks.h" +#endif // Qorvo CHIP library #include "qvCHIP.h" @@ -71,6 +77,7 @@ constexpr int extDiscTimeoutSecs = 20; /***************************************************************************** * Application Function Definitions *****************************************************************************/ + CHIP_ERROR CHIP_Init(void); #if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR @@ -84,6 +91,13 @@ void Application_Init(void) { CHIP_ERROR error; +#if defined(GP_APP_DIVERSITY_CLEARBOX_TESTING_HOOK_APPLICATION_INIT) + GP_CLEARBOX_TESTING_APPLICATION_INIT_HOOK; +#endif +#if defined(GP_APP_DIVERSITY_POWERCYCLECOUNTING) + gpAppFramework_Reset_Init(); +#endif + /* Initialize CHIP stack */ error = CHIP_Init(); if (error != CHIP_NO_ERROR) @@ -212,7 +226,6 @@ CHIP_ERROR CHIP_Init(void) /***************************************************************************** * --- Main *****************************************************************************/ - int main(void) { int result; diff --git a/examples/platform/qpg/powercycle_counting.c b/examples/platform/qpg/powercycle_counting.c new file mode 100644 index 00000000000000..be141ce77c4572 --- /dev/null +++ b/examples/platform/qpg/powercycle_counting.c @@ -0,0 +1,125 @@ +/* + * + * Copyright (c) 2021 Project CHIP Authors + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** @file "gpAppFramework_Reset.c" + * + * Application API + * + * Implementation of gpAppFramework Reset + */ + +/***************************************************************************** + * Includes Definitions + *****************************************************************************/ +#define GP_COMPONENT_ID_APPFRAMEWORK 56 +#define GP_COMPONENT_ID GP_COMPONENT_ID_APPFRAMEWORK + +#include "powercycle_counting.h" +#include "global.h" +#include "gpAssert.h" +#include "gpLog.h" +#include "gpReset.h" +#include "gpSched.h" +#include "qvCHIP.h" +#include "qvCHIP_KVS.h" + +/***************************************************************************** + * Macro Definitions + *****************************************************************************/ +#define RESET_COUNTING_PERIOD_US 2000000 // 2s + +#define KVS_RESET_CYCLES_KEY "qrst" +/***************************************************************************** + * Static Function Prototypes + *****************************************************************************/ + +/***************************************************************************** + * Static Function Definitions + *****************************************************************************/ + +static void gpAppFramework_HardwareResetTriggered(void) +{ + UInt8 resetCounts; + qvStatus_t status; + size_t readBytesSize; + + status = qvCHIP_KvsGet(KVS_RESET_CYCLES_KEY, &resetCounts, 1, &readBytesSize, 0); + if (status == QV_STATUS_INVALID_DATA || readBytesSize != 0) + { + resetCounts = 0; + } + else if (status != QV_STATUS_NO_ERROR) + { + GP_LOG_SYSTEM_PRINTF("got status %d", 0, status); + GP_ASSERT_SYSTEM(status == QV_STATUS_NO_ERROR); // fixme + } + + GP_LOG_SYSTEM_PRINTF("ResetCount[%d]", 0, resetCounts); + + resetCounts++; + + status = qvCHIP_KvsPut(KVS_RESET_CYCLES_KEY, &resetCounts, 1); + if (status != QV_STATUS_NO_ERROR) + { + GP_LOG_SYSTEM_PRINTF("got status %d", 0, status); + GP_ASSERT_SYSTEM(status == QV_STATUS_NO_ERROR); // fixme + } +} + +/***************************************************************************** + * Public Function Definitions + *****************************************************************************/ +UInt8 gpAppFramework_Reset_GetResetCount(void) +{ + UInt8 resetCounts; + const UInt8 resetCountsCleared = 0; + + qvStatus_t status; + size_t readBytesSize; + status = qvCHIP_KvsGet(KVS_RESET_CYCLES_KEY, &resetCounts, 1, &readBytesSize, 0); + if (status == QV_STATUS_INVALID_DATA || readBytesSize != 1) + { + resetCounts = 0; + } + else if (status != QV_STATUS_NO_ERROR) + { + GP_LOG_SYSTEM_PRINTF("got status %d", 0, status); + GP_ASSERT_SYSTEM(status == QV_STATUS_NO_ERROR); + } + + GP_LOG_PRINTF("Processing reset counts: %u", 0, resetCounts); + + status = qvCHIP_KvsPut(KVS_RESET_CYCLES_KEY, &resetCountsCleared, 1); + if (status != QV_STATUS_NO_ERROR) + { + GP_LOG_SYSTEM_PRINTF("got status %d", 0, status); + GP_ASSERT_SYSTEM(status == QV_STATUS_NO_ERROR); // fixme + } + + return resetCounts; +} + +void gpAppFramework_Reset_Init(void) +{ + if (gpReset_GetResetReason() == gpReset_ResetReason_HW_Por) + { + gpAppFramework_HardwareResetTriggered(); + } + + gpSched_ScheduleEvent(RESET_COUNTING_PERIOD_US, gpAppFramework_Reset_cbTriggerResetCountCompleted); +} diff --git a/examples/platform/qpg/powercycle_counting.h b/examples/platform/qpg/powercycle_counting.h new file mode 100644 index 00000000000000..ca561bf0221fc1 --- /dev/null +++ b/examples/platform/qpg/powercycle_counting.h @@ -0,0 +1,35 @@ +/* + * + * Copyright (c) 2022 Project CHIP Authors + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _POWERCYCLE_COUNTING_H_ +#define _POWERCYCLE_COUNTING_H_ + +#include "inttypes.h" + +#ifdef __cplusplus +extern "C" { +#endif +void gpAppFramework_Reset_Init(void); +uint8_t gpAppFramework_Reset_GetResetCount(void); +void gpAppFramework_Reset_cbTriggerResetCountCompleted(void); + +#ifdef __cplusplus +} +#endif + +#endif // _POWERCYCLE_COUNTING_H_ diff --git a/third_party/qpg_sdk/BUILD.gn b/third_party/qpg_sdk/BUILD.gn index d1c60542365ae9..3ccd4878c05f39 100755 --- a/third_party/qpg_sdk/BUILD.gn +++ b/third_party/qpg_sdk/BUILD.gn @@ -29,6 +29,20 @@ group("qpg_sdk") { ":freertos", qpg_sdk_target, ] + public_configs = [ ":qpg_include_paths_config" ] +} + +config("qpg_include_paths_config") { + include_dirs = [ + "${qpg_sdk_root}/Components/Qorvo/BaseUtils/gpNvm/inc", + "${qpg_sdk_root}/Components/Qorvo/HAL_PLATFORM/inc", + "${qpg_sdk_root}/Components/Qorvo/OS/gpLog/inc", + "${qpg_sdk_root}/Components/Qorvo/OS/gpReset/inc", + "${qpg_sdk_root}/Components/Qorvo/OS/gpSched/inc", + "${qpg_sdk_root}/Components/Qorvo/OS/gpAssert/inc", + "${qpg_sdk_root}/Components/Qorvo/HAL_PLATFORM/inc/compiler/ARMGCCEMB", + "${qpg_sdk_root}/Components/Qorvo/Matter/qvCHIP/inc", + ] } config("qpg_freertos_config") {