diff --git a/CMakeLists.txt b/CMakeLists.txt index 8c785c539..13b577979 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,17 +24,9 @@ option(FREERTOS_PLUS_TCP_ENABLE_BUILD_CHECKS "Enable the build checks for FreeRT # Configuration # Override these at project level with: -# Optional: set(FREERTOS_PLUS_TCP_BUFFER_ALLOCATION "1" CACHE STRING "" FORCE) # Optional: set(FREERTOS_PLUS_TCP_COMPILER "" CACHE STRING "" FORCE) # Required: set(FREERTOS_PLUS_TCP_NETWORK_IF "POSIX" CACHE STRING "" FORCE) -# Select the appropriate buffer allocation method. -# See: https://freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/Embedded_Ethernet_Buffer_Management.html -if (NOT FREERTOS_PLUS_TCP_BUFFER_ALLOCATION) - message(STATUS "Using default FREERTOS_PLUS_TCP_BUFFER_ALLOCATION = 2") - set(FREERTOS_PLUS_TCP_BUFFER_ALLOCATION "2" CACHE STRING "FreeRTOS buffer allocation model number. 1 .. 2.") -endif() - # Select the Compiler - if left blank will detect using CMake # Note relies on CMake to detect over any setting here. # Valid options are: diff --git a/README.md b/README.md index e329ca746..43ee02ab0 100644 --- a/README.md +++ b/README.md @@ -108,7 +108,7 @@ Below is the breakdown of what each directory contains: - This directory contains all the [.c] source files. ## Note -At this time it is recommended to use BufferAllocation_2.c in which case it is essential to use the heap_4.c memory allocation scheme. See [memory management](http://www.FreeRTOS.org/a00111.html). +At this time it is recommended to leave ipconfigBUFFER_ALLOC_STATIC disabled in which case it is essential to use the heap_4.c memory allocation scheme. See [memory management](http://www.FreeRTOS.org/a00111.html). ### Kernel sources The FreeRTOS Kernel Source is in [FreeRTOS/FreeRTOS-Kernel repository](https://github.com/FreeRTOS/FreeRTOS-Kernel), and it is consumed by testing/PR checks as a submodule in this repository. diff --git a/readme.txt b/readme.txt index 62f2df846..e5ba7924f 100644 --- a/readme.txt +++ b/readme.txt @@ -12,7 +12,7 @@ https://www.freertos.org/Documentation/03-Libraries/02-FreeRTOS-plus/02-FreeRTOS License information is available on: http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/FreeRTOS_Plus_TCP_License.html -At this time it is recommended to use BufferAllocation_2.c in which case it is +At this time it is recommended to leave ipconfigBUFFER_ALLOC_STATIC disabled in which case it is essential to use the heap_4.c memory allocation scheme: http://www.FreeRTOS.org/a00111.html diff --git a/source/FreeRTOS_DNS_Parser.c b/source/FreeRTOS_DNS_Parser.c index a1a3f2038..e8728d1ca 100644 --- a/source/FreeRTOS_DNS_Parser.c +++ b/source/FreeRTOS_DNS_Parser.c @@ -487,7 +487,7 @@ uint8_t * pucNewBuffer = NULL; size_t uxExtraLength; - if( xBufferAllocFixedSize == pdFALSE ) + #if ( ipconfigBUFFER_ALLOC_STATIC == 0 ) { size_t uxDataLength = uxBufferLength + sizeof( UDPHeader_t ) + @@ -537,10 +537,11 @@ pxNetworkBuffer = NULL; } } - else + #else /* if ( ipconfigBUFFER_ALLOC_STATIC == 0 ) */ { pucNewBuffer = &( pxNetworkBuffer->pucEthernetBuffer[ uxUDPOffset ] ); } + #endif /* if ( ipconfigBUFFER_ALLOC_STATIC == 0 ) */ if( ( pxNetworkBuffer != NULL ) ) { @@ -1188,9 +1189,9 @@ * that were already present. */ uxSizeNeeded = pxNetworkBuffer->xDataLength + sizeof( NBNSAnswer_t ) - 2 * sizeof( uint16_t ); - if( xBufferAllocFixedSize == pdFALSE ) + #if ( ipconfigBUFFER_ALLOC_STATIC == 0 ) { - /* We're linked with BufferAllocation_2.c + /* Dynamic buffers are used, * pxResizeNetworkBufferWithDescriptor() will malloc a new bigger buffer, * and memcpy the data. The old buffer will be free'd. */ @@ -1206,12 +1207,13 @@ pxNetworkBuffer->xDataLength = uxSizeNeeded; pucUDPPayloadBuffer = &( pxNetworkBuffer->pucEthernetBuffer[ ipUDP_PAYLOAD_OFFSET_IPv4 ] ); } - else + #else /* if ( ipconfigBUFFER_ALLOC_STATIC == 0 ) */ { - /* BufferAllocation_1.c is used, the Network Buffers can contain at least + /* Fixed buffers are used, the Network Buffers can contain at least * ipconfigNETWORK_MTU + ipSIZE_OF_ETH_HEADER. */ configASSERT( uxSizeNeeded < ipconfigNETWORK_MTU + ipSIZE_OF_ETH_HEADER ); } + #endif /* if ( ipconfigBUFFER_ALLOC_STATIC == 0 ) */ pxNetworkBuffer->xDataLength = uxSizeNeeded; diff --git a/source/FreeRTOS_ND.c b/source/FreeRTOS_ND.c index 62d100ed6..064419e9d 100644 --- a/source/FreeRTOS_ND.c +++ b/source/FreeRTOS_ND.c @@ -780,7 +780,7 @@ /* MISRA Ref 11.3.1 [Misaligned access] */ /* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */ /* coverity[misra_c_2012_rule_11_3_violation] */ - pxNetworkBuffer = pxGetNetworkBufferWithDescriptor( BUFFER_FROM_WHERE_CALL( 181 ) uxPacketLength, uxBlockTimeTicks ); + pxNetworkBuffer = pxGetNetworkBufferWithDescriptor( uxPacketLength, uxBlockTimeTicks ); if( pxNetworkBuffer != NULL ) { @@ -952,7 +952,7 @@ if( xSendEventStructToIPTask( &xEventMessage, xDontBlock ) != pdPASS ) { /* Failed to send the message, so release the network buffer. */ - vReleaseNetworkBufferAndDescriptor( BUFFER_FROM_WHERE_CALL( 140 ) pxNDWaitingNetworkBuffer ); + vReleaseNetworkBufferAndDescriptor( pxARPWaitingNetworkBuffer ); } /* Clear the buffer. */ @@ -1384,7 +1384,7 @@ size_t uxNeededSize; uxNeededSize = sizeof( ICMPPacket_IPv6_t ); - pxTempBuffer = pxGetNetworkBufferWithDescriptor( BUFFER_FROM_WHERE_CALL( 199 ) uxNeededSize, 0U ); + pxTempBuffer = pxGetNetworkBufferWithDescriptor( uxNeededSize, 0U ); if( pxTempBuffer != NULL ) { diff --git a/source/FreeRTOS_TCP_Transmission.c b/source/FreeRTOS_TCP_Transmission.c index 3b0abe63f..d413763bd 100644 --- a/source/FreeRTOS_TCP_Transmission.c +++ b/source/FreeRTOS_TCP_Transmission.c @@ -634,7 +634,7 @@ size_t uxNeeded; BaseType_t xResize; - if( xBufferAllocFixedSize != pdFALSE ) + #if ( ipconfigBUFFER_ALLOC_STATIC != 0 ) { /* Network buffers are created with a fixed size and can hold the largest * MTU. */ @@ -651,7 +651,7 @@ xResize = pdFALSE; } } - else + #else /* if ( ipconfigBUFFER_ALLOC_STATIC != 0 ) */ { /* Network buffers are created with a variable size. See if it must * grow. */ @@ -674,6 +674,7 @@ xResize = pdFALSE; } } + #endif /* if ( ipconfigBUFFER_ALLOC_STATIC != 0 ) */ if( xResize != pdFALSE ) { diff --git a/source/include/FreeRTOSIPConfigDefaults.h b/source/include/FreeRTOSIPConfigDefaults.h index 77ae9e9c8..5d8e03514 100644 --- a/source/include/FreeRTOSIPConfigDefaults.h +++ b/source/include/FreeRTOSIPConfigDefaults.h @@ -859,6 +859,65 @@ STATIC_ASSERT( ipconfigMAX_IP_TASK_SLEEP_TIME <= portMAX_DELAY ); /*---------------------------------------------------------------------------*/ +/* + * ipconfigBUFFER_ALLOC_STATIC + * + * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/Embedded_Ethernet_Buffer_Management.html + * + * Type: BaseType_t ( ipconfigENABLE | ipconfigDISABLE ) + * + * Sets the buffer allocation method to use fixed static memory of size + * ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS * ipTOTAL_ETHERNET_FRAME_SIZE. + * If disabled then a memory allocator that will not fragment the heap + * should be used. + */ + +#ifndef ipconfigBUFFER_ALLOC_STATIC + #define ipconfigBUFFER_ALLOC_STATIC ipconfigDISABLE +#endif + +#if ( ( ipconfigBUFFER_ALLOC_STATIC != ipconfigDISABLE ) && ( ipconfigBUFFER_ALLOC_STATIC != ipconfigENABLE ) ) + #error Invalid ipconfigBUFFER_ALLOC_STATIC configuration +#endif + +#ifndef ipconfigBUFFER_ALLOC_INIT + #define ipconfigBUFFER_ALLOC_INIT() do {} while( ipFALSE_BOOL ) +#endif + +#ifndef ipconfigBUFFER_ALLOC_LOCK + #define ipconfigBUFFER_ALLOC_LOCK() taskENTER_CRITICAL() +#endif + +#ifndef ipconfigBUFFER_ALLOC_UNLOCK + #define ipconfigBUFFER_ALLOC_UNLOCK() taskEXIT_CRITICAL() +#endif + +#if ipconfigIS_ENABLED( ipconfigBUFFER_ALLOC_STATIC ) + + #ifndef ipconfigBUFFER_ALLOC_LOCK_FROM_ISR + #define ipconfigBUFFER_ALLOC_LOCK_FROM_ISR() UBaseType_t uxSavedInterruptStatus = ( UBaseType_t ) portSET_INTERRUPT_MASK_FROM_ISR(); { + #endif + + #ifndef ipconfigBUFFER_ALLOC_UNLOCK_FROM_ISR + #define ipconfigBUFFER_ALLOC_UNLOCK_FROM_ISR() portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus ); } + #endif + + #ifndef ipconfigBUFFER_ALLOC_STATIC_CUSTOM_LOCATION + #define ipconfigBUFFER_ALLOC_STATIC_CUSTOM_LOCATION ipconfigDISABLE + #endif + + #ifndef ipconfigBUFFER_ALLOC_STATIC_CUSTOM_LOCATION_STRING + #define ipconfigBUFFER_ALLOC_STATIC_CUSTOM_LOCATION_STRING ".EthBuffersSection" + #endif + +#endif /* if ipconfigIS_ENABLED( ipconfigBUFFER_ALLOC_STATIC ) */ + +#ifndef ipconfigBUFFER_ALLOC_STATIC_CUSTOM_SIZE + #define ipconfigBUFFER_ALLOC_STATIC_CUSTOM_SIZE ipconfigDISABLE +#endif + +/*---------------------------------------------------------------------------*/ + /* * ipconfigUSE_LINKED_RX_MESSAGES * @@ -3213,27 +3272,6 @@ STATIC_ASSERT( ipconfigDNS_SEND_BLOCK_TIME_TICKS <= portMAX_DELAY ); /*---------------------------------------------------------------------------*/ -/* - * ipconfigTCP_IP_SANITY - * - * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigTCP_IP_SANITY - * - * Type: BaseType_t ( ipconfigENABLE | ipconfigDISABLE ) - * - * Enables warnings when irregularities are detected when using - * BufferAllocation_1.c. - */ - -#ifndef ipconfigTCP_IP_SANITY - #define ipconfigTCP_IP_SANITY ipconfigDISABLE -#endif - -#if ( ( ipconfigTCP_IP_SANITY != ipconfigDISABLE ) && ( ipconfigTCP_IP_SANITY != ipconfigENABLE ) ) - #error Invalid ipconfigTCP_IP_SANITY configuration -#endif - -/*---------------------------------------------------------------------------*/ - /* * ipconfigTCP_MAY_LOG_PORT * diff --git a/source/include/FreeRTOS_IP_Private.h b/source/include/FreeRTOS_IP_Private.h index cd5afb8c0..a286bf2d8 100644 --- a/source/include/FreeRTOS_IP_Private.h +++ b/source/include/FreeRTOS_IP_Private.h @@ -328,9 +328,6 @@ extern uint16_t usPacketIdentifier; */ extern List_t xBoundUDPSocketsList; -/* True when BufferAllocation_1.c was included, false for BufferAllocation_2.c */ -extern const BaseType_t xBufferAllocFixedSize; - /* As FreeRTOS_Routing is included later, use forward declarations * of the two structs. */ struct xNetworkEndPoint; diff --git a/source/include/NetworkBufferManagement.h b/source/include/NetworkBufferManagement.h index 3fd9804a3..d15e83146 100644 --- a/source/include/NetworkBufferManagement.h +++ b/source/include/NetworkBufferManagement.h @@ -36,24 +36,29 @@ #include "FreeRTOS_IP.h" -/* _HT_ Two macro's needed while debugging/testing, please ignore. */ - -#define BUFFER_FROM_WHERE_DECL -#define BUFFER_FROM_WHERE_CALL( aWhere ) - /* NOTE PUBLIC API FUNCTIONS. */ + BaseType_t xNetworkBuffersInitialise( void ); NetworkBufferDescriptor_t * pxGetNetworkBufferWithDescriptor( size_t xRequestedSizeBytes, TickType_t xBlockTimeTicks ); - -/* The definition of the below function is only available if BufferAllocation_2.c has been linked into the source. */ -NetworkBufferDescriptor_t * pxNetworkBufferGetFromISR( size_t xRequestedSizeBytes ); void vReleaseNetworkBufferAndDescriptor( NetworkBufferDescriptor_t * const pxNetworkBuffer ); -/* The definition of the below function is only available if BufferAllocation_2.c has been linked into the source. */ -BaseType_t vNetworkBufferReleaseFromISR( NetworkBufferDescriptor_t * const pxNetworkBuffer ); -uint8_t * pucGetNetworkBuffer( size_t * pxRequestedSizeBytes ); -void vReleaseNetworkBuffer( uint8_t * pucEthernetBuffer ); +#if ( ipconfigBUFFER_ALLOC_STATIC != 0 ) + + NetworkBufferDescriptor_t * pxNetworkBufferGetFromISR( size_t xRequestedSizeBytes ); + + BaseType_t vNetworkBufferReleaseFromISR( NetworkBufferDescriptor_t * const pxNetworkBuffer ); + + void vNetworkBufferAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ); + + extern const UBaseType_t uxBufferAllocFixedSize; + +#else + +/* Increase the size of a Network Buffer. */ + NetworkBufferDescriptor_t * pxResizeNetworkBufferWithDescriptor( NetworkBufferDescriptor_t * pxNetworkBuffer, + size_t xNewSizeBytes ); +#endif /* ipconfigIS_ENABLED( ipconfigBUFFER_ALLOC_STATIC ) */ /* Get the current number of free network buffers. */ UBaseType_t uxGetNumberOfFreeNetworkBuffers( void ); @@ -65,21 +70,6 @@ UBaseType_t uxGetMinimumFreeNetworkBuffers( void ); NetworkBufferDescriptor_t * pxDuplicateNetworkBufferWithDescriptor( const NetworkBufferDescriptor_t * const pxNetworkBuffer, size_t uxNewLength ); -/* Increase the size of a Network Buffer. - * In case BufferAllocation_2.c is used, the new space must be allocated. */ -NetworkBufferDescriptor_t * pxResizeNetworkBufferWithDescriptor( NetworkBufferDescriptor_t * pxNetworkBuffer, - size_t xNewSizeBytes ); - -#if ipconfigTCP_IP_SANITY - -/* - * Check if an address is a valid pointer to a network descriptor - * by looking it up in the array of network descriptors - */ - UBaseType_t bIsValidNetworkDescriptor( const NetworkBufferDescriptor_t * pxDesc ); - BaseType_t prvIsFreeBuffer( const NetworkBufferDescriptor_t * pxDescr ); -#endif - /* *INDENT-OFF* */ #ifdef __cplusplus } /* extern "C" */ diff --git a/source/include/NetworkInterface.h b/source/include/NetworkInterface.h index 50b354ca9..8970d5eb5 100644 --- a/source/include/NetworkInterface.h +++ b/source/include/NetworkInterface.h @@ -47,9 +47,6 @@ * BaseType_t xGetPhyLinkStatus( struct xNetworkInterface *pxInterface ); */ -/* The following function is defined only when BufferAllocation_1.c is linked in the project. */ -void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ); - BaseType_t xGetPhyLinkStatus( struct xNetworkInterface * pxInterface ); #define MAC_IS_MULTICAST( pucMACAddressBytes ) ( ( pucMACAddressBytes[ 0 ] & 1U ) != 0U ) diff --git a/source/portable/BufferManagement/BufferAllocation.c b/source/portable/BufferManagement/BufferAllocation.c new file mode 100644 index 000000000..c4345c332 --- /dev/null +++ b/source/portable/BufferManagement/BufferAllocation.c @@ -0,0 +1,678 @@ +/* + * FreeRTOS+TCP + * Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * http://aws.amazon.com/freertos + * http://www.FreeRTOS.org + */ + +/** + * @file BufferAllocation.c + * @brief Provides static and dynamic methods of buffer allocation + */ + +/* Standard includes. */ +#include + +/* FreeRTOS includes. */ +#include "FreeRTOS.h" +#include "task.h" +#include "queue.h" +#include "semphr.h" + +/* FreeRTOS+TCP includes. */ +#include "FreeRTOS_IP.h" +#include "FreeRTOS_IP_Private.h" +#include "NetworkInterface.h" +#include "NetworkBufferManagement.h" + +/* The obtained network buffer must be large enough to hold a packet that might + * replace the packet that was requested to be sent. */ +#if ipconfigIS_ENABLED( ipconfigUSE_TCP ) + #define baMINIMAL_BUFFER_SIZE TCP_PACKET_SIZE +#else + #define baMINIMAL_BUFFER_SIZE sizeof( ARPPacket_t ) +#endif + +/* 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 */ +/* 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] */ +#if defined( ipconfigETHERNET_MINIMUM_PACKET_BYTES ) + #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 + +#define baALIGNMENT_MASK ( portBYTE_ALIGNMENT - 1U ) +#define baADD_WILL_OVERFLOW( a, b ) ( ( a ) > ( SIZE_MAX - ( b ) ) ) +#define baINTERRUPT_BUFFER_GET_THRESHOLD ( 3 ) + +#if ipconfigIS_DISABLED( ipconfigBUFFER_ALLOC_FIXED_SIZE_CUSTOM_BUFFER_SIZE ) + #define BUFFER_SIZE ( ipTOTAL_ETHERNET_FRAME_SIZE + ipBUFFER_PADDING ) + #define BUFFER_SIZE_ALIGNED ( ( BUFFER_SIZE + portBYTE_ALIGNMENT ) & ~baALIGNMENT_MASK ) +#endif + +static NetworkBufferDescriptor_t xNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ]; + +static List_t xFreeBuffersList; + +static UBaseType_t uxMinimumFreeNetworkBuffers = 0U; + +static SemaphoreHandle_t xNetworkBufferSemaphore = NULL; + +/*-----------------------------------------------------------*/ + +static BaseType_t xIsValidNetworkDescriptor( const NetworkBufferDescriptor_t * pxDesc ) +{ + BaseType_t xReturn; + + const UBaseType_t offset = ( UBaseType_t ) ( ( ( const char * ) pxDesc ) - ( ( const char * ) xNetworkBuffers ) ); + const ptrdiff_t index = pxDesc - xNetworkBuffers; + + if( ( offset >= sizeof( xNetworkBuffers ) ) || ( ( offset % sizeof( xNetworkBuffers[ 0 ] ) ) != 0 ) ) + { + xReturn = pdFALSE; + } + else if( ( index < 0 ) || ( ( UBaseType_t ) index > ( ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS - 1 ) ) ) + { + xReturn = pdFALSE; + } + else + { + xReturn = pdTRUE; + } + + return xReturn; +} + +/*-----------------------------------------------------------*/ + +static BaseType_t xIsFreeBuffer( const NetworkBufferDescriptor_t * pxDesc ) +{ + return ( xIsValidNetworkDescriptor( pxDesc ) != pdFALSE ) && ( listIS_CONTAINED_WITHIN( &xFreeBuffersList, &( pxDesc->xBufferListItem ) ) != pdFALSE ); +} + +/*-----------------------------------------------------------*/ + +static NetworkBufferDescriptor_t * pxGetNetworkBuffer( void ) +{ + NetworkBufferDescriptor_t * pxReturn = ( NetworkBufferDescriptor_t * ) listGET_OWNER_OF_HEAD_ENTRY( &xFreeBuffersList ); + + if( xIsFreeBuffer( pxReturn ) != pdFALSE ) + { + ( void ) uxListRemove( &( pxReturn->xBufferListItem ) ); + } + else + { + pxReturn = NULL; + } + + return pxReturn; +} + +/*-----------------------------------------------------------*/ + +static BaseType_t xFreeNetworkBuffer( NetworkBufferDescriptor_t * const pxNetworkBuffer ) +{ + const BaseType_t xListItemAlreadyInFreeList = listIS_CONTAINED_WITHIN( &xFreeBuffersList, &( pxNetworkBuffer->xBufferListItem ) ); + + if( xListItemAlreadyInFreeList == pdFALSE ) + { + vListInsertEnd( &xFreeBuffersList, &( pxNetworkBuffer->xBufferListItem ) ); + } + + return xListItemAlreadyInFreeList; + +} + +/*-----------------------------------------------------------*/ + +static void vInitNetworkBuffer( NetworkBufferDescriptor_t * pxNetworkBuffer, size_t xRequestedSizeBytes ) +{ + pxNetworkBuffer->xDataLength = xRequestedSizeBytes; + pxNetworkBuffer->pxInterface = NULL; + pxNetworkBuffer->pxEndPoint = NULL; + + #if ipconfigIS_ENABLED( ipconfigBUFFER_ALLOC_FIXED_SIZE ) + { + /* make sure the buffer is not linked */ + pxNetworkBuffer->pxNextBuffer = NULL; + } + #endif +} + +/*-----------------------------------------------------------*/ + +static void vUpdateMinimumFreeNetworkBuffers( void ) +{ + /* Reading UBaseType_t, no critical section needed. */ + const UBaseType_t uxCount = uxGetNumberOfFreeNetworkBuffers(); + + /* For stats, latch the lowest number of network buffers since booting. */ + if( uxMinimumFreeNetworkBuffers > uxCount ) + { + uxMinimumFreeNetworkBuffers = uxCount; + } +} + +/*-----------------------------------------------------------*/ + +UBaseType_t uxGetMinimumFreeNetworkBuffers( void ) +{ + return uxMinimumFreeNetworkBuffers; +} + +/*-----------------------------------------------------------*/ + +UBaseType_t uxGetNumberOfFreeNetworkBuffers( void ) +{ + return listCURRENT_LIST_LENGTH( &xFreeBuffersList ); +} + +/*-----------------------------------------------------------*/ + +#if ipconfigIS_DISABLED( ipconfigBUFFER_ALLOC_FIXED_SIZE ) + +static uint8_t * pucGetNetworkBuffer( size_t * const pxRequestedSizeBytes ) +{ + size_t xSize = *pxRequestedSizeBytes; + + if( xSize < baMINIMAL_BUFFER_SIZE ) + { + /* Buffers must be at least large enough to hold a TCP-packet with + * headers, or an ARP packet, in case TCP is not included. */ + xSize = baMINIMAL_BUFFER_SIZE; + } + + BaseType_t xIntegerOverflowed = pdFALSE; + + /* Round up xSize to the nearest multiple of N bytes, + * where N equals 'sizeof( size_t )'. */ + if( ( xSize & baALIGNMENT_MASK ) != 0U ) + { + const size_t xBytesRequiredForAlignment = portBYTE_ALIGNMENT - ( xSize & baALIGNMENT_MASK ); + + if( baADD_WILL_OVERFLOW( xSize, xBytesRequiredForAlignment ) == 0 ) + { + xSize += xBytesRequiredForAlignment; + } + else + { + xIntegerOverflowed = pdTRUE; + } + } + + size_t xAllocatedBytes; + + if( baADD_WILL_OVERFLOW( xSize, ipBUFFER_PADDING ) == 0 ) + { + xAllocatedBytes = xSize + ipBUFFER_PADDING; + } + else + { + xIntegerOverflowed = pdTRUE; + } + + uint8_t * pucEthernetBuffer = NULL; + + if( ( xIntegerOverflowed == pdFALSE ) && ( xAllocatedBytes <= ( SIZE_MAX >> 1 ) ) ) + { + *pxRequestedSizeBytes = xSize; + + /* Allocate a buffer large enough to store the requested Ethernet frame size + * and a pointer to a network buffer structure (hence the addition of + * ipBUFFER_PADDING bytes). */ + pucEthernetBuffer = ( uint8_t * ) pvPortMalloc( xAllocatedBytes ); + configASSERT( pucEthernetBuffer != NULL ); + + if( pucEthernetBuffer != NULL ) + { + /* Enough space is left at the start of the buffer to place a pointer to + * the network buffer structure that references this Ethernet buffer. + * Return a pointer to the start of the Ethernet buffer itself. */ + pucEthernetBuffer += ipBUFFER_PADDING; + } + } + + return pucEthernetBuffer; +} + +#endif /* if ipconfigIS_DISABLED( ipconfigBUFFER_ALLOC_FIXED_SIZE ) */ + +/*-----------------------------------------------------------*/ + +#if ( ipconfigIS_DISABLED( ipconfigBUFFER_ALLOC_FIXED_SIZE ) ) + +static void vReleaseNetworkBuffer( const uint8_t * const pucEthernetBuffer ) +{ + /* There is space before the Ethernet buffer in which a pointer to the + * network buffer that references this Ethernet buffer is stored. Remove the + * space before freeing the buffer. */ + if( pucEthernetBuffer != NULL ) + { + const uint8_t * pucEthernetBufferCopy = pucEthernetBuffer - ipBUFFER_PADDING; + vPortFree( ( void * ) pucEthernetBufferCopy ); + } +} + +#endif /* if ipconfigIS_DISABLED( ipconfigBUFFER_ALLOC_FIXED_SIZE ) */ + +/*-----------------------------------------------------------*/ + +#if ipconfigIS_DISABLED( ipconfigBUFFER_ALLOC_FIXED_SIZE ) + +NetworkBufferDescriptor_t * pxResizeNetworkBufferWithDescriptor( NetworkBufferDescriptor_t * pxNetworkBuffer, + size_t xNewSizeBytes ) +{ + NetworkBufferDescriptor_t * pxNetworkBufferCopy = pxNetworkBuffer; + size_t uxSizeBytes = xNewSizeBytes; + + if( baADD_WILL_OVERFLOW( uxSizeBytes, ipBUFFER_PADDING ) == 0 ) + { + uxSizeBytes += ipBUFFER_PADDING; + + uint8_t * const pucBuffer = pucGetNetworkBuffer( &( uxSizeBytes ) ); + + if( pucBuffer == NULL ) + { + pxNetworkBufferCopy = NULL; + } + else + { + pxNetworkBufferCopy->xDataLength = uxSizeBytes; + + const size_t xOriginalLength = pxNetworkBufferCopy->xDataLength + ipBUFFER_PADDING; + + if( uxSizeBytes > xOriginalLength ) + { + uxSizeBytes = xOriginalLength; + } + + ( void ) memcpy( pucBuffer - ipBUFFER_PADDING, + pxNetworkBufferCopy->pucEthernetBuffer - ipBUFFER_PADDING, + uxSizeBytes ); + vReleaseNetworkBuffer( pxNetworkBufferCopy->pucEthernetBuffer ); + pxNetworkBufferCopy->pucEthernetBuffer = pucBuffer; + } + } + else + { + pxNetworkBufferCopy = NULL; + } + + return pxNetworkBufferCopy; +} + +#endif /* if ipconfigIS_DISABLED( ipconfigBUFFER_ALLOC_FIXED_SIZE ) */ + +/*-----------------------------------------------------------*/ + +#if ipconfigIS_ENABLED( ipconfigBUFFER_ALLOC_FIXED_SIZE ) && ipconfigIS_DISABLED( ipconfigBUFFER_ALLOC_FIXED_SIZE_CUSTOM_ALLOCATE ) + +void vNetworkBufferAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ) +{ + // __attribute__( ( section( ".EthBuffersSection" ), aligned( baALIGNMENT_BYTES ) ) ); + #if ipconfigIS_ENABLED( ipconfigBUFFER_ALLOC_FIXED_SIZE_CUSTOM_BUFFER_SIZE ) + static uint8_t ucNetworkPackets[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ][ uxBufferAllocFixedSize ] __attribute__( ( aligned( portBYTE_ALIGNMENT ) ) ); + #else + static uint8_t ucNetworkPackets[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ][ BUFFER_SIZE_ALIGNED ] __attribute__( ( aligned( portBYTE_ALIGNMENT ) ) ); + #endif + + for( size_t i = 0; i < ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS; ++i ) + { + pxNetworkBuffers[ i ].pucEthernetBuffer = &( ucNetworkPackets[ i ][ ipBUFFER_PADDING ] ); + *( ( uint32_t * ) &( ucNetworkPackets[ i ][ 0 ] ) ) = ( uint32_t ) ( &( pxNetworkBuffers[ i ] ) ); + } +} + +#endif + +/*-----------------------------------------------------------*/ + +BaseType_t xNetworkBuffersInitialise( void ) +{ + BaseType_t xReturn = pdFAIL; + + if( xNetworkBufferSemaphore == NULL ) + { + ipconfigBUFFER_ALLOC_INIT(); + + #if ipconfigIS_ENABLED( configSUPPORT_STATIC_ALLOCATION ) + { + static StaticSemaphore_t xNetworkBufferSemaphoreBuffer; + xNetworkBufferSemaphore = xSemaphoreCreateCountingStatic( + ( UBaseType_t ) ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS, + ( UBaseType_t ) ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS, + &xNetworkBufferSemaphoreBuffer ); + } + #else + { + xNetworkBufferSemaphore = xSemaphoreCreateCounting( + ( UBaseType_t ) ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS, + ( UBaseType_t ) ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ); + } + #endif + + configASSERT( xNetworkBufferSemaphore != NULL ); + + if( xNetworkBufferSemaphore != NULL ) + { + #if ( configQUEUE_REGISTRY_SIZE > 0 ) + { + vQueueAddToRegistry( xNetworkBufferSemaphore, "NetBufSem" ); + } + #endif + + vListInitialise( &xFreeBuffersList ); + + #if ipconfigIS_ENABLED( ipconfigBUFFER_ALLOC_FIXED_SIZE ) + { + vNetworkBufferAllocateRAMToBuffers( xNetworkBuffers ); + } + #endif + + for( size_t i = 0U; i < ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS; ++i ) + { + NetworkBufferDescriptor_t * pxNetworkBuffer = &xNetworkBuffers[ i ]; + + #if ipconfigIS_DISABLED( ipconfigBUFFER_ALLOC_FIXED_SIZE ) + { + pxNetworkBuffer->pucEthernetBuffer = NULL; + } + #endif + + ListItem_t * pxBufferListItem = &pxNetworkBuffer->xBufferListItem; + vListInitialiseItem( pxBufferListItem ); + listSET_LIST_ITEM_OWNER( pxBufferListItem, pxNetworkBuffer ); + vListInsert( &xFreeBuffersList, pxBufferListItem ); + } + + uxMinimumFreeNetworkBuffers = ( UBaseType_t ) ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS; + + xReturn = pdPASS; + } + } + + return xReturn; +} + +/*-----------------------------------------------------------*/ + +NetworkBufferDescriptor_t * pxGetNetworkBufferWithDescriptor( size_t xRequestedSizeBytes, TickType_t xBlockTimeTicks ) +{ + NetworkBufferDescriptor_t * pxReturn = NULL; + + #if ipconfigIS_DISABLED( ipconfigBUFFER_ALLOC_FIXED_SIZE ) + size_t xRequestedSizeBytesCopy = xRequestedSizeBytes; + + if( ( xRequestedSizeBytesCopy < ( size_t ) baMINIMAL_BUFFER_SIZE ) ) + { + /* ARP packets can replace application packets, so the storage must be + * at least large enough to hold an ARP. */ + xRequestedSizeBytesCopy = baMINIMAL_BUFFER_SIZE; + } + + BaseType_t xIntegerOverflowed = pdFALSE; + + /* Add 2 bytes to xRequestedSizeBytesCopy and round up xRequestedSizeBytesCopy + * to the nearest multiple of N bytes, where N equals 'sizeof( size_t )'. */ + if( baADD_WILL_OVERFLOW( xRequestedSizeBytesCopy, 2 ) == 0 ) + { + xRequestedSizeBytesCopy += 2U; + } + else + { + xIntegerOverflowed = pdTRUE; + } + + if( ( xRequestedSizeBytesCopy & baALIGNMENT_MASK ) != 0U ) + { + const size_t xBytesRequiredForAlignment = portBYTE_ALIGNMENT - ( xRequestedSizeBytesCopy & baALIGNMENT_MASK ); + + if( baADD_WILL_OVERFLOW( xRequestedSizeBytesCopy, xBytesRequiredForAlignment ) == 0 ) + { + xRequestedSizeBytesCopy += xBytesRequiredForAlignment; + } + else + { + xIntegerOverflowed = pdTRUE; + } + } + + size_t xAllocatedBytes = 0; + + if( baADD_WILL_OVERFLOW( xRequestedSizeBytesCopy, ipBUFFER_PADDING ) == 0 ) + { + xAllocatedBytes = xRequestedSizeBytesCopy + ipBUFFER_PADDING; + } + else + { + xIntegerOverflowed |= pdTRUE; + } + + if( ( xIntegerOverflowed == pdFALSE ) && ( xAllocatedBytes <= ( SIZE_MAX >> 1 ) ) ) + { + #endif /* if ipconfigIS_DISABLED( ipconfigBUFFER_ALLOC_FIXED_SIZE ) */ + + if( xNetworkBufferSemaphore != NULL ) + { + /* If there is a semaphore available, there is a network buffer available. */ + if( xSemaphoreTake( xNetworkBufferSemaphore, xBlockTimeTicks ) == pdPASS ) + { + /* Protect the structure as it is accessed from tasks and interrupts. */ + ipconfigBUFFER_ALLOC_LOCK(); + { + pxReturn = pxGetNetworkBuffer(); + } + ipconfigBUFFER_ALLOC_UNLOCK(); + + if( pxReturn != NULL ) + { + vUpdateMinimumFreeNetworkBuffers(); + + #if ipconfigIS_DISABLED( ipconfigBUFFER_ALLOC_FIXED_SIZE ) + { + configASSERT( pxReturn->pucEthernetBuffer == NULL ); + + if( xRequestedSizeBytesCopy > 0U ) + { + /* Extra space is obtained so a pointer to the network buffer can + * be stored at the beginning of the buffer. */ + pxReturn->pucEthernetBuffer = ( uint8_t * ) pvPortMalloc( xAllocatedBytes ); + + if( pxReturn->pucEthernetBuffer == NULL ) + { + /* The attempt to allocate storage for the buffer payload failed, + * so the network buffer structure cannot be used and must be + * released. */ + vReleaseNetworkBufferAndDescriptor( pxReturn ); + pxReturn = NULL; + } + else + { + /* Store a pointer to the network buffer structure in the + * buffer storage area, then move the buffer pointer on past the + * stored pointer so the pointer value is not overwritten by the + * application when the buffer is used. */ + /* MISRA Ref 11.3.1 [Misaligned access] */ + /* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */ + /* coverity[misra_c_2012_rule_11_3_violation] */ + *( ( NetworkBufferDescriptor_t ** ) ( pxReturn->pucEthernetBuffer ) ) = pxReturn; + pxReturn->pucEthernetBuffer += ipBUFFER_PADDING; + + /* Store the actual size of the allocated buffer, which may be + * greater than the original requested size. */ + vInitNetworkBuffer( pxReturn, xRequestedSizeBytesCopy ); + } + } + } + #else + { + vInitNetworkBuffer( pxReturn, xRequestedSizeBytes ); + } + #endif /* if ipconfigIS_DISABLED( ipconfigBUFFER_ALLOC_FIXED_SIZE ) */ + } + } + } + + #if ipconfigIS_DISABLED( ipconfigBUFFER_ALLOC_FIXED_SIZE ) + } + #endif + + if( pxReturn == NULL ) + { + iptraceFAILED_TO_OBTAIN_NETWORK_BUFFER(); + } + else + { + iptraceNETWORK_BUFFER_OBTAINED( pxReturn ); + } + + return pxReturn; +} + +/*-----------------------------------------------------------*/ + +void vReleaseNetworkBufferAndDescriptor( NetworkBufferDescriptor_t * const pxNetworkBuffer ) +{ + if( xIsValidNetworkDescriptor( pxNetworkBuffer ) != pdFALSE ) + { + #if ipconfigIS_DISABLED( ipconfigBUFFER_ALLOC_FIXED_SIZE ) + { + /* Release the storage allocated to the buffer payload. */ + vReleaseNetworkBuffer( pxNetworkBuffer->pucEthernetBuffer ); + pxNetworkBuffer->pucEthernetBuffer = NULL; + pxNetworkBuffer->xDataLength = 0U; + } + #endif + + BaseType_t xListItemAlreadyInFreeList; + + /* Ensure the buffer is returned to the list of free buffers before the + * counting semaphore is 'given' to say a buffer is available. */ + ipconfigBUFFER_ALLOC_LOCK(); + { + xListItemAlreadyInFreeList = xFreeNetworkBuffer( pxNetworkBuffer ); + } + ipconfigBUFFER_ALLOC_UNLOCK(); + + if( xListItemAlreadyInFreeList == pdFALSE ) + { + if( xSemaphoreGive( xNetworkBufferSemaphore ) == pdPASS ) + { + iptraceNETWORK_BUFFER_RELEASED( pxNetworkBuffer ); + } + } + } +} + +/*-----------------------------------------------------------*/ + +#if ipconfigIS_ENABLED( ipconfigBUFFER_ALLOC_FIXED_SIZE ) + +NetworkBufferDescriptor_t * pxNetworkBufferGetFromISR( size_t xRequestedSizeBytes ) +{ + NetworkBufferDescriptor_t * pxReturn = NULL; + + if( xNetworkBufferSemaphore != NULL ) + { + /* If there is a semaphore available then there is a buffer available, but, + * as this is called from an interrupt, only take a buffer if there are at + * least baINTERRUPT_BUFFER_GET_THRESHOLD buffers remaining. This prevents, + * to a certain degree at least, a rapidly executing interrupt exhausting + * buffer and in so doing preventing tasks from continuing. */ + if( uxQueueMessagesWaitingFromISR( ( QueueHandle_t ) xNetworkBufferSemaphore ) > ( UBaseType_t ) baINTERRUPT_BUFFER_GET_THRESHOLD ) + { + if( xSemaphoreTakeFromISR( xNetworkBufferSemaphore, NULL ) == pdPASS ) + { + /* Protect the structure as it is accessed from tasks and interrupts. */ + ipconfigBUFFER_ALLOC_LOCK_FROM_ISR(); + { + pxReturn = pxGetNetworkBuffer(); + } + ipconfigBUFFER_ALLOC_UNLOCK_FROM_ISR(); + + if( pxReturn != NULL ) + { + vUpdateMinimumFreeNetworkBuffers(); + + vInitNetworkBuffer( pxReturn, xRequestedSizeBytes ); + } + } + } + } + + if( pxReturn == NULL ) + { + iptraceFAILED_TO_OBTAIN_NETWORK_BUFFER_FROM_ISR(); + } + else + { + iptraceNETWORK_BUFFER_OBTAINED_FROM_ISR( pxReturn ); + } + + return pxReturn; +} + +#endif /* if ipconfigIS_ENABLED( ipconfigBUFFER_ALLOC_FIXED_SIZE ) */ + +/*-----------------------------------------------------------*/ + +#if ipconfigIS_ENABLED( ipconfigBUFFER_ALLOC_FIXED_SIZE ) + +BaseType_t xReleaseNetworkBufferFromISR( NetworkBufferDescriptor_t * const pxNetworkBuffer ) +{ + BaseType_t xHigherPriorityTaskWoken = pdFALSE; + + if( xIsValidNetworkDescriptor( pxNetworkBuffer ) != pdFALSE ) + { + BaseType_t xListItemAlreadyInFreeList; + + /* Ensure the buffer is returned to the list of free buffers before the + * counting semaphore is 'given' to say a buffer is available. */ + ipconfigBUFFER_ALLOC_LOCK_FROM_ISR(); + { + xListItemAlreadyInFreeList = xFreeNetworkBuffer( pxNetworkBuffer ); + } + ipconfigBUFFER_ALLOC_UNLOCK_FROM_ISR(); + + if( xListItemAlreadyInFreeList == pdFALSE ) + { + if( xSemaphoreGiveFromISR( xNetworkBufferSemaphore, &xHigherPriorityTaskWoken ) == pdPASS ) + { + iptraceNETWORK_BUFFER_RELEASED( pxNetworkBuffer ); + } + } + } + + return xHigherPriorityTaskWoken; +} + +#endif /* if ipconfigIS_ENABLED( ipconfigBUFFER_ALLOC_FIXED_SIZE ) */ + +/*-----------------------------------------------------------*/ diff --git a/source/portable/BufferManagement/BufferAllocation_1.c b/source/portable/BufferManagement/BufferAllocation_1.c deleted file mode 100644 index 55ac667ec..000000000 --- a/source/portable/BufferManagement/BufferAllocation_1.c +++ /dev/null @@ -1,442 +0,0 @@ -/* - * FreeRTOS+TCP - * Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * http://aws.amazon.com/freertos - * http://www.FreeRTOS.org - */ - -/****************************************************************************** -* -* See the following web page for essential buffer allocation scheme usage and -* configuration details: -* https://freertos.org/Documentation/03-Libraries/02-FreeRTOS-plus/02-FreeRTOS-plus-TCP/05-Buffer-management -* -******************************************************************************/ - -/* Standard includes. */ -#include - -/* FreeRTOS includes. */ -#include "FreeRTOS.h" -#include "task.h" -#include "queue.h" -#include "semphr.h" - -/* FreeRTOS+TCP includes. */ -#include "FreeRTOS_IP.h" -#include "FreeRTOS_IP_Private.h" -#include "NetworkInterface.h" -#include "NetworkBufferManagement.h" - -/* For an Ethernet interrupt to be able to obtain a network buffer there must - * be at least this number of buffers available. */ -#define baINTERRUPT_BUFFER_GET_THRESHOLD ( 3 ) - -/* A list of free (available) NetworkBufferDescriptor_t structures. */ -static List_t xFreeBuffersList; - -/* Some statistics about the use of buffers. */ -static UBaseType_t uxMinimumFreeNetworkBuffers = 0U; - -/* Declares the pool of NetworkBufferDescriptor_t structures that are available - * to the system. All the network buffers referenced from xFreeBuffersList exist - * in this array. The array is not accessed directly except during initialisation, - * when the xFreeBuffersList is filled (as all the buffers are free when the system - * is booted). */ -static NetworkBufferDescriptor_t xNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ]; - -/* This constant is defined as true to let FreeRTOS_TCP_IP.c know that the - * network buffers have constant size, large enough to hold the biggest Ethernet - * packet. No resizing will be done. */ -const BaseType_t xBufferAllocFixedSize = pdTRUE; - -/* The semaphore used to obtain network buffers. */ -static SemaphoreHandle_t xNetworkBufferSemaphore = NULL; - -#if ( ipconfigTCP_IP_SANITY != 0 ) - static char cIsLow = pdFALSE; - UBaseType_t bIsValidNetworkDescriptor( const NetworkBufferDescriptor_t * pxDesc ); -#else - static UBaseType_t bIsValidNetworkDescriptor( const NetworkBufferDescriptor_t * pxDesc ); -#endif /* ipconfigTCP_IP_SANITY */ - -static void prvShowWarnings( void ); - -/* The user can define their own ipconfigBUFFER_ALLOC_LOCK() and - * ipconfigBUFFER_ALLOC_UNLOCK() macros, especially for use form an ISR. If these - * are not defined then default them to call the normal enter/exit critical - * section macros. */ -#if !defined( ipconfigBUFFER_ALLOC_LOCK ) - - #define ipconfigBUFFER_ALLOC_INIT() do {} while( ipFALSE_BOOL ) - #define ipconfigBUFFER_ALLOC_LOCK_FROM_ISR() \ - UBaseType_t uxSavedInterruptStatus = ( UBaseType_t ) portSET_INTERRUPT_MASK_FROM_ISR(); \ - { - #define ipconfigBUFFER_ALLOC_UNLOCK_FROM_ISR() \ - portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus ); \ -} - - #define ipconfigBUFFER_ALLOC_LOCK() taskENTER_CRITICAL() - #define ipconfigBUFFER_ALLOC_UNLOCK() taskEXIT_CRITICAL() - -#endif /* ipconfigBUFFER_ALLOC_LOCK */ - -/*-----------------------------------------------------------*/ - -#if ( ipconfigTCP_IP_SANITY != 0 ) - -/* HT: SANITY code will be removed as soon as the library is stable - * and and ready to become public - * Function below gives information about the use of buffers */ - #define WARN_LOW ( 2 ) - #define WARN_HIGH ( ( 5 * ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ) / 10 ) - -#endif /* ipconfigTCP_IP_SANITY */ - -/*-----------------------------------------------------------*/ - -#if ( ipconfigTCP_IP_SANITY != 0 ) - - BaseType_t prvIsFreeBuffer( const NetworkBufferDescriptor_t * pxDescr ) - { - return ( bIsValidNetworkDescriptor( pxDescr ) != 0 ) && - ( listIS_CONTAINED_WITHIN( &xFreeBuffersList, &( pxDescr->xBufferListItem ) ) != 0 ); - } - /*-----------------------------------------------------------*/ - - static void prvShowWarnings( void ) - { - UBaseType_t uxCount = uxGetNumberOfFreeNetworkBuffers(); - - if( ( ( cIsLow == 0 ) && ( uxCount <= WARN_LOW ) ) || ( ( cIsLow != 0 ) && ( uxCount >= WARN_HIGH ) ) ) - { - cIsLow = !cIsLow; - FreeRTOS_debug_printf( ( "*** Warning *** %s %lu buffers left\n", cIsLow ? "only" : "now", uxCount ) ); - } - } - /*-----------------------------------------------------------*/ - - UBaseType_t bIsValidNetworkDescriptor( const NetworkBufferDescriptor_t * pxDesc ) - { - uint32_t offset = ( uint32_t ) ( ( ( const char * ) pxDesc ) - ( ( const char * ) xNetworkBuffers ) ); - - if( ( offset >= sizeof( xNetworkBuffers ) ) || - ( ( offset % sizeof( xNetworkBuffers[ 0 ] ) ) != 0 ) ) - { - return pdFALSE; - } - - return ( UBaseType_t ) ( pxDesc - xNetworkBuffers ) + 1; - } - /*-----------------------------------------------------------*/ - -#else /* if ( ipconfigTCP_IP_SANITY != 0 ) */ - static UBaseType_t bIsValidNetworkDescriptor( const NetworkBufferDescriptor_t * pxDesc ) - { - ( void ) pxDesc; - return ( UBaseType_t ) pdTRUE; - } - /*-----------------------------------------------------------*/ - - static void prvShowWarnings( void ) - { - } - /*-----------------------------------------------------------*/ - -#endif /* ipconfigTCP_IP_SANITY */ - -BaseType_t xNetworkBuffersInitialise( void ) -{ - BaseType_t xReturn; - uint32_t x; - - /* Only initialise the buffers and their associated kernel objects if they - * have not been initialised before. */ - if( xNetworkBufferSemaphore == NULL ) - { - /* In case alternative locking is used, the mutexes can be initialised - * here */ - ipconfigBUFFER_ALLOC_INIT(); - - #if ( configSUPPORT_STATIC_ALLOCATION == 1 ) - { - static StaticSemaphore_t xNetworkBufferSemaphoreBuffer; - xNetworkBufferSemaphore = xSemaphoreCreateCountingStatic( - ( UBaseType_t ) ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS, - ( UBaseType_t ) ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS, - &xNetworkBufferSemaphoreBuffer ); - } - #else - { - xNetworkBufferSemaphore = xSemaphoreCreateCounting( ( UBaseType_t ) ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS, ( UBaseType_t ) ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ); - } - #endif /* configSUPPORT_STATIC_ALLOCATION */ - - configASSERT( xNetworkBufferSemaphore != NULL ); - - if( xNetworkBufferSemaphore != NULL ) - { - vListInitialise( &xFreeBuffersList ); - - /* Initialise all the network buffers. The buffer storage comes - * from the network interface, and different hardware has different - * requirements. */ - vNetworkInterfaceAllocateRAMToBuffers( xNetworkBuffers ); - - for( x = 0U; x < ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS; x++ ) - { - /* Initialise and set the owner of the buffer list items. */ - vListInitialiseItem( &( xNetworkBuffers[ x ].xBufferListItem ) ); - listSET_LIST_ITEM_OWNER( &( xNetworkBuffers[ x ].xBufferListItem ), &xNetworkBuffers[ x ] ); - - /* Currently, all buffers are available for use. */ - vListInsert( &xFreeBuffersList, &( xNetworkBuffers[ x ].xBufferListItem ) ); - } - - uxMinimumFreeNetworkBuffers = ( UBaseType_t ) ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS; - } - } - - if( xNetworkBufferSemaphore == NULL ) - { - xReturn = pdFAIL; - } - else - { - xReturn = pdPASS; - } - - return xReturn; -} -/*-----------------------------------------------------------*/ - -NetworkBufferDescriptor_t * pxGetNetworkBufferWithDescriptor( size_t xRequestedSizeBytes, - TickType_t xBlockTimeTicks ) -{ - NetworkBufferDescriptor_t * pxReturn = NULL; - BaseType_t xInvalid = pdFALSE; - UBaseType_t uxCount; - - /* The current implementation only has a single size memory block, so - * the requested size parameter is not used (yet). */ - ( void ) xRequestedSizeBytes; - - if( xNetworkBufferSemaphore != NULL ) - { - /* If there is a semaphore available, there is a network buffer - * available. */ - if( xSemaphoreTake( xNetworkBufferSemaphore, xBlockTimeTicks ) == pdPASS ) - { - /* Protect the structure as it is accessed from tasks and - * interrupts. */ - ipconfigBUFFER_ALLOC_LOCK(); - { - pxReturn = ( NetworkBufferDescriptor_t * ) listGET_OWNER_OF_HEAD_ENTRY( &xFreeBuffersList ); - - if( ( bIsValidNetworkDescriptor( pxReturn ) != pdFALSE_UNSIGNED ) && - listIS_CONTAINED_WITHIN( &xFreeBuffersList, &( pxReturn->xBufferListItem ) ) ) - { - ( void ) uxListRemove( &( pxReturn->xBufferListItem ) ); - } - else - { - xInvalid = pdTRUE; - } - } - ipconfigBUFFER_ALLOC_UNLOCK(); - - if( xInvalid == pdTRUE ) - { - /* _RB_ Can printf() be called from an interrupt? (comment - * above says this can be called from an interrupt too) */ - - /* _HT_ The function shall not be called from an ISR. Comment - * was indeed misleading. Hopefully clear now? - * So the printf()is OK here. */ - FreeRTOS_debug_printf( ( "pxGetNetworkBufferWithDescriptor: INVALID BUFFER: %p (valid %lu)\n", - pxReturn, bIsValidNetworkDescriptor( pxReturn ) ) ); - pxReturn = NULL; - } - else - { - /* Reading UBaseType_t, no critical section needed. */ - uxCount = listCURRENT_LIST_LENGTH( &xFreeBuffersList ); - - /* For stats, latch the lowest number of network buffers since - * booting. */ - if( uxMinimumFreeNetworkBuffers > uxCount ) - { - uxMinimumFreeNetworkBuffers = uxCount; - } - - pxReturn->xDataLength = xRequestedSizeBytes; - pxReturn->pxInterface = NULL; - pxReturn->pxEndPoint = NULL; - - #if ( ipconfigTCP_IP_SANITY != 0 ) - { - prvShowWarnings(); - } - #endif /* ipconfigTCP_IP_SANITY */ - - #if ( ipconfigUSE_LINKED_RX_MESSAGES != 0 ) - { - /* make sure the buffer is not linked */ - pxReturn->pxNextBuffer = NULL; - } - #endif /* ipconfigUSE_LINKED_RX_MESSAGES */ - } - - iptraceNETWORK_BUFFER_OBTAINED( pxReturn ); - } - else - { - /* lint wants to see at least a comment. */ - iptraceFAILED_TO_OBTAIN_NETWORK_BUFFER(); - } - } - - return pxReturn; -} -/*-----------------------------------------------------------*/ - -NetworkBufferDescriptor_t * pxNetworkBufferGetFromISR( size_t xRequestedSizeBytes ) -{ - NetworkBufferDescriptor_t * pxReturn = NULL; - - /* The current implementation only has a single size memory block, so - * the requested size parameter is not used (yet). */ - ( void ) xRequestedSizeBytes; - - /* If there is a semaphore available then there is a buffer available, but, - * as this is called from an interrupt, only take a buffer if there are at - * least baINTERRUPT_BUFFER_GET_THRESHOLD buffers remaining. This prevents, - * to a certain degree at least, a rapidly executing interrupt exhausting - * buffer and in so doing preventing tasks from continuing. */ - if( uxQueueMessagesWaitingFromISR( ( QueueHandle_t ) xNetworkBufferSemaphore ) > ( UBaseType_t ) baINTERRUPT_BUFFER_GET_THRESHOLD ) - { - if( xSemaphoreTakeFromISR( xNetworkBufferSemaphore, NULL ) == pdPASS ) - { - /* Protect the structure as it is accessed from tasks and interrupts. */ - ipconfigBUFFER_ALLOC_LOCK_FROM_ISR(); - { - pxReturn = ( NetworkBufferDescriptor_t * ) listGET_OWNER_OF_HEAD_ENTRY( &xFreeBuffersList ); - uxListRemove( &( pxReturn->xBufferListItem ) ); - } - ipconfigBUFFER_ALLOC_UNLOCK_FROM_ISR(); - - iptraceNETWORK_BUFFER_OBTAINED_FROM_ISR( pxReturn ); - } - } - - if( pxReturn == NULL ) - { - iptraceFAILED_TO_OBTAIN_NETWORK_BUFFER_FROM_ISR(); - } - - return pxReturn; -} -/*-----------------------------------------------------------*/ - -BaseType_t vNetworkBufferReleaseFromISR( NetworkBufferDescriptor_t * const pxNetworkBuffer ) -{ - BaseType_t xHigherPriorityTaskWoken = pdFALSE; - - /* Ensure the buffer is returned to the list of free buffers before the - * counting semaphore is 'given' to say a buffer is available. */ - ipconfigBUFFER_ALLOC_LOCK_FROM_ISR(); - { - vListInsertEnd( &xFreeBuffersList, &( pxNetworkBuffer->xBufferListItem ) ); - } - ipconfigBUFFER_ALLOC_UNLOCK_FROM_ISR(); - - ( void ) xSemaphoreGiveFromISR( xNetworkBufferSemaphore, &xHigherPriorityTaskWoken ); - iptraceNETWORK_BUFFER_RELEASED( pxNetworkBuffer ); - - return xHigherPriorityTaskWoken; -} -/*-----------------------------------------------------------*/ - -void vReleaseNetworkBufferAndDescriptor( NetworkBufferDescriptor_t * const pxNetworkBuffer ) -{ - BaseType_t xListItemAlreadyInFreeList; - - if( bIsValidNetworkDescriptor( pxNetworkBuffer ) == pdFALSE_UNSIGNED ) - { - FreeRTOS_debug_printf( ( "vReleaseNetworkBufferAndDescriptor: Invalid buffer %p\n", pxNetworkBuffer ) ); - } - else - { - /* Ensure the buffer is returned to the list of free buffers before the - * counting semaphore is 'given' to say a buffer is available. */ - ipconfigBUFFER_ALLOC_LOCK(); - { - { - xListItemAlreadyInFreeList = listIS_CONTAINED_WITHIN( &xFreeBuffersList, &( pxNetworkBuffer->xBufferListItem ) ); - - if( xListItemAlreadyInFreeList == pdFALSE ) - { - vListInsertEnd( &xFreeBuffersList, &( pxNetworkBuffer->xBufferListItem ) ); - } - } - } - ipconfigBUFFER_ALLOC_UNLOCK(); - - if( xListItemAlreadyInFreeList ) - { - FreeRTOS_debug_printf( ( "vReleaseNetworkBufferAndDescriptor: %p ALREADY RELEASED (now %lu)\n", - pxNetworkBuffer, uxGetNumberOfFreeNetworkBuffers() ) ); - } - else - { - ( void ) xSemaphoreGive( xNetworkBufferSemaphore ); - prvShowWarnings(); - } - - iptraceNETWORK_BUFFER_RELEASED( pxNetworkBuffer ); - } -} -/*-----------------------------------------------------------*/ - -UBaseType_t uxGetMinimumFreeNetworkBuffers( void ) -{ - return uxMinimumFreeNetworkBuffers; -} -/*-----------------------------------------------------------*/ - -UBaseType_t uxGetNumberOfFreeNetworkBuffers( void ) -{ - return listCURRENT_LIST_LENGTH( &xFreeBuffersList ); -} - -NetworkBufferDescriptor_t * pxResizeNetworkBufferWithDescriptor( NetworkBufferDescriptor_t * pxNetworkBuffer, - size_t xNewSizeBytes ) -{ - /* In BufferAllocation_1.c all network buffer are allocated with a - * maximum size of 'ipTOTAL_ETHERNET_FRAME_SIZE'.No need to resize the - * network buffer. */ - pxNetworkBuffer->xDataLength = xNewSizeBytes; - return pxNetworkBuffer; -} - -/*#endif */ /* ipconfigINCLUDE_TEST_CODE */ diff --git a/source/portable/BufferManagement/BufferAllocation_2.c b/source/portable/BufferManagement/BufferAllocation_2.c deleted file mode 100644 index b67d1d424..000000000 --- a/source/portable/BufferManagement/BufferAllocation_2.c +++ /dev/null @@ -1,501 +0,0 @@ -/* - * FreeRTOS+TCP - * Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * http://www.FreeRTOS.org - * http://aws.amazon.com/freertos - * - * 1 tab == 4 spaces! - */ - -/****************************************************************************** -* -* See the following web page for essential buffer allocation scheme usage and -* configuration details: -* https://freertos.org/Documentation/03-Libraries/02-FreeRTOS-plus/02-FreeRTOS-plus-TCP/05-Buffer-management -* -******************************************************************************/ - -/* THIS FILE SHOULD NOT BE USED IF THE PROJECT INCLUDES A MEMORY ALLOCATOR - * THAT WILL FRAGMENT THE HEAP MEMORY. For example, heap_2 must not be used, - * heap_4 can be used. */ - - -/* Standard includes. */ -#include - -/* FreeRTOS includes. */ -#include "FreeRTOS.h" -#include "task.h" -#include "semphr.h" - -/* FreeRTOS+TCP includes. */ -#include "FreeRTOS_IP.h" -#include "FreeRTOS_UDP_IP.h" -#include "FreeRTOS_IP_Private.h" -#include "NetworkInterface.h" -#include "NetworkBufferManagement.h" - -/* The obtained network buffer must be large enough to hold a packet that might - * replace the packet that was requested to be sent. */ -#if ipconfigUSE_TCP == 1 - #define baMINIMAL_BUFFER_SIZE sizeof( TCPPacket_t ) -#else - #define baMINIMAL_BUFFER_SIZE sizeof( ARPPacket_t ) -#endif /* ipconfigUSE_TCP == 1 */ - -#define baALIGNMENT_BYTES ( sizeof( size_t ) ) -#define baALIGNMENT_MASK ( baALIGNMENT_BYTES - 1U ) -#define baADD_WILL_OVERFLOW( a, b ) ( ( a ) > ( SIZE_MAX - ( b ) ) ) - -STATIC_ASSERT( ipconfigETHERNET_MINIMUM_PACKET_BYTES <= baMINIMAL_BUFFER_SIZE ); - -/* A list of free (available) NetworkBufferDescriptor_t structures. */ -static List_t xFreeBuffersList; - -/* Some statistics about the use of buffers. */ -static size_t uxMinimumFreeNetworkBuffers; - -/* This constant is defined as false to let FreeRTOS_TCP_IP.c know that the - * network buffers have a variable size: resizing may be necessary */ -const BaseType_t xBufferAllocFixedSize = pdFALSE; - -/* The semaphore used to obtain network buffers. */ -static SemaphoreHandle_t xNetworkBufferSemaphore = NULL; - -/*-----------------------------------------------------------*/ - -BaseType_t xNetworkBuffersInitialise( void ) -{ - /* Declares the pool of NetworkBufferDescriptor_t structures that are available - * to the system. All the network buffers referenced from xFreeBuffersList exist - * in this array. The array is not accessed directly except during initialisation, - * when the xFreeBuffersList is filled (as all the buffers are free when the system - * is booted). */ - static NetworkBufferDescriptor_t xNetworkBufferDescriptors[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ]; - BaseType_t xReturn; - uint32_t x; - - /* Only initialise the buffers and their associated kernel objects if they - * have not been initialised before. */ - if( xNetworkBufferSemaphore == NULL ) - { - #if ( configSUPPORT_STATIC_ALLOCATION == 1 ) - { - static StaticSemaphore_t xNetworkBufferSemaphoreBuffer; - xNetworkBufferSemaphore = xSemaphoreCreateCountingStatic( - ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS, - ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS, - &xNetworkBufferSemaphoreBuffer ); - } - #else - { - xNetworkBufferSemaphore = xSemaphoreCreateCounting( ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS, ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ); - } - #endif /* configSUPPORT_STATIC_ALLOCATION */ - - configASSERT( xNetworkBufferSemaphore != NULL ); - - if( xNetworkBufferSemaphore != NULL ) - { - #if ( configQUEUE_REGISTRY_SIZE > 0 ) - { - vQueueAddToRegistry( xNetworkBufferSemaphore, "NetBufSem" ); - } - #endif /* configQUEUE_REGISTRY_SIZE */ - - /* If the trace recorder code is included name the semaphore for viewing - * in FreeRTOS+Trace. */ - #if ( ipconfigINCLUDE_EXAMPLE_FREERTOS_PLUS_TRACE_CALLS == 1 ) - { - extern QueueHandle_t xNetworkEventQueue; - vTraceSetQueueName( xNetworkEventQueue, "IPStackEvent" ); - vTraceSetQueueName( xNetworkBufferSemaphore, "NetworkBufferCount" ); - } - #endif /* ipconfigINCLUDE_EXAMPLE_FREERTOS_PLUS_TRACE_CALLS == 1 */ - - vListInitialise( &xFreeBuffersList ); - - /* Initialise all the network buffers. No storage is allocated to - * the buffers yet. */ - for( x = 0U; x < ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS; x++ ) - { - /* Initialise and set the owner of the buffer list items. */ - xNetworkBufferDescriptors[ x ].pucEthernetBuffer = NULL; - vListInitialiseItem( &( xNetworkBufferDescriptors[ x ].xBufferListItem ) ); - listSET_LIST_ITEM_OWNER( &( xNetworkBufferDescriptors[ x ].xBufferListItem ), &xNetworkBufferDescriptors[ x ] ); - - /* Currently, all buffers are available for use. */ - vListInsert( &xFreeBuffersList, &( xNetworkBufferDescriptors[ x ].xBufferListItem ) ); - } - - uxMinimumFreeNetworkBuffers = ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS; - } - } - - if( xNetworkBufferSemaphore == NULL ) - { - xReturn = pdFAIL; - } - else - { - xReturn = pdPASS; - } - - return xReturn; -} -/*-----------------------------------------------------------*/ - -uint8_t * pucGetNetworkBuffer( size_t * pxRequestedSizeBytes ) -{ - uint8_t * pucEthernetBuffer = NULL; - size_t uxMaxAllowedBytes = ( SIZE_MAX >> 1 ); - size_t xSize = *pxRequestedSizeBytes; - size_t xBytesRequiredForAlignment, xAllocatedBytes; - BaseType_t xIntegerOverflowed = pdFALSE; - - if( xSize < baMINIMAL_BUFFER_SIZE ) - { - /* Buffers must be at least large enough to hold a TCP-packet with - * headers, or an ARP packet, in case TCP is not included. */ - xSize = baMINIMAL_BUFFER_SIZE; - } - - /* Round up xSize to the nearest multiple of N bytes, - * where N equals 'sizeof( size_t )'. */ - if( ( xSize & baALIGNMENT_MASK ) != 0U ) - { - xBytesRequiredForAlignment = baALIGNMENT_BYTES - ( xSize & baALIGNMENT_MASK ); - - if( baADD_WILL_OVERFLOW( xSize, xBytesRequiredForAlignment ) == pdFAIL ) - { - xSize += xBytesRequiredForAlignment; - } - else - { - xIntegerOverflowed = pdTRUE; - } - } - - if( baADD_WILL_OVERFLOW( xSize, ipBUFFER_PADDING ) == pdFAIL ) - { - xAllocatedBytes = xSize + ipBUFFER_PADDING; - } - else - { - xIntegerOverflowed = pdTRUE; - } - - if( ( xIntegerOverflowed == pdFALSE ) && ( xAllocatedBytes <= uxMaxAllowedBytes ) ) - { - *pxRequestedSizeBytes = xSize; - - /* Allocate a buffer large enough to store the requested Ethernet frame size - * and a pointer to a network buffer structure (hence the addition of - * ipBUFFER_PADDING bytes). */ - pucEthernetBuffer = ( uint8_t * ) pvPortMalloc( xAllocatedBytes ); - configASSERT( pucEthernetBuffer != NULL ); - - if( pucEthernetBuffer != NULL ) - { - /* Enough space is left at the start of the buffer to place a pointer to - * the network buffer structure that references this Ethernet buffer. - * Return a pointer to the start of the Ethernet buffer itself. */ - - /* MISRA Ref 18.4.1 [Usage of +, -, += and -= operators on expression of pointer type]. */ - /* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-184. */ - /* coverity[misra_c_2012_rule_18_4_violation] */ - pucEthernetBuffer += ipBUFFER_PADDING; - } - } - - return pucEthernetBuffer; -} -/*-----------------------------------------------------------*/ - -void vReleaseNetworkBuffer( uint8_t * pucEthernetBuffer ) -{ - uint8_t * pucEthernetBufferCopy = pucEthernetBuffer; - - /* There is space before the Ethernet buffer in which a pointer to the - * network buffer that references this Ethernet buffer is stored. Remove the - * space before freeing the buffer. */ - if( pucEthernetBufferCopy != NULL ) - { - /* MISRA Ref 18.4.1 [Usage of +, -, += and -= operators on expression of pointer type]. */ - /* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-184. */ - /* coverity[misra_c_2012_rule_18_4_violation] */ - pucEthernetBufferCopy -= ipBUFFER_PADDING; - vPortFree( ( void * ) pucEthernetBufferCopy ); - } -} -/*-----------------------------------------------------------*/ - -NetworkBufferDescriptor_t * pxGetNetworkBufferWithDescriptor( size_t xRequestedSizeBytes, - TickType_t xBlockTimeTicks ) -{ - NetworkBufferDescriptor_t * pxReturn = NULL; - size_t uxCount; - size_t uxMaxAllowedBytes = ( SIZE_MAX >> 1 ); - size_t xRequestedSizeBytesCopy = xRequestedSizeBytes; - size_t xBytesRequiredForAlignment, xAllocatedBytes; - BaseType_t xIntegerOverflowed = pdFALSE; - - if( ( xRequestedSizeBytesCopy < ( size_t ) baMINIMAL_BUFFER_SIZE ) ) - { - /* ARP packets can replace application packets, so the storage must be - * at least large enough to hold an ARP. */ - xRequestedSizeBytesCopy = baMINIMAL_BUFFER_SIZE; - } - - /* Add 2 bytes to xRequestedSizeBytesCopy and round up xRequestedSizeBytesCopy - * to the nearest multiple of N bytes, where N equals 'sizeof( size_t )'. */ - if( baADD_WILL_OVERFLOW( xRequestedSizeBytesCopy, 2U ) == pdFAIL ) - { - xRequestedSizeBytesCopy += 2U; - } - else - { - xIntegerOverflowed = pdTRUE; - } - - if( ( xRequestedSizeBytesCopy & baALIGNMENT_MASK ) != 0U ) - { - xBytesRequiredForAlignment = baALIGNMENT_BYTES - ( xRequestedSizeBytesCopy & baALIGNMENT_MASK ); - - if( baADD_WILL_OVERFLOW( xRequestedSizeBytesCopy, xBytesRequiredForAlignment ) == pdFAIL ) - { - xRequestedSizeBytesCopy += xBytesRequiredForAlignment; - } - else - { - xIntegerOverflowed = pdTRUE; - } - } - - if( baADD_WILL_OVERFLOW( xRequestedSizeBytesCopy, ipBUFFER_PADDING ) == pdFAIL ) - { - xAllocatedBytes = xRequestedSizeBytesCopy + ipBUFFER_PADDING; - } - else - { - xIntegerOverflowed = pdTRUE; - } - - if( ( xIntegerOverflowed == pdFALSE ) && ( xAllocatedBytes <= uxMaxAllowedBytes ) && ( xNetworkBufferSemaphore != NULL ) ) - { - /* If there is a semaphore available, there is a network buffer available. */ - if( xSemaphoreTake( xNetworkBufferSemaphore, xBlockTimeTicks ) == pdPASS ) - { - /* Protect the structure as it is accessed from tasks and interrupts. */ - taskENTER_CRITICAL(); - { - pxReturn = ( NetworkBufferDescriptor_t * ) listGET_OWNER_OF_HEAD_ENTRY( &xFreeBuffersList ); - ( void ) uxListRemove( &( pxReturn->xBufferListItem ) ); - } - taskEXIT_CRITICAL(); - - /* Reading UBaseType_t, no critical section needed. */ - uxCount = listCURRENT_LIST_LENGTH( &xFreeBuffersList ); - - if( uxMinimumFreeNetworkBuffers > uxCount ) - { - uxMinimumFreeNetworkBuffers = uxCount; - } - - /* Allocate storage of exactly the requested size to the buffer. */ - configASSERT( pxReturn->pucEthernetBuffer == NULL ); - - if( xRequestedSizeBytesCopy > 0U ) - { - /* Extra space is obtained so a pointer to the network buffer can - * be stored at the beginning of the buffer. */ - pxReturn->pucEthernetBuffer = ( uint8_t * ) pvPortMalloc( xAllocatedBytes ); - - if( pxReturn->pucEthernetBuffer == NULL ) - { - /* The attempt to allocate storage for the buffer payload failed, - * so the network buffer structure cannot be used and must be - * released. */ - vReleaseNetworkBufferAndDescriptor( pxReturn ); - pxReturn = NULL; - } - else - { - /* Store a pointer to the network buffer structure in the - * buffer storage area, then move the buffer pointer on past the - * stored pointer so the pointer value is not overwritten by the - * application when the buffer is used. */ - /* MISRA Ref 11.3.1 [Misaligned access] */ - /* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */ - /* coverity[misra_c_2012_rule_11_3_violation] */ - *( ( NetworkBufferDescriptor_t ** ) ( pxReturn->pucEthernetBuffer ) ) = pxReturn; - - /* MISRA Ref 18.4.1 [Usage of +, -, += and -= operators on expression of pointer type]. */ - /* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-184. */ - /* coverity[misra_c_2012_rule_18_4_violation] */ - pxReturn->pucEthernetBuffer += ipBUFFER_PADDING; - - /* Store the actual size of the allocated buffer, which may be - * greater than the original requested size. */ - pxReturn->xDataLength = xRequestedSizeBytesCopy; - pxReturn->pxInterface = NULL; - pxReturn->pxEndPoint = NULL; - - #if ( ipconfigUSE_LINKED_RX_MESSAGES != 0 ) - { - /* make sure the buffer is not linked */ - pxReturn->pxNextBuffer = NULL; - } - #endif /* ipconfigUSE_LINKED_RX_MESSAGES */ - } - } - else - { - /* A descriptor is being returned without an associated buffer being - * allocated. */ - } - } - } - - if( pxReturn == NULL ) - { - iptraceFAILED_TO_OBTAIN_NETWORK_BUFFER(); - } - else - { - /* No action. */ - iptraceNETWORK_BUFFER_OBTAINED( pxReturn ); - } - - return pxReturn; -} -/*-----------------------------------------------------------*/ - -void vReleaseNetworkBufferAndDescriptor( NetworkBufferDescriptor_t * const pxNetworkBuffer ) -{ - BaseType_t xListItemAlreadyInFreeList; - - /* Ensure the buffer is returned to the list of free buffers before the - * counting semaphore is 'given' to say a buffer is available. Release the - * storage allocated to the buffer payload. THIS FILE SHOULD NOT BE USED - * IF THE PROJECT INCLUDES A MEMORY ALLOCATOR THAT WILL FRAGMENT THE HEAP - * MEMORY. For example, heap_2 must not be used, heap_4 can be used. */ - vReleaseNetworkBuffer( pxNetworkBuffer->pucEthernetBuffer ); - pxNetworkBuffer->pucEthernetBuffer = NULL; - pxNetworkBuffer->xDataLength = 0U; - - taskENTER_CRITICAL(); - { - xListItemAlreadyInFreeList = listIS_CONTAINED_WITHIN( &xFreeBuffersList, &( pxNetworkBuffer->xBufferListItem ) ); - - if( xListItemAlreadyInFreeList == pdFALSE ) - { - vListInsertEnd( &xFreeBuffersList, &( pxNetworkBuffer->xBufferListItem ) ); - } - } - taskEXIT_CRITICAL(); - - /* - * Update the network state machine, unless the program fails to release its 'xNetworkBufferSemaphore'. - * The program should only try to release its semaphore if 'xListItemAlreadyInFreeList' is false. - */ - if( xListItemAlreadyInFreeList == pdFALSE ) - { - if( xSemaphoreGive( xNetworkBufferSemaphore ) == pdTRUE ) - { - iptraceNETWORK_BUFFER_RELEASED( pxNetworkBuffer ); - } - } - else - { - /* No action. */ - iptraceNETWORK_BUFFER_RELEASED( pxNetworkBuffer ); - } -} -/*-----------------------------------------------------------*/ - -/* - * Returns the number of free network buffers - */ -UBaseType_t uxGetNumberOfFreeNetworkBuffers( void ) -{ - return listCURRENT_LIST_LENGTH( &xFreeBuffersList ); -} -/*-----------------------------------------------------------*/ - -UBaseType_t uxGetMinimumFreeNetworkBuffers( void ) -{ - return uxMinimumFreeNetworkBuffers; -} -/*-----------------------------------------------------------*/ - -NetworkBufferDescriptor_t * pxResizeNetworkBufferWithDescriptor( NetworkBufferDescriptor_t * pxNetworkBuffer, - size_t xNewSizeBytes ) -{ - size_t xOriginalLength; - uint8_t * pucBuffer; - size_t uxSizeBytes = xNewSizeBytes; - NetworkBufferDescriptor_t * pxNetworkBufferCopy = pxNetworkBuffer; - - xOriginalLength = pxNetworkBufferCopy->xDataLength + ipBUFFER_PADDING; - - if( baADD_WILL_OVERFLOW( uxSizeBytes, ipBUFFER_PADDING ) == pdFAIL ) - { - uxSizeBytes = uxSizeBytes + ipBUFFER_PADDING; - - pucBuffer = pucGetNetworkBuffer( &( uxSizeBytes ) ); - - if( pucBuffer == NULL ) - { - /* In case the allocation fails, return NULL. */ - pxNetworkBufferCopy = NULL; - } - else - { - pxNetworkBufferCopy->xDataLength = uxSizeBytes; - - if( uxSizeBytes > xOriginalLength ) - { - uxSizeBytes = xOriginalLength; - } - - /* MISRA Ref 18.4.1 [Usage of +, -, += and -= operators on expression of pointer type]. */ - /* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-184. */ - /* coverity[misra_c_2012_rule_18_4_violation] */ - ( void ) memcpy( pucBuffer - ipBUFFER_PADDING, - /* MISRA Ref 18.4.1 [Usage of +, -, += and -= operators on expression of pointer type]. */ - /* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-184. */ - /* coverity[misra_c_2012_rule_18_4_violation] */ - pxNetworkBufferCopy->pucEthernetBuffer - ipBUFFER_PADDING, - uxSizeBytes ); - vReleaseNetworkBuffer( pxNetworkBufferCopy->pucEthernetBuffer ); - pxNetworkBufferCopy->pucEthernetBuffer = pucBuffer; - } - } - else - { - pxNetworkBufferCopy = NULL; - } - - return pxNetworkBufferCopy; -} diff --git a/source/portable/CMakeLists.txt b/source/portable/CMakeLists.txt index 4afd6fca1..04915bf2d 100644 --- a/source/portable/CMakeLists.txt +++ b/source/portable/CMakeLists.txt @@ -1,10 +1,12 @@ add_library( freertos_plus_tcp_port STATIC ) -target_sources( freertos_plus_tcp_port - PRIVATE - BufferManagement/BufferAllocation_${FREERTOS_PLUS_TCP_BUFFER_ALLOCATION}.c - # Note: There's NetworkInterface/pic32mzef that has it's own BufferAllocation_2.c -) +if (NOT ( (FREERTOS_PLUS_TCP_NETWORK_IF STREQUAL "PIC32MZEF_ETH") OR + (FREERTOS_PLUS_TCP_NETWORK_IF STREQUAL "PIC32MZEF_WIFI") ) ) + target_sources( freertos_plus_tcp_port + PRIVATE + BufferManagement/BufferAllocation.c + ) +endif() target_include_directories( freertos_plus_tcp_port PUBLIC diff --git a/source/portable/NetworkInterface/ATSAME5x/NetworkInterface.c b/source/portable/NetworkInterface/ATSAME5x/NetworkInterface.c index dabedde09..76ce47438 100644 --- a/source/portable/NetworkInterface/ATSAME5x/NetworkInterface.c +++ b/source/portable/NetworkInterface/ATSAME5x/NetworkInterface.c @@ -119,21 +119,6 @@ static BaseType_t isICMP( const NetworkBufferDescriptor_t * pxDescriptor ); #define ipCONSIDER_FRAME_FOR_PROCESSING( pucEthernetBuffer ) eProcessBuffer #endif -/* Ethernet buffers for BufferAllocation_1.c scheme. - * Set ipUSE_STATIC_ALLOCATION to 1 if using BufferAllocation_1.c, - * otherwise to 0, to save RAM. From Iperf testing, there is no point in using - * static allocation with a non zero-copy driver. - */ -#define ipUSE_STATIC_ALLOCATION 0 -#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 /* if ( ipUSE_STATIC_ALLOCATION == 1 ) */ - - /* Holds the handle of the task used as a deferred interrupt processor. The * handle is used so direct notifications can be sent to the task for all EMAC/DMA * related interrupts. */ @@ -497,28 +482,6 @@ void xRxCallback( void ) vTaskNotifyGiveFromISR( xEMACTaskHandle, 0 ); } -#if ( ipUSE_STATIC_ALLOCATION == 1 ) - -/* Next provide the vNetworkInterfaceAllocateRAMToBuffers() function, which - * simply fills in the pucEthernetBuffer member of each descriptor. */ - void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ) - { - BaseType_t x; - - for( x = 0; x < ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS; x++ ) - { - /* pucEthernetBuffer is set to point ipBUFFER_PADDING bytes in from the - * beginning of the allocated buffer. */ - pxNetworkBuffers[ x ].pucEthernetBuffer = &( ucBuffers[ x ][ ipBUFFER_PADDING ] ); - - /* The following line is also required, but will not be required in - * future versions. */ - *( ( uint32_t * ) &ucBuffers[ x ][ 0 ] ) = ( uint32_t ) &( pxNetworkBuffers[ x ] ); - } - } -#endif /* if ( ipUSE_STATIC_ALLOCATION == 1 ) */ - - /*********************************************************************/ /* GMAC functions */ /*********************************************************************/ diff --git a/source/portable/NetworkInterface/DriverSAM/NetworkInterface.c b/source/portable/NetworkInterface/DriverSAM/NetworkInterface.c index 8a837dd35..256f6887a 100644 --- a/source/portable/NetworkInterface/DriverSAM/NetworkInterface.c +++ b/source/portable/NetworkInterface/DriverSAM/NetworkInterface.c @@ -302,6 +302,14 @@ const PhyProperties_t xPHYProperties = * see "../Common/phyHandling.c". */ static EthernetPhy_t xPhyObject; +#if ipconfigIS_ENABLED( ipconfigBUFFER_ALLOC_STATIC ) + #if ipconfigIS_ENABLED( ipconfigBUFFER_ALLOC_STATIC_CUSTOM_SIZE ) + const UBaseType_t uxBufferAllocFixedSize = NETWORK_BUFFER_SIZE; + #else + #error ipconfigBUFFER_ALLOC_STATIC_CUSTOM_SIZE must be enabled for DriverSAM + #endif +#endif + /*-----------------------------------------------------------*/ /* @@ -1408,23 +1416,6 @@ static void vCheckBuffersAndQueue( void ) } /*-----------------------------------------------------------*/ -extern uint8_t ucNetworkPackets[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS * NETWORK_BUFFER_SIZE ]; -void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ) -{ - uint8_t * ucRAMBuffer = ucNetworkPackets; - uint32_t ulIndex; - - for( ulIndex = 0; ulIndex < ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS; ulIndex++ ) - { - pxNetworkBuffers[ ulIndex ].pucEthernetBuffer = ucRAMBuffer + ipBUFFER_PADDING; - *( ( unsigned * ) ucRAMBuffer ) = ( unsigned ) ( &( pxNetworkBuffers[ ulIndex ] ) ); - ucRAMBuffer += NETWORK_BUFFER_SIZE; - } - - cache_clean_invalidate(); -} -/*-----------------------------------------------------------*/ - static void prvEMACHandlerTask( void * pvParameters ) { UBaseType_t uxCount; diff --git a/source/portable/NetworkInterface/DriverSAM/gmac_SAM.c b/source/portable/NetworkInterface/DriverSAM/gmac_SAM.c index e43924b2c..552e2bc28 100644 --- a/source/portable/NetworkInterface/DriverSAM/gmac_SAM.c +++ b/source/portable/NetworkInterface/DriverSAM/gmac_SAM.c @@ -123,22 +123,6 @@ * @{ */ -/* - * When BufferAllocation_1.c is used, the network buffer space - * is declared statically as 'ucNetworkPackets[]'. - * Like the DMA descriptors, this array is located in a non-cached area. - * Here an example of the total size: - * - * #define ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS 24 - * #define GMAC_FRAME_LENTGH_MAX 1536 - * Hidden space for back-pointer and IP-type 16 - * - * Total size: 24 * ( 1536 + 16 ) = 37248 bytes - */ -__attribute__( ( aligned( 32 ) ) ) -__attribute__( ( section( ".first_data" ) ) ) -uint8_t ucNetworkPackets[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS * NETWORK_BUFFER_SIZE ]; - /** TX descriptor lists */ __attribute__( ( section( ".first_data" ) ) ) COMPILER_ALIGNED( 8 ) diff --git a/source/portable/NetworkInterface/LPC18xx/NetworkInterface.c b/source/portable/NetworkInterface/LPC18xx/NetworkInterface.c index 5f4e5742b..616f0dca8 100644 --- a/source/portable/NetworkInterface/LPC18xx/NetworkInterface.c +++ b/source/portable/NetworkInterface/LPC18xx/NetworkInterface.c @@ -328,24 +328,6 @@ BaseType_t xNetworkInterfaceInitialise( void ) } /*-----------------------------------------------------------*/ -#define niBUFFER_1_PACKET_SIZE 1536 - -static __attribute__( ( section( "._ramAHB32" ) ) ) uint8_t ucNetworkPackets[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS * niBUFFER_1_PACKET_SIZE ] __attribute__( ( aligned( 32 ) ) ); - -void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ) -{ - uint8_t * ucRAMBuffer = ucNetworkPackets; - uint32_t ul; - - for( ul = 0; ul < ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS; ul++ ) - { - pxNetworkBuffers[ ul ].pucEthernetBuffer = ucRAMBuffer + ipBUFFER_PADDING; - *( ( unsigned * ) ucRAMBuffer ) = ( unsigned ) ( &( pxNetworkBuffers[ ul ] ) ); - ucRAMBuffer += niBUFFER_1_PACKET_SIZE; - } -} -/*-----------------------------------------------------------*/ - configPLACE_IN_SECTION_RAM static void vClearTXBuffers() { diff --git a/source/portable/NetworkInterface/LPC54018/NetworkInterface.c b/source/portable/NetworkInterface/LPC54018/NetworkInterface.c index d6a822fb0..9b1819ea2 100644 --- a/source/portable/NetworkInterface/LPC54018/NetworkInterface.c +++ b/source/portable/NetworkInterface/LPC54018/NetworkInterface.c @@ -116,6 +116,14 @@ uint32_t rxbuffer[ ENET_RXBD_NUM ]; TaskHandle_t receiveTaskHandle; +#if ipconfigIS_ENABLED( ipconfigBUFFER_ALLOC_STATIC ) + #if ipconfigIS_ENABLED( ipconfigBUFFER_ALLOC_STATIC_CUSTOM_SIZE ) + const UBaseType_t uxBufferAllocFixedSize = ENET_RXBUFF_SIZE; + #else + #error ipconfigBUFFER_ALLOC_STATIC_CUSTOM_SIZE must be enabled for lpc54018 + #endif +#endif + void ENET_IntCallback( ENET_Type * base, enet_handle_t * handle, enet_event_t event, @@ -368,15 +376,3 @@ BaseType_t xNetworkInterfaceOutput( NetworkBufferDescriptor_t * const pxNetworkB return response; } - -/* statically allocate the buffers */ -/* allocating them as uint32_t's to force them into word alignment, a requirement of the DMA. */ -__ALIGN_BEGIN static uint32_t buffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ][ ( ipBUFFER_PADDING + ENET_RXBUFF_SIZE ) / sizeof( uint32_t ) + 1 ] __ALIGN_END; -void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ) -{ - for( int x = 0; x < ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS; x++ ) - { - pxNetworkBuffers[ x ].pucEthernetBuffer = ( uint8_t * ) &buffers[ x ][ 0 ] + ipBUFFER_PADDING; - buffers[ x ][ 0 ] = ( uint32_t ) &pxNetworkBuffers[ x ]; - } -} diff --git a/source/portable/NetworkInterface/M487/NetworkInterface.c b/source/portable/NetworkInterface/M487/NetworkInterface.c index 32b320803..3915ddcfe 100644 --- a/source/portable/NetworkInterface/M487/NetworkInterface.c +++ b/source/portable/NetworkInterface/M487/NetworkInterface.c @@ -72,17 +72,6 @@ static TimerHandle_t xPhyHandlerTask = NULL; static void prvEMACHandlerTask( void * pvParameters ); static void prvPhyTmrCallback( TimerHandle_t xTimer ); -/* The size of each buffer when BufferAllocation_1 is used: - * https://freertos.org/Documentation/03-Libraries/02-FreeRTOS-plus/02-FreeRTOS-plus-TCP/05-Buffer-management */ - -#define niBUFFER_1_PACKET_SIZE 1536 -#ifdef __ICCARM__ - #pragma data_alignment=4 - static uint8_t ucNetworkPackets[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS * niBUFFER_1_PACKET_SIZE ] -#else - static uint8_t ucNetworkPackets[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS * niBUFFER_1_PACKET_SIZE ] __attribute__( ( aligned( 4 ) ) ); -#endif - BaseType_t xNetworkInterfaceInitialise( void ) { uint8_t hwaddr[ 6 ]; @@ -179,21 +168,6 @@ BaseType_t xNetworkInterfaceOutput( NetworkBufferDescriptor_t * const pxDescript return pdTRUE; } - -void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ) -{ - uint8_t * ucRAMBuffer = ucNetworkPackets; - uint32_t ul; - - for( ul = 0; ul < ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS; ul++ ) - { - pxNetworkBuffers[ ul ].pucEthernetBuffer = ucRAMBuffer + ipBUFFER_PADDING; - *( ( unsigned * ) ucRAMBuffer ) = ( unsigned ) ( &( pxNetworkBuffers[ ul ] ) ); - ucRAMBuffer += niBUFFER_1_PACKET_SIZE; - } -} - - BaseType_t xGetPhyLinkStatus( void ) { BaseType_t xReturn; diff --git a/source/portable/NetworkInterface/MPS2_AN385/NetworkInterface.c b/source/portable/NetworkInterface/MPS2_AN385/NetworkInterface.c index 1c55f82db..b01989bc3 100644 --- a/source/portable/NetworkInterface/MPS2_AN385/NetworkInterface.c +++ b/source/portable/NetworkInterface/MPS2_AN385/NetworkInterface.c @@ -368,19 +368,6 @@ static BaseType_t xMPS2_NetworkInterfaceOutput( NetworkInterface_t * pxInterface } /*-----------------------------------------------------------*/ -void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ) -{ - /* FIX ME if you want to use BufferAllocation_1.c, which uses statically - * allocated network buffers. */ - - /* Hard force an assert as this driver cannot be used with BufferAllocation_1.c - * without implementing this function. */ - configASSERT( xRxTaskHandle == ( TaskHandle_t ) 1 ); - ( void ) pxNetworkBuffers; -} -/*-----------------------------------------------------------*/ - - static BaseType_t xMPS2_GetPhyLinkStatus( NetworkInterface_t * pxInterface ) { const struct smsc9220_eth_dev_t * dev = &SMSC9220_ETH_DEV; diff --git a/source/portable/NetworkInterface/MPS3_AN552/NetworkInterface.c b/source/portable/NetworkInterface/MPS3_AN552/NetworkInterface.c index ac68594ac..8bc8d7214 100644 --- a/source/portable/NetworkInterface/MPS3_AN552/NetworkInterface.c +++ b/source/portable/NetworkInterface/MPS3_AN552/NetworkInterface.c @@ -485,19 +485,6 @@ static BaseType_t xLAN91C111_NetworkInterfaceOutput( NetworkInterface_t * pxInte } /*-----------------------------------------------------------*/ -void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ) -{ - /* FIX ME if you want to use BufferAllocation_1.c, which uses statically - * allocated network buffers. */ - - /* Hard force an assert as this driver cannot be used with BufferAllocation_1.c - * without implementing this function. */ - configASSERT( 0 ); - ( void ) pxNetworkBuffers; -} -/*-----------------------------------------------------------*/ - - static BaseType_t xLAN91C111_GetPhyLinkStatus( NetworkInterface_t * pxInterface ) { ( void ) pxInterface; diff --git a/source/portable/NetworkInterface/RX/NetworkInterface.c b/source/portable/NetworkInterface/RX/NetworkInterface.c index 516da7b45..3e6d7e976 100644 --- a/source/portable/NetworkInterface/RX/NetworkInterface.c +++ b/source/portable/NetworkInterface/RX/NetworkInterface.c @@ -86,6 +86,14 @@ static eMAC_INIT_STATUS_TYPE xMacInitStatus = eMACInit; /* Pointer to the interface object of this NIC */ static NetworkInterface_t * pxMyInterface = NULL; +#if ipconfigIS_ENABLED( ipconfigBUFFER_ALLOC_STATIC ) + #if ipconfigIS_ENABLED( ipconfigBUFFER_ALLOC_STATIC_CUSTOM_SIZE ) + const UBaseType_t uxBufferAllocFixedSize = ETHER_CFG_BUFSIZE; + #else + #error ipconfigBUFFER_ALLOC_STATIC_CUSTOM_SIZE must be enabled for RX + #endif +#endif + static int16_t SendData( uint8_t * pucBuffer, size_t length ); static int InitializeNetwork( void ); @@ -414,37 +422,6 @@ static void prvEMACDeferredInterruptHandlerTask( void * pvParameters ) } } /* End of function prvEMACDeferredInterruptHandlerTask() */ - -/*********************************************************************************************************************** - * Function Name: vNetworkInterfaceAllocateRAMToBuffers () - * Description : . - * Arguments : pxNetworkBuffers - * Return Value : none - **********************************************************************************************************************/ - -void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ) -{ - uint32_t ul; - uint8_t * buffer_address; - portPOINTER_SIZE_TYPE uxStartAddress; - - static uint8_t ETH_BUFFERS[ ( ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS * ETHER_CFG_BUFSIZE ) + portBYTE_ALIGNMENT ]; - - /* Align the buffer start address to portBYTE_ALIGNMENT bytes */ - uxStartAddress = ( portPOINTER_SIZE_TYPE ) & ETH_BUFFERS[ 0 ]; - uxStartAddress += portBYTE_ALIGNMENT; - uxStartAddress &= ~( ( portPOINTER_SIZE_TYPE ) portBYTE_ALIGNMENT_MASK ); - - buffer_address = ( uint8_t * ) uxStartAddress; - - for( ul = 0; ul < ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS; ul++ ) - { - pxNetworkBuffers[ ul ].pucEthernetBuffer = buffer_address + ipBUFFER_PADDING; - *( ( unsigned * ) buffer_address ) = ( unsigned ) ( &( pxNetworkBuffers[ ul ] ) ); - buffer_address += ETHER_CFG_BUFSIZE; - } -} /* End of function vNetworkInterfaceAllocateRAMToBuffers() */ - /*********************************************************************************************************************** * Function Name: prvLinkStatusChange () * Description : Function will be called when the Link Status of the phy has changed ( see ether_callback.c ) diff --git a/source/portable/NetworkInterface/STM32/Legacy/STM32Fxx/NetworkInterface.c b/source/portable/NetworkInterface/STM32/Legacy/STM32Fxx/NetworkInterface.c index 2e06048bd..630ac04e2 100644 --- a/source/portable/NetworkInterface/STM32/Legacy/STM32Fxx/NetworkInterface.c +++ b/source/portable/NetworkInterface/STM32/Legacy/STM32Fxx/NetworkInterface.c @@ -171,6 +171,14 @@ typedef enum static eMAC_INIT_STATUS_TYPE xMacInitStatus = eMACInit; +#if ipconfigIS_ENABLED( ipconfigBUFFER_ALLOC_STATIC ) + #if ipconfigIS_ENABLED( ipconfigBUFFER_ALLOC_STATIC_CUSTOM_SIZE ) + const UBaseType_t uxBufferAllocFixedSize = ETH_MAX_PACKET_SIZE; + #else + #error ipconfigBUFFER_ALLOC_STATIC_CUSTOM_SIZE must be enabled for STM32Fxx + #endif +#endif + /*-----------------------------------------------------------*/ /* @@ -1375,28 +1383,6 @@ static BaseType_t xSTM32F_GetPhyLinkStatus( NetworkInterface_t * pxInterface ) } /*-----------------------------------------------------------*/ -/* Uncomment this in case BufferAllocation_1.c is used. */ - -void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ) -{ - static - #if defined( STM32F7xx ) - __attribute__( ( section( ".first_data" ) ) ) - #endif - uint8_t ucNetworkPackets[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS * ETH_MAX_PACKET_SIZE ] __attribute__( ( aligned( 32 ) ) ); - uint8_t * ucRAMBuffer = ucNetworkPackets; - uint32_t ul; - - for( ul = 0; ul < ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS; ul++ ) - { - pxNetworkBuffers[ ul ].pucEthernetBuffer = ucRAMBuffer + ipBUFFER_PADDING; - *( ( unsigned * ) ucRAMBuffer ) = ( unsigned ) ( &( pxNetworkBuffers[ ul ] ) ); - ucRAMBuffer += ETH_MAX_PACKET_SIZE; - } -} - -/*-----------------------------------------------------------*/ - NetworkInterface_t * pxSTM32Fxx_FillInterfaceDescriptor( BaseType_t xEMACIndex, NetworkInterface_t * pxInterface ) { diff --git a/source/portable/NetworkInterface/STM32/Legacy/STM32Fxx/readme.md b/source/portable/NetworkInterface/STM32/Legacy/STM32Fxx/readme.md index c419195de..d26d9695b 100644 --- a/source/portable/NetworkInterface/STM32/Legacy/STM32Fxx/readme.md +++ b/source/portable/NetworkInterface/STM32/Legacy/STM32Fxx/readme.md @@ -108,7 +108,7 @@ Without memory caching, let the size be at least a multiple of 8 ( for DMA ), an STM32F7xx only: NetworkInterface.c will place the 2 DMA tables in a special section called 'first_data'. -In case 'BufferAllocation_1.c' is used, the network packets will also be declared in this section 'first_data'. +In case static buffer allocation is used, the network packets will also be declared in this section 'first_data'. As long as the part has no caching, this section can be placed anywhere in RAM. On an STM32F7 with an L1 data cache, it shall be placed in the first 64KB of RAM, which is always uncached. The linker script must be changed for this, for instance as follows: diff --git a/source/portable/NetworkInterface/STM32/Legacy/STM32Hxx/NetworkInterface.c b/source/portable/NetworkInterface/STM32/Legacy/STM32Hxx/NetworkInterface.c index 6536b3085..134c4d66e 100644 --- a/source/portable/NetworkInterface/STM32/Legacy/STM32Hxx/NetworkInterface.c +++ b/source/portable/NetworkInterface/STM32/Legacy/STM32Hxx/NetworkInterface.c @@ -147,6 +147,14 @@ ETH_DMADescTypeDef DMATxDscrTab[ ETH_TX_DESC_CNT ] __attribute__( ( section( uint8_t Tx_Buff[ ETH_TX_DESC_CNT ][ ETH_TX_BUF_SIZE ] __attribute__( ( section( ".ethernet_data" ), aligned( 32 ) ) ); #endif +#if ipconfigIS_ENABLED( ipconfigBUFFER_ALLOC_STATIC ) + #if ipconfigIS_ENABLED( ipconfigBUFFER_ALLOC_STATIC_CUSTOM_SIZE ) + const UBaseType_t uxBufferAllocFixedSize = ETH_RX_BUF_SIZE; + #else + #error ipconfigBUFFER_ALLOC_STATIC_CUSTOM_SIZE must be enabled for STM32Hxx + #endif +#endif + /* This function binds PHY IO functions, then inits and configures */ static void prvMACBProbePhy( void ); @@ -785,11 +793,6 @@ static BaseType_t prvNetworkInterfaceInput( void ) if( data_buffer.buffer != NULL ) { pxReceivedBuffer = pxPacketBuffer_to_NetworkBuffer( data_buffer.buffer ); - #if ( ipconfigTCP_IP_SANITY != 0 ) - { - configASSERT( bIsValidNetworkDescriptor( pxReceivedBuffer ) != 0 ); - } - #endif } if( pxReceivedBuffer == NULL ) @@ -1028,26 +1031,6 @@ void HAL_ETH_DMAErrorCallback( ETH_HandleTypeDef * heth ) * END Ethernet Handling Functions *******************************************************************************/ -uint8_t ucNetworkPackets[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS * ETH_RX_BUF_SIZE ] -#if ( ipconfigZERO_COPY_RX_DRIVER != 0 || ipconfigZERO_COPY_TX_DRIVER != 0 ) - __attribute__( ( section( ".ethernet_data" ) ) ) -#endif /* ( ipconfigZERO_COPY_RX_DRIVER != 0 || ipconfigZERO_COPY_TX_DRIVER != 0 ) */ -__attribute__( ( aligned( 32 ) ) ); - -void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ) -{ - uint8_t * ucRAMBuffer = ucNetworkPackets; - uint32_t ul; - - for( ul = 0; ul < ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS; ul++ ) - { - pxNetworkBuffers[ ul ].pucEthernetBuffer = ucRAMBuffer + ipBUFFER_PADDING; - *( ( unsigned * ) ucRAMBuffer ) = ( unsigned ) ( &( pxNetworkBuffers[ ul ] ) ); - ucRAMBuffer += ETH_RX_BUF_SIZE; - } -} -/*-----------------------------------------------------------*/ - static void vClearOptionBit( volatile uint32_t * pulValue, uint32_t ulValue ) { diff --git a/source/portable/NetworkInterface/TM4C/NetworkInterface.c b/source/portable/NetworkInterface/TM4C/NetworkInterface.c index 5a5a4f1cd..2a3c8135b 100644 --- a/source/portable/NetworkInterface/TM4C/NetworkInterface.c +++ b/source/portable/NetworkInterface/TM4C/NetworkInterface.c @@ -133,8 +133,6 @@ static tEMACDMADescriptor _rx_descriptors[ niEMAC_RX_DMA_DESC_COUNT ]; static tDescriptorList _tx_descriptor_list = { .number_descriptors = niEMAC_TX_DMA_DESC_COUNT, 0 }; static tDescriptorList _rx_descriptor_list = { .number_descriptors = niEMAC_RX_DMA_DESC_COUNT, 0 }; -static uint8_t _network_buffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ][ BUFFER_SIZE_ROUNDED_UP ] __attribute__( ( aligned( 4 ) ) ); - static EthernetPhy_t xPhyObject; static TaskHandle_t _deferred_task_handle = NULL; @@ -403,20 +401,6 @@ BaseType_t xNetworkInterfaceOutput( NetworkBufferDescriptor_t * const pxNetworkB return success; } -void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ) -{ - BaseType_t i; - - for( i = 0; i < ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS; i++ ) - { - /* Assign buffers to each descriptor */ - pxNetworkBuffers[ i ].pucEthernetBuffer = &_network_buffers[ i ][ ipBUFFER_PADDING ]; - - /* Set the 'hidden' reference to the descriptor for use in DMA interrupts */ - *( ( uint32_t * ) &_network_buffers[ i ][ 0 ] ) = ( uint32_t ) &( ( pxNetworkBuffers[ i ] ) ); - } -} - static BaseType_t _ethernet_mac_get( uint8_t * mac_address_bytes ) { BaseType_t success = pdPASS; diff --git a/source/portable/NetworkInterface/ThirdParty/MSP432/NetworkInterface.c b/source/portable/NetworkInterface/ThirdParty/MSP432/NetworkInterface.c index bac7e4587..36c9306af 100644 --- a/source/portable/NetworkInterface/ThirdParty/MSP432/NetworkInterface.c +++ b/source/portable/NetworkInterface/ThirdParty/MSP432/NetworkInterface.c @@ -977,7 +977,6 @@ static void prvCheckLinkUpOrDownNetStateTask( void * pvParameters ) } - /* Call this function to obtain the MAC address used by the driver */ void vPublicGetMACAddr( uint8_t uc8MACAddrGet[ ipMAC_ADDRESS_LENGTH_BYTES ] ) { @@ -989,26 +988,3 @@ BaseType_t xGetPhyLinkStatus( void ) { return networkUP; } - - -/*----------------------------------------------------------------------------------------------------- - * For BufferAllocation_1.c (see the FreeRTOS documentation for further details and examples) - * ----------------------------------------------------------------------------------------------------- */ -#define BUFFER_SIZE_ALLOC1 ( ipTOTAL_ETHERNET_FRAME_SIZE + ipBUFFER_PADDING ) -#define BUFFER_SIZE_ALLOC1_ROUNDED_UP ( ( BUFFER_SIZE_ALLOC1 + 7 ) & ~0x07UL ) -static uint8_t ucBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ][ BUFFER_SIZE_ALLOC1_ROUNDED_UP ]; -void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ) -{ - BaseType_t x; - - for( x = 0; x < ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS; x++ ) - { - /* pucEthernetBuffer is set to point ipBUFFER_PADDING bytes in from the - * beginning of the allocated buffer. */ - pxNetworkBuffers[ x ].pucEthernetBuffer = &( ucBuffers[ x ][ ipBUFFER_PADDING ] ); - - /* The following line is also required, but will not be required in - * future versions. */ - *( ( uint32_t * ) &ucBuffers[ x ][ 0 ] ) = ( uint32_t ) &( pxNetworkBuffers[ x ] ); - } -} diff --git a/source/portable/NetworkInterface/WinPCap/NetworkInterface.c b/source/portable/NetworkInterface/WinPCap/NetworkInterface.c index e7f8975a8..1822ff8c4 100644 --- a/source/portable/NetworkInterface/WinPCap/NetworkInterface.c +++ b/source/portable/NetworkInterface/WinPCap/NetworkInterface.c @@ -864,7 +864,7 @@ static void prvInterruptSimulatorTask( void * pvParameters ) if( pxNetworkBuffer->pxEndPoint == NULL ) { FreeRTOS_printf( ( "Network interface: dropped packet\n" ) ); - vReleaseNetworkBufferAndDescriptor( BUFFER_FROM_WHERE_CALL( 153 ) pxNetworkBuffer ); + vReleaseNetworkBufferAndDescriptor( pxNetworkBuffer ); } else { @@ -942,41 +942,3 @@ static const char * prvRemoveSpaces( char * pcBuffer, return pcBuffer; } /*-----------------------------------------------------------*/ - -#define BUFFER_SIZE ( ipTOTAL_ETHERNET_FRAME_SIZE + ipBUFFER_PADDING ) -#define BUFFER_SIZE_ROUNDED_UP ( ( BUFFER_SIZE + 7 ) & ~0x07UL ) - -void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ) -{ - static uint8_t * pucNetworkPacketBuffers = NULL; - size_t uxIndex; - - if( pucNetworkPacketBuffers == NULL ) - { - pucNetworkPacketBuffers = ( uint8_t * ) malloc( ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS * BUFFER_SIZE_ROUNDED_UP ); - } - - if( pucNetworkPacketBuffers == NULL ) - { - FreeRTOS_printf( ( "Failed to allocate memory for pxNetworkBuffers" ) ); - configASSERT( 0 ); - } - else - { - for( uxIndex = 0; uxIndex < ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS; uxIndex++ ) - { - size_t uxOffset = uxIndex * BUFFER_SIZE_ROUNDED_UP; - NetworkBufferDescriptor_t ** ppDescriptor; - - /* At the beginning of each pbuff is a pointer to the relevant descriptor */ - ppDescriptor = ( NetworkBufferDescriptor_t ** ) &( pucNetworkPacketBuffers[ uxOffset ] ); - - /* Set this pointer to the address of the correct descriptor */ - *ppDescriptor = &( pxNetworkBuffers[ uxIndex ] ); - - /* pucEthernetBuffer is set to point ipBUFFER_PADDING bytes in from the - * beginning of the allocated buffer. */ - pxNetworkBuffers[ uxIndex ].pucEthernetBuffer = &( pucNetworkPacketBuffers[ uxOffset + ipBUFFER_PADDING ] ); - } - } -} diff --git a/source/portable/NetworkInterface/Zynq/NetworkInterface.c b/source/portable/NetworkInterface/Zynq/NetworkInterface.c index 8b5913bf1..2b9c77ffa 100644 --- a/source/portable/NetworkInterface/Zynq/NetworkInterface.c +++ b/source/portable/NetworkInterface/Zynq/NetworkInterface.c @@ -63,10 +63,6 @@ #define niBMSR_LINK_STATUS 0x0004uL -/* The size of each buffer when BufferAllocation_1 is used: - * https://freertos.org/Documentation/03-Libraries/02-FreeRTOS-plus/02-FreeRTOS-plus-TCP/05-Buffer-management */ -#define niBUFFER_1_PACKET_SIZE 1536 - /* Naming and numbering of PHY registers. */ #define PHY_REG_01_BMSR 0x01 /* Basic mode status register */ @@ -485,28 +481,15 @@ static BaseType_t prvGMACWaitLS( BaseType_t xEMACIndex, } /*-----------------------------------------------------------*/ -#if ( nicUSE_UNCACHED_MEMORY == 0 ) - void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ) - { - static uint8_t ucNetworkPackets[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS * niBUFFER_1_PACKET_SIZE ] __attribute__( ( aligned( 32 ) ) ); - uint8_t * ucRAMBuffer = ucNetworkPackets; - uint32_t ul; +#if ipconfigIS_ENABLED( ipconfigBUFFER_ALLOC_STATIC ) && ( nicUSE_UNCACHED_MEMORY != 0 ) - for( ul = 0; ul < ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS; ul++ ) - { - pxNetworkBuffers[ ul ].pucEthernetBuffer = ucRAMBuffer + ipBUFFER_PADDING; - *( ( unsigned * ) ucRAMBuffer ) = ( unsigned ) ( &( pxNetworkBuffers[ ul ] ) ); - ucRAMBuffer += niBUFFER_1_PACKET_SIZE; - } - } -#else /* if ( nicUSE_UNCACHED_MEMORY == 0 ) */ void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ) { static uint8_t * pucNetworkPackets = NULL; if( pucNetworkPackets == NULL ) { - pucNetworkPackets = pucGetUncachedMemory( ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS * niBUFFER_1_PACKET_SIZE ); + pucNetworkPackets = pucGetUncachedMemory( ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS * ipTOTAL_ETHERNET_FRAME_SIZE ); if( pucNetworkPackets != NULL ) { @@ -517,12 +500,13 @@ static BaseType_t prvGMACWaitLS( BaseType_t xEMACIndex, { pxNetworkBuffers[ ul ].pucEthernetBuffer = ucRAMBuffer + ipBUFFER_PADDING; *( ( unsigned * ) ucRAMBuffer ) = ( unsigned ) ( &( pxNetworkBuffers[ ul ] ) ); - ucRAMBuffer += niBUFFER_1_PACKET_SIZE; + ucRAMBuffer += ipTOTAL_ETHERNET_FRAME_SIZE; } } } } -#endif /* ( nicUSE_UNCACHED_MEMORY == 0 ) */ + +#endif /* if ipconfigIS_ENABLED( ipconfigBUFFER_ALLOC_STATIC ) && ( nicUSE_UNCACHED_MEMORY != 0 ) */ /*-----------------------------------------------------------*/ static BaseType_t xZynqGetPhyLinkStatus( NetworkInterface_t * pxInterface ) diff --git a/source/portable/NetworkInterface/board_family/NetworkInterface.c b/source/portable/NetworkInterface/board_family/NetworkInterface.c index dfb1979c6..96a2c2f2a 100644 --- a/source/portable/NetworkInterface/board_family/NetworkInterface.c +++ b/source/portable/NetworkInterface/board_family/NetworkInterface.c @@ -64,10 +64,14 @@ BaseType_t xNetworkInterfaceOutput( NetworkBufferDescriptor_t * const pxNetworkB return pdFALSE; } -void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ) -{ - /* FIX ME. */ -} +#if ipconfigIS_ENABLED( ipconfigBUFFER_ALLOC_STATIC ) + + void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ) + { + /* FIX ME. */ + } + +#endif BaseType_t xGetPhyLinkStatus( void ) { diff --git a/source/portable/NetworkInterface/libslirp/MBuffNetworkInterface.c b/source/portable/NetworkInterface/libslirp/MBuffNetworkInterface.c index 3c2699acd..936907ae4 100644 --- a/source/portable/NetworkInterface/libslirp/MBuffNetworkInterface.c +++ b/source/portable/NetworkInterface/libslirp/MBuffNetworkInterface.c @@ -324,49 +324,6 @@ static BaseType_t xNetworkInterfaceOutput( NetworkInterface_t * pxNetif, return xResult; } -#define BUFFER_SIZE ( ipTOTAL_ETHERNET_FRAME_SIZE + ipBUFFER_PADDING ) -#define BUFFER_SIZE_ROUNDED_UP ( ( BUFFER_SIZE + 7 ) & ~0x07UL ) - -/*! - * @brief Allocate RAM for packet buffers and set the pucEthernetBuffer field for each descriptor. - * Called when the BufferAllocation1 scheme is used. - * @param [in,out] pxNetworkBuffers Pointer to an array of NetworkBufferDescriptor_t to populate. - */ -void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ) -{ - static uint8_t * pucNetworkPacketBuffers = NULL; - size_t uxIndex; - - if( pucNetworkPacketBuffers == NULL ) - { - pucNetworkPacketBuffers = ( uint8_t * ) malloc( ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS * BUFFER_SIZE_ROUNDED_UP ); - } - - if( pucNetworkPacketBuffers == NULL ) - { - FreeRTOS_printf( ( "Failed to allocate memory for pxNetworkBuffers" ) ); - configASSERT( 0 ); - } - else - { - for( uxIndex = 0; uxIndex < ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS; uxIndex++ ) - { - size_t uxOffset = uxIndex * BUFFER_SIZE_ROUNDED_UP; - NetworkBufferDescriptor_t ** ppDescriptor; - - /* At the beginning of each pbuff is a pointer to the relevant descriptor */ - ppDescriptor = ( NetworkBufferDescriptor_t ** ) &( pucNetworkPacketBuffers[ uxOffset ] ); - - /* Set this pointer to the address of the correct descriptor */ - *ppDescriptor = &( pxNetworkBuffers[ uxIndex ] ); - - /* pucEthernetBuffer is set to point ipBUFFER_PADDING bytes in from the - * beginning of the allocated buffer. */ - pxNetworkBuffers[ uxIndex ].pucEthernetBuffer = &( pucNetworkPacketBuffers[ uxOffset + ipBUFFER_PADDING ] ); - } - } -} - BaseType_t xGetPhyLinkStatus( NetworkInterface_t * pxNetif ) { BaseType_t xResult = pdFALSE; diff --git a/source/portable/NetworkInterface/linux/NetworkInterface.c b/source/portable/NetworkInterface/linux/NetworkInterface.c index a198be31c..d8236a15b 100644 --- a/source/portable/NetworkInterface/linux/NetworkInterface.c +++ b/source/portable/NetworkInterface/linux/NetworkInterface.c @@ -1088,47 +1088,3 @@ static void print_hex( unsigned const char * const bin_data, FreeRTOS_debug_printf( ( "\n" ) ); } - - -#define BUFFER_SIZE ( ipTOTAL_ETHERNET_FRAME_SIZE + ipBUFFER_PADDING ) -#define BUFFER_SIZE_ROUNDED_UP ( ( BUFFER_SIZE + 7 ) & ~0x07UL ) - -/*! - * @brief Allocate RAM for packet buffers and set the pucEthernetBuffer field for each descriptor. - * Called when the BufferAllocation1 scheme is used. - * @param [in,out] pxNetworkBuffers Pointer to an array of NetworkBufferDescriptor_t to populate. - */ -void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ) -{ - static uint8_t * pucNetworkPacketBuffers = NULL; - size_t uxIndex; - - if( pucNetworkPacketBuffers == NULL ) - { - pucNetworkPacketBuffers = ( uint8_t * ) malloc( ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS * BUFFER_SIZE_ROUNDED_UP ); - } - - if( pucNetworkPacketBuffers == NULL ) - { - FreeRTOS_printf( ( "Failed to allocate memory for pxNetworkBuffers" ) ); - configASSERT( 0 ); - } - else - { - for( uxIndex = 0; uxIndex < ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS; uxIndex++ ) - { - size_t uxOffset = uxIndex * BUFFER_SIZE_ROUNDED_UP; - NetworkBufferDescriptor_t ** ppDescriptor; - - /* At the beginning of each pbuff is a pointer to the relevant descriptor */ - ppDescriptor = ( NetworkBufferDescriptor_t ** ) &( pucNetworkPacketBuffers[ uxOffset ] ); - - /* Set this pointer to the address of the correct descriptor */ - *ppDescriptor = &( pxNetworkBuffers[ uxIndex ] ); - - /* pucEthernetBuffer is set to point ipBUFFER_PADDING bytes in from the - * beginning of the allocated buffer. */ - pxNetworkBuffers[ uxIndex ].pucEthernetBuffer = &( pucNetworkPacketBuffers[ uxOffset + ipBUFFER_PADDING ] ); - } - } -} diff --git a/source/portable/NetworkInterface/mw300_rd/NetworkInterface.c b/source/portable/NetworkInterface/mw300_rd/NetworkInterface.c index 26baf2ddc..a01101998 100644 --- a/source/portable/NetworkInterface/mw300_rd/NetworkInterface.c +++ b/source/portable/NetworkInterface/mw300_rd/NetworkInterface.c @@ -181,11 +181,6 @@ BaseType_t xNetworkInterfaceInitialise( void ) return ( xInterfaceState == INTERFACE_UP && ret == WM_SUCCESS ) ? pdTRUE : pdFALSE; } -void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ) -{ - /* FIX ME. */ -} - BaseType_t xGetPhyLinkStatus( void ) { /* FIX ME. */ diff --git a/source/portable/NetworkInterface/pic32mzef/BufferAllocation_2.c b/source/portable/NetworkInterface/pic32mzef/BufferAllocation.c similarity index 99% rename from source/portable/NetworkInterface/pic32mzef/BufferAllocation_2.c rename to source/portable/NetworkInterface/pic32mzef/BufferAllocation.c index 622a9b84f..5b159f7a0 100644 --- a/source/portable/NetworkInterface/pic32mzef/BufferAllocation_2.c +++ b/source/portable/NetworkInterface/pic32mzef/BufferAllocation.c @@ -84,10 +84,6 @@ static size_t uxMinimumFreeNetworkBuffers; * is booted). */ static NetworkBufferDescriptor_t xNetworkBufferDescriptors[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ]; -/* This constant is defined as false to let FreeRTOS_TCP_IP.c know that the - * network buffers have a variable size: resizing may be necessary */ -const BaseType_t xBufferAllocFixedSize = pdFALSE; - /* The semaphore used to obtain network buffers. */ static SemaphoreHandle_t xNetworkBufferSemaphore = NULL; diff --git a/source/portable/NetworkInterface/pic32mzef/CMakeLists.txt b/source/portable/NetworkInterface/pic32mzef/CMakeLists.txt index 5e295e757..48bc28df8 100644 --- a/source/portable/NetworkInterface/pic32mzef/CMakeLists.txt +++ b/source/portable/NetworkInterface/pic32mzef/CMakeLists.txt @@ -6,9 +6,9 @@ endif() #------------------------------------------------------------------------------ add_library( freertos_plus_tcp_network_if STATIC ) -# What about BufferAllocation_2.c here? target_sources( freertos_plus_tcp_network_if PRIVATE + BufferAllocation.c $<$:NetworkInterface_eth.c> $<$:NetworkInterface_wifi.c> ) diff --git a/source/portable/NetworkInterface/pic32mzef/NetworkInterface_eth.c b/source/portable/NetworkInterface/pic32mzef/NetworkInterface_eth.c index df35ed880..9ab7f4a67 100644 --- a/source/portable/NetworkInterface/pic32mzef/NetworkInterface_eth.c +++ b/source/portable/NetworkInterface/pic32mzef/NetworkInterface_eth.c @@ -172,7 +172,7 @@ /* use the configuration data from the system_init.c */ extern const TCPIP_NETWORK_CONFIG TCPIP_HOSTS_CONFIGURATION[]; -/* BufferAllocation_2.c:: packet allocation function */ +/* dynamic buffer allocation packet allocation function */ extern TCPIP_MAC_PACKET * PIC32_MacPacketAllocate( uint16_t pktLen, uint16_t segLoadLen, TCPIP_MAC_PACKET_FLAGS flags ); diff --git a/source/portable/NetworkInterface/xilinx_ultrascale/NetworkInterface.c b/source/portable/NetworkInterface/xilinx_ultrascale/NetworkInterface.c index bf97e3e27..9a3a2cd2d 100644 --- a/source/portable/NetworkInterface/xilinx_ultrascale/NetworkInterface.c +++ b/source/portable/NetworkInterface/xilinx_ultrascale/NetworkInterface.c @@ -62,20 +62,18 @@ #define niBMSR_LINK_STATUS 0x0004uL -#if ( ipconfigNETWORK_MTU > 1526 ) - #if ( ipconfigPORT_SUPPRESS_WARNING == 0 ) - #warning the use of Jumbo Frames has not been tested sufficiently yet. +#if 0 + #if ( ipconfigNETWORK_MTU > 1526 ) + #if ( ipconfigPORT_SUPPRESS_WARNING == 0 ) + #warning the use of Jumbo Frames has not been tested sufficiently yet. + #endif + #define USE_JUMBO_FRAMES 1 #endif - #define USE_JUMBO_FRAMES 1 -#endif -/* The size of each buffer when BufferAllocation_1 is used: - * https://freertos.org/Documentation/03-Libraries/02-FreeRTOS-plus/02-FreeRTOS-plus-TCP/05-Buffer-management */ -#if ( USE_JUMBO_FRAMES == 1 ) - #define niBUFFER_1_PACKET_SIZE 10240 -#else - #define niBUFFER_1_PACKET_SIZE 1536 -#endif + #if ( USE_JUMBO_FRAMES == 1 ) + #define niBUFFER_1_PACKET_SIZE 10240 + #endif +#endif /* if 0 */ /* Naming and numbering of PHY registers. */ #define PHY_REG_01_BMSR 0x01 /* Basic mode status register */ @@ -598,21 +596,8 @@ static BaseType_t prvGMACWaitLS( BaseType_t xEMACIndex, } /*-----------------------------------------------------------*/ -#if ( nicUSE_UNCACHED_MEMORY == 0 ) - void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ) - { - static uint8_t ucNetworkPackets[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS * niBUFFER_1_PACKET_SIZE ] __attribute__( ( aligned( 32 ) ) ); - uint8_t * ucRAMBuffer = ucNetworkPackets; - uint32_t ul; +#if ipconfigIS_ENABLED( ipconfigBUFFER_ALLOC_STATIC ) && ( nicUSE_UNCACHED_MEMORY != 0 ) - for( ul = 0; ul < ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS; ul++ ) - { - pxNetworkBuffers[ ul ].pucEthernetBuffer = ucRAMBuffer + ipBUFFER_PADDING; - *( ( uintptr_t * ) ucRAMBuffer ) = ( uintptr_t ) &( pxNetworkBuffers[ ul ] ); - ucRAMBuffer += niBUFFER_1_PACKET_SIZE; - } - } -#else /* if ( nicUSE_UNCACHED_MEMORY == 0 ) */ void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] ) { static uint8_t * pucNetworkPackets = NULL; @@ -635,7 +620,8 @@ static BaseType_t prvGMACWaitLS( BaseType_t xEMACIndex, } } } -#endif /* ( nicUSE_UNCACHED_MEMORY == 0 ) */ + +#endif /* if ipconfigIS_ENABLED( ipconfigBUFFER_ALLOC_STATIC ) && ( nicUSE_UNCACHED_MEMORY != 0 ) */ /*-----------------------------------------------------------*/ static BaseType_t xUltrascaleGetPhyLinkStatus( NetworkInterface_t * pxInterface ) diff --git a/source/portable/NetworkInterface/xilinx_ultrascale/readme.md b/source/portable/NetworkInterface/xilinx_ultrascale/readme.md index c58d1d39d..f65060a93 100644 --- a/source/portable/NetworkInterface/xilinx_ultrascale/readme.md +++ b/source/portable/NetworkInterface/xilinx_ultrascale/readme.md @@ -38,7 +38,7 @@ It is obligatory to define these in your FreeRTOSIPConfig.h : #define ipconfigZERO_COPY_TX_DRIVER 1 -Please link you project with BufferAllocation_1.c ( not xxx_2.c ). +Please enable ipconfigBUFFER_ALLOC_STATIC. The following option causes the memory of the network packets to be allocated in normal ( cached ) memory. With this option, TCP processing seems a faster diff --git a/test/Coverity/CMakeLists.txt b/test/Coverity/CMakeLists.txt index b098e37fa..d9c0977d1 100644 --- a/test/Coverity/CMakeLists.txt +++ b/test/Coverity/CMakeLists.txt @@ -50,7 +50,7 @@ file( GLOB TCP_SOURCES add_executable( StaticAnalysis ${TCP_SOURCES} ${KERNEL_SOURCES} ${CMAKE_CURRENT_LIST_DIR}/Portable.c - ${MODULE_ROOT_DIR}/source/portable/BufferManagement/BufferAllocation_2.c ) + ${MODULE_ROOT_DIR}/source/portable/BufferManagement/BufferAllocation.c ) # Link the include directories with the target target_include_directories( StaticAnalysis diff --git a/test/cbmc/proofs/ARP/ARP_OutputARPRequest_buffer_alloc1/Configurations.json b/test/cbmc/proofs/ARP/ARP_OutputARPRequest_buffer_alloc1/Configurations.json index ff5898c18..6e5553186 100644 --- a/test/cbmc/proofs/ARP/ARP_OutputARPRequest_buffer_alloc1/Configurations.json +++ b/test/cbmc/proofs/ARP/ARP_OutputARPRequest_buffer_alloc1/Configurations.json @@ -12,7 +12,7 @@ "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP.goto", "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_ARP.goto", "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_Routing.goto", - "$(FREERTOS_PLUS_TCP)/source/portable/BufferManagement/BufferAllocation_1.goto", + "$(FREERTOS_PLUS_TCP)/source/portable/BufferManagement/BufferAllocation.goto", "$(FREERTOS_PLUS_TCP)/test/FreeRTOS-Kernel/list.goto", "$(FREERTOS_PLUS_TCP)/test/FreeRTOS-Kernel/queue.goto", "$(FREERTOS_PLUS_TCP)/test/cbmc/proofs/CBMCStubLibrary/tasksStubs.goto", diff --git a/test/cbmc/proofs/ARP/ARP_OutputARPRequest_buffer_alloc1/OutputARPRequest_harness.c b/test/cbmc/proofs/ARP/ARP_OutputARPRequest_buffer_alloc1/OutputARPRequest_harness.c index 24762ed1c..b724cb1ee 100644 --- a/test/cbmc/proofs/ARP/ARP_OutputARPRequest_buffer_alloc1/OutputARPRequest_harness.c +++ b/test/cbmc/proofs/ARP/ARP_OutputARPRequest_buffer_alloc1/OutputARPRequest_harness.c @@ -1,6 +1,4 @@ -/* This harness is linked against - * libraries/freertos_plus/standard/freertos_plus_tcp/source/portable/BufferManagement/BufferAllocation_1.goto - */ +/* This harness uses the static buffer allocation method */ #include #include @@ -43,9 +41,8 @@ void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkB * triggered when the allocation fails. Nevertheless, the code is perfectly * guarded against a failing Semaphore allocation. To make the assert pass, * it is assumed for now, that pvPortMalloc doesn't fail. Using a model allowing - * failures of the allocation might be possible - * after removing the assert in l.105 of BufferAllocation_1.c, from a memory - * safety point of view. */ + * failures of the allocation might be possible after removing the assert in + * BufferAllocation.c, from a memory safety point of view. */ void * pvPortMalloc( size_t xWantedSize ) { void * ptr = malloc( xWantedSize ); diff --git a/test/cbmc/proofs/ARP/ARP_OutputARPRequest_buffer_alloc1/README.md b/test/cbmc/proofs/ARP/ARP_OutputARPRequest_buffer_alloc1/README.md index ea5eac78d..58292656a 100644 --- a/test/cbmc/proofs/ARP/ARP_OutputARPRequest_buffer_alloc1/README.md +++ b/test/cbmc/proofs/ARP/ARP_OutputARPRequest_buffer_alloc1/README.md @@ -1,5 +1,5 @@ This is the memory safety proof for ```FreeRTOS_OutputARPRequest``` -method combined with the BufferAllocation_1.c allocation strategy. +method combined with the static BufferAllocation.c allocation strategy. This proof is a work-in-progress. Proof assumptions are described in the harness. The proof also assumes the following functions are diff --git a/test/cbmc/proofs/ARP/ARP_OutputARPRequest_buffer_alloc2/Configurations.json b/test/cbmc/proofs/ARP/ARP_OutputARPRequest_buffer_alloc2/Configurations.json index d37f17720..bc9cf7193 100644 --- a/test/cbmc/proofs/ARP/ARP_OutputARPRequest_buffer_alloc2/Configurations.json +++ b/test/cbmc/proofs/ARP/ARP_OutputARPRequest_buffer_alloc2/Configurations.json @@ -12,7 +12,7 @@ "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_ARP.goto", "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP.goto", "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_Routing.goto", - "$(FREERTOS_PLUS_TCP)/source/portable/BufferManagement/BufferAllocation_2.goto", + "$(FREERTOS_PLUS_TCP)/source/portable/BufferManagement/BufferAllocation.goto", "$(FREERTOS_PLUS_TCP)/test/FreeRTOS-Kernel/list.goto", "$(FREERTOS_PLUS_TCP)/test/FreeRTOS-Kernel/queue.goto", "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_kernel_api.goto", diff --git a/test/cbmc/proofs/ARP/ARP_OutputARPRequest_buffer_alloc2/OutputARPRequest_harness.c b/test/cbmc/proofs/ARP/ARP_OutputARPRequest_buffer_alloc2/OutputARPRequest_harness.c index af3abf26e..b6254bd66 100644 --- a/test/cbmc/proofs/ARP/ARP_OutputARPRequest_buffer_alloc2/OutputARPRequest_harness.c +++ b/test/cbmc/proofs/ARP/ARP_OutputARPRequest_buffer_alloc2/OutputARPRequest_harness.c @@ -1,6 +1,4 @@ -/* This harness is linked against - * libraries/freertos_plus/standard/freertos_plus_tcp/source/portable/BufferManagement/BufferAllocation_2.goto - */ +/* This harness uses the dynamic buffer allocation method */ #include #include diff --git a/test/cbmc/proofs/ARP/ARP_OutputARPRequest_buffer_alloc2/README.md b/test/cbmc/proofs/ARP/ARP_OutputARPRequest_buffer_alloc2/README.md index 5d509a7e8..f50b3e69f 100644 --- a/test/cbmc/proofs/ARP/ARP_OutputARPRequest_buffer_alloc2/README.md +++ b/test/cbmc/proofs/ARP/ARP_OutputARPRequest_buffer_alloc2/README.md @@ -1,5 +1,5 @@ This is the memory safety proof for FreeRTOS_OutputARPRequest -method combined with the BufferAllocation_2.c allocation strategy. +method combined with the dynamic BufferAllocation.c allocation strategy. This proof is a work-in-progress. Proof assumptions are described in the harness. The proof also assumes the following functions are @@ -27,19 +27,19 @@ This proof checks FreeRTOS_OutputARPRequest in multiple configuration: * The proof in the directory config_minimal_configuration guarantees that the implementation and interaction between FreeRTOS_OutputARPRequest and - FreeRTOS-Plus-TCP/source/portable/BufferManagement/BufferAllocation_2.c + FreeRTOS-Plus-TCP/source/portable/BufferManagement/BufferAllocation.c are memory save. This proof depends entirely of the implementation correctness of vNetworkInterfaceAllocateRAMToBuffers. * The proof in directory minimal_configuration_minimal_packet_size guarantees that using - FreeRTOS-Plus-TCP/source/portable/BufferManagement/BufferAllocation_2.c + FreeRTOS-Plus-TCP/source/portable/BufferManagement/BufferAllocation.c along with the ipconfigETHERNET_MINIMUM_PACKET_BYTES is memory save as long as TCP is enabled ( ipconfigUSE_TCP 1 ) and ipconfigETHERNET_MINIMUM_PACKET_BYTES < sizeof( TCPPacket_t ). * The directory minimal_configuration_minimal_packet_size_no_tcp reminds that ipconfigETHERNET_MINIMUM_PACKET_BYTES must not be used if TCP is disabled ( ipconfigUSE_TCP 1 ) along with the - FreeRTOS-Plus-TCP/source/portable/BufferManagement/BufferAllocation_2.c + FreeRTOS-Plus-TCP/source/portable/BufferManagement/BufferAllocation.c allocator. * The proof in directory config_minimal_configuration_linked_rx_messages guarantees that the diff --git a/test/cbmc/proofs/DNS/prepareReplyDNSMessage/prepareReplyDNSMessage_harness.c b/test/cbmc/proofs/DNS/prepareReplyDNSMessage/prepareReplyDNSMessage_harness.c index d75332945..4ecf27fd4 100644 --- a/test/cbmc/proofs/DNS/prepareReplyDNSMessage/prepareReplyDNSMessage_harness.c +++ b/test/cbmc/proofs/DNS/prepareReplyDNSMessage/prepareReplyDNSMessage_harness.c @@ -99,9 +99,9 @@ void harness() BaseType_t xDataSize; /* The pucEthernetBuffer is re adjusted to the following size before the - * call to prepareReplyDNSMessage by pxResizeNetworkBufferWithDescriptor. If buffer allocation - * scheme #1 (BufferAllocation_1.c) is used we assert if the needed size is actually present - * in the buffer. */ + * call to prepareReplyDNSMessage by pxResizeNetworkBufferWithDescriptor. + * If the static buffer allocation scheme is used we assert if the needed + * size is actually present in the buffer. */ __CPROVER_assume( ( xDataSize > ( sizeof( UDPPacket_t ) + sizeof( NBNSRequest_t ) + sizeof( NBNSAnswer_t ) - 2 * sizeof( uint16_t ) ) ) && ( xDataSize < ipconfigNETWORK_MTU ) ); xNetworkBuffer.pucEthernetBuffer = safeMalloc( xDataSize ); diff --git a/test/cbmc/proofs/ProcessDHCPReplies/Makefile.json b/test/cbmc/proofs/ProcessDHCPReplies/Makefile.json index 09d5c8d4e..2d20e8e55 100644 --- a/test/cbmc/proofs/ProcessDHCPReplies/Makefile.json +++ b/test/cbmc/proofs/ProcessDHCPReplies/Makefile.json @@ -42,7 +42,7 @@ "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/cbmc.goto", "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_api.goto", "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_DHCP.goto", - "$(FREERTOS_PLUS_TCP)/source/portable/BufferManagement/BufferAllocation_2.goto", + "$(FREERTOS_PLUS_TCP)/source/portable/BufferManagement/BufferAllocation.goto", "$(FREERTOS_PLUS_TCP)/test/FreeRTOS-Kernel/event_groups.goto", "$(FREERTOS_PLUS_TCP)/test/FreeRTOS-Kernel/list.goto" ], diff --git a/test/unit-test/CMakeLists.txt b/test/unit-test/CMakeLists.txt index e3e9bcfaf..12c8584cb 100644 --- a/test/unit-test/CMakeLists.txt +++ b/test/unit-test/CMakeLists.txt @@ -33,7 +33,7 @@ set( UNIT_TEST_DIR ${MODULE_ROOT_DIR}/test/unit-test CACHE INTERNAL "Unit-test d set( KERNEL_DIRECTORY ${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel ) -# See if FreRTOS-Kernel is submoduled +# See if FreeRTOS-Kernel is submoduled if( NOT EXISTS ${KERNEL_DIRECTORY}/include ) # Inform the user of the actions message( STATUS "FreeRTOS-Kernel is required for this build. Submoduling it..." ) @@ -63,10 +63,8 @@ set( TCP_INCLUDES "${MODULE_ROOT_DIR}/source/include/FreeRTOS_IP.h" "${MODULE_ROOT_DIR}/source/include/FreeRTOS_IPv4.h" "${MODULE_ROOT_DIR}/source/include/FreeRTOS_IPv6.h" "${MODULE_ROOT_DIR}/source/include/FreeRTOS_IP_Common.h" - "${MODULE_ROOT_DIR}/source/include/FreeRTOS_IP_Common.h" "${MODULE_ROOT_DIR}/source/include/FreeRTOS_ND.h" "${MODULE_ROOT_DIR}/source/include/FreeRTOS_ARP.h" - "${MODULE_ROOT_DIR}/source/include/FreeRTOS_ARP.h" "${MODULE_ROOT_DIR}/source/include/FreeRTOS_BitConfig.h" "${MODULE_ROOT_DIR}/source/include/FreeRTOS_ICMP.h" "${MODULE_ROOT_DIR}/source/include/FreeRTOS_IP_Timers.h" @@ -130,14 +128,6 @@ foreach( file ${TCP_INCLUDES} ) execute_process( COMMAND sed "1 i\#include \"FreeRTOSIPConfig.h\"" ${CMAKE_BINARY_DIR}/Annexed_TCP/${MODIFIED_FILE}_tmp1.h OUTPUT_FILE ${CMAKE_BINARY_DIR}/Annexed_TCP/${MODIFIED_FILE}_tmp.h ) - if(${MODIFIED_FILE} STREQUAL "FreeRTOS_IP_Private" ) - execute_process( COMMAND sed "s/extern const BaseType_t xBufferAllocFixedSize/extern BaseType_t xBufferAllocFixedSize/g" ${CMAKE_BINARY_DIR}/Annexed_TCP/${MODIFIED_FILE}_tmp.h - OUTPUT_FILE ${CMAKE_BINARY_DIR}/Annexed_TCP/${MODIFIED_FILE}_tmp2.h ) - execute_process( COMMAND mv ${CMAKE_BINARY_DIR}/Annexed_TCP/${MODIFIED_FILE}_tmp2.h ${CMAKE_BINARY_DIR}/Annexed_TCP/${MODIFIED_FILE}_tmp.h ) - endif() - - - # Use this tool to process all conditional declarations. if(${MODIFIED_FILE} STREQUAL "FreeRTOS_Routing" OR ${MODIFIED_FILE} STREQUAL "FreeRTOS_IP_Private" ) execute_process( COMMAND unifdefall -U${Guard} -USEND_REPEATED_COUNT diff --git a/test/unit-test/FreeRTOS_DNS_Cache/FreeRTOS_DNS_Cache_stubs.c b/test/unit-test/FreeRTOS_DNS_Cache/FreeRTOS_DNS_Cache_stubs.c index 3ff0cf226..84a3283d9 100644 --- a/test/unit-test/FreeRTOS_DNS_Cache/FreeRTOS_DNS_Cache_stubs.c +++ b/test/unit-test/FreeRTOS_DNS_Cache/FreeRTOS_DNS_Cache_stubs.c @@ -40,8 +40,6 @@ #include "FreeRTOS_IP_Private.h" -const BaseType_t xBufferAllocFixedSize = pdTRUE; - /* =========================== EXTERN VARIABLES =========================== */ struct freertos_addrinfo pucAddrBuffer[ 2 ]; diff --git a/test/unit-test/FreeRTOS_DNS_Callback/FreeRTOS_DNS_Callback_stubs.c b/test/unit-test/FreeRTOS_DNS_Callback/FreeRTOS_DNS_Callback_stubs.c index b7ad3e2d0..94e0c97b7 100644 --- a/test/unit-test/FreeRTOS_DNS_Callback/FreeRTOS_DNS_Callback_stubs.c +++ b/test/unit-test/FreeRTOS_DNS_Callback/FreeRTOS_DNS_Callback_stubs.c @@ -40,8 +40,6 @@ #include "FreeRTOS_IP_Private.h" -const BaseType_t xBufferAllocFixedSize = pdTRUE; - void vPortEnterCritical( void ) { } diff --git a/test/unit-test/FreeRTOS_DNS_Networking/FreeRTOS_DNS_Networking_stubs.c b/test/unit-test/FreeRTOS_DNS_Networking/FreeRTOS_DNS_Networking_stubs.c index f65fde89e..dc8e7f2e9 100644 --- a/test/unit-test/FreeRTOS_DNS_Networking/FreeRTOS_DNS_Networking_stubs.c +++ b/test/unit-test/FreeRTOS_DNS_Networking/FreeRTOS_DNS_Networking_stubs.c @@ -41,8 +41,6 @@ #include "FreeRTOS_IP_Private.h" -const BaseType_t xBufferAllocFixedSize = pdTRUE; - void vPortEnterCritical( void ) { } diff --git a/test/unit-test/FreeRTOS_DNS_Parser/FreeRTOS_DNS_Parser_stubs.c b/test/unit-test/FreeRTOS_DNS_Parser/FreeRTOS_DNS_Parser_stubs.c index 63926601e..18987b477 100644 --- a/test/unit-test/FreeRTOS_DNS_Parser/FreeRTOS_DNS_Parser_stubs.c +++ b/test/unit-test/FreeRTOS_DNS_Parser/FreeRTOS_DNS_Parser_stubs.c @@ -42,8 +42,6 @@ /* =========================== EXTERN VARIABLES =========================== */ -BaseType_t xBufferAllocFixedSize = pdFALSE; - uint16_t usPacketIdentifier; struct freertos_addrinfo pucAddrBuffer[ 2 ]; diff --git a/test/unit-test/FreeRTOS_DNS_Parser/FreeRTOS_DNS_Parser_utest.c b/test/unit-test/FreeRTOS_DNS_Parser/FreeRTOS_DNS_Parser_utest.c index cee6d148a..ca6217205 100644 --- a/test/unit-test/FreeRTOS_DNS_Parser/FreeRTOS_DNS_Parser_utest.c +++ b/test/unit-test/FreeRTOS_DNS_Parser/FreeRTOS_DNS_Parser_utest.c @@ -82,8 +82,6 @@ static void dns_callback( const char * pcName, /* =========================== EXTERN VARIABLES =========================== */ -extern BaseType_t xBufferAllocFixedSize; - extern struct freertos_addrinfo pucAddrBuffer[ 2 ]; extern struct freertos_sockaddr pucSockAddrBuffer[ 1 ]; @@ -971,8 +969,8 @@ void test_DNS_TreatNBNS_success_nbns_non_fixed_size_buffer( void ) } /** - * @brief success path, BufferAllocation_1.c is used, the Network Buffers can contain at least - * ipconfigNETWORK_MTU + ipSIZE_OF_ETH_HEADER. + * @brief success path, static buffer allocation is used, the Network Buffers + * can contain at least ipconfigNETWORK_MTU + ipSIZE_OF_ETH_HEADER. */ void test_DNS_TreatNBNS_Fail_BufferAllocation1( void ) { @@ -990,7 +988,6 @@ void test_DNS_TreatNBNS_Fail_BufferAllocation1( void ) pxNetworkBuffer.xDataLength = 3000; hook_return = pdTRUE; - xBufferAllocFixedSize = pdTRUE; pxUDPPayloadBuffer_to_NetworkBuffer_ExpectAnyArgsAndReturn( &pxNetworkBuffer ); uxIPHeaderSizePacket_IgnoreAndReturn( ipSIZE_OF_IPv4_HEADER ); usChar2u16_ExpectAnyArgsAndReturn( dnsNBNS_FLAGS_OPCODE_QUERY ); /* usFlags */ @@ -1002,8 +999,8 @@ void test_DNS_TreatNBNS_Fail_BufferAllocation1( void ) } /** - * @brief success path, BufferAllocation_1.c is used, the Network Buffers can contain at least - * ipconfigNETWORK_MTU + ipSIZE_OF_ETH_HEADER. + * @brief success path, static buffer allocation is used, the Network Buffers + * can contain at least ipconfigNETWORK_MTU + ipSIZE_OF_ETH_HEADER. */ void test_DNS_TreatNBNS_success_BufferAllocation1( void ) { @@ -1021,7 +1018,6 @@ void test_DNS_TreatNBNS_success_BufferAllocation1( void ) pxNetworkBuffer.xDataLength = 300; hook_return = pdTRUE; - xBufferAllocFixedSize = pdTRUE; pxUDPPayloadBuffer_to_NetworkBuffer_ExpectAnyArgsAndReturn( &pxNetworkBuffer ); uxIPHeaderSizePacket_IgnoreAndReturn( ipSIZE_OF_IPv4_HEADER ); usChar2u16_ExpectAnyArgsAndReturn( dnsNBNS_FLAGS_OPCODE_QUERY ); /* usFlags */ @@ -1108,7 +1104,6 @@ void test_DNS_TreatNBNS_success_nbns_non_fixed_size_buffer2( void ) size_t uxBufferLength = 300; uint32_t ulIPAddress; - xBufferAllocFixedSize = pdFALSE; NetworkBufferDescriptor_t pxNetworkBuffer = { 0 }; struct xNetworkEndPoint xEndPoint = { 0 }; @@ -1778,7 +1773,6 @@ void test_DNS_ParseDNSReply_answer_lmmnr_reply_xBufferAllocFixedsize( void ) struct freertos_addrinfo * pxAddressInfo; uint16_t usPort; - xBufferAllocFixedSize = pdTRUE; uint8_t * nullAddress = NULL; NetworkEndPoint_t xEndPoint = { 0 }; @@ -2838,7 +2832,6 @@ void test_DNS_ParseDNSReply_answer_lmmnr_reply_valid_new_netbuffer3( void ) usChar2u16_ExpectAnyArgsAndReturn( dnsTYPE_AAAA_HOST ); /* usType */ usChar2u16_ExpectAnyArgsAndReturn( dnsCLASS_IN ); /* usClass */ hook_return = pdTRUE; - xBufferAllocFixedSize = pdTRUE; pxUDPPayloadBuffer_to_NetworkBuffer_ExpectAnyArgsAndReturn( &pxNetworkBuffer ); usGenerateChecksum_ExpectAnyArgsAndReturn( 555 ); diff --git a/test/unit-test/FreeRTOS_TCP_Transmission/FreeRTOS_TCP_Transmission_stubs.c b/test/unit-test/FreeRTOS_TCP_Transmission/FreeRTOS_TCP_Transmission_stubs.c index 14958490f..09a20ca52 100644 --- a/test/unit-test/FreeRTOS_TCP_Transmission/FreeRTOS_TCP_Transmission_stubs.c +++ b/test/unit-test/FreeRTOS_TCP_Transmission/FreeRTOS_TCP_Transmission_stubs.c @@ -45,7 +45,6 @@ /** @brief The expected IP version and header length coded into the IP header itself. */ uint16_t usPacketIdentifier; BaseType_t xTCPWindowLoggingLevel; -BaseType_t xBufferAllocFixedSize = pdFALSE; BaseType_t NetworkInterfaceOutputFunction_Stub_Called = 0; diff --git a/test/unit-test/FreeRTOS_TCP_Transmission/FreeRTOS_TCP_Transmission_utest.c b/test/unit-test/FreeRTOS_TCP_Transmission/FreeRTOS_TCP_Transmission_utest.c index bdfae7693..5e93ce117 100644 --- a/test/unit-test/FreeRTOS_TCP_Transmission/FreeRTOS_TCP_Transmission_utest.c +++ b/test/unit-test/FreeRTOS_TCP_Transmission/FreeRTOS_TCP_Transmission_utest.c @@ -397,7 +397,6 @@ void test_prvTCPSendRepeated_Zero_To_Send( void ) pxNetworkBuffer = &xNetworkBuffer; pxNetworkBuffer->pucEthernetBuffer = ucEthernetBuffer; - xBufferAllocFixedSize = pdFALSE; pxSocket->u.xTCP.txStream = ( StreamBuffer_t * ) 0x12345678; pxSocket->u.xTCP.eTCPState = eCONNECT_SYN; pxSocket->u.xTCP.usMSS = 1000; @@ -1311,8 +1310,6 @@ void test_prvTCPBufferResize_Fixed_Size_With_Buffer( void ) pxNetworkBuffer = &xNetworkBuffer; pxNetworkBuffer->pucEthernetBuffer = ucEthernetBuffer; - xBufferAllocFixedSize = pdTRUE; - uxIPHeaderSizeSocket_ExpectAnyArgsAndReturn( ipSIZE_OF_IPv4_HEADER ); pReturn = prvTCPBufferResize( pxSocket, pxNetworkBuffer, 500, 0 ); @@ -1329,8 +1326,6 @@ void test_prvTCPBufferResize_Fixed_Size_Without_Buffer( void ) pxNetworkBuffer = &xNetworkBuffer; pxNetworkBuffer->pucEthernetBuffer = ucEthernetBuffer; - xBufferAllocFixedSize = pdTRUE; - NetworkBufferDescriptor_t NewNetworkBuffer; NewNetworkBuffer.pucEthernetBuffer = ucEthernetBuffer; @@ -1349,7 +1344,6 @@ void test_prvTCPBufferResize_Without_Buffer( void ) pxNetworkBuffer = &xNetworkBuffer; pxNetworkBuffer->pucEthernetBuffer = ucEthernetBuffer; - xBufferAllocFixedSize = pdFALSE; NetworkBufferDescriptor_t NewNetworkBuffer; NewNetworkBuffer.pucEthernetBuffer = ucEthernetBuffer; @@ -1370,7 +1364,6 @@ void test_prvTCPBufferResize_Without_Buffer_Null_New_Buffer( void ) pxNetworkBuffer = &xNetworkBuffer; pxNetworkBuffer->pucEthernetBuffer = ucEthernetBuffer; - xBufferAllocFixedSize = pdFALSE; NetworkBufferDescriptor_t NewNetworkBuffer; NewNetworkBuffer.pucEthernetBuffer = ucEthernetBuffer; @@ -1391,7 +1384,6 @@ void test_prvTCPBufferResize_With_Buffer_LT_Needed_GT_Last_Packet( void ) pxNetworkBuffer->pucEthernetBuffer = ucEthernetBuffer; pxNetworkBuffer->xDataLength = 500; - xBufferAllocFixedSize = pdFALSE; NetworkBufferDescriptor_t NewNetworkBuffer; NewNetworkBuffer.pucEthernetBuffer = ucEthernetBuffer; @@ -1414,7 +1406,6 @@ void test_prvTCPBufferResize_With_Buffer_LT_Needed_LT_Last_Packet( void ) pxNetworkBuffer->pucEthernetBuffer = ucEthernetBuffer; pxNetworkBuffer->xDataLength = 10; - xBufferAllocFixedSize = pdFALSE; NetworkBufferDescriptor_t NewNetworkBuffer; NewNetworkBuffer.pucEthernetBuffer = ucEthernetBuffer; @@ -1436,7 +1427,6 @@ void test_prvTCPBufferResize_With_Buffer_GT_Needed( void ) pxNetworkBuffer = &xNetworkBuffer; pxNetworkBuffer->pucEthernetBuffer = ucEthernetBuffer; - xBufferAllocFixedSize = pdFALSE; NetworkBufferDescriptor_t NewNetworkBuffer; NewNetworkBuffer.pucEthernetBuffer = ucEthernetBuffer; @@ -1501,7 +1491,6 @@ void test_prvTCPPrepareSend_State_Syn_Zero_Data( void ) pxNetworkBuffer = &xNetworkBuffer; pxNetworkBuffer->pucEthernetBuffer = ucEthernetBuffer; - xBufferAllocFixedSize = pdFALSE; pxSocket->u.xTCP.txStream = ( StreamBuffer_t * ) 0x12345678; pxSocket->u.xTCP.eTCPState = eCONNECT_SYN; pxSocket->u.xTCP.usMSS = 1000; @@ -1526,7 +1515,6 @@ void test_prvTCPPrepareSend_State_Syn_Zero_Data_Win_Change( void ) uint8_t ReturnEthernetBuffer[ ipconfigNETWORK_MTU ]; - xBufferAllocFixedSize = pdFALSE; pxSocket->u.xTCP.txStream = ( StreamBuffer_t * ) 0x12345678; pxSocket->u.xTCP.eTCPState = eCONNECT_SYN; pxSocket->u.xTCP.usMSS = 1000; @@ -1550,7 +1538,6 @@ void test_prvTCPPrepareSend_State_Syn_Zero_Data_Keep_Alive( void ) uint8_t ReturnEthernetBuffer[ ipconfigNETWORK_MTU ]; - xBufferAllocFixedSize = pdFALSE; pxSocket->u.xTCP.txStream = ( StreamBuffer_t * ) 0x12345678; pxSocket->u.xTCP.eTCPState = eCONNECT_SYN; pxSocket->u.xTCP.usMSS = 1000; @@ -1575,7 +1562,6 @@ void test_prvTCPPrepareSend_State_Established_Zero_Data_KLCount1_Age_GT_Max( voi uint8_t ReturnEthernetBuffer[ ipconfigNETWORK_MTU ]; - xBufferAllocFixedSize = pdFALSE; pxSocket->u.xTCP.txStream = NULL; pxSocket->u.xTCP.eTCPState = eESTABLISHED; pxSocket->u.xTCP.usMSS = 1000; @@ -1603,7 +1589,6 @@ void test_prvTCPPrepareSend_State_Established_Null_Buffer_Zero_Data_KLCount0_Age pxSocket = &xSocket; pxNetworkBuffer = NULL; - xBufferAllocFixedSize = pdFALSE; pxSocket->u.xTCP.txStream = NULL; pxSocket->u.xTCP.eTCPState = eESTABLISHED; pxSocket->u.xTCP.usMSS = 1000; @@ -1630,7 +1615,6 @@ void test_prvTCPPrepareSend_State_Established_Null_Buffer_Zero_Data_KLCount1_Age pxSocket = &xSocket; pxNetworkBuffer = NULL; - xBufferAllocFixedSize = pdFALSE; pxSocket->u.xTCP.txStream = NULL; pxSocket->u.xTCP.eTCPState = eESTABLISHED; pxSocket->u.xTCP.usMSS = 1000; @@ -1661,7 +1645,6 @@ void test_prvTCPPrepareSend_State_Established_Zero_Data_KLCount1_Age_GT_Max_Win_ uint8_t ReturnEthernetBuffer[ ipconfigNETWORK_MTU ]; - xBufferAllocFixedSize = pdFALSE; pxSocket->u.xTCP.txStream = NULL; pxSocket->u.xTCP.eTCPState = eESTABLISHED; pxSocket->u.xTCP.usMSS = 1000; @@ -1694,7 +1677,6 @@ void test_prvTCPPrepareSend_State_Established_Non_Zero_Data_No_Buffer( void ) StreamBuffer_t StreamBuffer; - xBufferAllocFixedSize = pdFALSE; pxSocket->u.xTCP.txStream = ( StreamBuffer_t * ) &StreamBuffer; pxSocket->u.xTCP.eTCPState = eESTABLISHED; pxSocket->u.xTCP.usMSS = 1000; @@ -1721,7 +1703,6 @@ void test_prvTCPPrepareSend_State_Established_Non_Zero_Data_MSS_0_KLCount4( void pxNetworkBuffer = &xNetworkBuffer; pxNetworkBuffer->pucEthernetBuffer = ucEthernetBuffer; - xBufferAllocFixedSize = pdFALSE; uint8_t ReturnEthernetBuffer[ ipconfigNETWORK_MTU ]; NetworkBufferDescriptor_t NewNetworkBuffer; NewNetworkBuffer.pucEthernetBuffer = ReturnEthernetBuffer; @@ -1754,7 +1735,6 @@ void test_prvTCPPrepareSend_State_Established_Non_Zero_Data_Not_Close_Not_ShutDo pxNetworkBuffer = &xNetworkBuffer; pxNetworkBuffer->pucEthernetBuffer = ucEthernetBuffer; - xBufferAllocFixedSize = pdFALSE; uint8_t ReturnEthernetBuffer[ ipconfigNETWORK_MTU ]; NetworkBufferDescriptor_t NewNetworkBuffer; NewNetworkBuffer.pucEthernetBuffer = ReturnEthernetBuffer; diff --git a/test/unit-test/TCPFilePaths.cmake b/test/unit-test/TCPFilePaths.cmake index adfb31218..4b4745772 100644 --- a/test/unit-test/TCPFilePaths.cmake +++ b/test/unit-test/TCPFilePaths.cmake @@ -50,7 +50,7 @@ set( TCP_SOURCES # TCP library Include directories. set( TCP_INCLUDE_DIRS ${CMAKE_CURRENT_LIST_DIR}/../../source/include - ${CMAKE_CURRENT_LIST_DIR}/../../source/portable/Buffermanagement + ${CMAKE_CURRENT_LIST_DIR}/../../source/portable/BufferManagement ${CMAKE_CURRENT_LIST_DIR}/../../source/portable/Compiler/MSVC ${CMAKE_CURRENT_LIST_DIR}/stubs ) diff --git a/tools/tcp_utilities/plus_tcp_demo_cli.c b/tools/tcp_utilities/plus_tcp_demo_cli.c index 37e00e72b..2f146e304 100644 --- a/tools/tcp_utilities/plus_tcp_demo_cli.c +++ b/tools/tcp_utilities/plus_tcp_demo_cli.c @@ -561,7 +561,7 @@ static void handle_arpq( char * pcBuffer ) #if ( ipconfigUSE_IPv6 != 0 ) case ipTYPE_IPv6: - pxBuffer = pxGetNetworkBufferWithDescriptor( BUFFER_FROM_WHERE_CALL( 180 ) uxNeededSize, pdMS_TO_TICKS( 100U ) ); + pxBuffer = pxGetNetworkBufferWithDescriptor( uxNeededSize, pdMS_TO_TICKS( 100U ) ); if( pxBuffer != NULL ) { diff --git a/tools/tcp_utilities/tcp_mem_stats.c b/tools/tcp_utilities/tcp_mem_stats.c index 90c921e07..2d56b3ec9 100644 --- a/tools/tcp_utilities/tcp_mem_stats.c +++ b/tools/tcp_utilities/tcp_mem_stats.c @@ -230,11 +230,10 @@ STATS_PRINTF( ( "TCPMemStat,ipconfig item,Value,PerUnit,Total\n" ) ); xFirstLineNr = xCurrentLine; - if( xBufferAllocFixedSize != 0 ) + #if ( ipconfigBUFFER_ALLOC_STATIC != 0 ) { size_t uxBytes; - /* Using BufferAllocation_1.c */ uxPacketSize = ( ipconfigNETWORK_MTU + ipSIZE_OF_ETH_HEADER + ipBUFFER_PADDING + 31 ) & ~0x1FuL; uxBytes = ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS * ( uxPacketSize + sizeof( NetworkBufferDescriptor_t ) ); @@ -245,11 +244,10 @@ xCurrentLine ) ); uxStaticSize += uxBytes; } - else + #else /* if ( ipconfigBUFFER_ALLOC_STATIC != 0 ) */ { size_t uxBytes; - /* Using BufferAllocation_2.c */ uxBytes = ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS * sizeof( NetworkBufferDescriptor_t ); STATS_PRINTF( ( "TCPMemStat,NUM_NETWORK_BUFFER_DESCRIPTORS,%u,%u,=B%d*C%d,Descriptors only\n", ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS, @@ -258,6 +256,7 @@ xCurrentLine ) ); uxStaticSize += uxBytes; } + #endif /* if ( ipconfigBUFFER_ALLOC_STATIC != 0 ) */ { #if ( ipconfigUSE_TCP_WIN != 0 ) @@ -314,15 +313,15 @@ /* * End of fixed RAM allocations. */ - if( xBufferAllocFixedSize != 0 ) + #if ( ipconfigBUFFER_ALLOC_STATIC != 0 ) { pucComment[ 0 ] = 0; } - else + #else { size_t uxBytes; - /* BufferAllocation_2.c uses HEAP to store network packets. */ + /* Dynamic buffer allocation uses HEAP to store network packets. */ uxPacketSize = ( ipconfigNETWORK_MTU + ipSIZE_OF_ETH_HEADER + ipBUFFER_PADDING + 3 ) & ~0x03uL; uxBytes = ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS * uxPacketSize; STATS_PRINTF( ( "TCPMemStat,Network buffers in HEAP,%u,%u,=B%d*C%d\n", @@ -331,8 +330,9 @@ xCurrentLine, xCurrentLine ) ); uxStaticSize += uxBytes; - snprintf( pucComment, sizeof pucComment, "Actual size fluctuates because BufferAllocation_2.c is used" ); + snprintf( pucComment, sizeof pucComment, "Actual size fluctuates because dynamic buffer allocation is used" ); } + #endif /* if ( ipconfigBUFFER_ALLOC_STATIC != 0 ) */ xLastHeaderLineNr = xCurrentLine;