-
Notifications
You must be signed in to change notification settings - Fork 1
/
timer_create_code.c
57 lines (50 loc) · 1.7 KB
/
timer_create_code.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
#include <stdio.h>
#include <time.h>
#include <sys/netmgr.h>
#include <sys/neutrino.h>
#define MY_PULSE_CODE _PULSE_CODE_MINAVAIL
typedef union {
struct _pulse pulse;
/* your other message structures would go
here too */
} my_message_t;
main()
{
struct sigevent event;
struct itimerspec itime;
timer_t timer_id;
int chid;
int rcvid;
my_message_t msg;
chid = ChannelCreate(0);
SIGEV_INTR_INIT(&event);
InterruptAttachEvent(10,&event,0);
//event.sigev_intr_init()
event.sigev_notify = SIGEV_PULSE;
event.sigev_coid = ConnectAttach(ND_LOCAL_NODE, 0,
chid,
_NTO_SIDE_CHANNEL, 0);
event.sigev_priority = getprio(0);
event.sigev_code = MY_PULSE_CODE;
timer_create(CLOCK_MONOTONIC, &event, &timer_id);
itime.it_value.tv_sec = 1;
/* 500 million nsecs = .5 secs */
itime.it_value.tv_nsec = 500000000;
itime.it_interval.tv_sec = 1;
/* 500 million nsecs = .5 secs */
itime.it_interval.tv_nsec = 500000000;
timer_settime(timer_id, 0, &itime, NULL);
/*
* As of the timer_settime(), we will receive our pulse
* in 1.5 seconds (the itime.it_value) and every 1.5
* seconds thereafter (the itime.it_interval)
*/
for (;;) {
rcvid = MsgReceive(chid, &msg, sizeof(msg), NULL);
if (rcvid == 0) { /* we got a pulse */
if (msg.pulse.code == MY_PULSE_CODE) {
printf("we got a pulse from our timer\n");
} /* else other pulses ... */
} /* else other messages ... */
}
}