Esempio n. 1
0
File: mbxdel.c Progetto: cjecho/RTAI
void fun1(long t)
{
	int msg;
	if (t & 1) {
		RT_PRINTK("TASK %d BLOCKS TIMED RECEIVING ON MBX\n", t);
		RT_PRINTK("TASK %d UNBLOCKS RECEIVING ON MBX %d BYTES\n", t, rt_mbx_receive_timed(&mbx, &msg, sizeof(msg), 2000000000));
	} else {
		RT_PRINTK("TASK %d BLOCKS RECEIVING ON MBX\n", t);
		RT_PRINTK("TASK %d UNBLOCKS RECEIVING ON MBX %d BYTES\n", t, rt_mbx_receive(&mbx, &msg, sizeof(msg)));
	}
        atomic_inc(&cleanup);
}
Esempio n. 2
0
static void task_code(int task_no)
{
	int i, ret;
	char buf[9];
	buf[8] = 0;
	for (i = 0; i < 5; ++i)	{
		rt_sem_wait(&sems[task_no]);
		TAKE_PRINT; 
		rt_printk(strs[task_no]);
		GIVE_PRINT;
		if (task_no == NUM_TASKS-1) {
			rt_printk("\n");
		}
		rt_sem_signal(&sems[(task_no + 1) % NUM_TASKS]);
	}
	rt_sem_signal(&sync_sem);
	rt_sem_wait(&prio_sem);
	TAKE_PRINT; 
	rt_printk(strs[task_no]);
	GIVE_PRINT;
	rt_sleep(nano2count(1000000000LL));
	rt_sem_wait_timed(&prio_sem, nano2count((task_no + 1)*1000000000LL));
	TAKE_PRINT; 
	rt_printk("sem timeout, task %d, %s\n", task_no, strs[task_no]);
	GIVE_PRINT;
	rt_sem_signal(&sync_sem);

/* message queue stuff */
	if ((ret = rt_mbx_receive(&mbx_in, buf, 8)) != 0) {
		rt_printk("rt_mbx_receive() failed with %d\n", ret);
	}
	TAKE_PRINT; 
	rt_printk("\nreceived by task %d ", task_no);
	rt_printk(buf); 
	GIVE_PRINT;
	rt_mbx_send(&mbx_out, strs[task_no], 8);
/* test receive timeout */
	rt_sem_wait(&sync_sem);
	if (rt_mbx_receive_timed(&mbx_in, buf, 8, nano2count((task_no + 1)*1000000000LL))) {
		TAKE_PRINT;
		rt_printk("mbx timeout, task %d, %s\n", task_no, strs[task_no]);
		GIVE_PRINT;
	}

	rt_printk("\ntask %d complete\n", task_no); 
}
Esempio n. 3
0
File: mbx.c Progetto: cjecho/RTAI
static void mfun(long t)
{
	RTIME time;
	unsigned long long msg;
	int size, maxt = 0, itime;

	while (1) {
		time = rt_get_cpu_time_ns();
		cpu_used[hard_cpu_id()]++;

		mstat[t] = 's';
		if ((size = rt_mbx_send_timed(&smbx, &name[t], sizeof(long long), nano2count(TIMEOUT)))) {
			rt_printk("SEND TIMEDOUT TASK: %d, UNSENT: %d, STAT: %c %c %c, OVERTIME: %d.\n", t, size, mstat[0], mstat[1], bstat, (int)(rt_get_cpu_time_ns() - time));
			goto prem;
		}

		msg = 0;
		mstat[t] = 'r';
		if ((size = rt_mbx_receive_timed(&rmbx[t], &msg, sizeof(msg), nano2count(TIMEOUT)))) {
			rt_printk("RECEIVE TIMEDOUT TIME: %d, NOTRECEIVED: %d, MSG: %x%x, STAT: %c %c %c, OVERTIME: %d.\n", t, size, ((int *)&msg)[1], ((int *)&msg)[0], mstat[0], mstat[1], bstat, (int)(rt_get_cpu_time_ns() - time));
			goto prem;
		}

		if (msg != 0xccccccccccccccccLL) {
                        rt_printk("WRONG REPLY TO TASK: %d, MSG: %x %x.\n", t, ((int *)&msg)[0], ((int *)&msg)[1]);
                        goto prem;
		}
		mstat[t] = 'd';
		if ((itime = rt_get_cpu_time_ns() - time) > maxt) {
			rt_printk("TASK: %d, MAXWAITIME: %d.\n", t, maxt = itime);
		}
		meant[t] = (itime + meant[t]) >> 1;
		rt_sleep(nano2count(SLEEP_TIME));
	}

prem:
	premature = PREMATURE;
	rt_printk("TASK # %d ENDS PREMATURELY\n", t);
}
Esempio n. 4
0
File: master.c Progetto: cjecho/RTAI
int main(int argc, char* argv[])
{
	unsigned long mtsk_name = nam2num("MTSK");
	unsigned long btsk_name = nam2num("BTSK");
	unsigned long sem_name  = nam2num("SEM");
	unsigned long smbx_name  = nam2num("SMBX");
	unsigned long rmbx_name  = nam2num("RMBX");
	unsigned long msg;

	long long mbx_msg;
	long long llmsg = 0xaaaaaaaaaaaaaaaaLL;

	RT_TASK *mtsk, *rcvd_from;
	SEM *sem;
	MBX *smbx, *rmbx;
	int pid, count;

 	if (!(mtsk = rt_task_init_schmod(mtsk_name, 0, 0, 0, SCHED_FIFO, 0x1))) {
		printf("CANNOT INIT MASTER TASK\n");
		exit(1);
	}
	printf("MASTER TASK INIT: name = %lx, address = %p.\n", mtsk_name, mtsk);

	printf("MASTER TASK STARTS THE ONESHOT TIMER\n");
	rt_set_oneshot_mode();
	start_rt_timer(nano2count(10000000));
	mlockall(MCL_CURRENT | MCL_FUTURE);
	rt_make_hard_real_time();
	rt_sleep(1000000);


	printf("MASTER TASK MAKES ITSELF PERIODIC WITH A PERIOD OF 1 ms\n");
	rt_task_make_periodic(mtsk, rt_get_time(), nano2count(PERIOD));
	rt_sleep(nano2count(1000000000));

	count = PERIODIC_LOOPS;
	printf("MASTER TASK LOOPS ON WAIT_PERIOD FOR %d PERIODS\n", count);
	while(count--) {
		printf("PERIOD %d\n", count);
		rt_task_wait_period();
	}

	count = SLEEP_LOOPS;
	printf("MASTER TASK LOOPS ON SLEEP 0.1 s FOR %d PERIODS\n", count);
	while(count--) {
		printf("SLEEPING %d\n", count);
		rt_sleep(nano2count(DELAY));
	}
	printf("MASTER TASK YIELDS ITSELF\n");
	rt_task_yield();

	printf("MASTER TASK CREATES BUDDY TASK\n");
	pid = fork();
	if (!pid) {
		execl("./slave", "./slave", NULL);
	}

	printf("MASTER TASK SUSPENDS ITSELF, TO BE RESUMED BY BUDDY TASK\n");
	rt_task_suspend(mtsk);
	printf("MASTER TASK RESUMED BY BUDDY TASK\n");

 	if (!(sem = rt_sem_init(sem_name, 0))) {
		printf("CANNOT CREATE SEMAPHORE %lx\n", sem_name);
		exit(1);
	}
	printf("MASTER TASK CREATES SEM: name = %lx, address = %p.\n", sem_name, sem);

	printf("MASTER TASK WAIT_IF ON SEM\n");
	rt_sem_wait_if(sem);

	printf("MASTER STEP BLOCKS WAITING ON SEM\n");
	rt_sem_wait(sem);

	printf("MASTER TASK SIGNALLED BY BUDDY TASK WAKES UP AND BLOCKS WAIT TIMED 1 s ON SEM\n");
	rt_sem_wait_timed(sem, nano2count(1000000000));

	printf("MASTER TASK DELETES SEM\n");
	rt_sem_delete(sem);

	printf("MASTER TASK BLOCKS RECEIVING FROM ANY\n");
	rcvd_from = rt_receive(0, (void *)&msg);
	printf("MASTER TASK RECEIVED MESSAGE %lx FROM BUDDY TASK\n", msg);

	printf("MASTER TASK RPCS TO BUDDY TASK THE MESSAGE %lx\n", 0xabcdefL);
	rcvd_from = rt_rpc(rcvd_from, 0xabcdef, (void *)&msg);
	printf("MASTER TASK RECEIVED THE MESSAGE %lx RETURNED BY BUDDY TASK\n", msg);
//exit(1);
 	if (!(smbx = rt_mbx_init(smbx_name, 1))) {
		printf("CANNOT CREATE MAILBOX %lx\n", smbx_name);
		exit(1);
	}
 	if (!(rmbx = rt_mbx_init(rmbx_name, 1))) {
		printf("CANNOT CREATE MAILBOX %lx\n", rmbx_name);
		exit(1);
	}
	printf("MASTER TASK CREATED TWO MAILBOXES %p %p %p %p \n", smbx, rmbx, &mtsk_name, &msg);

	count = MBX_LOOPS;
	while(count--) {
		rt_mbx_send(smbx, &llmsg, sizeof(llmsg));
		printf("%d MASTER TASK SENDS THE MESSAGE %llx MBX\n", count, llmsg);
		mbx_msg = 0;
		rt_mbx_receive_timed(rmbx, &mbx_msg, sizeof(mbx_msg), nano2count(MSG_DELAY));
		printf("%d MASTER TASK RECEIVED THE MESSAGE %llx FROM MBX\n", count, mbx_msg);
		rt_sleep(nano2count(DELAY));
	}

	printf("MASTER TASK SENDS THE MESSAGE %lx TO BUDDY TO ALLOW ITS END\n", 0xeeeeeeeeL);
	rt_send(rcvd_from, 0xeeeeeeee);

	printf("MASTER TASK WAITS FOR BUDDY TASK END\n");
	while (rt_get_adr(btsk_name)) {
		rt_sleep(nano2count(1000000000));
	}
	printf("MASTER TASK STOPS THE PERIODIC TIMER\n");
	stop_rt_timer();

	printf("MASTER TASK DELETES MAILBOX %p\n", smbx);
	rt_mbx_delete(smbx);
	printf("MASTER TASK DELETES MAILBOX %p\n", rmbx);
	rt_mbx_delete(rmbx);

	printf("MASTER TASK DELETES ITSELF\n");
	rt_task_delete(mtsk);

	printf("END MASTER TASK\n");

	return 0;
}