ostimer.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2000-2004 by ETH Zurich
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 ETH ZURICH 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 ETH ZURICH
00021  *  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  * unix_timer.c - unix emulation of a real-time clock that is used as a timer
00036  *
00037  * 2004.04.01 Matthias Ringwald <matthias.ringwald@inf.ethz.ch>
00038  *
00039  */
00040 
00041 #ifdef __CYGWIN__
00042 #include <sys/features.h>
00043 #include <sys/signal.h>
00044 #endif
00045 
00046 #include <cfg/os.h>
00047 #include <dev/irqreg.h>
00048 #include <sys/atom.h>
00049 #include <unistd.h>
00050 
00051 
00052 #ifndef NUT_CPU_FREQ
00053 #define NUT_CPU_FREQ    14000000UL
00054 #endif
00055 
00056 extern int timer_count;
00057 
00058 /* timer thread, generating ms ticks */
00059 static pthread_t timer_thread;
00060 
00067 #define SCALE   1
00068 
00069 void *NutTimerEmulation(void *arg)
00070 {
00071     uint8_t trigger_irq = (uint8_t) (uintptr_t) arg;
00072 
00073     // non-nut thread => not interested in SIGUSR1 (IRQ signals)
00074     pthread_sigmask(SIG_BLOCK, &irq_signal, 0);
00075 
00076     for( ;; ) {
00077         usleep( 1000 * SCALE );
00078 
00079         NutUnixRaiseInterrupt(trigger_irq);
00080     }
00081     return NULL;
00082 }
00083 
00090 void NutRegisterTimer(void (*handler) (void *))
00091 {
00092     uint8_t timerIrqNr = IRQ_TIMER0;
00093 
00094     // register irq handler
00095     NutRegisterIrqHandler(timerIrqNr, handler, (void *) 0);
00096 
00097     // create rtc timer simulation
00098     pthread_create(&timer_thread, NULL, NutTimerEmulation, (void *) (uintptr_t) timerIrqNr);
00099 }
00100 
00106 uint32_t NutArchClockGet(int idx)
00107 {
00108     return NUT_CPU_FREQ;
00109 }
00110 
00116 uint32_t NutGetTickClock(void)
00117 {
00118     return 1000UL;
00119 }
00120 
00124 uint32_t NutTimerMillisToTicks(uint32_t ms)
00125 {
00126     return ms;
00127 }

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