Skip to content

Commit

Permalink
Merge pull request #28 from dominicgs/reset
Browse files Browse the repository at this point in the history
LPC43xx: add watchdog reset
  • Loading branch information
mossmann committed Jan 27, 2017
2 parents e180b2a + d3d6f3e commit c9f40aa
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
9 changes: 9 additions & 0 deletions include/libopencm3/lpc43xx/wwdt.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,18 @@ extern "C" {

/* Watchdog mode register */
#define WWDT_MOD MMIO32(WWDT_BASE + 0x000)
#define WWDT_MOD_WDEN (1<<0)
#define WWDT_MOD_WDRESET (1<<1)
#define WWDT_MOD_WDTOF (1<<2)
#define WWDT_MOD_WDINT (1<<3)
#define WWDT_MOD_WDPROTECT (1<<4)

/* Watchdog timer constant register */
#define WWDT_TC MMIO32(WWDT_BASE + 0x004)

/* Watchdog feed sequence register */
#define WWDT_FEED MMIO32(WWDT_BASE + 0x008)
#define WWDT_FEED_SEQUENCE WWDT_FEED = 0xAA; WWDT_FEED = 0x55

/* Watchdog timer value register */
#define WWDT_TV MMIO32(WWDT_BASE + 0x00C)
Expand All @@ -66,6 +72,9 @@ extern "C" {

/**@}*/

/* Reset LPC4330 in timeout*4 clock cycles (min 256, max 2^24) */
void wwdt_reset(uint32_t timeout);

#ifdef __cplusplus
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion lib/lpc43xx/m4/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ CFLAGS = -O2 -g3 \
ARFLAGS = rcs

# LPC43xx common files for M4 / M0
OBJ_LPC43XX = gpio.o scu.o i2c.o ssp.o uart.o timer.o
OBJ_LPC43XX = gpio.o scu.o i2c.o ssp.o uart.o timer.o wwdt.o

#LPC43xx M4 specific file + Generic LPC43xx M4/M0 files
OBJS = $(OBJ_LPC43XX) ipc.o
Expand Down
27 changes: 27 additions & 0 deletions lib/lpc43xx/wwdt.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* This file is part of the libopencm3 project.
*
* Copyright (C) 2016 Dominic Spill <dominicgs@gmail.com>
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*/

#include <libopencm3/lpc43xx/wwdt.h>

void wwdt_reset(uint32_t timeout) {
WWDT_MOD = WWDT_MOD_WDEN | WWDT_MOD_WDRESET;
timeout &= 0xFFFFFF;
WWDT_TC = timeout;
WWDT_FEED_SEQUENCE;
}

0 comments on commit c9f40aa

Please sign in to comment.