snifer

【原创】基于嵌入式的WDT驱动编写及测试

0
阅读(2062)

今天写一下如何编写一个字符驱动程序操作目标板的LED的亮灭。

平台还是熟悉的:

主机:Ubuntu 10.10

       目标机:FS_S5PC100

       目标机内核版本:2.6.35

       交叉编译器版本:arm-none-linux-gnueabi-gcc-4.5.1

注意:在实验过程中"$"后的操作在主机上,"#"后的操作在开发板上

1、编写代码:

#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>

int main (void) 
{
int fd;
int data;
fd = open ("/dev/adc",O_RDWR);
if (fd < 0) {
perror("open");
exit(0);
}
while(1)
{
read (fd, (char *)&data, sizeof(data));
printf("Voltage = %.2f\n", 3.3/4096*data);
sleep(1);
}
close (fd);
printf ("/dev/adc closed :)\n");
return 0;
}

2、  编译模块

$ make

3、  编译应用程序

$ arm-none-linux-gnueabi-gcc test.c –o test

4、  拷贝驱动及应用程序到目标板上

$ cp s5pc100_wdt.ko test /source/rootfs

5、  启动开发板后加载模块

# insmod s5pc100_wdt.ko

6、  创建设备节点

# mknod /dev/wdt c 250 0

7、  测试

# ./test

       应用程序每隔一秒喂一次狗,10秒后系统复位