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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [CORTEX_LM3S811_GCC/] [hw_include/] [watchdog.c] - Blame information for rev 581

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 581 jeremybenn
//*****************************************************************************
2
//
3
// watchdog.c - Driver for the Watchdog Timer Module.
4
//
5
// Copyright (c) 2005,2006 Luminary Micro, Inc.  All rights reserved.
6
//
7
// Software License Agreement
8
//
9
// Luminary Micro, Inc. (LMI) is supplying this software for use solely and
10
// exclusively on LMI's Stellaris Family of microcontroller products.
11
//
12
// The software is owned by LMI and/or its suppliers, and is protected under
13
// applicable copyright laws.  All rights are reserved.  Any use in violation
14
// of the foregoing restrictions may subject the user to criminal sanctions
15
// under applicable laws, as well as to civil liability for the breach of the
16
// terms and conditions of this license.
17
//
18
// THIS SOFTWARE IS PROVIDED "AS IS".  NO WARRANTIES, WHETHER EXPRESS, IMPLIED
19
// OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
20
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
21
// LMI SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
22
// CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
23
//
24
// This is part of revision 991 of the Stellaris Driver Library.
25
//
26
//*****************************************************************************
27
 
28
//*****************************************************************************
29
//
30
//! \addtogroup watchdog_api
31
//! @{
32
//
33
//*****************************************************************************
34
 
35
#include "../hw_ints.h"
36
#include "../hw_memmap.h"
37
#include "../hw_types.h"
38
#include "../hw_watchdog.h"
39
#include "debug.h"
40
#include "interrupt.h"
41
#include "watchdog.h"
42
 
43
//*****************************************************************************
44
//
45
//! Determines if the watchdog timer is enabled.
46
//!
47
//! \param ulBase is the base address of the watchdog timer module.
48
//!
49
//! This will check to see if the watchdog timer is enabled.
50
//!
51
//! \return Returns \b true if the watchdog timer is enabled, and \b false
52
//! if it is not.
53
//
54
//*****************************************************************************
55
#if defined(GROUP_running) || defined(BUILD_ALL) || defined(DOXYGEN)
56
tBoolean
57
WatchdogRunning(unsigned long ulBase)
58
{
59
    //
60
    // Check the arguments.
61
    //
62
    ASSERT(ulBase == WATCHDOG_BASE);
63
 
64
    //
65
    // See if the watchdog timer module is enabled, and return.
66
    //
67
    return(HWREG(ulBase + WDT_O_CTL) & WDT_CTL_INTEN);
68
}
69
#endif
70
 
71
//*****************************************************************************
72
//
73
//! Enables the watchdog timer.
74
//!
75
//! \param ulBase is the base address of the watchdog timer module.
76
//!
77
//! This will enable the watchdog timer counter and interrupt.
78
//!
79
//! \note This function will have no effect if the watchdog timer has
80
//! been locked.
81
//!
82
//! \sa WatchdogLock(), WatchdogUnlock()
83
//!
84
//! \return None.
85
//
86
//*****************************************************************************
87
#if defined(GROUP_enable) || defined(BUILD_ALL) || defined(DOXYGEN)
88
void
89
WatchdogEnable(unsigned long ulBase)
90
{
91
    //
92
    // Check the arguments.
93
    //
94
    ASSERT(ulBase == WATCHDOG_BASE);
95
 
96
    //
97
    // Enable the watchdog timer module.
98
    //
99
    HWREG(ulBase + WDT_O_CTL) |= WDT_CTL_INTEN;
100
}
101
#endif
102
 
103
//*****************************************************************************
104
//
105
//! Enables the watchdog timer reset.
106
//!
107
//! \param ulBase is the base address of the watchdog timer module.
108
//!
109
//! Enables the capability of the watchdog timer to issue a reset to the
110
//! processor upon a second timeout condition.
111
//!
112
//! \note This function will have no effect if the watchdog timer has
113
//! been locked.
114
//!
115
//! \sa WatchdogLock(), WatchdogUnlock()
116
//!
117
//! \return None.
118
//
119
//*****************************************************************************
120
#if defined(GROUP_resetenable) || defined(BUILD_ALL) || defined(DOXYGEN)
121
void
122
WatchdogResetEnable(unsigned long ulBase)
123
{
124
    //
125
    // Check the arguments.
126
    //
127
    ASSERT(ulBase == WATCHDOG_BASE);
128
 
129
    //
130
    // Enable the watchdog reset.
131
    //
132
    HWREG(ulBase + WDT_O_CTL) |= WDT_CTL_RESEN;
133
}
134
#endif
135
 
136
//*****************************************************************************
137
//
138
//! Disables the watchdog timer reset.
139
//!
140
//! \param ulBase is the base address of the watchdog timer module.
141
//!
142
//! Disables the capability of the watchdog timer to issue a reset to the
143
//! processor upon a second timeout condition.
144
//!
145
//! \note This function will have no effect if the watchdog timer has
146
//! been locked.
147
//!
148
//! \sa WatchdogLock(), WatchdogUnlock()
149
//!
150
//! \return None.
151
//
152
//*****************************************************************************
153
#if defined(GROUP_resetdisable) || defined(BUILD_ALL) || defined(DOXYGEN)
154
void
155
WatchdogResetDisable(unsigned long ulBase)
156
{
157
    //
158
    // Check the arguments.
159
    //
160
    ASSERT(ulBase == WATCHDOG_BASE);
161
 
162
    //
163
    // Disable the watchdog reset.
164
    //
165
    HWREG(ulBase + WDT_O_CTL) &= ~(WDT_CTL_RESEN);
166
}
167
#endif
168
 
169
//*****************************************************************************
170
//
171
//! Enables the watchdog timer lock mechanism.
172
//!
173
//! \param ulBase is the base address of the watchdog timer module.
174
//!
175
//! Locks out write access to the watchdog timer configuration registers.
176
//!
177
//! \return None.
178
//
179
//*****************************************************************************
180
#if defined(GROUP_lock) || defined(BUILD_ALL) || defined(DOXYGEN)
181
void
182
WatchdogLock(unsigned long ulBase)
183
{
184
    //
185
    // Check the arguments.
186
    //
187
    ASSERT(ulBase == WATCHDOG_BASE);
188
 
189
    //
190
    // Lock out watchdog register writes.  Writing anything to the WDT_O_LOCK
191
    // register causes the lock to go into effect.
192
    //
193
    HWREG(ulBase + WDT_O_LOCK) = WDT_LOCK_LOCKED;
194
}
195
#endif
196
 
197
//*****************************************************************************
198
//
199
//! Disables the watchdog timer lock mechanism.
200
//!
201
//! \param ulBase is the base address of the watchdog timer module.
202
//!
203
//! Enables write access to the watchdog timer configuration registers.
204
//!
205
//! \return None.
206
//
207
//*****************************************************************************
208
#if defined(GROUP_unlock) || defined(BUILD_ALL) || defined(DOXYGEN)
209
void
210
WatchdogUnlock(unsigned long ulBase)
211
{
212
    //
213
    // Check the arguments.
214
    //
215
    ASSERT(ulBase == WATCHDOG_BASE);
216
 
217
    //
218
    // Unlock watchdog register writes.
219
    //
220
    HWREG(ulBase + WDT_O_LOCK) = WDT_LOCK_UNLOCK;
221
}
222
#endif
223
 
224
//*****************************************************************************
225
//
226
//! Gets the state of the watchdog timer lock mechanism.
227
//!
228
//! \param ulBase is the base address of the watchdog timer module.
229
//!
230
//! Returns the lock state of the watchdog timer registers.
231
//!
232
//! \return Returns \b true if the watchdog timer registers are locked, and
233
//! \b false if they are not locked.
234
//
235
//*****************************************************************************
236
#if defined(GROUP_lockstate) || defined(BUILD_ALL) || defined(DOXYGEN)
237
tBoolean
238
WatchdogLockState(unsigned long ulBase)
239
{
240
    //
241
    // Check the arguments.
242
    //
243
    ASSERT(ulBase == WATCHDOG_BASE);
244
 
245
    //
246
    // Get the lock state.
247
    //
248
    return((HWREG(ulBase + WDT_O_LOCK) == WDT_LOCK_LOCKED) ? true : false);
249
}
250
#endif
251
 
252
//*****************************************************************************
253
//
254
//! Sets the watchdog timer reload value.
255
//!
256
//! \param ulBase is the base address of the watchdog timer module.
257
//! \param ulLoadVal is the load value for the watchdog timer.
258
//!
259
//! This function sets the value to load into the watchdog timer when the count
260
//! reaches zero for the first time; if the watchdog timer is running when this
261
//! function is called, then the value will be immediately loaded into the
262
//! watchdog timer counter. If the parameter \e ulLoadVal is 0, then an
263
//! interrupt is immediately generated.
264
//!
265
//! \note This function will have no effect if the watchdog timer has
266
//! been locked.
267
//!
268
//! \sa WatchdogLock(), WatchdogUnlock(), WatchdogReloadGet()
269
//!
270
//! \return None.
271
//
272
//*****************************************************************************
273
#if defined(GROUP_reloadset) || defined(BUILD_ALL) || defined(DOXYGEN)
274
void
275
WatchdogReloadSet(unsigned long ulBase, unsigned long ulLoadVal)
276
{
277
    //
278
    // Check the arguments.
279
    //
280
    ASSERT(ulBase == WATCHDOG_BASE);
281
 
282
    //
283
    // Set the load register.
284
    //
285
    HWREG(ulBase + WDT_O_LOAD) = ulLoadVal;
286
}
287
#endif
288
 
289
//*****************************************************************************
290
//
291
//! Gets the watchdog timer reload value.
292
//!
293
//! \param ulBase is the base address of the watchdog timer module.
294
//!
295
//! This function gets the value that is loaded into the watchdog timer when
296
//! the count reaches zero for the first time.
297
//!
298
//! \sa WatchdogReloadSet()
299
//!
300
//! \return None.
301
//
302
//*****************************************************************************
303
#if defined(GROUP_reloadget) || defined(BUILD_ALL) || defined(DOXYGEN)
304
unsigned long
305
WatchdogReloadGet(unsigned long ulBase)
306
{
307
    //
308
    // Check the arguments.
309
    //
310
    ASSERT(ulBase == WATCHDOG_BASE);
311
 
312
    //
313
    // Get the load register.
314
    //
315
    return(HWREG(ulBase + WDT_O_LOAD));
316
}
317
#endif
318
 
319
//*****************************************************************************
320
//
321
//! Gets the current watchdog timer value.
322
//!
323
//! \param ulBase is the base address of the watchdog timer module.
324
//!
325
//! This function reads the current value of the watchdog timer.
326
//!
327
//! \return Returns the current value of the watchdog timer.
328
//
329
//*****************************************************************************
330
#if defined(GROUP_valueget) || defined(BUILD_ALL) || defined(DOXYGEN)
331
unsigned long
332
WatchdogValueGet(unsigned long ulBase)
333
{
334
    //
335
    // Check the arguments.
336
    //
337
    ASSERT(ulBase == WATCHDOG_BASE);
338
 
339
    //
340
    // Get the current watchdog timer register value.
341
    //
342
    return(HWREG(ulBase + WDT_O_VALUE));
343
}
344
#endif
345
 
346
//*****************************************************************************
347
//
348
//! Registers an interrupt handler for watchdog timer interrupt.
349
//!
350
//! \param ulBase is the base address of the watchdog timer module.
351
//! \param pfnHandler is a pointer to the function to be called when the
352
//! watchdog timer interrupt occurs.
353
//!
354
//! This function does the actual registering of the interrupt handler.  This
355
//! will enable the global interrupt in the interrupt controller; the watchdog
356
//! timer interrupt must be enabled via WatchdogEnable(). It is the interrupt
357
//! handler's responsibility to clear the interrupt source via
358
//! WatchdogIntClear().
359
//!
360
//! \sa IntRegister() for important information about registering interrupt
361
//! handlers.
362
//!
363
//! \return None.
364
//
365
//*****************************************************************************
366
#if defined(GROUP_intregister) || defined(BUILD_ALL) || defined(DOXYGEN)
367
void
368
WatchdogIntRegister(unsigned long ulBase, void (*pfnHandler)(void))
369
{
370
    //
371
    // Check the arguments.
372
    //
373
    ASSERT(ulBase == WATCHDOG_BASE);
374
 
375
    //
376
    // Register the interrupt handler.
377
    //
378
    IntRegister(INT_WATCHDOG, pfnHandler);
379
 
380
    //
381
    // Enable the watchdog timer interrupt.
382
    //
383
    IntEnable(INT_WATCHDOG);
384
}
385
#endif
386
 
387
//*****************************************************************************
388
//
389
//! Unregisters an interrupt handler for the watchdog timer interrupt.
390
//!
391
//! \param ulBase is the base address of the watchdog timer module.
392
//!
393
//! This function does the actual unregistering of the interrupt handler.  This
394
//! function will clear the handler to be called when a watchdog timer
395
//! interrupt occurs.  This will also mask off the interrupt in the interrupt
396
//! controller so that the interrupt handler no longer is called.
397
//!
398
//! \sa IntRegister() for important information about registering interrupt
399
//! handlers.
400
//!
401
//! \return None.
402
//
403
//*****************************************************************************
404
#if defined(GROUP_intunregister) || defined(BUILD_ALL) || defined(DOXYGEN)
405
void
406
WatchdogIntUnregister(unsigned long ulBase)
407
{
408
    //
409
    // Check the arguments.
410
    //
411
    ASSERT(ulBase == WATCHDOG_BASE);
412
 
413
    //
414
    // Disable the interrupt.
415
    //
416
    IntDisable(INT_WATCHDOG);
417
 
418
    //
419
    // Unregister the interrupt handler.
420
    //
421
    IntUnregister(INT_WATCHDOG);
422
}
423
#endif
424
 
425
//*****************************************************************************
426
//
427
//! Enables the watchdog timer interrupt.
428
//!
429
//! \param ulBase is the base address of the watchdog timer module.
430
//!
431
//! Enables the watchdog timer interrupt.
432
//!
433
//! \note This function will have no effect if the watchdog timer has
434
//! been locked.
435
//!
436
//! \sa WatchdogLock(), WatchdogUnlock(), WatchdogEnable()
437
//!
438
//! \return None.
439
//
440
//*****************************************************************************
441
#if defined(GROUP_intenable) || defined(BUILD_ALL) || defined(DOXYGEN)
442
void
443
WatchdogIntEnable(unsigned long ulBase)
444
{
445
    //
446
    // Check the arguments.
447
    //
448
    ASSERT(ulBase == WATCHDOG_BASE);
449
 
450
    //
451
    // Enable the watchdog interrupt.
452
    //
453
    HWREG(ulBase + WDT_O_CTL) |= WDT_CTL_INTEN;
454
}
455
#endif
456
 
457
//*****************************************************************************
458
//
459
//! Gets the current watchdog timer interrupt status.
460
//!
461
//! \param ulBase is the base address of the watchdog timer module.
462
//! \param bMasked is \b false if the raw interrupt status is required and
463
//! \b true if the masked interrupt status is required.
464
//!
465
//! This returns the interrupt status for the watchdog timer module.  Either
466
//! the raw interrupt status or the status of interrupt that is allowed to
467
//! reflect to the processor can be returned.
468
//!
469
//! \return The current interrupt status, where a 1 indicates that the watchdog
470
//! interrupt is active, and a 0 indicates that it is not active.
471
//
472
//*****************************************************************************
473
#if defined(GROUP_intstatus) || defined(BUILD_ALL) || defined(DOXYGEN)
474
unsigned long
475
WatchdogIntStatus(unsigned long ulBase, tBoolean bMasked)
476
{
477
    //
478
    // Check the arguments.
479
    //
480
    ASSERT(ulBase == WATCHDOG_BASE);
481
 
482
    //
483
    // Return either the interrupt status or the raw interrupt status as
484
    // requested.
485
    //
486
    if(bMasked)
487
    {
488
        return(HWREG(ulBase + WDT_O_MIS));
489
    }
490
    else
491
    {
492
        return(HWREG(ulBase + WDT_O_RIS));
493
    }
494
}
495
#endif
496
 
497
//*****************************************************************************
498
//
499
//! Clears the watchdog timer interrupt.
500
//!
501
//! \param ulBase is the base address of the watchdog timer module.
502
//!
503
//! The watchdog timer interrupt source is cleared, so that it no longer
504
//! asserts.
505
//!
506
//! \return None.
507
//
508
//*****************************************************************************
509
#if defined(GROUP_intclear) || defined(BUILD_ALL) || defined(DOXYGEN)
510
void
511
WatchdogIntClear(unsigned long ulBase)
512
{
513
    //
514
    // Check the arguments.
515
    //
516
    ASSERT(ulBase == WATCHDOG_BASE);
517
 
518
    //
519
    // Clear the interrupt source.
520
    //
521
    HWREG(ulBase + WDT_O_ICR) = WDT_INT_TIMEOUT;
522
}
523
#endif
524
 
525
//*****************************************************************************
526
//
527
//! Enables stalling of the watchdog timer during debug events.
528
//!
529
//! \param ulBase is the base address of the watchdog timer module.
530
//!
531
//! This function allows the watchdog timer to stop counting when the processor
532
//! is stopped by the debugger.  By doing so, the watchdog is prevented from
533
//! expiring (typically almost immediately from a human time perspective) and
534
//! resetting the system (if reset is enabled).  The watchdog will instead
535
//! expired after the appropriate number of processor cycles have been executed
536
//! while debugging (or at the appropriate time after the processor has been
537
//! restarted).
538
//!
539
//! \return None.
540
//
541
//*****************************************************************************
542
#if defined(GROUP_stallenable) || defined(BUILD_ALL) || defined(DOXYGEN)
543
void
544
WatchdogStallEnable(unsigned long ulBase)
545
{
546
    //
547
    // Check the arguments.
548
    //
549
    ASSERT(ulBase == WATCHDOG_BASE);
550
 
551
    //
552
    // Enable timer stalling.
553
    //
554
    HWREG(ulBase + WDT_O_TEST) |= WDT_TEST_STALL;
555
}
556
#endif
557
 
558
//*****************************************************************************
559
//
560
//! Disables stalling of the watchdog timer during debug events.
561
//!
562
//! \param ulBase is the base address of the watchdog timer module.
563
//!
564
//! This function disables the debug mode stall of the watchdog timer.  By
565
//! doing so, the watchdog timer continues to count regardless of the processor
566
//! debug state.
567
//!
568
//! \return None.
569
//
570
//*****************************************************************************
571
#if defined(GROUP_stalldisable) || defined(BUILD_ALL) || defined(DOXYGEN)
572
void
573
WatchdogStallDisable(unsigned long ulBase)
574
{
575
    //
576
    // Check the arguments.
577
    //
578
    ASSERT(ulBase == WATCHDOG_BASE);
579
 
580
    //
581
    // Disable timer stalling.
582
    //
583
    HWREG(ulBase + WDT_O_TEST) &= ~(WDT_TEST_STALL);
584
}
585
#endif
586
 
587
//*****************************************************************************
588
//
589
// Close the Doxygen group.
590
//! @}
591
//
592
//*****************************************************************************

powered by: WebSVN 2.1.0

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