annotate packages/devs/watchdog/arm/at91/current/src/watchdog_at91.cxx @ 2729:74dbf4c3f2e1 after-copyright-change-20090129

Update all copyright banners to reflect FSF ownership; fix and improve licence text.
author jlarmour
date Thu, 29 Jan 2009 17:47:46 +0000
parents ac3572aaf2c9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
266
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
1 //==========================================================================
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
2 //
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
3 // devs/watchdog/arm/at91/watchdog_at91.cxx
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
4 //
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
5 // Watchdog implementation for ARM AT91 CPU
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
6 //
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
7 //==========================================================================
2729
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1797
diff changeset
8 // ####ECOSGPLCOPYRIGHTBEGIN####
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1797
diff changeset
9 // -------------------------------------------
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1797
diff changeset
10 // This file is part of eCos, the Embedded Configurable Operating System.
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1797
diff changeset
11 // Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
266
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
12 //
2729
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1797
diff changeset
13 // eCos is free software; you can redistribute it and/or modify it under
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1797
diff changeset
14 // the terms of the GNU General Public License as published by the Free
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1797
diff changeset
15 // Software Foundation; either version 2 or (at your option) any later
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1797
diff changeset
16 // version.
266
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
17 //
2729
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1797
diff changeset
18 // eCos is distributed in the hope that it will be useful, but WITHOUT
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1797
diff changeset
19 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1797
diff changeset
20 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1797
diff changeset
21 // for more details.
266
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
22 //
2729
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1797
diff changeset
23 // You should have received a copy of the GNU General Public License
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1797
diff changeset
24 // along with eCos; if not, write to the Free Software Foundation, Inc.,
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1797
diff changeset
25 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
266
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
26 //
2729
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1797
diff changeset
27 // As a special exception, if other files instantiate templates or use
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1797
diff changeset
28 // macros or inline functions from this file, or you compile this file
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1797
diff changeset
29 // and link it with other works to produce a work based on this file,
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1797
diff changeset
30 // this file does not by itself cause the resulting work to be covered by
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1797
diff changeset
31 // the GNU General Public License. However the source code for this file
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1797
diff changeset
32 // must still be made available in accordance with section (3) of the GNU
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1797
diff changeset
33 // General Public License v2.
266
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
34 //
2729
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1797
diff changeset
35 // This exception does not invalidate any other reasons why a work based
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1797
diff changeset
36 // on this file might be covered by the GNU General Public License.
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1797
diff changeset
37 // -------------------------------------------
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1797
diff changeset
38 // ####ECOSGPLCOPYRIGHTEND####
266
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
39 //==========================================================================
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
40 //#####DESCRIPTIONBEGIN####
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
41 //
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
42 // Author(s): tkoeller
1015
d4f4e1fb283b * src/watchdog_at91.cxx:
nickg
parents: 266
diff changeset
43 // Contributors: tkoeller, nickg
266
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
44 // Date: 2002-05-05
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
45 // Purpose: Watchdog class implementation
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
46 // Description: Contains an implementation of the Watchdog class for use
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
47 // with the ATMEL AT91 watchdog timer.
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
48 //
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
49 //####DESCRIPTIONEND####
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
50 //
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
51 //==========================================================================
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
52
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
53 #include <pkgconf/kernel.h>
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
54 #include <pkgconf/infra.h>
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
55 #include <pkgconf/kernel.h>
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
56 #include <pkgconf/watchdog.h>
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
57 #include <pkgconf/devs_watchdog_arm_at91.h>
1015
d4f4e1fb283b * src/watchdog_at91.cxx:
nickg
parents: 266
diff changeset
58
266
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
59 #include <cyg/infra/cyg_type.h>
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
60 #include <cyg/infra/cyg_ass.h>
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
61 #include <cyg/infra/cyg_trac.h>
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
62 #include <cyg/hal/hal_io.h>
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
63 #include <cyg/hal/hal_diag.h>
1015
d4f4e1fb283b * src/watchdog_at91.cxx:
nickg
parents: 266
diff changeset
64
266
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
65 #include <cyg/io/watchdog.hxx>
1015
d4f4e1fb283b * src/watchdog_at91.cxx:
nickg
parents: 266
diff changeset
66
266
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
67 #if !defined(CYGSEM_WATCHDOG_RESETS_ON_TIMEOUT)
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
68 #include <cyg/hal/hal_platform_ints.h>
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
69 #include <cyg/kernel/intr.hxx>
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
70 #endif
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
71
1015
d4f4e1fb283b * src/watchdog_at91.cxx:
nickg
parents: 266
diff changeset
72 //==========================================================================
d4f4e1fb283b * src/watchdog_at91.cxx:
nickg
parents: 266
diff changeset
73
d4f4e1fb283b * src/watchdog_at91.cxx:
nickg
parents: 266
diff changeset
74 #define MCLK_FREQUENCY_KHZ (CYGNUM_HAL_ARM_AT91_CLOCK_SPEED/1000)
266
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
75 #define MAX_TICKS 0x0000ffff
1015
d4f4e1fb283b * src/watchdog_at91.cxx:
nickg
parents: 266
diff changeset
76 #define BASE_TICKS (MCLK_FREQUENCY_KHZ * CYGNUM_DEVS_WATCHDOG_ARM_AT91_DESIRED_TIMEOUT_MS)
d4f4e1fb283b * src/watchdog_at91.cxx:
nickg
parents: 266
diff changeset
77
d4f4e1fb283b * src/watchdog_at91.cxx:
nickg
parents: 266
diff changeset
78 #if defined(CYGHWR_HAL_ARM_AT91_R40008) || \
d4f4e1fb283b * src/watchdog_at91.cxx:
nickg
parents: 266
diff changeset
79 defined(CYGHWR_HAL_ARM_AT91_R40807)
266
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
80
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
81 #if BASE_TICKS / 8 <= MAX_TICKS
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
82 #define DIVIDER 0
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
83 #define DIV_FACTOR 8
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
84 #elif BASE_TICKS / 32 <= MAX_TICKS
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
85 #define DIVIDER 1
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
86 #define DIV_FACTOR 32
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
87 #elif BASE_TICKS / 128 <= MAX_TICKS
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
88 #define DIVIDER 2
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
89 #define DIV_FACTOR 128
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
90 #elif BASE_TICKS / 1024 <= MAX_TICKS
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
91 #define DIVIDER 3
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
92 #define DIV_FACTOR 1024
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
93 #else
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
94 #error Desired resolution beyond hardware capabilities
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
95 #endif
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
96
1015
d4f4e1fb283b * src/watchdog_at91.cxx:
nickg
parents: 266
diff changeset
97 #elif defined(CYGHWR_HAL_ARM_AT91_M55800A)
d4f4e1fb283b * src/watchdog_at91.cxx:
nickg
parents: 266
diff changeset
98
d4f4e1fb283b * src/watchdog_at91.cxx:
nickg
parents: 266
diff changeset
99 #if BASE_TICKS / 32 <= MAX_TICKS
d4f4e1fb283b * src/watchdog_at91.cxx:
nickg
parents: 266
diff changeset
100 #define DIVIDER 0
d4f4e1fb283b * src/watchdog_at91.cxx:
nickg
parents: 266
diff changeset
101 #define DIV_FACTOR 32
d4f4e1fb283b * src/watchdog_at91.cxx:
nickg
parents: 266
diff changeset
102 #elif BASE_TICKS / 128 <= MAX_TICKS
d4f4e1fb283b * src/watchdog_at91.cxx:
nickg
parents: 266
diff changeset
103 #define DIVIDER 1
d4f4e1fb283b * src/watchdog_at91.cxx:
nickg
parents: 266
diff changeset
104 #define DIV_FACTOR 128
d4f4e1fb283b * src/watchdog_at91.cxx:
nickg
parents: 266
diff changeset
105 #elif BASE_TICKS / 1024 <= MAX_TICKS
d4f4e1fb283b * src/watchdog_at91.cxx:
nickg
parents: 266
diff changeset
106 #define DIVIDER 2
d4f4e1fb283b * src/watchdog_at91.cxx:
nickg
parents: 266
diff changeset
107 #define DIV_FACTOR 1024
d4f4e1fb283b * src/watchdog_at91.cxx:
nickg
parents: 266
diff changeset
108 #elif BASE_TICKS / 4096 <= MAX_TICKS
d4f4e1fb283b * src/watchdog_at91.cxx:
nickg
parents: 266
diff changeset
109 #define DIVIDER 3
d4f4e1fb283b * src/watchdog_at91.cxx:
nickg
parents: 266
diff changeset
110 #define DIV_FACTOR 4096
d4f4e1fb283b * src/watchdog_at91.cxx:
nickg
parents: 266
diff changeset
111 #else
d4f4e1fb283b * src/watchdog_at91.cxx:
nickg
parents: 266
diff changeset
112 #error Desired resolution beyond hardware capabilities
d4f4e1fb283b * src/watchdog_at91.cxx:
nickg
parents: 266
diff changeset
113 #endif
1797
ac3572aaf2c9 * src/watchdog_at91.cxx:
asl
parents: 1015
diff changeset
114 #elif defined(CYGHWR_HAL_ARM_AT91_JTST)
ac3572aaf2c9 * src/watchdog_at91.cxx:
asl
parents: 1015
diff changeset
115 #if BASE_TICKS / 32 <= MAX_TICKS
ac3572aaf2c9 * src/watchdog_at91.cxx:
asl
parents: 1015
diff changeset
116 #define DIVIDER 0
ac3572aaf2c9 * src/watchdog_at91.cxx:
asl
parents: 1015
diff changeset
117 #define DIV_FACTOR 32
ac3572aaf2c9 * src/watchdog_at91.cxx:
asl
parents: 1015
diff changeset
118 #elif BASE_TICKS / 128 <= MAX_TICKS
ac3572aaf2c9 * src/watchdog_at91.cxx:
asl
parents: 1015
diff changeset
119 #define DIVIDER 1
ac3572aaf2c9 * src/watchdog_at91.cxx:
asl
parents: 1015
diff changeset
120 #define DIV_FACTOR 128
ac3572aaf2c9 * src/watchdog_at91.cxx:
asl
parents: 1015
diff changeset
121 #elif BASE_TICKS / 1024 <= MAX_TICKS
ac3572aaf2c9 * src/watchdog_at91.cxx:
asl
parents: 1015
diff changeset
122 #define DIVIDER 2
ac3572aaf2c9 * src/watchdog_at91.cxx:
asl
parents: 1015
diff changeset
123 #define DIV_FACTOR 1024
ac3572aaf2c9 * src/watchdog_at91.cxx:
asl
parents: 1015
diff changeset
124 #elif BASE_TICKS / 2046 <= MAX_TICKS
ac3572aaf2c9 * src/watchdog_at91.cxx:
asl
parents: 1015
diff changeset
125 #define DIVIDER 3
ac3572aaf2c9 * src/watchdog_at91.cxx:
asl
parents: 1015
diff changeset
126 #define DIV_FACTOR 2046
ac3572aaf2c9 * src/watchdog_at91.cxx:
asl
parents: 1015
diff changeset
127 #else
ac3572aaf2c9 * src/watchdog_at91.cxx:
asl
parents: 1015
diff changeset
128 #error Desired resolution beyond hardware capabilities
ac3572aaf2c9 * src/watchdog_at91.cxx:
asl
parents: 1015
diff changeset
129 #endif
1015
d4f4e1fb283b * src/watchdog_at91.cxx:
nickg
parents: 266
diff changeset
130
d4f4e1fb283b * src/watchdog_at91.cxx:
nickg
parents: 266
diff changeset
131 #endif
d4f4e1fb283b * src/watchdog_at91.cxx:
nickg
parents: 266
diff changeset
132
266
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
133 #define TICKS ((BASE_TICKS / DIV_FACTOR) | 0xfff)
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
134 #define RESOLUTION ((cyg_uint64) (TICKS * DIV_FACTOR ) * 1000000 / MCLK_FREQUENCY_KHZ)
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
135
1015
d4f4e1fb283b * src/watchdog_at91.cxx:
nickg
parents: 266
diff changeset
136 //==========================================================================
266
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
137
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
138 #if defined(CYGSEM_WATCHDOG_RESETS_ON_TIMEOUT)
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
139
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
140 #define OMRVAL (AT91_WD_OMR_OKEY | AT91_WD_OMR_RSTEN | AT91_WD_OMR_WDEN)
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
141
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
142 void
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
143 Cyg_Watchdog::init_hw(void)
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
144 {
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
145 CYG_REPORT_FUNCTION();
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
146 CYG_REPORT_FUNCARGVOID();
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
147 resolution = RESOLUTION;
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
148 CYG_REPORT_RETURN();
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
149 }
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
150
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
151 #else /* defined(CYGSEM_WATCHDOG_RESETS_ON_TIMEOUT) */
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
152
1015
d4f4e1fb283b * src/watchdog_at91.cxx:
nickg
parents: 266
diff changeset
153 //==========================================================================
d4f4e1fb283b * src/watchdog_at91.cxx:
nickg
parents: 266
diff changeset
154
266
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
155 #define OMRVAL (AT91_WD_OMR_OKEY | AT91_WD_OMR_IRQEN | AT91_WD_OMR_WDEN)
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
156 #define INT_PRIO 7
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
157
1015
d4f4e1fb283b * src/watchdog_at91.cxx:
nickg
parents: 266
diff changeset
158 //==========================================================================
266
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
159
1015
d4f4e1fb283b * src/watchdog_at91.cxx:
nickg
parents: 266
diff changeset
160 static Cyg_Watchdog *wd;
d4f4e1fb283b * src/watchdog_at91.cxx:
nickg
parents: 266
diff changeset
161
d4f4e1fb283b * src/watchdog_at91.cxx:
nickg
parents: 266
diff changeset
162 //==========================================================================
266
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
163
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
164 static cyg_uint32
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
165 isr(cyg_vector vector, CYG_ADDRWORD data)
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
166 {
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
167 CYG_REPORT_FUNCTION();
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
168 CYG_REPORT_FUNCARG2XV(vector, data);
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
169
1015
d4f4e1fb283b * src/watchdog_at91.cxx:
nickg
parents: 266
diff changeset
170 wd->trigger();
266
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
171 Cyg_Interrupt::acknowledge_interrupt(CYGNUM_HAL_INTERRUPT_WATCHDOG);
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
172 CYG_REPORT_RETVAL(Cyg_Interrupt::HANDLED);
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
173 return Cyg_Interrupt::HANDLED;
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
174 }
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
175
1015
d4f4e1fb283b * src/watchdog_at91.cxx:
nickg
parents: 266
diff changeset
176 //==========================================================================
d4f4e1fb283b * src/watchdog_at91.cxx:
nickg
parents: 266
diff changeset
177
d4f4e1fb283b * src/watchdog_at91.cxx:
nickg
parents: 266
diff changeset
178 static Cyg_Interrupt wdint(
d4f4e1fb283b * src/watchdog_at91.cxx:
nickg
parents: 266
diff changeset
179 CYGNUM_HAL_INTERRUPT_WATCHDOG,
d4f4e1fb283b * src/watchdog_at91.cxx:
nickg
parents: 266
diff changeset
180 INT_PRIO,
d4f4e1fb283b * src/watchdog_at91.cxx:
nickg
parents: 266
diff changeset
181 0,
d4f4e1fb283b * src/watchdog_at91.cxx:
nickg
parents: 266
diff changeset
182 isr,
d4f4e1fb283b * src/watchdog_at91.cxx:
nickg
parents: 266
diff changeset
183 NULL
d4f4e1fb283b * src/watchdog_at91.cxx:
nickg
parents: 266
diff changeset
184 );
d4f4e1fb283b * src/watchdog_at91.cxx:
nickg
parents: 266
diff changeset
185
d4f4e1fb283b * src/watchdog_at91.cxx:
nickg
parents: 266
diff changeset
186 //==========================================================================
266
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
187
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
188 void
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
189 Cyg_Watchdog::init_hw(void)
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
190 {
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
191 CYG_REPORT_FUNCTION();
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
192 CYG_REPORT_FUNCARGVOID();
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
193
1015
d4f4e1fb283b * src/watchdog_at91.cxx:
nickg
parents: 266
diff changeset
194 wd = this;
266
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
195 resolution = RESOLUTION;
1015
d4f4e1fb283b * src/watchdog_at91.cxx:
nickg
parents: 266
diff changeset
196 wdint.configure_interrupt(CYGNUM_HAL_INTERRUPT_WATCHDOG, false, true);
d4f4e1fb283b * src/watchdog_at91.cxx:
nickg
parents: 266
diff changeset
197 wdint.attach();
d4f4e1fb283b * src/watchdog_at91.cxx:
nickg
parents: 266
diff changeset
198 wdint.acknowledge_interrupt(CYGNUM_HAL_INTERRUPT_WATCHDOG);
d4f4e1fb283b * src/watchdog_at91.cxx:
nickg
parents: 266
diff changeset
199 wdint.unmask_interrupt(CYGNUM_HAL_INTERRUPT_WATCHDOG);
266
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
200 CYG_REPORT_RETURN();
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
201 }
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
202
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
203 #endif /* defined(CYGSEM_WATCHDOG_RESETS_ON_TIMEOUT) */
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
204
1015
d4f4e1fb283b * src/watchdog_at91.cxx:
nickg
parents: 266
diff changeset
205 //==========================================================================
266
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
206 /*
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
207 * Reset watchdog timer. This needs to be called regularly to prevent
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
208 * the watchdog from firing.
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
209 */
1015
d4f4e1fb283b * src/watchdog_at91.cxx:
nickg
parents: 266
diff changeset
210
266
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
211 void
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
212 Cyg_Watchdog::reset(void)
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
213 {
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
214 CYG_REPORT_FUNCTION();
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
215 CYG_REPORT_FUNCARGVOID();
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
216
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
217 /* Write magic code to reset the watchdog. */
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
218 HAL_WRITE_UINT32(AT91_WD + AT91_WD_CR, AT91_WD_CR_RSTKEY);
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
219 CYG_REPORT_RETURN();
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
220 }
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
221
1015
d4f4e1fb283b * src/watchdog_at91.cxx:
nickg
parents: 266
diff changeset
222 //==========================================================================
266
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
223 /*
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
224 * Start watchdog to generate a hardware reset
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
225 * or interrupt when expiring.
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
226 */
1015
d4f4e1fb283b * src/watchdog_at91.cxx:
nickg
parents: 266
diff changeset
227
266
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
228 void
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
229 Cyg_Watchdog::start(void)
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
230 {
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
231 CYG_REPORT_FUNCTION();
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
232 CYG_REPORT_FUNCARGVOID();
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
233
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
234 HAL_WRITE_UINT32(AT91_WD + AT91_WD_OMR, AT91_WD_OMR_OKEY);
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
235 HAL_WRITE_UINT32(
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
236 AT91_WD + AT91_WD_CMR,
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
237 AT91_WD_CMR_CKEY | ((TICKS >> 10) & AT91_WD_CMR_HPCV) | DIVIDER
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
238 );
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
239 HAL_WRITE_UINT32(AT91_WD + AT91_WD_CR, AT91_WD_CR_RSTKEY);
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
240 HAL_WRITE_UINT32(AT91_WD + AT91_WD_OMR, OMRVAL);
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
241 CYG_REPORT_RETURN();
2f403b92a5ac Add contributed at91 watchdog from Thomas Koeller
jlarmour
parents:
diff changeset
242 }
1015
d4f4e1fb283b * src/watchdog_at91.cxx:
nickg
parents: 266
diff changeset
243
d4f4e1fb283b * src/watchdog_at91.cxx:
nickg
parents: 266
diff changeset
244 //==========================================================================
d4f4e1fb283b * src/watchdog_at91.cxx:
nickg
parents: 266
diff changeset
245 // End of watchdog_at91.cxx