ev3 stays inside black line
[des2015.git] / natanael / ex11 / ex11a.c
1 #include <stdio.h>
2 #include <signal.h>
3 #include <unistd.h>
4 #include <sys/mman.h>
5 #include <native/intr.h>
6 #include <sys/io.h>
7 #include <native/task.h>
8
9 const RTIME period = 1e5;
10 const int nsamples = 10000;
11
12 RT_TASK task;
13 RTIME write_time;
14 RTIME arr_write_time[10000];
15 RTIME time_diff[10000];
16
17 void do_task(void *arg)
18 {
19 int i;
20 rt_task_set_periodic(NULL, TM_NOW, period);
21
22 for(i=0; i<nsamples; i++)
23 {
24 write_time = rt_timer_read();
25 arr_write_time[i] = write_time;
26
27 rt_task_wait_period(NULL);
28
29 time_diff[i] = rt_timer_read() - write_time;
30 }
31 }
32
33 //startup code
34 void startup()
35 {
36 rt_task_create(&task, NULL,0,50,0);
37 rt_task_start(&task, &do_task, NULL);
38 }
39
40 void init_xenomai() {
41 /* Avoids memory swapping for this program */
42 mlockall(MCL_CURRENT|MCL_FUTURE);
43
44 /* Perform auto-init of rt_print buffers if the task doesn't do so */
45 rt_print_auto_init(1);
46 }
47
48 int main(int argc, char* argv[])
49 {
50 printf("\nType CTRL-C to end this program\n\n" );
51
52 // code to set things to run xenomai
53 init_xenomai();
54
55 //startup code
56 startup();
57
58 // wait for CTRL-c is typed to end the program
59 pause();
60 }