S3C6410实时时钟RTC 秒字符设备
S3C6410实时时钟RTC 秒字符设备
/*《Linux 设备驱动开发详解》
驱动程序
*/
- #include <linux/module.h>
- #include <linux/types.h>
/*应用程序*/
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <fcntl.h>
- #include <signal.h>
- #include <sys/stat.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");
- }
- }
评论暂时关闭