2 * (C) Copyright 2004, Li-Pro.Net <www.li-pro.net>
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
29 #if defined(CONFIG_HW_WATCHDOG)
31 #if !defined(CONFIG_HW_WDENA_BASE)
32 #error "*** CONFIG_HW_WDENA_BASE not defined ***"
33 #if !defined(CONFIG_HW_WDENA_BIT)
34 #error "*** CONFIG_HW_WDENA_BIT not defined ***"
38 #if !defined(CONFIG_HW_WDTOG_BASE)
39 #error "*** CONFIG_HW_WDTOG_BASE not defined ***"
40 #if !defined(CONFIG_HW_WDTOG_BIT)
41 #error "*** CONFIG_HW_WDTOG_BIT not defined ***"
45 #ifdef CONFIG_HW_WDPORT_WRONLY /* emulate read access */
46 static unsigned __wd_ena_pio_portval = 0;
49 #define WD_PIO_INIT_DONE(V) ((V) & (1 << CONFIG_HW_WDENA_BIT))
51 void ssv_wd_pio_init(void)
53 nios_pio_t *ena_piop = (nios_pio_t*)CONFIG_HW_WDENA_BASE;
54 nios_pio_t *trg_piop = (nios_pio_t*)CONFIG_HW_WDTOG_BASE;
56 trg_piop->data &= ~(1 << CONFIG_HW_WDTOG_BIT);
58 #ifdef CONFIG_HW_WDPORT_WRONLY /* emulate read access */
60 __wd_ena_pio_portval |= (1 << CONFIG_HW_WDENA_BIT);
61 ena_piop->data = __wd_ena_pio_portval;
63 #else /* !CONFIG_HW_WDPORT_WRONLY */
65 trg_piop->direction |= (1 << CONFIG_HW_WDTOG_BIT);
67 ena_piop->data |= (1 << CONFIG_HW_WDENA_BIT);
68 ena_piop->direction |= (1 << CONFIG_HW_WDENA_BIT);
70 #endif /* CONFIG_HW_WDPORT_WRONLY */
73 void ssv_wd_pio_done(void)
75 nios_pio_t *piop = (nios_pio_t*)CONFIG_HW_WDENA_BASE;
77 #ifdef CONFIG_HW_WDPORT_WRONLY /* emulate read access */
79 __wd_ena_pio_portval &= ~(1 << CONFIG_HW_WDENA_BIT);
80 piop->data = __wd_ena_pio_portval;
82 #else /* !CONFIG_HW_WDPORT_WRONLY */
84 piop->data &= ~(1 << CONFIG_HW_WDENA_BIT);
86 #endif /* CONFIG_HW_WDPORT_WRONLY */
89 void ssv_wd_pio_reset(void)
91 nios_pio_t *trg_piop = (nios_pio_t*)CONFIG_HW_WDTOG_BASE;
93 #ifdef CONFIG_HW_WDPORT_WRONLY
94 if (WD_PIO_INIT_DONE(__wd_ena_pio_portval))
96 nios_pio_t *ena_piop = (nios_pio_t*)CONFIG_HW_WDENA_BASE;
98 if (WD_PIO_INIT_DONE(ena_piop->data))
101 trg_piop->data |= (1 << CONFIG_HW_WDTOG_BIT);
102 trg_piop->data &= ~(1 << CONFIG_HW_WDTOG_BIT);
106 void hw_watchdog_reset(void)
108 int re_enable = disable_interrupts ();
112 enable_interrupts ();
115 #if defined(CONFIG_CMD_BSP)
116 int do_wd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
118 nios_pio_t *ena_piop = (nios_pio_t*)CONFIG_HW_WDENA_BASE;
123 printf ("Watchdog timer status is %s\n",
124 #ifdef CONFIG_HW_WDPORT_WRONLY
125 WD_PIO_INIT_DONE(__wd_ena_pio_portval)
127 WD_PIO_INIT_DONE(ena_piop->data)
132 if (!strcmp(argv[1],"on"))
135 printf("Watchdog timer now is on\n");
138 else if (!strcmp(argv[1],"off"))
141 printf("Watchdog timer now is off\n");
154 "check and set watchdog",
155 "on - switch watchDog on\n"
156 "wd off - switch watchdog off\n"
157 "wd - print current status\n"
160 #endif /* CONFIG_HW_WATCHDOG */