Main Page   Modules   Data Structures   File List   Data Fields   Globals   Related Pages   Examples  

/opentcp/timers.c

Go to the documentation of this file.
00001 /*
00002  *Copyright (c) 2000-2002 Viola Systems Ltd.
00003  *All rights reserved.
00004  *
00005  *Redistribution and use in source and binary forms, with or without 
00006  *modification, are permitted provided that the following conditions 
00007  *are met:
00008  *
00009  *1. Redistributions of source code must retain the above copyright 
00010  *notice, this list of conditions and the following disclaimer.
00011  *
00012  *2. Redistributions in binary form must reproduce the above copyright 
00013  *notice, this list of conditions and the following disclaimer in the 
00014  *documentation and/or other materials provided with the distribution.
00015  *
00016  *3. The end-user documentation included with the redistribution, if 
00017  *any, must include the following acknowledgment:
00018  *      "This product includes software developed by Viola 
00019  *      Systems (http://www.violasystems.com/)."
00020  *
00021  *Alternately, this acknowledgment may appear in the software itself, 
00022  *if and wherever such third-party acknowledgments normally appear.
00023  *
00024  *4. The names "OpenTCP" and "Viola Systems" must not be used to 
00025  *endorse or promote products derived from this software without prior 
00026  *written permission. For written permission, please contact 
00027  *opentcp@opentcp.org.
00028  *
00029  *5. Products derived from this software may not be called "OpenTCP", 
00030  *nor may "OpenTCP" appear in their name, without prior written 
00031  *permission of the Viola Systems Ltd.
00032  *
00033  *THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED 
00034  *WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
00035  *MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
00036  *IN NO EVENT SHALL VIOLA SYSTEMS LTD. OR ITS CONTRIBUTORS BE LIABLE 
00037  *FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
00038  *CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
00039  *SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 
00040  *BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
00041  *WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 
00042  *OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 
00043  *EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00044  *====================================================================
00045  *
00046  *OpenTCP is the unified open source TCP/IP stack available on a series 
00047  *of 8/16-bit microcontrollers, please see <http://www.opentcp.org>.
00048  *
00049  *For more information on how to network-enable your devices, or how to 
00050  *obtain commercial technical support for OpenTCP, please see 
00051  *<http://www.violasystems.com/>.
00052  */
00053 
00074 #include <inet/debug.h>
00075 #include <inet/datatypes.h>
00076 #include <inet/timers.h>
00077 #include <inet/system.h>
00078 
00086 struct
00087 {
00088         UINT32 value;
00089         UINT8 free;
00090 } timer_pool[NUMTIMERS];
00091 
00105 void timer_pool_init (void)
00106 {
00107         UINT8 i;
00108 
00109         for( i=0; i < NUMTIMERS; i++) {
00110                 timer_pool[i].value = 0;
00111                 timer_pool[i].free = TRUE;
00112                 
00113         }
00114                 
00115 
00116 }
00117 
00118 
00131 UINT8 get_timer (void)
00132 {
00133         
00134         UINT8 i;
00135         UINT8 first_match;
00136         
00137         
00138         for( i=0; i < NUMTIMERS; i++) {
00139                 if( timer_pool[i].free == TRUE ) {
00140                         /* We found a free timer! */
00141                         /* Mark is reserved               */
00142                         
00143                         timer_pool[i].free = FALSE;
00144                         first_match = i;
00145                         return first_match;             /* Return Handle        */
00146                 }
00147         
00148         }
00149         
00150         /* Error Check  */
00151         
00152         TMR_DEBUGOUT("No Timers, Resetting..\n\r");
00153         RESET_SYSTEM();
00154         
00155 
00156 }
00157 
00158 
00169 void free_timer (UINT8 nbr)
00170 {
00171         /* Make a simple check */
00172         
00173         if( nbr > (NUMTIMERS-1) ) 
00174                 return; 
00175 
00176         timer_pool[nbr].free = TRUE;
00177 
00178 }
00179 
00180 
00194 void init_timer ( UINT8 nbr, UINT32 tout )
00195 {
00196         /* Make a simple check */
00197         
00198         UINT32 val;
00199         
00200         if( nbr > (NUMTIMERS-1) ) 
00201                 return; 
00202 
00203         if( timer_pool[nbr].free == TRUE ) 
00204                 return;
00205                 
00206         /* All OK                               */
00207         
00208         val = tout;
00209         
00210         OS_EnterCritical();
00211         
00212         /* Normalize seconds to timer tics      */
00213         
00214         timer_pool[nbr].value = val;
00215 
00216         OS_ExitCritical();
00217 
00218 } 
00219 
00233 UINT32 check_timer (UINT8 nbr)
00234 {
00235 
00236         return timer_pool[nbr].value;
00237 
00238 }
00239 
00240 
00248 void decrement_timers (void)
00249 {
00250         UINT8 i;
00251 
00252         /* Go Through Timers */
00253         
00254         for( i=0; i<NUMTIMERS; i++ ) {
00255                 if( (timer_pool[i].free == FALSE) && (timer_pool[i].value != 0))
00256                         timer_pool[i].value --;
00257         }
00258 }

Generated on Sun Aug 3 20:33:00 2003 for OpenTCP by doxygen1.2.18