I have Xenomai installed in an ARM PC (Xenomai 2.5.6 - Linux Kernel 2.6.35.9) and I need to read a 10 kHz clock signal. The signal is electrically connected to one of my GPIO's, which is mapped to a system file. If I create a task in user-space and open-read-close the file while measuring the time I get an average delay of 650 µs (i.e. this is the time that takes a full open-read-close cycle). This yields to a sampling rate of ~1.5 kHz.
while(1) // Task's infinite loop
{
t1 = rt_timer_read();
if((fd = open("test_file",O_RDONLY)) > 0)
{
read(fd,&buff,1);
close(fd);
}else{
errors++;
}
t2 = rt_timer_read();
t += t2-t1;
rt_task_wait_period(NULL);
}
Output:
[RT:] Start reading files: 05:19:05.804.754
[RT:] End reading files: 05:19:13.338.078
[RT:] Average time (10000 open-read-close cycles): 00000671.901 (microseconds)
[RT:] Errors found: 0
[RT:] (sig_handler) Signal received! (signo = 2)
I've read somewhere in the Internet that forcing my task to run in Kernel-space rather than user-space would enable it for a faster execution, but I'm not sure if this would be enough, nor if what I'm trying to do here is completely right.
I come from an electronics engineering background where I have always been told not to treat synchronous signals (like clock signals) asynchronously, and reading a file (i.e. my sync. signal) using a periodic task that may introduce jitter depending on the CPU/system load, doesn't look like a good approach. Is there a better way to do so?
Thanks!