-
Notifications
You must be signed in to change notification settings - Fork 1
/
periodic_interrupt.c
95 lines (81 loc) · 3.25 KB
/
periodic_interrupt.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
#include <stdio.h>
#include <time.h>
#include <sys/netmgr.h>
#include <sys/neutrino.h>
#define MY_PULSE_CODE _PULSE_CODE_MINAVAIL
#define MY_OTHER_PULSE_CODE _PULSE_CODE_MAXAVAIL
typedef union {
struct _pulse pulse;
/* your other message structures would go
here too */
} my_message_t;
main()
{
struct sigevent timer_event;
struct sigevent timer_event2;
struct itimerspec interval_time;
struct itimerspec interval_time2;
timer_t timer_id;
timer_t timer_id2;
int chid, chid2;
int rcvid, rcvid2;
my_message_t msg;
//------------------First timer------------------------------
chid = ChannelCreate(0);
// connect the message channel
timer_event.sigev_notify = SIGEV_PULSE;
timer_event.sigev_coid = ConnectAttach(ND_LOCAL_NODE, 0,chid,_NTO_SIDE_CHANNEL, 0);
timer_event.sigev_priority = getprio(0);
timer_event.sigev_code = MY_PULSE_CODE;
//create timer of type monotonic calling the event "timer_event"
timer_create(CLOCK_MONOTONIC, &timer_event, &timer_id);
// set the first shot to be 1 second
interval_time.it_value.tv_sec = 1;
/* 500 million nsecs = .5 secs */
//interval_time.it_value.tv_nsec = 500000000;
// set each interval to be 1 second
interval_time.it_interval.tv_sec = 1;
/* 500 million nsecs = .5 secs */
//interval_time.it_interval.tv_nsec = 500000000;
//update the timer to the loaded time
timer_settime(timer_id, 0, &interval_time, NULL);
//--------------------Second Timer--------------------------------------
// chid2 = ChannelCreate(1);
timer_event2.sigev_notify = SIGEV_PULSE;
timer_event2.sigev_coid = ConnectAttach(ND_LOCAL_NODE, 0,chid,_NTO_SIDE_CHANNEL, 0);
timer_event2.sigev_priority = getprio(0);
timer_event2.sigev_code = MY_OTHER_PULSE_CODE;
//create timer of type monotonic calling the event "timer_event"
timer_create(CLOCK_MONOTONIC, &timer_event2, &timer_id2);
// set the second timer to be 2.5 seconds
interval_time2.it_value.tv_sec = 2;
/* 500 million nsecs = .5 secs */
interval_time.it_value.tv_nsec = 500000000;
// set each interval to be 1 second
interval_time2.it_interval.tv_sec = 2;
/* 500 million nsecs = .5 secs */
interval_time.it_interval.tv_nsec = 500000000;
//update the timer to the loaded time
timer_settime(timer_id2, 0, &interval_time2, NULL);
int i;
for (i=1;i<10;i++) {
//wait for a pulse on the channel
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 first timer\n");
} /* else other pulses ... */
else{
printf("we got a pulse from our second timer\n");
}
}
/*
rcvid2 = MsgReceive(chid2, &msg, sizeof(msg), NULL);
if (rcvid2 == 0) { /* we got a pulse
if (msg.pulse.code == MY_PULSE_CODE) {
printf("we got a pulse from our second timer\n");
}
}
*/
}
}