📄 timeouts.c
字号:
/* * FILENAME: timeouts.c * * Copyright 2000-2004 By InterNiche Technologies Inc. All rights reserved * * Handles NicheTask task & application interval timers. * * MODULE: NTF * * ROUTINES: check_interval_timers(), inet_timer(), in_timerkill(), * ROUTINES: in_timerset(), port_1s_callout(), * * PORTABLE: yes */#include "license.h"#include "ipport.h"#ifdef INICHE_TIMERS /* build using interval timers? */#include "intimers.h"static void check_interval_timers(void);#endif#ifdef USE_COMPORTextern void uart_check(void);#endifunsigned long nextppp = 0L; /* tick for next call to ppp timer */void (*port_1s_callout)(void) = NULL;/* FUNCTION: inet_timer() * * This handles all TCP/IP related timeouts. Ideally this should be * called about 10 times a second; and no less than twice a second * (The minimum for TCP timeouts). Does NOT handle most * application timeouts. * * * PARAM1: void * * RETURNS: */voidinet_timer(void){#ifdef INICHE_TIMERS /* interval timers? */ check_interval_timers();#endif#ifdef USE_COMPORT uart_check();#endif /* Some timer routines only need calling once a second: */ if ((nextppp < cticks) || /* next call to PPP is due */ (nextppp > (cticks+(10*TPS))) ) /* for when cticks wraps */ { nextppp = cticks + TPS; if (port_1s_callout != NULL) (*port_1s_callout)(); }}#ifdef INICHE_TIMERSstruct intimer intimers[NUM_INTIMERS];/* FUNCTION: check_interval_timers() * * Check to see if any interval timers are ready to fire. * * RETURNS: NA */static int numtimers = 0; /* number of active timers */static voidcheck_interval_timers(){ int i; int found = 0; /* number of valid timers found */ /* if no timers, just return */ if(numtimers == 0) return; /* loop throught the timer list looking for active timers ready to fire */ for(i = 0; i < NUM_INTIMERS; i++) { if(intimers[i].callback) /* is this timer active? */ { if(intimers[i].tmo < cticks) /* timer ready fire? */ { intimers[i].tmo = intimers[i].interval + cticks; /* set next tmo */ intimers[i].callback(intimers[i].parm); /* call user routine */ } /* If we've examined all the active timers, return */ if(++found >= numtimers) return; } }}/* FUNCTION: in_timerset() * * Create an interval timer * * PARAM1: callback routine * PARAM2: number of milliseconds between callback calls * PARAM3: parameter to pass to callbacks * * RETURNS: timer ID if OK, else if table is full. */longin_timerset(void (*callback)(long), long msecs, long parm){ int i; for(i = 0; i < NUM_INTIMERS; i++) { if(intimers[i].callback == NULL) { /* found empty table entry, set up new timer */ intimers[i].callback = callback; intimers[i].parm = parm; /* set interval, in TPS (cticks) units */ intimers[i].interval = (msecs * TPS)/1000; intimers[i].tmo = intimers[i].interval + cticks; /* first tmo */ numtimers++; return (long)&intimers[i]; } } return 0;}/* FUNCTION: in_timerkill() * * Delete a timer created previously by a call to in_timerset() * * PARAM1: long timer Address of the timer to delete. * * RETURNS: 0 if OK, ENP error if timer not in list. */intin_timerkill(long timer){ int i; for(i = 0; i < NUM_INTIMERS; i++) { if(timer == (long)&intimers[i]) { intimers[i].callback = NULL; numtimers--; return 0; /* OK return */ } } dtrap(); /* timer to kill not found */ return ENP_PARAM;}#endif /* INICHE_TIMERS */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -