ostimer_gba.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2001-2005 by egnite Software GmbH. All rights reserved.
00003  *
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions
00006  * are met:
00007  *
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. Neither the name of the copyright holders nor the names of
00014  *    contributors may be used to endorse or promote products derived
00015  *    from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY EGNITE SOFTWARE GMBH AND CONTRIBUTORS
00018  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00019  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00020  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL EGNITE
00021  * SOFTWARE GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00022  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00023  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
00024  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
00025  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00026  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
00027  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00028  * SUCH DAMAGE.
00029  *
00030  * For additional information see http://www.ethernut.de/
00031  *
00032  */
00033 
00034 /*
00035  * $Log: ostimer_gba.c,v $
00036  * Revision 1.5  2008/07/08 08:25:04  haraldkipp
00037  * NutDelay is no more architecture specific.
00038  * Number of loops per millisecond is configurable or will be automatically
00039  * determined.
00040  * A new function NutMicroDelay provides shorter delays.
00041  *
00042  * Revision 1.4  2006/10/08 16:48:07  haraldkipp
00043  * Documentation fixed
00044  *
00045  * Revision 1.3  2005/10/24 17:59:19  haraldkipp
00046  * Use correct header file, arm, not gba.
00047  *
00048  * Revision 1.2  2005/08/02 17:46:45  haraldkipp
00049  * Major API documentation update.
00050  *
00051  * Revision 1.1  2005/07/26 18:02:26  haraldkipp
00052  * Moved from dev.
00053  *
00054  * Revision 1.2  2005/07/20 09:17:26  haraldkipp
00055  * Default NUT_CPU_FREQ and NUT_TICK_FREQ added.
00056  * NutTimerIntr() removed, because we can use the hardware independent code.
00057  *
00058  * Revision 1.1  2005/05/27 17:16:40  drsung
00059  * Moved the file.
00060  *
00061  * Revision 1.5  2005/04/05 17:50:46  haraldkipp
00062  * Use register names in gba.h.
00063  *
00064  * Revision 1.4  2004/11/08 19:16:37  haraldkipp
00065  * Hacked in Gameboy timer support
00066  *
00067  * Revision 1.3  2004/10/03 18:42:21  haraldkipp
00068  * No GBA support yet, but let the compiler run through
00069  *
00070  * Revision 1.2  2004/09/08 10:19:39  haraldkipp
00071  * Running on AT91 and S3C, thanks to James Tyou
00072  *
00073  */
00074 
00075 #include <cfg/arch.h>
00076 #include <arch/arm.h>
00077 #include <dev/irqreg.h>
00078 
00083 
00084 #ifndef NUT_CPU_FREQ
00085 #define NUT_CPU_FREQ    1000000UL
00086 #endif
00087 
00088 #ifndef NUT_TICK_FREQ
00089 #define NUT_TICK_FREQ   1000UL
00090 #endif
00091 
00092 static void (*os_handler) (void *);
00093 
00097 void Timer3Entry(void *arg)
00098 {
00099     outw(REG_IF, INT_TMR3);
00100     os_handler(0);
00101 }
00102 
00114 void NutRegisterTimer(void (*handler) (void *))
00115 {
00116     os_handler = handler;
00117 
00118 
00119     /* Disable master interrupt. */
00120     outw(REG_IME, 0);
00121 
00122     /* Set global interrupt vector. */
00123     NutRegisterIrqHandler(&sig_TMR3, Timer3Entry, 0);
00124 
00125     /* Enable timer and timer interrupts. */
00126     outdw(REG_TMR3CNT, TMR_IRQ_ENA | TMR_ENA | 48756);
00127 
00128     /* Enable timer 3 interrupts. */
00129     outw(REG_IE, inw(REG_IE) | INT_TMR3);
00130 
00131     /* Enable master interrupt. */
00132     outw(REG_IME, 1);
00133 }
00134 
00140 u_long NutGetCpuClock(void)
00141 {
00142     return NUT_CPU_FREQ;
00143 }
00144 
00150 u_long NutGetTickClock(void)
00151 {
00152     return NUT_TICK_FREQ;
00153 }
00154 
00158 u_long NutTimerMillisToTicks(u_long ms)
00159 {
00160     return ms * 1000L / NutGetTickClock();
00161 }
00162 

© 2000-2007 by egnite Software GmbH - visit http://www.ethernut.de/