Skip to content

Commit cc5ca9e

Browse files
committed
Watchdog Timer: basic support
1 parent 149f78b commit cc5ca9e

File tree

4 files changed

+129
-0
lines changed

4 files changed

+129
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
Watchdog Refresh
3+
4+
This sketch shows how to enable the watchdog and
5+
refresh the timer to avoid resets
6+
7+
Circuit:
8+
- Portenta C33
9+
*/
10+
11+
#include <WDT.h>
12+
13+
void setup() {
14+
Serial.begin(9600);
15+
while (!Serial);
16+
17+
wdt_cfg_t p_cfg;
18+
19+
p_cfg.timeout = WDT_TIMEOUT_16384;
20+
p_cfg.clock_division = WDT_CLOCK_DIVISION_8192;
21+
p_cfg.window_start = WDT_WINDOW_START_100;
22+
p_cfg.window_end = WDT_WINDOW_END_0;
23+
p_cfg.reset_control = WDT_RESET_CONTROL_RESET;
24+
p_cfg.stop_control = WDT_STOP_CONTROL_ENABLE;
25+
26+
WDT.begin(p_cfg);
27+
}
28+
29+
void loop() {
30+
Serial.println("Still Alive...");
31+
// Comment the line above to stop refreshing the watchdog
32+
WDT.refresh();
33+
delay(1000);
34+
}

libraries/WDT/library.properties

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name=WDT
2+
version=0.0.1
3+
author=Arduino
4+
maintainer=Arduino <info@arduino.cc>
5+
sentence=Watchdog timer library for Renesas RA boards
6+
paragraph=
7+
category=Timing
8+
url=
9+
architectures=renesas

libraries/WDT/src/WDT.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
WDT.cpp
3+
Copyright (c) 2023 Arduino SA. All right reserved.
4+
5+
This library is free software; you can redistribute it and/or
6+
modify it under the terms of the GNU Lesser General Public
7+
License as published by the Free Software Foundation; either
8+
version 2.1 of the License, or (at your option) any later version.
9+
10+
This library is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
Lesser General Public License for more details.
14+
15+
You should have received a copy of the GNU Lesser General Public
16+
License along with this library; if not, write to the Free Software
17+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
20+
#include "WDT.h"
21+
22+
WDTimer::WDTimer() { }
23+
WDTimer::~WDTimer() { }
24+
25+
int WDTimer::begin(wdt_cfg_t config)
26+
{
27+
if(_is_initialized) {
28+
return FSP_SUCCESS;
29+
}
30+
31+
fsp_err_t err = R_WDT_Open(&_p_ctrl, &config);
32+
if(FSP_SUCCESS == err ) {
33+
R_WDT_Refresh(&_p_ctrl);
34+
_is_initialized = true;
35+
}
36+
37+
return (int)err;
38+
}
39+
40+
void WDTimer::refresh()
41+
{
42+
R_WDT_Refresh(&_p_ctrl);
43+
}
44+
45+
WDTimer WDT;

libraries/WDT/src/WDT.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
WDT.h
3+
Copyright (c) 2023 Arduino SA. All right reserved.
4+
5+
This library is free software; you can redistribute it and/or
6+
modify it under the terms of the GNU Lesser General Public
7+
License as published by the Free Software Foundation; either
8+
version 2.1 of the License, or (at your option) any later version.
9+
10+
This library is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
Lesser General Public License for more details.
14+
15+
You should have received a copy of the GNU Lesser General Public
16+
License along with this library; if not, write to the Free Software
17+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
20+
#ifndef _WDTIMER_H_
21+
#define _WDTIMER_H_
22+
23+
#include "r_wdt.h"
24+
25+
class WDTimer {
26+
private:
27+
bool _is_initialized;
28+
wdt_instance_ctrl_t _p_ctrl;
29+
30+
public:
31+
WDTimer();
32+
~WDTimer();
33+
34+
int begin(wdt_cfg_t config);
35+
36+
void refresh();
37+
};
38+
39+
extern WDTimer WDT;
40+
41+
#endif

0 commit comments

Comments
 (0)