summaryrefslogtreecommitdiff
path: root/ecos/packages/io/watchdog
diff options
context:
space:
mode:
authorMichael Gielda <mgielda@antmicro.com>2014-04-03 14:53:04 +0200
committerMichael Gielda <mgielda@antmicro.com>2014-04-03 14:53:04 +0200
commitae1e4e08a1005a0c487f03ba189d7536e7fdcba6 (patch)
treef1c296f8a966a9a39876b0e98e16d9c5da1776dd /ecos/packages/io/watchdog
parentf157da5337118d3c5cd464266796de4262ac9dbd (diff)
Added the OS files
Diffstat (limited to 'ecos/packages/io/watchdog')
-rw-r--r--ecos/packages/io/watchdog/current/ChangeLog309
-rw-r--r--ecos/packages/io/watchdog/current/cdl/watchdog.cdl176
-rw-r--r--ecos/packages/io/watchdog/current/include/watchdog.h58
-rw-r--r--ecos/packages/io/watchdog/current/include/watchdog.hxx167
-rw-r--r--ecos/packages/io/watchdog/current/src/emulate.cxx148
-rw-r--r--ecos/packages/io/watchdog/current/src/watchdog.cxx193
-rw-r--r--ecos/packages/io/watchdog/current/tests/watchdog.cxx237
-rw-r--r--ecos/packages/io/watchdog/current/tests/watchdog2.cxx219
-rw-r--r--ecos/packages/io/watchdog/current/tests/watchdog_reset.cxx183
9 files changed, 1690 insertions, 0 deletions
diff --git a/ecos/packages/io/watchdog/current/ChangeLog b/ecos/packages/io/watchdog/current/ChangeLog
new file mode 100644
index 0000000..c86b24d
--- /dev/null
+++ b/ecos/packages/io/watchdog/current/ChangeLog
@@ -0,0 +1,309 @@
+2009-04-28 John Dallaway <john@dallaway.org.uk>
+
+ * cdl/watchdog.cdl: Move the CYGINT_WATCHDOG_IMPLEMENTATIONS
+ constraint to the interface declaration itself to ensure that the
+ eCos Configuration Tool presents implementators as radio buttons.
+
+2009-02-04 Bart Veer <bartv@ecoscentric.com>
+
+ * src/watchdog.cxx: switch to CYG_INIT_DEV_WATCHDOG init priority.
+
+2003-11-05 Bob Koninckx <bob.koninckx@mech.kuleuven.ac.be>
+
+ * src/watchdog.cxx:
+ * include/watchdog.hxx:
+ * include/watchdog.h: New file - add "C" API for watchdog functions.
+
+2003-04-03 Thomas Koeller <thomas.koeller@baslerweb.com>
+
+ * cdl/watchdog.cdl: Turned 'wallclock' into 'watchdog' in string.
+
+2003-04-02 Jonathan Larmour <jifl@eCosCentric.com>
+
+ * cdl/watchdog.cdl: Watchdog implementation requirement should be
+ in package, not interface itself. *Note* must be requires, not
+ active_if otherwise turning off the emulated watchdog means you
+ can never turn it on again!
+
+2000-05-31 Jesper Skov <jskov@redhat.com>
+
+ * tests/watchdog.cxx: fix comment.
+
+ * tests/watchdog2.cxx:
+ * cdl/watchdog.cdl:
+ watchdog2 tests timeout is not too fast (safe for both types of
+ watchdog semantics).
+
+ * tests/watchdog_reset.cxx:
+ * src/emulate.cxx:
+ * include/watchdog.hxx:
+ Fixed compile errors.
+
+ * cdl/watchdog.cdl: Only build test if the watchdog does not reset
+ the board.
+ Added build option for interactive reset test.
+
+2000-05-30 Jesper Skov <jskov@redhat.com>
+
+ * tests/watchdog_reset.cxx:
+ * tests/watchdog.cxx:
+ * src/emulate.cxx:
+ * src/watchdog.cxx:
+ * include/watchdog.hxx:
+ * cdl/watchdog.cdl:
+ Moved to io/watchdog.
+
+2000-01-31 Simon FitzMaurice <sdf@cygnus.co.uk>
+ * cdl/watchdog.cdl:
+
+ Adjust help URLs in line with new doc layout.
+
+2000-01-28 Simon FitzMaurice <sdf@cygnus.co.uk>
+ * cdl/watchdog.cdl:
+
+ Adjust help URLs in line with new doc layout.
+
+2000-01-19 Hugo Tyson <hmt@cygnus.co.uk>
+
+ * cdl/*.cdl: Add descriptions to a number of options &c which were
+ lacking same, also tidied up other typos as noticed en passant.
+
+1999-11-03 John Dallaway <jld@cygnus.co.uk>
+
+ * cdl/watchdog.cdl: Define build options.
+
+1999-09-09 Jonathan Larmour <jlarmour@cygnus.co.uk>
+
+ * include/pkgconf/watchdog.h: Rename CYGPKG_HAL_MN10300_SIM to
+ CYGPKG_HAL_MN10300_AM31_SIM
+
+1999-09-07 Jesper Skov <jskov@cygnus.co.uk>
+
+ * include/pkgconf/watchdog.h:
+ * src/aeb1.cxx: [added]
+ * src/PKGconf.mak:
+ * tests/PKGconf.mak:
+ Added watchdog driver for AEB-1 board.
+
+1999-09-07 Jesper Skov <jskov@cygnus.co.uk>
+ PRs 20427, 20428, 20432
+ * tests/PKGconf.mak (TESTS): Clear on targets that reset the
+ board.
+
+1999-09-01 Jesper Skov <jskov@cygnus.co.uk>
+ * cdl/watchdog.cdl:
+ * include/pkgconf/watchdog.h:
+ * src/PKGconf.mak:
+ * src/sh.cxx:
+ Added watchdog driver for SH.
+
+1999-08-27 Jesper Skov <jskov@cygnus.co.uk>
+ * include/pkgconf/watchdog.h:
+ * src/PKGconf.mak:
+ * src/ebsa285.cxx:
+ Added watchdog device for 21285.
+
+ * tests/watchdog_reset.cxx:
+ * tests/PKGconf.mak (TESTS):
+ Added test for watchdog devices that reset the board.
+
+1999-08-24 Nick Garnett <nickg@cygnus.co.uk>
+
+ * src/mn10300.cxx: Turn watchdog off in Cyg_Watchdog::trigger() to
+ prevent it repeating.
+
+1999-08-18 Nick Garnett <nickg@cygnus.co.uk>
+
+ * include/pkgconf/watchdog.h: Made test for use of a non-emulated
+ watchdog more generic for MN10300 targets.
+
+ * src/emulate.cxx:
+ * include/watchdog.hxx (class Cyg_Watchdog):
+ Added get_resolution() to return maximum time, in nanoseconds,
+ between calls to reset().
+
+ * tests/watchdog.cxx:
+ Modified to use the value returned from get_resolution() to
+ control the timing of reset() calls.
+
+ * src/mn10300.cxx:
+ Added support for AM33 variant. Since the AM33 can only provide a
+ maximum watchdog cycle time of 621ms, this has motiviated the
+ addition of the get_resolution() call described above.
+
+1999-07-14 Jesper Skov <jskov@cygnus.co.uk>
+
+ * src/mn10300.cxx:
+ * src/emulate.cxx:
+ Include pkgconf/kernel.h.
+
+1999-04-21 Gary Thomas <gthomas@cygnus.co.uk>
+
+ * tests/watchdog.cxx: The 'keep alive' message was interfering
+ with the watchdog measurement. Some rearrangement fixes this.
+
+1999-04-20 Jonathan Larmour <jlarmour@cygnus.co.uk>
+
+ * tests/watchdog.cxx:
+ Restrict number of loops, and number of seconds per loop when we
+ detect we are in a simulator. Do this instead of changing the
+ value of one_sec in the simulator, since this invalidates the test
+ somewhat.
+ Output occasional messages to reassure the user that the test is
+ still running.
+ Fix for PR 19865
+
+1999-04-14 Jesper Skov <jskov@cygnus.co.uk>
+
+ * tests/watchdog.cxx (cyg_start): Added workaround for PR 17974.
+
+1999-04-12 John Dallaway <jld@cygnus.co.uk>
+
+ * include/pkgconf/watchdog.h: Add cdl_package doc attribute.
+
+1999-04-08 Gary Thomas <gthomas@cygnus.co.uk>
+
+ * tests/watchdog.cxx: PR 19773 - Loop over first test for better
+ coverage. Print some additional messages, especially if failure
+ detected. Reset watchdog after installing handler.
+ (watchdog_thread): Capture fail time before printing message.
+
+1999-04-07 Jesper Skov <jskov@cygnus.co.uk>
+ PR 19667
+ * tests/watchdog.cxx (cyg_start):
+ Changed to use the new Cyg_Thread constructor.
+
+1999-03-22 Hugo Tyson <hmt@cygnus.co.uk>
+
+ * tests/watchdog.cxx:
+ Use CYGNUM_HAL_STACK_SIZE_TYPICAL for the stack size instead of
+ CYGNUM_HAL_MINIMUM_STACK_SIZE.
+
+1999-03-12 Hugo Tyson <hmt@cygnus.co.uk>
+
+ * tests/watchdog.cxx:
+ Deal with CYGNUM_HAL_MINIMUM_STACK_SIZE requirement.
+
+1999-03-04 Gary Thomas <gthomas@cygnus.co.uk>
+
+ * include/pkgconf/watchdog.h: Make package stand-alone (no "DEVICES")
+
+1999-02-20 Jonathan Larmour <jlarmour@cygnus.co.uk>
+
+ * src/mn10300.cxx:
+ Change CYG_VECTOR_WATCHDOG to CYGNUM_HAL_INTERRUPT_WATCHDOG in line
+ with HAL changes.
+ General QA improvements
+
+1999-02-03 Jesper Skov <jskov@cygnus.co.uk>
+ PR 19034
+ * tests/watchdog.cxx: Reduced run-time on SIM.
+
+1998-12-17 Jesper Skov <jskov@cygnus.co.uk>
+
+ * tests/watchdog.cxx: Do NOP test if kernel RTC disabled.
+
+1998-10-23 Jesper Skov <jskov@cygnus.co.uk>
+
+ * tests/watchdog.cxx (cyg_start): Reduce test time on TX39 SIM.
+
+ * include/pkgconf/watchdog.h: Use emulatation code for MN10300
+ SIM.
+
+Tue Oct 20 15:52:46 1998 Jonathan Larmour <jlarmour@cygnus.co.uk>
+
+ * src/mn10300.cxx:
+ Include <pkgconf/watchdog.h> so that we get CYGIMP_WATCHDOG_EMULATE
+ defined appropriately
+
+ * src/PKGconf.mak:
+ Remove unnecessary override of PKGCONF_CXXFLAGS
+
+1998-09-26 Bart Veer <bartv@cygnus.co.uk>
+
+ * include/pkgconf/watchdog.h:
+ PR17501: When using the emulation there is a requirement on the
+ kernel clock. This has been added to the configuration data. The
+ mn10300 hardware implementation does not have this requirement,
+ but there is no easy way to express this at present.
+
+1998-09-12 Bart Veer <bartv@cygnus.co.uk>
+
+ * include/pkgconf/watchdog.h:
+ Added missing descriptions (PR 17184)
+
+1998-09-02 Bart Veer <bartv@cygnus.co.uk>
+
+ * include/pkgconf/watchdog.h:
+ Added minimal configuration data.
+
+1998-09-01 Nick Garnett <nickg@cygnus.co.uk>
+
+ * src/mn10300.cxx:
+ Added include for <cyg/kernel/sched.inl>, for scheduler lock and
+ unlock functions.
+
+ * src/PKGconf.mak:
+ Added mn10300.cxx to COMPILE for mn10300.
+
+ * include/pkgconf/watchdog.h:
+ Default to using real hardware on MN10300.
+
+Fri Aug 28 09:42:26 1998 Jonathan Larmour <jlarmour@cygnus.co.uk>
+
+ * tests/watchdog.cxx:
+ Rename int main(argc, argv) to void cyg_start( void ) under the
+ new entry point system. Therefore also remove return code.
+
+Tue Aug 18 16:51:24 1998 Jonathan Larmour <jlarmour@cygnus.co.uk>
+
+ * tests/watchdog.cxx:
+ Move inclusion of thread.inl to before sched.hxx to prevent inline
+ warnings
+
+1998-08-14 Nick Garnett <nickg@cygnus.co.uk>
+
+ * src/emulate.cxx:
+ Added include for cyg/kernel/sched.inl.
+
+1998-07-31 Nick Garnett <nickg@cygnus.co.uk>
+
+ * src/PKGconf.mak:
+ Added mn10300.cxx to COMPILE list.
+
+ * src/mn10300.cxx:
+ Completed implementation using MN10300 watchdog timer.
+
+ * include/watchdog.hxx:
+ Renamed 'register' functions to 'install'. Added install() and
+ uninstall() to Cyg_Watchdog_Action class.
+
+ * include/pkgconf/watchdog.h:
+ Added this file to contain watchdog config options.
+
+1998-07-29 Nick Garnett <nickg@cygnus.co.uk>
+
+ * include/watchdog.hxx, src/emulate.cxx:
+ Created initial versions of watchdog device.
+
+// ####GPLCOPYRIGHTBEGIN####
+// -------------------------------------------
+// This file is part of eCos, the Embedded Configurable Operating System.
+// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2009 Free Software Foundation, Inc.
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 or (at your option) any
+// later version.
+//
+// This program 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
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the
+// Free Software Foundation, Inc., 51 Franklin Street,
+// Fifth Floor, Boston, MA 02110-1301, USA.
+// -------------------------------------------
+// ####GPLCOPYRIGHTEND####
diff --git a/ecos/packages/io/watchdog/current/cdl/watchdog.cdl b/ecos/packages/io/watchdog/current/cdl/watchdog.cdl
new file mode 100644
index 0000000..35735d3
--- /dev/null
+++ b/ecos/packages/io/watchdog/current/cdl/watchdog.cdl
@@ -0,0 +1,176 @@
+# ====================================================================
+#
+# watchdog.cdl
+#
+# eCos watchdog configuration data
+#
+# ====================================================================
+## ####ECOSGPLCOPYRIGHTBEGIN####
+## -------------------------------------------
+## This file is part of eCos, the Embedded Configurable Operating System.
+## Copyright (C) 1998, 1999, 2000, 2001, 2002, 2009 Free Software Foundation, Inc.
+##
+## eCos is free software; you can redistribute it and/or modify it under
+## the terms of the GNU General Public License as published by the Free
+## Software Foundation; either version 2 or (at your option) any later
+## version.
+##
+## eCos 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 General Public License
+## for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with eCos; if not, write to the Free Software Foundation, Inc.,
+## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+##
+## As a special exception, if other files instantiate templates or use
+## macros or inline functions from this file, or you compile this file
+## and link it with other works to produce a work based on this file,
+## this file does not by itself cause the resulting work to be covered by
+## the GNU General Public License. However the source code for this file
+## must still be made available in accordance with section (3) of the GNU
+## General Public License v2.
+##
+## This exception does not invalidate any other reasons why a work based
+## on this file might be covered by the GNU General Public License.
+## -------------------------------------------
+## ####ECOSGPLCOPYRIGHTEND####
+# ====================================================================
+######DESCRIPTIONBEGIN####
+#
+# Author(s): jskov
+# Original data: nickg
+# Contributors:
+# Date: 1999-07-13
+#
+#####DESCRIPTIONEND####
+#
+# ====================================================================
+
+cdl_package CYGPKG_IO_WATCHDOG {
+ display "Watchdog IO device"
+ define_header watchdog.h
+ include_dir cyg/io
+ description "
+ The watchdog IO device allows applications to make use of a
+ timer facility. Depending on the underlying hardware device
+ driver, a watchdog timeout will either cause a board reset
+ or an action routine to be called. The application must call
+ the watchdog reset function at regular intervals, or else the
+ device will timeout. The assumption is that the watchdog timer
+ should never trigger unless there has been a serious fault in
+ either the hardware or the software."
+
+ compile watchdog.cxx
+
+ cdl_interface CYGINT_WATCHDOG_HW_IMPLEMENTATIONS {
+ display "Number of watchdog hardware implementations"
+ no_define
+ }
+
+ cdl_interface CYGINT_WATCHDOG_IMPLEMENTATIONS {
+ display "Number of watchdog implementations"
+ no_define
+ requires 1 == CYGINT_WATCHDOG_IMPLEMENTATIONS
+ }
+
+ cdl_component CYGPKG_IO_WATCHDOG_IMPLEMENTATION {
+ display "Watchdog implementation"
+ flavor none
+ no_define
+ description "Implementations of the watchdog device."
+
+ cdl_option CYGPKG_WATCHDOG_EMULATE {
+ default_value { 0 == CYGINT_WATCHDOG_HW_IMPLEMENTATIONS }
+ display "Watchdog emulator"
+ implements CYGINT_WATCHDOG_IMPLEMENTATIONS
+ requires CYGVAR_KERNEL_COUNTERS_CLOCK
+ compile emulate.cxx
+ description "
+ When this option is enabled, a watchdog device will be
+ emulated using the kernel real-time clock."
+ }
+
+ cdl_option CYGIMP_WATCHDOG_NONE {
+ display "No watchdog"
+ default_value 0
+ implements CYGINT_WATCHDOG_IMPLEMENTATIONS
+ description "Disables the watchdog."
+ }
+ }
+
+ cdl_interface CYGINT_WATCHDOG_RESETS_ON_TIMEOUT {
+ display "Set if device causes a reset on timeout"
+ no_define
+ }
+
+ cdl_option CYGSEM_WATCHDOG_RESETS_ON_TIMEOUT {
+ display "Set if device causes a reset on timeout"
+ calculated { CYGINT_WATCHDOG_RESETS_ON_TIMEOUT == 1 }
+ description "
+ Some watchdog devices reset the board on timeout - for these
+ implementations it does not make sense to register timeout
+ actions so the code gets disabled when this option is set.
+ When this option is not set, it is the application's
+ responsibility to register an action handler which can force
+ a board reset when it gets called."
+ }
+
+ cdl_option CYGPKG_IO_WATCHDOG_BUILD_INTERACTIVE_TEST {
+ display "Build interactive watchdog test"
+ flavor bool
+ no_define
+ default_value 0
+ description "
+ This option enables the building of a watchdog test
+ which can be used to test that the board resets on
+ watchdog timeout. This test is built separately since
+ it only makes sense to use interactively."
+ }
+
+ cdl_component CYGPKG_IO_WATCHDOG_OPTIONS {
+ display "Watchdog build options"
+ flavor none
+ description "
+ Package specific build options including control over
+ compiler flags used only in building this package,
+ and details of which tests are built."
+
+
+ cdl_option CYGPKG_IO_WATCHDOG_CFLAGS_ADD {
+ display "Additional compiler flags"
+ flavor data
+ no_define
+ default_value { "" }
+ description "
+ This option modifies the set of compiler flags for
+ building the watchdog IO device. These flags are used
+ in addition to the set of global flags."
+ }
+
+ cdl_option CYGPKG_IO_WATCHDOG_CFLAGS_REMOVE {
+ display "Suppressed compiler flags"
+ flavor data
+ no_define
+ default_value { "" }
+ description "
+ This option modifies the set of compiler flags for
+ building the watchdog IO device. These flags are removed from
+ the set of global flags if present."
+ }
+
+ cdl_option CYGPKG_IO_WATCHDOG_TESTS {
+ display "Watchdog tests"
+ flavor data
+ no_define
+ calculated { CYGPKG_IO_WATCHDOG_BUILD_INTERACTIVE_TEST ?
+ CYGSEM_WATCHDOG_RESETS_ON_TIMEOUT ? "tests/watchdog2 tests/watchdog_reset" : "tests/watchdog tests/watchdog2 tests/watchdog_reset" :
+ CYGSEM_WATCHDOG_RESETS_ON_TIMEOUT ? "tests/watchdog2" : "tests/watchdog tests/watchdog2" }
+
+ description "
+ This option specifies the set of tests for the
+ watchdog IO device."
+ }
+ }
+}
diff --git a/ecos/packages/io/watchdog/current/include/watchdog.h b/ecos/packages/io/watchdog/current/include/watchdog.h
new file mode 100644
index 0000000..a202a7c
--- /dev/null
+++ b/ecos/packages/io/watchdog/current/include/watchdog.h
@@ -0,0 +1,58 @@
+#ifndef _IO_WATCHDOG_H_
+#define _IO_WATCHDOG_H_
+
+//==========================================================================
+//
+// watchdog.h
+//
+// c-api to the watchdog.
+//
+//==========================================================================
+// ####ECOSGPLCOPYRIGHTBEGIN####
+// -------------------------------------------
+// This file is part of eCos, the Embedded Configurable Operating System.
+// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
+//
+// eCos is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 2 or (at your option) any later
+// version.
+//
+// eCos 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 General Public License
+// for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with eCos; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// As a special exception, if other files instantiate templates or use
+// macros or inline functions from this file, or you compile this file
+// and link it with other works to produce a work based on this file,
+// this file does not by itself cause the resulting work to be covered by
+// the GNU General Public License. However the source code for this file
+// must still be made available in accordance with section (3) of the GNU
+// General Public License v2.
+//
+// This exception does not invalidate any other reasons why a work based
+// on this file might be covered by the GNU General Public License.
+// -------------------------------------------
+// ####ECOSGPLCOPYRIGHTEND####
+//==========================================================================
+//#####DESCRIPTIONBEGIN####
+//
+// Author(s): Bob Koninckx
+// Contributors: Bob Koninckx
+// Date: 2003-05-24
+// Purpose: provide a c-api to the watchdog
+//
+//####DESCRIPTIONEND####
+
+#include <cyg/infra/cyg_type.h>
+
+externC void watchdog_start(void);
+externC void watchdog_reset(void);
+externC cyg_uint64 watchdog_get_resolution(void);
+
+#endif // _IO_WATCHDOG_H_
diff --git a/ecos/packages/io/watchdog/current/include/watchdog.hxx b/ecos/packages/io/watchdog/current/include/watchdog.hxx
new file mode 100644
index 0000000..4eefeca
--- /dev/null
+++ b/ecos/packages/io/watchdog/current/include/watchdog.hxx
@@ -0,0 +1,167 @@
+#ifndef CYGONCE_DEVS_WATCHDOG_HXX
+#define CYGONCE_DEVS_WATCHDOG_HXX
+
+//==========================================================================
+//
+// watchdog.hxx
+//
+// Watchdog interface declaration
+//
+//==========================================================================
+// ####ECOSGPLCOPYRIGHTBEGIN####
+// -------------------------------------------
+// This file is part of eCos, the Embedded Configurable Operating System.
+// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
+//
+// eCos is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 2 or (at your option) any later
+// version.
+//
+// eCos 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 General Public License
+// for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with eCos; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// As a special exception, if other files instantiate templates or use
+// macros or inline functions from this file, or you compile this file
+// and link it with other works to produce a work based on this file,
+// this file does not by itself cause the resulting work to be covered by
+// the GNU General Public License. However the source code for this file
+// must still be made available in accordance with section (3) of the GNU
+// General Public License v2.
+//
+// This exception does not invalidate any other reasons why a work based
+// on this file might be covered by the GNU General Public License.
+// -------------------------------------------
+// ####ECOSGPLCOPYRIGHTEND####
+//==========================================================================
+//#####DESCRIPTIONBEGIN####
+//
+// Author(s): nickg
+// Contributors: nickg
+// Date: 1998-07-14
+// Purpose: Watchdog declarations
+// Description: This file defines the interface to the watchdog device
+// that provides timer based recovery from software and
+// hardware faults.
+// Usage: #include <cyg/devs/watchdog.hxx>
+//
+//####DESCRIPTIONEND####
+//
+//==========================================================================
+
+#include <cyg/infra/cyg_type.h>
+#include <cyg/infra/cyg_ass.h> // assertion macros
+
+class Cyg_Watchdog_Action;
+
+// -------------------------------------------------------------------------
+// Watchdog class
+
+class Cyg_Watchdog
+{
+
+ Cyg_Watchdog_Action *action_list;
+
+ cyg_uint64 resolution;
+
+public:
+
+ Cyg_Watchdog();
+
+ // Return time interval allowed between resets before watchdog
+ // triggers, in nanoseconds.
+ cyg_uint64 get_resolution( void );
+
+ // Start the watchdog running.
+ void start( void );
+
+ // Reset watchdog timer. This needs to be called regularly to prevent
+ // the watchdog firing.
+ void reset( void );
+
+#ifndef CYGSEM_WATCHDOG_RESETS_ON_TIMEOUT
+ // Trigger the watchdog as if the timer had expired.
+ void trigger( void );
+
+ // Register an action routine that will be called when the timer
+ // triggers.
+ void install_action( Cyg_Watchdog_Action *wdaction );
+
+ // Deregister a previously registered action routine.
+ void uninstall_action( Cyg_Watchdog_Action *wdaction );
+#endif
+
+ // A static instance of the single system defined watchdog device.
+ static Cyg_Watchdog watchdog;
+
+private:
+ void init_hw( void );
+};
+
+#ifndef CYGSEM_WATCHDOG_RESETS_ON_TIMEOUT
+// -------------------------------------------------------------------------
+// Watchdog action class
+
+class Cyg_Watchdog_Action
+{
+ friend class Cyg_Watchdog;
+
+ Cyg_Watchdog_Action *next; // link in chain
+
+ void (*action)( CYG_ADDRWORD data ); // action function
+
+ CYG_ADDRWORD data; // data argument
+
+public:
+
+ Cyg_Watchdog_Action(
+ void (*action)( CYG_ADDRWORD data ),
+ CYG_ADDRWORD data
+ );
+
+ ~Cyg_Watchdog_Action();
+
+ void install();
+
+ void uninstall();
+};
+
+// -------------------------------------------------------------------------
+// Cyg_Watchdog_Action inlines
+
+inline Cyg_Watchdog_Action::Cyg_Watchdog_Action(
+ void (*action_arg)( CYG_ADDRWORD data ),
+ CYG_ADDRWORD data_arg
+ )
+{
+ next = NULL;
+ action = action_arg;
+ data = data_arg;
+}
+
+inline Cyg_Watchdog_Action::~Cyg_Watchdog_Action()
+{
+ Cyg_Watchdog::watchdog.uninstall_action( this );
+}
+
+inline void Cyg_Watchdog_Action::install()
+{
+ Cyg_Watchdog::watchdog.install_action( this );
+}
+
+inline void Cyg_Watchdog_Action::uninstall()
+{
+ Cyg_Watchdog::watchdog.uninstall_action( this );
+}
+
+#endif // CYGSEM_WATCHDOG_RESETS_ON_TIMEOUT
+
+// -------------------------------------------------------------------------
+#endif // ifndef CYGONCE_DEVS_WATCHDOG_HXX
+// EOF watchdog.hxx
diff --git a/ecos/packages/io/watchdog/current/src/emulate.cxx b/ecos/packages/io/watchdog/current/src/emulate.cxx
new file mode 100644
index 0000000..f605110
--- /dev/null
+++ b/ecos/packages/io/watchdog/current/src/emulate.cxx
@@ -0,0 +1,148 @@
+//==========================================================================
+//
+// io/watchdog/emulate.cxx
+//
+// Watchdog implementation emulation
+//
+//==========================================================================
+// ####ECOSGPLCOPYRIGHTBEGIN####
+// -------------------------------------------
+// This file is part of eCos, the Embedded Configurable Operating System.
+// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
+//
+// eCos is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 2 or (at your option) any later
+// version.
+//
+// eCos 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 General Public License
+// for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with eCos; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// As a special exception, if other files instantiate templates or use
+// macros or inline functions from this file, or you compile this file
+// and link it with other works to produce a work based on this file,
+// this file does not by itself cause the resulting work to be covered by
+// the GNU General Public License. However the source code for this file
+// must still be made available in accordance with section (3) of the GNU
+// General Public License v2.
+//
+// This exception does not invalidate any other reasons why a work based
+// on this file might be covered by the GNU General Public License.
+// -------------------------------------------
+// ####ECOSGPLCOPYRIGHTEND####
+//==========================================================================
+//#####DESCRIPTIONBEGIN####
+//
+// Author(s): nickg
+// Contributors: nickg
+// Date: 1998-07-29
+// Purpose: Watchdog class implementation
+// Description: Contains an implementation of the Watchdog class for use
+// when there is no hardware watchdog timer. Instead it is
+// emulated using an Alarm object.
+//
+//####DESCRIPTIONEND####
+//
+//==========================================================================
+
+#include <pkgconf/watchdog.h> // watchdog configuration file
+#include <pkgconf/kernel.h> // Kernel config
+
+#include <cyg/kernel/ktypes.h> // base kernel types
+#include <cyg/infra/cyg_trac.h> // tracing macros
+#include <cyg/infra/cyg_ass.h> // assertion macros
+#include <cyg/kernel/instrmnt.h> // instrumentation
+
+#include <cyg/kernel/clock.hxx> // clock and alarm
+#include <cyg/kernel/sched.hxx> // scheduler
+
+#include <cyg/io/watchdog.hxx> // watchdog API
+
+#include <cyg/kernel/sched.inl> // scheduler inlines
+
+// -------------------------------------------------------------------------
+// Forward definitions
+
+static cyg_alarm_fn watchdog_alarm;
+
+// -------------------------------------------------------------------------
+// Statics
+
+static Cyg_Alarm alarm( Cyg_Clock::real_time_clock, watchdog_alarm, 0 );
+
+// One second's worth of ticks.
+static cyg_tick_count one_sec;
+
+// -------------------------------------------------------------------------
+// HW init
+
+void
+Cyg_Watchdog::init_hw(void)
+{
+ CYG_REPORT_FUNCTION();
+
+ Cyg_Clock::cyg_resolution res = Cyg_Clock::real_time_clock->get_resolution();
+
+ one_sec = ( res.divisor * 1000000000LL ) / res.dividend ;
+
+ resolution = 1000000000LL;
+
+ CYG_REPORT_RETURN();
+}
+
+// -------------------------------------------------------------------------
+// Start the watchdog running.
+
+void Cyg_Watchdog::start()
+{
+ CYG_REPORT_FUNCTION();
+
+ Cyg_Clock::cyg_resolution res = Cyg_Clock::real_time_clock->get_resolution();
+
+ // Set alarm to a one second single-shot trigger
+ alarm.initialize( Cyg_Clock::real_time_clock->current_value() + one_sec, 0 );
+
+ CYG_REPORT_RETURN();
+}
+
+// -------------------------------------------------------------------------
+// Reset watchdog timer. This needs to be called regularly to prevent
+// the watchdog firing.
+
+void Cyg_Watchdog::reset()
+{
+ CYG_REPORT_FUNCTION();
+
+ Cyg_Clock::cyg_resolution res = Cyg_Clock::real_time_clock->get_resolution();
+
+ Cyg_Scheduler::lock();
+
+ // Set alarm to a one second single-shot trigger
+ alarm.initialize( Cyg_Clock::real_time_clock->current_value() + one_sec, 0 );
+
+ Cyg_Scheduler::unlock();
+
+ CYG_REPORT_RETURN();
+}
+
+// -------------------------------------------------------------------------
+// Alarm function
+
+void watchdog_alarm( Cyg_Alarm *a, CYG_ADDRWORD data)
+{
+ CYG_REPORT_FUNCTION();
+
+ // Disable alarm just in case
+ alarm.disable();
+
+ Cyg_Watchdog::watchdog.trigger();
+}
+
+// -------------------------------------------------------------------------
+// EOF watchdog/emulate.cxx
diff --git a/ecos/packages/io/watchdog/current/src/watchdog.cxx b/ecos/packages/io/watchdog/current/src/watchdog.cxx
new file mode 100644
index 0000000..edb2e4b
--- /dev/null
+++ b/ecos/packages/io/watchdog/current/src/watchdog.cxx
@@ -0,0 +1,193 @@
+//==========================================================================
+//
+// io/watchdog/watchdog.cxx
+//
+// Watchdog common code
+//
+//==========================================================================
+// ####ECOSGPLCOPYRIGHTBEGIN####
+// -------------------------------------------
+// This file is part of eCos, the Embedded Configurable Operating System.
+// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2009 Free Software Foundation, Inc.
+//
+// eCos is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 2 or (at your option) any later
+// version.
+//
+// eCos 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 General Public License
+// for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with eCos; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// As a special exception, if other files instantiate templates or use
+// macros or inline functions from this file, or you compile this file
+// and link it with other works to produce a work based on this file,
+// this file does not by itself cause the resulting work to be covered by
+// the GNU General Public License. However the source code for this file
+// must still be made available in accordance with section (3) of the GNU
+// General Public License v2.
+//
+// This exception does not invalidate any other reasons why a work based
+// on this file might be covered by the GNU General Public License.
+// -------------------------------------------
+// ####ECOSGPLCOPYRIGHTEND####
+//==========================================================================
+//#####DESCRIPTIONBEGIN####
+//
+// Author(s): nickg
+// Contributors: nickg
+// Date: 1999-02-18
+// Purpose: Watchdog class implementation
+//
+//####DESCRIPTIONEND####
+//
+//==========================================================================
+
+#include <pkgconf/system.h> // system configuration file
+#include <pkgconf/watchdog.h> // configuration for this package
+
+#include <cyg/infra/cyg_trac.h> // tracing macros
+#include <cyg/infra/cyg_ass.h> // assertion macros
+
+#include <cyg/hal/drv_api.h> // for locking
+
+#include <cyg/io/watchdog.hxx> // watchdog API
+#include <cyg/io/watchdog.h> // watchdog c-api
+
+// -------------------------------------------------------------------------
+// Statics
+
+// A static pointer to the single system defined watchdog device.
+Cyg_Watchdog Cyg_Watchdog::watchdog CYGBLD_ATTRIB_INIT_PRI( CYG_INIT_DEV_WATCHDOG );
+
+// -------------------------------------------------------------------------
+// Constructor
+
+
+Cyg_Watchdog::Cyg_Watchdog()
+{
+ CYG_REPORT_FUNCTION();
+
+#ifndef CYGSEM_WATCHDOG_RESETS_ON_TIMEOUT
+ action_list = 0;
+#endif
+
+ // HW driver initialization. This must set the watchdog resolution.
+ init_hw();
+
+ CYG_REPORT_RETURN();
+}
+
+// -------------------------------------------------------------------------
+// Return reset resolution
+
+cyg_uint64
+Cyg_Watchdog::get_resolution()
+{
+ return resolution;
+}
+
+#ifndef CYGSEM_WATCHDOG_RESETS_ON_TIMEOUT
+// -------------------------------------------------------------------------
+// Trigger the watchdog as if the timer had expired. This should be called
+// from the driver's ISR.
+
+void
+Cyg_Watchdog::trigger()
+{
+ CYG_REPORT_FUNCTION();
+
+ cyg_drv_dsr_lock();
+
+ Cyg_Watchdog_Action *act = action_list;
+
+ while( 0 != act )
+ {
+ act->action( act->data );
+
+ act = act->next;
+ }
+
+ cyg_drv_dsr_unlock();
+
+ CYG_REPORT_RETURN();
+}
+
+// -------------------------------------------------------------------------
+// Register an action routine that will be called when the timer
+// triggers.
+
+void
+Cyg_Watchdog::install_action( Cyg_Watchdog_Action *action )
+{
+ CYG_REPORT_FUNCTION();
+
+ cyg_drv_dsr_lock();
+
+ action->next = action_list;
+ action_list = action;
+
+ cyg_drv_dsr_unlock();
+
+ CYG_REPORT_RETURN();
+}
+
+// -------------------------------------------------------------------------
+// Deregister a previously registered action routine.
+
+void
+Cyg_Watchdog::uninstall_action( Cyg_Watchdog_Action *action )
+{
+ CYG_REPORT_FUNCTION();
+
+ cyg_drv_dsr_lock();
+
+ Cyg_Watchdog_Action **act_ptr = &action_list;
+
+ while( 0 != *act_ptr )
+ {
+ Cyg_Watchdog_Action *a = *act_ptr;
+
+ if( a == action )
+ {
+ *act_ptr = a->next;
+ break;
+ }
+ act_ptr = &a->next;
+ }
+
+ cyg_drv_dsr_unlock();
+
+ CYG_REPORT_RETURN();
+}
+
+#endif // CYGSEM_WATCHDOG_RESETS_ON_TIMEOUT
+
+// -------------------------------------------------------------------------
+// Implementation of the C-api
+
+externC void
+watchdog_start(void)
+{
+ Cyg_Watchdog::watchdog.start();
+}
+
+externC void
+watchdog_reset(void)
+{
+ Cyg_Watchdog::watchdog.reset();
+}
+
+externC cyg_uint64
+watchdog_get_resolution(void)
+{
+ return Cyg_Watchdog::watchdog.get_resolution();
+}
+
+// -------------------------------------------------------------------------
+// EOF io/watchdog/watchdog.cxx
diff --git a/ecos/packages/io/watchdog/current/tests/watchdog.cxx b/ecos/packages/io/watchdog/current/tests/watchdog.cxx
new file mode 100644
index 0000000..257ab87
--- /dev/null
+++ b/ecos/packages/io/watchdog/current/tests/watchdog.cxx
@@ -0,0 +1,237 @@
+//==========================================================================
+//
+// watchdog.cxx
+//
+// Watchdog test
+//
+//==========================================================================
+// ####ECOSGPLCOPYRIGHTBEGIN####
+// -------------------------------------------
+// This file is part of eCos, the Embedded Configurable Operating System.
+// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
+//
+// eCos is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 2 or (at your option) any later
+// version.
+//
+// eCos 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 General Public License
+// for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with eCos; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// As a special exception, if other files instantiate templates or use
+// macros or inline functions from this file, or you compile this file
+// and link it with other works to produce a work based on this file,
+// this file does not by itself cause the resulting work to be covered by
+// the GNU General Public License. However the source code for this file
+// must still be made available in accordance with section (3) of the GNU
+// General Public License v2.
+//
+// This exception does not invalidate any other reasons why a work based
+// on this file might be covered by the GNU General Public License.
+// -------------------------------------------
+// ####ECOSGPLCOPYRIGHTEND####
+//==========================================================================
+//#####DESCRIPTIONBEGIN####
+//
+// Author(s): nickg
+// Contributors: nickg
+// Date: 1998-07-20
+// Description: This test exercises the Watchdog class and checks that it
+// works as advertised.
+//####DESCRIPTIONEND####
+// -------------------------------------------------------------------------
+
+#include <pkgconf/kernel.h>
+
+#include <cyg/kernel/thread.hxx>
+#include <cyg/kernel/thread.inl>
+#include <cyg/kernel/sched.hxx>
+#include <cyg/kernel/mutex.hxx>
+#include <cyg/kernel/sema.hxx>
+#include <cyg/kernel/clock.hxx>
+
+#include <cyg/kernel/diag.h>
+
+#include <cyg/io/watchdog.hxx>
+
+#include <cyg/infra/testcase.h>
+#include <cyg/infra/diag.h>
+
+#if defined(CYGFUN_KERNEL_THREADS_TIMER) && \
+ defined(CYGVAR_KERNEL_COUNTERS_CLOCK)
+
+#include <cyg/kernel/sched.inl>
+
+// -------------------------------------------------------------------------
+// Data for the test
+
+#ifdef CYGNUM_HAL_STACK_SIZE_TYPICAL
+#define STACKSIZE CYGNUM_HAL_STACK_SIZE_TYPICAL
+#else
+#define STACKSIZE (2*1024) // size of thread stack
+#endif
+
+char thread_stack[STACKSIZE];
+
+inline void *operator new(size_t size, void *ptr) { return ptr; };
+
+// array of threads.
+char thread[sizeof(Cyg_Thread)];
+
+Cyg_Thread *th;
+
+//cyg_tick_count one_sec;
+cyg_tick_count watchdog_delay;
+volatile bool watchdog_fired;
+volatile cyg_tick_count watchdog_time;
+
+#define WATCHDOG_LOOPS_HW 5
+#define WATCHDOG_LOOPS_SIM 1
+#define WATCHDOG_CYCLES_PER_LOOP_HW 10
+#define WATCHDOG_CYCLES_PER_LOOP_SIM 2
+#define WATCHDOG_TICKS_TILL_TIMEOUT 10
+
+// -------------------------------------------------------------------------
+// Action functions:
+
+void watchdog_action1( CYG_ADDRWORD data )
+{
+ watchdog_fired = true;
+ watchdog_time = Cyg_Clock::real_time_clock->current_value();
+}
+
+void watchdog_action2( CYG_ADDRWORD data )
+{
+ CYG_TEST_PASS_FINISH("Watchdog OK");
+}
+
+// -------------------------------------------------------------------------
+// Thread body
+
+
+void watchdog_thread( CYG_ADDRWORD id )
+{
+ cyg_tick_count watchdog_start_time;
+ cyg_tick_count thread_start_time, thread_end_time;
+ cyg_ucount8 watchdog_loops, watchdog_cycles_per_loop;
+
+ if (cyg_test_is_simulator) {
+ watchdog_loops = WATCHDOG_LOOPS_SIM;
+ watchdog_cycles_per_loop = WATCHDOG_CYCLES_PER_LOOP_SIM;
+ } else {
+ watchdog_loops = WATCHDOG_LOOPS_HW;
+ watchdog_cycles_per_loop = WATCHDOG_CYCLES_PER_LOOP_HW;
+ }
+
+ watchdog_fired = false;
+ Cyg_Watchdog::watchdog.start();
+
+ CYG_TEST_INFO("Testing that watchdog does not fire early");
+
+ for (cyg_ucount8 tries = 0; tries < watchdog_loops; tries++) {
+ diag_printf("Iteration #%d (testing over %d cycles)\n",
+ tries, watchdog_cycles_per_loop);
+
+ // First test that the watchdog does not trigger when being reset.
+ Cyg_Watchdog_Action wdaction( watchdog_action1, 0 );
+
+ wdaction.install();
+ Cyg_Watchdog::watchdog.reset();
+
+ watchdog_start_time = Cyg_Clock::real_time_clock->current_value();
+ watchdog_fired = false;
+
+ for( cyg_ucount8 i = 0; i < watchdog_cycles_per_loop; i++ ) {
+ thread_start_time = Cyg_Clock::real_time_clock->current_value();
+ th->delay( watchdog_delay-2 );
+ Cyg_Watchdog::watchdog.reset();
+ if (watchdog_fired) {
+ thread_end_time = Cyg_Clock::real_time_clock->current_value();
+ diag_printf("Watchdog fired prematurely after %d ticks\n",
+ (int)(watchdog_time - watchdog_start_time));
+ diag_printf(" Thread slept for %d ticks, loop #%d\n",
+ (int)(thread_end_time - thread_start_time), i);
+ CYG_TEST_FAIL_FINISH("Watchdog triggered unexpectedly");
+ break;
+ } else {
+ CYG_TEST_STILL_ALIVE(i, "Resetting watchdog...");
+ Cyg_Watchdog::watchdog.reset();
+ watchdog_fired = false;
+ watchdog_start_time = Cyg_Clock::real_time_clock->current_value();
+ }
+ }
+ }
+
+ // Now check that it triggers when not reset
+ CYG_TEST_INFO("Testing that watchdog fires");
+ {
+ Cyg_Watchdog_Action wdaction( watchdog_action2, 0 );
+
+ wdaction.install();
+
+ Cyg_Watchdog::watchdog.reset();
+
+ th->delay( watchdog_delay*WATCHDOG_TICKS_TILL_TIMEOUT );
+ }
+
+ CYG_TEST_FAIL_FINISH("Watchdog failed to trigger");
+}
+
+// -------------------------------------------------------------------------
+
+
+externC void
+cyg_start( void )
+{
+ CYG_TEST_INIT();
+
+#if !defined(CYGIMP_WATCHDOG_EMULATE) && defined(CYGPKG_HAL_MN10300_STDEVAL1)
+ // Workaround for PR 17974
+ if( cyg_test_is_simulator )
+ CYG_TEST_NA("Watchdog device not implemented in MN10300 simulator.");
+#endif
+
+
+ Cyg_Clock::cyg_resolution res = Cyg_Clock::real_time_clock->get_resolution();
+
+ cyg_uint64 wres = Cyg_Watchdog::watchdog.get_resolution();
+
+ // Calculate how many clock ticks there are in a watchdog cycle.
+
+ watchdog_delay = ((cyg_tick_count)wres * (cyg_tick_count)res.divisor );
+ watchdog_delay /= res.dividend;
+
+ th = new((void *)&thread) Cyg_Thread(CYG_SCHED_DEFAULT_INFO,
+ watchdog_thread,
+ 0,
+ "watchdog_thread",
+ (CYG_ADDRESS)thread_stack,
+ STACKSIZE
+ );
+
+ th->resume();
+
+ // Get the world going
+ Cyg_Scheduler::scheduler.start();
+
+}
+
+#else // if defined(CYGFUN_KERNEL_THREADS_TIMER) etc...
+
+externC void
+cyg_start( void )
+{
+ CYG_TEST_INIT();
+ CYG_TEST_NA("Kernel real-time clock/threads timer disabled");
+}
+
+#endif // if defined(CYGFUN_KERNEL_THREADS_TIMER) etc...
+
+// -------------------------------------------------------------------------
+// EOF watchdog.cxx
diff --git a/ecos/packages/io/watchdog/current/tests/watchdog2.cxx b/ecos/packages/io/watchdog/current/tests/watchdog2.cxx
new file mode 100644
index 0000000..155e46f
--- /dev/null
+++ b/ecos/packages/io/watchdog/current/tests/watchdog2.cxx
@@ -0,0 +1,219 @@
+//==========================================================================
+//
+// watchdog2.cxx
+//
+// Watchdog test
+//
+//==========================================================================
+// ####ECOSGPLCOPYRIGHTBEGIN####
+// -------------------------------------------
+// This file is part of eCos, the Embedded Configurable Operating System.
+// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
+//
+// eCos is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 2 or (at your option) any later
+// version.
+//
+// eCos 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 General Public License
+// for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with eCos; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// As a special exception, if other files instantiate templates or use
+// macros or inline functions from this file, or you compile this file
+// and link it with other works to produce a work based on this file,
+// this file does not by itself cause the resulting work to be covered by
+// the GNU General Public License. However the source code for this file
+// must still be made available in accordance with section (3) of the GNU
+// General Public License v2.
+//
+// This exception does not invalidate any other reasons why a work based
+// on this file might be covered by the GNU General Public License.
+// -------------------------------------------
+// ####ECOSGPLCOPYRIGHTEND####
+//==========================================================================
+//#####DESCRIPTIONBEGIN####
+//
+// Author(s): nickg
+// Contributors: nickg, jskov
+// Date: 1998-07-20
+// Description: Tests the watchdog driver.
+// This test tries to make sure the watchdog does not trigger
+// early. On boards where the watchdog performs a reset on
+// timeout, there will be no FAIL message - but it should
+// PASS even on those boards when the driver implementation
+// is correct.
+//
+//####DESCRIPTIONEND####
+// -------------------------------------------------------------------------
+
+#include <pkgconf/kernel.h>
+
+#include <cyg/kernel/thread.hxx>
+#include <cyg/kernel/thread.inl>
+#include <cyg/kernel/sched.hxx>
+#include <cyg/kernel/mutex.hxx>
+#include <cyg/kernel/sema.hxx>
+#include <cyg/kernel/clock.hxx>
+
+#include <cyg/kernel/diag.h>
+
+#include <cyg/io/watchdog.hxx>
+
+#include <cyg/infra/testcase.h>
+#include <cyg/infra/diag.h>
+
+#if defined(CYGFUN_KERNEL_THREADS_TIMER) && \
+ defined(CYGVAR_KERNEL_COUNTERS_CLOCK)
+
+#include <cyg/kernel/sched.inl>
+
+// -------------------------------------------------------------------------
+// Data for the test
+
+#ifdef CYGNUM_HAL_STACK_SIZE_TYPICAL
+#define STACKSIZE CYGNUM_HAL_STACK_SIZE_TYPICAL
+#else
+#define STACKSIZE (2*1024) // size of thread stack
+#endif
+
+char thread_stack[STACKSIZE];
+
+inline void *operator new(size_t size, void *ptr) { return ptr; };
+
+// array of threads.
+char thread[sizeof(Cyg_Thread)];
+
+Cyg_Thread *th;
+
+//cyg_tick_count one_sec;
+cyg_tick_count watchdog_delay;
+volatile bool watchdog_fired;
+volatile cyg_tick_count watchdog_time;
+
+#define WATCHDOG_CYCLES_PER_LOOP_HW 7
+#define WATCHDOG_CYCLES_PER_LOOP_SIM 2
+#define WATCHDOG_TICKS_TILL_TIMEOUT 10
+
+// -------------------------------------------------------------------------
+// Action functions:
+
+#ifdef CYGINT_WATCHDOG_RESETS_ON_TIMEOUT
+void watchdog_action1( CYG_ADDRWORD data )
+{
+ watchdog_fired = true;
+ watchdog_time = Cyg_Clock::real_time_clock->current_value();
+}
+#endif
+
+// -------------------------------------------------------------------------
+// Thread body
+
+void watchdog_thread( CYG_ADDRWORD id )
+{
+ cyg_tick_count watchdog_start_time;
+ cyg_tick_count thread_start_time, thread_end_time;
+ cyg_ucount8 watchdog_cycles_per_loop;
+
+ if (cyg_test_is_simulator) {
+ watchdog_cycles_per_loop = WATCHDOG_CYCLES_PER_LOOP_SIM;
+ } else {
+ watchdog_cycles_per_loop = WATCHDOG_CYCLES_PER_LOOP_HW;
+ }
+
+ CYG_TEST_INFO("Testing that watchdog does not fire early");
+
+ watchdog_fired = false;
+ Cyg_Watchdog::watchdog.start();
+
+#ifdef CYGINT_WATCHDOG_RESETS_ON_TIMEOUT
+ // First test that the watchdog does not trigger when being reset.
+ Cyg_Watchdog_Action wdaction( watchdog_action1, 0 );
+ wdaction.install();
+#endif
+ Cyg_Watchdog::watchdog.reset();
+
+ watchdog_start_time = Cyg_Clock::real_time_clock->current_value();
+ watchdog_fired = false;
+
+ for( cyg_ucount8 i = 0; i < watchdog_cycles_per_loop; i++ ) {
+ thread_start_time = Cyg_Clock::real_time_clock->current_value();
+ th->delay( watchdog_delay-2 );
+ Cyg_Watchdog::watchdog.reset();
+ if (watchdog_fired) {
+ thread_end_time = Cyg_Clock::real_time_clock->current_value();
+ diag_printf("Watchdog fired prematurely after %d ticks\n",
+ (int)(watchdog_time - watchdog_start_time));
+ diag_printf(" Thread slept for %d ticks, loop #%d\n",
+ (int)(thread_end_time - thread_start_time), i);
+ CYG_TEST_FAIL_FINISH("Watchdog triggered unexpectedly");
+ break;
+ } else {
+ // No printing - delays are fatal!
+ // CYG_TEST_STILL_ALIVE(i, "Resetting watchdog...");
+ Cyg_Watchdog::watchdog.reset();
+ watchdog_fired = false;
+ watchdog_start_time = Cyg_Clock::real_time_clock->current_value();
+ }
+ }
+
+ CYG_TEST_PASS_FINISH("Watchdog OK");
+}
+
+// -------------------------------------------------------------------------
+
+
+externC void
+cyg_start( void )
+{
+ CYG_TEST_INIT();
+
+#if !defined(CYGIMP_WATCHDOG_EMULATE) && defined(CYGPKG_HAL_MN10300_STDEVAL1)
+ // Workaround for PR 17974
+ if( cyg_test_is_simulator )
+ CYG_TEST_NA("Watchdog device not implemented in MN10300 simulator.");
+#endif
+
+
+ Cyg_Clock::cyg_resolution res = Cyg_Clock::real_time_clock->get_resolution();
+
+ cyg_uint64 wres = Cyg_Watchdog::watchdog.get_resolution();
+
+ // Calculate how many clock ticks there are in a watchdog cycle.
+
+ watchdog_delay = ((cyg_tick_count)wres * (cyg_tick_count)res.divisor );
+ watchdog_delay /= res.dividend;
+
+ th = new((void *)&thread) Cyg_Thread(CYG_SCHED_DEFAULT_INFO,
+ watchdog_thread,
+ 0,
+ "watchdog_thread",
+ (CYG_ADDRESS)thread_stack,
+ STACKSIZE
+ );
+
+ th->resume();
+
+ // Get the world going
+ Cyg_Scheduler::scheduler.start();
+
+}
+
+#else // if defined(CYGFUN_KERNEL_THREADS_TIMER) etc...
+
+externC void
+cyg_start( void )
+{
+ CYG_TEST_INIT();
+ CYG_TEST_NA("Kernel real-time clock/threads timer disabled");
+}
+
+#endif // if defined(CYGFUN_KERNEL_THREADS_TIMER) etc...
+
+// -------------------------------------------------------------------------
+// EOF watchdog.cxx
diff --git a/ecos/packages/io/watchdog/current/tests/watchdog_reset.cxx b/ecos/packages/io/watchdog/current/tests/watchdog_reset.cxx
new file mode 100644
index 0000000..3b70d23
--- /dev/null
+++ b/ecos/packages/io/watchdog/current/tests/watchdog_reset.cxx
@@ -0,0 +1,183 @@
+//==========================================================================
+//
+// watchdog_reset.cxx
+//
+// Watchdog reset test
+//
+//==========================================================================
+// ####ECOSGPLCOPYRIGHTBEGIN####
+// -------------------------------------------
+// This file is part of eCos, the Embedded Configurable Operating System.
+// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
+//
+// eCos is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 2 or (at your option) any later
+// version.
+//
+// eCos 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 General Public License
+// for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with eCos; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// As a special exception, if other files instantiate templates or use
+// macros or inline functions from this file, or you compile this file
+// and link it with other works to produce a work based on this file,
+// this file does not by itself cause the resulting work to be covered by
+// the GNU General Public License. However the source code for this file
+// must still be made available in accordance with section (3) of the GNU
+// General Public License v2.
+//
+// This exception does not invalidate any other reasons why a work based
+// on this file might be covered by the GNU General Public License.
+// -------------------------------------------
+// ####ECOSGPLCOPYRIGHTEND####
+//==========================================================================
+//#####DESCRIPTIONBEGIN####
+//
+// Author(s): jskov (based on watchdog.cxx)
+// Contributors: jskov, nickg
+// Date: 1999-08-27
+// Description: Tests that the watchdog timer resets the board.
+// This test needs to be run by an operator - automatic
+// testing not possible.
+//####DESCRIPTIONEND####
+// -------------------------------------------------------------------------
+
+#include <pkgconf/system.h>
+
+#include <cyg/infra/testcase.h>
+#include <cyg/infra/diag.h>
+
+// Package requirements
+#if defined(CYGPKG_KERNEL)
+
+#include <pkgconf/kernel.h>
+
+// Package option requirements
+#if defined(CYGFUN_KERNEL_THREADS_TIMER) && \
+ defined(CYGVAR_KERNEL_COUNTERS_CLOCK)
+
+
+#include <cyg/kernel/thread.inl>
+
+#include <cyg/hal/hal_cache.h>
+
+#include <cyg/io/watchdog.hxx> // watchdog API
+
+
+// -------------------------------------------------------------------------
+// Data for the test
+
+#ifdef CYGNUM_HAL_STACK_SIZE_TYPICAL
+#define STACKSIZE CYGNUM_HAL_STACK_SIZE_TYPICAL
+#else
+#define STACKSIZE (2*1024) // size of thread stack
+#endif
+
+char thread_stack[STACKSIZE];
+
+inline void *operator new(size_t size, void *ptr) { return ptr; };
+
+// array of threads.
+char thread[sizeof(Cyg_Thread)];
+
+Cyg_Thread *th;
+
+//cyg_tick_count one_sec;
+cyg_tick_count watchdog_delay;
+
+// -------------------------------------------------------------------------
+// Thread body
+
+volatile int watchdog_accuracy = 50;
+
+void watchdog_thread( CYG_ADDRWORD id )
+{
+ diag_printf("Test of watchdog timer accuracy. Expect the test to run\n"
+ "for at least 10 times the watchdog timeout time. After\n"
+ "that time you may have to reset the board manually and/or\n"
+ "restart GDB which tends to get a little confused.\n");
+ diag_printf("When you get contact with the board again, read the value\n"
+ "in watchdog_accuracy - it should be close to 100 if the\n"
+ "watchdog timer is accurate.\n");
+
+ // Disable data cache so the variable in memory gets updated.
+ HAL_DCACHE_SYNC();
+ HAL_DCACHE_DISABLE();
+
+ Cyg_Watchdog::watchdog.start();
+ Cyg_Watchdog::watchdog.reset();
+
+ while (watchdog_accuracy < 400) {
+ Cyg_Watchdog::watchdog.reset();
+ th->delay( watchdog_delay*watchdog_accuracy/100 );
+ watchdog_accuracy += 5;
+ }
+
+ CYG_TEST_FAIL_FINISH("Watchdog failed to reset board. "
+ "Timer value is off by at least a factor of 4!");
+}
+
+// -------------------------------------------------------------------------
+
+
+externC void
+cyg_start( void )
+{
+ CYG_TEST_INIT();
+
+#if !defined(CYGIMP_WATCHDOG_EMULATE) && defined(CYGPKG_HAL_MN10300_STDEVAL1)
+ // Workaround for PR 17974
+ if( cyg_test_is_simulator )
+ CYG_TEST_NA("Watchdog device not implemented in MN10300 simulator.");
+#endif
+
+
+ Cyg_Clock::cyg_resolution res = Cyg_Clock::real_time_clock->get_resolution();
+
+ cyg_uint64 wres = Cyg_Watchdog::watchdog.get_resolution();
+
+ // Calculate how many clock ticks there are in a watchdog cycle.
+
+ watchdog_delay = ((cyg_tick_count)wres * (cyg_tick_count)res.divisor );
+ watchdog_delay /= res.dividend;
+
+ th = new((void *)&thread) Cyg_Thread(CYG_SCHED_DEFAULT_INFO,
+ watchdog_thread,
+ 0,
+ "watchdog_thread",
+ (CYG_ADDRESS)thread_stack,
+ STACKSIZE
+ );
+
+ th->resume();
+
+ // Get the world going
+ Cyg_Scheduler::scheduler.start();
+
+}
+
+#else // CYGFUN_KERNEL_THREADS_TIMER etc...
+#define N_A_MSG "Needs kernel RTC/threads timer"
+#endif
+
+#else // CYGPKG_KERNEL
+#define N_A_MSG "Needs Kernel"
+#endif
+
+#ifdef N_A_MSG
+void
+cyg_start( void )
+{
+ CYG_TEST_INIT();
+ CYG_TEST_NA( N_A_MSG);
+}
+#endif // N_A_MSG
+
+// -------------------------------------------------------------------------
+// EOF watchdog_reset.cxx