⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rtai_xeno.h

📁 rtai-3.1-test3的源代码(Real-Time Application Interface )
💻 H
📖 第 1 页 / 共 2 页
字号:
    __xeno_user_exit();    __xeno_skin_exit();    __xeno_main_exit();    exit(0);}#endif  /* !XENO_MAIN_MODULE */#ifdef XENO_HEAP_MODULEvoid *xnarch_sysalloc (unsigned bytes) {    return malloc(bytes);}void xnarch_sysfree (void *chunk, unsigned bytes) {    free(chunk);}#else /* !XENO_HEAP_MODULE */void *xnarch_sysalloc(unsigned bytes);void xnarch_sysfree(void *chunk,		    unsigned bytes);#endif /* XENO_HEAP_MODULE */#ifdef XENO_TIMER_MODULEvoid *vml_timer_handle;static inline void xnarch_stop_timer (void) {    __pthread_cancel_vm(vml_timer_handle,NULL);}#endif /* XENO_TIMER_MODULE */#ifdef XENO_POD_MODULEextern void *vml_timer_handle;xnsysinfo_t vml_info;xnarchtcb_t *vml_root;xnarchtcb_t *vml_current;#define xnarch_relay_tick()  /* Nullified. *//* NOTES:   o IRQ threads have no TCB, since they are not known by the VM   abstraction.   o All in-kernel IRQ threads serving the VM have the same priority   level, except when they wait on a synchonization barrier.   o In theory, the IRQ synchronization mechanism might end up   causing interrupt loss, since we might be sleeping to much waiting   on the irqlock barrier until it is signaled. In practice, this   should not happen because interrupt-free sections are short thanks   to the mutex scheme.*/struct xnarch_tick_parms {    time_t sec;    long nsec;    void (*tickhandler)(void);    pid_t ppid;    int syncflag;};static void *xnarch_timer_thread (void *cookie){    struct xnarch_tick_parms *p = (struct xnarch_tick_parms *)cookie;    void (*tickhandler)(void) = p->tickhandler;    struct timespec ts;    pthread_create_rt("vmtimer",NULL,p->ppid,&p->syncflag,&vml_timer_handle);    pthread_migrate_rt(FUSION_RTAI_DOMAIN);    ts.tv_sec = p->sec;    ts.tv_nsec = p->nsec;    for (;;)	{	nanosleep(&ts,NULL);	xnarch_sync_irq();	tickhandler(); /* Should end up in xnpod_clock_irq() here. */	}    return NULL;}static inline void xnarch_start_timer (unsigned long nstick,				       void (*tickhandler)(void)){    struct xnarch_tick_parms parms;    struct sched_param param;    unsigned long tickval;    pthread_attr_t thattr;    pthread_t thid;    pthread_attr_init(&thattr);    pthread_attr_setdetachstate(&thattr,PTHREAD_CREATE_DETACHED);    pthread_attr_setschedpolicy(&thattr,SCHED_FIFO);    param.sched_priority = sched_get_priority_min(SCHED_FIFO) + 2;    pthread_attr_setschedparam(&thattr,&param);    if (vml_info.tickval > nstick)	{	fprintf(stderr,"Xenomai/VM: warning: VM tick freq > nucleus tick freq\n");	fprintf(stderr,"          : rounding VM tick to %lu us\n",vml_info.tickval / 1000);	tickval = vml_info.tickval;	}    else	{	tickval = ((nstick + vml_info.tickval - 1) / vml_info.tickval) * vml_info.tickval;	if (tickval != nstick)	    {	    fprintf(stderr,"Xenomai/VM: warning: VM tick not a multiple of nucleus tick\n");	    fprintf(stderr,"          : rounding VM tick to %lu us\n",tickval / 1000);	    }	}    parms.sec = tickval / 1000000000;    parms.nsec = tickval % 1000000000;    parms.tickhandler = tickhandler;    parms.syncflag = 0;    parms.ppid = getpid();    pthread_create(&thid,&thattr,&xnarch_timer_thread,&parms);    pthread_sync_rt(&parms.syncflag);    pthread_start_rt(vml_timer_handle);}static inline void xnarch_leave_root(xnarchtcb_t *rootcb) {}static inline void xnarch_enter_root(xnarchtcb_t *rootcb) {}static inline void xnarch_switch_to (xnarchtcb_t *out_tcb,				     xnarchtcb_t *in_tcb) {    vml_current = in_tcb;    __pthread_activate_vm(in_tcb->khandle,out_tcb->khandle);}static inline void xnarch_finalize_and_switch (xnarchtcb_t *dead_tcb,					       xnarchtcb_t *next_tcb) {    vml_current = next_tcb;    __pthread_cancel_vm(dead_tcb->khandle,next_tcb->khandle);}static inline void xnarch_finalize_no_switch (xnarchtcb_t *dead_tcb) {    __pthread_cancel_vm(dead_tcb->khandle,NULL);}static inline void xnarch_save_fpu(xnarchtcb_t *tcb) {    /* Handled by the in-kernel nucleus */}static inline void xnarch_restore_fpu(xnarchtcb_t *tcb) {    /* Handled by the in-kernel nucleus */}static inline void xnarch_init_root_tcb (xnarchtcb_t *tcb,					 struct xnthread *thread,					 const char *name){    struct sched_param param;    param.sched_priority = sched_get_priority_min(SCHED_FIFO);    if (sched_setscheduler(0,SCHED_FIFO,&param) < 0 ||	pthread_info_rt(&vml_info) < 0)	{	perror("Xenomai/VM");	exit(1);	}    pthread_init_rt("vmroot",tcb,&tcb->khandle);    pthread_migrate_rt(FUSION_RTAI_DOMAIN);    tcb->name = name;    vml_root = vml_current = tcb;}static inline void xnarch_init_tcb (xnarchtcb_t *tcb,				    void *adcookie) { /* <= UNUSED */    tcb->khandle = NULL;}static void *xnarch_thread_trampoline (void *cookie){    xnarchtcb_t *tcb = (xnarchtcb_t *)cookie;    if (!setjmp(tcb->rstenv))	{	/* After this, we are controlled by the in-kernel nucleus. */	pthread_create_rt(tcb->name,tcb,tcb->ppid,&tcb->syncflag,&tcb->khandle);	pthread_migrate_rt(FUSION_RTAI_DOMAIN);	}    xnarch_setimask(tcb->imask);    xnpod_welcome_thread(tcb->thread);    tcb->entry(tcb->cookie);    return NULL;}static inline void xnarch_init_thread (xnarchtcb_t *tcb,				       void (*entry)(void *),				       void *cookie,				       int imask,				       struct xnthread *thread,				       char *name){    struct sched_param param;    pthread_attr_t thattr;    if (tcb->khandle)	/* Restarting thread */	{        pthread_kill(tcb->thid,XNARCH_SIG_RESTART);	return;	}    tcb->imask = imask;    tcb->entry = entry;    tcb->cookie = cookie;    tcb->thread = thread;    tcb->name = name;    tcb->ppid = getpid();    tcb->syncflag = 0;    pthread_attr_init(&thattr);    pthread_attr_setdetachstate(&thattr,PTHREAD_CREATE_DETACHED);    pthread_attr_setschedpolicy(&thattr,SCHED_FIFO);    param.sched_priority = sched_get_priority_min(SCHED_FIFO);    pthread_attr_setschedparam(&thattr,&param);    pthread_create(&tcb->thid,&thattr,&xnarch_thread_trampoline,tcb);    pthread_sync_rt(&tcb->syncflag);}static inline void xnarch_init_fpu(xnarchtcb_t *tcb) {    /* Handled by the in-kernel nucleus */}int xnarch_setimask (int imask){    spl_t s;    splhigh(s);    splexit(!!imask);    return !!s;}#define xnarch_notify_ready()  /* Nullified */#endif /* XENO_POD_MODULE */extern xnsysinfo_t vml_info;void xnarch_exit_handler(int);static inline unsigned long long xnarch_tsc_to_ns (unsigned long long ts) {    return ts;}static inline unsigned long long xnarch_ns_to_tsc (unsigned long long ns) {    return ns;}static inline unsigned long long xnarch_get_cpu_time (void) {    unsigned long long t;    pthread_time_rt(&t);    return t;}static inline unsigned long long xnarch_get_cpu_tsc (void) {    return xnarch_get_cpu_time();}static inline unsigned long long xnarch_get_cpu_freq (void) {    return vml_info.cpufreq;}static inline void xnarch_halt (const char *emsg) {    fprintf(stderr,"Xenomai/VM: fatal: %s\n",emsg);    fflush(stderr);    xnarch_exit_handler(SIGKILL);    exit(99);}#ifdef __cplusplus}#endif/* Dashboard and graph control. */#define XNARCH_DECL_DISPLAY_CONTEXT();#define xnarch_init_display_context(obj)#define xnarch_create_display(obj,name,tag)#define xnarch_delete_display(obj)#define xnarch_post_graph(obj,state)#define xnarch_post_graph_if(obj,state,cond)#endif /* !_VM_ASM_RTAI_XENO_H */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -