📄 netprocess.c
字号:
/* * Function to process network packets and timeouts intermittently. * * (C) 2002 Compendium Technologies, Inc. * (C) 2002 Softools, Inc. * All rights reserved. * * This software is the proprietary information of Compendium Technologies, Inc. * and Softools, Inc. Use is subject to license terms. */#include "rabbitlwip.h"#include "lwip/netif.h"#include "lwip/sys.h"#include "lwip/memp.h"#include "RTK8019AS.h"#include <limits.h>#define RX_DEBUGunsigned char netProcessBusy = 0;extern unsigned char netCheckingTimeout;extern unsigned long netLastTimePeek;/* * Process (periodically) network traffic. This function can be run right from * an interrupt timer. */near void netProcess(void){ unsigned int gotPackets; unsigned long newTime; u16_t elapsedTime; // TODO: Socket replacement? ipset3(); if (netProcessBusy) { ipres(); return; } else { netProcessBusy = 1; ipres(); } // Decide if a timeout has occurred and call tcp_tmr if it has if (!netCheckingTimeout) { u16_t leftBeforeTimeout; struct sys_timeouts *timeouts; struct sys_timeout *tmptimeout; sys_timeout_handler h; void * arg; // If blocked somewhere else in sem_arch_wait(), we don't enter // this code because changing the milliseconds timer here will screw // things up. newTime = getMilliSeconds(); if (newTime < netLastTimePeek) { // Handle rollover, which will occur every 42? minutes elapsedTime = ULONG_MAX - netLastTimePeek + newTime; } else { elapsedTime = newTime - netLastTimePeek; } netLastTimePeek = newTime;#ifdef TIME_DEBUG printf("elapsed time: %d\n", elapsedTime);#endif timeouts = sys_arch_timeouts(); while (timeouts->next != NULL) { leftBeforeTimeout = timeouts->next->time;#ifdef TIME_DEBUG printf("timeout next time: %u\n", leftBeforeTimeout);#endif if (leftBeforeTimeout > 0) { if (leftBeforeTimeout <= elapsedTime) { elapsedTime -= leftBeforeTimeout; leftBeforeTimeout = 0; } else { leftBeforeTimeout -= elapsedTime; } } if (leftBeforeTimeout == 0) {#ifdef TIME_DEBUG puts("calling timeout\n");#endif /* If time == 0, a timeout occured before a message could be fetched. We should now call the timeout handler and deallocate the memory allocated for the timeout. */ tmptimeout = timeouts->next; timeouts->next = tmptimeout->next; h = tmptimeout->h; arg = tmptimeout->arg; memp_free(MEMP_SYS_TIMEOUT, tmptimeout); h(arg); } else { timeouts->next->time = leftBeforeTimeout;#ifdef TIME_DEBUG puts("not yet\n"); printf("still left: %u\n", leftBeforeTimeout);#endif break; } } }#ifdef DEBUG puts("+");#endif do { // Keep looping round robin through all the interface while packets // are being read struct netif * interface = netif_list; gotPackets = 0; while(interface != NULL) { // Try to read and route packets from each interface here // TODO: Different types of interfaces if (RTK8019AS_if_input(interface)) { gotPackets = 1;#ifdef RX_DEBUG printf("packet received\n");#endif } interface = interface->next; } } while(gotPackets);#ifdef DEBUG puts("-");#endif ipset3(); netProcessBusy = 0; ipres();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -