Add C++ independent watchdog driver
This commit is contained in:
parent
cca848eec0
commit
258c882c8c
41
platform/stm32g0xx/IndependentWatchdog.cc
Normal file
41
platform/stm32g0xx/IndependentWatchdog.cc
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
#include "platform/stm32g0xx/IndependentWatchdog.h"
|
||||||
|
|
||||||
|
using namespace perinet::platform::stm32g0xx;
|
||||||
|
|
||||||
|
IndependentWatchdog::IndependentWatchdog(uint32_t window, uint32_t reload)
|
||||||
|
: window(window)
|
||||||
|
, reload(reload)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void IndependentWatchdog::enable()
|
||||||
|
{
|
||||||
|
// Enable IWDG. LSI is turned on automatically
|
||||||
|
IWDG->KR = IWDG_KEY_ENABLE;
|
||||||
|
|
||||||
|
// Enable write access to IWDG_PR, IWDG_RLR and IWDG_WINR registers by writing 0x5555 in KR
|
||||||
|
IWDG->KR = IWDG_KEY_WRITE_ACCESS_ENABLE;
|
||||||
|
|
||||||
|
// Write to IWDG registers the Prescaler & Reload values to work with
|
||||||
|
IWDG->PR = IWDG_PRESCALER_4;
|
||||||
|
IWDG->RLR = this->reload;
|
||||||
|
|
||||||
|
// If window parameter is different than current value, modify window register
|
||||||
|
if (IWDG->WINR != this->window) {
|
||||||
|
// Write to IWDG WINR the IWDG_Window value to compare with. In any case,
|
||||||
|
// even if window feature is disabled, Watchdog will be reloaded by writing
|
||||||
|
// windows register
|
||||||
|
IWDG->WINR = this->window;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Reload IWDG counter with value defined in the reload register
|
||||||
|
IWDG->KR = IWDG_KEY_RELOAD;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void IndependentWatchdog::trigger()
|
||||||
|
{
|
||||||
|
// Reload IWDG counter with value defined in the reload register
|
||||||
|
IWDG->KR = IWDG_KEY_RELOAD;
|
||||||
|
}
|
24
platform/stm32g0xx/IndependentWatchdog.h
Normal file
24
platform/stm32g0xx/IndependentWatchdog.h
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#ifndef __PLATFORM_STM32G0XX_INDEPENDENTWATCHDOG_H__
|
||||||
|
#define __PLATFORM_STM32G0XX_INDEPENDENTWATCHDOG_H__
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
#include "stm32g0xx.h"
|
||||||
|
|
||||||
|
namespace perinet::platform::stm32g0xx {
|
||||||
|
|
||||||
|
class IndependentWatchdog
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
IndependentWatchdog(uint32_t, uint32_t);
|
||||||
|
void enable();
|
||||||
|
void trigger();
|
||||||
|
|
||||||
|
private:
|
||||||
|
uint32_t window;
|
||||||
|
uint32_t reload;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue
Block a user