base/include/asm-arm/arch-pxa/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) 2005 Luca Pizzi, (lucapizzi@hotmail.com)
00005 Copyright (c) 2005 Stefano Gafforelli, (stefano.gafforelli@tiscali.it)
00006 COPYRIGHT (C) 2002 Guennadi Liakhovetski, DSA GmbH (gl@dsa-ac.de)
00007 COPYRIGHT (C) 2002 Wolfgang Müller (wolfgang.mueller@dsa-ac.de)
00008 Copyright (c) 2001 Alex Züpke, SYSGO RTS GmbH (azu@sysgo.de)
00009 
00010 This program is free software; you can redistribute it and/or modify
00011 it under the terms of version 2 of the GNU General Public License as
00012 published by the Free Software Foundation.
00013 
00014 This program is distributed in the hope that it will be useful,
00015 but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 GNU General Public License for more details.
00018 
00019 You should have received a copy of the GNU General Public License
00020 along with this program; if not, write to the Free Software
00021 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 */
00023 /*
00024 --------------------------------------------------------------------------
00025 Acknowledgements
00026 - Paolo Mantegazza  (mantegazza@aero.polimi.it)
00027     creator of RTAI 
00028 */
00029 
00030 #ifndef _ASM_ARCH_RTAI_TIMER_H_
00031 #define _ASM_ARCH_RTAI_TIMER_H_
00032 
00033 //#include <asm/proc/hard_system.h>
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         /* This is what just happened: we were setting a next timer interrupt
00046            in the scheduler, while a previously configured timer-interrupt
00047            happened, so, just restore the correct value of the match register and
00048            proceed as usual. Yes, we will have to re-calculate the next interrupt. */
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 /* Current version */
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 //      next_match = OSMR0 = delay + rtai_tsc.hltsc[0];
00094     else
00095         next_match = ( OSMR0 += rt_times.periodic_tick );
00096 //      next_match = OSMR0 = ((unsigned long *)&rt_times.intr_time)[0];
00097 
00098 #ifdef PROTECT_TIMER
00099     while ((int)(next_match - OSCR) < 2 * SETUP_TIME_TICKS ) {
00100         OSSR = OSSR_M0;  /* Clear match on timer 0 */
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 

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