From 5003d17feda25490e655c0f1c15d2b13e395c9f7 Mon Sep 17 00:00:00 2001 From: Hein Tibosch Date: Wed, 6 May 2020 14:16:56 -0400 Subject: [PATCH] FreeRTOS+TCP : renewing DHCP lease while network is down (#53) Co-authored-by: Hein Tibosch Co-authored-by: Gary Wicker <14828980+gkwicker@users.noreply.github.com> --- .../Source/FreeRTOS-Plus-TCP/FreeRTOS_DHCP.c | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_DHCP.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_DHCP.c index 59d55dea4b..4f32d5c6e7 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_DHCP.c +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_DHCP.c @@ -488,18 +488,25 @@ BaseType_t xGivingUp = pdFALSE; case eLeasedAddress : - /* Resend the request at the appropriate time to renew the lease. */ - prvCreateDHCPSocket(); - - if( xDHCPData.xDHCPSocket != NULL ) + if( FreeRTOS_IsNetworkUp() ) { - xDHCPData.xDHCPTxTime = xTaskGetTickCount(); - xDHCPData.xDHCPTxPeriod = dhcpINITIAL_DHCP_TX_PERIOD; - prvSendDHCPRequest( ); - xDHCPData.eDHCPState = eWaitingAcknowledge; + /* Resend the request at the appropriate time to renew the lease. */ + prvCreateDHCPSocket(); - /* From now on, we should be called more often */ - vIPReloadDHCPTimer( dhcpINITIAL_TIMER_PERIOD ); + if( xDHCPData.xDHCPSocket != NULL ) + { + xDHCPData.xDHCPTxTime = xTaskGetTickCount(); + xDHCPData.xDHCPTxPeriod = dhcpINITIAL_DHCP_TX_PERIOD; + prvSendDHCPRequest(); + xDHCPData.eDHCPState = eWaitingAcknowledge; + + /* From now on, we should be called more often */ + vIPReloadDHCPTimer( dhcpINITIAL_TIMER_PERIOD ); + } + } + else + { + vIPReloadDHCPTimer( pdMS_TO_TICKS( dhcpINITIAL_DHCP_TX_PERIOD ) ); } break;