怎么做网站相册,百度站长平台提交网站,做自己的优惠券网站,app手机应用软件开发RTlinux主要的api函数实时应用程序分为两部分,内核部分和应用部分,应用部分需要和内核部分通过FIFO进行数据交换和控制,除此之外和一般应用程序没有太多区别,内核部分比较复杂,程序以模块方式挂入内核,这部分程序的编写需要对底层的东西有较高的要求,除了掌握RTLinux的API以外还…RTlinux主要的api函数实时应用程序分为两部分,内核部分和应用部分,应用部分需要和内核部分通过FIFO进行数据交换和控制,除此之外和一般应用程序没有太多区别,内核部分比较复杂,程序以模块方式挂入内核,这部分程序的编写需要对底层的东西有较高的要求,除了掌握RTLinux的API以外还需要对Linux内核编程有较深的了解,以及对硬件部分也有比较熟悉的掌握.没有找到完整的rtlinux的api说明,下面是网上找到的主要的一些函数.POSIX 线程创建函数一个实时程序是由几个执行的线程组成的。线程是轻量级进程它们共享共有的地址空间。在RTLinux中所有的线程共享Linux内核地址空间。int pthread_create (pthread_t *thread, pthread_attr_t * attr, void * (*start_routine)(void *), void *arg)这是RTLinux的标准POSIX线程创建函数。这个线程运行函数指针start_routine指向的过程arg是这个函数的指针的入口参数。线程的属性由attr对象决定可以为这个属性设置CPU号、堆栈大小等属性。设定若为NULL将会使用默认属性。返回0表示成功创建线程线程号放在thread所指向的空间返回非0表示创建失败。线程的属性决定在特定的CPU上创建线程(pthread_attr_setcpu_np)是否使用FPU(pthread_attr_setfp_np)。int pthread_attr_init (pthread_attr_t *attr)初始化线程运行的属性。int pthread_ attr_setschedparam (pthread_attr_t *attr, const structsched_param *param)和int pthread_ attr_setschedparam (constpthread_attr_t *attr, struct sched_param *param)这两个函数根据程序的需要相应地从attr中设定/取得线程的运行参数。param是为调度的SCHED_FIFO和SCHED_RR策略定义的属性。int pthread_attr_setcpu_np (pthread_atte_t *attr, int cpu)和int pthread_attr_getcpu_np (pthread_atte_t *attr, int cpu)设定/取得线程运行的CPU号。在SMP机器上允许线程在一个特定的CPU上运行。int pthread_cancel (pthread_t thread)取消一个运行的线程。int pthread_delete_np (pthread_t thread)删除一个线程并且释放该线程的所有资源。返回0表示成功删除非0表示删除失败。pthrad_t pthread_self (void)获得当前正在运行的线程号。clockid_t rtl_getschedclock (void)获得当前调度方法的时钟。int rtl_setclockmode (clockid_t clock, int mode, hrtime_t mode_param)设置当前的时钟模式modeRTL_CLOCK_MODE_ONESHOT时是非周期( 一次性) 模式mode_param参数无用modeRTL_CLOCK_MODE_PERIODIC时是周期模式mode_param参数是周期的长度。int pthread_wait_np (void)当前周期的线程运行结束总是返回0。时间相关函数RTLinux提供了一些时钟函数用于计时功能包括线程调度获得TSP(timestamps)等。下面的是一般的计时函数(需要包含rtl_time.h)int clock_gettime(clockid_t clock_id, struct timespec *ts);读取当前的时间保存到clock_id所指的对象中。hrtime_t clock_gethrtime(clockid_t clock);读取当前时间但返回一个64位(hrtime_t)的纳秒时间值。struct timespec {time_t tv_sec; /*秒*/long tv_nsec; /*纳秒*/};一些时间转换的函数用于把时间格式转换为另外一种格式。时间转换函数(需要包含rtl_time.h)hrtime_t timespec_to_ns(const struct timespec *ts)timespec到纳秒数转换struct timespec timespec_from_ns(hrtime_t t)纳秒数到timespec转换const struct timespec * hrt2ts(hrtime_t value)下面是一些支持的时钟类型。时钟类型相关的宏CLOCK_MONOTONIC: POSIX时钟以恒定速率运行不会复位和调整CLOCK_REALTIME:标准POSIX实时时钟。目前与CLOCK_MONOTONIC时钟相同CLOCK_RTL_SCHED:调度器用来任务调度的时钟以下是机器结构相关的时钟CLOCK_8254:在x86单处理器机器上用于调度的时钟CLOCK_APIC:用在SMP x86机器的时钟线程调度函数RTLinux提供一些调度方式允许线程代码在特定的时刻运行。RTLinux使用单纯优先级驱动的调度器更搞优先级的线程总是被选择运行。如果两个线程的优先级拥有一样的优先级选择那一个线程运行是不确定的。RTLinux使用下面的调度APIint pthread_setschedparam (pthread_t thread, int policy, const structsched_param *param)设置一个线程的调度参数用policy和sched_param两个参数设置thread的调度参数属性policySCHED_RR使用Round-Robin方法调度policySCHED_FIFO使用先进先出的方法调度返回0表示成功调度非0表示失败。int pthread_getschedparam (pthread_t thread, int policy, const structsched_param *param)获得一个线程的调度参数。将获得的policy和sched_param结构放在入口参数所指向的地址里面。int pthread_make_periodic_np (pthread_t thread, hrtime start_time,hrtime_t period)这个函数标记thread线程为可运行。线程将在start_time时刻开始运行运行的时间间隔由period给定。int pthread_wait_np (void)pthread_wait_np函数将挂起当前运行发线程直到下一周期。这个线程必须是pthread_make_periodic_np函数标记为可执行。int sched_get_priority_max (int policy)和int sched_get_priority_min (int policy)确定sched_priority可能的值。实时任务与