LPC11C24: Watchdog

This commit is contained in:
Pavel Kirienko
2014-08-02 13:46:45 +04:00
parent 1a0caeb723
commit 16a555e571
4 changed files with 114 additions and 2 deletions
@@ -0,0 +1,86 @@
/*
* @brief LPC11xx WWDT chip driver
*
* @note
* Copyright(C) NXP Semiconductors, 2012
* All rights reserved.
*
* @par
* Software that is described herein is for illustrative purposes only
* which provides customers with programming information regarding the
* LPC products. This software is supplied "AS IS" without any warranties of
* any kind, and NXP Semiconductors and its licensor disclaim any and
* all warranties, express or implied, including all implied warranties of
* merchantability, fitness for a particular purpose and non-infringement of
* intellectual property rights. NXP Semiconductors assumes no responsibility
* or liability for the use of the software, conveys no license or rights under any
* patent, copyright, mask work right, or any other intellectual property rights in
* or to any products. NXP Semiconductors reserves the right to make changes
* in the software without notification. NXP Semiconductors also makes no
* representation or warranty that such application will be suitable for the
* specified use without further testing or modification.
*
* @par
* Permission to use, copy, modify, and distribute this software and its
* documentation is hereby granted, under NXP Semiconductors' and its
* licensor's relevant copyrights in the software, without fee, provided that it
* is used in conjunction with NXP Semiconductors microcontrollers. This
* copyright, permission, and disclaimer notice must appear in all copies of
* this code.
*/
/*
* Compiler warning fixes
* Pavel Kirienko, 2014 <pavel.kirienko@gmail.com>
*/
#include "chip.h"
/*****************************************************************************
* Private types/enumerations/variables
****************************************************************************/
/*****************************************************************************
* Public types/enumerations/variables
****************************************************************************/
/*****************************************************************************
* Private functions
****************************************************************************/
/*****************************************************************************
* Public functions
****************************************************************************/
/* Initialize the Watchdog timer */
void Chip_WWDT_Init(LPC_WWDT_T *pWWDT)
{
Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_WDT);
/* Disable watchdog */
pWWDT->MOD = 0;
pWWDT->TC = 0xFF;
#if defined(WATCHDOG_WINDOW_SUPPORT)
pWWDT->WARNINT = 0xFFFF;
pWWDT->WINDOW = 0xFFFFFF;
#endif
}
/* Shutdown the Watchdog timer */
void Chip_WWDT_DeInit(LPC_WWDT_T *pWWDT)
{
(void)pWWDT;
Chip_Clock_DisablePeriphClock(SYSCTL_CLOCK_WDT);
}
/* Clear WWDT interrupt status flags */
void Chip_WWDT_ClearStatusFlag(LPC_WWDT_T *pWWDT, uint32_t status)
{
if (status & WWDT_WDMOD_WDTOF) {
pWWDT->MOD &= (~WWDT_WDMOD_WDTOF) & WWDT_WDMOD_BITMASK;
}
if (status & WWDT_WDMOD_WDINT) {
pWWDT->MOD |= WWDT_WDMOD_WDINT;
}
}
@@ -46,11 +46,15 @@ __attribute__((noinline))
#endif
void init()
{
board::resetWatchdog();
if (uavcan_lpc11c24::CanDriver::instance().init(1000000) < 0)
{
die();
}
board::resetWatchdog();
getNode().setNodeID(72);
getNode().setName("org.uavcan.lpc11c24_test");
@@ -67,10 +71,14 @@ void init()
std::copy(std::begin(uid), std::end(uid), std::begin(hwver.unique_id));
getNode().setHardwareVersion(hwver);
board::resetWatchdog();
while (getNode().start() < 0)
{
}
board::resetWatchdog();
while (getTimeSyncSlave().start() < 0)
{
}
@@ -79,6 +87,8 @@ void init()
{
}
getLogger().setLevel(uavcan::protocol::debug::LogLevel::DEBUG);
board::resetWatchdog();
}
void reverse(char* s)
@@ -145,5 +155,7 @@ int main()
logmsg.text = buf;
(void)getLogger().log(logmsg);
}
board::resetWatchdog();
}
}
@@ -57,8 +57,13 @@ void sysctlPowerUp(unsigned long powerupmask)
void initWatchdog()
{
sysctlPowerUp(SYSCTL_POWERDOWN_WDTOSC_PD); // Enable watchdog oscillator
// TODO: init watchdog
Chip_WWDT_Init(LPC_WWDT); // Initialize watchdog
sysctlPowerUp(SYSCTL_POWERDOWN_WDTOSC_PD); // Enable watchdog oscillator
Chip_Clock_SetWDTOSC(WDTLFO_OSC_0_60, 4); // WDT osc rate 0.6 MHz / 4 = 150 kHz
Chip_Clock_SetWDTClockSource(SYSCTL_WDTCLKSRC_WDTOSC, 1); // Clocking watchdog from its osc, div rate 1
Chip_WWDT_SetTimeOut(LPC_WWDT, 37500); // 1 sec (hardcoded to reduce code size)
Chip_WWDT_SetOption(LPC_WWDT, WWDT_WDMOD_WDRESET); // Mode: reset on timeout
Chip_WWDT_Start(LPC_WWDT); // Go
}
void initClock()
@@ -112,6 +117,8 @@ void init()
initWatchdog();
initClock();
initGpio();
resetWatchdog();
}
} // namespace
@@ -137,6 +144,11 @@ void setErrorLed(bool state)
LPC_GPIO[ErrorLedPort].DATA[1 << ErrorLedPin] = static_cast<unsigned long>(!state) << ErrorLedPin;
}
void resetWatchdog()
{
Chip_WWDT_Feed(LPC_WWDT);
}
} // namespace board
extern "C"
@@ -14,4 +14,6 @@ void readUniqueID(uint8_t out_uid[UniqueIDSize]);
void setStatusLed(bool state);
void setErrorLed(bool state);
void resetWatchdog();
}