📄 rtai_xeno.h
字号:
/* * Copyright (C) 2001,2002,2003 Philippe Gerum <rpm@xenomai.org>. * * Xenomai is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * Xenomai is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Xenomai; if not, write to the Free Software Foundation, * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * As a special exception, the RTAI project gives permission * for additional uses of the text contained in its release of * Xenomai. * * The exception is that, if you link the Xenomai libraries with other * files to produce an executable, this does not by itself cause the * resulting executable to be covered by the GNU General Public License. * Your use of that executable is in no way restricted on account of * linking the Xenomai libraries code into it. * * This exception does not however invalidate any other reasons why * the executable file might be covered by the GNU General Public * License. * * This exception applies only to the code released by the * RTAI project under the name Xenomai. If you copy code from other * RTAI project releases into a copy of Xenomai, as the General Public * License permits, the exception does not apply to the code that you * add in this way. To avoid misleading anyone as to the status of * such modified files, you must delete this exception notice from * them. * * If you write modifications of your own for Xenomai, it is your * choice whether to permit this exception to apply to your * modifications. If you do not wish that, delete this exception * notice. */#ifndef _VM_ASM_RTAI_XENO_H#define _VM_ASM_RTAI_XENO_H#include <sys/time.h>#include <errno.h>#include <malloc.h>#include <stdlib.h>#include <unistd.h>#include <string.h>#include <signal.h>#include <stdio.h>#include <setjmp.h>#include <asm/rtai_xnatomic.h>#include <xenomai/fusion.h>#define XNARCH_DEFAULT_TICK 1000000 /* ns, i.e. 1ms */#define XNARCH_IRQ_MAX 32#define XNARCH_SIG_RESTART SIGUSR1#define XNARCH_HOST_TICK 0 /* No host ticking service */#define XNARCH_APERIODIC_PREC 0 /* No aperiodic support */#define XNARCH_SCHED_LATENCY 0 /* No scheduling latency */struct xnthread;typedef struct xnarchtcb { /* Per-thread arch-dependent block */ const char *name; /* Symbolic name of thread (can be NULL) */ struct xnthread *thread; /* VM thread pointer (opaque) */ void *khandle; /* Kernel handle (opaque) */ void (*entry)(void *); /* Thread entry */ void *cookie; /* Thread cookie passed on entry */ int imask; /* Initial interrupt mask */ jmp_buf rstenv; /* Restart context info */ pid_t ppid; int syncflag; pthread_t thid; /* The following fields are not used by the Fusion skin, however they are set by the nucleus. */ unsigned stacksize; /* Aligned size of stack (bytes) */ unsigned long *stackbase; /* Stack space */} xnarchtcb_t;extern xnarchtcb_t *vml_root;extern xnarchtcb_t *vml_current;extern int vml_irqlock;typedef void *xnarch_fltinfo_t; /* Unused but required */#define xnarch_fault_trap(fi) (0)#define xnarch_fault_code(fi) (0)#define xnarch_fault_pc(fi) (0L)#define XNARCH_THREAD_COOKIE NULL#define XNARCH_THREAD_STACKSZ 0 /* Use the default POSIX value. */#define XNARCH_ROOT_STACKSZ 0 /* Only a placeholder -- no stack */#define xnarch_printf printf#define printk printf#define xnarch_llimd(ll,m,d) ((int)(ll) * (int)(m) / (int)(d))#define xnarch_imuldiv(i,m,d) ((int)(i) * (int)(m) / (int)(d))#define xnarch_ulldiv(ull,uld,rem) (((*rem) = ((ull) % (uld))), (ull) / (uld))#define xnarch_ullmod(ull,uld,rem) ((*rem) = ((ull) % (uld)))#define xnarch_stack_size(tcb) ((tcb)->stacksize)#define xnarch_fpu_ptr(tcb) (NULL)static inline int __attribute__ ((unused))xnarch_read_environ (const char *name, const char **ptype, void *pvar){ char *value; if (*ptype == NULL) return 0; /* Already read in */ *ptype = NULL; value = getenv(name); if (!value) return -1; if (**ptype == 's') *((char **)pvar) = value; else *((int *)pvar) = atoi(value); return 1;}static int inline xnarch_lock_irq (void) { extern int vml_irqlock; return xnarch_atomic_xchg(&vml_irqlock,1);}static inline void xnarch_unlock_irq (int x) { extern int vml_irqlock, vml_irqpend; if (!x && vml_irqlock) { if (xnarch_atomic_xchg(&vml_irqpend,0)) __pthread_release_vm(&vml_irqlock); else vml_irqlock = 0; }}void xnarch_sync_irq(void);int xnarch_setimask(int imask);typedef int spl_t;#define splhigh(x) ((x) = xnarch_lock_irq())#define splexit(x) xnarch_unlock_irq(x)#define splnone() xnarch_unlock_irq(0)/* Module arg macros */#define vartype(var) var ## _ ## tYpE#define MODULE_DESCRIPTION(s);#define MODULE_LICENSE(s);#define MODULE_AUTHOR(s);#define MODULE_PARM(var,type) static const char *vartype(var) = type#define MODULE_PARM_DESC(var,desc);#define MODULE_PARM_VALUE(var) (xnarch_read_environ(#var,&vartype(var),&var),var)/* Nullify other kernel macros */#define EXPORT_SYMBOL(sym);#define module_init(sym);#define module_exit(sym);#ifdef __cplusplusextern "C" {#endifvoid xnpod_welcome_thread(struct xnthread *);#ifdef XENO_INTR_MODULEint vml_irqlock = 0;int vml_irqpend = 0;void xnarch_sync_irq (void){ if (vml_irqlock) __pthread_hold_vm(&vml_irqpend);}static inline int xnarch_hook_irq (unsigned irq, void (*handler)(unsigned irq, void *cookie), void *cookie) { if (irq == 0) return -EINVAL; /* Reserved for the timer thread. */ return -ENOSYS;}static inline int xnarch_release_irq (unsigned irq) { return -ENOSYS;}static inline int xnarch_enable_irq (unsigned irq) { return -ENOSYS;}static inline int xnarch_disable_irq (unsigned irq) { return -ENOSYS;}static inline void xnarch_isr_chain_irq (unsigned irq) { /* Nop */}static inline void xnarch_isr_enable_irq (unsigned irq) { /* Nop */}#endif /* XENO_INTR_MODULE */#ifdef XENO_MAIN_MODULEint __xeno_main_init(void);void __xeno_main_exit(void);int __xeno_skin_init(void);void __xeno_skin_exit(void);int __xeno_user_init(void);void __xeno_user_exit(void);int vml_done = 0;static inline int xnarch_init (void) { return 0;}static inline void xnarch_exit (void) {}static void xnarch_restart_handler (int sig) { longjmp(vml_current->rstenv,1);}void xnarch_exit_handler (int sig){ vml_done = 1; __pthread_activate_vm(vml_root->khandle,vml_current->khandle); exit(99);}int main (int argc, char *argv[]){ struct sigaction sa; int err; if (geteuid() !=0) { fprintf(stderr,"This program must be run with root privileges"); exit(1); } err = __xeno_main_init(); if (err) { fprintf(stderr,"main_init() failed, err=%x\n",err); exit(2); } err = __xeno_skin_init(); if (err) { fprintf(stderr,"skin_init() failed, err=%x\n",err); exit(3); } err = __xeno_user_init(); if (err) { fprintf(stderr,"user_init() failed, err=%x\n",err); exit(4); } sa.sa_handler = &xnarch_restart_handler; sigemptyset(&sa.sa_mask); sa.sa_flags = SA_RESTART; sigaction(XNARCH_SIG_RESTART,&sa,NULL); sa.sa_handler = &xnarch_exit_handler; sa.sa_flags = 0; sigaction(SIGTERM,&sa,NULL); sigaction(SIGHUP,&sa,NULL); sigaction(SIGINT,&sa,NULL); while (!vml_done) __pthread_idle_vm(&vml_irqlock);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -