eNET: Implement eNET Watchdog
authorGraeme Russ <graeme.russ@gmail.com>
Fri, 23 Apr 2010 14:05:58 +0000 (00:05 +1000)
committerWolfgang Denk <wd@denx.de>
Wed, 5 May 2010 22:20:04 +0000 (00:20 +0200)
Signed-off-by: Graeme Russ <graeme.russ@gmail.com>
board/eNET/eNET.c
board/eNET/hardware.h
include/configs/eNET.h

index ad71f7e5dcb43b46856c8df0266bd56bf682b181..7f0e2577f1bf1d4537cddb0cdd39c8cef17b21e3 100644 (file)
@@ -45,6 +45,9 @@ DECLARE_GLOBAL_DATA_PTR;
 
 unsigned long monitor_flash_len = CONFIG_SYS_MONITOR_LEN;
 
+static void enet_timer_isr(void);
+static void enet_toggle_run_led(void);
+
 void init_sc520_enet (void)
 {
        /* Set CPU Speed to 100MHz */
@@ -160,6 +163,10 @@ int last_stage_init(void)
 
        major = minor = 0;
 
+       outb(0x00, LED_LATCH_ADDRESS);
+
+       register_timer_isr (enet_timer_isr);
+
        printf("Serck Controls eNET\n");
 
        return 0;
@@ -218,3 +225,41 @@ void setup_pcat_compatibility()
        writeb(SC520_IRQ_DISABLED, &sc520_mmcr->wpvmap);
        writeb(SC520_IRQ_DISABLED, &sc520_mmcr->icemap);
 }
+
+void enet_timer_isr(void)
+{
+       static long enet_ticks = 0;
+
+       enet_ticks++;
+
+       /* Toggle Watchdog every 100ms */
+       if ((enet_ticks % 100) == 0)
+               hw_watchdog_reset();
+
+       /* Toggle Run LED every 500ms */
+       if ((enet_ticks % 500) == 0)
+               enet_toggle_run_led();
+}
+
+void hw_watchdog_reset(void)
+{
+       /* Watchdog Reset must be atomic */
+       long flag = disable_interrupts();
+
+       if (sc520_mmcr->piodata15_0 & WATCHDOG_PIO_BIT)
+               sc520_mmcr->pioclr15_0 = WATCHDOG_PIO_BIT;
+       else
+               sc520_mmcr->pioset15_0 = WATCHDOG_PIO_BIT;
+
+       if (flag)
+               enable_interrupts();
+}
+
+void enet_toggle_run_led(void)
+{
+       unsigned char leds_state= inb(LED_LATCH_ADDRESS);
+       if (leds_state & LED_RUN_BITMASK)
+               outb(leds_state &~ LED_RUN_BITMASK, LED_LATCH_ADDRESS);
+       else
+               outb(leds_state | LED_RUN_BITMASK, LED_LATCH_ADDRESS);
+}
index 42474a62fab0cca66cb587cfff12977798ac44ba..dec2cd8040683d673bae05b72de149be8ada5e19 100644 (file)
@@ -31,5 +31,6 @@
 #define LED_RX_BITMASK         0x08
 #define LED_TX_BITMASK         0x10
 #define LED_ERR_BITMASK                0x20
+#define WATCHDOG_PIO_BIT       0x8000
 
 #endif /* HARDWARE_H_ */
index 61897949dd93f33e310048363ba503ff70e26111..361fe61b04fdbef4e75cefe20ae6877b2cc8f04d 100644 (file)
@@ -53,7 +53,7 @@
  * bottom (processor) board MUST be removed!
  */
 #undef CONFIG_WATCHDOG
-#undef CONFIG_HW_WATCHDOG
+#define CONFIG_HW_WATCHDOG
 
  /*-----------------------------------------------------------------------
   * Serial Configuration
 #define CONFIG_NET_MULTI
 #define CONFIG_RTL8139
 
-/*-----------------------------------------------------------------------
- * Hardware watchdog configuration
- */
-#define CONFIG_SYS_WATCHDOG_PIO_BIT            0x8000
-#define CONFIG_SYS_WATCHDIG_PIO_DATA           SC520_PIODATA15_0
-#define CONFIG_SYS_WATCHDIG_PIO_CLR            SC520_PIOCLR15_0
-#define CONFIG_SYS_WATCHDIG_PIO_SET            SC520_PIOSET15_0
-
 /*-----------------------------------------------------------------------
  * FPGA configuration
  */