Пример #1
0
int main(void)
{
	unsigned long hrttsk_name = nam2num("HRTTSK");
	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");
		perror("errno");
		exit(0);
 	}
 	if (!(hrttsk = rt_task_init(hrttsk_name, 1, 0, 0))) {
		printf("CANNOT INIT TESTB MASTER TASK\n");
		exit(1);
	}

	rt_set_usp_flags_mask(FORCE_SOFT);
	rt_task_suspend(hrttsk);
	printf("BACKGROUND REAL TIME TASK IS HARD .....\n");
	mlockall(MCL_CURRENT | MCL_FUTURE);

	rt_make_hard_real_time();
	while(rt_is_hard_real_time(hrttsk)) {
		rt_task_wait_period();
	}
	printf("..... BACKGROUND REAL TIME TASK IS SOFT NOW, YOU CAN KILL IT BY HAND\n");
	rt_task_delete(hrttsk);
	while(1) { sleep(3); printf("BACKGROUND PROCESS STILL RUNNING\n"); }
}
Пример #2
0
void taskh_func(long tid)
{
	RTIME time;
	unsigned int msg = 0, wait;
	rt_send(&taskm, msg);
	rt_send(&taskl, msg);
	while (1) {
		rt_receive(&taskm, &msg);
		time = rt_get_time_ns();
		if (MUTEX_LOCK(&mutex) <= 1) {
			if ((wait = (int)(rt_get_time_ns() - time)) > 250000) {
				rt_printk("PRIORITY INVERSION, WAITED FOR %d us\n", wait/1000);
			} else {
				rt_printk("NO PRIORITY INVERSION, WAITED FOR %d us\n", wait/1000);
			}
			if (SemType) {
				MUTEX_LOCK(&mutex);
				MUTEX_LOCK(&mutex);
				rt_busy_sleep(100000);
				MUTEX_LOCK(&mutex);
			}
			rt_busy_sleep(100000);
			if (SemType) {
				rt_sem_signal(&mutex);
				rt_busy_sleep(100000);
				rt_sem_signal(&mutex);
				rt_sem_signal(&mutex);
			}
			rt_sem_signal(&mutex);
		} else {
			rt_task_suspend(0);
		}
	}
}
Пример #3
0
void *thread_fun(void *arg)
{
 	funtask = rt_task_init_schmod(0xcaccb, 0, 0, 0, SCHED_FIFO, 0x1);
	rt_printk("FUN INIT\n");
	mlockall(MCL_CURRENT | MCL_FUTURE);
	rt_make_hard_real_time();

	if (!SNDBRCV) {
		rt_sleep(nano2count(100000000));
	}

	if (USE_RPC) {
		unsigned long msg;
		rt_printk("FUN RPC\n");
	        rt_rpc(maintask, 0, &msg);
	} else {
		rt_printk("FUN SEND\n");
        	rt_send(maintask, 0);
		rt_printk("FUN SUSP\n");
        	rt_task_suspend(funtask);
	}
	rt_printk("FUN DONE\n");

	rt_task_delete(funtask);
	rt_printk("FUN END\n");
	return 0;
}
Пример #4
0
static void main_task(void *arg)
{
	RT_TASK *p;
	int ret;

	traceobj_enter(&trobj);

	p = rt_task_self();
	traceobj_assert(&trobj, p != NULL && rt_task_same(p, &t_main));

	traceobj_mark(&trobj, 5);

	ret = rt_alarm_start(&alrm, 200000000ULL, 200000000ULL);
	traceobj_check(&trobj, ret, 0);

	traceobj_mark(&trobj, 6);

	ret = rt_task_suspend(&t_main);
	traceobj_check(&trobj, ret, 0);

	traceobj_mark(&trobj, 7);

	ret = rt_alarm_delete(&alrm);
	traceobj_check(&trobj, ret, 0);

	traceobj_exit(&trobj);
}
Пример #5
0
int rt_task_create(RT_TASK *task, const char *name,
                   int stksize, int prio, int mode)
{
    int ret, susp, cpus, cpu;
    cpu_set_t cpuset;

    susp = mode & T_SUSP;
    cpus = mode & T_CPUMASK;
    ret = __CURRENT(rt_task_create(task, name, stksize, prio,
                                   mode & ~(T_SUSP|T_CPUMASK|T_LOCK)));
    if (ret)
        return ret;

    if (cpus) {
        CPU_ZERO(&cpuset);
        for (cpu = 0, cpus >>= 24;
                cpus && cpu < 8; cpu++, cpus >>= 1) {
            if (cpus & 1)
                CPU_SET(cpu, &cpuset);
        }
        ret = rt_task_set_affinity(task, &cpuset);
        if (ret) {
            rt_task_delete(task);
            return ret;
        }
    }

    return susp ? rt_task_suspend(task) : 0;
}
Пример #6
0
/***
 *	rt_stack_mgr_delete 
 */
void rt_stack_mgr_delete (struct rtnet_mgr *mgr)
{
	rt_task_suspend(&(mgr->task));
	rt_task_delete(&(mgr->task));
	rt_mbx_delete(&(mgr->mbx));

}
Пример #7
0
RTAI_SYSCALL_MODE int rt_signal_helper(RT_TASK *task)
{
	if (task) {
		rt_task_suspend(task);
		return task->retval;
	}
	return (RT_CURRENT)->runnable_on_cpus;
}
Пример #8
0
/**
 * Wait for the CAN Receiver Task end
 * @param *ReceiveLoop_task CAN receiver thread
 */
void WaitReceiveTaskEnd(TASK_HANDLE *ReceiveLoop_task)
{
	/* normally this will fail with a non-periodic task that has already ended at this time */
	if (rt_task_suspend(ReceiveLoop_task) != 0){
		printk("Failed to join with Receive task\n");
	}
	rt_task_delete(ReceiveLoop_task);
}
Пример #9
0
void cleanup_all(void)
{
	/* normally this will fail with a non-periodic task that has already ended at this time */
	if (rt_task_suspend(&timerloop_task) != 0){
		printk("Failed to join with Timerloop task\n");
	}
	rt_task_delete(&timerloop_task);
}
Пример #10
0
/* run : worker thread for ball control 
         along with AI generation
*/
void run(void *vsocket){
    int sock = *(int *)&vsocket;
    int echolen;
    RTIME sleep; // as nano-seconds


    if(ballThreadSpeed % 6 == 0)
	ballThreadSpeed++;
    sleep = (RTIME)(50000000 / (ballThreadSpeed % 6));

    rt_task_suspend(NULL);
    while (true){
   	ballmove();
	echolen = strlen(ballData);
	if(send(sock, ballData, echolen, 0) != echolen)
		rt_err("send()");
        /*2 View mode case*/
        if(viewMode > 1){
		if(send(viewSocket2, ballData, echolen, 0) != echolen)
     			rt_err("send()");
	}

        
	if(AIMode){
            opponentMovement(AImoveGenerate());
	    echolen = strlen(moveData[1]);
	   if(send(sock, moveData[1], echolen, 0) != echolen)
		rt_err("send()");
 	   if(viewMode > 1){
		if(send(viewSocket2, moveData[1], echolen, 0) != echolen)
     		rt_err("send()");
           } 
        }
        if(reset){
            resetBall();
            echolen = strlen(gameData);
            if(send(sock, gameData, echolen, 0) != echolen)
                   rt_err("send()");
            if(viewMode > 1){
		if(send(viewSocket2, gameData, echolen, 0) != echolen)
     		rt_err("send()");
           }  
        }
        if(bounceplayer){
            bounceDirection(player,ball.radius);
            bounceplayer = false;
        }
        if(bounceOpponent){
            bounceDirection(opponent,ball.radius);
            bounceOpponent = false;
        }
        rt_task_sleep(sleep);
    }
}
Пример #11
0
static void spv(long loops)
{
	int skip, average = 0;
	for (skip = 0; skip < loops; skip++) {
		expected += period;
		rt_task_wait_period();
		average += (int)count2nano(rt_get_time() - expected);
	}
	rtf_put(0, &average, sizeof(average));
	rt_task_suspend(0);
}
Пример #12
0
void child_func(int arg) 
{
    int *explode = 0;

    rt_printk("Starting child task %d\n", arg);
    for(counters[arg] = 0; counters[arg] < 10; counters[arg]++) {
	// rt_printk("Child task %d, loop count %d\n", arg, counters[arg]);
	rt_task_wait_period();
    }
    *explode = 0;
    rt_task_suspend(rt_whoami());
}
Пример #13
0
void parent_func(int arg) 
{
    int i;

    rt_printk("Starting parent task %d\n", arg);
    for (i = 0; i < NUM_CHILDREN; i++) {
    	rt_task_init(&child_task[i], child_func, i, STACK_SIZE, PRIORITY, 0, 0);
	rt_set_task_trap_handler(&child_task[i], 14, my_trap_handler);
	rt_task_make_periodic(&child_task[i], rt_get_time() + period, period*i);
    }
    rt_task_suspend(rt_whoami());
}
Пример #14
0
static void SomeOtherThingsTodo( void *var1, int var2 )
{
// This function acts like a synchronous thread.
// Function rt_qReceive(...) does whatever is necessary to receive proxies,
// messages and schedule the execution of both static and dynamic QBLK's.
rt_printk( "QBLK Says: Hello World\n" );

count++;

// Reschedule for execution in one second.
if(count < 12) rt_qBlkWait( &Main, nano2count( 1000000000 ));
else rt_task_suspend(rt_whoami());
}
Пример #15
0
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;
}
Пример #16
0
/**
 * Clean all Semaphores, mutex, condition variable and main task
 */
void TimerCleanup(void)
{
	rt_sem_delete(&CanFestival_mutex);
	rt_mutex_delete(&condition_mutex);
	rt_cond_delete(&timer_set);
	rt_sem_delete(&control_task);

	/* normally this will fail with a non-periodic task that has already ended at this time */
	if (rt_task_suspend(&timerloop_task) != 0){
		printk("Failed to join with Timerloop task\n");
	}
	rt_task_delete(&timerloop_task);
}
Пример #17
0
Файл: tbx1.c Проект: ArcEye/RTAI
static void Task4(long t)
{
	int wakedup;
    
	rt_printk("\nTask4 (%p) starting\n", rt_whoami());
	while (count < MAXCOUNT) {
		count++;
		wakedup = rt_tbx_broadcast(&bx, msg2, sizeof(msg2));
		rt_printk("\nTask4=%lu, sending broadcast, wakedup=%d\n", count, wakedup);
		rt_sleep(nano2count(DELAY + SHIFT));
	}
	rt_printk("\nTask4 suspends itself\n");
	rt_task_suspend(rt_whoami());
}                                        
Пример #18
0
 INTERNAL_QUAL void rtos_task_make_periodic(RTOS_TASK* mytask, NANO_TIME nanosecs )
 {
     if (mytask->rtaitask == 0)
         return;
     if (rt_buddy() == mytask->rtaitask) {
         // do not suspend/resume my own thread
         // do best effort to change period.
         rtos_task_set_period(mytask,nanosecs);
         return;
     }
     // other thread is instructing us:
     if (nanosecs == 0) {
         // in RTAI, to drop from periodic to non periodic, do a
         // suspend/resume cycle.
         rt_task_suspend( mytask->rtaitask );
         rt_task_resume( mytask->rtaitask );
     }
     else {
         // same for the inverse
         rt_task_suspend( mytask->rtaitask );
         rt_task_make_periodic_relative_ns(mytask->rtaitask, 0, nanosecs);
     }
 }
Пример #19
0
Файл: tbx1.c Проект: ArcEye/RTAI
static void Task1(long t)
{
	int unsent;
    
	rt_printk("\nTask1 (%p) starting\n", rt_whoami());
	while (count < MAXCOUNT) {
		count++;
		unsent = rt_tbx_send(&bx, msg1, sizeof(msg1));
		rt_printk("\nTask1=%lu, simple sending, unsent=%d %d\n", count, unsent, sizeof(msg1));
		rt_sleep(nano2count(DELAY));
	}
	rt_printk("\nTask1 suspends itself\n");
	rt_task_suspend(rt_whoami());
}                                        
Пример #20
0
static void intr_handler(int t) {

	while(1) {
		cpu_used[hard_cpu_id()]++;
		t = imuldiv(maxj, 1000000, CPU_FREQ);
		rtf_put(CMDF, &t, sizeof(int));
		if (Mode) {
			if (rt_sem_wait(&sem) >= SEM_TIMOUT) {
				return;
			}
		} else {
			rt_task_suspend(&thread);
		}
	}
}
Пример #21
0
Файл: tbx1.c Проект: ArcEye/RTAI
static void Task7(long t)
{
	int unsent;
    
	rt_printk("\nTask7 (%p) starting\n", rt_whoami());
	while (count < MAXCOUNT) {
		count++;
		unsent = rt_tbx_urgent(&bx, msg3, sizeof(msg3));
		rt_printk("\nTask7=%lu, urgent sending, unsent=%d\n", count, unsent);
		rt_sleep(nano2count(3*DELAY + 2*SHIFT));
	}
	rt_printk("\nTask7 suspends itself\n");
	cleanup = 1;
	rt_task_suspend(rt_whoami());
}       
Пример #22
0
int my_trap_handler(int v, int signo, struct pt_regs *r, void *t)
{
    int i;

    rt_printk("RT task %p generated trap %d\n", t, v);
    for (i = 0; i < NUM_CHILDREN; i++) {
	if (&child_task[i] == t) {
	    if (counters[i] != 10) rt_printk("ERROR: ");
	    rt_printk("Child %d, loop counter = %d\n", i, counters[i]);
	    break;
	}
    }
    rt_task_suspend(t);
    rt_task_delete(t);
    return 1;
}
Пример #23
0
static void Task4(long t)
{
	int wakedup;
	MSG msg;

	rt_printk("\nTask4 (%p) starting\n", rt_whoami());
	while (count < MAXCOUNT) {
		count++;
		msg.progressive = count;
		msg.sending_task = 4;
		wakedup = rt_tbx_broadcast(&bx, (char*)&msg, sizeof(msg));
		rt_printk("\nTask4=%lu, sent broadcast, wakedup=%d\n", count, wakedup);
		rt_sleep(nano2count(DELAY + SHIFT));
	}
	rt_printk("\nTask4 suspends itself\n");
	rt_task_suspend(rt_whoami());
}
Пример #24
0
Файл: tbx3.c Проект: cjecho/RTAI
static void Task1(long t)
{
	int unsent;
	MSG msg;

	rt_printk("\nTask1 (%p) starting\n", rt_whoami());
	while (count < MAXCOUNT) {
		count++;
		msg.progressive = count;
		msg.sending_task = 1;
		unsent = rt_tbx_send_if(&bx, (char*)&msg, sizeof(msg));
		rt_printk("\nTask1=%lu, simple sending, unsent=%d\n", count, unsent);
		rt_sleep(nano2count(DELAY));
	}
	rt_printk("\nTask1 suspends itself\n");
	rt_task_suspend(rt_whoami());
}
Пример #25
0
Файл: tbx3.c Проект: cjecho/RTAI
static void Task3(long t)
{
	int status;
	MSG buf;

	rt_printk("\nTask3 (%p) starting\n", rt_whoami());
	while (count < MAXCOUNT) {
		memset((char*)&buf, 0, sizeof(buf));
		status = rt_tbx_receive_if(&bx, (char*)&buf, sizeof(buf));
		if (status == 0) {
			rt_printk("\nTask3 received msgnr %u from task %u, status=%d\n", buf.progressive, buf.sending_task, status);
		}
		rt_sleep(nano2count(TIMEBASE));
	}
	rt_printk("\nTask3 suspends itself\n");
	rt_task_suspend(rt_whoami());
}
Пример #26
0
static void Task7(long t)
{
	int unsent;
	MSG msg;

	rt_printk("\nTask7 (%p) starting\n", rt_whoami());
	while (count < MAXCOUNT) {
		count++;
		msg.progressive = count;
		msg.sending_task = 7;
		unsent = rt_tbx_urgent(&bx, (char*)&msg, sizeof(msg));
		rt_printk("\nTask7=%lu, urgent sending, unsent=%d\n", count, unsent);
		rt_sleep(nano2count(3*DELAY + 2*SHIFT));
	}
	rt_printk("\nTask7 suspends itself\n");
	cleanup = 1;
	rt_task_suspend(rt_whoami());
}
Пример #27
0
static void pend_task (long t)
{
	unsigned long msg;
	while(1) {
		switch (change) {
			case 0:
				rt_task_suspend(thread + t);
				break;
			case 1:
				rt_sem_wait(&sem);
				break;
			case 2:
				rt_return(rt_receive(NULL, &msg), 0);
				break;
		}
		cpu_used[hard_cpu_id()]++;
	}
}
Пример #28
0
void fun(int t)
{
	char buf[64];
	pid_t from;
	int msglen;

	rt_printk("Task %p starts.\n", rt_lxrt_whoami());

	// init a qBlk
	rt_InitTickQueue();
	rt_qBlkInit( &Main, SomeOtherThingsTodo, 0, 0);
	rt_qBlkWait( &Main, nano2count(1000000000));

        from = rt_qReceive( 0, buf, sizeof(buf), &msglen);

	rt_task_suspend(rt_whoami());
	rt_printk("Task %p Oops.\n", rt_lxrt_whoami());
}
Пример #29
0
int echo_rcv(int s,void *arg)
{
	int			ret=0;
	struct msghdr		msg;
	struct iovec		iov;
	struct sockaddr_in	addr;
	

	memset(&msg,0,sizeof(msg));
	iov.iov_base=&buffer;
	iov.iov_len=BUFSIZE;

	msg.msg_name=&addr;
	msg.msg_namelen=sizeof(addr);
	msg.msg_iov=&iov;
	msg.msg_iovlen=1;
	msg.msg_control=NULL;
	msg.msg_controllen=0;

	ret=rt_socket_recvmsg(sock, &msg, 0);

	if ( (ret>0) && (msg.msg_namelen==sizeof(struct sockaddr_in)) ) {
		
		union { unsigned long l; unsigned char c[4]; } rcv;
		struct sockaddr_in *sin = msg.msg_name;
		
		/* get the time    */
		rx_time = rt_get_cpu_time_ns();
		memcpy (&tx_time, buffer, sizeof(RTIME));
		rcvd++;

		ret = rtf_put(PRINT, &rx_time, sizeof(RTIME));
		ret = rtf_put(PRINT, &tx_time, sizeof(RTIME));
		if (0 == ret) {
			rt_task_suspend(&rt_task);
			rt_printk("fifo full, sending task suspended\n");
		}

		/* copy the address */
		rcv.l = sin->sin_addr.s_addr;
	}

	return 0;
}
Пример #30
0
static void __exit rtnetproxy_cleanup_module(void)
{

    /* Unregister the fallback at rtnet */
    rt_ip_register_fallback(0);

    /* free the rtai srq */
    rt_free_srq(rtnetproxy_srq);

    rt_task_suspend(&rtnetproxy_thread);
    rt_task_delete(&rtnetproxy_thread);

    /* Free the ringbuffers... */
    {
        struct sk_buff *del_skb;  /* standard skb */
        while ((del_skb = read_from_ringbuffer(&ring_skb_rtnet_kernel)) != 0)
        {
            dev_kfree_skb(del_skb);
        }
        while ((del_skb = read_from_ringbuffer(&ring_skb_kernel_rtnet)) != 0)
        {
            dev_kfree_skb(del_skb);
        }
    }
    {
        struct rtskb *del; /* rtnet skb */
        while ((del=read_from_ringbuffer(&ring_rtskb_kernel_rtnet))!=0)
        {
            kfree_rtskb(del); // Although this is kernel mode, freeing should work...
        }
        while ((del=read_from_ringbuffer(&ring_rtskb_rtnet_kernel))!=0)
        {
            kfree_rtskb(del); // Although this is kernel mode, freeing should work...
        }
    }

    /* Unregister the net device: */
    unregister_netdev(&dev_rtnetproxy);
    kfree(dev_rtnetproxy.priv);

    memset(&dev_rtnetproxy, 0, sizeof(dev_rtnetproxy));
    dev_rtnetproxy.init = rtnetproxy_init;
}