Skip to content

Commit

Permalink
Macro usage cleanup (#1080)
Browse files Browse the repository at this point in the history
* Remove duplicate definitions of macros, and move static assertion definition to FreeRTOSIPConfigDefaults.h
---------
Authored-by: Holden <holden@zenithaerotech.com>
  • Loading branch information
HTRamsey authored Jan 24, 2024
1 parent f01dd05 commit 631fd05
Show file tree
Hide file tree
Showing 27 changed files with 64 additions and 213 deletions.
2 changes: 1 addition & 1 deletion source/FreeRTOS_DNS_Parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -1108,7 +1108,7 @@
xEndPoint.bits.bIPv6 = pdFALSE_UNSIGNED;
xEndPoint.usDNSType = dnsTYPE_A_HOST;

#if defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 1 )
#if ( ipconfigIPv4_BACKWARD_COMPATIBLE == 1 )
xDNSHookReturn = xApplicationDNSQueryHook( ( const char * ) ucNBNSName );
#else
xDNSHookReturn = xApplicationDNSQueryHook_Multi( &( xEndPoint ), ( const char * ) ucNBNSName );
Expand Down
2 changes: 1 addition & 1 deletion source/FreeRTOS_IP_Utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,7 @@ void prvProcessNetworkDownEvent( struct xNetworkInterface * pxInterface )
{
if( pxEndPoint->bits.bCallDownHook != pdFALSE_UNSIGNED )
{
#if defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 1 )
#if ( ipconfigIPv4_BACKWARD_COMPATIBLE == 1 )
{
vApplicationIPNetworkEventHook( eNetworkDown );
}
Expand Down
29 changes: 29 additions & 0 deletions source/include/FreeRTOSIPConfigDefaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,33 @@
* MACROS details :
* https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html
*/

/*---------------------------------------------------------------------------*/

/*
* Compile time assertion with zero runtime effects.
* It will assert on 'e' not being zero, as it tries to divide by it.
*/

#ifdef static_assert
#define STATIC_ASSERT( e ) static_assert( e, "FreeRTOS-Plus-TCP Error" )
#elif defined( _Static_assert )
#define STATIC_ASSERT( e ) _Static_assert( e, "FreeRTOS-Plus-TCP Error" )
#else
/* MISRA Ref 20.10.1 [Lack of sizeof operator and compile time error checking] */
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-2010 */
/* coverity[misra_c_2012_rule_20_10_violation] */
#define ASSERT_CONCAT_( a, b ) a ## b
#define ASSERT_CONCAT( a, b ) ASSERT_CONCAT_( a, b )
#ifdef __COUNTER__
#define STATIC_ASSERT( e ) \
; enum { ASSERT_CONCAT( static_assert_, __COUNTER__ ) = 1 / ( int ) ( !!( e ) ) }
#else
#define STATIC_ASSERT( e ) \
; enum { ASSERT_CONCAT( assert_line_, __LINE__ ) = 1 / ( int ) ( !!( e ) ) }
#endif
#endif /* ifdef static_assert */

/*---------------------------------------------------------------------------*/

/*
Expand Down Expand Up @@ -990,6 +1017,8 @@
* Unit: count of ports
* Minimum: 0
* Maximum: 32
*
* There can be at most 32 PHY ports, but in most cases there are 4 or less.
*/

#ifndef ipconfigPHY_MAX_PORTS
Expand Down
7 changes: 0 additions & 7 deletions source/include/FreeRTOS_DNS_Globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,6 @@
* name field is an offset to the string, rather than the string itself. */
#define dnsNAME_IS_OFFSET ( ( uint8_t ) 0xc0 )

/** @brief The maximum number of times a DNS request should be sent out if a response
* is not received, before giving up. */
#ifndef ipconfigDNS_REQUEST_ATTEMPTS
#define ipconfigDNS_REQUEST_ATTEMPTS 5
#endif


/* NBNS flags. */
#if ( ipconfigUSE_NBNS == 1 )
#define dnsNBNS_FLAGS_RESPONSE 0x8000U /**< NBNS response flag. */
Expand Down
8 changes: 1 addition & 7 deletions source/include/FreeRTOS_IP.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ extern uint32_t ulApplicationGetNextSequenceNumber( uint32_t ulSourceAddress,
*/

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

/** @brief The maximum time the IP task is allowed to remain in the Blocked state if no
* events are posted to the network event queue. */
#ifndef ipconfigMAX_IP_TASK_SLEEP_TIME
#define ipconfigMAX_IP_TASK_SLEEP_TIME ( pdMS_TO_TICKS( 10000UL ) )
#endif

/* Trace macros to aid in debugging, disabled if ipconfigHAS_PRINTF != 1 */
#if ( ipconfigHAS_PRINTF == 1 )
#define DEBUG_DECLARE_TRACE_VARIABLE( type, var, init ) type var = ( init ) /**< Trace macro to set "type var = init". */
Expand Down
16 changes: 2 additions & 14 deletions source/portable/BufferManagement/BufferAllocation_2.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,8 @@
#define baALIGNMENT_MASK ( baALIGNMENT_BYTES - 1U )
#define baADD_WILL_OVERFLOW( a, b ) ( ( a ) > ( SIZE_MAX - ( b ) ) )

/* Compile time assertion with zero runtime effects
* it will assert on 'e' not being zero, as it tries to divide by it,
* will also print the line where the error occurred in case of failure */
#if defined( ipconfigETHERNET_MINIMUM_PACKET_BYTES )
/* MISRA Ref 20.10.1 [Lack of sizeof operator and compile time error checking] */
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-2010 */
/* coverity[misra_c_2012_rule_20_10_violation] */
#define ASSERT_CONCAT_( a, b ) a ## b
#define ASSERT_CONCAT( a, b ) ASSERT_CONCAT_( a, b )
#define STATIC_ASSERT( e ) \
enum { ASSERT_CONCAT( assert_line_, __LINE__ ) = ( 1 / ( !!( e ) ) ) }

STATIC_ASSERT( ipconfigETHERNET_MINIMUM_PACKET_BYTES <= baMINIMAL_BUFFER_SIZE );
#endif
STATIC_ASSERT( ipconfigETHERNET_MINIMUM_PACKET_BYTES <= baMINIMAL_BUFFER_SIZE );

/* A list of free (available) NetworkBufferDescriptor_t structures. */
static List_t xFreeBuffersList;

Expand Down
16 changes: 0 additions & 16 deletions source/portable/NetworkInterface/ATSAM4E/NetworkInterface.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,6 @@
#define BMSR_LINK_STATUS 0x0004 /*!< Link status */
#endif

#if defined( PHY_LS_HIGH_CHECK_TIME_MS ) || defined( PHY_LS_LOW_CHECK_TIME_MS )
#error please use the new defines with 'ipconfig' prefix
#endif

#ifndef ipconfigPHY_LS_HIGH_CHECK_TIME_MS

/* Check if the LinkStatus in the PHY is still high after 15 seconds of not
* receiving packets. */
#define ipconfigPHY_LS_HIGH_CHECK_TIME_MS 15000U
#endif

#ifndef ipconfigPHY_LS_LOW_CHECK_TIME_MS
/* Check if the LinkStatus in the PHY is still low every second. */
#define ipconfigPHY_LS_LOW_CHECK_TIME_MS 1000U
#endif

/* Interrupt events to process. Currently only the Rx event is processed
* although code for other events is included to allow for possible future
* expansion. */
Expand Down
16 changes: 8 additions & 8 deletions source/portable/NetworkInterface/ATSAME5x/NetworkInterface.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
#endif

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

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

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


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

/* The PING response queue */
#if ( defined( ipconfigSUPPORT_OUTGOING_PINGS ) && ( ipconfigSUPPORT_OUTGOING_PINGS == 1 ) )
#if ( ipconfigSUPPORT_OUTGOING_PINGS == 1 )
QueueHandle_t xPingReplyQueue = NULL;
#endif

Expand Down Expand Up @@ -254,7 +254,7 @@ BaseType_t xATSAM5x_NetworkInterfaceInitialise( NetworkInterface_t * pxInterface
prvPHYLinkReset();

/* Initialize PING capability */
#if ( defined( ipconfigSUPPORT_OUTGOING_PINGS ) && ( ipconfigSUPPORT_OUTGOING_PINGS == 1 ) )
#if ( ipconfigSUPPORT_OUTGOING_PINGS == 1 )
xPingReplyQueue = xQueueCreate( ipconfigPING_QUEUE_SIZE, sizeof( uint16_t ) );
#endif

Expand Down Expand Up @@ -471,7 +471,7 @@ void xRxCallback( void )
vTaskNotifyGiveFromISR( xEMACTaskHandle, 0 );
}

#if ( defined( ipUSE_STATIC_ALLOCATION ) && ( ipUSE_STATIC_ALLOCATION == 1 ) )
#if ( ipUSE_STATIC_ALLOCATION == 1 )

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


/*********************************************************************/
Expand Down Expand Up @@ -518,7 +518,7 @@ static void prvGMACInit()
prvGMACEnableMulticastHashTable( true );

/* Enable traffic for LLMNR, if defined. */
#if ( defined( ipconfigUSE_LLMNR ) && ( ipconfigUSE_LLMNR == 1 ) )
#if ( ipconfigUSE_LLMNR == 1 )
{
mac_async_set_filter_ex( &ETH_MAC, ucLLMNR_MAC_address );
}
Expand Down
16 changes: 0 additions & 16 deletions source/portable/NetworkInterface/Common/phyHandling.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,6 @@
#define phyMIN_PHY_ADDRESS 0
#define phyMAX_PHY_ADDRESS 31

#if defined( PHY_LS_HIGH_CHECK_TIME_MS ) || defined( PHY_LS_LOW_CHECK_TIME_MS )
#error please use the new defines with 'ipconfig' prefix
#endif

#ifndef ipconfigPHY_LS_HIGH_CHECK_TIME_MS

/* Check if the LinkStatus in the PHY is still high after 15 seconds of not
* receiving packets. */
#define ipconfigPHY_LS_HIGH_CHECK_TIME_MS 15000U
#endif

#ifndef ipconfigPHY_LS_LOW_CHECK_TIME_MS
/* Check if the LinkStatus in the PHY is still low every second. */
#define ipconfigPHY_LS_LOW_CHECK_TIME_MS 1000U
#endif

/* As the following 3 macro's are OK in most situations, and so they're not
* included in 'FreeRTOSIPConfigDefaults.h'.
* Users can change their values in the project's 'FreeRTOSIPConfig.h'. */
Expand Down
19 changes: 1 addition & 18 deletions source/portable/NetworkInterface/LPC18xx/NetworkInterface.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,25 +50,8 @@
/* The size of the stack allocated to the task that handles Rx packets. */
#define nwRX_TASK_STACK_SIZE 140

#if defined( PHY_LS_HIGH_CHECK_TIME_MS ) || defined( PHY_LS_LOW_CHECK_TIME_MS )
#error please use the new defines with 'ipconfig' prefix
#endif

#ifndef ipconfigPHY_LS_HIGH_CHECK_TIME_MS

/* Check if the LinkStatus in the PHY is still high after 15 seconds of not
* receiving packets. */
#define ipconfigPHY_LS_HIGH_CHECK_TIME_MS 15000U
#endif

#ifndef ipconfigPHY_LS_LOW_CHECK_TIME_MS
/* Check if the LinkStatus in the PHY is still low every second. */
#define ipconfigPHY_LS_LOW_CHECK_TIME_MS 1000U
#endif


#ifndef configUSE_RMII
#define configUSE_RMII 1
#define configUSE_RMII 1
#endif

#ifndef configNUM_RX_DESCRIPTORS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ static BaseType_t xMPS2_GetPhyLinkStatus( NetworkInterface_t * pxInterface )

/*-----------------------------------------------------------*/

#if defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 1 )
#if ( ipconfigIPv4_BACKWARD_COMPATIBLE == 1 )

/* Do not call the following function directly. It is there for downward compatibility.
* The function FreeRTOS_IPInit() will call it to initialice the interface and end-point
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ static BaseType_t xLAN91C111_GetPhyLinkStatus( NetworkInterface_t * pxInterface

/*-----------------------------------------------------------*/

#if defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 1 )
#if ( ipconfigIPv4_BACKWARD_COMPATIBLE == 1 )

/* Do not call the following function directly. It is there for downward compatibility.
* The function FreeRTOS_IPInit() will call it to initialise the interface and end-point
Expand Down
17 changes: 0 additions & 17 deletions source/portable/NetworkInterface/RX/NetworkInterface.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,23 +67,6 @@
#endif
#endif /* if defined( BSP_MCU_RX65N ) || defined( BSP_MCU_RX64M ) || defined( BSP_MCU_RX71M ) */

#if defined( PHY_LS_HIGH_CHECK_TIME_MS ) || defined( PHY_LS_LOW_CHECK_TIME_MS )
#error please use the new defines with 'ipconfig' prefix
#endif

#ifndef ipconfigPHY_LS_HIGH_CHECK_TIME_MS

/* Check if the LinkStatus in the PHY is still high after 2 seconds of not
* receiving packets. */
#define ipconfigPHY_LS_HIGH_CHECK_TIME_MS 2000U
#endif

#ifndef ipconfigPHY_LS_LOW_CHECK_TIME_MS
/* Check if the LinkStatus in the PHY is still low every second. */
#define ipconfigPHY_LS_LOW_CHECK_TIME_MS 1000U
#endif


/***********************************************************************************************************************
* Private global variables and functions
**********************************************************************************************************************/
Expand Down
4 changes: 0 additions & 4 deletions source/portable/NetworkInterface/STM32Fxx/stm32fxx_hal_eth.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,6 @@
* @{
*/

#if !defined( ARRAY_SIZE )
#define ARRAY_SIZE( x ) ( sizeof( x ) / sizeof( x )[ 0 ] )
#endif

#ifdef HAL_ETH_MODULE_ENABLED

#if ( stm_is_F1 != 0 || stm_is_F2 != 0 || stm_is_F4 != 0 || stm_is_F7 )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ static BaseType_t xSTM32H_GetPhyLinkStatus( NetworkInterface_t * pxInterface )
}
/*-----------------------------------------------------------*/

#if defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 1 )
#if ( ipconfigIPv4_BACKWARD_COMPATIBLE == 1 )

/* Do not call the following function directly. It is there for downward compatibility.
* The function FreeRTOS_IPInit() will call it to initialice the interface and end-point
Expand Down
3 changes: 0 additions & 3 deletions source/portable/NetworkInterface/STM32Hxx/stm32hxx_hal_eth.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,6 @@
#include "NetworkBufferManagement.h"
#include "FreeRTOS_IP_Private.h"

#ifndef ARRAY_SIZE
#define ARRAY_SIZE( x ) ( ( BaseType_t ) ( sizeof( x ) / sizeof( ( x )[ 0 ] ) ) )
#endif

/* A semaphore that indicates the number of freeTX DMA descriptors. */
extern SemaphoreHandle_t xTXDescriptorSemaphore;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,6 @@
#undef ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM
#define ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM 1
#endif
#ifndef ipconfigETHERNET_MINIMUM_PACKET_BYTES
#define ipconfigETHERNET_MINIMUM_PACKET_BYTES ETHERNET_MIN_PACKET_BYTES
#endif
#ifdef ipconfigETHERNET_MINIMUM_PACKET_BYTES
#undef ipconfigETHERNET_MINIMUM_PACKET_BYTES
#define ipconfigETHERNET_MINIMUM_PACKET_BYTES ETHERNET_MIN_PACKET_BYTES
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ static BaseType_t xWinPcap_GetPhyLinkStatus( NetworkInterface_t * pxInterface )
}
/*-----------------------------------------------------------*/

#if defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 1 )
#if ( ipconfigIPv4_BACKWARD_COMPATIBLE == 1 )


/* Do not call the following function directly. It is there for downward compatibility.
Expand Down
23 changes: 3 additions & 20 deletions source/portable/NetworkInterface/Zynq/NetworkInterface.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,29 +63,12 @@

#define niBMSR_LINK_STATUS 0x0004uL

#if defined( PHY_LS_HIGH_CHECK_TIME_MS ) || defined( PHY_LS_LOW_CHECK_TIME_MS )
#error please use the new defines with 'ipconfig' prefix
#endif

#ifndef ipconfigPHY_LS_HIGH_CHECK_TIME_MS

/* Check if the LinkStatus in the PHY is still high after 15 seconds of not
* receiving packets. */
#define ipconfigPHY_LS_HIGH_CHECK_TIME_MS 15000U
#endif

#ifndef ipconfigPHY_LS_LOW_CHECK_TIME_MS
/* Check if the LinkStatus in the PHY is still low every second. */
#define ipconfigPHY_LS_LOW_CHECK_TIME_MS 1000U
#endif


/* The size of each buffer when BufferAllocation_1 is used:
* http://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/Embedded_Ethernet_Buffer_Management.html */
#define niBUFFER_1_PACKET_SIZE 1536
#define niBUFFER_1_PACKET_SIZE 1536

/* Naming and numbering of PHY registers. */
#define PHY_REG_01_BMSR 0x01 /* Basic mode status register */
#define PHY_REG_01_BMSR 0x01 /* Basic mode status register */

#ifndef iptraceEMAC_TASK_STARTING
#define iptraceEMAC_TASK_STARTING() do {} while( ipFALSE_BOOL )
Expand Down Expand Up @@ -540,7 +523,7 @@ static BaseType_t xZynqGetPhyLinkStatus( NetworkInterface_t * pxInterface )
}
/*-----------------------------------------------------------*/

#if defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 1 )
#if ( ipconfigIPv4_BACKWARD_COMPATIBLE == 1 )

/* Do not call the following function directly. It is there for downward compatibility.
* The function FreeRTOS_IPInit() will call it to initialice the interface and end-point
Expand Down
Loading

0 comments on commit 631fd05

Please sign in to comment.