COMEDI and RTAI questions

Hi all,

sorry if I'm being ignorant, but I need some expertise in running the
comedi inside a rtai FIFO. I am using comedi_data_read to read a sample,
do some calculations with it and write in real time (this little module
is used in neuroscience to simulate ion currents in real cells), the
code is as follow:

#include <linux/module.h>
#include <asm/io.h>
#include <math.h>
#include <rtai.h>
#include <rtai_sched.h>
#include <rtai_fifos.h>


#define TICK_PERIOD 50000
#define TASK_PRIORITY 1
#define STACK_SIZE 10000
#define FIFO 0

#include <linux/comedi.h>
#include <linux/comedilib.h>

static RT_TASK task;

unsigned int channel;

float counter, h;
	
static void fun(int t)
{
	int subdevice = 0;
	int chan = 0;  
	int range = 2;
	int aref = 0;           
	comedi_t *device;
	lsampl_t datab;
	int pdatab;
	float mv, tauh, hinf, ih, gih;
	
	gih=10;
	
	device=comedi_open("/dev/comedi0");
	while (1) {
	comedi_data_read(device,subdevice,chan,range,aref,&datab);
	mv=100*(((float)datab/4096)*5-2.5);
	//mv=100*((float)datab/4096)*10+5;
	tauh=10000/(237*exp((mv+60)/12)+17*exp(-(mv+60)/25))+0.6;
	hinf=1/(1+exp((mv+76)/7));
	h=hinf+(h-hinf)*exp(-0.05/tauh);
	//h=rk4(h,hinf,tauh);
	ih=gih*h*(mv+45);
	//ih=10*(mv+93);
	counter=ih;
	pdatab=ih+2024;
	comedi_data_write(device,1,chan,0,aref,pdatab);
	rtf_put(FIFO, &counter, sizeof(counter));
	rtf_put(FIFO, &mv, sizeof(mv));
	rt_task_wait_period();
	}
}

int init_module(void)
{
	RTIME tick_period;
	counter=0;
	rt_set_periodic_mode();
	rt_task_init(&task, fun, 1, STACK_SIZE, TASK_PRIORITY, 1, 0);
	rtf_create(FIFO, 8000);
	tick_period = start_rt_timer(nano2count(TICK_PERIOD));
	rt_task_make_periodic(&task, rt_get_time() + tick_period, tick_period);
	h=.01;
	return 0;
}

void cleanup_module(void)
{
	int subdevice = 0;    
	int chan = 0; 
	int range = 1;
	int aref = 0;
	comedi_t *device;
	device=comedi_open("/dev/comedi0");
	comedi_data_write(device,1,chan,0,aref,2048);
	stop_rt_timer();
	rtf_destroy(FIFO);
	rt_task_delete(&task);
	return;
}

MODULE_LICENSE("GPL");

My questions are:

1. Is comedi_get_data doing all the acquisition set up when it is
invoked inside the function 'fun'? In other words, if I put a
comedi_data_read_hint before the while loop, would it be quicker? Also,
would that be a problem it I do the comedi_open inside the init_module()
function?

2. If any of you are kind enough to have a quick look at it, could you
suggest any optimization?

3. Which part of the 'fun' is periodic, just the while loop, right?

4. What happen if the computer cannot process the function inside the
periodic task in time?

5. TASK_PRIORITY, does anyone knows which are the options?

Many, many thanks.

richard
---
Dr R. Leao
John Curtin School of Medical Research,
The Australian National University

Received on 2005-05-30Z23:35:38