base/include/rtai_usi.h

Go to the documentation of this file.
00001 /* 00002 * Copyright (C) 1999-2005 Paolo Mantegazza <mantegazza@aero.polimi.it> 00003 * 00004 * This program is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public License as 00006 * published by the Free Software Foundation; either version 2 of the 00007 * License, or (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 */ 00018 00019 #ifndef _RTAI_USI_H 00020 #define _RTAI_USI_H 00021 00022 #ifndef __KERNEL__ 00023 00024 #include <asm/rtai_usi.h> 00025 //#include <asm/rtai_atomic.h> 00026 #include <asm/rtai_srq.h> 00027 00028 #ifdef __cplusplus 00029 extern "C" { 00030 #endif /* __cplusplus */ 00031 00032 static inline int rt_startup_irq(unsigned int irq) 00033 { 00034 return (int)rtai_srq(USI_SRQ_MASK | _STARTUP_IRQ, irq); 00035 } 00036 00037 #define rt_shutdown_irq(irq) \ 00038 do { rtai_srq(USI_SRQ_MASK | _SHUTDOWN_IRQ, irq); } while (0) 00039 00040 #define rt_enable_irq(irq) \ 00041 do { rtai_srq(USI_SRQ_MASK | _ENABLE_IRQ, irq); } while (0) 00042 00043 #define rt_disable_irq(irq) \ 00044 do { rtai_srq(USI_SRQ_MASK | _DISABLE_IRQ, irq); } while (0) 00045 00046 #define rt_mask_and_ack_irq(irq) \ 00047 do { rtai_srq(USI_SRQ_MASK | _MASK_AND_ACK_IRQ, irq); } while (0) 00048 00049 #define rt_ack_irq(irq) \ 00050 do { rtai_srq(USI_SRQ_MASK | _ACK_IRQ, irq); } while (0) 00051 00052 #define rt_unmask_irq(irq) \ 00053 do { rtai_srq(USI_SRQ_MASK | _UNMASK_IRQ, irq); } while (0) 00054 00055 #define rtai_cli() \ 00056 do { rtai_srq(USI_SRQ_MASK | _DISINT, 0); } while (0) 00057 00058 #define rtai_sti() \ 00059 do { rtai_srq(USI_SRQ_MASK | _ENINT, 0); } while (0) 00060 00061 #define rtai_save_flags_and_cli(flags) \ 00062 do { flags = (unsigned long)rtai_srq(USI_SRQ_MASK | _SAVE_FLAGS_CLI, 0); } while(0) 00063 00064 #define rtai_restore_flags(flags) \ 00065 do { rtai_srq(USI_SRQ_MASK | _RESTORE_FLAGS, flags); } while (0) 00066 00067 #ifdef CONFIG_SMP 00068 00069 struct __usi_xchg_dummy { unsigned long a[100]; }; 00070 #define __usi_xg(x) ((struct __usi_xchg_dummy *)(x)) 00071 00072 static inline unsigned long usi_atomic_cmpxchg(volatile void *ptr, unsigned long o, unsigned long n) 00073 { 00074 unsigned long prev; 00075 __asm__ __volatile__ ("lock; cmpxchgl %1, %2" 00076 : "=a" (prev) 00077 : "q"(n), "m" (*__usi_xg(ptr)), "0" (o) 00078 : "memory"); 00079 return prev; 00080 } 00081 00082 #define rt_spin_lock(lock) \ 00083 do { while (usi_atomic_cmpxchg(lock, 0, 1)); } while (0) 00084 00085 #define rt_spin_unlock(lock) \ 00086 do { *(volatile int *)lock = 0; } while (0) 00087 00088 #else 00089 #define rt_spin_lock(lock); 00090 00091 #define rt_spin_unlock(lock); 00092 #endif 00093 00094 #define rt_spin_lock_init(lock) \ 00095 do { *(volatile int *)lock = 0; } while (0) 00096 00097 #define rt_spin_lock_irq(lock) \ 00098 do { rtai_cli(); rt_spin_lock(lock); } while (0) 00099 00100 #define rt_spin_unlock_irq(lock) \ 00101 do { rt_spin_unlock(lock); rtai_sti(); } while (0) 00102 00103 static inline unsigned long rt_spin_lock_irqsave(void *lock) 00104 { 00105 unsigned long flags; 00106 rtai_save_flags_and_cli(flags); 00107 rt_spin_lock(lock); 00108 return flags; 00109 } 00110 00111 #define rt_spin_unlock_irqrestore(flags, lock) \ 00112 do { rt_spin_unlock(lock); rtai_restore_flags(flags); } while (0) 00113 00114 #ifdef __cplusplus 00115 } 00116 #endif /* __cplusplus */ 00117 00118 #endif /* !__KERNEL__ */ 00119 00120 #endif /* !_RTAI_USI_H */

Generated on Thu Nov 20 11:49:49 2008 for RTAI API by doxygen 1.3.8