00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef _ASM_ARCH_RTAI_TIMER_H_
00031 #define _ASM_ARCH_RTAI_TIMER_H_
00032
00033
00034 #include <linux/time.h>
00035 #include <linux/timer.h>
00036 #include <asm/mach/irq.h>
00037 #include <linux/timex.h>
00038
00039
00040 static inline int rtai_timer_irq_ack( void )
00041 {
00042 OSSR = OSSR_M0;
00043 rt_unmask_irq(RTAI_TIMER_IRQ);
00044 if ( (int)(OSCR - OSMR0) < 0 )
00045
00046
00047
00048
00049 OSMR0 = OSCR - 1;
00050 return 0;
00051 }
00052
00053 union rtai_tsc {
00054 unsigned long long tsc;
00055 unsigned long hltsc[2];
00056 };
00057 extern volatile union rtai_tsc rtai_tsc;
00058
00059 static inline RTIME rtai_rdtsc(void)
00060 {
00061 RTIME ts;
00062 unsigned long flags, count;
00063
00064 rtai_save_flags_and_cli(flags);
00065
00066 if ( ( count = OSCR ) < rtai_tsc.hltsc[0] )
00067 rtai_tsc.hltsc[1]++;
00068 rtai_tsc.hltsc[0] = count;
00069 ts = rtai_tsc.tsc;
00070 rtai_restore_flags(flags);
00071
00072 return ts;
00073 }
00074
00075 #define PROTECT_TIMER
00076
00077
00078
00079 static inline void rt_set_timer_match_reg(int delay)
00080 {
00081 unsigned long flags;
00082 unsigned long next_match;
00083
00084 #ifdef PROTECT_TIMER
00085 if ( delay > LATCH )
00086 delay = LATCH;
00087 #endif
00088
00089 rtai_save_flags_and_cli(flags);
00090
00091 if ( delay )
00092 next_match = OSMR0 = delay + OSCR;
00093
00094 else
00095 next_match = ( OSMR0 += rt_times.periodic_tick );
00096
00097
00098 #ifdef PROTECT_TIMER
00099 while ((int)(next_match - OSCR) < 2 * SETUP_TIME_TICKS ) {
00100 OSSR = OSSR_M0;
00101 next_match = OSMR0 = OSCR + 4 * SETUP_TIME_TICKS;
00102 }
00103 #endif
00104
00105 rtai_restore_flags(flags);
00106 }
00107 #endif
00108
00109 #define rt_set_timer_delay(x) rt_set_timer_match_reg(x)
00110
00111
00112