-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimer.c
53 lines (40 loc) · 1.22 KB
/
timer.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
#include <stdio.h>
#include "timer.h"
#include "main.h"
#include <sys/neutrino.h>
#include <errno.h>
#include <time.h>
#define EXIT_FAILURE -1
int debug = 0;
int chid;
timer_t timerid;
struct itimerspec timer;
void setupTimer (void)
{
struct sigevent event;
int coid;
char *funcname = "setupTimer";
if(debug) printf("\nREACHED TIMER FUNCTION");
coid = ConnectAttach (0, 0, chid, 0, 0);
if(coid == -1)
{
fprintf (stderr, "%s: couldn't ConnectAttach!\n",funcname);
printf("\nCould not connect attach %s", funcname);
perror (NULL);
exit (EXIT_FAILURE);
}
if(debug) printf("Connect Attach done well\n");
SIGEV_PULSE_INIT(&event, coid, SIGEV_PULSE_PRIO_INHERIT, CODE_TIMER, 0);
if (timer_create (CLOCK_REALTIME, &event, &timerid) == -1)
{
fprintf (stderr, "%s: can't timer_create,errno %d\n",funcname, errno);
printf("\n%s can't create timer errno = %d", funcname, errno);
perror (NULL);
exit (EXIT_FAILURE);
}
timer.it_value.tv_sec = 0;
timer.it_value.tv_nsec = nTICKS;
timer.it_interval.tv_sec = 0;
timer.it_interval.tv_nsec = nTICKS;
if(debug) fprintf(stderr,"Control Frequency = %d [Hz]\n",(int)(FREQ));
}