int main(void) { RT_TASK *task; RTIME now; int cnt=0; // make main thread LXRT soft realtime task = rt_task_init_schmod(nam2num("MYTASK"), 9, 0, 0, SCHED_FIFO, 0xF); mlockall(MCL_CURRENT | MCL_FUTURE); // start realtime timer and scheduler //rt_set_oneshot_mode(); rt_set_periodic_mode(); start_rt_timer(0); now = rt_get_time() + 10*PERIOD; rt_task_make_periodic(task, now, PERIOD); printf("Init mutex and cond.\n"); mutex = rt_sem_init(nam2num("MUTEX"), 1); if (mutex==0) printf("Error init mutex\n"); cond = rt_cond_init(nam2num("CONDITION")); if (cond==0) printf("Error init cond\n"); thread0 = rt_thread_create(fun0, NULL, 10000); //thread1 = rt_thread_create(fun1, NULL, 20000); //rt_sleep(PERIOD); while (cnt < THRESHOLD) { rt_task_wait_period(); rt_printk("main: Hello World %d!\n",cnt); rt_sem_wait(mutex); //now the mutex should have value 0 if (instance_cnt==0) { rt_sem_signal(mutex); //now the mutex should have vaule 1 rt_printk("worker thread busy!\n"); } else { instance_cnt++; rt_cond_signal(cond); rt_sem_signal(mutex); //now the mutex should have vaule 1 rt_printk("signaling worker thread to start!\n"); } cnt++; } // wait for end of program printf("TYPE <ENTER> TO TERMINATE\n"); getchar(); // cleanup stop_rt_timer(); return 0; }
int main(void) { RT_TASK *Main_Task; long msg; if (!(Main_Task = rt_thread_init(nam2num("MNTSK"), 10, 0, SCHED_FIFO, 0xF))) { printf("CANNOT INIT MAIN TASK\n"); exit(1); } if (!(hard_timer_running = rt_is_hard_timer_running())) { start_rt_timer(0); } barrier = rt_sem_init(nam2num("PREMS"), 4); latency_thread = rt_thread_create(latency_fun, NULL, 0); fast_thread = rt_thread_create(fast_fun, NULL, 0); slow_thread = rt_thread_create(slow_fun, NULL, 0); start = rt_get_time() + nano2count(200000000); rt_sem_wait_barrier(barrier); rt_receive(0, &msg); end = 1; rt_sem_wait_barrier(barrier); rt_thread_join(latency_thread); rt_thread_join(fast_thread); rt_thread_join(slow_thread); if (!hard_timer_running) { stop_rt_timer(); } rt_sem_delete(barrier); rt_thread_delete(Main_Task); return 0; }
static int my_init(void) { int i, ierr1, ierr2; rt_typed_sem_init(&semaphore1, 0, BIN_SEM); rt_typed_sem_init(&semaphore2, 0, BIN_SEM); rt_set_oneshot_mode(); ierr1 = rt_task_init_cpuid(&tasks[0], task_body1, 0, STACK_SIZE, 1, 0, 0, 0); ierr2 = rt_task_init_cpuid(&tasks[1], task_body2, 0, STACK_SIZE, 0, 0, 0, 0); printk("[task 1] init return code %d by program %s\n", ierr1, __FILE__); printk("[task 2] init return code %d by program %s\n", ierr2, __FILE__); if (ierr1 == -1 || ierr2 == -1) { return -1; } start_rt_timer(nano2count(TICK_PERIOD)); first_release = rt_get_time(); for (i = 0 ; i < N_TASK ; i++) { rt_task_make_periodic(&tasks[i], first_release, PERIOD); } return 0; }
int init_module (void) { RTIME tick_period; RTIME now; #ifdef SHM_DEBUG int size = SHMSIZ ; unsigned long vaddr, paddr; #endif shm = (int *)rtai_kmalloc(nam2num(SHMNAM), SHMSIZ); shm = (int *)rtai_kmalloc(nam2num(SHMNAM), SHMSIZ); shm = (int *)rtai_kmalloc(nam2num(SHMNAM), SHMSIZ); shm = (int *)rtai_kmalloc(nam2num(SHMNAM), SHMSIZ); if (shm == NULL) return -ENOMEM; memset(shm, 0, SHMSIZ); #ifdef SHM_DEBUG /* Show physical addresses of */ vaddr = (unsigned long)shm; while (size > 0) { paddr = kvirt_to_pa(vaddr); printk("vaddr=0x%lx paddr=0x%lx\n", vaddr, paddr); vaddr += PAGE_SIZE; size -= PAGE_SIZE; } #endif rt_task_init(&thread, fun, 0, STACK_SIZE, 0, 0, 0); tick_period = start_rt_timer(nano2count(TICK_PERIOD)); now = rt_get_time(); rt_task_make_periodic(&thread, now + tick_period, tick_period*PERIOD_COUNT); return 0; }
int main(void) { RT_TASK *task; signal(SIGTERM, catch_signal); signal(SIGINT, catch_signal); if (!(task = rt_thread_init(nam2num("SWITCH"), 0, 0, SCHED_FIFO, 0xF))) { printf("CANNOT INIT SWITCH TASK SIGNAL\n"); exit(1); } start_rt_timer(0); rt_request_signal(SWITCH_SIGNAL, switch_handler); rt_task_signal_handler(task, (void *)SWITCH_SIGNAL); rt_make_hard_real_time(); while (!end) { rt_sleep(nano2count(PERIOD)); } rt_task_signal_handler(task, NULL); rt_release_signal(SWITCH_SIGNAL, task); rt_make_soft_real_time(); stop_rt_timer(); rt_task_delete(task); return 0; }
static int my_init(void) { int i; rt_set_oneshot_mode(); for (i = 0 ; i < N_TASK ; i++) { int ierr = rt_task_init_cpuid(&tasks[i], task_body, i, STACK_SIZE, Priority[i], 0, 0, 0); printk("[task %d] init return code %d by program %s\n", i, ierr, __FILE__); if (ierr == -1) { return ierr; } } start_rt_timer(nano2count(TICK_PERIOD)); time_unit = calibrate(); first_release = rt_get_time(); for (i = 0 ; i < N_TASK ; i++) { rt_task_make_periodic(&tasks[i], first_release, Period[i] * time_unit); } return 0; }
int main(void) { pthread_setschedparam_np(0, SCHED_FIFO, 0, 0xF, PTHREAD_HARD_REAL_TIME); start_rt_timer(0); do_test(); return 0; }
int main(void) { int i, srq, count = 0, nextcount = 0, repeat; rt_thread_init(nam2num("MNTSK"), 100, 0, SCHED_FIFO, 0x1); rt_printk("\nTESTING THE SCHEDULER WITH SRQs [%d LOOPs].\n", LOOPS); repeat = 1000000000LL/((long long)DELAY*(long long)PRINT_FREQ); srq = rtai_open_srq(0xcacca); start_rt_timer(0); rt_grow_and_lock_stack(100000); #ifdef MAKE_HARD MAKE_HARD(); #endif for (i = 0; i < LOOPS; i++) { rtai_srq(srq, (unsigned long)nano2count(DELAY)); if (++count > nextcount) { nextcount += repeat; rt_printk(">>> %d.\n", nextcount); } } rt_make_soft_real_time(); stop_rt_timer(); rt_task_delete(NULL); rt_printk("END SCHEDULER TEST WITH SRQs.\n\n"); return 0; }
int main(void) { pthread_init_real_time_np("TASKA", 0, SCHED_FIFO, 0xF, PTHREAD_HARD_REAL_TIME); start_rt_timer(0); do_test(); return 0; }
int main(void) { struct sched_param mysched; mysched.sched_priority = sched_get_priority_max(SCHED_FIFO); if( sched_setscheduler( 0, SCHED_FIFO, &mysched ) == -1 ) { puts(" ERROR IN SETTING THE SCHEDULER UP"); perror("errno"); exit(0); } rt_grow_and_lock_stack(20000); #ifdef ONE_SHOT rt_set_oneshot_mode(); #endif start_rt_timer(nano2count(TICK_PERIOD)); firing_time = rt_get_time(); period = nano2count(1000000); prt = rt_init_timer(); rt_insert_timer(prt, 1, firing_time, period, prh, 0, 1); rt_tasklet_use_fpu(prt, 1); seqt = rt_init_timer(); rt_insert_timer(seqt, 0, firing_time, 0, seqh, 0, 1); while(!end) sleep(1); stop_rt_timer(); rt_delete_timer(prt); rt_delete_timer(seqt); return 0; }
int main(void) { RT_TASK *spktsk, *plrtsk; RTIME period; char buf[BUFSIZE], data, temp; unsigned int msg, i, len; printf("\n\nGENERIC RECEIVE\n"); ioperm(PORT_ADR, 1, 1); iopl(3); if (!(spktsk = rt_task_init_schmod(nam2num("SPKTSK"), 1, 0, 0, SCHED_FIFO, 0xF))) { printf("CANNOT INIT SPEAKER TASK\n"); exit(1); } rt_set_oneshot_mode(); start_rt_timer(0); mlockall(MCL_CURRENT | MCL_FUTURE); printf("\nSPEAKER TASK RUNNING\n"); rt_make_hard_real_time(); period = nano2count(PERIOD); rt_task_make_periodic(spktsk, rt_get_time() + 5*period, period); rt_returnx(rt_receivex(0, &msg, sizeof(int), &len), &msg, 1); for (i = 0; i < 100; i++) { rt_returnx(rt_receivex(0, &msg, sizeof(int), &len), &msg, 1); } 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(0, buf, BUFSIZE, &i)) { // rt_printk("EVDRP %d\n", i); } if ((plrtsk = rt_receivex_if(0, buf, BUFSIZE, &len))) { 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_task_delete(spktsk); printf("\nSPEAKER TASK STOPS\n"); return 0; }
int realtime_on(void){ int retval; /*RT_TASK * rt_task_init_schmod(unsigned long name, int priority, int stack_size, int max_msg_size, int policy, int cpus_allowed)*/ if(!(task = rt_task_init_schmod(nam2num("TAREA11"), 1, 0, 0, SCHED_FIFO, 0xF))){ printf("rt_task_init_schmod error\n"); return -1; } mlockall( MCL_CURRENT | MCL_FUTURE ); printf("TAREAL EN TIEMPO REAL (name = %lu, address = %p)\n", nam2num("TAREA1"), task); rt_set_oneshot_mode(); task_period_count = nano2count(task_period_ns); timer_period_count = start_rt_timer(task_period_count);/*Inicia temporizador*/ printf("\tRequested %d counts, got %d counts\n",(int) task_period_count, (int) timer_period_count); retval = rt_task_make_periodic(task, rt_get_time() + task_period_count, task_period_count); /* recurring period */ if (0 != retval) { printf("rt_task_make_periodic error\n"); return -1; } rt_make_hard_real_time(); printf("\tPeriodo=%f\n\n",(double)task_period_ns/1e9); return 1; }
int main(void) { pthread_setschedparam_np(0, SCHED_FIFO, 0, 0x1, PTHREAD_HARD_REAL_TIME_NP); mlockall(MCL_CURRENT | MCL_FUTURE); RT_SET_REAL_TIME_MODE(); pthread_cleanup_push(main_exit_handler, 0); start_rt_timer(nano2count(TICK)); DISPLAY("User space POSIX test program.\n"); pthread_cond_init(cond = &conds, NULL); pthread_mutex_init(mtx = &mtxs, NULL); pthread_barrier_init(barrier = &barriers, NULL, 5); pthread_create(&thread1, NULL, task_func1, NULL); pthread_create(&thread2, NULL, task_func2, NULL); pthread_create(&thread3, NULL, task_func3, NULL); pthread_create(&thread4, NULL, task_func4, NULL); pthread_barrier_wait(barrier); DISPLAY("\nDo not panic, wait 2 s, till task3 times out.\n\n"); pthread_barrier_wait(barrier); pthread_join(thread1, NULL); pthread_join(thread2, NULL); pthread_join(thread3, NULL); pthread_join(thread4, NULL); pthread_cond_destroy(cond); pthread_mutex_destroy(mtx); pthread_cleanup_pop(1); DISPLAY("User space POSIX test program removed.\n"); pthread_exit(0); return 0; }
int init_module(void) { RTIME tick_period; int err; printk("%s: Loading RX%d Test module...\n", test_name, rt_port); err = rt_spopen(rt_port, line_param[0], line_param[1], line_param[2], line_param[3], line_param[4], line_param[5]); if (err) return err; /* Register error handler */ rt_spset_err_callback_fun(rt_port, error_handler); /* Start RX message handler */ rt_task_init(&thread, rx_handler, 0, STACK_SIZE, 0, 0, 0); rt_task_resume(&thread); rt_set_oneshot_mode(); if (period) { tick_period = start_rt_timer(nano2count(period)); rt_task_make_periodic(&thread, rt_get_time(), tick_period); } return 0; }
int init_module(void) { int i; rt_sem_init(&barrier, NTASKS + 1); smbx = rt_msgget(nam2num("SMSG"), 0x666 | IPC_CREAT); for (i = 0; i < NTASKS; i++) { char mname[6] = "RMBX"; mname[4] = i + '0'; mname[5] = 0; rmbx[i] = rt_msgget(nam2num(mname), 0x666 | IPC_CREAT); } rt_set_oneshot_mode(); start_rt_timer(0); rt_kthread_init(&bthread, bfun, 0, 0x8000, 1, 1, 0); rt_task_resume(&bthread); for (i = 0; i < NTASKS; i++) { rt_kthread_init(&mthread[i], mfun, i, 0x8000, i + 2, 1, 0); rt_task_resume(&mthread[i]); } return 0; }
int main(int argc, char *argv[]) { int fifo, period, skip, average = 0; RT_TASK *task; RTIME expected; if ((fifo = open("/dev/rtf0", O_WRONLY)) < 0) { printf("Error opening FIFO0 in UCAL\n"); exit(1); } if (!(task = rt_task_init_schmod(nam2num("UCAL"), 0, 0, 0, SCHED_FIFO, 0xF))) { printf("Cannot init UCAL\n"); exit(1); } rt_set_oneshot_mode(); period = start_rt_timer(nano2count(atoi(argv[1]))); mlockall(MCL_CURRENT | MCL_FUTURE); rt_make_hard_real_time(); expected = rt_get_time() + 100*period; rt_task_make_periodic(task, expected, period); for (skip = 0; skip < atoi(argv[2]); skip++) { expected += period; rt_task_wait_period(); average += (int)count2nano(rt_get_time() - expected); } rt_make_soft_real_time(); stop_rt_timer(); rt_task_delete(task); write(fifo, &average, sizeof(average)); close(fifo); exit(0); }
int main(void) { RT_TASK *maint; MSG msg = { 0, 0 }; maint = rt_task_init(nam2num("MAIN"), 99, 0, 0); bx = rt_tbx_init(nam2num("BX"), TBXSIZE, ORDER); start_rt_timer(nano2count(TIMEBASE)); pthread_create(&pt1, NULL, Task1, NULL); pthread_create(&pt2, NULL, Task2, NULL); pthread_create(&pt3, NULL, Task3, NULL); pthread_create(&pt4, NULL, Task4, NULL); pthread_create(&pt5, NULL, Task5, NULL); pthread_create(&pt6, NULL, Task6, NULL); pthread_create(&pt7, NULL, Task7, NULL); printf("\ntasks started\n"); pthread_join(pt1, NULL); pthread_join(pt4, NULL); pthread_join(pt7, NULL); endall = 1; rt_tbx_broadcast(bx, (char*)&msg, sizeof(msg)); pthread_join(pt2, NULL); pthread_join(pt3, NULL); pthread_join(pt5, NULL); pthread_join(pt6, NULL); rt_tbx_delete(bx); rt_task_delete(maint); stop_rt_timer(); printf("\n\nEND\n\n"); return 0; }
int __init hello_init(void) { RTIME sampling; rt_printk(KERN_INFO "TESTE - *************************** INICIO *******************************\n"); rt_task_init(&Task_1, signalIchi, 0, 3000, 0, 0, NULL); rt_task_init(&Task_2, signalNi, 0, 3000, 0, 0, NULL); rt_task_init(&Task_3, signalSan, 0, 3000, 0, 0, NULL); sampling = start_rt_timer(nano2count(TICK)); rt_sem_init(&rMutex, 1); rt_task_make_periodic(&Task_1, rt_get_time() + sampling * 16, sampling * 16); rt_task_make_periodic(&Task_2, rt_get_time() + sampling * 18, sampling * 18); rt_task_make_periodic(&Task_3, rt_get_time() + sampling * 30, sampling * 30); rt_change_prio(&Task_1, 2); rt_change_prio(&Task_2, 1); rt_change_prio(&Task_3, 3); rt_printk(KERN_INFO "Init module function\n"); return 0; }
void _rtapi_clock_set_period_hook(long int nsecs, RTIME *counts, RTIME *got_counts) { rt_set_periodic_mode(); *counts = nano2count((RTIME) nsecs); if(count2nano(*counts) > nsecs) (*counts)--; *got_counts = start_rt_timer(*counts); rtapi_data->timer_period = count2nano(*got_counts); }
int init_module(void) { start_rt_timer(0); worst_lat = rt_shm_alloc(nam2num("WSTLAT"), sizeof(RTIME), USE_VMALLOC); task = rt_named_task_init_cpuid("LOOPER", fun, 0, 100000, 0, 1, 0, 1); rt_task_resume(task); return 0; }
int tdma_attach(struct rtnet_device *rtdev, void *priv) { struct rtmac_tdma *tdma = (struct rtmac_tdma *)priv; rt_printk("RTmac: tdma1: init time devision multiple access (tdma) for realtime stations\n"); memset(tdma, 0, sizeof(struct rtmac_tdma)); spin_lock_init(&tdma->delta_t_lock); tdma->rtdev = rtdev; /* * init semas, they implement a producer consumer between the * sending realtime- and the driver-task * */ rt_sem_init(&tdma->client_tx, 0); /* * init tx queue * */ rtskb_prio_queue_init(&tdma->tx_queue); /* * init rt stuff * - timer * - list heads * */ /* generic */ /* master */ init_timer(&tdma->rt_add_timer); INIT_LIST_HEAD(&tdma->rt_add_list); INIT_LIST_HEAD(&tdma->rt_list); INIT_LIST_HEAD(&tdma->rt_list_rate); init_timer(&tdma->task_change_timer); init_timer(&tdma->master_wait_timer); init_timer(&tdma->master_sent_conf_timer); init_timer(&tdma->master_sent_test_timer); rtskb_queue_init(&tdma->master_queue); /* client */ init_timer(&tdma->client_sent_ack_timer); /* * start timer */ rt_set_oneshot_mode(); start_rt_timer(0); return 0; }
int init_module(void) { start_rt_timer(0); rt_task_init(&rtai_sig_task, tsk_sig_fun, 0, STKSZ, 0, 0, 0); rt_task_resume(&rtai_sig_task); rt_task_init(&sig_task, sig_fun, 0, STKSZ, 0, 0, sighdl); rt_task_resume(&sig_task); return 0; }
int init_module(void) { rt_task_init(&parent_task, parent_func, 0, STACK_SIZE, 0, 0, 0); rt_set_oneshot_mode(); period = start_rt_timer((int) nano2count(TICK_PERIOD)); rt_set_runnable_on_cpus(&parent_task, RUN_ON_CPUS); rt_task_resume(&parent_task); return 0; }
int main(void) { pthread_setschedparam_np(0, SCHED_FIFO, 0, 0xF, PTHREAD_HARD_REAL_TIME_NP); start_rt_timer(0); pthread_mutex_init(&m, NULL); pthread_cond_init(&c, NULL); do_test(); return 0; }
int init_module(void) { RTIME period; rt_task_init(&agentask, fun, 0, STACK_SIZE, 0, 0, 0); rt_set_oneshot_mode(); period = start_rt_timer((int) nano2count(TICK_PERIOD)); rt_task_make_periodic(&agentask, rt_get_time() + period, period); return 0; }
int main(void) { double omega = (2.0*M_PI*SIN_FREQ*SAMP_TIME)/1.0E9; RTIME until; RT_TASK *task; lsampl_t data[NCHAN*2]; long k, sinewave, retval = 0; signal(SIGKILL, endme); signal(SIGTERM, endme); start_rt_timer(0); task = rt_task_init_schmod(nam2num("MYTASK"), 1, 0, 0, SCHED_FIFO, 0xF); printf("COMEDI CMD TEST BEGINS: SAMPLING FREQ: %d, RUN TIME: %d.\n", SAMP_FREQ, RUN_TIME); if (init_board()) {; printf("Board initialization failed.\n"); return 1; } do_cmd(); mlockall(MCL_CURRENT | MCL_FUTURE); rt_make_hard_real_time(); until = rt_get_cpu_time_ns() + (long long)RUN_TIME*1000000000; for (k = 0; k < SAMP_FREQ*RUN_TIME && !end; k++) { sinewave = (long)(maxdata/4*sin(k*omega)); data[0] = (lsampl_t)( sinewave + maxdata/2); data[1] = (lsampl_t)(- sinewave + maxdata/2); while (rt_comedi_command_data_write(dev, subdev, NCHAN, data) != NCHAN) { rt_sleep(nano2count(SAMP_TIME/2)); } if (k == TRIGSAMP) { rt_comedi_trigger(dev, subdev); } } while (until > rt_get_cpu_time_ns()) { rt_sleep(nano2count(100000)); } comedi_cancel(dev, subdev); comedi_close(dev); comedi_data_write(dev, subdev, 0, 0, AREF_GROUND, 2048); comedi_data_write(dev, subdev, 1, 0, AREF_GROUND, 2048); printf("COMEDI TEST ENDS.\n"); if (retval < 0) { printf("rt_comedi_wait_timed overruns: %d\n", abs(retval)); } stop_rt_timer(); rt_make_soft_real_time(); rt_task_delete(task); return 0; }
int init_module(void) { unsigned int local_ip; unsigned int server_ip = rt_inet_aton(server_ip_s); struct rtnet_callback callback = {echo_rcv, NULL}; if (strlen(local_ip_s) != 0) local_ip = rt_inet_aton(local_ip_s); else local_ip = INADDR_ANY; if (interval < 1) interval = 1; if (interval > 1000) interval = 1000; if (packetsize < 1) packetsize = 1; if (packetsize > 1400) packetsize = 1400; printk("***** start of rt_client ***** %s %s *****\n", __DATE__, __TIME__); printk("local ip address %s=%08x\n", local_ip_s, local_ip); printk("server ip address %s=%08x\n", server_ip_s, server_ip); printk("interval = %d\n", interval); printk("packetsize = %d\n", packetsize); printk("start timer %d\n", start_timer); rtf_create(PRINT, 8000); /* create rt-socket */ sock = socket_rt(AF_INET,SOCK_DGRAM,0); /* bind the rt-socket to local_addr */ memset(&local_addr, 0, sizeof(struct sockaddr_in)); local_addr.sin_family = AF_INET; local_addr.sin_port = htons(RCV_PORT); local_addr.sin_addr.s_addr = local_ip; bind_rt(sock, (struct sockaddr *)&local_addr, sizeof(struct sockaddr_in)); /* set server-addr */ memset(&server_addr, 0, sizeof(struct sockaddr_in)); server_addr.sin_family = AF_INET; server_addr.sin_port = htons(SRV_PORT); server_addr.sin_addr.s_addr = server_ip; /* set up callback handler */ ioctl_rt(sock, RTNET_RTIOC_CALLBACK, &callback); if (start_timer) { rt_set_oneshot_mode(); start_rt_timer(0); } rt_task_init(&rt_task,(void *)process,0,4096,10,0,NULL); rt_task_make_periodic_relative_ns(&rt_task, 1000000, (RTIME)interval * 1000000); return 0; }
int init_module(void) { printk("TESTING RTDM SEMs [LOOPs %d, TIMEOUTs %d (ns)].\n", LOOPS, DELAY); start_rt_timer(0); rtdm_sem_init(&sem1, 0); rtdm_sem_init(&sem2, 0); rtdm_task_init_cpuid(&stask1, "task1", task1, NULL, 0, 0, 0); rtdm_task_init_cpuid(&stask2, "task2", task2, NULL, 1, 0, 0); return 0; }
static int __latency_init(void) { /* XXX check option ranges here */ /* register a proc entry */ #ifdef CONFIG_PROC_FS create_proc_read_entry("rtai/latency_calibrate", /* name */ 0, /* default mode */ NULL, /* parent dir */ proc_read, /* function */ NULL /* client data */ ); #endif rtf_create(DEBUG_FIFO, 16000); /* create a fifo length: 16000 bytes */ rt_linux_use_fpu(use_fpu); /* declare if we use the FPU */ rt_task_init( /* create our measuring task */ &thread, /* poiter to our RT_TASK */ fun, /* implementation of the task */ 0, /* we could transfer data -> task */ 3000, /* stack size */ 0, /* priority */ use_fpu, /* do we use the FPU? */ 0 /* signal? XXX */ ); rt_set_runnable_on_cpus( /* select on which CPUs the task is */ &thread, /* allowed to run */ RUN_ON_CPUS ); /* Test if we have to start the timer */ if (start_timer || (start_timer = !rt_is_hard_timer_running())) { if (timer_mode) { rt_set_periodic_mode(); } else { rt_set_oneshot_mode(); } rt_assign_irq_to_cpu(TIMER_8254_IRQ, TIMER_TO_CPU); period_counts = start_rt_timer(nano2count(period)); } else { period_counts = nano2count(period); } loops = (1000000000*avrgtime)/period; /* Calculate the start time for the task. */ /* We set this to "now plus 10 periods" */ expected = rt_get_time() + 10 * period_counts; rt_task_make_periodic(&thread, expected, period_counts); return 0; }
int main(void) { int i, indx[NTASKS]; unsigned long mytask_name = nam2num("MASTER"); signal(SIGINT, endme); if (!(mytask = rt_task_init(mytask_name, 1, 0, 0))) { printf("CANNOT INIT TASK %lu\n", mytask_name); exit(1); } printf("MASTER INIT: name = %lu, address = %p.\n", mytask_name, mytask); sem = rt_sem_init(10000, 0); rt_set_oneshot_mode(); // rt_set_periodic_mode(); start_rt_timer(0); for (i = 0; i < ntasks; i++) { indx[i] = i; if (!(task[i] = rt_thread_create(thread_fun, &indx[i], 10000))) { printf("ERROR IN CREATING THREAD %d\n", indx[i]); exit(1); } } for (i = 0; i < ntasks; i++) { while (!rt_get_adr(taskname(i))) { rt_sleep(nano2count(20000000)); } } for (i = 0; i < ntasks; i++) { rt_send(rt_get_adr(taskname(i)), (unsigned long)sem); } for (i = 0; i < ntasks; i++) { rt_sem_wait(sem); } for (i = 0; i < ntasks; i++) { while (rt_get_adr(taskname(i))) { rt_sleep(nano2count(20000000)); } } for (i = 0; i < ntasks; i++) { rt_thread_join(task[i]); } rt_sem_delete(sem); stop_rt_timer(); rt_task_delete(mytask); printf("MASTER %lu %p ENDS\n", mytask_name, mytask); return 0; }