⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 watchdog.c

📁 ARM开发实例emed linuxexamples.tar.gz
💻 C
字号:
/* * 实验名称:看门狗实验 * 实验说明:S3C2410内部具有一个看门狗定时器,可以设置为看门狗功能,设定在一定时             间内,如果没有将看门狗计数寄存器复位,将引发系统复位,本实验设定复             位时间为2秒,如果在两秒内没有复位将导致系统复位。 * 最后修改:2004-09-01 */#include <stdio.h>#include <asm-arm/arch-s3c2410/S3C2410.h>#include <sys/io.h>#include <unistd.h>#include "../include/directio.h"#define _DEBUG_ printf#define PCLK (50*1024*1024)/* * watchdog application code * compile : *          $/usr/local/arm/2.95.3/bin/arm-linux-gcc -o watchdog watchdog.c *          $cp watchdog /tftpboot/examples * run in target: *          #mount 192.168.1.180:/tftpboot/ /mnt/nfs *          #cd /mnt/nfs/examples *          #insmod eintdrv.o *          #mknod eint c 98 0 *          #./interrupt *//* * 主函数 */int main(int argc, char **argv){    /*     *	t_watchdog = 1 / (PCLK / (Prescaler value + 1 ) / Division_factor)     */    _DEBUG_("WatchDog TimerTest!\n");    _DEBUG_("t_watchdog = 1 / (PCLK / (Prescaler value + 1) / Division_factor)\n");    /*     * port_open      */    if(port_init() != 0)    {        _DEBUG_("port open error\n");	_DEBUG_("Please follow me:\n");	_DEBUG_("    #insmod directio\n");	_DEBUG_("    #mknod /dev/directio c 199 0\n");	_DEBUG_("    #./watchdog\n");        return -1;    }    /*     * 设置看门狗控制寄存器rWTCON:     *   PCLK = PCLK     *   Prescaler = (PCLK/1000000-1)     *   Clock division = 128     */    port_outl(rWTCON, ((PCLK/1000000-1)<<8) | (3<<3) | (1)); //Prescaler=0x31(49),Clock division 128,Interrupt disable,Watch-dog timer enable    _DEBUG_("    PCLK = %dMHz\n", PCLK/1024/1024);    _DEBUG_("    Prescaler value = %d\n", (PCLK/1000000-1));    _DEBUG_("    Clock division = %d\n", 128);    _DEBUG_("t_watchdog = %f\n", 1.0 / (PCLK / (((PCLK/1000000-1)) + 1) / (128)));    /*     * 设置看门狗计数寄存器rWTCNT     *   wWTCNT = 16896     */    port_outl(rWTCNT, 8448 * 2); // 16896 (0x4200)        _DEBUG_("Please feed the dog every %f sec, if not System will restart.\n", (8448 * 2) * 1.0 / (PCLK / (((PCLK/1000000-1)) + 1) / (128)));    /*     * 打开看门狗     */    port_outl(rWTCON, port_inl(rWTCON) | (1 << 5));    while(1)    {        /*         * 每秒钟喂狗一次,如果不喂狗,看门狗打开两秒钟后将复位         */        _DEBUG_("Feed the dog\n");        port_outl(rWTCNT, 8448 * 2); // 16896 (0x4200)        sleep(2);    }    /* uninit the port */    port_uninit();}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -