我也遇到这个问题,发现unsigned long freq = clk_get_rate(wdt_clock);函数返回0所以我怀疑是看门狗时钟没有初始化。最后通过修改内核源码,看门狗正常了。
解决方法:
1、在clock-exynos4.c的数组static struct clk exynos4_init_clocks[]中添加
{
.name = "watchdog",
.parent = &exynos4_clk_pclk_acp,
.enable = exynos4_clk_ip_perir_ctrl,
.ctrlbit = (1 << 14),
}
2、然后在s3c2410_wdt.c中将
ifdef CONFIG_CPU_FREQ 改成 #if 0
3、然后在s3c2410_wdt.c中将
if (get_user(new_margin, p))
return -EFAULT;
if (s3c2410wdt_set_heartbeat(new_margin))
改成
if (s3c2410wdt_set_heartbeat(argp))
最终使看门狗正常工作。
看门狗测试程序:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/types.h>
#include <linux/watchdog.h>
int main(void)
{
int fd = open("/dev/watchdog", O_WRONLY);
int* timeout = 0;
int count = 0;
if (fd == -1)
{
perror("watchdog");
exit(EXIT_FAILURE);
}
ioctl(fd, WDIOC_SETTIMEOUT, 5);
while (1)
{
//ioctl(fd, WDIOC_KEEPALIVE, 0);
printf("feel dog %d\r\n",count++);
sleep(1);
}
close(fd);
return 0;
}