xenomai任务切换测试程序

#include <errno.h>
#include <signal.h>
#include <string.h>
#include <sys/resource.h>
#include <unistd.h>
#include <sys/mman.h>
#include <native/task.h>
#include <native/timer.h>
#define TASK_PRIO  99 /* Highest RT priority */
#define TASK_MODE  0  /* No flags */
#define TASK_STKSZ 0  /* Stack size (use default one) */
RT_TASK task_desc;
static int run=1;
void task_body (void *cookie)
{
    int err;
    int time=0;
    err=rt_task_set_periodic(NULL,TM_NOW,1000000);
    while(run) {
        rt_task_wait_period(NULL);
        time++;
        rt_printf("tims is %d\n",time);
    /* ... "cookie" should be NULL ... */
    }
}
void signal_handler(int sig)
{
        run=0;
}
 
void cleanup ()
{
    rt_task_delete(&task_desc);
}
int main (int argc, char *argv[])
{
    int err,ret;
      rt_print_auto_init(1);
//    printf("start run.\n");
    signal(SIGTERM,signal_handler);
                                                                                        1,1           Top
 
  signal(SIGINT,signal_handler);
    mlockall(MCL_CURRENT|MCL_FUTURE);
    /* ... */
    printf("start!!!!!!\n");
    ret = rt_task_create(&task_desc, "my_task", 0, 80, T_FPU);
    if (ret < 0) {
        fprintf(stderr, "Failed to create task: %s\n", strerror(-ret));
        return -1;
    }
 
    printf("Starting my_task...\n");
    ret = rt_task_start(&task_desc, &task_body, NULL);
    if (ret < 0) {
        fprintf(stderr, "Failed to start task: %s\n", strerror(-ret));
        return -1;
    }
   while(run)
        {
                sched_yield();
        }
    cleanup();
    printf("end\n");
    return 0;
 
}
                                                                                        65,1          Bot
 

转自https://blog.csdn.net/u011123091/article/details/86370204

发布了9 篇原创文章 · 获赞 2 · 访问量 4097

猜你喜欢

转载自blog.csdn.net/qq_27085429/article/details/94593256