Ejemplo n.º 1
3
Archivo: ex07c.c Proyecto: jd7h/des
void demo(void *arg)
{
    //Round Robin
    rt_task_set_mode(0,T_RRB,NULL);
    rt_task_slice(NULL,15); //time slice in jiffies

    RTIME starttime, runtime;
    int num=*(int *)arg;
    RT_TASK *curtask;
    RT_TASK_INFO curtaskinfo;

    rt_printf("Task  : %d\n",num);

    rt_sem_p(&mysync,TM_INFINITE);

    // let the task run RUNTIME(=200) jiffies in steps of SPINTIME(=20) jiffies
    runtime = 0;
    while(runtime < EXECTIME) {
      rt_timer_spin(SPINTIME*BASEPERIOD);  // spin cpu doing nothing
      // note: rt_timer_spin function does not accept jiffies only nanoseconds
      //       deviates from timing conventions throughout the Xenomai API

      runtime = runtime + SPINTIME;

      rt_printf("Running Task  : %d  at time : %d\n",num,runtime);
    }
    rt_printf("End Task  : %d\n",num);
}
Ejemplo n.º 2
0
static void rr_task(void *arg)
{
	int ret, n;

	traceobj_enter(&trobj);

	ret = rt_task_slice(NULL, RR_QUANTUM);
	traceobj_check(&trobj, ret, 0);

	ret = rt_sem_p(&sem, TM_INFINITE);
	traceobj_check(&trobj, ret, 0);

	for (n = 0; n < 1000000; n++) {
		d *= 0.99;
		f = d / 16;
	}

	traceobj_exit(&trobj);
}
Ejemplo n.º 3
0
//startup code
void startup()
{
	int i;
	char str[10] ;

	// semaphore to sync task startup on
	rt_sem_create(&mysync, "MySemaphore", 0, S_FIFO);

	// change to period mode because round robin does not work
	// in one shot mode
	rt_timer_set_mode(BASEPERIOD);// set tick period
	for(i = 0; i < NTASKS; i++) {
		rt_printf("start task: %d\n", i);
		sprintf(str, "task%d", i);
		rt_task_create(&demo_task[i], str, 0, 50, 0);
		rt_task_slice(&demo_task[i], 1);
		rt_task_start(&demo_task[i], &demo, &i);
	}
	rt_printf("wake up all tasks\n");
	rt_sem_broadcast(&mysync);
}