base/arch/i386/calibration/calibration_helper.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2003 Paolo Mantegazza <mantegazza@aero.polimi.it>
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2 of the License, or (at your option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Lesser General Public License for more details.
00013 
00014  * You should have received a copy of the GNU Lesser General Public
00015  * License along with this library; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
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 }

Generated on Tue Feb 2 17:46:04 2010 for RTAI API by  doxygen 1.4.7