Skip to content

Commit c76a048

Browse files
committed
Avoid portTICK_PERIOD_MS usage in library code
portTICK_PERIOD_MS evaluates to zero when configTICK_RATE_HZ > 1000, which (while uncommon) is a valid configuration (e.g., for stress testing). To ensure compatibility and robustness, this change replaces its usage with safer FreeRTOS-provided time conversion macros. Notably, the FreeRTOS kernel itself avoids using portTICK_PERIOD_MS.
1 parent 3733583 commit c76a048

File tree

6 files changed

+8
-8
lines changed

6 files changed

+8
-8
lines changed

source/FreeRTOS_DNS_Cache.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@
220220
pxIP->xIPAddress.ulIP_IPv4 = 0U;
221221
}
222222

223-
ulCurrentTimeSeconds = ( uint32_t ) ( ( xCurrentTickCount / portTICK_PERIOD_MS ) / 1000U );
223+
ulCurrentTimeSeconds = ( uint32_t ) ( ( xCurrentTickCount / configTICK_RATE_HZ ) );
224224
xResult = prvFindEntryIndex( pcName, pxIP, &uxIndex );
225225

226226
if( xResult == pdTRUE )

source/FreeRTOS_DNS_Callback.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@
125125
* @param[in] pcHostName The hostname whose IP address is being searched for.
126126
* @param[in] pvSearchID The search ID of the DNS callback function to set.
127127
* @param[in] pCallbackFunction The callback function pointer.
128-
* @param[in] uxTimeout Timeout of the callback function.
128+
* @param[in] uxTimeout Timeout of the callback function in ms.
129129
* @param[in] uxIdentifier Random number used as ID in the DNS message.
130130
* @param[in] xIsIPv6 pdTRUE if the address type should be IPv6.
131131
*/
@@ -145,7 +145,7 @@
145145
DNSCallback_t * pxCallback = ( ( DNSCallback_t * ) pvPortMalloc( sizeof( *pxCallback ) + lLength ) );
146146

147147
/* Translate from ms to number of clock ticks. */
148-
uxTimeout /= portTICK_PERIOD_MS;
148+
uxTimeout = pdMS_TO_TICKS( uxTimeout );
149149

150150
if( pxCallback != NULL )
151151
{

source/FreeRTOS_TCP_WIN.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@
374374
TickType_t uxNow = xTaskGetTickCount();
375375
TickType_t uxDiff = uxNow - pxTimer->uxBorn;
376376

377-
return ( uint32_t ) ( uxDiff * portTICK_PERIOD_MS );
377+
return ( uint32_t ) pdTICKS_TO_MS( uxDiff );
378378
}
379379
/*-----------------------------------------------------------*/
380380

source/FreeRTOS_Tiny_TCP.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
TickType_t uxNow = xTaskGetTickCount();
125125
TickType_t uxDiff = uxNow - pxTimer->uxBorn;
126126

127-
return uxDiff * portTICK_PERIOD_MS;
127+
return pdTICKS_TO_MS( uxDiff );
128128
}
129129
/*-----------------------------------------------------------*/
130130

source/include/FreeRTOSIPConfigDefaults.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@
322322
#error ipconfigRA_SEARCH_TIME_OUT_MSEC must be at least 0
323323
#endif
324324

325-
STATIC_ASSERT( ipconfigRA_SEARCH_TIME_OUT_MSEC <= ( portMAX_DELAY * portTICK_PERIOD_MS ) );
325+
STATIC_ASSERT( pdMS_TO_TICKS( ipconfigRA_SEARCH_TIME_OUT_MSEC ) <= portMAX_DELAY );
326326

327327
/*---------------------------------------------------------------------------*/
328328

@@ -370,7 +370,7 @@ STATIC_ASSERT( ipconfigRA_SEARCH_TIME_OUT_MSEC <= ( portMAX_DELAY * portTICK_PER
370370
#error ipconfigRA_IP_TEST_TIME_OUT_MSEC must be at least 0
371371
#endif
372372

373-
STATIC_ASSERT( ipconfigRA_IP_TEST_TIME_OUT_MSEC <= ( portMAX_DELAY * portTICK_PERIOD_MS ) );
373+
STATIC_ASSERT( pdMS_TO_TICKS( ipconfigRA_IP_TEST_TIME_OUT_MSEC ) <= portMAX_DELAY );
374374

375375
/*---------------------------------------------------------------------------*/
376376

source/portable/NetworkInterface/SH2A/NetworkInterface.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
* task performing the transmit will block for niTX_BUFFER_FREE_WAIT
5656
* milliseconds. It will do this a maximum of niMAX_TX_ATTEMPTS before giving
5757
* up. */
58-
#define niTX_BUFFER_FREE_WAIT ( ( TickType_t ) 2UL / portTICK_PERIOD_MS )
58+
#define niTX_BUFFER_FREE_WAIT ( pdMS_TO_TICKS ( 2UL ) )
5959
#define niMAX_TX_ATTEMPTS ( 5 )
6060

6161
/* The length of the queue used to send interrupt status words from the

0 commit comments

Comments
 (0)