add watchcat
This commit is contained in:
1 parent
eae39374a8
commit
e9d01a0878
8 files changed
+69
-12
No files matched your search
@@ -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
|
||||
Reference in new issue
Block a user