Mikroelektronika MIKROE-442 Datenbogen

Seite von 726
mikroBasic PRO for dsPIC30/33 and PIC24
MikroElektronika
491
SPI_Ethernet_initDHCP
Prototype
sub function SPI_Ethernet_initDHCP(dim tmax as byte) as byte 
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 configuration 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.
SPI_Ethernet_doDHCPLeaseTime
Prototype
sub function SPI_Ethernet_doDHCPLeaseTime() as byte 
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 true
  ...
  if(SPI_Ethernet_doDHCPLeaseTime() <> 0) then
    ... ‘ it’s time to renew the IP address lease                  
  end if  
wend
Notes
None.