static int WDT_open(struct inode *inode, struct file *filp) { if (wdt_opened != 0){ return -EBUSY; } wdt_opened++; WDT_disable(); WDT_disable_rst(); WDT_disable_intr(); #ifdef WDT_ACTION_RESET WDT_enable_rst(); #endif #ifdef WDT_ACTION_INTERRUPT fLib_SetIntTrig(IRQ_WATCHDOG, 1, 0); WDT_enable_intr(); if (request_irq(IRQ_WATCHDOG, WDT_interrupt, IRQF_DISABLED, "wdt", NULL)) { PDEBUG(KERN_ERR "Unable to allocate WDT IRQ=0x%X\n", IRQ_WATCHDOG); WDT_disable_intr(); return -EBUSY; } #endif WDT_enable(); WDT_margin = WDT_MARGIN; WDT_ping(); PDEBUG("WDT module open success\n"); return 0; }
void setup( void ) { NVM_ResetReason_t resetReason; /* Assume data is invalid to begin with */ g_sampleDataValid = false; WDT_init(); LED_init(); /* Initialize serial UART drivers */ Serial_init(); /* Initialize sensors */ GPS_init(); OBD_init(); /* Print or initialize the reset reason */ if ( NVM_getResetReason( &resetReason ) ) { /* Valid reset reason */ if ( NVM_RESET_REASON_NORMAL != resetReason ) { Log_printf( "Reset Reason: 0x%02X\n", resetReason ); } } else { /* Invalid reset reason, initialize it */ NVM_setResetReason( NVM_RESET_REASON_NORMAL ); } /* Start the watchdog timer */ WDT_enable( WDT_TIMEOUT_MAX ); }
static int WDT_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg) { unsigned long new_margin = 0; switch (cmd) { case WDIOC_SETMATCH: if (get_user(wdt_match, (unsigned long *)arg)) return -EFAULT; if (unlikely(wdt_match > ULONG_MAX/refclk)) return -EINVAL; writel(wdt_match * refclk, WDT_MMR_MATCH_VALUE); wdt_match = readl(WDT_MMR_MATCH_VALUE); PDEBUG("set match to %d\n", wdt_match); break; case WDIOC_KEEPALIVE: WDT_ping(); break; case WDIOC_SETTIMEOUT: if (get_user(new_margin, (unsigned long *) arg)) return -EFAULT; if (unlikely(new_margin > ULONG_MAX/refclk)) return -EINVAL; WDT_margin = new_margin; WDT_ping(); break; case WDIOC_GETTIMEOUT: return put_user(WDT_margin, (unsigned long *) arg); case WDIOC_ENABLE: WDT_enable(); WDT_ping(); break; case WDIOC_DISABLE: WDT_disable(); break; default: return -ENOTTY; } return 0; }