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.4 2006/10/08 16:48:07 haraldkipp 00037 * Documentation fixed 00038 * 00039 * Revision 1.3 2005/10/24 17:59:19 haraldkipp 00040 * Use correct header file, arm, not gba. 00041 * 00042 * Revision 1.2 2005/08/02 17:46:45 haraldkipp 00043 * Major API documentation update. 00044 * 00045 * Revision 1.1 2005/07/26 18:02:26 haraldkipp 00046 * Moved from dev. 00047 * 00048 * Revision 1.2 2005/07/20 09:17:26 haraldkipp 00049 * Default NUT_CPU_FREQ and NUT_TICK_FREQ added. 00050 * NutTimerIntr() removed, because we can use the hardware independent code. 00051 * 00052 * Revision 1.1 2005/05/27 17:16:40 drsung 00053 * Moved the file. 00054 * 00055 * Revision 1.5 2005/04/05 17:50:46 haraldkipp 00056 * Use register names in gba.h. 00057 * 00058 * Revision 1.4 2004/11/08 19:16:37 haraldkipp 00059 * Hacked in Gameboy timer support 00060 * 00061 * Revision 1.3 2004/10/03 18:42:21 haraldkipp 00062 * No GBA support yet, but let the compiler run through 00063 * 00064 * Revision 1.2 2004/09/08 10:19:39 haraldkipp 00065 * Running on AT91 and S3C, thanks to James Tyou 00066 * 00067 */ 00068 00069 #include <cfg/arch.h> 00070 #include <arch/arm.h> 00071 #include <dev/irqreg.h> 00072 00077 00078 #ifndef NUT_CPU_FREQ 00079 #define NUT_CPU_FREQ 1000000UL 00080 #endif 00081 00082 #ifndef NUT_TICK_FREQ 00083 #define NUT_TICK_FREQ 1000UL 00084 #endif 00085 00086 static void (*os_handler) (void *); 00087 00103 void NutDelay(u_char ms) 00104 { 00105 u_short delay_cnt = 2400; //*KU* for 14.745600 MHz Clock 00106 u_short delay_cnt_buffer; 00107 00108 while (ms--) { 00109 delay_cnt_buffer = delay_cnt; 00110 while (delay_cnt_buffer--); 00111 } 00112 } 00113 00114 00118 void Timer3Entry(void *arg) 00119 { 00120 outw(REG_IF, INT_TMR3); 00121 os_handler(0); 00122 } 00123 00135 void NutRegisterTimer(void (*handler) (void *)) 00136 { 00137 os_handler = handler; 00138 00139 00140 /* Disable master interrupt. */ 00141 outw(REG_IME, 0); 00142 00143 /* Set global interrupt vector. */ 00144 NutRegisterIrqHandler(&sig_TMR3, Timer3Entry, 0); 00145 00146 /* Enable timer and timer interrupts. */ 00147 outdw(REG_TMR3CNT, TMR_IRQ_ENA | TMR_ENA | 48756); 00148 00149 /* Enable timer 3 interrupts. */ 00150 outw(REG_IE, inw(REG_IE) | INT_TMR3); 00151 00152 /* Enable master interrupt. */ 00153 outw(REG_IME, 1); 00154 } 00155 00161 u_long NutGetCpuClock(void) 00162 { 00163 return NUT_CPU_FREQ; 00164 } 00165 00171 u_long NutGetTickClock(void) 00172 { 00173 return NUT_TICK_FREQ; 00174 } 00175 00179 u_long NutTimerMillisToTicks(u_long ms) 00180 { 00181 return ms * 1000L / NutGetTickClock(); 00182 } 00183