-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_thr.c
119 lines (93 loc) · 1.88 KB
/
test_thr.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <linux/kdev_t.h>
#include <pthread.h>
#include <time.h>
#define SVM_FILE_NAME "/dev/svm_driver"
#define LED_FILE_NAME "/dev/led_driver"
void *thread_svm(void *arg);
void *thread_led(void *arg);
int main(int argc, char **argv)
{
int svm_fd;
int led_fd;
char led_data;
int svm_flag=1;
int led_flag=1;
int thread_svm_state=1;
int thread_led_state=1;
pthread_t svm, led;
void *thsvm_ret, *thled_ret;
// dev_driver open
while (svm_flag==1)
{
thread_svm_state = pthread_create(&svm, NULL, thread_svm , NULL);
if(thread_svm_state!=0){
puts("svm_thread error\n");
exit(1);
}
// pthread_join(svm, &thsvm_ret);
svm_flag=0;
}
while (led_flag==1){
thread_led_state = pthread_create(&led, NULL, thread_led , NULL);
if(thread_led_state!=0){
puts("svm_thread error\n");
exit(1);
}
// pthread_join(led, &thled_ret);
led_flag=0;
}
pthread_join(svm, &thsvm_ret);
pthread_join(led, &thled_ret);
free(thsvm_ret);
free(thled_ret);
return 0;
}
void thread_svm(void *arg){
svm_fd = open(SVM_FILE_NAME, O_RDWR);
if (svm_fd < 0)
{
fprintf(stderr, "Can't open %s\n", SVM_FILE_NAME);
return -1;
}
int service_count=3; //test
char svm_data;
svm_data='c'
write(fd, &svm_data, sizeof(char));
while(service_count>0){
svm_data='l'
write(fd, &svm_data, sizeof(char));
sleep(1);
svm_data='c'
write(fd, &svm_data, sizeof(char));
sleep(1);
}
close(svm_fd);
}
void thread_led(void *arg){
led_fd = open(LED_FILE_NAME, O_RDWR);
char = led_data;
int i,j;
if (led_fd < 0)
{
fprintf(stderr, "Can't open %s\n", LED_FILE_NAME);
return -1;
}
while (1)
{
for(i=0;i<19;i++)
{
data = (char)i;
write(led_fd, &led_data, sizeof(char));
if(i>=10)
sleep(2);
}
}
close(led_fd);
return 0;
}