Skip to content

Commit 631fd05

Browse files
authored
Macro usage cleanup (FreeRTOS#1080)
* Remove duplicate definitions of macros, and move static assertion definition to FreeRTOSIPConfigDefaults.h --------- Authored-by: Holden <[email protected]>
1 parent f01dd05 commit 631fd05

File tree

27 files changed

+64
-213
lines changed

27 files changed

+64
-213
lines changed

source/FreeRTOS_DNS_Parser.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1108,7 +1108,7 @@
11081108
xEndPoint.bits.bIPv6 = pdFALSE_UNSIGNED;
11091109
xEndPoint.usDNSType = dnsTYPE_A_HOST;
11101110

1111-
#if defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 1 )
1111+
#if ( ipconfigIPv4_BACKWARD_COMPATIBLE == 1 )
11121112
xDNSHookReturn = xApplicationDNSQueryHook( ( const char * ) ucNBNSName );
11131113
#else
11141114
xDNSHookReturn = xApplicationDNSQueryHook_Multi( &( xEndPoint ), ( const char * ) ucNBNSName );

source/FreeRTOS_IP_Utils.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ void prvProcessNetworkDownEvent( struct xNetworkInterface * pxInterface )
839839
{
840840
if( pxEndPoint->bits.bCallDownHook != pdFALSE_UNSIGNED )
841841
{
842-
#if defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 1 )
842+
#if ( ipconfigIPv4_BACKWARD_COMPATIBLE == 1 )
843843
{
844844
vApplicationIPNetworkEventHook( eNetworkDown );
845845
}

source/include/FreeRTOSIPConfigDefaults.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,33 @@
6060
* MACROS details :
6161
* https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html
6262
*/
63+
64+
/*---------------------------------------------------------------------------*/
65+
66+
/*
67+
* Compile time assertion with zero runtime effects.
68+
* It will assert on 'e' not being zero, as it tries to divide by it.
69+
*/
70+
71+
#ifdef static_assert
72+
#define STATIC_ASSERT( e ) static_assert( e, "FreeRTOS-Plus-TCP Error" )
73+
#elif defined( _Static_assert )
74+
#define STATIC_ASSERT( e ) _Static_assert( e, "FreeRTOS-Plus-TCP Error" )
75+
#else
76+
/* MISRA Ref 20.10.1 [Lack of sizeof operator and compile time error checking] */
77+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-2010 */
78+
/* coverity[misra_c_2012_rule_20_10_violation] */
79+
#define ASSERT_CONCAT_( a, b ) a ## b
80+
#define ASSERT_CONCAT( a, b ) ASSERT_CONCAT_( a, b )
81+
#ifdef __COUNTER__
82+
#define STATIC_ASSERT( e ) \
83+
; enum { ASSERT_CONCAT( static_assert_, __COUNTER__ ) = 1 / ( int ) ( !!( e ) ) }
84+
#else
85+
#define STATIC_ASSERT( e ) \
86+
; enum { ASSERT_CONCAT( assert_line_, __LINE__ ) = 1 / ( int ) ( !!( e ) ) }
87+
#endif
88+
#endif /* ifdef static_assert */
89+
6390
/*---------------------------------------------------------------------------*/
6491

6592
/*
@@ -990,6 +1017,8 @@
9901017
* Unit: count of ports
9911018
* Minimum: 0
9921019
* Maximum: 32
1020+
*
1021+
* There can be at most 32 PHY ports, but in most cases there are 4 or less.
9931022
*/
9941023

9951024
#ifndef ipconfigPHY_MAX_PORTS

source/include/FreeRTOS_DNS_Globals.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,6 @@
5757
* name field is an offset to the string, rather than the string itself. */
5858
#define dnsNAME_IS_OFFSET ( ( uint8_t ) 0xc0 )
5959

60-
/** @brief The maximum number of times a DNS request should be sent out if a response
61-
* is not received, before giving up. */
62-
#ifndef ipconfigDNS_REQUEST_ATTEMPTS
63-
#define ipconfigDNS_REQUEST_ATTEMPTS 5
64-
#endif
65-
66-
6760
/* NBNS flags. */
6861
#if ( ipconfigUSE_NBNS == 1 )
6962
#define dnsNBNS_FLAGS_RESPONSE 0x8000U /**< NBNS response flag. */

source/include/FreeRTOS_IP.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ extern uint32_t ulApplicationGetNextSequenceNumber( uint32_t ulSourceAddress,
117117
*/
118118

119119
/* Use setting from FreeRTOS if defined and non-zero */
120-
#if defined( ipconfigBUFFER_PADDING ) && ( ipconfigBUFFER_PADDING != 0 )
120+
#if ( ipconfigBUFFER_PADDING != 0 )
121121
#define ipBUFFER_PADDING ipconfigBUFFER_PADDING
122122
#elif ( UINTPTR_MAX > 0xFFFFFFFF )
123123
#define ipBUFFER_PADDING ( 12U + ipconfigPACKET_FILLER_SIZE )
@@ -142,12 +142,6 @@ extern uint32_t ulApplicationGetNextSequenceNumber( uint32_t ulSourceAddress,
142142
* handled. The value is chosen simply to be easy to spot when debugging. */
143143
#define ipUNHANDLED_PROTOCOL 0x4321U
144144

145-
/** @brief The maximum time the IP task is allowed to remain in the Blocked state if no
146-
* events are posted to the network event queue. */
147-
#ifndef ipconfigMAX_IP_TASK_SLEEP_TIME
148-
#define ipconfigMAX_IP_TASK_SLEEP_TIME ( pdMS_TO_TICKS( 10000UL ) )
149-
#endif
150-
151145
/* Trace macros to aid in debugging, disabled if ipconfigHAS_PRINTF != 1 */
152146
#if ( ipconfigHAS_PRINTF == 1 )
153147
#define DEBUG_DECLARE_TRACE_VARIABLE( type, var, init ) type var = ( init ) /**< Trace macro to set "type var = init". */

source/portable/BufferManagement/BufferAllocation_2.c

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,20 +67,8 @@
6767
#define baALIGNMENT_MASK ( baALIGNMENT_BYTES - 1U )
6868
#define baADD_WILL_OVERFLOW( a, b ) ( ( a ) > ( SIZE_MAX - ( b ) ) )
6969

70-
/* Compile time assertion with zero runtime effects
71-
* it will assert on 'e' not being zero, as it tries to divide by it,
72-
* will also print the line where the error occurred in case of failure */
73-
#if defined( ipconfigETHERNET_MINIMUM_PACKET_BYTES )
74-
/* MISRA Ref 20.10.1 [Lack of sizeof operator and compile time error checking] */
75-
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-2010 */
76-
/* coverity[misra_c_2012_rule_20_10_violation] */
77-
#define ASSERT_CONCAT_( a, b ) a ## b
78-
#define ASSERT_CONCAT( a, b ) ASSERT_CONCAT_( a, b )
79-
#define STATIC_ASSERT( e ) \
80-
enum { ASSERT_CONCAT( assert_line_, __LINE__ ) = ( 1 / ( !!( e ) ) ) }
81-
82-
STATIC_ASSERT( ipconfigETHERNET_MINIMUM_PACKET_BYTES <= baMINIMAL_BUFFER_SIZE );
83-
#endif
70+
STATIC_ASSERT( ipconfigETHERNET_MINIMUM_PACKET_BYTES <= baMINIMAL_BUFFER_SIZE );
71+
8472
/* A list of free (available) NetworkBufferDescriptor_t structures. */
8573
static List_t xFreeBuffersList;
8674

source/portable/NetworkInterface/ATSAM4E/NetworkInterface.c

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,6 @@
5353
#define BMSR_LINK_STATUS 0x0004 /*!< Link status */
5454
#endif
5555

56-
#if defined( PHY_LS_HIGH_CHECK_TIME_MS ) || defined( PHY_LS_LOW_CHECK_TIME_MS )
57-
#error please use the new defines with 'ipconfig' prefix
58-
#endif
59-
60-
#ifndef ipconfigPHY_LS_HIGH_CHECK_TIME_MS
61-
62-
/* Check if the LinkStatus in the PHY is still high after 15 seconds of not
63-
* receiving packets. */
64-
#define ipconfigPHY_LS_HIGH_CHECK_TIME_MS 15000U
65-
#endif
66-
67-
#ifndef ipconfigPHY_LS_LOW_CHECK_TIME_MS
68-
/* Check if the LinkStatus in the PHY is still low every second. */
69-
#define ipconfigPHY_LS_LOW_CHECK_TIME_MS 1000U
70-
#endif
71-
7256
/* Interrupt events to process. Currently only the Rx event is processed
7357
* although code for other events is included to allow for possible future
7458
* expansion. */

source/portable/NetworkInterface/ATSAME5x/NetworkInterface.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
#endif
8787

8888
/* Setup LLMNR specific multicast address. */
89-
#if ( defined( ipconfigUSE_LLMNR ) && ( ipconfigUSE_LLMNR == 1 ) )
89+
#if ( ipconfigUSE_LLMNR == 1 )
9090
static uint8_t ucLLMNR_MAC_address[] = { 0x01, 0x00, 0x5E, 0x00, 0x00, 0xFC };
9191
#endif
9292

@@ -122,13 +122,13 @@ static uint8_t ucLLMNR_MAC_address[] = { 0x01, 0x00, 0x5E, 0x00, 0x00, 0xFC };
122122
* static allocation with a non zero-copy driver.
123123
*/
124124
#define ipUSE_STATIC_ALLOCATION 0
125-
#if ( defined( ipUSE_STATIC_ALLOCATION ) && ( ipUSE_STATIC_ALLOCATION == 1 ) )
125+
#if ( ipUSE_STATIC_ALLOCATION == 1 )
126126

127127
/* 1536 bytes is more than needed, 1524 would be enough.
128128
* But 1536 is a multiple of 32, which gives a great alignment for cached memories. */
129129
#define NETWORK_BUFFER_SIZE 1536
130130
static uint8_t ucBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ][ NETWORK_BUFFER_SIZE ];
131-
#endif /* ( defined( ipUSE_STATIC_ALLOCATION ) && ( ipUSE_STATIC_ALLOCATION == 1 )) */
131+
#endif /* if ( ipUSE_STATIC_ALLOCATION == 1 ) */
132132

133133

134134
/* Holds the handle of the task used as a deferred interrupt processor. The
@@ -137,7 +137,7 @@ static uint8_t ucLLMNR_MAC_address[] = { 0x01, 0x00, 0x5E, 0x00, 0x00, 0xFC };
137137
TaskHandle_t xEMACTaskHandle = NULL;
138138

139139
/* The PING response queue */
140-
#if ( defined( ipconfigSUPPORT_OUTGOING_PINGS ) && ( ipconfigSUPPORT_OUTGOING_PINGS == 1 ) )
140+
#if ( ipconfigSUPPORT_OUTGOING_PINGS == 1 )
141141
QueueHandle_t xPingReplyQueue = NULL;
142142
#endif
143143

@@ -254,7 +254,7 @@ BaseType_t xATSAM5x_NetworkInterfaceInitialise( NetworkInterface_t * pxInterface
254254
prvPHYLinkReset();
255255

256256
/* Initialize PING capability */
257-
#if ( defined( ipconfigSUPPORT_OUTGOING_PINGS ) && ( ipconfigSUPPORT_OUTGOING_PINGS == 1 ) )
257+
#if ( ipconfigSUPPORT_OUTGOING_PINGS == 1 )
258258
xPingReplyQueue = xQueueCreate( ipconfigPING_QUEUE_SIZE, sizeof( uint16_t ) );
259259
#endif
260260

@@ -471,7 +471,7 @@ void xRxCallback( void )
471471
vTaskNotifyGiveFromISR( xEMACTaskHandle, 0 );
472472
}
473473

474-
#if ( defined( ipUSE_STATIC_ALLOCATION ) && ( ipUSE_STATIC_ALLOCATION == 1 ) )
474+
#if ( ipUSE_STATIC_ALLOCATION == 1 )
475475

476476
/* Next provide the vNetworkInterfaceAllocateRAMToBuffers() function, which
477477
* simply fills in the pucEthernetBuffer member of each descriptor. */
@@ -490,7 +490,7 @@ void xRxCallback( void )
490490
*( ( uint32_t * ) &ucBuffers[ x ][ 0 ] ) = ( uint32_t ) &( pxNetworkBuffers[ x ] );
491491
}
492492
}
493-
#endif /* ( defined( ipUSE_STATIC_ALLOCATION ) && ( ipUSE_STATIC_ALLOCATION == 1 )) */
493+
#endif /* if ( ipUSE_STATIC_ALLOCATION == 1 ) */
494494

495495

496496
/*********************************************************************/
@@ -518,7 +518,7 @@ static void prvGMACInit()
518518
prvGMACEnableMulticastHashTable( true );
519519

520520
/* Enable traffic for LLMNR, if defined. */
521-
#if ( defined( ipconfigUSE_LLMNR ) && ( ipconfigUSE_LLMNR == 1 ) )
521+
#if ( ipconfigUSE_LLMNR == 1 )
522522
{
523523
mac_async_set_filter_ex( &ETH_MAC, ucLLMNR_MAC_address );
524524
}

source/portable/NetworkInterface/Common/phyHandling.c

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -55,22 +55,6 @@
5555
#define phyMIN_PHY_ADDRESS 0
5656
#define phyMAX_PHY_ADDRESS 31
5757

58-
#if defined( PHY_LS_HIGH_CHECK_TIME_MS ) || defined( PHY_LS_LOW_CHECK_TIME_MS )
59-
#error please use the new defines with 'ipconfig' prefix
60-
#endif
61-
62-
#ifndef ipconfigPHY_LS_HIGH_CHECK_TIME_MS
63-
64-
/* Check if the LinkStatus in the PHY is still high after 15 seconds of not
65-
* receiving packets. */
66-
#define ipconfigPHY_LS_HIGH_CHECK_TIME_MS 15000U
67-
#endif
68-
69-
#ifndef ipconfigPHY_LS_LOW_CHECK_TIME_MS
70-
/* Check if the LinkStatus in the PHY is still low every second. */
71-
#define ipconfigPHY_LS_LOW_CHECK_TIME_MS 1000U
72-
#endif
73-
7458
/* As the following 3 macro's are OK in most situations, and so they're not
7559
* included in 'FreeRTOSIPConfigDefaults.h'.
7660
* Users can change their values in the project's 'FreeRTOSIPConfig.h'. */

source/portable/NetworkInterface/LPC18xx/NetworkInterface.c

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -50,25 +50,8 @@
5050
/* The size of the stack allocated to the task that handles Rx packets. */
5151
#define nwRX_TASK_STACK_SIZE 140
5252

53-
#if defined( PHY_LS_HIGH_CHECK_TIME_MS ) || defined( PHY_LS_LOW_CHECK_TIME_MS )
54-
#error please use the new defines with 'ipconfig' prefix
55-
#endif
56-
57-
#ifndef ipconfigPHY_LS_HIGH_CHECK_TIME_MS
58-
59-
/* Check if the LinkStatus in the PHY is still high after 15 seconds of not
60-
* receiving packets. */
61-
#define ipconfigPHY_LS_HIGH_CHECK_TIME_MS 15000U
62-
#endif
63-
64-
#ifndef ipconfigPHY_LS_LOW_CHECK_TIME_MS
65-
/* Check if the LinkStatus in the PHY is still low every second. */
66-
#define ipconfigPHY_LS_LOW_CHECK_TIME_MS 1000U
67-
#endif
68-
69-
7053
#ifndef configUSE_RMII
71-
#define configUSE_RMII 1
54+
#define configUSE_RMII 1
7255
#endif
7356

7457
#ifndef configNUM_RX_DESCRIPTORS

0 commit comments

Comments
 (0)