Skip to content

Commit aac4e7e

Browse files
committed
apps-conf.h / uip-conf.h / udpapp.h / stack.c
- Minor cleanup - Can now set most uip-conf.h settings from apps-conf.h. Users only need modify one file for most common stack setting changes - Socket (TCP) and UDP app can now be configured simultaneously (allows for DNS/DHCP + TCP app scenarios) WiShield::init() / WiShield.cpp/h - now returns boolean for success/fail - now takes seconds parameter to timeout connection attempt after seconds amount of time - default init now an overload which calls real version with 60 seconds timeout
1 parent b7dfe4c commit aac4e7e

File tree

6 files changed

+49
-20
lines changed

6 files changed

+49
-20
lines changed

WiShield.cpp

+15-4
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@ extern "C" {
4646
#include "WProgram.h"
4747
#include "WiShield.h"
4848

49-
void WiShield::init()
49+
boolean WiShield::init(U8 seconds)
5050
{
51+
boolean retVal = false;
5152
zg_init();
5253

5354
#ifdef USE_DIG0_INTR
@@ -61,11 +62,21 @@ void WiShield::init()
6162
PCMSK0 |= (1<<PCINT0);
6263
#endif
6364

64-
while(zg_get_conn_state() != 1) {
65-
zg_drv_process();
65+
// TODO: potential for rollover bug after ~58 days...
66+
unsigned long time = millis();
67+
while(time + (seconds * 1000) > millis()) {
68+
if(1 != zg_get_conn_state()) {
69+
zg_drv_process();
70+
}
71+
else {
72+
retVal = true;
73+
break;
74+
}
6675
}
67-
76+
6877
stack_init();
78+
79+
return retVal;
6980
}
7081

7182
void WiShield::run()

WiShield.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ extern "C" {
4444

4545
class WiShield {
4646
public:
47-
void init();
47+
boolean init() {return init(60);}
48+
boolean init(U8 seconds);
4849
void run();
4950
};
5051

apps-conf.h

+16
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,26 @@
3535
#ifndef __APPS_CONF_H__
3636
#define __APPS_CONF_H__
3737

38+
// ----------------------------------------------------------------------------
39+
// -- Begin uIP/WiShield stack configuration settings
40+
3841
//Here we include the header file for the application(s) we use in our project.
3942
#define APP_WEBSERVER
4043
//#define APP_WEBCLIENT
4144
//#define APP_SOCKAPP
4245
//#define APP_UDPAPP
4346
//#define APP_WISERVER
4447

48+
#define MAX_TCP_CONNS 1 // Max TCP connections desired
49+
#define MAX_TCP_LISTENPORTS 1 // Max TCP listening ports
50+
#define MAX_UDP_CONNS 1 // Max UDP connections desired
51+
// Don't play with UIP_CLOCK_DIV unless you know what you are doing!
52+
#define UIP_CLOCK_DIV 2 // Referenced in stack.c; default 2
53+
54+
// -- End uIP/WiShield stack configuration settings
55+
// ----------------------------------------------------------------------------
56+
57+
4558
#ifdef APP_WEBSERVER
4659
#include "webserver.h"
4760
#endif
@@ -56,6 +69,9 @@
5669

5770
#ifdef APP_UDPAPP
5871
#include "udpapp.h"
72+
#define UIP_UDP_ENABLED 1
73+
#else
74+
#define UIP_UDP_ENABLED 0
5975
#endif
6076

6177
#ifdef APP_WISERVER

stack.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ void stack_init(void)
6565
mac.addr[4] = mac_addr[4];
6666
mac.addr[5] = mac_addr[5];
6767

68-
timer_set(&periodic_timer, CLOCK_SECOND / 2);
68+
timer_set(&periodic_timer, CLOCK_SECOND / UIP_CLOCK_DIV);
6969
timer_set(&arp_timer, CLOCK_SECOND * 10);
7070
timer_set(&self_arp_timer, CLOCK_SECOND * 30);
7171

@@ -81,14 +81,14 @@ void stack_init(void)
8181
webclient_init();
8282
#endif
8383

84-
#ifdef APP_SOCKAPP
85-
socket_app_init();
86-
#endif
87-
8884
#ifdef APP_UDPAPP
8985
udpapp_init();
9086
#endif
9187

88+
#ifdef APP_SOCKAPP
89+
socket_app_init();
90+
#endif
91+
9292
uip_ipaddr(ipaddr, local_ip[0], local_ip[1], local_ip[2], local_ip[3]);
9393
uip_sethostaddr(ipaddr);
9494
uip_ipaddr(ipaddr, gateway_ip[0],gateway_ip[1],gateway_ip[2],gateway_ip[3]);

udpapp.h

+2
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,11 @@
3737

3838
#include "pt.h"
3939

40+
#if !defined(APP_SOCKAPP) && !defined(APP_WISERVER)
4041
typedef struct socket_app_state {
4142
char name;
4243
} uip_tcp_appstate_t;
44+
#endif // !defined(APP_SOCKAPP) && !defined(APP_WISERVER)
4345

4446
void dummy_app_appcall(void);
4547
#ifndef UIP_APPCALL

uip-conf.h

+9-10
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
#include <inttypes.h>
3939
#include <avr/io.h>
4040
#include <stdio.h>
41-
//#include <stdbool.h>
4241

4342
/**
4443
* 8 bit datatype
@@ -68,19 +67,22 @@ typedef uint16_t u16_t;
6867
*/
6968
typedef unsigned short uip_stats_t;
7069

70+
//Include app configuration
71+
#include "apps-conf.h"
72+
7173
/**
7274
* Maximum number of TCP connections.
7375
*
7476
* \hideinitializer
7577
*/
76-
#define UIP_CONF_MAX_CONNECTIONS 1
78+
#define UIP_CONF_MAX_CONNECTIONS MAX_TCP_CONNS
7779

7880
/**
7981
* Maximum number of listening TCP ports.
8082
*
8183
* \hideinitializer
8284
*/
83-
#define UIP_CONF_MAX_LISTENPORTS 1
85+
#define UIP_CONF_MAX_LISTENPORTS MAX_TCP_LISTENPORTS
8486

8587
/**
8688
* uIP buffer size.
@@ -107,14 +109,14 @@ typedef unsigned short uip_stats_t;
107109
*
108110
* \hideinitializer
109111
*/
110-
#define UIP_CONF_UDP 0
112+
#define UIP_CONF_UDP UIP_UDP_ENABLED
111113

112114
/**
113115
* UDP checksums on or off
114116
*
115117
* \hideinitializer
116118
*/
117-
#define UIP_CONF_UDP_CHECKSUMS 0
119+
#define UIP_CONF_UDP_CHECKSUMS UIP_UDP_ENABLED
118120

119121
/**
120122
* uIP statistics on or off
@@ -128,17 +130,14 @@ typedef unsigned short uip_stats_t;
128130
*
129131
* \hideinitializer
130132
*/
131-
#define UIP_CONF_BROADCAST 0
133+
#define UIP_CONF_BROADCAST UIP_UDP_ENABLED
132134

133135
/**
134136
* The maximum amount of concurrent UDP connections.
135137
*
136138
* \hideinitializer
137139
*/
138-
#define UIP_CONF_UDP_CONNS 1
139-
140-
//Include app configuration
141-
#include "apps-conf.h"
140+
#define UIP_CONF_UDP_CONNS MAX_UDP_CONNS
142141

143142
#endif /* __UIP_CONF_H__ */
144143

0 commit comments

Comments
 (0)