Example #1
0
File: ucal.c Project: cjecho/RTAI
int main(int argc, char *argv[])
{
	int fifo, period, skip, average = 0;
	RT_TASK *task;
	RTIME expected;

        if ((fifo = open("/dev/rtf0", O_WRONLY)) < 0) {
                printf("Error opening FIFO0 in UCAL\n");
                exit(1);
        }
 	if (!(task = rt_task_init_schmod(nam2num("UCAL"), 0, 0, 0, SCHED_FIFO, 0xF))) {
		printf("Cannot init UCAL\n");
		exit(1);
	}

	rt_set_oneshot_mode();
	period = start_rt_timer(nano2count(atoi(argv[1])));
	mlockall(MCL_CURRENT | MCL_FUTURE);
	rt_make_hard_real_time();
	expected = rt_get_time() + 100*period;
	rt_task_make_periodic(task, expected, period);
	for (skip = 0; skip < atoi(argv[2]); skip++) {
		expected += period;
		rt_task_wait_period();
		average += (int)count2nano(rt_get_time() - expected);
	}
	rt_make_soft_real_time();
	stop_rt_timer();
	rt_task_delete(task);
	write(fifo, &average, sizeof(average));
	close(fifo);
	exit(0);
}
Example #2
0
File: stest.c Project: cjecho/RTAI
int main(void)
{
	struct sched_param mysched;

	mysched.sched_priority = sched_get_priority_max(SCHED_FIFO);
	if( sched_setscheduler( 0, SCHED_FIFO, &mysched ) == -1 ) {
		puts(" ERROR IN SETTING THE SCHEDULER UP");
		perror("errno");
		exit(0);
 	}
	rt_grow_and_lock_stack(20000);

#ifdef ONE_SHOT
	rt_set_oneshot_mode();
#endif
	start_rt_timer(nano2count(TICK_PERIOD));
	firing_time = rt_get_time();
	period = nano2count(1000000);
	prt = rt_init_timer();
	rt_insert_timer(prt, 1, firing_time, period, prh, 0, 1);
	rt_tasklet_use_fpu(prt, 1);
	seqt = rt_init_timer();
	rt_insert_timer(seqt, 0, firing_time, 0, seqh, 0, 1);
	while(!end) sleep(1);
	stop_rt_timer();
	rt_delete_timer(prt);
	rt_delete_timer(seqt);
	return 0;
}
Example #3
0
int init_module(void)
{
	int i;

	rt_sem_init(&barrier, NTASKS + 1);

	smbx    = rt_msgget(nam2num("SMSG"), 0x666 | IPC_CREAT);
	for (i = 0; i < NTASKS; i++) {
		char mname[6] = "RMBX";
		mname[4] = i + '0';
		mname[5] = 0;
		rmbx[i] = rt_msgget(nam2num(mname), 0x666 | IPC_CREAT);
	}

	rt_set_oneshot_mode();
	start_rt_timer(0);

	rt_kthread_init(&bthread, bfun, 0, 0x8000, 1, 1, 0);
	rt_task_resume(&bthread);
	for (i = 0; i < NTASKS; i++) {
		rt_kthread_init(&mthread[i], mfun, i, 0x8000, i + 2, 1, 0);
		rt_task_resume(&mthread[i]);
	}

	return 0;
}
int init_module(void)
{
	int i;
	DBG_PRINT_INIT;
	if (rt_task_init(&start_task, start_task_code, 0, 10000, 10, 0, 0) != 0) {
		printk("Could not start init task\n");
	}
	if (rt_mbx_init(&mbx_in, NUM_TASKS*8) || rt_mbx_init(&mbx_out, NUM_TASKS*8)) {
		printk("could not create message queue\n");
		return 1;
	}
	for (i = 0; i < NUM_TASKS; ++i) {
		rt_sem_init(&sems[i], 0);
		if (rt_task_init(&tasks[i], task_code, i, 3000, NUM_TASKS - i, 0, 0) != 0) {
			printk("rt_task_ipc_init failed\n");
			return 1;
		}
	}     
#ifdef ONE_SHOT
	rt_set_oneshot_mode();
#endif
	start_rt_timer_ns(10000000);
	checkt = rdtsc();
	checkj = jiffies;
	rt_task_resume(&start_task);
	for (i = 0; i < NUM_TASKS; ++i) {
		rt_task_resume(&tasks[i]);
	}     
	return 0;
}
static int my_init(void) {
    int i, ierr1, ierr2;
    rt_typed_sem_init(&semaphore1, 0, BIN_SEM);
    rt_typed_sem_init(&semaphore2, 0, BIN_SEM);

    rt_set_oneshot_mode();
    ierr1 = rt_task_init_cpuid(&tasks[0], task_body1, 0, STACK_SIZE, 1, 0, 0, 0);
    ierr2 = rt_task_init_cpuid(&tasks[1], task_body2, 0, STACK_SIZE, 0, 0, 0, 0);

    printk("[task 1] init return code %d by program %s\n", ierr1, __FILE__);
    printk("[task 2] init return code %d by program %s\n", ierr2, __FILE__);

    if (ierr1 == -1 || ierr2 == -1) {
        return -1;
    }

    start_rt_timer(nano2count(TICK_PERIOD));

    first_release = rt_get_time();
    for (i = 0 ; i < N_TASK ; i++) {
        rt_task_make_periodic(&tasks[i], first_release, PERIOD);
    }

    return 0;
}
static int my_init(void) {
    int i;

    rt_set_oneshot_mode();

    for (i = 0 ; i < N_TASK ; i++) {
        int ierr = rt_task_init_cpuid(&tasks[i], task_body, i, STACK_SIZE, Priority[i], 0, 0, 0);

        printk("[task %d] init return code %d by program %s\n", i, ierr, __FILE__);

        if (ierr == -1) {
            return ierr;
        }
    }

    start_rt_timer(nano2count(TICK_PERIOD));

    time_unit = calibrate();

	first_release = rt_get_time();
    for (i = 0 ; i < N_TASK ; i++) {
        rt_task_make_periodic(&tasks[i], first_release, Period[i] * time_unit);
    }

    return 0;
}
Example #7
0
int init_module(void)
{
    RTIME tick_period;
    int err;

    printk("%s: Loading RX%d Test module...\n", test_name, rt_port);

    err = rt_spopen(rt_port, 
		    line_param[0], line_param[1], line_param[2], 
		    line_param[3], line_param[4], line_param[5]);
    if (err) return err;
	
    /* Register error handler */
    rt_spset_err_callback_fun(rt_port, error_handler);

    /* Start RX message handler */
    rt_task_init(&thread, rx_handler, 0, STACK_SIZE, 0, 0, 0);
    rt_task_resume(&thread);

    rt_set_oneshot_mode();
    if (period) {
	tick_period = start_rt_timer(nano2count(period));
	rt_task_make_periodic(&thread, rt_get_time(), tick_period);
    }
    return 0;
}
Example #8
0
int realtime_on(void){
    int retval;

    /*RT_TASK * rt_task_init_schmod(unsigned long name, int priority, int stack_size, int max_msg_size, int policy, int cpus_allowed)*/
    if(!(task = rt_task_init_schmod(nam2num("TAREA11"), 1, 0, 0, SCHED_FIFO, 0xF))){
        printf("rt_task_init_schmod error\n");
        return -1;
    }

    mlockall( MCL_CURRENT | MCL_FUTURE );
    printf("TAREAL EN TIEMPO REAL (name = %lu, address = %p)\n", nam2num("TAREA1"), task);

    rt_set_oneshot_mode();
    task_period_count = nano2count(task_period_ns);
    timer_period_count = start_rt_timer(task_period_count);/*Inicia temporizador*/

    printf("\tRequested %d counts, got %d counts\n",(int) task_period_count, (int) timer_period_count);
    retval = rt_task_make_periodic(task, rt_get_time() + task_period_count, task_period_count); /* recurring period */
    if (0 != retval) {
      printf("rt_task_make_periodic error\n");
      return -1;
    }

    rt_make_hard_real_time(); 

    printf("\tPeriodo=%f\n\n",(double)task_period_ns/1e9);

    return 1;
}
Example #9
0
int main(void)
{
	RT_TASK *spktsk, *plrtsk;
	RTIME period;
	char buf[BUFSIZE], data, temp;
	unsigned int msg, i, len;

        printf("\n\nGENERIC RECEIVE\n");
	ioperm(PORT_ADR, 1, 1);
	iopl(3);
        if (!(spktsk = rt_task_init_schmod(nam2num("SPKTSK"), 1, 0, 0, SCHED_FIFO, 0xF))) {
                printf("CANNOT INIT SPEAKER TASK\n");
                exit(1);
        }

	rt_set_oneshot_mode();
	start_rt_timer(0);
	mlockall(MCL_CURRENT | MCL_FUTURE);
	printf("\nSPEAKER TASK RUNNING\n");
	rt_make_hard_real_time();

	period = nano2count(PERIOD);
	rt_task_make_periodic(spktsk, rt_get_time() + 5*period, period);

	rt_returnx(rt_receivex(0, &msg, sizeof(int), &len), &msg, 1);
        for (i = 0; i < 100; i++) {
		rt_returnx(rt_receivex(0, &msg, sizeof(int), &len), &msg, 1);
        }

	len = 0;
	while(1) {
		if (len) {
			data = filter(buf[i++]);
			temp = inb(PORT_ADR);            
			temp &= 0xfd;
			temp |= (data & 1) << 1;
			outb(temp, PORT_ADR);
			len--;
		} else {
			if (rt_evdrpx(0, buf, BUFSIZE, &i)) {
//				rt_printk("EVDRP %d\n", i);
			}
			if ((plrtsk = rt_receivex_if(0, buf, BUFSIZE, &len))) {
				rt_returnx(plrtsk, &len, sizeof(int));
				if (len == sizeof(int) && ((int *)buf)[0] == 0xFFFFFFFF) {
					break;
				} 
				i = 0;
			}
		}
		rt_task_wait_period();
	}

	rt_sleep(nano2count(100000000));
	rt_make_soft_real_time();
	stop_rt_timer();
	rt_task_delete(spktsk);
	printf("\nSPEAKER TASK STOPS\n");
	return 0;
}
Example #10
0
int tdma_attach(struct rtnet_device *rtdev, void *priv)
{
    struct rtmac_tdma *tdma = (struct rtmac_tdma *)priv;

    rt_printk("RTmac: tdma1: init time devision multiple access (tdma) for realtime stations\n");

    memset(tdma, 0, sizeof(struct rtmac_tdma));
    spin_lock_init(&tdma->delta_t_lock);

    tdma->rtdev = rtdev;

    /*
     * init semas, they implement a producer consumer between the
     * sending realtime- and the driver-task
     *
     */
    rt_sem_init(&tdma->client_tx, 0);

    /*
     * init tx queue
     *
     */
    rtskb_prio_queue_init(&tdma->tx_queue);

    /*
     * init rt stuff
     * - timer
     * - list heads
     *
     */
    /* generic */

    /* master */
    init_timer(&tdma->rt_add_timer);
    INIT_LIST_HEAD(&tdma->rt_add_list);
    INIT_LIST_HEAD(&tdma->rt_list);
    INIT_LIST_HEAD(&tdma->rt_list_rate);

    init_timer(&tdma->task_change_timer);
    init_timer(&tdma->master_wait_timer);
    init_timer(&tdma->master_sent_conf_timer);
    init_timer(&tdma->master_sent_test_timer);

    rtskb_queue_init(&tdma->master_queue);


    /* client */
    init_timer(&tdma->client_sent_ack_timer);


    /*
     * start timer
     */
    rt_set_oneshot_mode();
    start_rt_timer(0);

    return 0;
}
Example #11
0
int init_module(void)
{
    unsigned int            local_ip;
    unsigned int            server_ip = rt_inet_aton(server_ip_s);
    struct rtnet_callback   callback  = {echo_rcv, NULL};


    if (strlen(local_ip_s) != 0)
        local_ip = rt_inet_aton(local_ip_s);
    else
        local_ip = INADDR_ANY;

    if (interval < 1) interval = 1;
    if (interval > 1000) interval = 1000;

    if (packetsize < 1) packetsize = 1;
    if (packetsize > 1400) packetsize = 1400;

    printk("***** start of rt_client ***** %s %s *****\n", __DATE__, __TIME__);
    printk("local  ip address %s=%08x\n", local_ip_s, local_ip);
    printk("server ip address %s=%08x\n", server_ip_s, server_ip);
    printk("interval = %d\n", interval);
    printk("packetsize = %d\n", packetsize);
    printk("start timer %d\n", start_timer);

    rtf_create(PRINT, 8000);

    /* create rt-socket */
    sock = socket_rt(AF_INET,SOCK_DGRAM,0);

    /* bind the rt-socket to local_addr */
    memset(&local_addr, 0, sizeof(struct sockaddr_in));
    local_addr.sin_family = AF_INET;
    local_addr.sin_port = htons(RCV_PORT);
    local_addr.sin_addr.s_addr = local_ip;
    bind_rt(sock, (struct sockaddr *)&local_addr, sizeof(struct sockaddr_in));

    /* set server-addr */
    memset(&server_addr, 0, sizeof(struct sockaddr_in));
    server_addr.sin_family = AF_INET;
    server_addr.sin_port = htons(SRV_PORT);
    server_addr.sin_addr.s_addr = server_ip;

    /* set up callback handler */
    ioctl_rt(sock, RTNET_RTIOC_CALLBACK, &callback);

    if (start_timer) {
        rt_set_oneshot_mode();
        start_rt_timer(0);
    }

    rt_task_init(&rt_task,(void *)process,0,4096,10,0,NULL);
    rt_task_make_periodic_relative_ns(&rt_task, 1000000,
                                      (RTIME)interval * 1000000);

    return 0;
}
int init_module(void)
{
	RTIME period;
	rt_task_init(&agentask, fun, 0, STACK_SIZE, 0, 0, 0);
	rt_set_oneshot_mode();
	period = start_rt_timer((int) nano2count(TICK_PERIOD));
	rt_task_make_periodic(&agentask, rt_get_time() + period, period);
	return 0;
}
Example #13
0
int init_module(void)
{
    rt_task_init(&parent_task, parent_func, 0, STACK_SIZE, 0, 0, 0);
    rt_set_oneshot_mode();
    period = start_rt_timer((int) nano2count(TICK_PERIOD));
    rt_set_runnable_on_cpus(&parent_task, RUN_ON_CPUS);
    rt_task_resume(&parent_task);
    return 0;
}
Example #14
0
static int
__latency_init(void)
{

	/* XXX check option ranges here */

	/* register a proc entry */
#ifdef CONFIG_PROC_FS
	create_proc_read_entry("rtai/latency_calibrate", /* name             */
	                       0,			 /* default mode     */
	                       NULL, 			 /* parent dir       */
			       proc_read, 		 /* function         */
			       NULL			 /* client data      */
	);
#endif

	rtf_create(DEBUG_FIFO, 16000);	/* create a fifo length: 16000 bytes */
	rt_linux_use_fpu(use_fpu);	/* declare if we use the FPU         */

	rt_task_init(			/* create our measuring task         */
			    &thread,	/* poiter to our RT_TASK             */
			    fun,	/* implementation of the task        */
			    0,		/* we could transfer data -> task    */
			    3000,	/* stack size                        */
			    0,		/* priority                          */
			    use_fpu,	/* do we use the FPU?                */
			    0		/* signal? XXX                       */
	);

	rt_set_runnable_on_cpus(	/* select on which CPUs the task is  */
		&thread,		/* allowed to run                    */
		RUN_ON_CPUS
	);

	/* Test if we have to start the timer                                */
	if (start_timer || (start_timer = !rt_is_hard_timer_running())) {
		if (timer_mode) {
			rt_set_periodic_mode();
		} else {
			rt_set_oneshot_mode();
		}
		rt_assign_irq_to_cpu(TIMER_8254_IRQ, TIMER_TO_CPU);
		period_counts = start_rt_timer(nano2count(period));
	} else {
		period_counts = nano2count(period);
	}

	loops = (1000000000*avrgtime)/period;

	/* Calculate the start time for the task. */
	/* We set this to "now plus 10 periods"   */
	expected = rt_get_time() + 10 * period_counts;
	rt_task_make_periodic(&thread, expected, period_counts);
	return 0;
}
Example #15
0
int main(void)
{
	int i, indx[NTASKS];       
	unsigned long mytask_name = nam2num("MASTER");

	signal(SIGINT, endme);

 	if (!(mytask = rt_task_init(mytask_name, 1, 0, 0))) {
		printf("CANNOT INIT TASK %lu\n", mytask_name);
		exit(1);
	}
	printf("MASTER INIT: name = %lu, address = %p.\n", mytask_name, mytask);

	sem = rt_sem_init(10000, 0); 
	rt_set_oneshot_mode();
//	rt_set_periodic_mode();
	start_rt_timer(0);

	for (i = 0; i < ntasks; i++) {
		indx[i] = i;
		if (!(task[i] = rt_thread_create(thread_fun, &indx[i], 10000))) {
			printf("ERROR IN CREATING THREAD %d\n", indx[i]);
			exit(1);
 		}       
 	}       

	for (i = 0; i < ntasks; i++) {
		while (!rt_get_adr(taskname(i))) {
			rt_sleep(nano2count(20000000));
		}
	}

	for (i = 0; i < ntasks; i++) {
		rt_send(rt_get_adr(taskname(i)), (unsigned long)sem);
	}

	for (i = 0; i < ntasks; i++) {
		rt_sem_wait(sem);
	}

	for (i = 0; i < ntasks; i++) {
		while (rt_get_adr(taskname(i))) {
			rt_sleep(nano2count(20000000));
		}
	}

	for (i = 0; i < ntasks; i++) {
		rt_thread_join(task[i]);
	}
	rt_sem_delete(sem);
	stop_rt_timer();
	rt_task_delete(mytask);
	printf("MASTER %lu %p ENDS\n", mytask_name, mytask);
	return 0;
}
Example #16
0
int init_module(void)
{
	rt_task_init(&thread, fun, 0, 3000, 0, 0, 0);
	rt_set_oneshot_mode();
	period = start_rt_timer(nano2count(PERIOD));
	expected = rt_get_time() + 10*period;
	rt_task_make_periodic(&thread, expected, period);
//	rt_printk("\n\n*** 'LATENCY_8254 IN USE %d", LATENCY_8254);
	printk("\n*** Wait %d seconds for it ... ***\n\n", (int)(((long long)SKIP*(long long)PERIOD)/1000000000));
	return 0;
}
Example #17
0
int init_module(void)
{
#ifdef ONE_SHOT
	rt_set_oneshot_mode();
#endif
	rt_sem_init(&notEmpty, 0);
	rt_typed_sem_init(&mutex, 1, SEM_TYPE);
	TimesBufferstatus = empty;
	HourBufferstatus = empty;
	return 0;
}
Example #18
0
int init_module(void)
{
#ifdef ONE_SHOT
	rt_set_oneshot_mode();
#endif
	firing_time = rt_get_time() + nano2count(100000000);
	period = nano2count(TICK_PERIOD);
	start_rt_timer(period);
	rt_insert_timer(&prt, 1, firing_time, period, prh, 0xAAAAAAAA, 0);
	rt_insert_timer(&ost, 0, firing_time, nano2count(PERIODIC_BUDDY*TICK_PERIOD/2), osh, 0xBBBBBBBB, 0);
	return 0;
}
Example #19
0
int main(void)
{
	RT_TASK *spktsk, *plrtsk;
	RTIME period;
	MBX *mbx;
	char data, temp;
	unsigned int msg, i;

//	ioperm(PORT_ADR, 1, 1);
	iopl(3);
        if (!(spktsk = rt_task_init_schmod(nam2num("SPKTSK"), 1, 0, 0, SCHED_FIFO, 0xF))) {
                printf("CANNOT INIT SPEAKER TASK\n");
                exit(1);
        }
        mbx = rt_mbx_init(nam2num("SNDMBX"), 4000);
	printf("\nSPEAKER TASK RUNNING\n");

	rt_set_oneshot_mode();
	start_rt_timer(0);
	mlockall(MCL_CURRENT | MCL_FUTURE);
	rt_make_hard_real_time();

	period = nano2count(PERIOD);
	rt_task_make_periodic(spktsk, rt_get_time() + 5*period, period);

        for (i = 0; i < 100; i++) {
		plrtsk = rt_receive(0, &msg);
		rt_return(plrtsk, msg);
        }

	while(1) {
		if (!rt_mbx_receive_if(mbx, &data, 1)) {
			data = filter(data);
			temp = inb(PORT_ADR);            
			temp &= 0xfd;
			temp |= (data & 1) << 1;
			outb(temp, PORT_ADR);
		}
		rt_task_wait_period();
		if ((plrtsk = rt_receive_if(0, &msg))) {
			rt_return(plrtsk, msg);
			break;
		} 
	}

	rt_sleep(nano2count(100000000));
	rt_make_soft_real_time();
	rt_mbx_delete(mbx);
	stop_rt_timer();
	rt_task_delete(spktsk);
	printf("\nSPEAKER TASK STOPS\n");
	return 0;
}
Example #20
0
int init_module(void)
{
	RTIME tick_period;
	rtf_create_using_bh(CMDF, 4, 0);
#ifdef ONE_SHOT
	rt_set_oneshot_mode();
#endif
	tick_period = start_rt_timer(nano2count(TICK_PERIOD));
	rt_task_init(&thread, intr_handler, 0, STACK_SIZE, 0, 0, 0);
	rt_task_make_periodic(&thread, rt_get_time() + 2*tick_period, tick_period);
	return 0;
}
Example #21
0
int init_module(void)
{
	rt_bits_init(&bits, 0xFFFF0000);
	rt_task_init(&task0, fun0, 0, STACK_SIZE, 0, 0, 0);
	rt_task_init(&task1, fun1, 0, STACK_SIZE, 0, 0, 0);
	rt_task_init(&task, fun, 0, STACK_SIZE, 0, 0, 0);
	rt_set_oneshot_mode();
	start_rt_timer(nano2count(SLEEP_TIME));
	rt_task_resume(&task0);
	rt_task_resume(&task1);
	rt_task_resume(&task);
	return 0;
}
Example #22
0
int main(void)
{
	RT_TASK *mytask;
	int smbx, rmbx[NTASKS];
	int i, bthread, mthread[NTASKS];
	char msg[] = "let's end the game";

	mytask = rt_thread_init(nam2num("MAIN"), 2, 0, SCHED_FIFO, 0xF);
	barrier = rt_sem_init(rt_get_name(0), NTASKS + 1);

	smbx    = rt_msgget(nam2num("SMSG"), 0x666 | IPC_CREAT);
	for (i = 0; i < NTASKS; i++) {
		char mname[6] = "RMBX";
		mname[4] = i + '0';
		mname[5] = 0;
		rmbx[i] = rt_msgget(nam2num(mname), 0x666 | IPC_CREAT);
	}

	rt_set_oneshot_mode();
	start_rt_timer(0);

	bthread = rt_thread_create(bfun, 0, 0x8000);
	for (i = 0; i < NTASKS; i++) {
		mthread[i] = rt_thread_create(mfun, (void *)i, 0x8000);
	}

	printf("IF NOTHING HAPPENS IS OK, TYPE ENTER TO FINISH.\n");
	getchar();

	for (i = 0; i < NTASKS; i++) {
		end = i;
		rt_msgsnd_nu(rmbx[i], 1, msg, sizeof(msg), 0);
		rt_thread_join(mthread[i]);
	}

	end = NTASKS;
	rt_msgsnd_nu(smbx, 1, msg, sizeof(msg), 0);
	rt_thread_join(bthread);

	for (i = 0; i < NTASKS; i++) {
		rt_msgctl(rmbx[i], IPC_RMID, NULL);
		printf("TASK %d, LOOPS: %d.\n", i, cnt[i]); 
	}
	rt_msgctl(smbx, IPC_RMID, NULL);

	stop_rt_timer();
	rt_sem_delete(barrier);
	rt_task_delete(mytask);
	printf("MAIN TASK ENDS.\n");
	return 0;
}
Example #23
0
File: mbx.c Project: cjecho/RTAI
int init_module(void)
{
	rt_typed_mbx_init(&smbx, 5, MBX_TYPE); //5
	rt_typed_mbx_init(&rmbx[0], 1, MBX_TYPE); //1
	rt_typed_mbx_init(&rmbx[1], 3, MBX_TYPE); //3
	rt_task_init(&btask, bfun, 0, STACK_SIZE, 0, 0, 0);
	rt_task_init(&mtask[0], mfun, 0, STACK_SIZE, 1, 0, 0);
	rt_task_init(&mtask[1], mfun, 1, STACK_SIZE, 1, 0, 0);
	rt_set_oneshot_mode();
	start_rt_timer(nano2count(SLEEP_TIME));
	rt_task_resume(&btask);
	rt_task_resume(&mtask[0]);
	rt_task_resume(&mtask[1]);
	return 0;
}
Example #24
0
int init_module(void)
{
	int i;

	thread = (RT_TASK *)kmalloc(NTASKS*sizeof(RT_TASK), GFP_KERNEL);
	rt_rwl_init(&rwl);
	rt_set_oneshot_mode();
	start_rt_timer(0);
	for (i = 0; i < NTASKS; i++) {
		extcnt[i] = 999999;
		rt_task_init(&thread[i], fun, i + 1, STACK_SIZE, NTASKS - i, 0, 0);
		rt_task_resume(&thread[i]);
	}
	return 0;
}
Example #25
0
File: sound.c Project: ArcEye/RTAI
int main(void)
{
	pthread_t thread;
	unsigned int player, cnt;
	unsigned long msg;
	RT_TASK *mytask;
	MBX *mbx;
	char data[BUFSIZE];

	signal(SIGINT, endme);
	rt_allow_nonroot_hrt();

	if ((player = open("../../../share/linux.au", O_RDONLY)) < 0) {
		printf("ERROR OPENING SOUND FILE (linux.au)\n");
		exit(1);
	}
 	if (!(mytask = rt_task_init(nam2num("SNDMAS"), 2, 0, 0))) {
		printf("CANNOT INIT MASTER TASK\n");
		exit(1);
	}
	mlockall(MCL_CURRENT | MCL_FUTURE);
	printf("\nINIT MASTER TASK %p\n\n(CTRL-C TO END EVERYTHING)\n", mytask);

	mbx = rt_typed_named_mbx_init("SNDMBX", 2000, FIFO_Q);
	rt_set_oneshot_mode();
	start_rt_timer(0);
	thread = rt_thread_create(intr_handler, NULL, 10000);
	rt_mbx_receive(mbx, &data, 1);

	while (!end) {	
		lseek(player, 0, SEEK_SET);
		while(!end && (cnt = read(player, &data, BUFSIZE)) > 0) {
			rt_mbx_send(mbx, data, cnt);
		}
	}

	rt_rpc(rt_get_adr(nam2num("SOUND")), msg, &msg); 
	while (rt_get_adr(nam2num("SOUND"))) {
		rt_sleep(nano2count(1000000));
	}
	rt_task_delete(mytask);
	rt_mbx_delete(mbx);
	stop_rt_timer();
	close(player);
	printf("\nEND MASTER TASK %p\n", mytask);
	rt_thread_join(thread);
	return 0;
}
Example #26
0
int __init rtcfg_init(void)
{
    int ret;


    printk("RTcfg: init real-time configuration distribution protocol\n");

#if defined(CONFIG_RTAI_24) || defined(CONFIG_RTAI_30) || defined(CONFIG_RTAI_31)
    if (start_timer) {
        rt_set_oneshot_mode();
        start_rt_timer(0);
    }
#endif

    ret = rtcfg_init_ioctls();
    if (ret != 0)
        goto error1;

    rtcfg_init_state_machines();

    ret = rtcfg_init_frames();
    if (ret != 0)
        goto error2;

#ifdef CONFIG_PROC_FS
    ret = rtcfg_init_proc();
    if (ret != 0)
        goto error3;
#endif

    return 0;

  error3:
    rtcfg_cleanup_frames();

  error2:
    rtcfg_cleanup_state_machines();
    rtcfg_cleanup_ioctls();

  error1:
#if defined(CONFIG_RTAI_24) || defined(CONFIG_RTAI_30) || defined(CONFIG_RTAI_31)
    if (start_timer)
        stop_rt_timer();
#endif

    return ret;
}
int init_module(void)
{
	int ret;

	unsigned long local_ip  = rt_inet_aton(local_ip_s);
	unsigned long server_ip = rt_inet_aton(server_ip_s);

	rtf_create(PRINT, 40000);
	rt_sem_init(&tx_sem, 0);

	rt_printk ("local  ip address %s=%8x\n", local_ip_s, (unsigned int) local_ip);
	rt_printk ("server ip address %s=%8x\n", server_ip_s, (unsigned int) server_ip);

	/* create rt-socket */
	sock=rt_socket(AF_INET,SOCK_DGRAM,0);
	
	/* bind the rt-socket to local_addr */	
	memset(&local_addr, 0, sizeof(struct sockaddr_in));
	local_addr.sin_family = AF_INET;
	local_addr.sin_port = htons(RCV_PORT);
	local_addr.sin_addr.s_addr = local_ip;
	ret=rt_socket_bind(sock, (struct sockaddr *) &local_addr, sizeof(struct sockaddr_in));

	/* set server-addr */
	memset(&server_addr, 0, sizeof(struct sockaddr_in));
	server_addr.sin_family = AF_INET;
	server_addr.sin_port = htons(SRV_PORT);
	server_addr.sin_addr.s_addr = server_ip;

	// set up receiving
	rt_socket_callback(sock, echo_rcv, NULL);
	
	rt_set_oneshot_mode();
	start_rt_timer(TIMERTICKS);

        ret=rt_task_init(&rt_task,(void *)process,0,4096,10,0,NULL);

        rt_task_resume(&rt_task);

        rt_request_global_irq(parirq, parport_irq_handler);
        rt_startup_irq(parirq);

        outb(0xFF, PAR_DATA);
        outb(0x14 + KHZ0_1, PAR_CONTROL);

	return ret;
}
Example #28
0
File: main.c Project: glegrain/RTAI
static int test_init(void) {
    int ierr;

    rt_set_oneshot_mode();

    printk("PGM STARTING\n");

    init_matrices();

    // Create real-time tasks
    ierr = rt_task_init_cpuid(&sens_task,  // task
                              senscode,    // rt_thread
                              0,           // data
                              STACK_SIZE,  // stack_size
                              3,           // priority
                              0,           // uses_fpu
                              0,           // signal
                              0);          // cpuid

    ierr = rt_task_init_cpuid(&act_task,   // task
                              actcode,     // rt_thread
                              0,           // data
                              STACK_SIZE,  // stack_size
                              4,           // priority
                              0,           // uses_fpu
                              0,           // signal
                              0);          // cpuid

    // init semaphores
    rt_typed_sem_init(&sensDone,  // semaphore pointer
                      0,          // initial value
                      BIN_SEM);   // semaphore type

    if (!ierr) {

        start_rt_timer(nano2count(TICK_PERIOD));
        now = rt_get_time();
        // Start tasks
        rt_task_make_periodic(&sens_task, now,  nano2count(PERIOD));
        //rt_task_resume(&act_task);

    }
    //return ierr;
    return 0; // pour ne pas faire planter le kernel
}
Example #29
0
int init_module(void)
{
	int i;

	rt_set_oneshot_mode();
	start_rt_timer(0);
	sync_sem = rt_named_sem_init("SYNCSM", 0);
	prio_sem = rt_named_sem_init("PRIOSM", 0);
	if (!(mbx_in = rt_named_mbx_init("MBXIN", NUM_TASKS*8)) || !(mbx_out = rt_named_mbx_init("MBXOUT", NUM_TASKS*8))) {
		rt_printk("could not create message queues\n");
		return 1;
	}
	for (i = 0; i < NUM_TASKS; ++i) {
		sems[i] = rt_named_sem_init(sem[i], 0);
	}
	print_sem = rt_typed_named_sem_init("PRTSEM", 1, BIN_SEM);
	return 0;
}
Example #30
0
File: mbxdel.c Project: cjecho/RTAI
int init_module(void)
{
	int i;
        rt_set_oneshot_mode();
	start_rt_timer(0);
	rt_mbx_init(&mbx, 5);
	for (i = 0; i < NUM_TASKS; i++) {
		rt_task_init(&task[i], fun1, i, STACK_SIZE, 0, 0, 0);
		rt_task_resume(&task[i]);
	}
	rt_task_init(&task[NUM_TASKS], fun2, NUM_TASKS, STACK_SIZE, 1, 0, 0);
	rt_task_resume(&task[NUM_TASKS]);
	while (atomic_read(&cleanup) < (NUM_TASKS + 1)) {
		current->state = TASK_INTERRUPTIBLE;
		schedule_timeout(HZ/10);
	}
	return 0;
}