From 090000ab834664655a481dc75dcfc1d541bd5ba9 Mon Sep 17 00:00:00 2001 From: Christoph Seitz Date: Thu, 15 Jun 2023 21:58:44 +0200 Subject: [PATCH 1/9] Add priority fields for sockets and buffers. --- source/FreeRTOS_Sockets.c | 21 +++++++++++++++++++ source/FreeRTOS_TCP_Transmission_IPV4.c | 3 +++ source/FreeRTOS_TCP_Transmission_IPV6.c | 3 +++ source/include/FreeRTOSIPConfigDefaults.h | 4 ++++ source/include/FreeRTOS_IP.h | 3 +++ source/include/FreeRTOS_IP_Private.h | 4 ++++ source/include/FreeRTOS_Sockets.h | 7 ++++++- .../BufferManagement/BufferAllocation_1.c | 3 +++ .../BufferManagement/BufferAllocation_2.c | 3 +++ 9 files changed, 50 insertions(+), 1 deletion(-) diff --git a/source/FreeRTOS_Sockets.c b/source/FreeRTOS_Sockets.c index d1bf73b09..27579543c 100644 --- a/source/FreeRTOS_Sockets.c +++ b/source/FreeRTOS_Sockets.c @@ -758,6 +758,9 @@ Socket_t FreeRTOS_socket( BaseType_t xDomain, pxSocket->xSendBlockTime = ipconfigSOCK_DEFAULT_SEND_BLOCK_TIME; pxSocket->ucSocketOptions = ( uint8_t ) FREERTOS_SO_UDPCKSUM_OUT; pxSocket->ucProtocol = ( uint8_t ) xProtocolCpy; /* protocol: UDP or TCP */ + #if ( ipconfigPACKET_PRIORITIES > 1 ) + pxSocket->ucPriority = 0; + #endif xReturn = pxSocket; } @@ -2928,6 +2931,24 @@ BaseType_t FreeRTOS_setsockopt( Socket_t xSocket, xReturn = prvSetOptionStopRX( pxSocket, pvOptionValue ); break; #endif /* ipconfigUSE_TCP == 1 */ + #if ( ipconfigPACKET_PRIORITIES > 1 ) + case FREERTOS_SO_PRIORITY: + { + uint8_t * pucValue = ( uint8_t * ) pvOptionValue; + + if( ( pucValue == NULL ) && ( *pucValue > 8 ) ) + { + xReturn = pdFREERTOS_ERRNO_EINVAL; + } + else + { + pxSocket->ucPriority = *pucValue; + xReturn = pdPASS; + } + + break; + } + #endif /* if ipconfigEVENT_QUEUES > 1 */ default: /* No other options are handled. */ diff --git a/source/FreeRTOS_TCP_Transmission_IPV4.c b/source/FreeRTOS_TCP_Transmission_IPV4.c index 3e5f69cd5..9c5968006 100644 --- a/source/FreeRTOS_TCP_Transmission_IPV4.c +++ b/source/FreeRTOS_TCP_Transmission_IPV4.c @@ -183,6 +183,9 @@ void prvTCPReturnPacket_IPV4( FreeRTOS_Socket_t * pxSocket, prvTCPReturn_SetSequenceNumber( pxSocket, pxNetworkBuffer, uxIPHeaderSize, ulLen ); pxIPHeader->ulDestinationIPAddress = FreeRTOS_htonl( pxSocket->u.xTCP.xRemoteIP.ulIP_IPv4 ); pxIPHeader->ulSourceIPAddress = pxNetworkBuffer->pxEndPoint->ipv4_settings.ulIPAddress; + #if ( ipconfigPACKET_PRIORITIES > 1 ) + pxNetworkBuffer->ucPriority = pxSocket->ucPriority; + #endif } else { diff --git a/source/FreeRTOS_TCP_Transmission_IPV6.c b/source/FreeRTOS_TCP_Transmission_IPV6.c index 6c7d08923..3db6fa988 100644 --- a/source/FreeRTOS_TCP_Transmission_IPV6.c +++ b/source/FreeRTOS_TCP_Transmission_IPV6.c @@ -193,6 +193,9 @@ void prvTCPReturnPacket_IPV6( FreeRTOS_Socket_t * pxSocket, prvTCPReturn_SetSequenceNumber( pxSocket, pxNetworkBuffer, uxIPHeaderSize, ulLen ); ( void ) memcpy( pxIPHeader->xDestinationAddress.ucBytes, pxSocket->u.xTCP.xRemoteIP.xIP_IPv6.ucBytes, ipSIZE_OF_IPv6_ADDRESS ); ( void ) memcpy( pxIPHeader->xSourceAddress.ucBytes, pxNetworkBuffer->pxEndPoint->ipv6_settings.xIPAddress.ucBytes, ipSIZE_OF_IPv6_ADDRESS ); + #if ( ipconfigPACKET_PRIORITIES > 1 ) + pxNetworkBuffer->ucPriority = pxSocket->ucPriority; + #endif } else { diff --git a/source/include/FreeRTOSIPConfigDefaults.h b/source/include/FreeRTOSIPConfigDefaults.h index 7cbdb9e31..04039458b 100644 --- a/source/include/FreeRTOSIPConfigDefaults.h +++ b/source/include/FreeRTOSIPConfigDefaults.h @@ -1161,4 +1161,8 @@ #define ipconfigRA_IP_TEST_TIME_OUT_MSEC ( 1500U ) #endif +#ifndef ipconfigPACKET_PRIORITIES + #define ipconfigPACKET_PRIORITIES 1 +#endif + #endif /* FREERTOS_DEFAULT_IP_CONFIG_H */ diff --git a/source/include/FreeRTOS_IP.h b/source/include/FreeRTOS_IP.h index 8500c5fc4..f7815b5cd 100644 --- a/source/include/FreeRTOS_IP.h +++ b/source/include/FreeRTOS_IP.h @@ -168,6 +168,9 @@ typedef struct xNETWORK_BUFFER #if ( ipconfigUSE_LINKED_RX_MESSAGES != 0 ) struct xNETWORK_BUFFER * pxNextBuffer; /**< Possible optimisation for expert users - requires network driver support. */ #endif + #if ( ipconfigPACKET_PRIORITIES > 1 ) + uint8_t ucPriority; /**< Priority of the buffer*/ + #endif #define ul_IPAddress xIPAddress.xIP_IPv4 #define x_IPv6Address xIPAddress.xIP_IPv6 diff --git a/source/include/FreeRTOS_IP_Private.h b/source/include/FreeRTOS_IP_Private.h index 59b47c22a..52fbabc8e 100644 --- a/source/include/FreeRTOS_IP_Private.h +++ b/source/include/FreeRTOS_IP_Private.h @@ -715,6 +715,10 @@ struct xSOCKET */ void * pvSocketID; + #if ( ipconfigPACKET_PRIORITIES > 1 ) + uint8_t ucPriority; /**< Priority of the socket */ + #endif + /* TCP/UDP specific fields: */ /* Before accessing any member of this structure, it should be confirmed */ /* that the protocol corresponds with the type of structure */ diff --git a/source/include/FreeRTOS_Sockets.h b/source/include/FreeRTOS_Sockets.h index fcfac4930..7c18ca689 100644 --- a/source/include/FreeRTOS_Sockets.h +++ b/source/include/FreeRTOS_Sockets.h @@ -148,8 +148,13 @@ #endif #if ( ipconfigUSE_TCP == 1 ) - #define FREERTOS_SO_SET_LOW_HIGH_WATER ( 18 ) + #define FREERTOS_SO_SET_LOW_HIGH_WATER ( 18 ) #endif + + #if ( ipconfigPACKET_PRIORITIES > 1 ) + #define FREERTOS_SO_PRIORITY ( 19 ) + #endif + #define FREERTOS_INADDR_ANY ( 0U ) /* The 0.0.0.0 IPv4 address. */ #if ( 0 ) /* Not Used */ diff --git a/source/portable/BufferManagement/BufferAllocation_1.c b/source/portable/BufferManagement/BufferAllocation_1.c index 546666e2b..1d43565e2 100644 --- a/source/portable/BufferManagement/BufferAllocation_1.c +++ b/source/portable/BufferManagement/BufferAllocation_1.c @@ -292,6 +292,9 @@ NetworkBufferDescriptor_t * pxGetNetworkBufferWithDescriptor( size_t xRequestedS pxReturn->xDataLength = xRequestedSizeBytes; pxReturn->pxInterface = NULL; pxReturn->pxEndPoint = NULL; + #if ( ipconfigPACKET_PRIORITIES > 1 ) + pxReturn->ucPriority = 1; + #endif #if ( ipconfigTCP_IP_SANITY != 0 ) { diff --git a/source/portable/BufferManagement/BufferAllocation_2.c b/source/portable/BufferManagement/BufferAllocation_2.c index 075cdf0a7..987cfd12e 100644 --- a/source/portable/BufferManagement/BufferAllocation_2.c +++ b/source/portable/BufferManagement/BufferAllocation_2.c @@ -306,6 +306,9 @@ NetworkBufferDescriptor_t * pxGetNetworkBufferWithDescriptor( size_t xRequestedS pxReturn->xDataLength = xRequestedSizeBytesCopy; pxReturn->pxInterface = NULL; pxReturn->pxEndPoint = NULL; + #if ( ipconfigPACKET_PRIORITIES > 1 ) + pxReturn->ucPriority = 1; + #endif #if ( ipconfigUSE_LINKED_RX_MESSAGES != 0 ) { From 43c522db48933a41ce47c432b6739742e017711f Mon Sep 17 00:00:00 2001 From: Christoph Seitz Date: Thu, 15 Jun 2023 22:05:20 +0200 Subject: [PATCH 2/9] Add multiple event queues. This enables strict priority based scheduling of packets within the stack. The user can define a socket/packet priority mapping for each queue. This allows certain high priority traffic to overtake packets or low priority traffic to fill the rest of the bandwidth. --- source/FreeRTOS_IP.c | 131 +++++++++++++++++++--- source/include/FreeRTOSIPConfigDefaults.h | 22 +++- 2 files changed, 134 insertions(+), 19 deletions(-) diff --git a/source/FreeRTOS_IP.c b/source/FreeRTOS_IP.c index de33cf1aa..7afc28277 100644 --- a/source/FreeRTOS_IP.c +++ b/source/FreeRTOS_IP.c @@ -178,6 +178,11 @@ static eFrameProcessingResult_t prvProcessUDPPacket( NetworkBufferDescriptor_t * /** @brief The queue used to pass events into the IP-task for processing. */ QueueHandle_t xNetworkEventQueue = NULL; +#if ipconfigEVENT_QUEUES > 1 + QueueHandle_t xNetworkEventQueues[ ipconfigEVENT_QUEUES ] = { 0 }; + uint8_t xQueueMapping[ ipconfigPACKET_PRIORITIES ] = ipconfigPACKET_PRIORITY_MAPPING; +#endif + /** @brief The IP packet ID. */ uint16_t usPacketIdentifier = 0U; @@ -271,10 +276,31 @@ static void prvProcessIPEventsAndTimers( void ) /* Wait until there is something to do. If the following call exits * due to a time out rather than a message being received, set a * 'NoEvent' value. */ - if( xQueueReceive( xNetworkEventQueue, ( void * ) &xReceivedEvent, xNextIPSleep ) == pdFALSE ) - { - xReceivedEvent.eEventType = eNoEvent; - } + #if ipconfigEVENT_QUEUES > 1 + if( ulTaskNotifyTake( pdFALSE, xNextIPSleep ) == pdFALSE ) + { + xReceivedEvent.eEventType = eNoEvent; + } + else + { + BaseType_t xIndex; + BaseType_t xReturn; + + for( xIndex = ipconfigEVENT_QUEUES - 1; xIndex >= 0; xIndex-- ) + { + if( uxQueueMessagesWaiting( xNetworkEventQueues[ xIndex ] ) > 0 ) + { + xQueueReceive( xNetworkEventQueues[ xIndex ], &xReceivedEvent, 0 ); + break; + } + } + } + #else /* if ipconfigEVENT_QUEUES > 1 */ + if( xQueueReceive( xNetworkEventQueue, ( void * ) &xReceivedEvent, xNextIPSleep ) == pdFALSE ) + { + xReceivedEvent.eEventType = eNoEvent; + } + #endif /* if ipconfigEVENT_QUEUES > 1 */ #if ( ipconfigCHECK_IP_QUEUE_SPACE != 0 ) { @@ -942,6 +968,11 @@ void * FreeRTOS_GetUDPPayloadBuffer_Multi( size_t uxRequestedSizeBytes, BaseType_t FreeRTOS_IPInit_Multi( void ) { BaseType_t xReturn = pdFALSE; + BaseType_t xAllocSuccessful = pdFALSE; + + #if ipconfigEVENT_QUEUES > 1 + BaseType_t xIndex; + #endif /* There must be at least one interface and one end-point. */ configASSERT( FreeRTOS_FirstNetworkInterface() != NULL ); @@ -953,21 +984,54 @@ BaseType_t FreeRTOS_IPInit_Multi( void ) /* Attempt to create the queue used to communicate with the IP task. */ #if ( configSUPPORT_STATIC_ALLOCATION == 1 ) { - static StaticQueue_t xNetworkEventStaticQueue; - static uint8_t ucNetworkEventQueueStorageArea[ ipconfigEVENT_QUEUE_LENGTH * sizeof( IPStackEvent_t ) ]; - xNetworkEventQueue = xQueueCreateStatic( ipconfigEVENT_QUEUE_LENGTH, - sizeof( IPStackEvent_t ), - ucNetworkEventQueueStorageArea, - &xNetworkEventStaticQueue ); + #if ( ipconfigEVENT_QUEUES > 1 ) + static StaticQueue_t xPacketEventStaticQueue[ ipconfigEVENT_QUEUES ]; + static uint8_t ucPacketEventQueueStorageArea[ ipconfigEVENT_QUEUES ][ ipconfigEVENT_QUEUE_LENGTH * sizeof( IPStackEvent_t ) ]; + + xAllocSuccessful = pdTRUE; + + for( xIndex = 0; xIndex < ipconfigEVENT_QUEUES; xIndex++ ) + { + xNetworkEventQueues[ xIndex ] = xQueueCreateStatic( ipconfigEVENT_QUEUE_LENGTH, + sizeof( IPStackEvent_t ), + ucPacketEventQueueStorageArea[ xIndex ], + &xPacketEventStaticQueue[ xIndex ] ); + xAllocSuccessful &= ( xNetworkEventQueues[ xIndex ] != NULL ); + } + + xNetworkEventQueue = xNetworkEventQueues[ ipconfigEVENT_QUEUES - 1 ]; + #else /* if ipconfigEVENT_QUEUES > 1 */ + static StaticQueue_t xNetworkEventStaticQueue; + static uint8_t ucNetworkEventQueueStorageArea[ ipconfigEVENT_QUEUE_LENGTH * sizeof( IPStackEvent_t ) ]; + xNetworkEventQueue = xQueueCreateStatic( ipconfigEVENT_QUEUE_LENGTH, + sizeof( IPStackEvent_t ), + ucNetworkEventQueueStorageArea, + &xNetworkEventStaticQueue ); + xAllocSuccessful = ( xNetworkEventQueue != NULL ); + #endif /* if ipconfigEVENT_QUEUES > 1 */ } - #else + #else /* if ( configSUPPORT_STATIC_ALLOCATION == 1 ) */ { - xNetworkEventQueue = xQueueCreate( ipconfigEVENT_QUEUE_LENGTH, sizeof( IPStackEvent_t ) ); - configASSERT( xNetworkEventQueue != NULL ); + #if ( ipconfigEVENT_QUEUES > 1 ) + xAllocSuccessful = pdTRUE; + + for( xIndex = 0; xIndex < ipconfigEVENT_QUEUES; xIndex++ ) + { + xNetworkEventQueues[ xIndex ] = xQueueCreate( ipconfigEVENT_QUEUE_LENGTH, sizeof( IPStackEvent_t ) ); + configASSERT( xNetworkEventQueues[ xIndex ] != NULL ); + xAllocSuccessful &= ( xNetworkEventQueues[ xIndex ] != NULL ); + } + + xNetworkEventQueue = xNetworkEventQueues[ ipconfigEVENT_QUEUES - 1 ]; + #else /* if ( ipconfigEVENT_QUEUES > 1 ) */ + xNetworkEventQueue = xQueueCreate( ipconfigEVENT_QUEUE_LENGTH, sizeof( IPStackEvent_t ) ); + configASSERT( xNetworkEventQueue != NULL ); + xAllocSuccessful = ( xNetworkEventQueue != NULL ); + #endif /* if ( ipconfigEVENT_QUEUES > 1 ) */ } #endif /* configSUPPORT_STATIC_ALLOCATION */ - if( xNetworkEventQueue != NULL ) + if( xAllocSuccessful != pdFALSE ) { #if ( configQUEUE_REGISTRY_SIZE > 0 ) { @@ -1017,8 +1081,18 @@ BaseType_t FreeRTOS_IPInit_Multi( void ) FreeRTOS_debug_printf( ( "FreeRTOS_IPInit_Multi: xNetworkBuffersInitialise() failed\n" ) ); /* Clean up. */ - vQueueDelete( xNetworkEventQueue ); - xNetworkEventQueue = NULL; + #if ( ipconfigEVENT_QUEUES > 1 ) + for( xIndex = 0; xIndex < ipconfigEVENT_QUEUES; xIndex++ ) + { + vQueueDelete( xNetworkEventQueues[ xIndex ] ); + xNetworkEventQueues[ xIndex ] = NULL; + } + + xNetworkEventQueue = NULL; + #else + vQueueDelete( xNetworkEventQueue ); + xNetworkEventQueue = NULL; + #endif } } else @@ -1392,7 +1466,11 @@ BaseType_t xSendEventStructToIPTask( const IPStackEvent_t * pxEvent, * IP task is already awake processing other message. */ vIPSetTCPTimerExpiredState( pdTRUE ); - if( uxQueueMessagesWaiting( xNetworkEventQueue ) != 0U ) + #if ipconfigEVENT_QUEUES > 1 + if( ulTaskGenericNotifyValueClear( xIPTaskHandle, 0, 0 ) != 0U ) + #else + if( uxQueueMessagesWaiting( xNetworkEventQueue ) != 0U ) + #endif { /* Not actually going to send the message but this is not a * failure as the message didn't need to be sent. */ @@ -1411,7 +1489,24 @@ BaseType_t xSendEventStructToIPTask( const IPStackEvent_t * pxEvent, uxUseTimeout = ( TickType_t ) 0; } - xReturn = xQueueSendToBack( xNetworkEventQueue, pxEvent, uxUseTimeout ); + #if ipconfigEVENT_QUEUES > 1 + BaseType_t xQueue = ipconfigEVENT_QUEUES - 1; + + if( ( pxEvent->eEventType == eNetworkRxEvent ) || ( pxEvent->eEventType == eNetworkTxEvent ) || ( pxEvent->eEventType == eStackTxEvent ) ) + { + NetworkBufferDescriptor_t * pxBuffer = ( NetworkBufferDescriptor_t * ) pxEvent->pvData; + xQueue = xQueueMapping[ pxBuffer->ucPriority ]; + } + + xReturn = xQueueSendToBack( xNetworkEventQueues[ xQueue ], pxEvent, uxUseTimeout ); + + if( xReturn != pdFAIL ) + { + xTaskNotifyGive( xIPTaskHandle ); + } + #else /* if ipconfigEVENT_QUEUES > 1 */ + xReturn = xQueueSendToBack( xNetworkEventQueue, pxEvent, uxUseTimeout ); + #endif /* if ipconfigEVENT_QUEUES > 1 */ if( xReturn == pdFAIL ) { diff --git a/source/include/FreeRTOSIPConfigDefaults.h b/source/include/FreeRTOSIPConfigDefaults.h index 04039458b..d3e5b8e8a 100644 --- a/source/include/FreeRTOSIPConfigDefaults.h +++ b/source/include/FreeRTOSIPConfigDefaults.h @@ -1161,8 +1161,28 @@ #define ipconfigRA_IP_TEST_TIME_OUT_MSEC ( 1500U ) #endif +#ifndef ipconfigEVENT_QUEUES + #define ipconfigEVENT_QUEUES 1 +#endif + #ifndef ipconfigPACKET_PRIORITIES - #define ipconfigPACKET_PRIORITIES 1 + #if ipconfigEVENT_QUEUES > 1 + #define ipconfigPACKET_PRIORITIES 8 + #else + #define ipconfigPACKET_PRIORITIES 1 + #endif +#endif + +#ifndef ipconfigPACKET_PRIORITY_MAPPING + #if ipconfigPACKET_PRIORITIES == 8 && ipconfigEVENT_QUEUES == 3 + #define ipconfigPACKET_PRIORITY_MAPPING { 0, 1, 1, 1, 2, 2, 2, 2, } + #elif ipconfigPACKET_PRIORITIES > 1 && ipconfigEVENT_QUEUES > 1 + #error "Please define your own ipconfigPACKET_PRIORITY_MAPPING." + #endif +#endif + +#if ipconfigPACKET_PRIORITIES == 1 && ipconfigEVENT_QUEUES > 1 + #error "Network event queues need priority support." #endif #endif /* FREERTOS_DEFAULT_IP_CONFIG_H */ From f731c9d36ebf78f01eddfbb8e18e690840c58410 Mon Sep 17 00:00:00 2001 From: Christoph Seitz Date: Thu, 15 Jun 2023 22:35:25 +0200 Subject: [PATCH 3/9] Add missing udp packet priority. --- source/FreeRTOS_Sockets.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/source/FreeRTOS_Sockets.c b/source/FreeRTOS_Sockets.c index 27579543c..95c66b28a 100644 --- a/source/FreeRTOS_Sockets.c +++ b/source/FreeRTOS_Sockets.c @@ -1434,6 +1434,9 @@ static int32_t prvSendUDPPacket( const FreeRTOS_Socket_t * pxSocket, pxNetworkBuffer->xDataLength = uxTotalDataLength + uxPayloadOffset; pxNetworkBuffer->usPort = pxDestinationAddress->sin_port; pxNetworkBuffer->usBoundPort = ( uint16_t ) socketGET_SOCKET_PORT( pxSocket ); + #if ipconfigPACKET_PRIORITIES > 1 + pxNetworkBuffer->ucPriority = pxSocket->ucPriority; + #endif /* The socket options are passed to the IP layer in the * space that will eventually get used by the Ethernet header. */ From 97d05ae1405f1e40939c6ffb696338d51385ad64 Mon Sep 17 00:00:00 2001 From: Christoph Seitz Date: Thu, 15 Jun 2023 22:35:59 +0200 Subject: [PATCH 4/9] Fix priority check in setsockopt --- source/FreeRTOS_Sockets.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/FreeRTOS_Sockets.c b/source/FreeRTOS_Sockets.c index 95c66b28a..bd321949e 100644 --- a/source/FreeRTOS_Sockets.c +++ b/source/FreeRTOS_Sockets.c @@ -2939,7 +2939,7 @@ BaseType_t FreeRTOS_setsockopt( Socket_t xSocket, { uint8_t * pucValue = ( uint8_t * ) pvOptionValue; - if( ( pucValue == NULL ) && ( *pucValue > 8 ) ) + if( ( pucValue == NULL ) && ( *pucValue >= ipconfigPACKET_PRIORITIES ) ) { xReturn = pdFREERTOS_ERRNO_EINVAL; } From 680ae63363981671b63b64959d96e8da44611688 Mon Sep 17 00:00:00 2001 From: Christoph Seitz Date: Thu, 15 Jun 2023 22:44:05 +0200 Subject: [PATCH 5/9] Add default priority config value. --- source/FreeRTOS_Sockets.c | 2 +- source/include/FreeRTOSIPConfigDefaults.h | 4 ++++ source/portable/BufferManagement/BufferAllocation_1.c | 2 +- source/portable/BufferManagement/BufferAllocation_2.c | 2 +- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/source/FreeRTOS_Sockets.c b/source/FreeRTOS_Sockets.c index bd321949e..121d6aec6 100644 --- a/source/FreeRTOS_Sockets.c +++ b/source/FreeRTOS_Sockets.c @@ -759,7 +759,7 @@ Socket_t FreeRTOS_socket( BaseType_t xDomain, pxSocket->ucSocketOptions = ( uint8_t ) FREERTOS_SO_UDPCKSUM_OUT; pxSocket->ucProtocol = ( uint8_t ) xProtocolCpy; /* protocol: UDP or TCP */ #if ( ipconfigPACKET_PRIORITIES > 1 ) - pxSocket->ucPriority = 0; + pxSocket->ucPriority = ipconfigPACKET_PRIORITY_DEFAULT; #endif xReturn = pxSocket; diff --git a/source/include/FreeRTOSIPConfigDefaults.h b/source/include/FreeRTOSIPConfigDefaults.h index d3e5b8e8a..65235a6dd 100644 --- a/source/include/FreeRTOSIPConfigDefaults.h +++ b/source/include/FreeRTOSIPConfigDefaults.h @@ -1181,6 +1181,10 @@ #endif #endif +#ifndef ipconfigPACKET_PRIORITY_DEFAULT + #define ipconfigPACKET_PRIORITY_DEFAULT 1 +#endif + #if ipconfigPACKET_PRIORITIES == 1 && ipconfigEVENT_QUEUES > 1 #error "Network event queues need priority support." #endif diff --git a/source/portable/BufferManagement/BufferAllocation_1.c b/source/portable/BufferManagement/BufferAllocation_1.c index 1d43565e2..7f2e9102f 100644 --- a/source/portable/BufferManagement/BufferAllocation_1.c +++ b/source/portable/BufferManagement/BufferAllocation_1.c @@ -293,7 +293,7 @@ NetworkBufferDescriptor_t * pxGetNetworkBufferWithDescriptor( size_t xRequestedS pxReturn->pxInterface = NULL; pxReturn->pxEndPoint = NULL; #if ( ipconfigPACKET_PRIORITIES > 1 ) - pxReturn->ucPriority = 1; + pxReturn->ucPriority = ipconfigPACKET_PRIORITY_DEFAULT; #endif #if ( ipconfigTCP_IP_SANITY != 0 ) diff --git a/source/portable/BufferManagement/BufferAllocation_2.c b/source/portable/BufferManagement/BufferAllocation_2.c index 987cfd12e..48906a2fa 100644 --- a/source/portable/BufferManagement/BufferAllocation_2.c +++ b/source/portable/BufferManagement/BufferAllocation_2.c @@ -307,7 +307,7 @@ NetworkBufferDescriptor_t * pxGetNetworkBufferWithDescriptor( size_t xRequestedS pxReturn->pxInterface = NULL; pxReturn->pxEndPoint = NULL; #if ( ipconfigPACKET_PRIORITIES > 1 ) - pxReturn->ucPriority = 1; + pxReturn->ucPriority = ipconfigPACKET_PRIORITY_DEFAULT; #endif #if ( ipconfigUSE_LINKED_RX_MESSAGES != 0 ) From 890ef295ad6485443c5f2c2d70616681e3a74007 Mon Sep 17 00:00:00 2001 From: Christoph Seitz Date: Fri, 16 Jun 2023 12:57:54 +0200 Subject: [PATCH 6/9] Address review comments. --- source/FreeRTOS_IP.c | 2 +- source/FreeRTOS_Sockets.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/source/FreeRTOS_IP.c b/source/FreeRTOS_IP.c index 7afc28277..3d041c11a 100644 --- a/source/FreeRTOS_IP.c +++ b/source/FreeRTOS_IP.c @@ -1467,7 +1467,7 @@ BaseType_t xSendEventStructToIPTask( const IPStackEvent_t * pxEvent, vIPSetTCPTimerExpiredState( pdTRUE ); #if ipconfigEVENT_QUEUES > 1 - if( ulTaskGenericNotifyValueClear( xIPTaskHandle, 0, 0 ) != 0U ) + if( ulTaskNotifyValueClear( xIPTaskHandle, 0 ) != 0U ) #else if( uxQueueMessagesWaiting( xNetworkEventQueue ) != 0U ) #endif diff --git a/source/FreeRTOS_Sockets.c b/source/FreeRTOS_Sockets.c index 121d6aec6..fe6fa1dd3 100644 --- a/source/FreeRTOS_Sockets.c +++ b/source/FreeRTOS_Sockets.c @@ -2939,7 +2939,7 @@ BaseType_t FreeRTOS_setsockopt( Socket_t xSocket, { uint8_t * pucValue = ( uint8_t * ) pvOptionValue; - if( ( pucValue == NULL ) && ( *pucValue >= ipconfigPACKET_PRIORITIES ) ) + if( ( pucValue == NULL ) || ( *pucValue >= ipconfigPACKET_PRIORITIES ) ) { xReturn = pdFREERTOS_ERRNO_EINVAL; } From 9d8c6a0438653adbb24fe585332d90d8b730f971 Mon Sep 17 00:00:00 2001 From: Christoph Seitz Date: Fri, 16 Jun 2023 12:58:08 +0200 Subject: [PATCH 7/9] Add spellchecking entry. --- .github/lexicon.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/lexicon.txt b/.github/lexicon.txt index 1304e6386..e3f4ff4ec 100755 --- a/.github/lexicon.txt +++ b/.github/lexicon.txt @@ -1345,6 +1345,7 @@ ucpeerwinscalefactor ucpreference ucprefix ucprefixlength +ucpriority ucprotocol ucprotocoladdresslength ucprotocolheadersize From 88cbabc6be38ed426fa011dd868af28a2d9da667 Mon Sep 17 00:00:00 2001 From: Christoph Seitz Date: Fri, 16 Jun 2023 20:19:50 +0200 Subject: [PATCH 8/9] Fix define wording. --- source/FreeRTOS_IP.c | 22 +++++++++++----------- source/include/FreeRTOSIPConfigDefaults.h | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/source/FreeRTOS_IP.c b/source/FreeRTOS_IP.c index 3d041c11a..7967bdc11 100644 --- a/source/FreeRTOS_IP.c +++ b/source/FreeRTOS_IP.c @@ -178,7 +178,7 @@ static eFrameProcessingResult_t prvProcessUDPPacket( NetworkBufferDescriptor_t * /** @brief The queue used to pass events into the IP-task for processing. */ QueueHandle_t xNetworkEventQueue = NULL; -#if ipconfigEVENT_QUEUES > 1 +#if ( ipconfigEVENT_QUEUES > 1 ) QueueHandle_t xNetworkEventQueues[ ipconfigEVENT_QUEUES ] = { 0 }; uint8_t xQueueMapping[ ipconfigPACKET_PRIORITIES ] = ipconfigPACKET_PRIORITY_MAPPING; #endif @@ -276,7 +276,7 @@ static void prvProcessIPEventsAndTimers( void ) /* Wait until there is something to do. If the following call exits * due to a time out rather than a message being received, set a * 'NoEvent' value. */ - #if ipconfigEVENT_QUEUES > 1 + #if ( ipconfigEVENT_QUEUES > 1 ) if( ulTaskNotifyTake( pdFALSE, xNextIPSleep ) == pdFALSE ) { xReceivedEvent.eEventType = eNoEvent; @@ -295,12 +295,12 @@ static void prvProcessIPEventsAndTimers( void ) } } } - #else /* if ipconfigEVENT_QUEUES > 1 */ + #else /* if ( ipconfigEVENT_QUEUES > 1 ) */ if( xQueueReceive( xNetworkEventQueue, ( void * ) &xReceivedEvent, xNextIPSleep ) == pdFALSE ) { xReceivedEvent.eEventType = eNoEvent; } - #endif /* if ipconfigEVENT_QUEUES > 1 */ + #endif /* if ( ipconfigEVENT_QUEUES > 1 ) */ #if ( ipconfigCHECK_IP_QUEUE_SPACE != 0 ) { @@ -970,7 +970,7 @@ BaseType_t FreeRTOS_IPInit_Multi( void ) BaseType_t xReturn = pdFALSE; BaseType_t xAllocSuccessful = pdFALSE; - #if ipconfigEVENT_QUEUES > 1 + #if ( ipconfigEVENT_QUEUES > 1 ) BaseType_t xIndex; #endif @@ -1000,7 +1000,7 @@ BaseType_t FreeRTOS_IPInit_Multi( void ) } xNetworkEventQueue = xNetworkEventQueues[ ipconfigEVENT_QUEUES - 1 ]; - #else /* if ipconfigEVENT_QUEUES > 1 */ + #else /* if ( ipconfigEVENT_QUEUES > 1 ) */ static StaticQueue_t xNetworkEventStaticQueue; static uint8_t ucNetworkEventQueueStorageArea[ ipconfigEVENT_QUEUE_LENGTH * sizeof( IPStackEvent_t ) ]; xNetworkEventQueue = xQueueCreateStatic( ipconfigEVENT_QUEUE_LENGTH, @@ -1008,7 +1008,7 @@ BaseType_t FreeRTOS_IPInit_Multi( void ) ucNetworkEventQueueStorageArea, &xNetworkEventStaticQueue ); xAllocSuccessful = ( xNetworkEventQueue != NULL ); - #endif /* if ipconfigEVENT_QUEUES > 1 */ + #endif /* if ( ipconfigEVENT_QUEUES > 1 ) */ } #else /* if ( configSUPPORT_STATIC_ALLOCATION == 1 ) */ { @@ -1466,7 +1466,7 @@ BaseType_t xSendEventStructToIPTask( const IPStackEvent_t * pxEvent, * IP task is already awake processing other message. */ vIPSetTCPTimerExpiredState( pdTRUE ); - #if ipconfigEVENT_QUEUES > 1 + #if ( ipconfigEVENT_QUEUES > 1 ) if( ulTaskNotifyValueClear( xIPTaskHandle, 0 ) != 0U ) #else if( uxQueueMessagesWaiting( xNetworkEventQueue ) != 0U ) @@ -1489,7 +1489,7 @@ BaseType_t xSendEventStructToIPTask( const IPStackEvent_t * pxEvent, uxUseTimeout = ( TickType_t ) 0; } - #if ipconfigEVENT_QUEUES > 1 + #if ( ipconfigEVENT_QUEUES > 1 ) BaseType_t xQueue = ipconfigEVENT_QUEUES - 1; if( ( pxEvent->eEventType == eNetworkRxEvent ) || ( pxEvent->eEventType == eNetworkTxEvent ) || ( pxEvent->eEventType == eStackTxEvent ) ) @@ -1504,9 +1504,9 @@ BaseType_t xSendEventStructToIPTask( const IPStackEvent_t * pxEvent, { xTaskNotifyGive( xIPTaskHandle ); } - #else /* if ipconfigEVENT_QUEUES > 1 */ + #else /* if ( ipconfigEVENT_QUEUES > 1 ) */ xReturn = xQueueSendToBack( xNetworkEventQueue, pxEvent, uxUseTimeout ); - #endif /* if ipconfigEVENT_QUEUES > 1 */ + #endif /* if ( ipconfigEVENT_QUEUES > 1 ) */ if( xReturn == pdFAIL ) { diff --git a/source/include/FreeRTOSIPConfigDefaults.h b/source/include/FreeRTOSIPConfigDefaults.h index 65235a6dd..b683f68c9 100644 --- a/source/include/FreeRTOSIPConfigDefaults.h +++ b/source/include/FreeRTOSIPConfigDefaults.h @@ -1166,7 +1166,7 @@ #endif #ifndef ipconfigPACKET_PRIORITIES - #if ipconfigEVENT_QUEUES > 1 + #if ( ipconfigEVENT_QUEUES > 1 ) #define ipconfigPACKET_PRIORITIES 8 #else #define ipconfigPACKET_PRIORITIES 1 From be084d1d744776e42fdfd02ee1f37aab0d02ade0 Mon Sep 17 00:00:00 2001 From: Christoph Seitz Date: Fri, 16 Jun 2023 20:20:48 +0200 Subject: [PATCH 9/9] Change priority value to BaseType_t. --- source/FreeRTOS_Sockets.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/FreeRTOS_Sockets.c b/source/FreeRTOS_Sockets.c index fe6fa1dd3..aa3b3fe77 100644 --- a/source/FreeRTOS_Sockets.c +++ b/source/FreeRTOS_Sockets.c @@ -2937,21 +2937,21 @@ BaseType_t FreeRTOS_setsockopt( Socket_t xSocket, #if ( ipconfigPACKET_PRIORITIES > 1 ) case FREERTOS_SO_PRIORITY: { - uint8_t * pucValue = ( uint8_t * ) pvOptionValue; + BaseType_t * pxValue = ( BaseType_t * ) pvOptionValue; - if( ( pucValue == NULL ) || ( *pucValue >= ipconfigPACKET_PRIORITIES ) ) + if( ( pxValue == NULL ) || ( *pxValue >= ipconfigPACKET_PRIORITIES ) ) { xReturn = pdFREERTOS_ERRNO_EINVAL; } else { - pxSocket->ucPriority = *pucValue; + pxSocket->ucPriority = *pxValue; xReturn = pdPASS; } break; } - #endif /* if ipconfigEVENT_QUEUES > 1 */ + #endif /* if ( ipconfigPACKET_PRIORITIES > 1 ) */ default: /* No other options are handled. */