Mikroelektronika MIKROE-724 データシート

ページ / 726
516
mikoBasic PRO for dsPIC30/33 and PIC24
MikroElektronika
SPI_Ethernet_24j600_initDHCP
Prototype
sub function SPI_Ethernet_24j600_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_24j600_getIpAddress - fetch IP address. 
- SPI_Ethernet_24j600_getGwIpAddress - fetch gateway IP address. 
- SPI_Ethernet_24j600_getDnsIpAddress - fetch DNS IP address. 
- SPI_Ethernet_24j600_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_24j600_Init.
Example
... 
    SPI_Ethernet_24j600_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_24j600_userTimerSec
  is 
used to keep track of time. It is user responsibility to increment this variable each second in it’s code.
SPI_Ethernet_24j600_doDHCPLeaseTime
Prototype
sub function SPI_Ethernet_24j600_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_24j600_Init.
Example
while true
  ...
  if(SPI_Ethernet_24j600_doDHCPLeaseTime() <> 0) then
    ... ‘ it’s time to renew the IP address lease                  
  end if  
wend
Notes
None.