removed binary and ex10b
[des2015.git] / mart / ex10 / ex10a.c
index e69de29..4b0a0a4 100644 (file)
@@ -0,0 +1,46 @@
+#include <stdio.h>
+#include <signal.h>
+#include <unistd.h>
+#include <sys/mman.h>
+
+#include <native/task.h>
+#include <native/timer.h>
+
+#include <rtdk.h>
+
+#define SAMPLES 10000
+RT_TASK task;
+
+RTIME times[SAMPLES];
+
+void taskf(void *arg)
+{
+       RT_TASK *curtask;
+       rt_task_set_periodic(NULL, TM_NOW, 1e5);
+
+       unsigned int i;
+       for(i = 0; i<SAMPLES; i++){
+               times[i] = rt_timer_read();     
+               rt_task_wait_period(NULL);
+       }
+       FILE *file;
+       file = fopen("ex10a.csv", "w");
+       for(i = 0; i<SAMPLES-1; i++){
+               fprintf(file, "%u,%llu\n", i, times[i+1]-times[i]);
+       }
+       fclose(file);
+}
+
+void taskw(void *arg)
+{
+       rt_task_join(&task);
+}
+
+int main(int argc, char* argv[])
+{
+       rt_print_auto_init(1);
+       mlockall(MCL_CURRENT | MCL_FUTURE);
+       rt_task_create(&task, NULL, 0, 50, 0);
+       rt_task_start(&task, &taskf, NULL);
+       sleep(2);
+}