外部看门狗驱动模块支持-max706s

/*
 * max706s Watchdog: A Simple Hardware Watchdog Device
 * Based on Softdog driver by Alan Cox and PC Watchdog driver by Ken Hollis
 *
 * Author: Gergely Madarasz <gorgo@itc.hu>
 *
 * Copyright (c) 1999 ITConsult-Pro Co. <info@itc.hu>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version
 * 2 of the License, or (at your option) any later version.
 *
 *
 */
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/types.h>
#include <linux/string.h>
#include <linux/init.h>
#include <linux/security.h>
#include <asm/uaccess.h>
#include <asm/gpio.h>
#include <linux/fs.h>
#include <asm/io.h>
#include <linux/kthread.h>  
#include <linux/miscdevice.h>
#include <linux/sched.h> 
#include <asm/ioctl.h>
#include <mach/system.h>
#define  WAIT_TIME_3M   1800
static struct task_struct *tsk;  
unsigned int ENABLE_GPIO = GPIOG(5);
unsigned int CLK_GPIO = GPIOG(4);
static int FLAG = 0;
#define WDT_EXCE    113
static unsigned int timeCount = 0;
static   int threadIsRun  = 1;
static void delay(int time)
{
int i;
for( ;time>0;time--)
for(i = 1000 ;i>0;i--);
}
static void wdt_arch_reset(void)
{
pr_err("%s: to check\n", __func__);
*(volatile unsigned int *)WDOG_MODE_REG = 0;
delay(100000);
*(volatile unsigned int *)WDOG_MODE_REG |= 2;
while(1) {
delay(100);
*(volatile unsigned int *)WDOG_MODE_REG |= 1;
}
}




static int thread_max706s(void *data)  
{  
   printk("进入线程1执行函数....\n");  
gpio_direction_output(ENABLE_GPIO, 0);
    do {
if(timeCount ++ > WAIT_TIME_3M && !FLAG){
printk("系统重启。。。\n");
break;
}

gpio_direction_output(CLK_GPIO, 1);
schedule_timeout_uninterruptible(15);
gpio_direction_output(CLK_GPIO, 0);
schedule_timeout_uninterruptible(15);
// printk("线程运行正常....\n");
    }while(threadIsRun);  
printk("线程1退出循环");
threadIsRun  = 2;
wdt_arch_reset();
    return 0;  
}  


static long wdt_ioctl(struct file *filp, unsigned int cmd, unsigned long arg){
switch (cmd){
case WDT_EXCE:threadIsRun = 0;
break;
default:printk("参数非法\n");return -EINVAL;
}
return 0;
}


static int wdt_open(struct inode* inode, struct file* filp){
FLAG = 1;
printk("wdt_open!\n");

return 0;
}


static int wdt_release(struct inode* inode, struct file* filp){
return 0;
}
struct file_operations wdt_fops = {
.owner = THIS_MODULE,
.unlocked_ioctl = wdt_ioctl,
.open = wdt_open,
.release = wdt_release,
};
static struct miscdevice max706s_miscdev = {
.minor = WATCHDOG_MINOR,
.name = "watchdog",
.fops = &wdt_fops,
};
static int __init max706s_init(void)
{
int ret;
struct sched_param param;
ret = misc_register(&max706s_miscdev);
if(ret){
printk("misc_register失败。。。\n");
return -1;
}
ret=gpio_request(CLK_GPIO,"max706s_gpio");
if(ret){
printk("gpio_request()--1 err....\n");
return -1;
}
ret=gpio_request(ENABLE_GPIO,"max706s_test");
if(ret){
printk("gpio_request()--2 err....\n");
return -1;
}

//喂狗线程
tsk = kthread_run(thread_max706s, NULL, "max706s_thread");
if(tsk==NULL){
printk("线程创建失败....\n");
return -1;
}
    param.sched_priority = 0;
    sched_setscheduler(tsk, SCHED_RR, &param);
printk("初始化成功。。\n");
return 0;
}


static void __exit max706s_exit(void)
{
if(threadIsRun != 2)
threadIsRun = 0;
while(threadIsRun != 2){
schedule_timeout_uninterruptible(1);
};

gpio_free(CLK_GPIO);
gpio_free(GPIOH(0));
misc_deregister(&max706s_miscdev);
printk("模块退出...\n");
}


module_init(max706s_init);
module_exit(max706s_exit);
MODULE_LICENSE("GPL");
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值