/home/hillier_g/checkout/most4linux/most-kernel/rt-nrt.h

Go to the documentation of this file.
00001 /*
00002  *  Copyright(c) Siemens AG, Muenchen, Germany, 2005, 2006, 2007
00003  *                           Bernhard Walle <bernhard.walle@gmx.de>
00004  *                           Gernot Hillier <gernot.hillier@siemens.com>
00005  *
00006  * ----------------------------------------------------------------------------
00007  * This program is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License version 2 as 
00009  * published by the Free Software Foundation;
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019  * ----------------------------------------------------------------------------
00020  */
00021 #ifndef RT_NRT_H
00022 #define RT_NRT_H
00023 
00038 #ifdef HAVE_CONFIG_H
00039 #include "config/config.h"
00040 #endif
00041 #include <asm/uaccess.h>
00042 #include <asm/div64.h>
00043 #include <linux/version.h>
00044 #include <linux/spinlock.h>
00045 #include <linux/interrupt.h>
00046 #include <linux/delay.h>
00047 
00048 #ifdef RT_RTDM
00049 #   include <rtdm/rtdm_driver.h>
00050 #   include "rtseqlock.h"
00051 #   ifdef XENO_VERSION_NAME
00052 #       include <native/timer.h>
00053 #   endif
00054 #endif
00055  /* {{{ */
00062 
00063 #if defined(RT_RTDM) || defined(DOXYGEN)
00064 
00072 #define rt_nrt_exec(rt, nrt)                                \
00073     rt
00074 
00075 #if defined(XENO_VERSION_NAME) || defined(DOXYGEN)
00076 
00089 #define rtnrt_start_timer_oneshot()                         \
00090     rt_timer_set_mode(TM_ONESHOT)
00091 #elif defined(RTAI_RELEASE)
00092 #define rtnrt_start_timer_oneshot()                         \
00093     start_rt_timer(0)
00094 #else
00095 #error "Unsupported operating system for RTDM"
00096 #endif
00097 
00098 #else
00099 
00100 #define rt_nrt_exec(rt, nrt)                                \
00101     nrt
00102 
00103 #define rtnrt_start_timer_oneshot()                         \
00104     0
00105 
00106 #endif /* RT_RTDM */
00107  /* }}} */
00109 
00110  /* {{{ */
00122 
00123 #if defined(RT_RTDM) || defined(DOXYGEN)
00124 
00131 #define rtnrt_printk(fmt, arg...) \
00132         rtdm_printk(fmt, ##arg)
00133 #else
00134 
00135 #define rtnrt_printk(fmt, arg...) \
00136         printk(fmt, ##arg)
00137 
00138 #endif
00139 
00140 #if defined(DEBUG) || defined(DOXYGEN)
00141 
00148 #define rtnrt_debug(fmt, arg...) \
00149         rtnrt_printk(KERN_DEBUG fmt, ##arg)
00150 #else
00151 
00152 #define rtnrt_debug(fmt, arg...) \
00153         do { } while (0)
00154 #endif
00155 
00162 #   define rtnrt_info(fmt, arg...) \
00163         rtnrt_printk(KERN_INFO fmt, ##arg)
00164 
00165 
00172 #define rtnrt_notice(fmt, arg...) \
00173     rtnrt_printk(KERN_NOTICE fmt,##arg)
00174 
00181 #define rtnrt_warn(fmt, arg...) \
00182     rtnrt_printk(KERN_WARNING "- " fmt,##arg)
00183 
00190 #define rtnrt_err(fmt, arg...) \
00191     rtnrt_printk(KERN_ERR "* " fmt,##arg)
00192 
00199 #define rtnrt_crit(fmt, arg...) \
00200     rtnrt_printk(KERN_CRIT "# " fmt,##arg)
00201 
00208 #define rtnrt_alert(fmt, arg...) \
00209     rtnrt_printk(KERN_ALERT "!!!! " fmt,##arg)
00210 
00217 #define rtnrt_emeg(fmt, arg...) \
00218     rtnrt_printk(KERN_EMERG "***!!!!*** " fmt,##arg)
00219 
00220  /* }}} */
00222 
00223  /* {{{ */
00244 #if defined(CONFIG_PREEMPT_RT) || defined(DOXYGEN)
00245 
00253 #   define RTNRT_LSPINLOCK_UNLOCKED(lock)                  \
00254         SPIN_LOCK_UNLOCKED(lock)
00255 #else
00256 #   define RTNRT_LSPINLOCK_UNLOCKED(lock)                  \
00257         SPIN_LOCK_UNLOCKED
00258 #endif
00259 
00260 
00261 #if defined(RT_RTDM) || defined(DOXYGEN)
00262 
00268 #define RTNRT_LOCK_UNLOCKED(lock)                          \
00269     RTDM_LOCK_UNLOCKED
00270 
00276 #define rtnrt_lock_init(lock)                               \
00277     rtdm_lock_init(lock)
00278 
00284 #define rtnrt_lock_get(lock)                                \
00285     rtdm_lock_get(lock)
00286 
00292 #define rtnrt_lock_put(lock)                                \
00293     rtdm_lock_put(lock)
00294 
00301 #define rtnrt_lock_get_irqsave(lock, flags)                 \
00302     rtdm_lock_get_irqsave(lock, flags)
00303 
00310 #define rtnrt_lock_put_irqrestore(lock, flags)              \
00311     rtdm_lock_put_irqrestore(lock, flags)
00312 
00316 typedef rtdm_lock_t rtnrt_lock_t;
00317 
00321 typedef rtdm_lockctx_t rtnrt_lockctx_t;
00322 
00323 #else /* NRT variant */
00324 
00325 #if defined(CONFIG_PREEMPT_RT)
00326 #   define RTNRT_LOCK_UNLOCKED(lock)                        \
00327         SPIN_LOCK_UNLOCKED(lock)
00328 #else /* not CONFIG_PREEMPT_RT */
00329 #   define RTNRT_LOCK_UNLOCKED(lock)                        \
00330         SPIN_LOCK_UNLOCKED
00331 #endif /* CONFIG_PREEMPT_RT */
00332 
00333 #define rtnrt_lock_init(lock)                               \
00334     spin_lock_init(lock)
00335 
00336 #define rtnrt_lock_get(lock)                                \
00337     spin_lock(lock)
00338 
00339 #define rtnrt_lock_put(lock)                                \
00340     spin_unlock(lock)
00341 
00342 #define rtnrt_lock_get_irqsave(lock, flags)                 \
00343     spin_lock_irqsave(lock, flags)
00344 
00345 #define rtnrt_lock_put_irqrestore(lock, flags)              \
00346     spin_unlock_irqrestore(lock, flags)
00347 
00348 typedef spinlock_t rtnrt_lock_t;
00349 
00350 typedef unsigned long rtnrt_lockctx_t;
00351 
00352 #endif
00353  /* }}} */
00355  /* {{{ */
00364 #if defined(RT_RTDM) || defined(DOXYGEN)
00365 
00369 #define RTNRT_SEQLOCK_UNLOCKED                       \
00370     RT_SEQLOCK_UNLOCKED
00371 
00375 #define rtnrt_seqlock_init(x)                        \
00376     rt_seqlock_init(x)
00377 
00383 #define rtnrt_write_seqlock(sl)                      \
00384     rt_write_seqlock(seqlock_t *sl)
00385 
00391 #define rtnrt_write_sequnlock(sl)                    \
00392     rt_write_sequnlock(seqlock_t *sl)
00393 
00399 #define rtnrt_read_seqbegin(sl)                      \
00400     rt_read_seqbegin(sl)
00401 
00408 #define rtnrt_read_seqretry(sl, iv)                   \
00409     rt_read_seqretry(sl, iv)
00410 
00417 #define rtnrt_write_seqlock_irqsave(sl, flags)        \
00418     rt_write_seqlock_irqsave(sl, flags)
00419 
00426 #define rtnrt_write_sequnlock_irqrestore(sl, flags)   \
00427     rt_write_sequnlock_irqrestore(sl, flags)
00428 
00432 typedef rt_seqlock_t rtnrt_seqlock_t;
00433 
00434 #else
00435 
00436 #define RTNRT_SEQLOCK_UNLOCKED                       \
00437     SEQLOCK_UNLOCKED
00438 
00439 #define rtnrt_seqlock_init(x)                        \
00440     seqlock_init(x)
00441 
00442 #define rtnrt_write_seqlock(sl)                      \
00443     write_seqlock(seqlock_t *sl)
00444 
00445 #define rtnrt_write_sequnlock(sl)                    \
00446     write_sequnlock(seqlock_t *sl)
00447 
00448 #define rtnrt_read_seqbegin(sl)                      \
00449     read_seqbegin(sl)
00450 
00451 #define rtnrt_read_seqretry(sl, iv)                  \
00452     read_seqretry(sl, iv)
00453 
00454 #define rtnrt_write_seqlock_irqsave(sl, flags)       \
00455     write_seqlock_irqsave(sl, flags)
00456 
00457 #define rtnrt_write_sequnlock_irqrestore(sl, flags)  \
00458     write_sequnlock_irqrestore(sl, flags)
00459 
00460 typedef seqlock_t rtnrt_seqlock_t;
00461 
00462 
00463 
00464 #endif
00465  /* }}} */
00466  /* {{{ */
00479 
00484 #if !defined(NSEC_PER_MSEC) || defined(DOXYGEN)
00485 #define NSEC_PER_MSEC       1000000L
00486 #endif
00487 
00488 #if (defined(RTDM_API_VER) && (RTDM_API_VER < 5)) || defined (DOXYGEN) \
00489     || !defined(RTDM_API_VER)
00490 
00496 typedef uint64_t nanosecs_abs_t;
00497 
00506 typedef uint64_t nanosecs_rel_t;
00507 
00508 #endif
00509 
00510 #if defined(RT_RTDM) || defined(DOXYGEN)
00511 
00528 static inline nanosecs_abs_t rtnrt_clock_read(void)
00529 {
00530     return rtdm_clock_read();
00531 }
00532 
00533 #else
00534 
00535 static inline nanosecs_abs_t rtnrt_clock_read(void)
00536 {
00537     struct timespec ts;
00538 
00539     getnstimeofday(&ts);
00540     return (nanosecs_abs_t)ts.tv_sec * NSEC_PER_SEC + ts.tv_nsec;
00541 }
00542 
00543 #endif
00544  /* }}} */
00546  /* {{{ */
00555 
00556 #if defined(RT_RTDM) || defined(DOXYGEN)
00557 
00570 static inline int rtnrt_task_sleep(unsigned int millisecs)
00571 {
00572     nanosecs_abs_t      sleep_until;
00573     nanosecs_rel_t      delay;
00574     int                 ret;
00575 
00576     delay = millisecs * NSEC_PER_MSEC;
00577     sleep_until = rtnrt_clock_read() + delay;
00578 
00579     ret = rtdm_task_sleep(delay);
00580     if (ret == -EINTR) {
00581         uint64_t time_left = sleep_until - rtnrt_clock_read();
00582         do_div(time_left, NSEC_PER_MSEC);
00583 
00584         /* return not zero because of rounding issues */
00585         return time_left == 0 ? 1 : time_left; 
00586     }
00587 
00588     return ret;
00589 }
00590 
00607 #define rtnrt_ndelay(delay_nsecs)                           \
00608     rtdm_task_busy_sleep(delay_nsecs)
00609 
00617 #define rtnrt_udelay(delay_usecs)                           \
00618     rtdm_task_busy_sleep((delay_usecs) * NSEC_PER_USEC)
00619 
00627 #define rtnrt_mdelay(delay_msecs)                           \
00628     rtdm_task_busy_sleep((delay_msecs) * NSEC_PER_MSEC)
00629 
00630 #else
00631 
00632 static inline int rtnrt_task_sleep(unsigned int millisecs)
00633 {
00634     return msleep_interruptible(millisecs);
00635 }
00636 
00637 #define rtnrt_ndelay(delay_nsecs)                           \
00638     ndelay(delay_nsecs)
00639 #define rtnrt_udelay(delay_usecs)                           \
00640     udelay(delay_usecs)
00641 #define rtnrt_mdelay(delay_msecs)                           \
00642     mdelay(delay_msecs)
00643 
00644 #endif
00645  /* }}} */
00647  /* {{{ */
00661 
00676 typedef unsigned long (*rtnrt_memcopy_func)(void              *to, 
00677                                             const void        *from, 
00678                                             unsigned long     count,
00679                                             void              *cookie);
00680 
00681 
00687 struct rtnrt_memcopy_desc {
00688     rtnrt_memcopy_func  function;       
00689     void                *cookie;        
00691 };
00692 
00702 static inline unsigned long rtnrt_memmove(void              *to,
00703                                          const void         *from,
00704                                          unsigned long      count,
00705                                          void               *cookie)
00706 {
00707     memmove(to, from, count);
00708     return 0;
00709 }
00710 
00720 static inline unsigned long rtnrt_copy_to_user(void              *to, 
00721                                               const void         *from,
00722                                               unsigned long      count,
00723                                               void               *cookie)
00724 {
00725     return copy_to_user(to, from, count);
00726 }
00727 
00740 static inline unsigned long rtnrt_copy_from_user(void              *to, 
00741                                                 const void         *from, 
00742                                                 unsigned long      count,
00743                                                 void               *cookie)
00744 {
00745     return copy_from_user(to, from, count);
00746 }
00747 
00748 #ifdef RT_RTDM
00749 
00762 static inline unsigned long rtnrt_copy_to_user_rt(void              *to, 
00763                                                  const void         *from, 
00764                                                  unsigned long      count,
00765                                                  void               *cookie)
00766 {
00767     rtdm_user_info_t *user_info = (rtdm_user_info_t *)cookie;
00768     
00769     if (user_info) {
00770         unsigned long ret;
00771         
00772         ret = rtdm_copy_to_user(user_info, to, from, count);
00773         return (ret < 0) ? count : 0;
00774     } else {
00775         memcpy(to, from, count);
00776         return 0;
00777     }
00778 }
00779 
00792 static inline unsigned long rtnrt_copy_from_user_rt(void              *to, 
00793                                                    const void         *from, 
00794                                                    unsigned long      count,
00795                                                    void               *cookie)
00796 {
00797     rtdm_user_info_t *user_info = (rtdm_user_info_t *)cookie;
00798 
00799     if (user_info) {
00800         unsigned long ret;
00801         
00802         ret = rtdm_copy_from_user(user_info, to, from, count);
00803         return (ret < 0) ? count : 0;
00804     } else {
00805         memcpy(to, from, count);
00806         return 0;
00807     }
00808 }
00809 
00810 #endif
00811 
00823 #define rtnrt_copy(desc, to, from, count)   \
00824     (desc)->function(to, from, count, (desc)->cookie)
00825  /* }}} */
00827  /* {{{ */
00857 
00858 #if defined(RT_RTDM) || defined(DOXYGEN)
00859 
00867 #define DEFINE_NRTSIG(name)                          \
00868     static rtdm_nrtsig_t name
00869 
00879 #define rtnrt_nrtsig_init(nrt_sig, handler)          \
00880     rtdm_nrtsig_init(nrt_sig, handler)
00881 
00888 #define rtnrt_nrtsig_destroy(nrt_sig)                \
00889     rtdm_nrtsig_destroy(nrt_sig)
00890 
00899 #define rtnrt_nrtsig_action(nrt_sig, handler)        \
00900     rtdm_nrtsig_pend(nrt_sig)
00901 
00906 typedef rtdm_nrtsig_t rtnrt_nrtsig_t;
00907 
00908 #else
00909 
00910 #define DEFINE_NRTSIG(name)
00911 
00912 #define rtnrt_nrtsig_init(nrt_sig, handler)      0
00913 
00914 #define rtnrt_nrtsig_destroy(nrt_sig) \
00915     do {} while (0)
00916 
00917 #define rtnrt_nrtsig_action(nrt_sig, handler)            \
00918     handler(NULL)
00919 
00920 typedef void * rtnrt_nrtsig_t;
00921 
00922 #endif
00923  /* }}} */
00925  /* {{{ */
00936 
00937 /* compatibility accross various RTDM versions */
00938 
00939 #if defined(RT_RTDM) || defined(DOXYGEN)
00940 #if !defined(RTDM_IRQTYPE_SHARED) || defined(DOXYGEN)
00941 
00947 #   define RTDM_IRQTYPE_SHARED      0
00948 #endif /* RTDM_IRQTYPE_SHARED */
00949 
00950 
00951 #if !defined(RTDM_IRQ_NONE) || defined(DOXYGEN)
00952 
00959 #   define RTDM_IRQ_NONE            0
00960 #endif /* RTDM_IRQ_NONE */
00961 
00962 #if !defined(RTDM_IRQ_HANDLED) || defined(DOXYGEN)
00963 
00970 #   define RTDM_IRQ_HANDLED         0
00971 #endif /* RTDM_IRQ_HANDLED */
00972 
00973 #if !defined(RTDM_IRQ_ENABLE) || defined(DOXYGEN)
00974 
00978 #define RTDM_IRQ_ENABLE             0
00979 #endif /* RTDM_IRQ_ENABLE */
00980 #endif /* RT_RTDM */
00981 
00982 #if defined(RT_RTDM) || defined(DOXYGEN)
00983 
01005 #define DECLARE_IRQ_PROXY(proxy_name, calling_function, arg_type)         \
01006     static int proxy_name(rtdm_irq_t *irq_handle)                         \
01007     {                                                                     \
01008         return calling_function(rtdm_irq_get_arg(irq_handle, arg_type));  \
01009     }
01010 
01016 #define RTNRT_IRQ_HANDLED                                                 \
01017     (RTDM_IRQ_HANDLED | RTDM_IRQ_ENABLE)
01018 
01024 #define RTNRT_IRQ_NONE                                                    \
01025     (RTDM_IRQ_NONE | RTDM_IRQ_ENABLE)
01026 
01031 typedef int rtnrt_irqreturn_t;
01032 
01052 #define rtnrt_register_interrupt_handler(rtdm_irq_handle,                 \
01053                                         interrupt_line,                   \
01054                                         interrupt_handler,                \
01055                                         shared,                           \
01056                                         device_name,                      \
01057                                         cookie)                           \
01058     rtdm_irq_request(rtdm_irq_handle, interrupt_line, int_handler,        \
01059             shared, device_name, cookie)
01060 
01068 #define rtnrt_irq_enable(rtdm_irq_handle)                                 \
01069     rtdm_irq_enable(rtdm_irq_handle)
01070 
01084 #define rtnrt_free_interrupt_handler(rtdm_irq_handle,                     \
01085                                     interrupt_line,                       \
01086                                     device_name)                          \
01087     rtdm_irq_free(rtdm_irq_handle);
01088 
01089 #else /* not RT_RTDM */
01090 
01091 #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,18))
01092 #define DECLARE_IRQ_PROXY(proxy_name, calling_function, arg_type)         \
01093     static irqreturn_t proxy_name(int              irq,                   \
01094                                       void             *dev_id,           \
01095                                       struct pt_regs   *regs)             \
01096     {                                                                     \
01097         return calling_function((arg_type *)dev_id);                      \
01098     }
01099 
01100 #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,19))
01101 #define DECLARE_IRQ_PROXY(proxy_name, calling_function, arg_type)         \
01102     static irqreturn_t proxy_name(int              irq,                   \
01103                                       void             *dev_id)           \
01104     {                                                                     \
01105         return calling_function((arg_type *)dev_id);                      \
01106     }
01107 #endif
01108 
01109 
01110 #define RTNRT_IRQ_HANDLED                                                 \
01111     IRQ_HANDLED
01112 
01113 #define RTNRT_IRQ_NONE                                                    \
01114     IRQ_NONE
01115 
01116 typedef irqreturn_t rtnrt_irqreturn_t;
01117 
01118 #define rtnrt_register_interrupt_handler(rtdm_irq_handle,                 \
01119                                         interrupt_line,                   \
01120                                         interrupt_handler,                \
01121                                         shared,                           \
01122                                         device_name,                      \
01123                                         cookie)                           \
01124     request_irq(interrupt_line, interrupt_handler, shared,                \
01125             device_name, cookie)
01126 
01127 #define rtnrt_irq_enable(rtdm_irq_handle)                                 \
01128     0
01129 
01130 #define rtnrt_free_interrupt_handler(rtdm_irq_handle,                     \
01131                                     interrupt_line,                       \
01132                                     device_name)                          \
01133     free_irq(interrupt_line, device_name)
01134 
01135 #endif /* RT_RTDM */
01136  /* }}} */
01138 
01139 
01140 #endif /* RT_NRT_H */
01141 
01142 /* vim: set ts=4 et sw=4 foldmethod=marker: */

Generated on Fri Mar 9 14:48:58 2007 for MOST Linux Drivers (Linux and RTAI) by  doxygen 1.5.0