User manual

Table Of Contents
456
mikoC PRO for PIC32
MikroElektronika
SPI_Ethernet_initDHCP
SPI_Ethernet_doDHCPLeaseTime
Prototype
unsigned int SPI_Ethernet_initDHCP(unsigned char tmax);
Description This is DHCP module routine. It sends an DHCP request for network parameters (IP, gateway, DNS
addresses and IP subnet mask) and waits for DHCP reply. If the requested parameters were obtained
successfully, their values are stored into the library global variables.
These parameters can be fetched by using appropriate library IP get routines:
- SPI_Ethernet_getIpAddress - fetch IP address.
- SPI_Ethernet_getGwIpAddress - fetch gateway IP address.
- SPI_Ethernet_getDnsIpAddress - fetch DNS IP address.
- SPI_Ethernet_getIpMask - fetch IP subnet mask.
UDP port 68 is used as DHCP client port and UDP port 67 is used as DHCP server port.
Parameters - tmax: time in seconds to wait for an reply.
Returns - 1 - network parameters were obtained successfully.
- 0 - otherwise.
Requires Ethernet module has to be initialized. See SPI_Ethernet_Init.
Example
...
SPI_Ethernet_initDHCP(5); // get network conguration from DHCP server,
wait 5 sec for the response
...
Notes The Ethernet services are not stopped while this routine waits for DNS reply. The incoming packets will
be processed normaly during this time.
When DHCP module is used, global library variable SPI_Ethernet_userTimerSec is used to keep
track of time. It is user responsibility to increment this variable each second in it’s code.
Prototype
unsigned int SPI_Ethernet_doDHCPLeaseTime();
Description This is DHCP module routine. It takes care of IP address lease time by decrementing the global lease
time library counter. When this time expires, it’s time to contact DHCP server and renew the lease.
Parameters None
Returns - 0 - lease time has not expired yet.
- 1 - lease time has expired, it’s time to renew it.
Requires Ethernet module has to be initialized. See SPI_Ethernet_Init.
Example
while(1) {
...
if (SPI_Ethernet_doDHCPLeaseTime())
... // it’s time to renew the IP address lease
}
Notes None.