1 |
27 |
unneback |
//==========================================================================
|
2 |
|
|
//
|
3 |
|
|
// watchdog/sa11x0.cxx
|
4 |
|
|
//
|
5 |
|
|
// Watchdog implementation for StrongARM SA11x0s
|
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): hmt, jskov (based on the MN10300 watchdog code by nickg)
|
44 |
|
|
// Contributors: jskov, nickg
|
45 |
|
|
// Date: 2001-02-27
|
46 |
|
|
// Purpose: Watchdog class implementation
|
47 |
|
|
// Description: Contains an implementation of the Watchdog class for use
|
48 |
|
|
// with the SA11X0 hardware watchdog timer.
|
49 |
|
|
//
|
50 |
|
|
//####DESCRIPTIONEND####
|
51 |
|
|
//
|
52 |
|
|
//==========================================================================
|
53 |
|
|
|
54 |
|
|
#include <pkgconf/system.h> // system configuration file
|
55 |
|
|
#include <pkgconf/watchdog.h> // configuration for this package
|
56 |
|
|
#include <pkgconf/kernel.h> // kernel config
|
57 |
|
|
|
58 |
|
|
#include <cyg/infra/cyg_trac.h> // tracing macros
|
59 |
|
|
#include <cyg/kernel/instrmnt.h> // instrumentation
|
60 |
|
|
|
61 |
|
|
#include <cyg/hal/hal_io.h> // IO register access
|
62 |
|
|
#include <cyg/hal/hal_intr.h> // Interrupts
|
63 |
|
|
#include <cyg/hal/hal_sa11x0.h> // IO registers per se
|
64 |
|
|
|
65 |
|
|
#include <cyg/io/watchdog.hxx> // watchdog API
|
66 |
|
|
|
67 |
|
|
// -------------------------------------------------------------------------
|
68 |
|
|
// SA11x0 watchdog works by enabling the watchdog (duh!) which means that
|
69 |
|
|
// when OS Timer Match Register #3 "OSMR3" compares equal to the 3.6864MHz
|
70 |
|
|
// clock in OSCR, then the system resets.
|
71 |
|
|
//
|
72 |
|
|
// To stay ahead of this, we must repeatedly set OSMR3 to OSCR + K where K
|
73 |
|
|
// is the watchdog timeout. This REQUIRES that the OSCR be freerunning.
|
74 |
|
|
//
|
75 |
|
|
// OSCR runs at 3.6864MHz, so one second is 3686400 ticks.
|
76 |
|
|
//
|
77 |
|
|
// The match register is 32 bits, and wraps as an int32 does (the
|
78 |
|
|
// comparison is exact, so you don't need to take special care.) So we can
|
79 |
|
|
// literally do the addition in the obvious way.
|
80 |
|
|
|
81 |
|
|
#define WATCHDOG_TIMER_TICKS 3686400
|
82 |
|
|
#define WATCHDOG_RESOLUTION (1000000000)
|
83 |
|
|
|
84 |
|
|
// -------------------------------------------------------------------------
|
85 |
|
|
// Constructor
|
86 |
|
|
|
87 |
|
|
void
|
88 |
|
|
Cyg_Watchdog::init_hw(void)
|
89 |
|
|
{
|
90 |
|
|
CYG_REPORT_FUNCTION();
|
91 |
|
|
|
92 |
|
|
// HW doesn't need init
|
93 |
|
|
|
94 |
|
|
resolution = WATCHDOG_RESOLUTION;
|
95 |
|
|
|
96 |
|
|
CYG_REPORT_RETURN();
|
97 |
|
|
}
|
98 |
|
|
|
99 |
|
|
|
100 |
|
|
|
101 |
|
|
// -------------------------------------------------------------------------
|
102 |
|
|
// Start the watchdog running.
|
103 |
|
|
|
104 |
|
|
void
|
105 |
|
|
Cyg_Watchdog::start(void)
|
106 |
|
|
{
|
107 |
|
|
int old;
|
108 |
|
|
CYG_REPORT_FUNCTION();
|
109 |
|
|
|
110 |
|
|
HAL_DISABLE_INTERRUPTS( old );
|
111 |
|
|
|
112 |
|
|
// Init the watchdog timer.
|
113 |
|
|
*SA11X0_OSMR3 = *SA11X0_OSCR + WATCHDOG_TIMER_TICKS;
|
114 |
|
|
*SA11X0_OSSR = SA11X0_OSSR_TIMER3; // Ack any pending intr
|
115 |
|
|
*SA11X0_OIER |= SA11X0_OIER_TIMER3; // Enable interrupt is necessary
|
116 |
|
|
|
117 |
|
|
CYG_ASSERT( *SA11X0_OSCR < *SA11X0_OSMR3 ||
|
118 |
|
|
*SA11X0_OSMR3 <= WATCHDOG_TIMER_TICKS, "Watchdog wierdness" );
|
119 |
|
|
|
120 |
|
|
// Enable the watchdog.
|
121 |
|
|
*SA11X0_OWER = SA11X0_OWER_ENABLE;
|
122 |
|
|
|
123 |
|
|
HAL_RESTORE_INTERRUPTS( old );
|
124 |
|
|
|
125 |
|
|
CYG_REPORT_RETURN();
|
126 |
|
|
}
|
127 |
|
|
|
128 |
|
|
// -------------------------------------------------------------------------
|
129 |
|
|
// Reset watchdog timer. This needs to be called regularly to prevent
|
130 |
|
|
// the watchdog firing.
|
131 |
|
|
|
132 |
|
|
void
|
133 |
|
|
Cyg_Watchdog::reset()
|
134 |
|
|
{
|
135 |
|
|
CYG_REPORT_FUNCTION();
|
136 |
|
|
|
137 |
|
|
*SA11X0_OSMR3 = *SA11X0_OSCR + WATCHDOG_TIMER_TICKS;
|
138 |
|
|
|
139 |
|
|
CYG_ASSERT( *SA11X0_OSCR < *SA11X0_OSMR3 ||
|
140 |
|
|
*SA11X0_OSMR3 <= WATCHDOG_TIMER_TICKS, "Watchdog wierdness" );
|
141 |
|
|
|
142 |
|
|
CYG_REPORT_RETURN();
|
143 |
|
|
}
|
144 |
|
|
|
145 |
|
|
|
146 |
|
|
// -------------------------------------------------------------------------
|
147 |
|
|
// EOF watchdog_sa11x0.cxx
|