Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Features/driver/iwdg #21

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
19 changes: 19 additions & 0 deletions Drivers/IWDG_driver/Inc/independent_watchdog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

#ifndef INDEPENDENT_WATCHDOG_H
#define INDEPENDENT_WATCHDOG_H

#include <stdint.h>
#include "main.h"

class IndependentWatchdog : public Watchdog {
private:
IWDG_HandleTypeDef* watchdog;

public:
IndependentWatchdog(IWDG_HandleTypeDef* watchdog);
bool refreshWatchdog() override ;
};


#endif /* SRC_DRIVERS_INDEPENDENTWATCHDOG_H_ */

11 changes: 11 additions & 0 deletions Drivers/IWDG_driver/Inc/watchdog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef WATCHDOG_H_
#define WATCHDOG_H_

class Watchdog {
public:
virtual bool refreshWatchdog() = 0;
};

#endif


27 changes: 27 additions & 0 deletions Drivers/IWDG_driver/Src/independent_watchdog.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "independent_watchdog.h"
#include "main.h"

/**
* @brief Borrow the configuration of an already existing watchdog and set it
* to the prescaler and Reload values.
*
*/
IndependentWatchdog::IndependentWatchdog(IWDG_HandleTypeDef *watchdog) {
this->watchdog = watchdog;
IWDG_InitTypeDef initDef = watchdog->Init;
this->iwdg_prescaler = initDef.Prescaler;
this->iwdg_reload = initDef.Reload;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iwdg_prescaler and iwdf_reload dont exist anymore (and arent used) so probably remove lines 11,12 and 13 I think

}


/**
* @brief Refreshes the watchdog that is a member variable of the class
* @returns true on success, false on failure
*/

bool IndependentWatchdog::refreshWatchdog() {
if (this->watchdog == nullptr) {
return false;
}
return (HAL_IWDG_Refresh(watchdog) == HAL_OK);
}