base/include/asm-arm/arch-imx/rtai_timer.h

Go to the documentation of this file.
00001 /* 020222 asm-arm/arch-pxa/timer.h - ARM/PXA255 specific timer
00002 Don't include directly - it's included through asm-arm/rtai.h
00003 
00004 Copyright (c) 2006 Torsten Koschorrek, (koschorrek@synertronixx.de)
00005 Copyright (c) 2005 Luca Pizzi, (lucapizzi@hotmail.com)
00006 Copyright (c) 2005 Stefano Gafforelli, (stefano.gafforelli@tiscali.it)
00007 COPYRIGHT (C) 2002 Guennadi Liakhovetski, DSA GmbH (gl@dsa-ac.de)
00008 COPYRIGHT (C) 2002 Wolfgang Müller (wolfgang.mueller@dsa-ac.de)
00009 Copyright (c) 2001 Alex Züpke, SYSGO RTS GmbH (azu@sysgo.de)
00010 
00011 This program is free software; you can redistribute it and/or modify
00012 it under the terms of version 2 of the GNU General Public License as
00013 published by the Free Software Foundation.
00014 
00015 This program is distributed in the hope that it will be useful,
00016 but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 GNU General Public License for more details.
00019 
00020 You should have received a copy of the GNU General Public License
00021 along with this program; if not, write to the Free Software
00022 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023 */
00024 /*
00025 --------------------------------------------------------------------------
00026 Acknowledgements
00027 - Paolo Mantegazza  (mantegazza@aero.polimi.it)
00028     creator of RTAI 
00029 - port to imx architecture using both
00030   arch-pxa/rtai_timer.h and arch-ep9301/rtai_timer.h
00031   20060613: Torsten Koschorrek (koschorrek@synertronixx.de)
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         /* This is what just happened: we were setting a next timer
00052            interrupt in the scheduler, while a previously configured
00053            timer-interrupt happened, so, just restore the correct value
00054            of the match register and proceed as usual. Yes, we will
00055            have to re-calculate the next interrupt. */
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 /* PROTECT_TIMER */
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 /* PROTECT_TIMER */
00111 
00112     rtai_restore_flags(flags);
00113 }
00114 
00115 #endif /* _ASM_ARCH_RTAI_TIMER_H_ */

Generated on Tue Feb 2 17:46:04 2010 for RTAI API by  doxygen 1.4.7