/***************************************
* Filename: fnd_app.c
* Title: fnd Device Application
* Desc: Implementation of system call
***************************************/
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
int main(void)
{
int retn;
int fd;
int flag = 0;
int menu;
short data, timerPeriod;
short fndValue;
fd = open("/dev/FND", O_RDWR);
printf("fd = %d\n", fd);
if (fd<0) {
perror("/dev/FND");
exit(-1);
}
else
printf("[APP]FND detected...\n");
while(1)
{
printf("\n\n===== FND Test Program ====\n");
printf(" 1. OSTimer_1 Interrupt Period Setting\n");
printf(" 2. FND0 Read\n");
printf(" 3. FND0 Write\n");
printf(" 4. FND Clear\n");
printf(" 0. Program Quit\n");
do {
printf(" Select Menu => ");
scanf("%d", &menu);
} while(menu<0 || menu>4);
if(menu == 0) break;
switch(menu) {
case 1:
printf("Input OSTimer_1 Int. Period Value(1~10) => ");
scanf("%hd", &timerPeriod);
ioctl(fd, 3, timerPeriod);
printf("\n[APP]OSTimer_1 Period Setting Done!!\n");
break;
case 2:
printf("[APP]Wait OSTimer_1 Int...\n");
read(fd, &data, sizeof(short));
printf("\n[APP]FND0 Value Read(%04x) Done!!\n", data);
break;
case 3:
printf("Input FND0 Write Value(0~9) => ");
scanf("%hd", &fndValue);
write(fd, &fndValue, sizeof(short));
printf("\n[APP]FND0 Value Write Done!!\n");
break;
case 4:
ioctl(fd, 4, flag);
break;
}
}
close(fd);
return 0;
}
'c or linux' 카테고리의 다른 글
[공부중] header 파일 -irqs.h (0) | 2011.04.20 |
---|---|
CPU 구성요소 (0) | 2011.04.20 |
[공부중] Device 관점에 본 /proc와 /sys 디렉토리 (0) | 2011.04.20 |
[공부중] 커널 타이머 (0) | 2011.04.20 |
[공부중] minor number 기반으로 다루기 (0) | 2011.04.20 |