本文整理汇总了C++中rt_task_init_schmod函数的典型用法代码示例。如果您正苦于以下问题:C++ rt_task_init_schmod函数的具体用法?C++ rt_task_init_schmod怎么用?C++ rt_task_init_schmod使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rt_task_init_schmod函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sizeof
static void *async_fun(void *args)
{
RT_TASK *asynctsk;
if (!(asynctsk = rt_task_init_schmod(nam2num("ASYTSK"), 2, 0, 0, SCHED_FIFO, 0xF))) {
printf("CANNOT INIT ASYNC TASK\n");
exit(1);
}
mlockall(MCL_CURRENT | MCL_FUTURE);
while (!end) {
if (SERVER) {
unsigned long long retval;
long i1, i2;
int l1, l2;
l1 = l2 = sizeof(long);
rt_get_net_rpc_ret(mbx, &retval, &i1, &l1, &i2, &l2, 0LL, MBX_RECEIVE);
printf("SERVER ASYNC MSG: RETVAL = %llu, MSG = %ld, LEN = %d.\n", retval, i1, l1);
if (i1 < 0) {
end = 1;
break;
}
} else {
rt_sleep(nano2count(100000000));
}
}
rt_task_delete(asynctsk);
printf("\nASYNC SERVER TASK STOPS\n");
return (void *)0;
}
示例2: main
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;
}
示例3: main
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);
}
示例4: rt_task_init_schmod
void *thread_fun(void *arg)
{
funtask = rt_task_init_schmod(0xcaccb, 0, 0, 0, SCHED_FIFO, 0x1);
rt_printk("FUN INIT\n");
mlockall(MCL_CURRENT | MCL_FUTURE);
rt_make_hard_real_time();
if (!SNDBRCV) {
rt_sleep(nano2count(100000000));
}
if (USE_RPC) {
unsigned long msg;
rt_printk("FUN RPC\n");
rt_rpc(maintask, 0, &msg);
} else {
rt_printk("FUN SEND\n");
rt_send(maintask, 0);
rt_printk("FUN SUSP\n");
rt_task_suspend(funtask);
}
rt_printk("FUN DONE\n");
rt_task_delete(funtask);
rt_printk("FUN END\n");
return 0;
}
示例5: nam2num
void *init_task_1(void *arg)
{
unsigned long Task_1_name = nam2num("TASK_1");
//TODO:RAWLINSON
if(!(Task_1 = rt_task_init_schmod(Task_1_name,1,0,0,SCHED_FIFO, CPU_ALLOWED))) {
printf("[ERRO] Não foi possível criar a tarefa 1.\n");
exit(1);
}
rt_allow_nonroot_hrt();
rt_make_hard_real_time();
rt_task_make_periodic(Task_1, rt_get_time() + sampling * 5, sampling * 10);
while (1) {
time(&aclock); // Pega tempo em segundos.
newtime = localtime(&aclock);
printf("[TASK 1] =======> %s", asctime(newtime));
rt_task_wait_period();
}
}
示例6: realtime_on
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;
}
示例7: pthread_setcanceltype
static void *logMsg_fun(void *args)
{
RT_TASK *buddy;
struct { int nch; FILE *fs; } type;
char msg[MAX_MSG_SIZE];
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
if (!(buddy = rt_task_init_schmod(nam2num("LOGSRV"), 1, 0, 0, SCHED_FIFO, 0xFFFFFFFF))) {
printf("CANNOT INIT LOG MSG SERVER BUDDY TASK %p.\n", buddy);
return (void *)1;
}
rt_send(*(RT_TASK **)args, (unsigned int)buddy);
while (1) {
if (!rt_mbx_receive(logmbx, &type, sizeof(type)) && !rt_mbx_receive(logmbx, msg, type.nch)) {
if (type.fs) {
fprintf(type.fs, msg);
} else {
fprintf(stderr, msg);
fprintf(logfile, msg);
}
} else {
while(!rt_mbx_receive_wp(logmbx, msg, MAX_MSG_SIZE));
}
}
return (void *)0;
}
示例8: writing_task_proc
//----------------------------------------------------------------------------
// real time task
void writing_task_proc(void *arg)
{
#ifdef RTAI
writing_task = rt_task_init_schmod(nam2num("WRTSK"),2, 0, 0,
SCHED_FIFO, 0xF);
rt_make_hard_real_time();
#endif
while (1) {
std::list<TPCANMsg>::iterator iter;
for (iter = List->begin(); iter != List->end(); iter++) {
// test for standard frames only
if ((nExtended == CAN_INIT_TYPE_EX) ||
!(iter->MSGTYPE & MSGTYPE_EXTENDED)) {
// send the message
if ((errno = CAN_Write(h, &(*iter))))
shutdownnow = 1;
}
if (shutdownnow == 1)
break;
}
if (shutdownnow == 1)
break;
}
#ifdef RTAI
rt_make_soft_real_time();
rt_task_delete(writing_task);
#endif
}
示例9: main
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;
}
示例10: main
int main(int argc, char *argv[])
{
unsigned int player, msg, spknode, spkport, i;
RT_TASK *plrtsk, *spktsk;
struct sockaddr_in addr;
char data[BUFSIZE];
thread = rt_thread_create(endme, NULL, 2000);
if ((player = open("../../../share/linux.au", O_RDONLY)) < 0) {
printf("ERROR OPENING SOUND FILE (linux.au)\n");
exit(1);
}
if (!(plrtsk = rt_task_init_schmod(nam2num("PLRTSK"), 2, 0, 0, SCHED_FIFO, 0xF))) {
printf("CANNOT INIT PLAYER TASK\n");
exit(1);
}
spknode = 0;
if (argc == 2 && strstr(argv[1], "SpkNode=")) {
inet_aton(argv[1] + 8, &addr.sin_addr);
spknode = addr.sin_addr.s_addr;
}
if (!spknode) {
inet_aton("127.0.0.1", &addr.sin_addr);
spknode = addr.sin_addr.s_addr;
}
while ((spkport = rt_request_hard_port(spknode)) <= 0 && spkport != -EINVAL);
rt_make_hard_real_time();
spktsk = RT_get_adr(spknode, spkport, "SPKTSK");
RT_rpcx(spknode, spkport, spktsk, &i, &msg, sizeof(int), sizeof(int));
for (i = 0; i < 100; i++) {
RT_rpcx(spknode, spkport, spktsk, &i, &msg, sizeof(int), sizeof(int));
}
mlockall(MCL_CURRENT | MCL_FUTURE);
printf("\nPLAYER TASK RUNNING\n(TYPE ENTER TO END EVERYTHING)\n");
while (!end) {
lseek(player, 0, SEEK_SET);
while(!end && (i = read(player, data, BUFSIZE)) > 0) {
RT_rpcx(spknode, spkport, spktsk, data, &msg, i, sizeof(int));
if (msg != i) {
printf("SPEAKER RECEIVED LESS THAN SENT BY PLAYER\n");
}
}
}
msg = 0xFFFFFFFF;
RT_rpcx(spknode, spkport, spktsk, &msg, &msg, sizeof(int), 1);
rt_make_soft_real_time();
rt_release_port(spknode, spkport);
rt_task_delete(plrtsk);
close(player);
printf("PLAYER TASK STOPS\n");
return 0;
}
示例11: main
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;
}
示例12: taskname
void *thread_fun(void *arg)
{
RTIME start_time, period;
RTIME t0, t;
SEM *sem;
RT_TASK *mytask;
unsigned long mytask_name;
int mytask_indx, jit, maxj, maxjp, count;
mytask_indx = *((int *)arg);
mytask_name = taskname(mytask_indx);
cpus_allowed = 1 - cpus_allowed;
if (!(mytask = rt_task_init_schmod(mytask_name, 1, 0, 0, SCHED_FIFO, 1 << cpus_allowed))) {
printf("CANNOT INIT TASK %lu\n", mytask_name);
exit(1);
}
printf("THREAD INIT: index = %d, name = %lu, address = %p.\n", mytask_indx, mytask_name, mytask);
mlockall(MCL_CURRENT | MCL_FUTURE);
if (!(mytask_indx%2)) {
rt_make_hard_real_time();
}
rt_receive(0, (unsigned long *)((void *)&sem));
period = nano2count(PERIOD);
start_time = rt_get_time() + nano2count(10000000);
rt_task_make_periodic(mytask, start_time + (mytask_indx + 1)*period, ntasks*period);
// start of task body
{
count = maxj = 0;
t0 = rt_get_cpu_time_ns();
while(count++ < LOOPS) {
rt_task_wait_period();
t = rt_get_cpu_time_ns();
if ((jit = t - t0 - ntasks*(RTIME)PERIOD) < 0) {
jit = -jit;
}
if (count > 1 && jit > maxj) {
maxj = jit;
}
t0 = t;
// rtai_print_to_screen("THREAD: index = %d, count %d\n", mytask_indx, count);
}
maxjp = (maxj + 499)/1000;
}
// end of task body
rt_sem_signal(sem);
if (!(mytask_indx%2)) {
rt_make_soft_real_time();
}
rt_task_delete(mytask);
printf("THREAD %lu ENDS, LOOPS: %d MAX JIT: %d (us)\n", mytask_name, count, maxjp);
return 0;
}
示例13: init
int init()
{
mlockall(MCL_CURRENT | MCL_FUTURE);
/* Initialize LXRT */
#ifdef RTAI
maint = rt_task_init_schmod(nam2num("MAINT"), 3, 0, 0,
SCHED_FIFO, 0xF);
#endif
}
示例14: netlink_send
void *tx_thread(void *arg)
{
int fd=*((int*)arg);
RT_TASK *task;
int ret;
int i;
char dummy_data[10];
if (fd > 0) {
ret = netlink_send(fd,NLCMD_INIT,10,&dummy_data[0]);
printf("tx_thread starting, fd %d\n",fd);
task = rt_task_init_schmod(nam2num("TASK1"), 0, 0, 0, SCHED_FIFO, 0xF);
mlockall(MCL_CURRENT | MCL_FUTURE);
// rt_make_hard_real_time();
while (!oai_exit) {
if (tx_sdu_active == 1)
printf("tx_thread: waiting (MBOX %d)\n",((unsigned int*)DAQ_MBOX)[0]);
while(((volatile int)tx_sdu_active) != 0) {
rt_sleep(nano2count(66666));
}
printf("tx_thread: calling netlink\n");
ret = netlink_recv(fd,rxsdu);
tx_sdu_active = 1;
tx_sdu_length = ret;
/*
if (ret > 0) {
printf("received TX SDU: ");
for (i=0;i<ret;i++) {
printf("%02hhx ",rxsdu[i]);
}
printf("\n");
}
*/
}
} else {
printf("tx_thread: no netlink\n");
}
printf("tx_thread exiting\n");
return(0);
}
示例15: main
int main(int argc, char *argv[])
{
unsigned long msg;
int prio, bprio;
if (argc > 1) {
USE_RPC = atoi(argv[1]);
SNDBRCV = atoi(argv[2]);
HARDMAIN = atoi(argv[3]);
}
if (!(maintask = rt_task_init_schmod(0xcacca, 1, 0, 0, SCHED_FIFO, 0x1))) {
rt_printk("CANNOT INIT MAIN\n");
exit(1);
}
start_rt_timer(0);
rt_printk("MAIN INIT\n");
pthread_create(&thread, NULL, thread_fun, NULL);
mlockall(MCL_CURRENT | MCL_FUTURE);
if (HARDMAIN) {
rt_make_hard_real_time();
}
rt_get_priorities(maintask, &prio, &bprio);
rt_printk("TEST: %s, %s, %d\n", USE_RPC ? "WITH RPC" : "WITH SUSP/RESM", SNDBRCV ? "SEND BEFORE RECEIVE" : "RECEIVE BEFORE SEND", prio);
if (SNDBRCV) {
rt_sleep(nano2count(100000000));
}
rt_get_priorities(maintask, &prio, &bprio);
rt_printk("MAIN REC %d\n", prio);
if (USE_RPC) {
RT_TASK *task;
task = rt_receive(0, &msg);
rt_get_priorities(maintask, &prio, &bprio);
rt_printk("MAIN RET %d\n", prio);
rt_return(task, 0);
} else {
rt_receive(0, &msg);
rt_get_priorities(maintask, &prio, &bprio);
rt_printk("MAIN RES %d\n", prio);
rt_task_resume(funtask);
}
rt_get_priorities(maintask, &prio, &bprio);
rt_printk("MAIN DONE %d\n", prio);
stop_rt_timer();
rt_task_delete(maintask);
rt_printk("MAIN END\n");
return 0;
}