Chinaunix首页 | 论坛 | 博客
  • 博客访问: 315232
  • 博文数量: 135
  • 博客积分: 867
  • 博客等级: 准尉
  • 技术积分: 865
  • 用 户 组: 普通用户
  • 注册时间: 2012-03-15 14:50
文章分类

全部博文(135)

文章存档

2012年(135)

分类:

2012-09-19 11:39:23

原文地址:UBOOT WDT驱动流程 作者:iibull

#define ms_to_ticks(t)    (((t << 8) / 1000) - 1)
#define ticks_to_ms(t)    (((t + 1) * 1000) >> 8)

/* Hardware timeout in seconds */
#define WDT_HW_TIMEOUT 2

/*
 * Set the watchdog time interval in 1/256Hz (write-once)
 * Counter is 12 bit.
 */

static int wdt_settimeout(unsigned int timeout)
{
    unsigned int reg;
     wdt_t *wd     = (wdt_t *) WDT_BASE;

    /* Check if disabled */
    if (readl(&wd->mr) & WDT_MR_WDDIS) {
        printf("sorry, watchdog is disabled\n");
        return -1;
    }

    /*
     * All counting occurs at SLOW_CLOCK / 128 = 256 Hz
     *
     * Since WDV is a 12-bit counter, the maximum period is
     * 4096 / 256 = 16 seconds.
     */


    reg = WDT_MR_WDRSTEN        /* causes watchdog reset */
        | WDT_MR_WDDBGHLT        /* disabled in debug mode */
        | WDT_MR_WDD(0xfff)    /* restart at any time */
        | WDT_MR_WDV(timeout);    /* timer value */

    writel(reg, &wd->mr);

    return 0;
}

void hw_watchdog_reset(void)
{
    wdt_t *wd     = (wdt_t *) WDT_BASE;
    writel(WDT_CR_WDRSTT | WDT_CR_KEY, &wd->cr);
}

void hw_watchdog_init(void)
{
    /* 16 seconds timer, resets enabled */
    at91_wdt_settimeout(ms_to_ticks(WDT_HW_TIMEOUT * 1000));
}


阅读(616) | 评论(0) | 转发(0) |
0

上一篇:UBOOT RTC驱动流程

下一篇:UBOOT 网口测试

给主人留下些什么吧!~~