2013-01-12 23:44:42 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2012, Texas Instruments Incorporated - http://www.ti.com/
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* 3. Neither the name of the copyright holder nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
|
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
|
|
|
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* \addtogroup cc2538
|
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* \defgroup cc2538-wdt cc2538 watchdog timer driver
|
|
|
|
*
|
|
|
|
* Driver for the cc2538 Watchdog Timer
|
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* \file
|
|
|
|
* Implementation of the cc2538 watchdog driver. The peripheral runs in
|
|
|
|
* watchdog mode.
|
|
|
|
*/
|
|
|
|
#include "contiki.h"
|
|
|
|
#include "reg.h"
|
|
|
|
#include "cpu.h"
|
|
|
|
#include "dev/smwdthrosc.h"
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2014-05-18 13:03:27 +02:00
|
|
|
/* Enabled by default */
|
|
|
|
#ifndef WATCHDOG_CONF_ENABLE
|
|
|
|
#define WATCHDOG_CONF_ENABLE 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if WATCHDOG_CONF_ENABLE
|
|
|
|
#define WATCHDOG_ENABLE SMWDTHROSC_WDCTL_EN
|
|
|
|
#else
|
|
|
|
#define WATCHDOG_ENABLE 0
|
|
|
|
#endif
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2013-01-12 23:44:42 +01:00
|
|
|
/** \brief Initialisation function for the WDT. Currently simply explicitly
|
|
|
|
* sets the WDT interval to max interval */
|
|
|
|
void
|
|
|
|
watchdog_init(void)
|
|
|
|
{
|
|
|
|
/* Max interval, don't enable yet */
|
|
|
|
REG(SMWDTHROSC_WDCTL) = 0;
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2014-05-18 13:03:27 +02:00
|
|
|
/** \brief Starts the WDT in watchdog mode if enabled by user configuration,
|
|
|
|
* maximum interval */
|
2013-01-12 23:44:42 +01:00
|
|
|
void
|
|
|
|
watchdog_start(void)
|
|
|
|
{
|
2014-05-18 13:03:27 +02:00
|
|
|
/* Max interval (32768), watchdog mode, enable if configured to do so */
|
|
|
|
REG(SMWDTHROSC_WDCTL) = WATCHDOG_ENABLE;
|
2013-01-12 23:44:42 +01:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2014-05-18 13:03:27 +02:00
|
|
|
/**
|
|
|
|
* \brief Writes the WDT clear sequence.
|
|
|
|
*
|
|
|
|
* Due to how the SMWDTHROSC_WDCTL works, it is OK to simply write these bits
|
|
|
|
* rather than use RMW operations.
|
|
|
|
*/
|
2013-01-12 23:44:42 +01:00
|
|
|
void
|
|
|
|
watchdog_periodic(void)
|
|
|
|
{
|
|
|
|
REG(SMWDTHROSC_WDCTL) = (SMWDTHROSC_WDCTL_CLR_3 | SMWDTHROSC_WDCTL_CLR_1);
|
|
|
|
REG(SMWDTHROSC_WDCTL) = (SMWDTHROSC_WDCTL_CLR_2 | SMWDTHROSC_WDCTL_CLR_0);
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
/** \brief In watchdog mode, the WDT can not be stopped. This function is
|
|
|
|
* defined here to satisfy API requirements.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
watchdog_stop(void)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2014-05-18 13:03:27 +02:00
|
|
|
/** \brief Keeps control until the WDT throws a reset signal. Starts the WDT
|
|
|
|
* if not already started. */
|
2013-01-12 23:44:42 +01:00
|
|
|
void
|
|
|
|
watchdog_reboot(void)
|
|
|
|
{
|
|
|
|
INTERRUPTS_DISABLE();
|
2014-05-18 13:03:27 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If the WDT is not started, set minimum interval and start
|
|
|
|
* If the WDT is started, this will have no effect
|
|
|
|
*/
|
|
|
|
REG(SMWDTHROSC_WDCTL) = SMWDTHROSC_WDCTL_INT | SMWDTHROSC_WDCTL_EN;
|
|
|
|
|
2013-01-12 23:44:42 +01:00
|
|
|
while(1);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
* @}
|
|
|
|
*/
|