Exemplo n.º 1
0
int main(void)
{
	int pid;
	char ch;
	char k = 'k';
	RT_TASK *mytask;
	MBX *Keyboard;

	menu();
	pid = fork();
	if (!pid) {
		execl("./screen", "./screen", NULL);
	}
	sleep(1);

 	if (!(mytask = rt_task_init(nam2num("KBRTSK"), 10, 0, 0))) {
		printf("CANNOT INIT KEYBOARD TASK\n");
		exit(1);
	}

 	if (!(Keyboard = rt_get_adr(nam2num("KEYBRD")))) {
		printf("CANNOT FIND KEYBOARD MAILBOX\n");
		exit(1);
	}

	if (rt_mbx_send(Keyboard, &k, 1) > 0 ) {
		fprintf(stderr, "Can't send initial command to RT-task\n");
		exit(1);
	}

	do {
		ch = get_key();
		if (ch == 'p' || ch == 'P') {
			menu();
		}
		if (ch != 'f' && rt_mbx_send_if(Keyboard, &ch, 1) > 0 ) {
			fprintf(stderr, "Can't send command to RT-task\n");
		}
	} while (ch != 'f');
	ch = 'r';
	rt_mbx_send(Keyboard, &ch, 1);
	ch = 'c';
	rt_mbx_send(Keyboard, &ch, 1);
	ch = 'f';
	rt_mbx_send(Keyboard, &ch, 1);
	rt_task_resume(rt_get_adr(nam2num("MASTER")));
	while (rt_get_adr(nam2num("MASTER"))) {
		rt_sleep(nano2count(1000000));
	}
	kill(pid, SIGINT);
	rt_task_delete(mytask);
	stop_rt_timer();
	exit(0);
}
Exemplo n.º 2
0
Arquivo: sender.c Projeto: ArcEye/RTAI
int main(int argc, char *argv[])
{
	unsigned long rcvnode;
	RT_TASK *sndtsk, *rcvtsk;
	MBX *mbx;
	long rcvport, i;
        struct sockaddr_in addr;

        thread = rt_thread_create(endme, NULL, 2000);

        if (!(sndtsk = rt_task_init_schmod(nam2num("SNDTSK"), 1, 0, 0, SCHED_FIFO, 0xF))) {
                printf("CANNOT INIT SENDER TASK\n");
                exit(1);
        }
	rcvnode = 0;
        if (argc == 2 && strstr(argv[1], "RcvNode=")) {
                inet_aton(argv[1] + 8, &addr.sin_addr);
		rcvnode = addr.sin_addr.s_addr;
        }
        if (!rcvnode) {
                inet_aton("127.0.0.1", &addr.sin_addr);
		rcvnode = addr.sin_addr.s_addr;
        }
        mbx = rt_mbx_init(nam2num("SNDMBX"), 500);
        while ((rcvport = rt_request_port(rcvnode)) <= 0 && rcvport != -EINVAL);
	printf("\nSENDER TASK RUNNING\n");
	mlockall(MCL_CURRENT | MCL_FUTURE);
	rt_make_hard_real_time();

	for (i = 0; i < MAXLOOPS && !end; i++) {
		rt_mbx_send(mbx, &i, sizeof(long));
		rt_printk("SENT %ld\n", i);
                RT_sleep(rcvnode, rcvport, 200000000);
	}
	i = -1;
	rt_mbx_send(mbx, &i, sizeof(long));
	rt_make_soft_real_time();

	while (!(rcvtsk = RT_get_adr(rcvnode, rcvport, "RCVTSK"))) {
		RT_sleep(rcvnode, rcvport, 100000000);
	}
	RT_rpc(rcvnode, rcvport, rcvtsk, i, &i);
	rt_release_port(rcvnode, rcvport);
	rt_mbx_delete(mbx);
	rt_task_delete(sndtsk);
	printf("\nSENDER TASK STOPS\n");
	return 0;
}
Exemplo n.º 3
0
Arquivo: mbx.c Projeto: cjecho/RTAI
static void bfun(long t)
{
	unsigned long long msg;
	unsigned long long name = 0xccccccccccccccccLL;

	while (1) {
		cpu_used[hard_cpu_id()]++;

		msg = 0LL;
		bstat = 'r';
		rt_mbx_receive(&smbx, &msg, sizeof(msg));
		if (msg == 0x1122334455667788LL) {
			t = 0;
		} else {
			if (msg == 0x99aabbccddeeff00LL) {
				t = 1;
			} else {
				rt_printk("SERVER RECEIVED AN UNKNOWN MSG: %x%x, STAT: %c %c %c.\n", ((int *)&msg)[1], ((int *)&msg)[0], mstat[0], mstat[1], bstat);
				t = 0;
				goto prem;
			}
		}
		bstat = '0' + t;
		rt_mbx_send(&rmbx[t], &name, sizeof(name));
	}
prem:
	premature = PREMATURE;
	rt_printk("SERVER TASK ENDS PREMATURELY.\n");
}
Exemplo n.º 4
0
/*
 * initialization task
 */
static void start_task_code(int notused)
{
	int i;
	char buf[9];
	buf[8] = 0;
  /* create the sync semaphore */
	rt_sem_init(&sync_sem, 0);
  /* create the priority-test semaphore */
	rt_sem_init(&prio_sem, 0);
  /* pass the semaphore to the first task */
	rt_sem_signal(&sems[0]);
  /* wait for each task to send the sync semaphore */
	for (i = 0; i < NUM_TASKS; ++i) {
		rt_sem_wait(&sync_sem);
	}
	rt_printk(sync_str);
  /* post the priority-test semaphore -- the tasks should then run */
  /* in priority order */
	for (i = 0; i < NUM_TASKS; ++i) {
		rt_sem_signal(&prio_sem);
	}
	rt_printk("\n");
	for (i = 0; i < NUM_TASKS; ++i) {
		rt_sem_wait(&sync_sem);
	}
	rt_printk(sync_str);

  /* now, test message queues */
	TAKE_PRINT; 
	rt_printk("testing message queues\n");
	GIVE_PRINT;
	for (i = 0; i < NUM_TASKS; ++i) {
		if (rt_mbx_send(&mbx_in, strs[i], 8)) {
			rt_printk("rt_mbx_send() failed\n");
		}
	}
	for (i = 0; i < NUM_TASKS; ++i) {
		rt_mbx_receive(&mbx_out, buf, 8);
		TAKE_PRINT; 
		rt_printk("\nreceived from mbx_out: %s", buf); 
		GIVE_PRINT;
	}
	rt_printk("\n");
	for (i = 0; i < NUM_TASKS; ++i) {
		rt_sem_signal(&sync_sem);
	}
	TAKE_PRINT; 
	rt_printk("\ninit task complete\n"); 
	GIVE_PRINT;

  /* nothing more for this task to do */
}
Exemplo n.º 5
0
int main(void)
{
	RT_TASK *mytask;
	MBX *Keyboard, *Screen;
	unsigned int i;
	char d = 'd';
	char chain[12];
	char displine[40] = "CLOCK-> 00:00:00  CHRONO-> 00:00:00";

	signal(SIGINT, endme);
 	if (!(mytask = rt_task_init_schmod(nam2num("SCRTSK"), 20, 0, 0, SCHED_FIFO, 0xF))) {
		printf("CANNOT INIT SCREEN TASK\n");
		exit(1);
	}

 	if (!(Keyboard = rt_get_adr(nam2num("KEYBRD")))) {
		printf("CANNOT FIND KEYBOARD MAILBOX\n");
		exit(1);
	}

	if (rt_mbx_send(Keyboard, &d, 1) > 0 ) {
		fprintf(stderr, "Can't send initial command to RT-task\n");
		exit(1);
	}

 	if (!(Screen = rt_get_adr(nam2num("SCREEN")))) {
		printf("CANNOT FIND SCREEN MAILBOX\n");
		exit(1);
	}

	sleep(1);
	printf("%s\n", displine);
	while(1) {
		if (rt_mbx_receive(Screen, chain, 12)) break;
		if (chain[0] == 't') {
			for (i = 0; i < 11; i++) {
				displine[i+27] = chain[i+1];
			}
		} else if (chain[0] == 'h') {
			for (i = 0; i < 8; i++) {
				displine[i+8] = chain[i+1];
			}
		}
		printf("%s\n", displine);
	}
	rt_task_delete(mytask);
	return 0;
}
Exemplo n.º 6
0
Arquivo: sound.c Projeto: ArcEye/RTAI
int main(void)
{
	pthread_t thread;
	unsigned int player, cnt;
	unsigned long msg;
	RT_TASK *mytask;
	MBX *mbx;
	char data[BUFSIZE];

	signal(SIGINT, endme);
	rt_allow_nonroot_hrt();

	if ((player = open("../../../share/linux.au", O_RDONLY)) < 0) {
		printf("ERROR OPENING SOUND FILE (linux.au)\n");
		exit(1);
	}
 	if (!(mytask = rt_task_init(nam2num("SNDMAS"), 2, 0, 0))) {
		printf("CANNOT INIT MASTER TASK\n");
		exit(1);
	}
	mlockall(MCL_CURRENT | MCL_FUTURE);
	printf("\nINIT MASTER TASK %p\n\n(CTRL-C TO END EVERYTHING)\n", mytask);

	mbx = rt_typed_named_mbx_init("SNDMBX", 2000, FIFO_Q);
	rt_set_oneshot_mode();
	start_rt_timer(0);
	thread = rt_thread_create(intr_handler, NULL, 10000);
	rt_mbx_receive(mbx, &data, 1);

	while (!end) {	
		lseek(player, 0, SEEK_SET);
		while(!end && (cnt = read(player, &data, BUFSIZE)) > 0) {
			rt_mbx_send(mbx, data, cnt);
		}
	}

	rt_rpc(rt_get_adr(nam2num("SOUND")), msg, &msg); 
	while (rt_get_adr(nam2num("SOUND"))) {
		rt_sleep(nano2count(1000000));
	}
	rt_task_delete(mytask);
	rt_mbx_delete(mbx);
	stop_rt_timer();
	close(player);
	printf("\nEND MASTER TASK %p\n", mytask);
	rt_thread_join(thread);
	return 0;
}
Exemplo n.º 7
0
static void *intr_handler(void *args)
{
	RT_TASK *mytask, *master;
	RTIME period;
	MBX *mbx;
	char data = 'G';
	char temp;
	unsigned int msg;

	pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
//	rt_allow_nonroot_hrt();
	ioperm(PORT_ADR, 1, 1);

 	if (!(mytask = rt_task_init_schmod(nam2num("SOUND"), 1, 0, 0, SCHED_FIFO, 0xF))) {
		printf("CANNOT INIT SOUND TASK\n");
		exit(1);
	}
	mbx = rt_get_adr(nam2num("SNDMBX"));
	mlockall(MCL_CURRENT | MCL_FUTURE);

	printf("\nINIT SOUND TASK %p\n", mytask);

	rt_make_hard_real_time();
	period = nano2count(PERIOD);
	rt_mbx_send(mbx, &data, 1);
	rt_task_make_periodic(mytask, rt_get_time() + 100*period, period);

	while(1) {
		if (!rt_mbx_receive_if(mbx, &data, 1)) {
			data = filter(data);
			temp = inb(PORT_ADR);            
			temp &= 0xfd;
			temp |= (data & 1) << 1;
			outb(temp, PORT_ADR);
		}
		rt_task_wait_period();
		if ((master = rt_receive_if(0, &msg))) {
			rt_return(master, msg);
			break;
		} 
	}

	rt_make_soft_real_time();
	rt_task_delete(mytask);
	printf("\nEND SOUND TASK %p\n", mytask);
	return 0;
}
Exemplo n.º 8
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); 
}
Exemplo n.º 9
0
Arquivo: master.c Projeto: 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;
}