source: rtems/c/src/lib/libbsp/sparc/leon3/timer/watchdog.c @ 4a7d1026

4.115
Last change on this file since 4a7d1026 was 4a7d1026, checked in by Daniel Hellstrom <daniel@…>, on 04/13/15 at 08:25:52

sparc bsps: updated license to rtems.org

  • Property mode set to 100644
File size: 2.3 KB
Line 
1/*  GPTIMER Watchdog timer routines. On some systems the first GPTIMER
2 *  core's last Timer instance underflow signal is connected to system
3 *  reset.
4 *
5 *  COPYRIGHT (c) 2012.
6 *  Cobham Gaisler AB.
7 *
8 *  The license and distribution terms for this file may be
9 *  found in the file LICENSE in this distribution or at
10 *  http://www.rtems.org/license/LICENSE.
11 */
12
13#include <bsp.h>
14#include <bsp/watchdog.h>
15#include <grlib.h>
16
17extern volatile struct gptimer_regs *LEON3_Timer_Regs;
18
19struct gptimer_watchdog_priv {
20  struct gptimer_regs *regs;
21  struct gptimer_timer_regs *timer;
22  int timerno;
23};
24
25struct gptimer_watchdog_priv bsp_watchdogs[1];
26int bsp_watchdog_count = 0;
27
28int bsp_watchdog_init(void)
29{
30  int timercnt;
31
32  if (!LEON3_Timer_Regs)
33    return 0;
34
35  /* Get Watchdogs in system, this is implemented for one GPTIMER core
36   * only.
37   *
38   * First watchdog is a special case, we can get the first timer core by
39   * looking at LEON3_Timer_Regs, the watchdog within a timer core is
40   * always the last timer. Unfortunately we can not know it the watchdog
41   * functionality is available or not, we assume that it is if we
42   * reached this function.
43   */
44  bsp_watchdogs[0].regs = (struct gptimer_regs *)LEON3_Timer_Regs;
45
46  /* Find Timer that has watchdog functionality */
47  timercnt = bsp_watchdogs[0].regs->cfg & 0x7;
48  if (timercnt < 2) /* First timer system clock timer */
49    return 0;
50
51  bsp_watchdogs[0].timerno = timercnt - 1;
52  bsp_watchdogs[0].timer = &bsp_watchdogs[0].regs->timer[bsp_watchdogs[0].timerno];
53
54  bsp_watchdog_count = 1;
55  return bsp_watchdog_count;
56}
57
58void bsp_watchdog_reload(int watchdog, unsigned int reload_value)
59{
60  if (bsp_watchdog_count == 0)
61    bsp_watchdog_init();
62
63  if (bsp_watchdog_count <= watchdog)
64    return;
65
66  /* Kick watchdog, and clear interrupt pending bit */
67  bsp_watchdogs[watchdog].timer->reload = reload_value;
68  bsp_watchdogs[watchdog].timer->ctrl =
69    (GPTIMER_TIMER_CTRL_LD | GPTIMER_TIMER_CTRL_EN) |
70    (bsp_watchdogs[watchdog].timer->ctrl & ~(1<<4));
71}
72
73void bsp_watchdog_stop(int watchdog)
74{
75  if (bsp_watchdog_count == 0)
76    bsp_watchdog_init();
77
78  if (bsp_watchdog_count <= watchdog)
79    return;
80
81  /* Stop watchdog timer */
82  bsp_watchdogs[watchdog].timer->ctrl = 0;
83}
84
85/* Use watchdog timer to reset system */
86void bsp_watchdog_system_reset(void)
87{
88  sparc_disable_interrupts();
89  bsp_watchdog_reload(0, 1);
90}
Note: See TracBrowser for help on using the repository browser.