全志A20看门狗watchdog调试

全志的芯片手册里面watchdog只有两个寄存器:WDOG_CTRL_REG和WDOG_MODE_REG
从我的调试结果来看
WDOG_CTRL_REG设置好像无法生效,改进方法是在喂狗时先关闭狗,再喂狗,再使能狗
①wdt_enable(false);
②然后再喂狗;

③wdt_enable(true);


驱动修改如下:

static ssize_t sunxi_wdt_write(struct file *file, const char __user *data, size_t len, loff_t *ppos)
{
	printk("write:\n");

	/* See if we got the magic character 'V' and reload the timer */
	if(len) 
	{
		if(!g_nowayout) 
		{
			size_t i;

			/* in case it was set long ago */
			expect_release = false;

			/* scan to see whether or not we got the magic character */
			for(i = 0; i != len; i++) {
				char c;
				if(get_user(c, data + i))
					return -EFAULT;
				if(c == 'V')
				{
					printk("cyl: got V\n");
					//expect_release = true;
				}
			}
		}
		/* someone wrote to us, we should reload the timer */
+       wdt_enable(false);
		watchdog_kick();
+ 		wdt_enable(true);
	}
	return len;
}


应用程序如下:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
int main(void)
{
	int fd = open("/dev/watchdog", O_WRONLY);
	int ret = 0;
	int cnt = 0;
	if (fd == -1) {
		perror("watchdog");
		exit(EXIT_FAILURE);
	}
	while (1) {
		ret = write(fd, "V", 1);
		if (ret != 1) {
			ret = -1;
			break;
		}
		sleep(1);
		cnt++;
		if(cnt > 100)
		{
			printf("end end end end \n");
			break;
		}
		else
		{
			printf("cnt = %d \n", cnt);
			
		}
		
	}
	while(1)
	{
		printf("%d \n", cnt++);
		sleep(1);
	}
	close(fd);
	return ret;
}

注意:
此方法是我在喂狗无效后,实在没有办法的情况下做的。如果有人有更好的方法,请给我留言分享。谢谢!



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值