00001 /*############################################################################## 00002 00003 nIP - nano IP stack 00004 00005 File : time.c 00006 00007 Description : Functions to handle time 00008 00009 Copyright notice: 00010 00011 Copyright (C) 2005 - 00012 Andreas Dittrich, dittrich@informatik.hu-berlin.de 00013 Jon Kowal, kowal@informatik.hu-berlin.de 00014 00015 This program 7is free software; you can redistribute it and/or 00016 modify it under the terms of the GNU General Public License 00017 as published by the Free Software Foundation; either version 2 00018 of the License, or (at your option) any later version. 00019 00020 This program is distributed in the hope that it will be useful, 00021 but WITHOUT ANY WARRANTY; without even the implied warranty of 00022 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00023 GNU General Public License for more details. 00024 00025 You should have received a copy of the GNU General Public License 00026 along with this program; if not, write to the Free Software 00027 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00028 00029 #############################################################################*/ 00030 00031 #include <stdint.h> 00032 #include "time.h" 00033 #include "avr/interrupt.h" 00034 #include "dispatcher.h" 00035 00036 /** Time in seconds since 0 hours, 0 minutes, 0 seconds, January 1st, 1970, UTC. 00037 * As the clock is being set it's value may be increased or decreased and is 00038 * therefor not usable for linear time measurement. Use the below tickcount 00039 * variable for that. */ 00040 uint32_t clock; 00041 00042 /** Miliseconds of clock with a precision of 1/256s */ 00043 uint8_t mclock; 00044 00045 /** Time in seconds since system start. Use this value for timeout measurement 00046 * as it will always be increased linearly. */ 00047 uint32_t tickcount; 00048 00049 00050 #if USE_CLOCK 00051 00052 /** interrupt service routine for clock timer 00053 */ 00054 ISR (TIMER1_OVF_vect) 00055 { 00056 00057 if ( mclock == 0xFF ) { 00058 00059 // /*debug*/ LEDS = (LEDS & ~0x20) + ((LEDS + 0x20) & 0x20); 00060 00061 // increment seconds 00062 clock++; 00063 tickcount++; 00064 00065 // check timer for all network interfaces 00066 #if (NIP_DISP_ENABLE==1) 00067 nip_disp_notify( NIP_DISP_TIMER ); 00068 nip_disp_notify_if( 0, NIP_DISP_IF_TIMER ); 00069 // nip_dispatcher(); 00070 #endif 00071 // You can add Hooks for any modules that depend on the timer-interrupt 00072 // DHCP_Timer(); 00073 00074 // check TCP timer 00075 // TCP_Check_Timer( NULL ); 00076 } 00077 00078 mclock = mclock + 1; 00079 TCNT1 = TCNT1 - (SYSCLK / 1024 / 256); 00080 } 00081 00082 /** Initialize and start timer interrupt for clock and tickcount 00083 */ 00084 void Start_Clock (void) 00085 { 00086 //Interrupt for the Clock enable 00087 // timer_enable_int(_BV(TOIE1)); 00088 00089 TIMSK = _BV(TOIE1);// | _BV(TICIE); 00090 // LEDCTRL=LED_MASK; 00091 00092 //Setzen des Prescaler auf 1024 00093 TCCR1B |= (1<<CS10 | 0<<CS11 | 1<<CS12); 00094 return; 00095 } 00096 00097 #endif //#if USE_CLOCK 00098