Skip to content

Commit 820da7e

Browse files
authored
Merge pull request #666 from ckormanyos/tune_avr_wdg
Tune up and test again AVR watchdog
2 parents feec9af + c9affb2 commit 820da7e

1 file changed

Lines changed: 15 additions & 6 deletions

File tree

ref_app/src/mcal/avr/mcal_wdg.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
///////////////////////////////////////////////////////////////////////////////
2-
// Copyright Christopher Kormanyos 2007 - 2024.
2+
// Copyright Christopher Kormanyos 2007 - 2025.
33
// Distributed under the Boost Software License,
44
// Version 1.0. (See accompanying file LICENSE_1_0.txt
55
// or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -29,19 +29,28 @@ auto mcal::wdg::init(const config_type*) -> void
2929
// Reset the watchdog timer.
3030
asm volatile("wdr");
3131

32-
// Set the watchdog timer period and activate the watchdog timer.
32+
// Start timed sequence in order to set the watchdog
33+
// timer period and activate the watchdog timer.
3334
mcal::reg::reg_access_static<std::uint8_t,
3435
std::uint8_t,
3536
mcal::reg::wdtcsr,
3637
std::uint8_t(0x18U)>::reg_set();
3738

38-
// See Chapter 11.9.2, Table 11-2: Watchdog Timer Prescale Select.
39-
// Select WDP3:WDP0 in WDTCSR to binary 0b0111, resulting
40-
// in a watchdog period of approximately 2s.
39+
// In "Atmel-7810-Automotive-Microcontrollers-ATmega328P_Datasheet.pdf",
40+
// see Chapter 10.9.2, Table 10-3: Watchdog Timer Prescale Select.
41+
// Set WDP3 (bit 5) and clear WDP2:WDP0 (bits 0, 1 and 2) in WDTCSR
42+
// (i.e., set to hex 0x20). This results in a watchdog period
43+
// of approximately 4s.
4144
mcal::reg::reg_access_static<std::uint8_t,
4245
std::uint8_t,
4346
mcal::reg::wdtcsr,
44-
std::uint8_t(0x08U) | std::uint8_t(0x07U)>::reg_set();
47+
std::uint8_t(0x20U)>::reg_set();
48+
49+
// Set WDRF in the MCU status register.
50+
mcal::reg::reg_access_static<std::uint8_t,
51+
std::uint8_t,
52+
mcal::reg::mcusr,
53+
std::uint8_t(3U)>::bit_set();
4554
}
4655

4756
auto mcal::wdg::secure::trigger() -> void

0 commit comments

Comments
 (0)