From 16a555e571f44dc62f0236260557aa7ed0e7cff3 Mon Sep 17 00:00:00 2001 From: Pavel Kirienko Date: Sat, 2 Aug 2014 13:46:45 +0400 Subject: [PATCH] LPC11C24: Watchdog --- .../lpc_chip_11cxx_lib/src/wwdt_11xx.c | 86 +++++++++++++++++++ .../test_olimex_lpc_p11c24/src/main.cpp | 12 +++ .../test_olimex_lpc_p11c24/src/sys/board.cpp | 16 +++- .../test_olimex_lpc_p11c24/src/sys/board.hpp | 2 + 4 files changed, 114 insertions(+), 2 deletions(-) create mode 100755 libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/src/wwdt_11xx.c diff --git a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/src/wwdt_11xx.c b/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/src/wwdt_11xx.c new file mode 100755 index 0000000000..c78656d2ea --- /dev/null +++ b/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/src/wwdt_11xx.c @@ -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 + */ + +#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; + } +} diff --git a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/src/main.cpp b/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/src/main.cpp index d379a5b816..68c7cb68af 100644 --- a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/src/main.cpp +++ b/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/src/main.cpp @@ -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(); } } diff --git a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/src/sys/board.cpp b/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/src/sys/board.cpp index 223c593d7e..610d923dc9 100644 --- a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/src/sys/board.cpp +++ b/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/src/sys/board.cpp @@ -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(!state) << ErrorLedPin; } +void resetWatchdog() +{ + Chip_WWDT_Feed(LPC_WWDT); +} + } // namespace board extern "C" diff --git a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/src/sys/board.hpp b/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/src/sys/board.hpp index eb0f5ea04b..0882f4b60e 100644 --- a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/src/sys/board.hpp +++ b/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/src/sys/board.hpp @@ -14,4 +14,6 @@ void readUniqueID(uint8_t out_uid[UniqueIDSize]); void setStatusLed(bool state); void setErrorLed(bool state); +void resetWatchdog(); + }