如何在Dragonboard 410c上实现一个秒表定时器
}
/*模块卸载函数*/
void second_exit(void)
{
cdev_del(&second_devp->cdev); /*注销cdev*/
kfree(second_devp); /*释放设备结构体内存*/
unregister_chrdev_region(MKDEV(second_major, 0), 1); /*释放设备号*/
}
MODULE_AUTHOR("Sola");
MODULE_LICENSE("Dual BSD/GPL");
module_param(second_major, int, S_IRUGO);
module_init(second_init);
module_exit(second_exit);
(2)驱动程序文件timer_demo_test.c的具体实现代码如下:
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/time.h>
main()
{
int fd;
int counter = 0;
int old_counter = 0;
/*打开/dev/second设备文件*/
fd = open("/dev/second", O_RDONLY);
if (fd != - 1)
{
while (1)
{
read(fd,&counter, sizeof(unsigned int));//读目前经历的秒数
if(counter!=old_counter)
{
printf("seconds after open /dev/second :%d\n",counter);
old_counter = counter;
}
}
}
else
{
printf("Device open failure\n");
}
}
DragonBoard 410c 定时器 相关文章: