00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
#include <stdio.h>
00020
#include <stdlib.h>
00021
#include <unistd.h>
00022
#include <fcntl.h>
00023
#include <sched.h>
00024
#include <sys/mman.h>
00025
00026
#include <rtai_fifos.h>
00027
00028 int main(
int argc,
char *argv[])
00029 {
00030
int fifo, period, skip, average = 0;
00031
char nm[
RTF_NAMELEN+1];
00032
RT_TASK *
task;
00033
RTIME expected;
00034
00035
if ((fifo = open(rtf_getfifobyminor(0,nm,
sizeof(nm)), O_WRONLY)) < 0) {
00036 printf(
"Error opening %s in calibration helper\n",nm);
00037 exit(1);
00038 }
00039
if (!(
task =
rt_task_init_schmod(
nam2num(
"UCAL"), 0, 0, 0, SCHED_FIFO, 0xF))) {
00040 printf(
"Cannot init calibration helper\n");
00041 exit(1);
00042 }
00043
00044
rt_set_oneshot_mode();
00045 period =
start_rt_timer(
nano2count(atoi(argv[1])));
00046 mlockall(MCL_CURRENT | MCL_FUTURE);
00047
rt_make_hard_real_time();
00048 expected =
rt_get_time() + 100*period;
00049
rt_task_make_periodic(
task, expected, period);
00050
for (skip = 0; skip < atoi(argv[2]); skip++) {
00051 expected += period;
00052
rt_task_wait_period();
00053 average += (
int)
count2nano(
rt_get_time() - expected);
00054 }
00055
rt_make_soft_real_time();
00056
stop_rt_timer();
00057
rt_task_delete(
task);
00058 write(fifo, &average,
sizeof(average));
00059 close(fifo);
00060 exit(0);
00061 }