-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevents.c
77 lines (63 loc) · 1.21 KB
/
events.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
#include <u.h>
#include <libc.h>
int setup(void);
void
main(void)
{
int eventfd, pinfd, i, reads = 0, state;
u32int event;
char pin;
if(setup() != 0)
{
exits("ctlfd");
}
eventfd = open("#G/gpio/event", OREAD);
if(!eventfd)
{
exits("eventfd");
}
pinfd = open("#G/gpio/GPIO0", OREAD);
if(!pinfd)
{
close(eventfd);
exits("pinfd");
}
while(++reads < 100)
{
read(eventfd, &event, sizeof(u32int));
for(i = 0; i < sizeof(u32int) * 8; i++)
{
state = event & (1 << i);
if((state >> i) & 1)
{
print("%d: pin %d, state changed\n", reads, i);
if(i == 17) {
read(pinfd, &pin, 1);
print("\tGPIO0 state=%c\n", pin);
}
}
}
}
close(eventfd);
close(pinfd);
exits(0);
}
int setup(void)
{
int ctlfd;
char boardscheme[] = "scheme board";
char funcin[] = "function in GPIO0";
char edgerising[] = "event edge-rising enable GPIO0";
char edgefalling[] = "event edge-falling enable GPIO0";
ctlfd = open("#G/gpio/ctl", OWRITE);
if(!ctlfd)
{
return -1;
}
write(ctlfd, boardscheme, strlen(boardscheme));
write(ctlfd, funcin, strlen(funcin));
write(ctlfd, edgerising, strlen(edgerising));
write(ctlfd, edgefalling, strlen(edgefalling));
close(ctlfd);
return 0;
}