예제 #1
0
파일: ktestmsg.c 프로젝트: cjecho/RTAI
static void bfun(int t)
{
	int smbx, *rmbx, *msg, mtype, i, n;

	rmbx = rt_malloc(NTASKS*sizeof(int));
	msg  = rt_malloc((MAXSIZ + 1)*sizeof(int));

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

	rt_sem_wait_barrier(&barrier);
	while (end < NTASKS) {
		rt_msgrcv_nu(smbx, &mtype, msg, sizeof(int)*(MAXSIZ + 1), 1, 0);
		n = 0;
		for (i = 1; i < MAXSIZ; i++) {
			n += msg[i];
		}
		if (msg[MAXSIZ] != n) {
			rt_printk("SERVER RECEIVED AN UNKNOWN MSG.\n");
			goto prem;
		}
		msg[1] = 0xFFFFFFFF;
		rt_msgsnd_nu(rmbx[msg[0]], 1, msg, 2*sizeof(int), 0);
	}
prem:
	rt_free(rmbx);
	rt_free(msg);
	rt_printk("SERVER TASK ENDS.\n");
}
예제 #2
0
파일: testmsg.c 프로젝트: ArcEye/RTAI
static void mfun(int t)
{
	char tname[6] = "MFUN", mname[6] = "RMBX";
	RT_TASK *mytask;
	int smbx, rmbx, msg[MAXSIZ + 1], mtype, i;

	randu();
	tname[4] = mname[4] = t + '0';
	tname[5] = mname[5] = 0;
	mytask = rt_thread_init(nam2num(tname), t + 2, 0, SCHED_FIFO, 0xF);
	smbx = rt_msgget(nam2num("SMSG"), 0);
	rmbx = rt_msgget(nam2num(mname), 0);
	mlockall(MCL_CURRENT | MCL_FUTURE);
	rt_make_hard_real_time();

	msg[0] = t;
	rt_sem_wait_barrier(barrier);
	while (end < t) {
		msg[MAXSIZ] = 0;
		for (i = 1; i < MAXSIZ; i++) {
			msg[MAXSIZ] += (msg[i] = MAXSIZ*randu()); 
		}
		if (rt_msgsnd_nu(smbx, 1, msg, sizeof(msg), 0)) {
			rt_printk("SEND FAILED, TASK: %d\n", t);
			goto prem;
		}
		msg[0] = msg[1] = 0;
		if (rt_msgrcv_nu(rmbx, &mtype, msg, sizeof(msg), 1, 0) < 0) {
			rt_printk("RECEIVE FAILED, TASK: %d\n", t);
			goto prem;
		}
		if (msg[0] != t || msg[1] != 0xFFFFFFFF) {
			rt_printk("WRONG REPLY TO TASK: %d.\n", t);
                        goto prem;
		}
		cnt[t]++;
//		rt_printk("TASK: %d, OK (%d).\n", t, cnt[t]);
		rt_sleep(nano2count(SLEEP_TIME));
	}
prem: 
	rt_make_soft_real_time();
	rt_task_delete(mytask);
	printf("TASK %d ENDS.\n", t);
}
예제 #3
0
파일: ktestmsg.c 프로젝트: cjecho/RTAI
static void mfun(int t)
{
	char tname[6] = "MFUN", mname[6] = "RMBX";
	int smbx, rmbx, *msg, mtype, i;

	msg  = rt_malloc((MAXSIZ + 1)*sizeof(int));

	randu();
	tname[4] = mname[4] = t + '0';
	tname[5] = mname[5] = 0;
	smbx = rt_msgget(nam2num("SMSG"), 0);
	rmbx = rt_msgget(nam2num(mname), 0);

	msg[0] = t;
	rt_sem_wait_barrier(&barrier);
	while (end < t) {
		msg[MAXSIZ] = 0;
		for (i = 1; i < MAXSIZ; i++) {
			msg[MAXSIZ] += (msg[i] = MAXSIZ*randu());
		}
		if (rt_msgsnd_nu(smbx, 1, msg, sizeof(int)*(MAXSIZ + 1), 0)) {
			rt_printk("SEND FAILED, TASK: %d\n", t);
			goto prem;
		}
		msg[0] = msg[1] = 0;
		if (rt_msgrcv_nu(rmbx, &mtype, msg, sizeof(int)*(MAXSIZ + 1), 1, 0) < 0) {
			rt_printk("RECEIVE FAILED, TASK: %d\n", t);
			goto prem;
		}
		if (msg[0] != t || msg[1] != 0xFFFFFFFF) {
			rt_printk("WRONG REPLY TO TASK: %d.\n", t);
                        goto prem;
		}
		cnt[t]++;
//		rt_printk("TASK: %d, OK (%d).\n", t, cnt[t]);
		rt_sleep(nano2count(SLEEP_TIME));
	}
prem:
	rt_free(msg);
	rt_printk("TASK %d ENDS.\n", t);
}
예제 #4
0
파일: testmsg.c 프로젝트: ArcEye/RTAI
static void bfun(int t)
{
	RT_TASK *mytask;
	int smbx, rmbx[NTASKS], msg[MAXSIZ + 1], mtype, i, n;

	mytask = rt_thread_init(nam2num("BFUN"), 1, 0, SCHED_FIFO, 0xF);
	smbx = rt_msgget(nam2num("SMSG"), 0);
	for (i = 0; i < NTASKS; i++) {
		char mname[6] = "RMBX";
		mname[4] = i + '0';
		mname[5] = 0;
		rmbx[i] = rt_msgget(nam2num(mname), 0);
	}
	mlockall(MCL_CURRENT | MCL_FUTURE);
	rt_make_hard_real_time();

	rt_sem_wait_barrier(barrier);
	while (end < NTASKS) {
		rt_msgrcv_nu(smbx, &mtype, msg, sizeof(msg), 1, 0);
		n = 0;
		for (i = 1; i < MAXSIZ; i++) {
			n += msg[i];
		}
		if (msg[MAXSIZ] != n) {
			rt_printk("SERVER RECEIVED AN UNKNOWN MSG.\n");
//			goto prem;
		}
if(end >= NTASKS) goto prem;
		msg[1] = 0xFFFFFFFF;
		rt_msgsnd_nu(rmbx[msg[0]], 1, msg, 2*sizeof(int), 0);
	}
prem:
	rt_make_soft_real_time();
	rt_task_delete(mytask);
	printf("SERVER TASK ENDS.\n");
}