Commit 1f762269 authored by Martin Horauer's avatar Martin Horauer
Browse files

modified watchdog library

parent f88d705d
TARGET=XMC_4500_RELAX_KIT
TOOLCHAIN=GCC_ARM
ROOT=.
......@@ -17,6 +17,11 @@ and the XMC will reset after 5 seconds. At the next start the XMC checks with
`wd.watchdogCauseReset()` if the watchdog timer was the cause of a reset; in
this case LED1 is turned on.
=========
WARNING: This example relies on a library. In case the folder `XMCWatchdog-Library.git` and the file `XMCWatchdog-Library.git.lib` are missing you may add them by using the command:
`mbed add https://github.com/mbed-Infineon-XMC/XMCWatchdog-Library.git`
=========
== Makefile Usage
[source%nowrap, bash]
......
XMCWatchdog-Library.git @ 632d32df
Subproject commit 632d32df5246cc2d1e835c49dc5c2487d0efb679
https://github.com/mbed-Infineon-XMC/XMCWatchdog-Library/#632d32df5246cc2d1e835c49dc5c2487d0efb679
/* mbed Example Program
* Copyright (c) 2006-2014 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/***************************************************************** Includes **/
#include "xmc_wdt.h"
#include "xmc_scu.h"
#include "Watchdog.h"
#include "mbed.h"
/****************************************************************** Globals **/
XMC_WDT_CONFIG_t wdt_cfg;
/**************************************************************** Functions **/
/** @brief Constructor
*
*/
Watchdog::Watchdog() {
/* Check if watchdog was cause of reset */
if ((XMC_SCU_RESET_GetDeviceResetReason() & XMC_SCU_RESET_REASON_WATCHDOG) != 0){
wdreset = true;
}else{
wdreset = false;
}
/* Clear system reset status */
SCU_RESET->RSTCLR |= SCU_RESET_RSTCLR_RSCLR_Msk;
}
/** @brief Destuctor
*
*/
Watchdog::~Watchdog() {
XMC_WDT_Stop();
}
/** @brief Configure watchdog timer
*
* @param time Time in seconds
*/
void Watchdog::configure(float time) {
/* Use standby clock as watchdog clock source */
XMC_SCU_HIB_EnableHibernateDomain();
XMC_SCU_CLOCK_SetWdtClockSource(XMC_SCU_CLOCK_WDTCLKSRC_STDBY);
XMC_SCU_CLOCK_EnableClock(XMC_SCU_CLOCK_WDT);
wdt_time = time / (1 / (double)XMC_SCU_CLOCK_GetWdtClockFrequency());
/* Configure watchdog */
wdt_cfg.window_lower_bound = 0;
wdt_cfg.window_upper_bound = (uint32_t)wdt_time;
wdt_cfg.service_pulse_width = 255;
XMC_WDT_Init(&wdt_cfg);
XMC_WDT_Start();
}
/** @brief Watchdog service
*
*/
void Watchdog::service() {
XMC_WDT_Service();
}
/** @brief Check if watchdog was cause of reset
*
* @return true if yes, no otherwise
*/
bool Watchdog::watchdogCausedReset() {
return wdreset;
}
/*EOF*/
/** Watchdog class for the XMC MCU family.
*
* Example:
*/
#ifndef WATCHDOG_H
#define WATCHDOG_H
#include "mbed.h"
class Watchdog {
public:
/** Create HelloWorld instance
*/
Watchdog();
/** Delete HelloWorld instance
*/
~Watchdog();
/** Print the text
*
* @param timeout in seconds
*/
void configure(float timeout);
/** Watchdog service
*/
void service();
/** Check if watchdog was cause of reset
*
* @returns
* true watchdog was cause of reset
* fasle watchdog was not cause of reset
*/
bool watchdogCausedReset();
private:
double wdt_time;
bool wdreset;
};
#endif // WATCHDOG_H
/*EOF*/
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment