How to create and compile a Xenomai helloworld program
来源:互联网 发布:淘宝网柒牌男装 编辑:程序博客网 时间:2024/04/29 05:56
How to create and compile a Xenomai helloworldprogram
Contents
一、create a task.2
二、start a task.2
三、helloworld.2
四、编译执行...4
1> xeno-config --xeno-cflags.4
2> xeno-config --xeno-ldflags.4
3>设置flags环境变量有效...4
4>编译...4
5>声明动态库环境变量...4
6>执行程序...5
说明:如何编译调用了xenomai API的程序,可以参考此文档。
一、createa task
创建任务使用 int rt_task_create()函数(参考API手册更详细,native api)
int rt_task_create (RT_TASK *task, const char *name, intstack_size, int priority, int mode)
*task,指向RT_TASK类型。在创建任务之前,一定要事先声明好。用来存储实时任务需要的数据。
name任务的符号名称。
stack_size 为任务分配的堆栈大小。如果设置为0,会使用预定义的默认设置。
priority优先级。最高99,最低0
mode 模式。
二、starta task
int rt_task_start (RT_TASK *task, void(*task_func)(void*arg), void *arg)
task就是指rt_task_create()里创建的任务
task_func 任务要执行的功能函数,比如helloworld程序,就是这个功能函数里输出helloworld的。
arg参数。空指针参数。
三、helloworld
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include <sys/mman.h>
#include <native/task.h>
#include <native/timer.h>
#include <rtdk.h>
RT_TASK demo_task;
void demo(void *arg) //task function,任务要执行的函数功能
{
RT_TASK *curtask;
RT_TASK_INFO curtaskinfo;
// hello world
rt_printf("Hello World!\n");
// inquire current task
curtask=rt_task_self();
rt_task_inquire(curtask,&curtaskinfo);
// print task name
rt_printf("Task name : %s \n", curtaskinfo.name);
}
int main(int argc, char* argv[])
{
char str[10] ;
// 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("start task\n");
/*
* Arguments: &task,
* name,
* stack size (0=default),
* priority,
* mode (FPU, start suspended, ...)
*/
sprintf(str,"hello");
rt_task_create(&demo_task, str, 0, 50, 0);
/*
* Arguments: &task,
* task function,
* function argument
*/
rt_task_start(&demo_task, &demo, 0);
}
四、编译执行
一般来说,如果库的头文件不在/usr/include目录中,那么在编译的时候需要用-I参数指定其路径。由于同一个库在不同系统上可能位于不同的目录下,用户安装库的时候也可以将库安装在不同的目录下,所以即使使用同一个库,由于库的路径的不同,造成了用-I参数指定的头文件的路径也可能不同,其结果就是造成了编译命令界面的不统一。
可以使用xeno-config获得编译时候库的位置,然后告诉gcc。
首先获得CFLAGS和LDFLAGS。分别是编译选项的参数和连接选项的参数。
1> xeno-config --xeno-cflagsxeno-config --xeno-cflags
2> xeno-config --xeno-ldflagsxeno-config --xeno-ldflags
3>设置flags环境变量有效
说明
这里的export LDFLAGS=`xeno-config --xeno-ldflags` ,符号,不是单引号,是键盘上面
这个按键。
4>编译
gcc $CFLAGS $LDFLAGS -lnative -lrtdk ex01.c -o ex01
5>声明动态库环境变量
程序执行需要的动态库在/usr/xenomai/lib里面,在环境变量里进行声明
export LD_LIBRARY_PATH=/usr/xenomai/lib
6>执行程序
我们在PC上编译生成的在本地运行的程序,要在ARM板子上运行,把GCC命令改成对应交叉编译工具即可。
如果不使用xeno-config ,交叉编译命令格式大概如下
arm-linux-gnueabi-gcc \
-I/home/carles/.../xenomai-2.5.6/usr/xenomai/include \
-D_GNU_SOURCE-D_REENTRANT -Wall-pipe -D__XENO__ \
-lnative \
-L/home/carles/.../xenomai-2.5.6/usr/xenomai/lib \
-lxenomai -lpthread-lrtdk \
ex01.c-o ex01
- How to create and compile a Xenomai helloworld program
- How to Create a Java Concurrent Program
- How to compile a TCL script into an EXE program
- How to Create a First C Program on Linux
- How to create a simple 2D graphics program?
- how to install xenomai(and some comments)
- How to create a Flex project with java Env so you can compile and debug it in Jboss directly?
- How to Compile and Run C/C++ program on Ubuntu 11.10
- How to: Create and Use a Data Connection Library
- How to Create a Slick and Clean Button in Photoshop
- How to create and apply a patch with git
- How to create (and deploy) a windows service in C# ?
- How To Create A Socket Based iPhone App and Server
- User Xcode and GCC How to create a C programe
- How to create and apply a patch with Git
- How to Create a Customer
- how to create a Makefile
- How to create a StackOverflowException. And how to figure out where it is happening.
- 利用AsyncTask高效异步加载图片,适用于ListView 和GridView
- Android编辑框被输入法遮盖,有效的处理办法
- java的注释和分隔符
- 仿百度智能提示搜索框
- OpenAL简介
- How to create and compile a Xenomai helloworld program
- MySQL create users and grant privilege
- Quartz表达式详解
- IOS这里是高效费舍尔茨洗牌 随机生成字符串
- String.valueOf Long.valueOf Integer.valueOf 源码分析 缓存
- Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.3.3.RELEASE
- 连接mysql数据库提示mysqladmin flush-hosts
- Java transient关键字使用小记
- Android Activity生命周期