Found this one when I patched in the new +TCP 0831
and associated DHCP changes. an easy one to find.
in vDHCPProcess state == eWaitingSendFirstDiscover
If xApplicationDHCPHook returns at eDHCPPhase==eDHCPPhasePreDiscover
which sets xGivingUp==true
Down the bottom of vDHCPProcess
xGivingUp is checked and if true, then the socket is closed.
BUT !!!
prvInitialiseDHCP(); was never called, because of the initial eDHCPUseDefault return from the hook
so the socket never gets born.
Until I have a good look at the best way to deal with this (maybe change code path )
really needs an assert if there is an attept to close a open socket.
I have put in
/* hack by GLEN /
/ only close socket if it was opened… */
if (xDHCPData.xDHCPSocket!=NULL) {
vSocketClose( xDHCPData.xDHCPSocket );
xDHCPData.xDHCPSocket = NULL;
}
Point of information. xDHCPData above is declared as a static variable, so the C language defines that it will be zero initialized at startup, so pointer members should be NULL. (If it was declared in block scope with auto duration, then yes, it doesn’t get initialized, but file/global scoped variables are supposed to be zero initialized if not otherwise initiaized).
There are some embeded enviroments where this doesn’t happen, but those are non-conforming to the standard.
However, we recently made a change in FreeRTOS_DHCP.c to use vSocketClose(). That’s the internal version of FreeRTOS_closesocket(). The internal version does not check for NULL or FREERTOS_INVALID_SOCKET (~0U).
I agree with Richard Damon that the xDHCPData will be zero’d after start-up, but if FreeRTOS_socket() fails, the socket pointer could become FREERTOS_INVALID_SOCKET.
The function prvCreateDHCPSocket() still has an assert:
A note about the new FreeRTOS_DHCP.c in the previous post: you need the latest Labs release to be able to compile it. In fact the current 160908 release already contains the above FreeRTOS_DHCP.c.
The naming of the DHCP-hook and some enums have changed since the earlier 160112 release. The essence is still the same though.
The parameter ulNetMask was dropped. It can be retrieved by calling FreeRTOS_GetAddressConfiguration().
Sorry for this inconvenience. In the 160112 release, the DHCP hook was still a new experimental feature. It worked OK but the naming was not very clear.
We think that it will be more clear now to new users what the hook does and how it works.
thanks for all the responses and work you have done.
I have not found any other problems with 0831 to date. I will download 0908 tomorrow and patch that in. ( I just copy over and do an SVN DIFF) . 0831 is now in a live system…running abt 900 pps and 80% utilization of the F4 in DSP…
I have some fixes for the TFTP server from 0831 latest so I will post that in the forum as some input that tomorrow. I have the tftp server working, loading data into external flash,when booting my xilinx fpga…The tricky bit was that my spi flash shared the spi with the ethernet …solid as a rock.