Esempio n. 1
0
static int __switches_init(void)
{
	int i;
	int e;

	printk("\nWait for it ...\n");
	rt_typed_sem_init(&sem, 1, SEM_TYPE);
	rt_linux_use_fpu(1);
	thread = (RT_TASK *)kmalloc(ntasks*sizeof(RT_TASK), GFP_KERNEL);
	for (i = 0; i < ntasks; i++) {
#ifdef DISTRIBUTE
		e = rt_task_init_cpuid(thread + i, pend_task, i, stack_size, 0, use_fpu, 0,  i%2);
#else
		e = rt_task_init_cpuid(thread + i, pend_task, i, stack_size, 0, use_fpu, 0,  hard_cpu_id());
#endif
		if (e < 0) {
		task_init_has_failed:
		    rt_printk("switches: failed to initialize task %d, error=%d\n", i, e);
		    while (--i >= 0)
			rt_task_delete(thread + i);
		    return -1;
		}
	}
	e = rt_task_init_cpuid(&task, sched_task, i, stack_size, 1, use_fpu, 0, hard_cpu_id());
	if (e < 0)
	    goto task_init_has_failed;
	rt_task_resume(&task);

	return 0;
}
Esempio n. 2
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;
}
Esempio n. 4
0
File: main.c Progetto: 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
}
Esempio n. 5
0
File: clock.c Progetto: cjecho/RTAI
int init_module(void)
{
	hide = FALSE;
	pause = FALSE;
	rtf_create(Keyboard, 1000);
	rtf_create_handler(Keyboard, keybrd_handler);
	rtf_create(Screen, 10000);
	rt_sem_init(&keybrd_sem, 0);
	rt_task_init_cpuid(&read, ClockChrono_Read, 0, 2000, 0, 0, 0, READ_RUN_ON_CPU);
	rt_task_init_cpuid(&chrono, ClockChrono_Chrono, 0, 2000, 0, 0, 0, CHRONO_RUN_ON_CPU);
	rt_task_init_cpuid(&clock, ClockChrono_Clock, 0, 2000, 0, 0, 0, CLOCK_RUN_ON_CPU);
	rt_task_init_cpuid(&write, ClockChrono_Write, 0, 2000, 0, 0, 0, WRITE_RUN_ON_CPU);
	start_rt_apic_timers(apic_setup_data, 0);
	rt_task_resume(&read);
	rt_task_resume(&chrono);
	rt_task_resume(&clock);
	rt_task_resume(&write);
	return 0;
}
Esempio n. 6
0
int init_module(void)
{
	rt_set_oneshot_mode();
	start_rt_timer(0);
	if (SemType) {
		printk("USING A RESOURCE SEMAPHORE, AND WE HAVE ...\n");
		rt_typed_sem_init(&mutex, 1, RES_SEM);
	} else {
		printk("USING A BINARY SEMAPHORE, AND WE HAVE ...\n");
		rt_typed_sem_init(&mutex, 1, BIN_SEM | PRIO_Q);
	}
	rt_task_init_cpuid(&taskl, taskl_func, 0, RT_STACK, 1000, 0, 0, 0);
	rt_task_init_cpuid(&taskm, taskm_func, 0, RT_STACK,  500, 0, 0, 0);
	rt_task_init_cpuid(&taskh, taskh_func, 0, RT_STACK,    0, 0, 0, 0);
	rt_task_resume(&taskl);
	rt_task_resume(&taskm);
	rt_task_resume(&taskh);
	return 0;
}
Esempio n. 7
0
static int __preempt_init(void)
{
	RTIME start;

	rtf_create(FIFO, 1000);
	rt_linux_use_fpu(USE_FPU);
	rt_task_init_cpuid(&thread, fun, 0, 5000, 0, USE_FPU, 0, 0);
	rt_task_init_cpuid(&Fast_Task, Fast_Thread, 0, 5000, 1, 0, 0, 0);
	rt_task_init_cpuid(&Slow_Task, Slow_Thread, 0, 5000, 2, 0, 0, 0);
#ifdef ONESHOT_MODE
	rt_set_oneshot_mode();
#endif
	period = start_rt_timer(nano2count(TICK_TIME));
	expected = start = rt_get_time() + 100*period;
	rt_task_make_periodic(&thread, start, period);
	rt_task_make_periodic(&Fast_Task, start, FASTMUL*period);
	rt_task_make_periodic(&Slow_Task, start, SLOWMUL*period);

	return 0;
}
Esempio n. 8
0
File: signal.c Progetto: ArcEye/RTAI
int rt_request_signal(long signal, void (*sighdl)(long, RT_TASK *))
{
	struct sigsuprt_t arg = { NULL, RT_CURRENT, signal, sighdl };
	if (signal >= 0 && sighdl && (arg.sigtask = rt_malloc(sizeof(RT_TASK)))) {
		if (!rt_task_init_cpuid(arg.sigtask, signal_suprt_fun, (long)&arg, SIGNAL_TASK_STACK_SIZE, arg.task->priority, 0, NULL, arg.task->runnable_on_cpus)) {
			rt_task_resume(arg.sigtask);
			rt_task_suspend(arg.task);
			return arg.task->retval;
		}
		rt_free(arg.sigtask);
	}
	return -EINVAL;
}
Esempio n. 9
0
int _rtapi_task_new_hook(task_data *task, int task_id) {
    int retval, v;
    retval = rt_task_init_cpuid(ostask_array[task_id], _rtapi_task_wrapper,
				task_id, task->stacksize, task->prio,
				task->uses_fp, 0 /* signal */, task->cpu);
    if (retval) return retval;

    /* request to handle traps in the new task */
    for(v=0; v<HAL_NR_FAULTS; v++)
        rt_set_task_trap_handler(ostask_array[task_id], v, _rtapi_trap_handler);

    return 0;
}
Esempio n. 10
0
int init_module(void)
{
	int i, k;

	k = 1;
	for (i = 0; i < NTASKS; i++) {
		rt_task_init_cpuid(&thread[i], fun, k = ~k, STACK_SIZE, 0, 0, 0, i%2);
	}
	start_rt_apic_timers(apic_setup_data, 0);
	for (i = 0; i < NTASKS; i++) {
		rt_task_make_periodic_relative_ns(&thread[i], (i+1)*TICK_PERIOD, NTASKS*TICK_PERIOD);
	}
	return 0;
}
Esempio n. 11
0
static int rtai_timers_init(void)
{
	int cpuid;
	
	for (cpuid = 0; cpuid < num_online_cpus(); cpuid++) {
		timers_lock[cpuid] = timers_lock[0];
		timers_list[cpuid] = timers_list[0];
		timers_list[cpuid].cpuid = cpuid;
		timers_list[cpuid].next = timers_list[cpuid].prev = &timers_list[cpuid];
	}
	for (cpuid = 0; cpuid < num_online_cpus(); cpuid++) {
		rt_task_init_cpuid(&timers_manager[cpuid], rt_timers_manager, cpuid, TimersManagerStacksize, TimersManagerPrio, 0, NULL, cpuid);
		rt_task_resume(&timers_manager[cpuid]);
	}
	return 0;
}
Esempio n. 12
0
int init_module(void)
{
	rt_assign_irq_to_cpu(0, 0);
	rtf_create(CMDF, 10000);
	if (Mode) {
		rt_typed_sem_init(&sem, 0, SEM_TYPE);
	}
	rt_task_init_cpuid(&thread, intr_handler, 0, STACK_SIZE, 0, 0, 0, 0);
	rt_task_resume(&thread);
#ifdef IRQEXT
	rt_request_timer((void *)rt_timer_tick_ext, imuldiv(TICK, FREQ_8254, 1000000000), 0);
	rt_set_global_irq_ext(0, 1, 0);
#else
	rt_request_timer((void *)rt_timer_tick, imuldiv(TICK, FREQ_8254, 1000000000), 0);
#endif
	SETUP_8254_TSC_EMULATION;
	return 0;
}
Esempio n. 13
0
int rt_lock_cpu(int cpu, int irqsl[], int nirqsl)
{
	int irq;
	if (cpu >= smp_num_cpus || cpu < 0) {
		return -EINVAL;
	}
	if (!idle_task.magic) {
		rt_task_init_cpuid(&idle_task, idle_fun, 0, STACK_SIZE, RT_LINUX_PRIORITY - 1, 0, 0, cpu);
	}
	rtai_cpu = cpu;
	if (irqsl && nirqsl < MAXIRQS && nirqsl > 0) {
		memcpy(&irqs, irqsl, (nirqs = nirqsl)*sizeof(int));
	} else if (!nirqs) {
		return -EINVAL;
	}
	for (irq = 0; irq < nirqs; irq++) {
		rt_assign_irq_to_cpu(irqs[irq], (1 << (1 - cpu)));
	}	
	return 0;
}
Esempio n. 14
0
int __rtai_tasklets_init(void)
{
	int cpuid;

	if(set_rt_fun_ext_index(rt_tasklet_fun, TASKLETS_IDX)) {
		printk("Recompile your module with a different index\n");
		return -EACCES;
	}
	if (init_ptimers()) {
		return -ENOMEM;
	}
	for (cpuid = 0; cpuid < num_online_cpus(); cpuid++) {
		timers_lock[cpuid] = timers_lock[0];
		timers_list[cpuid] = timers_list[0];
		timers_list[cpuid].cpuid = cpuid;
		timers_list[cpuid].next = timers_list[cpuid].prev = &timers_list[cpuid];
		rt_task_init_cpuid(&timers_manager[cpuid], rt_timers_manager, cpuid, TaskletsStacksize, TimersManagerPrio, 0, 0, cpuid);
		rt_task_resume(&timers_manager[cpuid]);
	}
	printk(KERN_INFO "RTAI[tasklets]: loaded.\n");
	return 0;
}
Esempio n. 15
0
int init_module(void)
{
	rt_task_init_cpuid(&Chrono, &CommandChrono_task, 0, 2000, 0, 0, 0, 1);
	rt_task_resume(&Chrono);
	return 0;
}
Esempio n. 16
0
int init_module(void)
{
	rt_task_init_cpuid(&Display, Display_task, 0, 2000, 0, 0, 0, 0);
	rt_task_resume(&Display);
	return 0;
}
Esempio n. 17
0
static long long user_srq(unsigned long whatever)
{
	extern int calibrate_8254(void);
	unsigned long args[MAXARGS];
	int ret;

	ret = copy_from_user(args, (unsigned long *)whatever, MAXARGS*sizeof(unsigned long));
	switch (args[0]) {
		case CAL_8254: {
			return calibrate_8254();
			break;
		}

		case KTHREADS:
		case KLATENCY: {
			rt_set_oneshot_mode();
			period = start_rt_timer(nano2count(args[1]));
			if (args[0] == KLATENCY) {
				rt_task_init_cpuid(&rtask, spv, args[2], STACKSIZE, 0, 0, 0, hard_cpu_id());
			} else {
//				rt_kthread_init_cpuid(&rtask, spv, args[2], STACKSIZE, 0, 0, 0, hard_cpu_id());	
			}
			expected = rt_get_time() + 100*period;
			rt_task_make_periodic(&rtask, expected, period);
			break;
		}

		case END_KLATENCY: {
			stop_rt_timer();
			rt_task_delete(&rtask);
			break;
		}

		case FREQ_CAL: {
			times.intrs = -1;
			reset_count = args[1]*HZ;
			count = 0;
			rt_assign_irq_to_cpu(TIMER_8254_IRQ, 1 << hard_cpu_id());
			rt_request_timer(just_ret, COUNT, 1);
			rt_request_global_irq(TIMER_8254_IRQ, calibrate);
			break;
		}

		case END_FREQ_CAL: {
		        rt_free_timer();
		        rt_reset_irq_to_sym_mode(TIMER_8254_IRQ);
		        rt_free_global_irq(TIMER_8254_IRQ);
			break;
		}

		case BUS_CHECK: {
			loops = maxj = 0;
			bus_period = imuldiv(args[1], CPU_FREQ, 1000000000);
			bus_threshold = imuldiv(args[2], CPU_FREQ, 1000000000);
			use_parport = args[3];
			rt_assign_irq_to_cpu(TIMER_8254_IRQ, 1 << hard_cpu_id());
			rt_request_timer((void *)rt_timer_tick_ext, imuldiv(args[1], FREQ_8254, 1000000000), 0);
			rt_set_global_irq_ext(TIMER_8254_IRQ, 1, 0);
			break;
		}

		case END_BUS_CHECK: {
		        rt_free_timer();
		        rt_reset_irq_to_sym_mode(TIMER_8254_IRQ);
			break;
		}
		case GET_PARAMS: {
			rtf_put(0, &params, sizeof(params));
			break;
		}
	} 
	return 0;
}
Esempio n. 18
0
static int _init(void)
{
	int broadcast = 1;
	int64_t timeout = -1;

	rt_printk("RtnetTest: Module initialisation started\n");

	memset(buffer_in, 0, sizeof(buffer_in));
	memset(&loc_addr, 0, sizeof (struct sockaddr_in));

	memset(buffer_out, 0, sizeof(buffer_out));
	memset(&tx_addr, 0, sizeof (struct sockaddr_in));

	loc_addr.sin_family      = AF_INET;
	loc_addr.sin_port        = htons(UDPPORT);
	loc_addr.sin_addr.s_addr = INADDR_ANY;

	tx_addr.sin_family       = AF_INET;
	tx_addr.sin_port         = htons(UDPPORT);
	tx_addr.sin_addr.s_addr  = rt_inet_aton("127.0.0.1");

	if (((mbx = rt_typed_named_mbx_init("MYMBX", 2000*sizeof(struct sample), FIFO_Q))) == NULL) {
		rt_printk("RtnetTest: Cannot create the mailbox\n");
		return -1;
	}

	if (((sock = rt_dev_socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP))) < 0) {
		rt_printk("RtnetTest: Error opening UDP/IP socket: %d\n", sock);
		return -1;
	}
	if (rt_dev_setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &broadcast, sizeof(broadcast)) == -1) {
		rt_printk("RtnetTest: Can't set broadcast options\n");
		goto close_socks;
	}

	rt_dev_ioctl(sock, RTNET_RTIOC_TIMEOUT, &timeout);

	if (rt_dev_bind(sock, (struct sockaddr *) &loc_addr, sizeof(struct sockaddr_in)) < 0) {
		rt_printk("RtnetTest: Can't bind the network socket");
		goto close_socks;
	}

	rt_set_periodic_mode();
	period = start_rt_timer(nano2count(WORKCYCLE));

	if (rt_task_init_cpuid(&rx_task, receiver, 0, STKSIZ, 0, 0, 0, CPU) < 0) {
		rt_printk("RtnetTest: Can't initialise the receiver task");
		goto close_socks;
	}

	if (rt_task_init_cpuid(&tx_task, sender, 0, STKSIZ, 0, 0, 0, CPU) < 0) {
		rt_printk("RtnetTest: Can't initialise the transmitter task");
		goto close_socks;
	}

	if (0 != rt_task_make_periodic(&tx_task, rt_get_time() + 20*period, period)) {
		rt_printk("RtnetTest: Make sender periodic failed\n");
		goto close_socks;
	}

	if (rt_task_resume(&rx_task) < 0) {
		rt_printk("RtnetTest: Can't start the receiver task");
		goto close_socks;
	}

	rt_printk("RtnetTest: Module initialisation completed\n");
	return 0;

close_socks:

	rt_dev_close(sock);
	rt_dev_shutdown(sock, SHUT_RDWR);
	return -1;
}