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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [devs/] [watchdog/] [arm/] [sa11x0/] [current/] [src/] [watchdog_sa11x0.cxx] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
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 Free Software Foundation, 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      
16
// version.                                                                 
17
//
18
// eCos is distributed in the hope that it will be useful, but WITHOUT      
19
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or    
20
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License    
21
// for more details.                                                        
22
//
23
// You should have received a copy of the GNU General Public License        
24
// along with eCos; if not, write to the Free Software Foundation, Inc.,    
25
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.            
26
//
27
// As a special exception, if other files instantiate templates or use      
28
// macros or inline functions from this file, or you compile this file      
29
// and link it with other works to produce a work based on this file,       
30
// this file does not by itself cause the resulting work to be covered by   
31
// the GNU General Public License. However the source code for this file    
32
// must still be made available in accordance with section (3) of the GNU   
33
// General Public License v2.                                               
34
//
35
// This exception does not invalidate any other reasons why a work based    
36
// on this file might be covered by the GNU General Public License.         
37
// -------------------------------------------                              
38
// ####ECOSGPLCOPYRIGHTEND####                                              
39
//==========================================================================
40
//#####DESCRIPTIONBEGIN####
41
//
42
// Author(s):    hmt, jskov (based on the MN10300 watchdog code by nickg)
43
// Contributors: jskov, nickg
44
// Date:         2001-02-27
45
// Purpose:      Watchdog class implementation
46
// Description:  Contains an implementation of the Watchdog class for use
47
//               with the SA11X0 hardware watchdog timer.
48
//
49
//####DESCRIPTIONEND####
50
//
51
//==========================================================================
52
 
53
#include <pkgconf/system.h>             // system configuration file
54
#include <pkgconf/watchdog.h>           // configuration for this package
55
#include <pkgconf/kernel.h>             // kernel config
56
 
57
#include <cyg/infra/cyg_trac.h>         // tracing macros
58
#include <cyg/kernel/instrmnt.h>        // instrumentation
59
 
60
#include <cyg/hal/hal_io.h>             // IO register access
61
#include <cyg/hal/hal_intr.h>           // Interrupts
62
#include <cyg/hal/hal_sa11x0.h>         // IO registers per se
63
 
64
#include <cyg/io/watchdog.hxx>          // watchdog API
65
 
66
// -------------------------------------------------------------------------
67
// SA11x0 watchdog works by enabling the watchdog (duh!) which means that
68
// when OS Timer Match Register #3 "OSMR3" compares equal to the 3.6864MHz
69
// clock in OSCR, then the system resets.
70
//
71
// To stay ahead of this, we must repeatedly set OSMR3 to OSCR + K where K
72
// is the watchdog timeout.  This REQUIRES that the OSCR be freerunning.
73
//
74
// OSCR runs at 3.6864MHz, so one second is 3686400 ticks.
75
// 
76
// The match register is 32 bits, and wraps as an int32 does (the
77
// comparison is exact, so you don't need to take special care.)  So we can
78
// literally do the addition in the obvious way.
79
 
80
#define WATCHDOG_TIMER_TICKS            3686400
81
#define WATCHDOG_RESOLUTION             (1000000000)
82
 
83
// -------------------------------------------------------------------------
84
// Constructor
85
 
86
void
87
Cyg_Watchdog::init_hw(void)
88
{
89
    CYG_REPORT_FUNCTION();
90
 
91
    // HW doesn't need init
92
 
93
    resolution          = WATCHDOG_RESOLUTION;
94
 
95
    CYG_REPORT_RETURN();
96
}
97
 
98
 
99
 
100
// -------------------------------------------------------------------------
101
// Start the watchdog running.
102
 
103
void
104
Cyg_Watchdog::start(void)
105
{
106
    int old;
107
    CYG_REPORT_FUNCTION();
108
 
109
    HAL_DISABLE_INTERRUPTS( old );
110
 
111
    // Init the watchdog timer.
112
    *SA11X0_OSMR3 = *SA11X0_OSCR + WATCHDOG_TIMER_TICKS;
113
    *SA11X0_OSSR = SA11X0_OSSR_TIMER3; // Ack any pending intr
114
    *SA11X0_OIER |= SA11X0_OIER_TIMER3; // Enable interrupt is necessary
115
 
116
    CYG_ASSERT( *SA11X0_OSCR < *SA11X0_OSMR3 ||
117
                *SA11X0_OSMR3 <= WATCHDOG_TIMER_TICKS, "Watchdog wierdness" );
118
 
119
    // Enable the watchdog.
120
    *SA11X0_OWER = SA11X0_OWER_ENABLE;
121
 
122
    HAL_RESTORE_INTERRUPTS( old );
123
 
124
    CYG_REPORT_RETURN();
125
}
126
 
127
// -------------------------------------------------------------------------
128
// Reset watchdog timer. This needs to be called regularly to prevent
129
// the watchdog firing.
130
 
131
void
132
Cyg_Watchdog::reset()
133
{
134
    CYG_REPORT_FUNCTION();
135
 
136
    *SA11X0_OSMR3 = *SA11X0_OSCR + WATCHDOG_TIMER_TICKS;
137
 
138
    CYG_ASSERT( *SA11X0_OSCR < *SA11X0_OSMR3 ||
139
                *SA11X0_OSMR3 <= WATCHDOG_TIMER_TICKS, "Watchdog wierdness" );
140
 
141
    CYG_REPORT_RETURN();
142
}
143
 
144
 
145
// -------------------------------------------------------------------------
146
// EOF watchdog_sa11x0.cxx

powered by: WebSVN 2.1.0

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