-
Notifications
You must be signed in to change notification settings - Fork 129
/
Copy pathpthread_led.c
61 lines (57 loc) · 1008 Bytes
/
pthread_led.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
#include "data_global.h"
extern unsigned char dev_led_mask;
extern int dev_led_fd;
extern pthread_mutex_t mutex_led;
extern pthread_cond_t cond_led;
void *pthread_led (void *arg)
{
int led_no;
unsigned char led_set;
if ((dev_led_fd = open (DEV_LED, O_RDWR | O_NONBLOCK)) < 0 )
{
printf ("Cann't open file /dev/led\n");
exit (-1);
}
printf ("pthread_led is ok\n");
while (1)
{
pthread_mutex_lock (&mutex_led);
pthread_cond_wait (&cond_led, &mutex_led);
led_set = dev_led_mask;
pthread_mutex_unlock (&mutex_led);
// printf ("pthread_led is wake up\n");
switch (led_set & 0xf0)
{
case 0x10:
{
led_no = 0;
break;
}
case 0x20:
{
led_no = 1;
break;
}
case 0x40:
{
led_no = 2;
break;
}
case 0x80:
{
led_no = 3;
break;
}
default :break;
}
led_set &= 0x0f;
if (led_set & (0x1 << led_no))
{
ioctl (dev_led_fd, LED_ON, led_no);
}
else
{
ioctl (dev_led_fd, LED_OFF, led_no);
}
}
}