diff --git a/source/FreeRTOS_IP_Utils.c b/source/FreeRTOS_IP_Utils.c index 73ad81c108..906c2b6ba6 100644 --- a/source/FreeRTOS_IP_Utils.c +++ b/source/FreeRTOS_IP_Utils.c @@ -983,18 +983,28 @@ void vPreCheckConfigs( void ) #if ( configASSERT_DEFINED == 1 ) { - volatile size_t uxSize = sizeof( uintptr_t ); - - if( uxSize == 8U ) - { - /* This is a 64-bit platform, make sure there is enough space in - * pucEthernetBuffer to store a pointer and also make sure that the value of - * ipconfigBUFFER_PADDING is such that (ipconfigBUFFER_PADDING + ipSIZE_OF_ETH_HEADER) is a - * 32 bit (4 byte) aligned value, so that when incrementing the ethernet buffer with - * (ipconfigBUFFER_PADDING + ipSIZE_OF_ETH_HEADER) bytes it lands in a 32 bit aligned address - * which lets us efficiently access 32 bit values later in the packet. */ - configASSERT( ( ipconfigBUFFER_PADDING >= 14 ) && ( ( ( ( ipconfigBUFFER_PADDING ) + ( ipSIZE_OF_ETH_HEADER ) ) % 4 ) == 0 ) ); - } + size_t uxSize; + + /* Check if ipBUFFER_PADDING has a minimum size, depending on the platform. + * See FreeRTOS_IP.h for more details. */ + #if ( UINTPTR_MAX > 0xFFFFFFFFU ) + + /* + * This is a 64-bit platform, make sure there is enough space in + * pucEthernetBuffer to store a pointer. + */ + configASSERT( ipBUFFER_PADDING >= 14U ); + #else + /* This is a 32-bit platform. */ + configASSERT( ipBUFFER_PADDING >= 10U ); + #endif /* UINTPTR_MAX > 0xFFFFFFFFU */ + + /* + * The size of the Ethernet header (14) plus ipBUFFER_PADDING should be a + * multiple of 32 bits, in order to get aligned access to all uint32_t + * fields in the protocol headers. + */ + configASSERT( ( ( ( ipSIZE_OF_ETH_HEADER ) + ( ipBUFFER_PADDING ) ) % 4U ) == 0U ); /* LCOV_EXCL_BR_START */ uxSize = ipconfigNETWORK_MTU; diff --git a/source/include/FreeRTOS_IP.h b/source/include/FreeRTOS_IP.h index 1995b9ffec..85af11a7e1 100644 --- a/source/include/FreeRTOS_IP.h +++ b/source/include/FreeRTOS_IP.h @@ -97,22 +97,30 @@ extern uint32_t ulApplicationGetNextSequenceNumber( uint32_t ulSourceAddress, * pointer back to the network buffer. Should be a multiple of 8 to ensure 8 byte * alignment is maintained on architectures that require it. * - * In order to get a 32-bit alignment of network packets, an offset of 2 bytes - * would be desirable, as defined by ipconfigPACKET_FILLER_SIZE. So the malloc'd + * In order to get a 32-bit or 64-bit alignment of network packets, an offset of 2 bytes + * is ideal as defined by ipconfigPACKET_FILLER_SIZE. So the malloc'd * buffer will have the following contents: - * uint32_t pointer; // word-aligned - * uchar_8 filler[6]; - * << ETH-header >> // half-word-aligned - * uchar_8 dest[6]; // start of pucEthernetBuffer - * uchar_8 dest[6]; - * uchar16_t type; - * << IP-header >> // word-aligned + * + * +---------+-----------+---------+ + * | Offset | Alignment | Length | + * | 32 | 64 | 32 | 64 | 32 | 64 | + * |----|----|-----|-----|----|----| + * | 0 | 0 | 4 | 8 | 4 | 8 | uchar_8 * pointer; // Points to the 'NetworkBufferDescriptor_t'. + * | 4 | 8 | 4 | 8 | 6 | 6 | uchar_8 filler[6]; // To give the +2 byte offset. + * |-------------------------------| + * | 10 | 14 | 4+2 | 8+2 | 6 | 6 | uchar_8 dest_mac[6]; // Destination address. + * | 16 | 20 | 4 | 8 | 6 | 6 | uchar_8 src_mac[6]; // Source address. + * | 22 | 26 | 4+2 | 4+2 | 2 | 2 | uchar16_t ethertype; + * | 24 | 28 | 4 | 4 | ~ | ~ | << IP-header >> // word-aligned, either 4 or 8 bytes. * uint8_t ucVersionHeaderLength; * etc */ -#if ( ipconfigBUFFER_PADDING != 0 ) +/* Use setting from FreeRTOS if defined and non-zero */ +#if defined( ipconfigBUFFER_PADDING ) && ( ipconfigBUFFER_PADDING != 0 ) #define ipBUFFER_PADDING ipconfigBUFFER_PADDING +#elif ( UINTPTR_MAX > 0xFFFFFFFF ) + #define ipBUFFER_PADDING ( 12U + ipconfigPACKET_FILLER_SIZE ) #else #define ipBUFFER_PADDING ( 8U + ipconfigPACKET_FILLER_SIZE ) #endif