1 |
786 |
skrzyp |
//==========================================================================
|
2 |
|
|
//
|
3 |
|
|
// devs/watchdog/arm/at91/watchdog_at91wdtc.cxx
|
4 |
|
|
//
|
5 |
|
|
// Watchdog implementation for ARM AT91 CPUs using the WDTC
|
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, 2003, 2006, 2009 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): tkoeller
|
43 |
|
|
// Contributors: tkoeller, nickg, asl
|
44 |
|
|
// Date: 2006-02-18
|
45 |
|
|
// Purpose: Watchdog class implementation
|
46 |
|
|
// Description: Contains an implementation of the Watchdog class for use
|
47 |
|
|
// with the ATMEL AT91 watchdog timer controller.
|
48 |
|
|
//
|
49 |
|
|
//####DESCRIPTIONEND####
|
50 |
|
|
//
|
51 |
|
|
//==========================================================================
|
52 |
|
|
|
53 |
|
|
#include <pkgconf/kernel.h>
|
54 |
|
|
#include <pkgconf/infra.h>
|
55 |
|
|
#include <pkgconf/kernel.h>
|
56 |
|
|
#include <pkgconf/watchdog.h>
|
57 |
|
|
#include <pkgconf/devs_watchdog_arm_at91wdtc.h>
|
58 |
|
|
|
59 |
|
|
#include <cyg/infra/cyg_type.h>
|
60 |
|
|
#include <cyg/infra/cyg_ass.h>
|
61 |
|
|
#include <cyg/infra/cyg_trac.h>
|
62 |
|
|
#include <cyg/hal/hal_io.h>
|
63 |
|
|
#include <cyg/hal/hal_diag.h>
|
64 |
|
|
|
65 |
|
|
#include <cyg/io/watchdog.hxx>
|
66 |
|
|
|
67 |
|
|
#include <cyg/infra/diag.h>
|
68 |
|
|
|
69 |
|
|
#if !defined(CYGSEM_WATCHDOG_RESETS_ON_TIMEOUT)
|
70 |
|
|
#include <cyg/hal/hal_platform_ints.h>
|
71 |
|
|
#include <cyg/kernel/intr.hxx>
|
72 |
|
|
#endif
|
73 |
|
|
|
74 |
|
|
//==========================================================================
|
75 |
|
|
|
76 |
|
|
#if defined(CYGSEM_WATCHDOG_RESETS_ON_TIMEOUT)
|
77 |
|
|
|
78 |
|
|
#define MRVAL (AT91_WDTC_WDMR_RSTEN | AT91_WDTC_WDMR_DBGHLT)
|
79 |
|
|
|
80 |
|
|
void
|
81 |
|
|
Cyg_Watchdog::init_hw(void)
|
82 |
|
|
{
|
83 |
|
|
CYG_REPORT_FUNCTION();
|
84 |
|
|
CYG_REPORT_FUNCARGVOID();
|
85 |
|
|
resolution = CYGNUM_DEVS_WATCHDOG_ARM_AT91WDTC_DESIRED_TIMEOUT_MS * 1000000;
|
86 |
|
|
CYG_REPORT_RETURN();
|
87 |
|
|
}
|
88 |
|
|
|
89 |
|
|
#else /* defined(CYGSEM_WATCHDOG_RESETS_ON_TIMEOUT) */
|
90 |
|
|
|
91 |
|
|
//==========================================================================
|
92 |
|
|
|
93 |
|
|
#define MRVAL (AT91_WDTC_WDMR_FIEN | AT91_WDTC_WDMR_DBGHLT)
|
94 |
|
|
#define INT_PRIO 7
|
95 |
|
|
|
96 |
|
|
//==========================================================================
|
97 |
|
|
|
98 |
|
|
static Cyg_Watchdog *wd;
|
99 |
|
|
|
100 |
|
|
//==========================================================================
|
101 |
|
|
|
102 |
|
|
static cyg_uint32
|
103 |
|
|
isr(cyg_vector vector, CYG_ADDRWORD data)
|
104 |
|
|
{
|
105 |
|
|
cyg_uint32 sr;
|
106 |
|
|
CYG_REPORT_FUNCTION();
|
107 |
|
|
CYG_REPORT_FUNCARG2XV(vector, data);
|
108 |
|
|
|
109 |
|
|
// Read the status register to clear the interrupt
|
110 |
|
|
HAL_READ_UINT32(AT91_WDTC + AT91_WDTC_WDSR, sr);
|
111 |
|
|
|
112 |
|
|
wd->trigger();
|
113 |
|
|
Cyg_Interrupt::acknowledge_interrupt(CYGNUM_HAL_INTERRUPT_WDTC);
|
114 |
|
|
CYG_REPORT_RETVAL(Cyg_Interrupt::HANDLED);
|
115 |
|
|
return Cyg_Interrupt::HANDLED;
|
116 |
|
|
}
|
117 |
|
|
|
118 |
|
|
//==========================================================================
|
119 |
|
|
|
120 |
|
|
static CYGBLD_ATTRIB_INIT_PRI(CYG_INIT_INTERRUPTS)
|
121 |
|
|
Cyg_Interrupt wdint(
|
122 |
|
|
CYGNUM_HAL_INTERRUPT_WDTC,
|
123 |
|
|
INT_PRIO,
|
124 |
|
|
0,
|
125 |
|
|
isr,
|
126 |
|
|
NULL
|
127 |
|
|
);
|
128 |
|
|
|
129 |
|
|
//==========================================================================
|
130 |
|
|
|
131 |
|
|
void
|
132 |
|
|
Cyg_Watchdog::init_hw(void)
|
133 |
|
|
{
|
134 |
|
|
CYG_REPORT_FUNCTION();
|
135 |
|
|
CYG_REPORT_FUNCARGVOID();
|
136 |
|
|
|
137 |
|
|
wd = this;
|
138 |
|
|
|
139 |
|
|
wdint.attach();
|
140 |
|
|
wdint.acknowledge_interrupt(CYGNUM_HAL_INTERRUPT_WDTC);
|
141 |
|
|
wdint.unmask_interrupt(CYGNUM_HAL_INTERRUPT_WDTC);
|
142 |
|
|
resolution = CYGNUM_DEVS_WATCHDOG_ARM_AT91WDTC_DESIRED_TIMEOUT_MS * 1000000;
|
143 |
|
|
CYG_REPORT_RETURN();
|
144 |
|
|
}
|
145 |
|
|
|
146 |
|
|
#endif /* defined(CYGSEM_WATCHDOG_RESETS_ON_TIMEOUT) */
|
147 |
|
|
|
148 |
|
|
//==========================================================================
|
149 |
|
|
/*
|
150 |
|
|
* Reset watchdog timer. This needs to be called regularly to prevent
|
151 |
|
|
* the watchdog from firing.
|
152 |
|
|
*/
|
153 |
|
|
|
154 |
|
|
void
|
155 |
|
|
Cyg_Watchdog::reset(void)
|
156 |
|
|
{
|
157 |
|
|
CYG_REPORT_FUNCTION();
|
158 |
|
|
CYG_REPORT_FUNCARGVOID();
|
159 |
|
|
|
160 |
|
|
/* Write magic code to reset the watchdog. */
|
161 |
|
|
HAL_WRITE_UINT32(AT91_WDTC + AT91_WDTC_WDCR,
|
162 |
|
|
AT91_WDTC_WDCR_RELOAD | AT91_WDTC_WDCR_KEY);
|
163 |
|
|
|
164 |
|
|
CYG_REPORT_RETURN();
|
165 |
|
|
}
|
166 |
|
|
|
167 |
|
|
//==========================================================================
|
168 |
|
|
/*
|
169 |
|
|
* Start watchdog to generate a hardware reset
|
170 |
|
|
* or interrupt when expiring.
|
171 |
|
|
*/
|
172 |
|
|
|
173 |
|
|
void
|
174 |
|
|
Cyg_Watchdog::start(void)
|
175 |
|
|
{
|
176 |
|
|
cyg_uint32 val, val1;
|
177 |
|
|
|
178 |
|
|
CYG_REPORT_FUNCTION();
|
179 |
|
|
CYG_REPORT_FUNCARGVOID();
|
180 |
|
|
|
181 |
|
|
val = (MRVAL | CYGNUM_DEVS_WATCHDOG_ARM_AT91WDTC_TIMEOUT_VALUE |
|
182 |
|
|
(CYGNUM_DEVS_WATCHDOG_ARM_AT91WDTC_TIMEOUT_VALUE <<
|
183 |
|
|
AT91_WDTC_WDMR_WDD_SHIFT));
|
184 |
|
|
|
185 |
|
|
HAL_WRITE_UINT32(AT91_WDTC + AT91_WDTC_WDMR, val);
|
186 |
|
|
HAL_READ_UINT32(AT91_WDTC + AT91_WDTC_WDMR, val1);
|
187 |
|
|
|
188 |
|
|
// If this assert goes if it probably means something else has
|
189 |
|
|
// already programmed the watchdog. The mode register is only
|
190 |
|
|
// writeable once and once it is set it can only be reset by a
|
191 |
|
|
// processor reset.
|
192 |
|
|
CYG_ASSERT(val == val1, "Unable to configure watchdog");
|
193 |
|
|
|
194 |
|
|
CYG_REPORT_RETURN();
|
195 |
|
|
}
|
196 |
|
|
|
197 |
|
|
//==========================================================================
|
198 |
|
|
// End of watchdog_at91.cxx
|