sim: support upstream Watchdog driver improvement
Fixes: https://github.com/InfiniTimeOrg/InfiniSim/issues/101main
parent
22c02bace6
commit
7613571f96
@ -1,34 +1,68 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
//#include <nrf52_bitfields.h>
|
||||||
|
|
||||||
namespace Pinetime {
|
namespace Pinetime {
|
||||||
namespace Drivers {
|
namespace Drivers {
|
||||||
|
/// Low level driver for the watchdog based on the nRF52832 Product Specification V1.1
|
||||||
|
///
|
||||||
|
/// This driver initializes the timeout and sleep and halt behaviours of the watchdog
|
||||||
|
/// in the method Watchdog::Setup().
|
||||||
|
///
|
||||||
|
/// The watchdog can then be started using the method Watchdog::Start(). At this point, the watchdog runs
|
||||||
|
/// and will reset the MCU if it's not reloaded before the timeout elapses.
|
||||||
|
///
|
||||||
|
/// The watchdog can be reloaded using Watchdog::Kick().
|
||||||
|
///
|
||||||
|
/// The watchdog also provide the cause of the last reset (reset pin, watchdog, soft reset, hard reset,... See
|
||||||
|
/// Watchdog::ResetReasons).
|
||||||
class Watchdog {
|
class Watchdog {
|
||||||
public:
|
public:
|
||||||
enum class ResetReasons { ResetPin, Watchdog, SoftReset, CpuLockup, SystemOff, LpComp, DebugInterface, NFC, HardReset };
|
/// Indicates the reasons of a reset of the MCU
|
||||||
void Setup(uint8_t timeoutSeconds);
|
enum class ResetReason { ResetPin, Watchdog, SoftReset, CpuLockup, SystemOff, LpComp, DebugInterface, NFC, HardReset };
|
||||||
|
|
||||||
|
/// Behaviours of the watchdog when the CPU is sleeping
|
||||||
|
enum class SleepBehaviour : uint8_t {
|
||||||
|
/// Pause watchdog while the CPU is sleeping
|
||||||
|
Pause = 0, // << WDT_CONFIG_SLEEP_Pos,
|
||||||
|
/// Keep the watchdog running while the CPU is sleeping
|
||||||
|
Run = 1 // << WDT_CONFIG_SLEEP_Pos
|
||||||
|
};
|
||||||
|
|
||||||
|
/// Behaviours of the watchdog when the CPU is halted by the debugger
|
||||||
|
enum class HaltBehaviour : uint8_t {
|
||||||
|
/// Pause watchdog while the CPU is halted by the debugger
|
||||||
|
Pause = 0, // << WDT_CONFIG_HALT_Pos,
|
||||||
|
/// Keep the watchdog running while the CPU is halted by the debugger
|
||||||
|
Run = 1 // << WDT_CONFIG_HALT_Pos
|
||||||
|
};
|
||||||
|
|
||||||
|
/// Configures the watchdog with a specific timeout, behaviour when sleeping and when halted by the debugger
|
||||||
|
///
|
||||||
|
/// @param sleepBehaviour Configure the watchdog to either be paused, or kept running, while the CPU is sleeping
|
||||||
|
/// @param haltBehaviour Configure the watchdog to either be paused, or kept running, while the CPU is halted by the debugger
|
||||||
|
void Setup(uint8_t timeoutSeconds, SleepBehaviour sleepBehaviour, HaltBehaviour haltBehaviour);
|
||||||
|
|
||||||
|
/// Starts the watchdog. The watchdog will reset the MCU when the timeout period is elapsed unless you call
|
||||||
|
/// Watchdog::Kick before the end of the period
|
||||||
void Start();
|
void Start();
|
||||||
void Kick();
|
|
||||||
ResetReasons ResetReason() const {
|
/// Reloads the watchdog.
|
||||||
|
///
|
||||||
|
/// Ensure that you call this function regularly with a period shorter
|
||||||
|
/// than the timeout period to prevent the watchdog from resetting the MCU.
|
||||||
|
void Reload();
|
||||||
|
|
||||||
|
/// Returns the reason of the last reset
|
||||||
|
ResetReason GetResetReason() const {
|
||||||
return resetReason;
|
return resetReason;
|
||||||
}
|
}
|
||||||
static const char* ResetReasonToString(ResetReasons reason);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ResetReasons resetReason;
|
ResetReason resetReason;
|
||||||
ResetReasons ActualResetReason() const;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class WatchdogView {
|
/// Converts a reset reason to a human readable string
|
||||||
public:
|
const char* ResetReasonToString(Watchdog::ResetReason reason);
|
||||||
WatchdogView(const Watchdog& watchdog) : watchdog {watchdog} {
|
|
||||||
}
|
|
||||||
Watchdog::ResetReasons ResetReason() const {
|
|
||||||
return watchdog.ResetReason();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
const Watchdog& watchdog;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue