本文整理汇总了C++中rt_task_create函数的典型用法代码示例。如果您正苦于以下问题:C++ rt_task_create函数的具体用法?C++ rt_task_create怎么用?C++ rt_task_create使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rt_task_create函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char* argv[])
{
// Perform auto-init of rt_print buffers if the task doesn't do so
rt_print_auto_init(1);
// Lock memory : avoid memory swapping for this program
mlockall(MCL_CURRENT|MCL_FUTURE);
rt_printf("starting tasks\n");
int res = rt_sem_create(&semGlobal, "a", 0, S_PRIO);
if(res < 0) rt_printf("Failed to create semaphore; error: %d: %s", res, strerror(-res));
rt_task_create(&task1, "t1", 0, 10, 0);
rt_task_create(&task2, "t2", 0, 20, 0);
rt_task_create(&task3, "t3", 0, 30, 0);
rt_task_create(&task4, "t4", 0, 40, 0);
rt_task_create(&task5, "t5", 0, 50, 0);
int a1 = 1;
int a2 = 2;
int a3 = 3;
int a4 = 4;
int a5 = 5;
rt_task_start(&task1, &task, &a1);
rt_task_start(&task2, &task, &a2);
rt_task_start(&task3, &task, &a3);
rt_task_start(&task4, &task, &a4);
rt_task_start(&task5, &task, &a5);
rt_sem_broadcast(&semGlobal);
}
示例2: main
int main(int argc, char* argv[])
{
signal(SIGTERM, catch_signal);
//signal(SIGINT, catch_signal);
int statusA, statusG, statusF, mutexacc, mutexgyro, i,j;
logIndex = 0;
// enable rt_task_print
rt_print_auto_init(1);
/* Avoids memory swapping for this program */
mlockall(MCL_CURRENT|MCL_FUTURE);
// Create mutexs
mutexgyro = rt_mutex_create(&mutex_gyro,NULL);
if(mutexgyro!=0){
fprintf(stderr, "Unable to create gyroscope mutex! Exiting...\n");
exit(EXIT_FAILURE);
}
mutexacc = rt_mutex_create(&mutex_acc,NULL);
if(mutexacc!=0){
fprintf(stderr, "Unable to create accelorometer mutex! Exiting...\n");
exit(EXIT_FAILURE);
}
isRunning = 1;
/*
* Arguments: &task, name, stack size (0=default), priority,
* mode (FPU, start suspended, ...)
*/
statusA = rt_task_create(&accThread, NULL, 0, 0, T_JOINABLE);
statusG = rt_task_create(&gyroThread, NULL, 0, 0, T_JOINABLE);
statusF = rt_task_create(&fusThread, NULL, 0, 0, T_JOINABLE);
/*
* Arguments: &task, task function, function argument
*/
statusA = rt_task_start(&accThread, &accelerometer, NULL);
statusG = rt_task_start(&gyroThread, &gyroscope, NULL);
statusF = rt_task_start(&fusThread, &sensor_fusion, NULL);
// threads in infinite loop, therefore this prevents the main from finishing
// (and killing its threads)
statusA = rt_task_join(&gyroThread);
statusF = rt_task_join(&fusThread);
statusG = rt_task_join(&accThread);
printlog[logIndex] = 4000;
for (i = 0; i < 50; i++) {
printf("Fusion%d: %d\n", i, printlog[i]);
}
rt_mutex_delete(&mutex_acc);
rt_mutex_delete(&mutex_gyro);
}
示例3: main
int main(){
rt_print_auto_init(1);
mlockall(MCL_CURRENT|MCL_FUTURE);
rt_task_shadow(NULL, "main", 5, T_CPU(0)|T_JOINABLE);
#ifdef mutex
rt_mutex_create(&a, "Mutex");
rt_mutex_create(&b, "b");
#endif
rt_task_create(&task1, "Task1", 0, 1, T_CPU(0)|T_JOINABLE);
rt_task_create(&task2, "Task2", 0, 2, T_CPU(0)|T_JOINABLE);
rt_task_start(&task1, &semWait1, NULL);
rt_task_start(&task2, &semWait2, NULL);
rt_printf("sync \n");
rt_task_join(&task1);
rt_task_join(&task2);
#ifdef mutex
rt_mutex_delete(&a);
rt_mutex_delete(&b);
#endif
}
示例4: startup
void startup(){
rt_queue_create(&rqueue, "rQueue", QUEUE_SIZE, 40, Q_FIFO);
rt_queue_create(&lqueue, "lQueue", QUEUE_SIZE, 40, Q_FIFO);
//rt_sem_create(&rsem, "rsem", 0, S_FIFO);
//&task, name, stack size (0 - default), priority, mode
rt_task_create(&rEnc_task, "rEnc Task", 0, 50, 0);
//&task, task function, function argument
rt_task_start(&rEnc_task, &rEnc, 0);
//&task, name, stack size (0 - default), priority, mode
rt_task_create(&lEnc_task, "lEnc Task", 0, 50, 0);
//&task, task function, function argument
rt_task_start(&lEnc_task, &lEnc, 0);
//&task, name, stack size (0 - default), priority, mode
rt_task_create(&Odo_task, "Odo Task", 0, 60, 0);
//&task, task function, function argument
rt_task_start(&Odo_task, &Odo, 0);
//rt_sem_broadcast(&rsem);
}
示例5: startup
//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;
}
示例6: main
int main(int argc, char *const argv[])
{
int ret;
traceobj_init(&trobj, argv[0], 0);
ret = rt_sem_create(&sem, "SEMA", 0, S_FIFO);
traceobj_check(&trobj, ret, 0);
ret = rt_task_create(&t_rr1, "rr_task_1", 0, 10, 0);
traceobj_check(&trobj, ret, 0);
ret = rt_task_start(&t_rr1, rr_task, "t1");
traceobj_check(&trobj, ret, 0);
ret = rt_task_create(&t_rr2, "rr_task_2", 0, 10, 0);
traceobj_check(&trobj, ret, 0);
ret = rt_task_start(&t_rr2, rr_task, "t2");
traceobj_check(&trobj, ret, 0);
ret = rt_sem_broadcast(&sem);
traceobj_check(&trobj, ret, 0);
traceobj_join(&trobj);
exit(0);
}
示例7: startup
//startup code
void startup()
{
rt_intr_create(&keypress, NULL, KEYBOARD_IRQ, I_PROPAGATE);
rt_task_create(&key_isr, NULL,0,50,0);
rt_task_start(&key_isr, &key_handler, NULL);
// Higher priority
rt_task_create(&dummy, NULL,0,53,0);
rt_task_start(&dummy, &dummy_task, NULL);
}
示例8: mlockall
ECRTData::ECRTData() {
mlockall(MCL_CURRENT|MCL_FUTURE);
rt_mutex_create(&(this->mutex), NULL);
rt_mutex_create(&(this->mutexBuffer), NULL);
rt_cond_create(&(this->freeCond), NULL);
rt_task_create(&(this->ecThread), NULL, 0, 99, T_JOINABLE);
rt_task_create(&(this->frThread), NULL, 0, 99, T_JOINABLE);
rt_task_create(&(this->statusThread), NULL, 0, 99, T_JOINABLE);
rt_task_create(&(this->supervisorThread), NULL, 0, 99, T_JOINABLE);
}
示例9: startup
void startup(){
// rt_task_create(&rMotor_task, "rMotor Task", 0, 50, 0);
// rt_task_create(&lMotor_task, "lMotor Task", 0, 50, 0);
//rt_task_create(&rMotor_stop_task, "rMotor Stop Task", 0, 51, 0);
//rt_task_create(&lMotor_stop_task, "lMotor Stop Task", 0, 51, 0);
rt_task_create(&rMotor_task, "rMotor Task", 0, 50, 0);
rt_task_create(&lMotor_task, "lMotor Task", 0, 50, 0);
// rt_task_start(&rMotor_stop_task, &rMotor_stop, 0);
//rt_task_start(&lMotor_stop_task, &lMotor_stop, 0);
rt_task_start(&rMotor_task, &rMotor, 0);
rt_task_start(&lMotor_task, &lMotor, 0);
}
示例10: startup
//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);
}
示例11: main
int main(int argc, char **argv) {
char task_name[TASKS][16];
RT_TASK task[TASKS];
rt_print_auto_init(1);
mlockall(MCL_CURRENT|MCL_FUTURE);
for(int i = 0; i < TASKS; i++) {
snprintf(task_name[i], 16, "Lab5Task-%d", i);
if (rt_task_create(&task[i], task_name[i], 0, 50 - (i*2), T_JOINABLE) != 0) {
exit(-1);
}
}
for (int i = 0; i < TASKS; i++) {
rt_printf("Starting task %s\n", task_name[i]);
rt_task_start(&task[i], &task_body, NULL);
}
rt_printf("All tasks started\n");
for(int i = 0; i < TASKS; i++) {
rt_task_join(&task[i]);
}
rt_printf("All tasks stopped, shared_resource = %d\n", shared_resource);
}
示例12: rt_task_create
int rt_task_create(RT_TASK *task, const char *name,
int stksize, int prio, int mode)
{
int ret, susp, cpus, cpu;
cpu_set_t cpuset;
susp = mode & T_SUSP;
cpus = mode & T_CPUMASK;
ret = __CURRENT(rt_task_create(task, name, stksize, prio,
mode & ~(T_SUSP|T_CPUMASK|T_LOCK)));
if (ret)
return ret;
if (cpus) {
CPU_ZERO(&cpuset);
for (cpu = 0, cpus >>= 24;
cpus && cpu < 8; cpu++, cpus >>= 1) {
if (cpus & 1)
CPU_SET(cpu, &cpuset);
}
ret = rt_task_set_affinity(task, &cpuset);
if (ret) {
rt_task_delete(task);
return ret;
}
}
return susp ? rt_task_suspend(task) : 0;
}
示例13: main
int main (int argc, char *argv[])
{
static char *messages[] = { "hello", "world", NULL };
int n, len;
void *msg;
mlockall(MCL_CURRENT|MCL_FUTURE);
err = rt_task_create(&task_desc,
"MyTaskName",
TASK_STKSZ,
TASK_PRIO,
TASK_MODE);
if (!err)
rt_task_start(&task_desc,&task_body,NULL);
/* ... */
for (n = 0; messages[n] != NULL; n++)
{
len = strlen(messages[n]) + 1;
/* Get a message block of the right size. */
msg = rt_queue_alloc(&q_desc,len);
if (!msg)
/* No memory available. */
fail();
strcpy(msg,messages[n]);
rt_queue_send(&q_desc,msg,len,Q_NORMAL);
}
rt_task_delete(&task_desc);
}
示例14: mlockall
RealtimeController::RealtimeController()
{
// lukitaan ohjelman nykyinen ja tuleva muisti niin että se pysyy RAM:ssa kokoajan
mlockall(MCL_CURRENT | MCL_FUTURE);
int xenoError = 0;
// luodaan task-handle reaaliaikasäikeelle
// antamalla T_FPU | T_JOINABLE saattaisi olla mahdollista käyttää
// mittausarvoja doubleina Voltteina koko ohjelmassa
xenoError = rt_task_create(&task_desc, NULL, 0, 99, T_JOINABLE);
xenoError = rt_pipe_create(&pipe_desc, NULL, 0, 0);
if(xenoError != 0)
qDebug("rt init error");
// käynnistetään säie
rt_task_start(&task_desc, &realtimeLoop, NULL);
// luodaan pipe reaaliaikasäikeen kanssa kommunikointiin
pipefd = open("/dev/rtp0", O_RDWR, 0);
if (pipefd < 0)
qDebug("Creating pipe failed");
// pysäytetään säätö oletuksena
stop();
}
示例15: sigemptyset
int RT::OS::createTask(RT::OS::Task *task,void *(*entry)(void *),void *arg,int prio) {
int retval = 0;
xenomai_task_t *t = new xenomai_task_t;
int priority = 99;
#ifdef DEBUG_RT
struct sigaction sa;
sigemptyset(&sa.sa_mask);
sa.sa_sigaction = rt_switch_warning;
sa.sa_flags = SA_SIGINFO;
sigaction(SIGDEBUG, &sa, NULL);
#endif
// Invert priority, default prio=0 but max priority for xenomai task is 99
if ((prio >=0) && (prio <=99))
priority -= prio;
if ((retval = rt_task_create(&t->task,"RTXI RT Thread",0,priority,T_FPU|T_JOINABLE))) {
ERROR_MSG("RT::OS::createTask : failed to create task\n");
return retval;
}
t->period = -1;
*task = t;
pthread_setspecific(is_rt_key,reinterpret_cast<const void *>(t));
if ((retval = rt_task_start(&t->task,reinterpret_cast<void(*)(void *)>(entry),arg))) {
ERROR_MSG("RT::OS::createTask : failed to start task\n");
return retval;
}
return 0;
}