/*-------------------------
*先申明下,本人是个菜鸟,刚开始接触驱动程序编写,交代下开发环境(主机系统redhat6.3,开发板ARM-s3c6410)
以watchdog (看门狗,俗称狗中断)为例,编写简单的中断(驱动)
-------------------------*/
#include <linux/init.h>
#include #include #include #include #include #include MODULE_LICENSE('GPL'); MODULE_AUTHOR('cheng'); typedef struct mydev{ unsigned long gpio_virt; unsigned long wdt_virt; unsigned long *gpmcon, *gpmdat; unsigned long *wtcon, *wtdat, *wtcnt, *wtclrint; void (*init_nydev)(struct mydev *this); void (*exit_mydev)(struct mydev *this); irqreturn_t (*do_irq)(int irq, struct mydev *this); void (*led_on)(struct mydev *this); void (*led_off)(struct mydev *this); void (*wdt_on)(struct mydev *this); void (*wdt_off)(struct mydev *this); }MYDEV; void my_init_mydev(struct mydev *this); void my_exit_mydev(struct mydev *this); irqreturn_t my_do_irq(int irq, struct mydev *this); void my_led_on(struct mydev *this); void my_led_off(struct mydev *this); void my_wdt_on(struct mydev *this); void my_wdt_off(struct mydev *this); MYDEV my ; static int test_init(void) { printk('hello,in my test_initn'); my.init_mydev = my_init_mydev; my.exit_mydev = my_exit_mydev; my.init_mydev(&my); return 0; } void test_exit() { my.exit_mydev(&my); printk('this is test exitn'); } module_init(test_init); module_exit(test_exit); void my_init_mydev(struct mydev *this) { this->do_irq = my_do_irq; this->led_on = my_led_on; this->led_off = my_led_off; this->wdt_on = my_wdt_on; this->wdt_off = my_wdt_off; int ret = request_irq(IRQ_WDT, this->do_irq, IRQF_SHARED,'hello', this); if(ret < 0){ printk('request_irq errorn'); return ; } this->gpio_virt = ioremap(0x7f008000, SZ_4K); this->wdt_virt = ioremap(0x7e004000, SZ_4K); this->gpmcon = this->gpio_virt + 0x820; this->gpmdat = this->gpio_virt + 0x824; this->wtcon = this->wdt_virt + 0x00; this->wtdat = this->wdt_virt + 0x04; this->wtcnt = this->wdt_virt + 0x08; this->wtclrint = this->wdt_virt + 0x0c; this->wdt_on(this); } void my_exit_mydev(struct mydev *this) { this->my_wtd_off(this); iounmap(this->wdt_virt); iounmap(this->gpio_virt); free_irq(IRQ_WDT,this); } irqreturn_t my_do_irq(int irq, struct mydev *this) { if(irq == IRQ_WDT){ *this->wtclrint = 0; printk('wang wang wangn'); static int flag = 1; if(flag) this->led_on(this); else this->led_off(this); flag ^= 1; } return IRQ_HANDLED; } void my_led_on(struct mydev *this) { *this->gpmcon = 1; *this->gpmdat = 0; } void my_led_off(struct mydev *this) { *this->gpmcon = 1; *this->gpmdat = 1; } void my_wdt_on(struct mydev *this) { *this->wtcon = (1 << 2) | (1 << 3) | (1 << 5) | (31 << 8); *this->wtdat = 0x4000; *this->wtcnt = 0x8000; } void my_wdt_off(struct mydev *this) { *this->wtcon = 0; } /* 下面是makefile内容: */ all: make -C linux-2.6.28_smdk6410 M=`pwd` modules clean: make -C /linux-2.6.28_smdk6410 M=`pwd` clean rm -rf modules.order obj-m += test.o
上一篇:S3C6410开发板开发环境的搭建
下一篇:【嵌入式开发】向开发板中烧写Linux系统-型号S3C6410
推荐阅读最新更新时间:2026-03-25 12:54
- 用于 7VIN 至 16VIN、1.5V 和 1.2V 输出的 LTM4628EV DC/DC 模块稳压器的典型应用电路
- 使用 Analog Devices 的 LTC3728LIGN 的参考设计
- DER-406 - 适用于 A19 灯的 5.76 W 高 PF 非隔离降压-升压型 TRIAC 调光 LED 驱动器
- ADR5045B 5V 输出精密微功率并联模式电压基准的典型应用
- LT3970EDDB-3.42 2.5V 降压转换器的典型应用
- MC78M08BDTG 8V 电流调节器的典型应用
- LT1021DCN8-5 精密电压基准的典型应用
- DER-282 - 100W, 扁平(11 mm), LLC DC-DC转换器
- REF193 低压差开尔文连接电压基准的典型应用电路
- LT3088EM 线性稳压器用于添加软启动的典型应用

Linux技术手册
智能机械臂
Arduino 2.3.6 64位安装程序
非常经典的关于LLC的杨波博士论文
1CIS223-04TG3M






京公网安备 11010802033920号