Chinaunix首页 | 论坛 | 博客
  • 博客访问: 9207276
  • 博文数量: 1728
  • 博客积分: 12961
  • 博客等级: 上将
  • 技术积分: 19870
  • 用 户 组: 普通用户
  • 注册时间: 2009-01-09 11:25
个人简介

偷得浮生半桶水(半日闲), 好记性不如抄下来(烂笔头). 信息爆炸的时代, 学习是一项持续的工作.

文章分类

全部博文(1728)

文章存档

2024年(4)

2023年(26)

2022年(112)

2021年(217)

2020年(157)

2019年(192)

2018年(81)

2017年(78)

2016年(70)

2015年(52)

2014年(40)

2013年(51)

2012年(85)

2011年(45)

2010年(231)

2009年(287)

分类: LINUX

2010-08-23 11:01:15

#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));
}


阅读(2088) | 评论(0) | 转发(1) |
0

上一篇:UBOOT RTC驱动流程

下一篇:UBOOT 网口测试

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