mirror of
https://github.com/ep00ch/lwip-contrib-mac.git
synced 2024-07-17 08:28:56 +00:00
Changed timer implementation a little (static- instead of global variables); minor layout changes to help beginners.
This commit is contained in:
parent
831ad1fe53
commit
e4543e2844
@ -70,31 +70,39 @@ void shutdown_adapter(void);
|
|||||||
void update_adapter(void);
|
void update_adapter(void);
|
||||||
|
|
||||||
#if NO_SYS
|
#if NO_SYS
|
||||||
/* functions used for timer execution */
|
/* port-defined functions used for timer execution */
|
||||||
void sys_init_timing();
|
void sys_init_timing();
|
||||||
u32_t sys_get_ms();
|
u32_t sys_get_ms();
|
||||||
|
#endif /* NO_SYS*/
|
||||||
|
|
||||||
/* globales variables for timer execution */
|
/* globales variables for netifs */
|
||||||
int last_time;
|
/* THE ethernet interface */
|
||||||
int timerTcpFast, timerTcpSlow, timerArp;
|
struct netif netif;
|
||||||
int timerDhcpFine, timerDhcpCoarse, timerIpReass;
|
#if LWIP_HAVE_LOOPIF
|
||||||
int timerAutoIP, timerIgmp;
|
/* THE loopback interface */
|
||||||
|
struct netif loop_netif;
|
||||||
|
#endif /* LWIP_HAVE_LOOPIF */
|
||||||
|
|
||||||
void timers_init()
|
|
||||||
|
#if NO_SYS
|
||||||
|
/* special functions used for NO_SYS=1 only */
|
||||||
|
static void
|
||||||
|
nosys_init()
|
||||||
{
|
{
|
||||||
last_time = clock();
|
sys_init_timing();
|
||||||
timerTcpFast = 0;
|
lwip_init();
|
||||||
timerTcpSlow = 0;
|
|
||||||
timerArp = 0;
|
|
||||||
timerDhcpFine = 0;
|
|
||||||
timerDhcpCoarse = 0;
|
|
||||||
timerIpReass = 0;
|
|
||||||
timerAutoIP = 0;
|
|
||||||
timerIgmp = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void timers_update()
|
/* get the current time and see if any timer has expired */
|
||||||
|
static void
|
||||||
|
timers_update()
|
||||||
{
|
{
|
||||||
|
/* static variables for timer execution, initialized to zero! */
|
||||||
|
static int last_time,
|
||||||
|
timerTcpFast, timerTcpSlow, timerArp,
|
||||||
|
timerDhcpFine, timerDhcpCoarse, timerIpReass,
|
||||||
|
timerAutoIP, timerIgmp;
|
||||||
|
|
||||||
int cur_time;
|
int cur_time;
|
||||||
int time_diff;
|
int time_diff;
|
||||||
|
|
||||||
@ -166,29 +174,12 @@ void timers_update()
|
|||||||
}
|
}
|
||||||
#endif /* LWIP_IGMP */
|
#endif /* LWIP_IGMP */
|
||||||
}
|
}
|
||||||
|
|
||||||
void nosys_init()
|
|
||||||
{
|
|
||||||
lwip_init();
|
|
||||||
sys_init_timing();
|
|
||||||
timers_init();
|
|
||||||
}
|
|
||||||
#else /* NO_SYS */
|
|
||||||
#define timers_init()
|
|
||||||
#define timers_update()
|
|
||||||
#define nosys_init()
|
|
||||||
#endif /* NO_SYS */
|
#endif /* NO_SYS */
|
||||||
|
|
||||||
/* THE ethernet interface */
|
|
||||||
struct netif netif;
|
|
||||||
#if LWIP_HAVE_LOOPIF
|
|
||||||
/* THE loopback interface */
|
|
||||||
struct netif loop_netif;
|
|
||||||
#endif /* LWIP_HAVE_LOOPIF */
|
|
||||||
|
|
||||||
/* a simple multicast test */
|
/* a simple multicast test */
|
||||||
#if LWIP_UDP && LWIP_IGMP
|
#if LWIP_UDP && LWIP_IGMP
|
||||||
void mcast_init(void)
|
static void
|
||||||
|
mcast_init(void)
|
||||||
{
|
{
|
||||||
struct udp_pcb *pcb;
|
struct udp_pcb *pcb;
|
||||||
struct pbuf* p;
|
struct pbuf* p;
|
||||||
@ -220,7 +211,8 @@ void mcast_init(void)
|
|||||||
#endif /* LWIP_UDP && LWIP_IGMP*/
|
#endif /* LWIP_UDP && LWIP_IGMP*/
|
||||||
|
|
||||||
/* This function initializes all network interfaces */
|
/* This function initializes all network interfaces */
|
||||||
void my_netif_init()
|
static void
|
||||||
|
msvc_netif_init()
|
||||||
{
|
{
|
||||||
struct ip_addr ipaddr, netmask, gw;
|
struct ip_addr ipaddr, netmask, gw;
|
||||||
#if LWIP_HAVE_LOOPIF
|
#if LWIP_HAVE_LOOPIF
|
||||||
@ -270,7 +262,7 @@ void main_loop()
|
|||||||
tcpip_init(0,0);
|
tcpip_init(0,0);
|
||||||
#endif /* NO_SYS */
|
#endif /* NO_SYS */
|
||||||
|
|
||||||
my_netif_init();
|
msvc_netif_init();
|
||||||
|
|
||||||
#if LWIP_UDP && LWIP_IGMP
|
#if LWIP_UDP && LWIP_IGMP
|
||||||
mcast_init();
|
mcast_init();
|
||||||
@ -282,8 +274,10 @@ void main_loop()
|
|||||||
#endif /* LWIP_TCP */
|
#endif /* LWIP_TCP */
|
||||||
|
|
||||||
while (!_kbhit()) {
|
while (!_kbhit()) {
|
||||||
|
#if NO_SYS
|
||||||
/* handle timers with NO_SYS=1 */
|
/* handle timers with NO_SYS=1 */
|
||||||
timers_update();
|
timers_update();
|
||||||
|
#endif /* NO_SYS */
|
||||||
|
|
||||||
/* check for packets */
|
/* check for packets */
|
||||||
update_adapter();
|
update_adapter();
|
||||||
|
Loading…
Reference in New Issue
Block a user