1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
RIOT/cpu/kinetis_common/wdog.c
Johann Fischer 8afc8dfdc3 cpu/kinetis_common: add common startup.c
cpu/kinetis_common/wdog.c: move wdog disable code to initial wdog driver
  cpu/kinetis_common/wdog.c: add COP WDOG
  cpu/kinetis_common/include/wdog.h: add configuration example
  cpu/kinetis_common: add fault handlers
  cpu/kinetis_common: add .ramcode and ISR vector relocation to startup.c
2015-02-15 10:28:13 +01:00

76 lines
1.9 KiB
C

/*
* Copyright (C) 2015 PHYTEC Messtechnik GmbH
* Copyright (C) 2015 Eistec AB
*
* This file is subject to the terms and conditions of the GNU Lesser General
* Public License v2.1. See the file LICENSE in the top level directory for more
* details.
*/
/**
* @ingroup cpu_kinetis_common_wdog
*
* @{
*
* @file
* @brief Low-level WDOG driver implementation
*
* @author Johann Fischer <j.fischer@phytec.de>
* @author Joakim Gebart <joakim.gebart@eistec.se>
*
* @}
*/
#include <stdint.h>
#include "wdog.h"
#include "cpu-conf.h"
#include "periph_conf.h"
#ifndef KINETIS_WDOG_ADVANCED
/**
* Attempts to determine the type of the WDOG,
* using the WDOG_STCTRLH_CLKSRC_MASK field.
*/
#ifdef WDOG_STCTRLH_CLKSRC_MASK
#define KINETIS_WDOG_ADVANCED 1
#endif
#endif
/**
* @brief Disable hardware watchdog.
*
* For advanced WDOG (mostly Kinetis MCUs with Cortex-M4 inside):
* The following unlock sequence must be completed within 256 bus cycles or
* the watchdog will reset the system. The watchdog is enabled by default at
* power on.
*
* The sequence is:
* 1. Write 0xC520 to the unlock register
* 2. Write 0xD928 to the unlock register
*
* Watchdog is now unlocked to allow us to change its settings
*
* 3. Clear the WDOGEN bit of the WDOG_STCTRLH register to completely disable
* the watchdog.
*
* It is now possible to single step through the code without the watchdog
* resetting the system.
*
* TODO: Only disable watchdog on debug builds.
*/
void wdog_disable(void)
{
#if KINETIS_WDOG_ADVANCED
/* unlock and disable the WDOG */
WDOG->UNLOCK = (uint16_t)0xc520;
WDOG->UNLOCK = (uint16_t)0xd928;
WDOG->STCTRLH = (uint16_t)(WDOG_STCTRLH_WAITEN_MASK
| WDOG_STCTRLH_STOPEN_MASK
| WDOG_STCTRLH_ALLOWUPDATE_MASK
| WDOG_STCTRLH_CLKSRC_MASK);
#else
/* disable the COP WDOG */
SIM->COPC = (uint32_t)0x00u;
#endif
}