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.youkuaiyun.com/u011123091/article/details/86370204

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值