OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [io/] [watchdog/] [v2_0/] [src/] [emulate.cxx] - Blame information for rev 565

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
//==========================================================================
2
//
3
//      io/watchdog/emulate.cxx
4
//
5
//      Watchdog implementation emulation
6
//
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.
12
//
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.
16
//
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
20
// for more details.
21
//
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.
25
//
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.
32
//
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.
35
//
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####
42
//
43
// Author(s):   nickg
44
// Contributors:        nickg
45
// Date:        1998-07-29
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.
50
//
51
//####DESCRIPTIONEND####
52
//
53
//==========================================================================
54
 
55
#include <pkgconf/watchdog.h>           // watchdog configuration file
56
#include <pkgconf/kernel.h>             // Kernel config
57
 
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
62
 
63
#include <cyg/kernel/clock.hxx>         // clock and alarm
64
#include <cyg/kernel/sched.hxx>         // scheduler
65
 
66
#include <cyg/io/watchdog.hxx>          // watchdog API
67
 
68
#include <cyg/kernel/sched.inl>         // scheduler inlines
69
 
70
// -------------------------------------------------------------------------
71
// Forward definitions
72
 
73
static cyg_alarm_fn    watchdog_alarm;
74
 
75
// -------------------------------------------------------------------------
76
// Statics
77
 
78
static Cyg_Alarm alarm( Cyg_Clock::real_time_clock, watchdog_alarm, 0 );
79
 
80
// One second's worth of ticks.
81
static cyg_tick_count one_sec;
82
 
83
// -------------------------------------------------------------------------
84
// HW init
85
 
86
void
87
Cyg_Watchdog::init_hw(void)
88
{
89
    CYG_REPORT_FUNCTION();
90
 
91
    Cyg_Clock::cyg_resolution res = Cyg_Clock::real_time_clock->get_resolution();
92
 
93
    one_sec             = ( res.divisor * 1000000000LL ) / res.dividend ;
94
 
95
    resolution          = 1000000000LL;
96
 
97
    CYG_REPORT_RETURN();
98
}
99
 
100
// -------------------------------------------------------------------------
101
// Start the watchdog running.
102
 
103
void Cyg_Watchdog::start()
104
{
105
    CYG_REPORT_FUNCTION();
106
 
107
    Cyg_Clock::cyg_resolution res = Cyg_Clock::real_time_clock->get_resolution();
108
 
109
    // Set alarm to a one second single-shot trigger
110
    alarm.initialize( Cyg_Clock::real_time_clock->current_value() + one_sec, 0 );
111
 
112
    CYG_REPORT_RETURN();
113
}
114
 
115
// -------------------------------------------------------------------------
116
// Reset watchdog timer. This needs to be called regularly to prevent
117
// the watchdog firing.
118
 
119
void Cyg_Watchdog::reset()
120
{
121
    CYG_REPORT_FUNCTION();
122
 
123
    Cyg_Clock::cyg_resolution res = Cyg_Clock::real_time_clock->get_resolution();
124
 
125
    Cyg_Scheduler::lock();
126
 
127
    // Set alarm to a one second single-shot trigger
128
    alarm.initialize( Cyg_Clock::real_time_clock->current_value() + one_sec, 0 );
129
 
130
    Cyg_Scheduler::unlock();
131
 
132
    CYG_REPORT_RETURN();
133
}
134
 
135
// -------------------------------------------------------------------------
136
// Alarm function
137
 
138
void watchdog_alarm( Cyg_Alarm *a, CYG_ADDRWORD data)
139
{
140
    CYG_REPORT_FUNCTION();
141
 
142
    // Disable alarm just in case
143
    alarm.disable();
144
 
145
    Cyg_Watchdog::watchdog.trigger();
146
}
147
 
148
// -------------------------------------------------------------------------
149
// EOF watchdog/emulate.cxx

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.