-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_debugfs.c
66 lines (61 loc) · 2.31 KB
/
test_debugfs.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/***************************************************************************//**
* \file test_app.c
*
* \details Userspace application to test the Device driver
*
* \author smalinux
*
* *******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
int8_t write_buf[1024];
int8_t read_buf[1024];
int main()
{
int fd;
char option;
printf("*********************************\n");
printf("************ Welcome ************\n");
fd = open("/sys/kernel/debug/sma_debugfs/sma_debug_file", O_RDWR);
if(fd < 0) {
printf("Cannot open device file...\n");
return 0;
}
while(1) {
printf("****Please Enter the Option******\n");
printf(" 1. Write \n");
printf(" 2. Read \n");
printf(" 3. Exit \n");
printf("*********************************\n");
scanf(" %c", &option);
printf("Your Option = %c\n", option);
switch(option) {
case '1':
printf("Enter the string to write into driver :");
scanf(" %[^\t\n]s", write_buf);
printf("Data Writing ...");
write(fd, write_buf, strlen(write_buf)+1);
printf("Done!\n");
break;
case '2':
printf("Data Reading ...");
read(fd, read_buf, 1024);
printf("Done!\n\n");
printf("Data = %s\n\n", read_buf);
break;
case '3':
close(fd);
exit(1);
break;
default:
printf("Enter Valid option = %c\n",option);
break;
}
}
close(fd);
}