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 
00031 
00032 
00033 
00034 #ifndef _ASM_ARCH_RTAI_TIMER_H_
00035 #define _ASM_ARCH_RTAI_TIMER_H_
00036 
00037 #include <linux/time.h>
00038 #include <linux/timer.h>
00039 #include <asm/mach/irq.h>
00040 #include <linux/timex.h>
00041 #include <asm/arch/imx-regs.h>
00042 
00043 static inline int rtai_timer_irq_ack( void )
00044 {
00045     if (IMX_TSTAT(0))
00046         IMX_TSTAT(0) = 0x0;
00047 
00048     rt_unmask_irq(RTAI_TIMER_IRQ);
00049 
00050     if ( (int)(IMX_TCN(0) - IMX_TCMP(0)) < 0 ) {
00051         
00052 
00053 
00054 
00055 
00056         IMX_TCMP(0) = IMX_TCN(0) - 1;
00057     }
00058 
00059     return 0;
00060 }
00061 
00062 union rtai_tsc {
00063     unsigned long long tsc;
00064     unsigned long hltsc[2];
00065 };
00066 extern volatile union rtai_tsc rtai_tsc;
00067 
00068 static inline RTIME rtai_rdtsc(void)
00069 {
00070     RTIME ts;
00071     unsigned long flags, count;
00072 
00073     rtai_save_flags_and_cli(flags);
00074 
00075     if ((count = IMX_TCN(0)) < rtai_tsc.hltsc[0])
00076         rtai_tsc.hltsc[1]++;
00077 
00078     rtai_tsc.hltsc[0] = count;
00079     ts = rtai_tsc.tsc;
00080 
00081     rtai_restore_flags(flags);
00082 
00083     return ts;
00084 }
00085 
00086 #define PROTECT_TIMER
00087 #define SETUP_TIME_TICKS (0)
00088 
00089 static inline void rt_set_timer_delay(int delay)
00090 {
00091     unsigned long flags;
00092     unsigned long next_match;
00093 
00094 #ifdef PROTECT_TIMER
00095     if ( delay > LATCH )
00096         delay = LATCH;
00097 #endif 
00098 
00099     rtai_save_flags_and_cli(flags);
00100 
00101     if ( delay )
00102         next_match = IMX_TCMP(0) = delay + IMX_TCN(0);
00103     else
00104         next_match = ( IMX_TCMP(0) += rt_times.periodic_tick );
00105 
00106 #ifdef PROTECT_TIMER
00107     while ((int)(next_match - IMX_TCN(0)) < 2 * SETUP_TIME_TICKS ) {
00108         next_match = IMX_TCMP(0) = IMX_TCN(0) + 4 * SETUP_TIME_TICKS;
00109     }
00110 #endif 
00111 
00112     rtai_restore_flags(flags);
00113 }
00114 
00115 #endif