static inline void RT_SEM_SIGNAL(unsigned long node, int port, SEM *sem) { if (rt_waiting_return(node, port)) { RT_sem_signal(node, port > 0 ? port : -port, sem); } else { RT_sem_signal(node, port, sem); } }
int main(int argc, char *argv[]) { RT_TASK *task; struct sockaddr_in addr; int i, srvport; if (!(task = rt_task_init(nam2num("TSKCOD"), 0, 0, 0))) { printf("CANNOT INIT TASK CODE\n"); exit(1); } comnode = 0; if (argc == 2 && strstr(argv[1], "ComNode=")) { inet_aton(argv[1] + 8, &addr.sin_addr); comnode = addr.sin_addr.s_addr; } if (!comnode) { inet_aton("127.0.0.1", &addr.sin_addr); comnode = addr.sin_addr.s_addr; } init_module(); for (i = 0; i < NUM_TASKS; i++) { rt_thread_join(thread[i]); } while ((srvport = rt_request_port(comnode)) <= 0) { msleep(100); } RT_sem_signal(comnode, srvport, end_sem); rt_release_port(comnode, srvport); rt_task_delete(task); exit(0); }
static void timer_tick(void) { rt_times.tick_time = rt_times.intr_time; rt_times.intr_time = rt_times.tick_time + rt_times.periodic_tick; rt_set_timer_delay(0); if (rt_times.tick_time >= rt_times.linux_time) { rt_times.linux_time += rt_times.linux_tick; rt_pend_linux_irq(TIMER_8254_IRQ); } if (run) { if (rt_waiting_return(tasknode, taskport)) { overuns++; } switch(run) { case 1: RT_sem_signal(tasknode, -taskport, rmt_sem); rt_printk("SEM SIGNAL %d\n", ++cnt); break; case 2: RT_task_resume(tasknode, -taskport, rmt_task); rt_printk("TASK RESUME %d\n", ++cnt); break; case 3: RT_send_if(tasknode, -taskport, rmt_task, run); rt_printk("TASK SEND %d\n", ++cnt); break; } } }
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); }
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"); }
static void start_task_code(long none) { int i, srvport; char buf[9]; while ((srvport = rt_request_port(tasknode)) <= 0); rt_printk("START TASK GOT SYNC TASKNODE PORT %lx, %d\n", tasknode, srvport); while (!RT_get_adr(tasknode, srvport, task[NUM_TASKS - 1])); rt_printk("START TASK REL SYNC TASKNODE PORT %lx, %d\n", tasknode, srvport); rt_release_port(tasknode, srvport); srvport = rt_request_port(comnode); rt_printk("START TASK GOT ITS INIT AND EXEC COMNODE PORT %lx, %d\n", comnode, srvport); print_sem = RT_get_adr(comnode, srvport, "PRTSEM"); sync_sem = RT_get_adr(comnode, srvport, "SYNCSM"); prio_sem = RT_get_adr(comnode, srvport, "PRIOSM"); 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]); } buf[8] = 0; 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; rt_release_port(comnode, srvport); rt_printk("START TASK REL ITS EXEC COMNODE PORT %lx, %d\n", comnode, srvport); atomic_inc(&cleanup); }
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; }
static void *task_code(void *arg) { RT_TASK *mytask; int task_no, i, ret, srvport; char buf[9]; task_no = *((int *)arg); buf[8] = 0; if (!(mytask = rt_thread_init(nam2num(task[task_no]), NUM_TASKS - task_no, 0, SCHED_FIFO, 0xF))) { printf("CANNOT INIT TASK TASK %d\n", task_no); exit(1); } srvport = rt_request_port(comnode); printf("TASK_NO %d GOT ITS EXEC COMNODE PORT %lx, %d\n", task_no, comnode, srvport); mlockall(MCL_CURRENT | MCL_FUTURE); rt_make_hard_real_time(); for (i = 0; i < 5; ++i) { RT_sem_wait(comnode, srvport, sems[task_no]); TAKE_PRINT; rt_printk(strs[task_no]); GIVE_PRINT; if (task_no == NUM_TASKS - 1) { TAKE_PRINT; rt_printk("\n"); GIVE_PRINT; } RT_SEM_SIGNAL(comnode, -srvport, sems[(task_no + 1)%NUM_TASKS]); } RT_SEM_SIGNAL(comnode, -srvport, sync_sem); RT_sem_wait(comnode, srvport, prio_sem); TAKE_PRINT; rt_printk(strs[task_no]); GIVE_PRINT; RT_sleep(comnode, srvport, 1000000000LL); RT_sem_wait_timed(comnode, srvport, prio_sem, (task_no + 1)*1000000000LL); TAKE_PRINT; rt_printk("sem timeout, task %d, %s\n", task_no, strs[task_no]); GIVE_PRINT; RT_SEM_SIGNAL(comnode, -srvport, sync_sem); /* message queue stuff */ if ((ret = RT_mbx_receive(comnode, srvport, mbx_in, buf, 8)) != 0) { TAKE_PRINT; rt_printk("RT_mbx_receive() failed with %d\n", ret); GIVE_PRINT; } TAKE_PRINT; rt_printk("\nreceived by task %d ", task_no); rt_printk(buf); GIVE_PRINT; RT_mbx_send(comnode, srvport, mbx_out, strs[task_no], 8); /* test receive timeout */ RT_sem_wait(comnode, srvport, sync_sem); if (RT_mbx_receive_timed(comnode, srvport, mbx_in, buf, 8, (task_no + 1)*1000000000LL)) { TAKE_PRINT; rt_printk("mbx timeout, task %d, %s\n", task_no, strs[task_no]); GIVE_PRINT; } TAKE_PRINT; rt_printk("\ntask %d complete\n", task_no); GIVE_PRINT; rt_make_soft_real_time(); printf("TASK_NO %d REL ITS EXEC COMNODE PORT %lx, %d\n", task_no, comnode, srvport); RT_sem_signal(comnode, srvport, end_sem); rt_release_port(comnode, srvport); rt_task_delete(mytask); return (void *)0; }