Watchdog timer for stm32f10x

Dependents:   F103-Web-Server

Fork of Watchdog by David Smart

Committer:
olympux
Date:
Sat Nov 15 11:44:16 2014 +0000
Revision:
5:38379e44fae3
Parent:
3:5959d3d35221
Compatible with STM32F10x

Who changed what in which revision?

UserRevisionLine numberNew contents of line
WiredHome 2:2873f068f325 1 /// @file Watchdog.cpp provides the interface to the Watchdog module
WiredHome 2:2873f068f325 2 ///
WiredHome 2:2873f068f325 3 /// This provides basic Watchdog service for the mbed. You can configure
WiredHome 2:2873f068f325 4 /// various timeout intervals that meet your system needs. Additionally,
WiredHome 2:2873f068f325 5 /// it is possible to identify if the Watchdog was the cause of any
WiredHome 2:2873f068f325 6 /// system restart.
WiredHome 2:2873f068f325 7 ///
WiredHome 2:2873f068f325 8 /// Adapted from Simon's Watchdog code from http://mbed.org/forum/mbed/topic/508/
WiredHome 2:2873f068f325 9 ///
WiredHome 2:2873f068f325 10 /// @note Copyright © 2011 by Smartware Computing, all rights reserved.
WiredHome 2:2873f068f325 11 /// This software may be used to derive new software, as long as
WiredHome 2:2873f068f325 12 /// this copyright statement remains in the source file.
WiredHome 2:2873f068f325 13 /// @author David Smart
WiredHome 2:2873f068f325 14 ///
WiredHome 0:7a316f14da9c 15 #include "mbed.h"
WiredHome 0:7a316f14da9c 16 #include "Watchdog.h"
WiredHome 0:7a316f14da9c 17
WiredHome 0:7a316f14da9c 18
WiredHome 0:7a316f14da9c 19 /// Watchdog gets instantiated at the module level
WiredHome 0:7a316f14da9c 20 Watchdog::Watchdog() {
olympux 5:38379e44fae3 21 wdreset = false;
WiredHome 0:7a316f14da9c 22 }
WiredHome 0:7a316f14da9c 23
WiredHome 0:7a316f14da9c 24 /// Load timeout value in watchdog timer and enable
olympux 5:38379e44fae3 25 void Watchdog::Configure(int pr) {
olympux 5:38379e44fae3 26 // http://www.st.com/web/en/resource/technical/document/reference_manual/CD00171190.pdf
olympux 5:38379e44fae3 27 IWDG->KR = 0x5555; // enable write to PR, RLR
olympux 5:38379e44fae3 28 IWDG->PR = pr; // Init prescaler, page 486 Reference Manual
olympux 5:38379e44fae3 29 IWDG->RLR = 0xFFF; // Init RLR
olympux 5:38379e44fae3 30 IWDG->KR = 0xAAAA; // Reload the watchdog
olympux 5:38379e44fae3 31 IWDG->KR = 0xCCCC;
WiredHome 0:7a316f14da9c 32 }
WiredHome 0:7a316f14da9c 33
WiredHome 0:7a316f14da9c 34 /// "Service", "kick" or "feed" the dog - reset the watchdog timer
WiredHome 0:7a316f14da9c 35 /// by writing this required bit pattern
WiredHome 0:7a316f14da9c 36 void Watchdog::Service() {
olympux 5:38379e44fae3 37 IWDG->KR = 0xAAAA;
WiredHome 0:7a316f14da9c 38 }
WiredHome 0:7a316f14da9c 39
WiredHome 0:7a316f14da9c 40 /// get the flag to indicate if the watchdog causes the reset
WiredHome 0:7a316f14da9c 41 bool Watchdog::WatchdogCausedReset() {
olympux 5:38379e44fae3 42 if (RCC->CSR & (1<<29)) {
olympux 5:38379e44fae3 43 wdreset = true;
olympux 5:38379e44fae3 44 RCC->CSR |= (1<<24); // clear reset flag
olympux 5:38379e44fae3 45 }
WiredHome 0:7a316f14da9c 46 return wdreset;
WiredHome 0:7a316f14da9c 47 }
WiredHome 0:7a316f14da9c 48
WiredHome 0:7a316f14da9c 49