|
|
View previous topic :: View next topic |
Author |
Message |
sandy wilson
Joined: 25 Feb 2004 Posts: 28
|
Disabling DCHP |
Posted: Fri Apr 27, 2007 4:44 am |
|
|
Hello,
I'm currently running the Microchip stack ported over to CCS (by CCS) on the CCS ethernet prototyping board.
What I'm trying to do is, if I have DHCP enabled and the board is connected to a network with no DHCP server I want to disable DHCP.
This is the code that I'm using:
int InitDHCPTask(void)
{
static TICKTYPE lastTick;
TICKTYPE currTick;
static enum {DHCP_NOT_BOUND_STATE=0,
DHCP_DELAY_STATE=1,
DHCP_BOUND_STATE=2,
DHCP_TIMEDOUT=3,
ETHER_NOT_CONNECTED=4} state=0;
switch(state)
{
//Initial state is that we are not linked to the DHCP server
case DHCP_NOT_BOUND_STATE:
//Check to see if any Ethernet at all...
if(!MACIsLinked())
{
//and move into NOT_CONNECTED state
//state = ETHER_NOT_CONNECTED;
printf("\n\rNot Linked");
return 1;
}
else if (!DHCPIsBound())
{
printf("\n\rNot bound ");
return 1;
}
else
{
printf("\r\nBound");
return 2;
}
break; }
}
and in the main loop
void main(void)
{
int1 DHCP_Set = FALSE;
int result = 1;
UDP_SOCKET last_rx_socket=INVALID_UDP_SOCKET;
MACAddrInit();
lcd_init();
StackInit();
do
{
result = InitDHCPTask();
}while (result == 1);
while(1)
{
StackTask();
LCDTask();
}
}
My problem is this. If I run it as it stands the code tells me that we are not bound and stays in that section of the code i.e. the stack never binds to the Network. If I remove the section
else if (!DHCPIsBound())
{
printf("\n\rNot bound ");
return 1;
}
the stack does bind and moves onto the infinite while loop. Any suggestions as to what I'm doing wrong and/orany suggestions on a better way to do this.
thanks for any help
Sandyw |
|
|
frequentguest Guest
|
|
Posted: Fri Apr 27, 2007 7:47 am |
|
|
I'm having some trouble reading your code, but if I'm understanding it correctly, you're expecting the status of DHCPIsBound() to change without calling StackTask().
Note that the the TCP/IP stack only processes requests, incoming or outgoing--that includes DHCP requests, when you call StackTask(). If you hold the processor in a loop without calling StackTask(), there will be no change in the status of the TCP/IP stack.
In the future, post code using the [code] tags to make it much more readable. |
|
|
sandy wilson
Joined: 25 Feb 2004 Posts: 28
|
|
Posted: Fri Apr 27, 2007 8:23 am |
|
|
Hello frequentguest,
Changed the code to:-
do
{
result = InitDHCPTask();
StackTask(); <==========Added this
}while (result == 1);
and a way it went and worked a treat. Thanks for your help
Sandyw |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|