add watchcat

This commit is contained in:
souldbminersmwc committed 2026-10-04 16:39:09 -04:00
1 parent eae39374a8
commit e9d01a0878
8 files changed
+69 -12

No files matched your search

+2 -4
View File
@@ -95,7 +95,8 @@ namespace board {
rc = pscPmModuleGetRequest(&s_pscModule, &state, &flags);
if (R_SUCCEEDED(rc)) {
if (state == PscPmState_Awake) {
i2c::wdt::Arm(i2c::wdt::MAX77620_WDT_2S);
i2c::wdt::ResetWdtEnableState();
i2c::wdt::Pet();
s_isAwake = true;
} else if (state == PscPmState_ReadySleep) {
i2c::wdt::Disarm();
@@ -251,9 +252,6 @@ namespace board {
rc = threadStart(&s_pscThread);
ASSERT_RESULT_OK(rc, "threadStart");
/* Arm the watchdog */
i2c::wdt::Arm(i2c::wdt::MAX77620_WDT_2S);
}
void Exit() {
@@ -1,5 +1,5 @@
/*
*
*
* Copyright (c) Souldbminer, Lightos_ and Horizon OC Contributors
*
* This program is free software; you can redistribute it and/or modify it
@@ -17,6 +17,9 @@
*/
#include "max77620_wdt.hpp"
#include "../file/config.hpp"
#include <lockable_mutex.h>
#include <mutex>
/* PMIC Registers */
#define MAX77620_REG_CNFGGLBL2 ((u8)0x01)
@@ -46,6 +49,9 @@
namespace i2c::wdt {
static LockableMutex g_wdt_mutex;
static bool isWdtEnabled = false;
static Result update_bits(u8 reg, u8 mask, u8 val) {
u8 cur;
Result rc;
@@ -58,7 +64,11 @@ namespace i2c::wdt {
return I2cSet_U8(I2cDevice_Max77620Pmic, reg, cur);
}
void Arm(max77620_wdt_time_t timeout) {
static void ArmLocked(max77620_wdt_time_t timeout) {
if (isWdtEnabled) {
return;
}
Result rc;
u8 twd;
@@ -91,16 +101,48 @@ namespace i2c::wdt {
/* Enable. */
rc = update_bits(MAX77620_REG_CNFGGLBL2, MAX77620_WDTEN, MAX77620_WDTEN);
ASSERT_RESULT_OK(rc, "update_bits");
isWdtEnabled = true;
}
void Disarm() {
if (!isWdtEnabled) {
return;
}
Result rc = update_bits(MAX77620_REG_CNFGGLBL2, MAX77620_WDTEN, (u8)0x00);
ASSERT_RESULT_OK(rc, "update_bits");
isWdtEnabled = false;
}
void ResetWdtEnableState() {
std::scoped_lock lock{g_wdt_mutex};
isWdtEnabled = false;
}
void Arm(max77620_wdt_time_t timeout) {
std::scoped_lock lock{g_wdt_mutex};
ArmLocked(timeout);
}
bool IsWdtEnabled() {
return isWdtEnabled;
}
void Pet() {
Result rc = update_bits(MAX77620_REG_CNFGGLBL3, MAX77620_WDTC_MASK, MAX77620_WDTC_KICK);
ASSERT_RESULT_OK(rc, "update_bits");
const bool watchdogEnabled = file::config::GetConfigValue(HocClkConfigValue_Watchdog);
std::scoped_lock lock{g_wdt_mutex};
if (watchdogEnabled) {
ArmLocked(i2c::wdt::MAX77620_WDT_2S);
Result rc = update_bits(MAX77620_REG_CNFGGLBL3, MAX77620_WDTC_MASK, MAX77620_WDTC_KICK);
ASSERT_RESULT_OK(rc, "update_bits");
} else {
Disarm();
}
}
} // namespace pwr::wdt
} // namespace i2c::wdt
@@ -15,6 +15,8 @@
*
*/
#pragma once
#include <hocclk.h>
#include <switch.h>
#include "i2cDrv.h"
@@ -34,4 +36,6 @@ namespace i2c::wdt {
void Pet();
} // namespace pwr::wdt
void ResetWdtEnableState();
bool IsWdtEnabled();
} // namespace i2c::wdt
@@ -779,6 +779,8 @@ namespace mgr {
else
gContext.resolutionHeight = 0; // N/A
gContext.isWdtEnabled = i2c::wdt::IsWdtEnabled();
return hasChanged;
}