SAM4S Xplained Pro: Watchdog timer support for Bob Doison

This commit is contained in:
Gregory Nutt
2014-04-21 19:19:56 -06:00
parent a8cb0ad8f4
commit 61e80ae998
7 changed files with 496 additions and 103 deletions
+3
View File
@@ -7237,3 +7237,6 @@
Bob Doison (2014-4-21).
* arch/arm/src/sam34/sam_wdt.c/.h: Add watchdog driver. From Bob
Doison (2014-4-21).
* nuttx/configs/sam4s-xplained-pro: Add board-specific watchdog
timer support. From Bob Doison (2014-4-21).
+12 -9
View File
@@ -1,9 +1,12 @@
- implement flash driver
- see arch/arm/src/stm32/stm32_flash.c and related
- both banks could be mapped with care taken not to erase the active code.
- perhaps the MPU could block code corruption?
- once implemented, the free() cmd replacement can show flash information.
- implement flash driver
- see arch/arm/src/stm32/stm32_flash.c and related
- both banks could be mapped with care taken not to erase the active code.
- perhaps the MPU could block code corruption?
- once implemented, the free() cmd replacement can show flash information.
- Seen crashes when running serial ports below 921600
- USB serial not quite stable when pushing lots of data
- UARTs don't use DMA. We may need this for high baudrates.
- Inbound hardware flow control requires dma.
+4 -2
View File
@@ -54,8 +54,8 @@
************************************************************************************/
/* Clocking *************************************************************************/
/* After power-on reset, the sam3u device is running on a 4MHz internal RC. These
* definitions will configure clocking with MCK = 48MHz, PLLA = 96, and CPU=120MHz.
/* After power-on reset, the sam4s device is running on a 4MHz internal RC. These
* definitions will configure clocking with MCK = 120MHz, PLLA = 240, and CPU=120MHz.
*/
/* Main oscillator register settings */
@@ -69,6 +69,8 @@
* PLLdiv: 1 (bypassed)
* Fpll: (12MHz * 20) / 1 = 240MHz
*/
#define BOARD_32KOSC_FREQUENCY (32768)
#define BOARD_SLCK_FREQUENCY (BOARD_32KOSC_FREQUENCY)
#define BOARD_MAINOSC_FREQUENCY (12000000)
#define BOARD_CKGR_PLLAR_MUL (19 << PMC_CKGR_PLLAR_MUL_SHIFT)
File diff suppressed because it is too large Load Diff
+5
View File
@@ -68,6 +68,11 @@ ifeq ($(CONFIG_ARCH_BUTTONS),y)
CSRCS += sam_buttons.c
endif
ifeq ($(CONFIG_SAM34_WDT),y)
CSRCS += sam_wdt.c
endif
COBJS = $(CSRCS:.c=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS)
+4 -2
View File
@@ -98,11 +98,10 @@ int nsh_archinitialize(void)
int ret;
#endif
message("initializing...\n");
#ifdef HAVE_HSMCI
/* Initialize the HSMCI driver */
message("initializing HSMCI\n");
ret = sam_hsmci_initialize();
if (ret < 0)
{
@@ -114,6 +113,7 @@ int nsh_archinitialize(void)
#ifdef HAVE_PROC
/* mount the proc filesystem */
message("Mounting procfs to /proc\n");
ret = mount(NULL, "/proc", "procfs", 0, NULL);
if (ret < 0)
{
@@ -125,6 +125,7 @@ int nsh_archinitialize(void)
#ifdef HAVE_USBMONITOR
/* Start the USB Monitor */
message("Starting USB Monitor\n");
ret = usbmonitor_start(0, NULL);
if (ret != OK)
{
@@ -134,6 +135,7 @@ int nsh_archinitialize(void)
#endif
#warning "add automount config...."
message("Mounting /dev/mmcsd0 to /fat\n");
ret = mount("/dev/mmcsd0", "/fat", "vfat", 0, NULL);
if (ret < 0)
{
+237
View File
@@ -0,0 +1,237 @@
/************************************************************************************
* configs/sam4s-xplained-pro/src/up_watchdog.c
*
* Copyright (C) 2014 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* 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 NuttX 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 OWNER 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.
*
************************************************************************************/
/************************************************************************************
* Included Files
************************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <errno.h>
#include <debug.h>
#include <sched.h>
#include <stdio.h>
#include <fcntl.h>
#include <nuttx/watchdog.h>
#include <arch/board/board.h>
#include <nuttx/kthread.h>
#include "sam_wdt.h"
#include <nuttx/clock.h>
#ifdef CONFIG_WATCHDOG
/************************************************************************************
* Definitions
************************************************************************************/
/* Configuration *******************************************************************/
/* Wathdog hardware should be enabled */
#if !defined(CONFIG_SAM34_WDT)
# warning "CONFIG_SAM34_WDT must be defined"
#endif
/* Select the path to the registered watchdog timer device */
#ifndef CONFIG_WATCHDOG_DEVPATH
# ifdef CONFIG_EXAMPLES_WATCHDOG_DEVPATH
# define CONFIG_WATCHDOG_DEVPATH CONFIG_EXAMPLES_WATCHDOG_DEVPATH
# else
# define CONFIG_WATCHDOG_DEVPATH "/dev/watchdog0"
# endif
#endif
/* Debug ***************************************************************************/
/* Non-standard debug that may be enabled just for testing the watchdog timer */
#ifndef CONFIG_DEBUG
# undef CONFIG_DEBUG_WATCHDOG
#endif
#ifdef CONFIG_DEBUG_WATCHDOG
# define wdgdbg dbg
# define wdglldbg lldbg
# ifdef CONFIG_DEBUG_VERBOSE
# define wdgvdbg vdbg
# define wdgllvdbg llvdbg
# else
# define wdgvdbg(x...)
# define wdgllvdbg(x...)
# endif
#else
# define wdgdbg(x...)
# define wdglldbg(x...)
# define wdgvdbg(x...)
# define wdgllvdbg(x...)
#endif
/************************************************************************************
* Private Functions
************************************************************************************/
/************************************************************************************
* Public Functions
************************************************************************************/
/*
Watchdog kicker task
*/
#if defined(CONFIG_WDT_THREAD)
static int wdog_daemon(int argc, char *argv[])
{
int fd;
int ret;
/* Open the watchdog device for reading */
wdgvdbg("Opening.\n");
fd = open(CONFIG_WATCHDOG_DEVPATH, O_RDONLY);
if (fd < 0)
{
wdgdbg("open %s failed: %d\n", CONFIG_WATCHDOG_DEVPATH, errno);
goto errout;
}
/* Start the watchdog timer. */
wdgvdbg("Starting.\n");
ret = ioctl(fd, WDIOC_START, 0);
if (ret < 0)
{
wdgdbg("ioctl(WDIOC_START) failed: %d\n", errno);
goto errout_with_dev;
}
while(1)
{
usleep((CONFIG_WDT_THREAD_INTERVAL)*1000);
wdgvdbg("ping\n");
ret = ioctl(fd, WDIOC_KEEPALIVE, 0);
if (ret < 0)
{
wdgdbg("ioctl(WDIOC_KEEPALIVE) failed: %d\n", errno);
goto errout_with_dev;
}
}
errout_with_dev:
close(fd);
errout:
return ERROR;
}
#endif
/****************************************************************************
* Name: up_wdginitialize()
*
* Description:
* Perform architecture-specific initialization of the Watchdog hardware.
* This interface must be provided by all configurations using
* apps/examples/watchdog
*
****************************************************************************/
int up_wdginitialize(void)
{
#if (defined(CONFIG_SAM34_WDT) && !defined(CONFIG_WDT_DISABLE_ON_RESET))
int fd;
int ret;
/* Initialize tha register the watchdog timer device */
wdgvdbg("Initializing Watchdog driver...\n");
sam_wdtinitialize(CONFIG_WATCHDOG_DEVPATH);
/* Open the watchdog device */
wdgvdbg("Opening.\n");
fd = open(CONFIG_WATCHDOG_DEVPATH, O_RDONLY);
if (fd < 0)
{
wdgdbg("open %s failed: %d\n", CONFIG_WATCHDOG_DEVPATH, errno);
goto errout;
}
/* Set the watchdog timeout */
wdgvdbg("Timeout = %d.\n", CONFIG_WDT_TIMEOUT);
ret = ioctl(fd, WDIOC_SETTIMEOUT, (unsigned long)CONFIG_WDT_TIMEOUT);
if (ret < 0)
{
wdgdbg("ioctl(WDIOC_SETTIMEOUT) failed: %d\n", errno);
goto errout_with_dev;
}
/* Set the watchdog minimum time */
wdgvdbg("MinTime = %d.\n", CONFIG_WDT_MINTIME);
ret = ioctl(fd, WDIOC_MINTIME, (unsigned long)CONFIG_WDT_MINTIME);
if (ret < 0)
{
wdgdbg("ioctl(WDIOC_MINTIME) failed: %d\n", errno);
goto errout_with_dev;
}
/* Start Kicker task */
#if defined(CONFIG_WDT_THREAD)
sched_lock();
int taskid = KERNEL_THREAD(CONFIG_WDT_THREAD_NAME,
CONFIG_WDT_THREAD_PRIORITY,
CONFIG_WDT_THREAD_STACKSIZE,
(main_t)wdog_daemon, (FAR char * const *)NULL);
ASSERT(taskid > 0);
sched_unlock();
#endif
return OK;
errout_with_dev:
close(fd);
errout:
return ERROR;
#else
return -ENODEV;
#endif
}
#endif /* CONFIG_WATCHDOG */