Esempio n. 1
0
static int init_module(void)
{
	int i, srvport;
	while ((srvport = rt_request_hard_port(tasknode)) <= 0) {
		msleep(100);
	}
printf("START TASK GOT SYNC TASKNODE PORT %lx, %d\n", tasknode, srvport);
	rt_make_hard_real_time();
	while (!RT_get_adr(tasknode, srvport, task[NUM_TASKS - 1])) {
		msleep(100);
	}
	rt_make_soft_real_time();
printf("START TASK REL SYNC TASKNODE PORT %lx, %d\n", tasknode, srvport);
	rt_release_port(tasknode, srvport);
	srvport = rt_request_hard_port(comnode);
printf("START TASK GOT INIT COMNODE PORT %lx, %d\n", comnode, srvport);
	rt_make_hard_real_time();
        print_sem = RT_get_adr(comnode, srvport, "PRTSEM");
        sync_sem = RT_get_adr(comnode, srvport, "SYNCSM");
        prio_sem = RT_get_adr(comnode, srvport, "PRIOSM");
        end_sem = RT_get_adr(comnode, srvport, "ENDSEM");
        mbx_in   = RT_get_adr(comnode, srvport, "MBXIN");
        mbx_out  = RT_get_adr(comnode, srvport, "MBXOUT");

	for (i = 0; i < NUM_TASKS; ++i) {
		sems[i] = RT_get_adr(comnode, srvport, sem[i]);
	}
printf("START TASK REL INIT COMNODE PORT %lx, %d\n", comnode, srvport);
	rt_make_soft_real_time();
	rt_release_port(comnode, srvport);
        thread = rt_thread_create(start_task_code, NULL, 10000);
	return 0;
}
Esempio n. 2
0
File: player.c Progetto: cjecho/RTAI
int main(int argc, char *argv[])
{
	unsigned int player, msg, spknode, spkport, i;
	RT_TASK *plrtsk, *spktsk;
        struct sockaddr_in addr;
	char data[BUFSIZE];

        thread = rt_thread_create(endme, NULL, 2000);
	if ((player = open("../../../share/linux.au", O_RDONLY)) < 0) {
		printf("ERROR OPENING SOUND FILE (linux.au)\n");
		exit(1);
	}

 	if (!(plrtsk = rt_task_init_schmod(nam2num("PLRTSK"), 2, 0, 0, SCHED_FIFO, 0xF))) {
		printf("CANNOT INIT PLAYER TASK\n");
		exit(1);
	}

        spknode = 0;
        if (argc == 2 && strstr(argv[1], "SpkNode=")) {
                inet_aton(argv[1] + 8, &addr.sin_addr);
                spknode = addr.sin_addr.s_addr;
        }
        if (!spknode) {
                inet_aton("127.0.0.1", &addr.sin_addr);
                spknode = addr.sin_addr.s_addr;
        }

	while ((spkport = rt_request_hard_port(spknode)) <= 0 && spkport != -EINVAL);
	rt_make_hard_real_time();
	spktsk = RT_get_adr(spknode, spkport, "SPKTSK");

	RT_rpcx(spknode, spkport, spktsk, &i, &msg, sizeof(int), sizeof(int));
        for (i = 0; i < 100; i++) {
		RT_rpcx(spknode, spkport, spktsk, &i, &msg, sizeof(int), sizeof(int));
        }
	mlockall(MCL_CURRENT | MCL_FUTURE);
	printf("\nPLAYER TASK RUNNING\n(TYPE ENTER TO END EVERYTHING)\n");

	while (!end) {
		lseek(player, 0, SEEK_SET);
		while(!end && (i = read(player, data, BUFSIZE)) > 0) {
			RT_rpcx(spknode, spkport, spktsk, data, &msg, i, sizeof(int));
			if (msg != i) {
				printf("SPEAKER RECEIVED LESS THAN SENT BY PLAYER\n");
			}
		}
	}

	msg = 0xFFFFFFFF;
	RT_rpcx(spknode, spkport, spktsk, &msg, &msg, sizeof(int), 1);
	rt_make_soft_real_time();
	rt_release_port(spknode, spkport);
	rt_task_delete(plrtsk);
	close(player);
	printf("PLAYER TASK STOPS\n");
	return 0;
}
Esempio n. 3
0
int main(int argc, char *argv[])
{
        RT_TASK *task;
        struct sockaddr_in addr;
	int i, srvport;

        if (!(task = rt_task_init(nam2num("STRTSK"), 0, 0, 0))) {
                printf("CANNOT INIT START_TASK TASK\n");
                exit(1);
        }

        comnode = tasknode = 0;
        for (i = 0; i < argc; i++) {
                if (strstr(argv[i], "ComNode=")) {
                	inet_aton(argv[i] + 8, &addr.sin_addr);
	                comnode = addr.sin_addr.s_addr;
                        argv[i] = 0;
                        continue;
                }
                if (strstr(argv[i], "TaskNode=")) {
                	inet_aton(argv[i] + 9, &addr.sin_addr);
	                tasknode = addr.sin_addr.s_addr;
                        argv[i] = 0;
                        continue;
                }
        }
        if (!comnode) {
                inet_aton("127.0.0.1", &addr.sin_addr);
                comnode = addr.sin_addr.s_addr;
        }
        if (!tasknode) {
                inet_aton("127.0.0.1", &addr.sin_addr);
                tasknode = addr.sin_addr.s_addr;
        }
	rt_grow_and_lock_stack(100000);
	init_module();
	rt_thread_join(thread);
        while ((srvport = rt_request_hard_port(comnode)) <= 0) {
                msleep(100);
        }
	rt_make_hard_real_time();
        RT_sem_signal(comnode, srvport, end_sem);
	rt_make_soft_real_time();
        rt_release_port(comnode, srvport);
        rt_task_delete(task);
	exit(0);
}
Esempio n. 4
0
static void sup_fun(long none)
{
	while (tasknode && (taskport = rt_request_hard_port(tasknode)) <= 0);
	rt_mbx_receive(&mbx, &rmt_task, sizeof(rmt_task));
	rt_mbx_receive(&mbx, &rmt_sem, sizeof(rmt_sem));
	rt_mbx_receive(&mbx, &run, 1);

	do {
		rt_task_suspend(&sup_task);
		switch(run) {
			case 1: RT_sem_signal(tasknode, -taskport, rmt_sem);
				break;
			case 2:
				RT_task_resume(tasknode, -taskport, rmt_task);
				break;
			case 3:
				RT_send_if(tasknode, -taskport, rmt_task, run);
				break;
		}
	} while (rt_mbx_receive_if(&mbx, &run, 1));

		rt_release_port(tasknode, taskport);
	rt_printk("ALL INTERRUPT MODULE FUNCTIONS TERMINATED\n");
}
Esempio n. 5
0
int main(int argc, char *argv[])
{
	unsigned int plrnode, plrport;
	RT_TASK *spktsk, *plrtsk;
	RTIME period;
	struct sockaddr_in addr;
	char buf[BUFSIZE], data, temp;
	unsigned int msg, i, len;

	printf("\n\nSPECIFIC RECEIVE USING EXPLICITELY ASSIGNED LOCAL STUB\n");
	ioperm(PORT_ADR, 1, 1);
        if (!(spktsk = rt_task_init_schmod(nam2num("SPKTSK"), 1, 0, 0, SCHED_FIFO, 0xF))) {
                printf("CANNOT INIT SPEAKER TASK\n");
                exit(1);
        }

        rt_returnx(rt_receivex(0, &msg, sizeof(int), &len), &msg, 1);
        plrnode = 0;
        if (argc == 2 && strstr(argv[1], "PlrNode=")) {
                inet_aton(argv[1] + 8, &addr.sin_addr);
                plrnode = addr.sin_addr.s_addr;
        }
        if (!plrnode) {
                inet_aton("127.0.0.1", &addr.sin_addr);
                plrnode = addr.sin_addr.s_addr;
        }

	rt_set_oneshot_mode();
	start_rt_timer(0);
	while ((plrport = rt_request_hard_port(plrnode)) <= 0 && plrport != -EINVAL);
	rt_make_hard_real_time();
	while (!(plrtsk = RT_get_adr(plrnode, plrport, "PLRTSK"))) {
		rt_sleep(nano2count(10000000));
	}

	printf("\nSPEAKER TASK RUNNING\n");

	mlockall(MCL_CURRENT | MCL_FUTURE);

	period = nano2count(PERIOD);
	rt_task_make_periodic(spktsk, rt_get_time() + 5*period, period);

	plrtsk = rt_find_asgn_stub(OWNER(plrnode, plrtsk), 1);
        for (i = 0; i < 100; i++) {
		rt_returnx(rt_receivex(plrtsk, &msg, sizeof(int), &len), &msg, sizeof(int));
        }

	len = 0;
	while(1) {
		if (len) {
			data = filter(buf[i++]);
			temp = inb(PORT_ADR);            
			temp &= 0xfd;
			temp |= (data & 1) << 1;
			outb(temp, PORT_ADR);
			len--;
		} else {
			if (rt_evdrpx(plrtsk, buf, BUFSIZE, &i)) {
//				rt_printk("EVDRP %d\n", i);
			}
			if (rt_receivex_if(plrtsk, buf, BUFSIZE, &len) == plrtsk) {
				rt_returnx(plrtsk, &len, sizeof(int));
				if (len == sizeof(int) && ((int *)buf)[0] == 0xFFFFFFFF) {
					break;
				} 
				i = 0;
			}
		}
		rt_task_wait_period();
	}

	rt_sleep(nano2count(100000000));
	rt_make_soft_real_time();
	stop_rt_timer();
	rt_release_port(plrnode, plrport);
	rt_task_delete(spktsk);
	printf("\nSPEAKER TASK STOPS\n");
	return 0;
}
Esempio n. 6
0
static void *start_task_code(void *args)
{
	int i, srvport;
	char buf[9];
        RT_TASK *task;

	buf[8] = 0;
	if (!(task = rt_thread_init(getpid(), 10, 0, SCHED_FIFO, 0xF))) {
                printf("CANNOT INIT START_TASK BUDDY\n");
                exit(1);
        }

	srvport = rt_request_hard_port(comnode);
printf("START TASK GOT ITS EXEC COMNODE PORT %lx, %d\n", comnode, srvport);
        mlockall(MCL_CURRENT | MCL_FUTURE);
	rt_make_hard_real_time();

	RT_SEM_SIGNAL(comnode, -srvport, sems[0]);
	for (i = 0; i < NUM_TASKS; ++i) {
		RT_sem_wait(comnode, srvport, sync_sem);
	}
	TAKE_PRINT;
	rt_printk(sync_str);
	GIVE_PRINT;
	for (i = 0; i < NUM_TASKS; ++i) {
		RT_SEM_SIGNAL(comnode, -srvport, prio_sem);
	}
	TAKE_PRINT;
	rt_printk("\n");
	GIVE_PRINT;
	for (i = 0; i < NUM_TASKS; ++i) {
		RT_sem_wait(comnode, srvport, sync_sem);
	}
	TAKE_PRINT;
	rt_printk(sync_str);
	GIVE_PRINT;

	TAKE_PRINT;
	rt_printk("testing message queues\n");
	GIVE_PRINT;
	for (i = 0; i < NUM_TASKS; ++i) {
		if (RT_mbx_send(comnode, srvport, mbx_in, strs[i], 8)) {
			TAKE_PRINT;
			rt_printk("RT_mbx_send() failed\n");
			GIVE_PRINT;
		}
	}
	for (i = 0; i < NUM_TASKS; ++i) {
		RT_mbx_receive(comnode, srvport, mbx_out, buf, 8);
		TAKE_PRINT;
		rt_printk("\nreceived from mbx_out: %s", buf);
		GIVE_PRINT;
	}
	TAKE_PRINT;
	rt_printk("\n");
	GIVE_PRINT;
	for (i = 0; i < NUM_TASKS; ++i) {
		RT_SEM_SIGNAL(comnode, -srvport, sync_sem);
	}
	TAKE_PRINT;
	rt_printk("\ninit task complete\n");
	GIVE_PRINT;
printf("START TASK REL ITS EXEC COMNODE PORT %lx, %d\n", comnode, srvport);
        RT_sem_signal(comnode, srvport, end_sem);
	rt_make_soft_real_time();
	rt_release_port(comnode, srvport);
	rt_task_delete(task);
	return (void *)0;
}