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; }
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 init_module(void) { int i; #ifdef ONE_SHOT rt_set_oneshot_mode(); #endif rt_task_init(&thread[0], driver, 0, STACK_SIZE, 0, 0, 0); for (i = 1; i < NTASKS; i++) { rt_task_init(&thread[i], fun, i, STACK_SIZE, 0, 0, 0); } tick_period = start_rt_timer(nano2count(TICK_PERIOD)); rt_assign_irq_to_cpu(TIMER_8254_IRQ, TIMER_TO_CPU); for (i = 0; i < NTASKS; i++) { rt_task_resume(&thread[i]); } for (i = 0; i < NTASKS; i++) { rt_set_runnable_on_cpus(&thread[i], RUN_ON_CPUS); } return 0; }
void parent_func(int arg) { int i; int my_oflags = 0; int n = 0; struct mq_attr my_attrs ={0,0,0,0}; mode_t my_mode = 0; struct Msg { const char *str; int str_size; uint prio; }; static const char str1[23] = "Test string number one\0"; static const char str2[28] = "This is test string num 2!!\0"; static const char str3[22] = "Test string number 3!\0"; static const char str4[34] = "This is test string number four!!\0"; uint nMsgs = 4; static const struct Msg myMsgs[4] = { {str1, 23, 5}, {str2, 28, 1}, {str3, 22, 6}, {str4, 34, 7}, }; #ifdef STEP_TRACE //Wait for the debugger to say GO! while(!zdbg) { rt_task_wait_period(); } #endif rt_printk("Starting parent task %d\n", arg); for(i = 0; i < 5; i++) { rt_printk("parent task %d, loop count %d\n", arg, i); } //Create my queue my_oflags = (O_RDWR | O_CREAT | O_NONBLOCK); my_mode = (S_IRUSR | S_IWUSR | S_IRGRP); my_attrs.mq_maxmsg = 10; my_attrs.mq_msgsize = 50; //Create a pQueue for comms with child my_q = mq_open("my_queue", my_oflags, my_mode, &my_attrs); if (my_q > 0) { rt_printk("Putting %d messages on queue\n", nMsgs); for (i = 0; i < nMsgs; i++) { //Put messages on the queue rt_printk("Sending: %s\n", myMsgs[i].str); n = mq_send(my_q, myMsgs[i].str, myMsgs[i].str_size, myMsgs[i].prio); rt_printk("Parent put message 1 of %d bytes on queue at priority %d\n", n, myMsgs[i].prio); } } else { rt_printk("ERROR: could not create my_queue\n"); } mq_close(my_q); rt_task_init(&child_task, child_func, 2, STACK_SIZE, CHILD_PRIORITY, 1, 0); init_z_apps(&child_task); rt_set_runnable_on_cpus(&child_task, RUN_ON_CPUS); rt_task_resume(&child_task); free_z_apps(rt_whoami()); rt_task_delete(rt_whoami()); }