123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- /*
- * (C) Copyright 2004, Li-Pro.Net <www.li-pro.net>
- * Stephan Linz <linz@li-pro.net>
- *
- * See file CREDITS for list of people who contributed to this
- * project.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
- * MA 02111-1307 USA
- */
- #include <common.h>
- #include <command.h>
- #include <nios.h>
- #include <nios-io.h>
- #if defined(CONFIG_HW_WATCHDOG)
- #if !defined(CONFIG_HW_WDENA_BASE)
- #error "*** CONFIG_HW_WDENA_BASE not defined ***"
- #if !defined(CONFIG_HW_WDENA_BIT)
- #error "*** CONFIG_HW_WDENA_BIT not defined ***"
- #endif
- #endif
- #if !defined(CONFIG_HW_WDTOG_BASE)
- #error "*** CONFIG_HW_WDTOG_BASE not defined ***"
- #if !defined(CONFIG_HW_WDTOG_BIT)
- #error "*** CONFIG_HW_WDTOG_BIT not defined ***"
- #endif
- #endif
- #ifdef CONFIG_HW_WDPORT_WRONLY /* emulate read access */
- static unsigned __wd_ena_pio_portval = 0;
- #endif
- #define WD_PIO_INIT_DONE(V) ((V) & (1 << CONFIG_HW_WDENA_BIT))
- void ssv_wd_pio_init(void)
- {
- nios_pio_t *ena_piop = (nios_pio_t*)CONFIG_HW_WDENA_BASE;
- nios_pio_t *trg_piop = (nios_pio_t*)CONFIG_HW_WDTOG_BASE;
- trg_piop->data &= ~(1 << CONFIG_HW_WDTOG_BIT);
- #ifdef CONFIG_HW_WDPORT_WRONLY /* emulate read access */
- __wd_ena_pio_portval |= (1 << CONFIG_HW_WDENA_BIT);
- ena_piop->data = __wd_ena_pio_portval;
- #else /* !CONFIG_HW_WDPORT_WRONLY */
- trg_piop->direction |= (1 << CONFIG_HW_WDTOG_BIT);
- ena_piop->data |= (1 << CONFIG_HW_WDENA_BIT);
- ena_piop->direction |= (1 << CONFIG_HW_WDENA_BIT);
- #endif /* CONFIG_HW_WDPORT_WRONLY */
- }
- void ssv_wd_pio_done(void)
- {
- nios_pio_t *piop = (nios_pio_t*)CONFIG_HW_WDENA_BASE;
- #ifdef CONFIG_HW_WDPORT_WRONLY /* emulate read access */
- __wd_ena_pio_portval &= ~(1 << CONFIG_HW_WDENA_BIT);
- piop->data = __wd_ena_pio_portval;
- #else /* !CONFIG_HW_WDPORT_WRONLY */
- piop->data &= ~(1 << CONFIG_HW_WDENA_BIT);
- #endif /* CONFIG_HW_WDPORT_WRONLY */
- }
- void ssv_wd_pio_reset(void)
- {
- nios_pio_t *trg_piop = (nios_pio_t*)CONFIG_HW_WDTOG_BASE;
- #ifdef CONFIG_HW_WDPORT_WRONLY
- if (WD_PIO_INIT_DONE(__wd_ena_pio_portval))
- #else
- nios_pio_t *ena_piop = (nios_pio_t*)CONFIG_HW_WDENA_BASE;
- if (WD_PIO_INIT_DONE(ena_piop->data))
- #endif
- {
- trg_piop->data |= (1 << CONFIG_HW_WDTOG_BIT);
- trg_piop->data &= ~(1 << CONFIG_HW_WDTOG_BIT);
- }
- }
- void hw_watchdog_reset(void)
- {
- int re_enable = disable_interrupts ();
- ssv_wd_pio_reset();
- if (re_enable)
- enable_interrupts ();
- }
- #if defined(CONFIG_CMD_BSP)
- int do_wd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
- {
- nios_pio_t *ena_piop = (nios_pio_t*)CONFIG_HW_WDENA_BASE;
- switch (argc)
- {
- case 1:
- printf ("Watchdog timer status is %s\n",
- #ifdef CONFIG_HW_WDPORT_WRONLY
- WD_PIO_INIT_DONE(__wd_ena_pio_portval)
- #else
- WD_PIO_INIT_DONE(ena_piop->data)
- #endif
- ? "on" : "off");
- return 0;
- case 2:
- if (!strcmp(argv[1],"on"))
- {
- ssv_wd_pio_init();
- printf("Watchdog timer now is on\n");
- return 0;
- }
- else if (!strcmp(argv[1],"off"))
- {
- ssv_wd_pio_done();
- printf("Watchdog timer now is off\n");
- return 0;
- }
- break;
- default:
- break;
- }
- cmd_usage(cmdtp);
- return 1;
- }
- U_BOOT_CMD(
- wd, 2, 1, do_wd,
- "check and set watchdog",
- "on - switch watchDog on\n"
- "wd off - switch watchdog off\n"
- "wd - print current status"
- );
- #endif
- #endif /* CONFIG_HW_WATCHDOG */
|