int __init init_module(void) { int err; /* Initialisation du timer */ if (TIMER_PERIODIC) err = rt_timer_set_mode(MS); else err = rt_timer_set_mode(TM_ONESHOT); if (err != 0) { printk("rt-app: %s: Error timer: %d\n", __func__, err); return -1; } /* Initialize FB */ fb_init(); printk("rt-app: Framebuffer initialized\n"); xeno_ts_init(); printk("rt-app: Touchscreen initialized\n"); /* Open Philips controller err = pca9554_open(NULL, NULL); if (err != 0) { printk("rt-app: %s: I2C slave open error: %d\n", __func__, err); goto fail_open; }*/ /* Initializing IRQ */ err = rt_intr_create(&isrDesc, "IMX_I2C", INT_I2C, imx_i2c_handler, NULL, 0); if (err != 0) { printk("rt-app: %s: Error interrupt registration: %d\n", __func__, err); goto fail_intr; } printk("rt-app: ISR initialized\n"); /* To Be Completed */ return space_invader(); //fail_open: // pca9554_close(NULL, NULL); fail_intr: xeno_ts_exit(); return -1; }
//startup code void startup(){ int err = 0; // semaphore to sync task startup on err = rt_sem_create(&mysync,"MySemaphore",1,S_FIFO); if(err < 0) rt_printf("Failed to create semaphore; error: %d: %s", err, strerror(-err)); err = 0; // set timing to ns rt_timer_set_mode(BASEPERIOD); err = rt_task_create(&highP, "high", 0, HIGH, 0); if(err < 0) rt_printf("Failed to create task high; error: %d: %s", err, strerror(-err)); err = 0; err = rt_task_start(&highP, &prioHigh, 0); if(err < 0) rt_printf("Failed to start task high; error: %d: %s", err, strerror(-err)); err = 0; err = rt_task_create(&midP, "mid", 0, MID, 0); if(err < 0) rt_printf("Failed to create task medium; error: %d: %s", err, strerror(-err)); err = 0; err = rt_task_start(&midP, &prioMid, 0); if(err < 0) rt_printf("Failed to start task medium; error: %d: %s", err, strerror(-err)); err = 0; err = rt_task_create(&lowP, "low", 0, LOW, 0); if(err < 0) rt_printf("Failed to create task low; error: %d: %s", err, strerror(-err)); err = 0; err = rt_task_start(&lowP, &prioLow, 0); if(err < 0) rt_printf("Failed to start task low; error: %d: %s", err, strerror(-err)); err = 0; }
//startup code void startup() { int i; char str[10] ; // semaphore to sync task startup on rt_sem_create(&mysync,"MySemaphore",0,S_FIFO); // set timing to ns rt_timer_set_mode(BASEPERIOD); for(i=0; i < NTASKS; i++) { rt_printf("start task : %d\n",i); sprintf(str,"task%d",i); rt_task_create(&demo_task[i], str, 0, 50, 0); rt_task_start(&demo_task[i], &demo, &i); } // assign priorities to tasks // (or in creation use 50+i) rt_task_set_priority(&demo_task[0],LOW); rt_task_set_priority(&demo_task[1],MID); rt_task_set_priority(&demo_task[2],MID); rt_printf("wake up all tasks\n"); rt_sem_broadcast(&mysync); }
void init_xenomai() { /* Avoids memory swapping for this program */ mlockall(MCL_CURRENT|MCL_FUTURE); /* Perform auto-init of rt_print buffers if the task doesn't do so */ rt_print_auto_init(1); rt_timer_set_mode(BASEPERIOD); }
int __init init_module(void) { int err; /* Initialisation du timer */ if (TIMER_PERIODIC) err = rt_timer_set_mode(MS); else err = rt_timer_set_mode(TM_ONESHOT); if (err != 0) { printk("rt-app: %s: Error timer: %d\n", __func__, err); return -1; } /* Initialize FB */ fb_init(); printk("rt-app: Framebuffer initialized\n"); xeno_ts_init(); printk("rt-app: Touchscreen initialized\n"); /* Initializing IRQ */ err = rt_intr_create(&isrDesc, "IMX_I2C", INT_I2C, imx_i2c_handler, NULL, 0); if (err != 0) { printk("rt-app: %s: Error interrupt registration: %d\n", __func__, err); goto fail_intr; } printk("rt-app: ISR initialized\n"); printk("rt-app: i2c driver call\n"); printk("rt_app: i2c driver ok\n"); return space_invader(); fail_intr: xeno_ts_exit(); return -1; }
//startup code void startup(){ int err = 0; // set timing to ns rt_timer_set_mode(BASEPERIOD); err = rt_intr_create(&keypress, NULL, LPT1_IRQ, I_PROPAGATE); if(err < 0) rt_printf("Failed creating interrupt: %d: %s", err, strerror(-err)); err = 0; err = rt_task_create(&taskP, "high", 0, 50, 0); if(err < 0) rt_printf("Failed to create task ; error: %d: %s", err, strerror(-err)); err = 0; err = rt_task_start(&taskP, &task, 0); if(err < 0) rt_printf("Failed to start task; error: %d: %s", err, strerror(-err)); err = 0; }
//startup code void startup() { int i; char str[10] ; void (*task_func[NTASKS]) (void *arg); task_func[0]=taskOne; task_func[1]=taskTwo; rt_queue_create(&myqueue,"myqueue",QUEUE_SIZE,10,Q_FIFO); rt_timer_set_mode(0);// set timer to tick in nanoseconds and not in jiffies for(i=0; i < NTASKS; i++) { rt_printf("start task : %d\n",i); sprintf(str,"task%d",i); rt_task_create(&task_struct[i], str, 0, 50, 0); rt_task_start(&task_struct[i], task_func[i], &i); } }
int RT::OS::initiate(void) { rt_timer_set_mode(TM_ONESHOT); // Kernel limitations on memory lock are no longer present, however // still a useful (for performance) method for preventing paging // of active RTXI memory struct rlimit rlim = { RLIM_INFINITY, RLIM_INFINITY }; setrlimit(RLIMIT_MEMLOCK,&rlim); if (mlockall(MCL_CURRENT | MCL_FUTURE)) { ERROR_MSG("RTOS:Xenomai::initiate : failed to lock memory.\n"); return -EPERM; } pthread_key_create(&is_rt_key,0); init_rt = true; return 0; }
//startup code void startup() { int i; char str[10] ; // semaphore to sync task startup on rt_sem_create(&mysync,"MySemaphore",0,S_FIFO); // change to period mode because round robin does not work // in one shot mode rt_timer_set_mode(BASEPERIOD);// set tick period for(i=0; i < NTASKS; i++) { rt_printf("start task : %d\n",i); sprintf(str,"task%d",i); if(i<NTASKS-1){rt_task_create(&demo_task[i], str, 0, 50, 0);} else{rt_task_create(&demo_task[i],str,0,80,0);} rt_task_start(&demo_task[i], &demo, &i); } rt_printf("wake up all tasks\n"); rt_sem_broadcast(&mysync); }
int root_thread_init (void) { rt_timer_set_mode(1000000); /* Forc 1ms periodic tick. */ rt_task_spawn(&consumer_task, "ConsumerTask", CONSUMER_STACK_SIZE, CONSUMER_TASK_PRI, 0, &consumer, NULL); rt_task_spawn(&producer_task, "ProducerTask", PRODUCER_STACK_SIZE, PRODUCER_TASK_PRI, 0, &producer, NULL); return 0; }
/*!***************************************************************************** ******************************************************************************* \note initXeno \date Oct. 2009 \remarks xenomai specific initializations ******************************************************************************* Function Parameters: [in]=input,[out]=output none ******************************************************************************/ void initXeno(char *task_name) { int rc; struct sigaction sa; // lock all of the pages currently and pages that become // mapped into the address space of the process mlockall(MCL_CURRENT | MCL_FUTURE); sl_rt_mutex_init(&mutex1); //become a real-time process char name[100]; sprintf(name, "x%s_main_%d", task_name, parent_process_id); rt_task_shadow(NULL, name, 0, 0); // what to do when mode switches happen signal(SIGDEBUG, action_upon_switch); // start the non real-time printing library rt_print_auto_init(1); // get the timer info if ((rc=rt_timer_set_mode((RTIME) XENO_CLOCK_PERIOD))) printf("rc_timer_set_mode returned %d\n",rc); // check what we got RT_TIMER_INFO info; rt_timer_inquire(&info); if (info.period == TM_ONESHOT) printf("Timer Period = TM_ONESHOT\n"); else printf("Timer Period = %ld [ns]\n",(long) info.period); }
int RT::OS::initiate(void) { rt_timer_set_mode(TM_ONESHOT); /************************************************************************************** * On some systems like Fedora Core 4 the memory footprint for rtxi exceeds the mlock * * limit allowed by the linux kernel. As root this limit can be removed with a call * * to setrlimit. However, as a non-root user the call to setrlimit will fail. So if * * you aren't root setrlimit will fail, but that is okay if your system is one that * * doesn't need the extra space. * **************************************************************************************/ struct rlimit rlim = { RLIM_INFINITY, RLIM_INFINITY }; setrlimit(RLIMIT_MEMLOCK,&rlim); if (mlockall(MCL_CURRENT | MCL_FUTURE)) { ERROR_MSG("RTOS:Xenomai::initiate : failed to lock memory.\n"); return -EPERM; } pthread_key_create(&is_rt_key,0); init_rt = true; return 0; }
int main(int argc, char **argv) { int err, c; while ((c = getopt(argc, argv, "hp:n:i:")) != EOF) switch (c) { case 'h': /* ./switch --h[istogram] */ do_histogram = 1; break; case 'p': sampling_period = atoi(optarg) * 1000; break; case 'n': nsamples = atoi(optarg); break; case 'i': ignore = atoi(optarg); break; default: fprintf(stderr, "usage: switch [options]\n" "\t-h - enable histogram\n" "\t-p <period_us> - timer period\n" "\t-n <samples> - number of samples to collect\n" "\t-i <samples> - number of _first_ samples to ignore\n"); exit(2); } if (sampling_period == 0) sampling_period = 100000; /* ns */ if (nsamples <= 0) { fprintf(stderr, "disregarding -n <%lld>, using -n <100000> " "samples\n", nsamples); nsamples = 100000; } signal(SIGINT, SIG_IGN); signal(SIGTERM, SIG_IGN); setlinebuf(stdout); mlockall(MCL_CURRENT|MCL_FUTURE); printf("== Sampling period: %llu us\n", sampling_period / 1000); printf("== Do not interrupt this program\n"); rt_timer_set_mode(TM_ONESHOT); /* Force aperiodic timing. */ err = rt_task_create(&worker_task, "worker", 0, 98, T_FPU); if (err) { fprintf(stderr,"switch: failed to create worker task, code %d\n", err); return 1; } err = rt_task_start(&worker_task, &worker, NULL); if (err) { fprintf(stderr,"switch: failed to start worker task, code %d\n", err); return 1; } err = rt_task_create(&event_task, "event", 0, 99, 0); if (err) { fprintf(stderr,"switch: failed to create event task, code %d\n", err); return 1; } err = rt_task_start(&event_task, &event, NULL); if (err) { fprintf(stderr,"switch: failed to start event task, code %d\n", err); return 1; } pause(); return 0; }
int main(int argc, char **argv) { int cpu = 0, c, err, sig; struct sigaction sa; char task_name[16]; sigset_t mask; while ((c = getopt(argc, argv, "g:hp:l:T:qH:B:sD:t:fc:P:b")) != EOF) switch (c) { case 'g': do_gnuplot = strdup(optarg); break; case 'h': do_histogram = 1; break; case 's': do_stats = 1; break; case 'H': histogram_size = atoi(optarg); break; case 'B': bucketsize = atoi(optarg); break; case 'p': period_ns = atoi(optarg) * 1000LL; break; case 'l': data_lines = atoi(optarg); break; case 'T': test_duration = atoi(optarg); alarm(test_duration + WARMUP_TIME); break; case 'q': quiet = 1; break; case 'D': benchdev_no = atoi(optarg); break; case 't': test_mode = atoi(optarg); break; case 'f': freeze_max = 1; break; case 'c': cpu = T_CPU(atoi(optarg)); break; case 'P': priority = atoi(optarg); break; case 'b': stop_upon_switch = 1; break; default: fprintf(stderr, "usage: latency [options]\n" " [-h] # print histograms of min, avg, max latencies\n" " [-g <file>] # dump histogram to <file> in gnuplot format\n" " [-s] # print statistics of min, avg, max latencies\n" " [-H <histogram-size>] # default = 200, increase if your last bucket is full\n" " [-B <bucket-size>] # default = 1000ns, decrease for more resolution\n" " [-p <period_us>] # sampling period\n" " [-l <data-lines per header>] # default=21, 0 to supress headers\n" " [-T <test_duration_seconds>] # default=0, so ^C to end\n" " [-q] # supresses RTD, RTH lines if -T is used\n" " [-D <testing_device_no>] # number of testing device, default=0\n" " [-t <test_mode>] # 0=user task (default), 1=kernel task, 2=timer IRQ\n" " [-f] # freeze trace for each new max latency\n" " [-c <cpu>] # pin measuring task down to given CPU\n" " [-P <priority>] # task priority (test mode 0 and 1 only)\n" " [-b] # break upon mode switch\n" ); exit(2); } if (!test_duration && quiet) { fprintf(stderr, "latency: -q only works if -T has been given.\n"); quiet = 0; } if ((test_mode < USER_TASK) || (test_mode > TIMER_HANDLER)) { fprintf(stderr, "latency: invalid test mode.\n"); exit(2); } time(&test_start); histogram_avg = calloc(histogram_size, sizeof(long)); histogram_max = calloc(histogram_size, sizeof(long)); histogram_min = calloc(histogram_size, sizeof(long)); if (!(histogram_avg && histogram_max && histogram_min)) cleanup(); if (period_ns == 0) period_ns = CONFIG_XENO_DEFAULT_PERIOD; /* ns */ if (priority <= T_LOPRIO) priority = T_LOPRIO + 1; else if (priority > T_HIPRIO) priority = T_HIPRIO; sigemptyset(&mask); sigaddset(&mask, SIGINT); sigaddset(&mask, SIGTERM); sigaddset(&mask, SIGHUP); sigaddset(&mask, SIGALRM); pthread_sigmask(SIG_BLOCK, &mask, NULL); sigemptyset(&sa.sa_mask); sa.sa_sigaction = sigdebug; sa.sa_flags = SA_SIGINFO; sigaction(SIGDEBUG, &sa, NULL); if (freeze_max) { /* If something goes wrong, we want to freeze the current trace path to help debugging. */ signal(SIGSEGV, faulthand); signal(SIGBUS, faulthand); } setlinebuf(stdout); printf("== Sampling period: %Ld us\n" "== Test mode: %s\n" "== All results in microseconds\n", period_ns / 1000, test_mode_names[test_mode]); mlockall(MCL_CURRENT | MCL_FUTURE); if (test_mode != USER_TASK) { char devname[RTDM_MAX_DEVNAME_LEN]; snprintf(devname, RTDM_MAX_DEVNAME_LEN, "rttest-timerbench%d", benchdev_no); benchdev = rt_dev_open(devname, O_RDWR); if (benchdev < 0) { fprintf(stderr, "latency: failed to open benchmark device, code %d\n" "(modprobe RTAI_timerbench?)\n", benchdev); return 0; } } rt_timer_set_mode(TM_ONESHOT); /* Force aperiodic timing. */ snprintf(task_name, sizeof(task_name), "display-%d", getpid()); err = rt_task_create(&display_task, task_name, 0, 0, T_FPU); if (err) { fprintf(stderr, "latency: failed to create display task, code %d\n", err); return 0; } err = rt_task_start(&display_task, &display, NULL); if (err) { fprintf(stderr, "latency: failed to start display task, code %d\n", err); return 0; } if (test_mode == USER_TASK) { snprintf(task_name, sizeof(task_name), "sampling-%d", getpid()); err = rt_task_create(&latency_task, task_name, 0, priority, T_FPU | cpu | T_WARNSW); if (err) { fprintf(stderr, "latency: failed to create latency task, code %d\n", err); return 0; } err = rt_task_start(&latency_task, &latency, NULL); if (err) { fprintf(stderr, "latency: failed to start latency task, code %d\n", err); return 0; } } sigwait(&mask, &sig); finished = 1; cleanup(); return 0; }