1 //==========================================================================
3 // io/watchdog/emulate.cxx
5 // Watchdog implementation emulation
7 //==========================================================================
8 //####ECOSGPLCOPYRIGHTBEGIN####
9 // -------------------------------------------
10 // This file is part of eCos, the Embedded Configurable Operating System.
11 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
13 // eCos is free software; you can redistribute it and/or modify it under
14 // the terms of the GNU General Public License as published by the Free
15 // Software Foundation; either version 2 or (at your option) any later version.
17 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
18 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 // You should have received a copy of the GNU General Public License along
23 // with eCos; if not, write to the Free Software Foundation, Inc.,
24 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
26 // As a special exception, if other files instantiate templates or use macros
27 // or inline functions from this file, or you compile this file and link it
28 // with other works to produce a work based on this file, this file does not
29 // by itself cause the resulting work to be covered by the GNU General Public
30 // License. However the source code for this file must still be made available
31 // in accordance with section (3) of the GNU General Public License.
33 // This exception does not invalidate any other reasons why a work based on
34 // this file might be covered by the GNU General Public License.
36 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
37 // at http://sources.redhat.com/ecos/ecos-license/
38 // -------------------------------------------
39 //####ECOSGPLCOPYRIGHTEND####
40 //==========================================================================
41 //#####DESCRIPTIONBEGIN####
44 // Contributors: nickg
46 // Purpose: Watchdog class implementation
47 // Description: Contains an implementation of the Watchdog class for use
48 // when there is no hardware watchdog timer. Instead it is
49 // emulated using an Alarm object.
51 //####DESCRIPTIONEND####
53 //==========================================================================
55 #include <pkgconf/watchdog.h> // watchdog configuration file
56 #include <pkgconf/kernel.h> // Kernel config
58 #include <cyg/kernel/ktypes.h> // base kernel types
59 #include <cyg/infra/cyg_trac.h> // tracing macros
60 #include <cyg/infra/cyg_ass.h> // assertion macros
61 #include <cyg/kernel/instrmnt.h> // instrumentation
63 #include <cyg/kernel/clock.hxx> // clock and alarm
64 #include <cyg/kernel/sched.hxx> // scheduler
66 #include <cyg/io/watchdog.hxx> // watchdog API
68 #include <cyg/kernel/sched.inl> // scheduler inlines
70 // -------------------------------------------------------------------------
71 // Forward definitions
73 static cyg_alarm_fn watchdog_alarm;
75 // -------------------------------------------------------------------------
78 static Cyg_Alarm alarm( Cyg_Clock::real_time_clock, watchdog_alarm, 0 );
80 // One second's worth of ticks.
81 static cyg_tick_count one_sec;
83 // -------------------------------------------------------------------------
87 Cyg_Watchdog::init_hw(void)
89 CYG_REPORT_FUNCTION();
91 Cyg_Clock::cyg_resolution res = Cyg_Clock::real_time_clock->get_resolution();
93 one_sec = ( res.divisor * 1000000000LL ) / res.dividend ;
95 resolution = 1000000000LL;
100 // -------------------------------------------------------------------------
101 // Start the watchdog running.
103 void Cyg_Watchdog::start()
105 CYG_REPORT_FUNCTION();
107 Cyg_Clock::cyg_resolution res = Cyg_Clock::real_time_clock->get_resolution();
109 // Set alarm to a one second single-shot trigger
110 alarm.initialize( Cyg_Clock::real_time_clock->current_value() + one_sec, 0 );
115 // -------------------------------------------------------------------------
116 // Reset watchdog timer. This needs to be called regularly to prevent
117 // the watchdog firing.
119 void Cyg_Watchdog::reset()
121 CYG_REPORT_FUNCTION();
123 Cyg_Clock::cyg_resolution res = Cyg_Clock::real_time_clock->get_resolution();
125 Cyg_Scheduler::lock();
127 // Set alarm to a one second single-shot trigger
128 alarm.initialize( Cyg_Clock::real_time_clock->current_value() + one_sec, 0 );
130 Cyg_Scheduler::unlock();
135 // -------------------------------------------------------------------------
138 void watchdog_alarm( Cyg_Alarm *a, CYG_ADDRWORD data)
140 CYG_REPORT_FUNCTION();
142 // Disable alarm just in case
145 Cyg_Watchdog::watchdog.trigger();
148 // -------------------------------------------------------------------------
149 // EOF watchdog/emulate.cxx