diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index d44477c032..2807ece489 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -34,3 +34,5 @@ If applicable, add screenshots to help explain your problem. Add any other context about the problem here. e.g. code snippet to reproduce the issue. e.g. stack trace, memory dump, debugger log, and many etc. + + diff --git a/.github/ISSUE_TEMPLATE/documentation-issue.md b/.github/ISSUE_TEMPLATE/documentation-issue.md index 062a678b53..3f81276f93 100644 --- a/.github/ISSUE_TEMPLATE/documentation-issue.md +++ b/.github/ISSUE_TEMPLATE/documentation-issue.md @@ -19,3 +19,5 @@ If applicable, please attach screenshot. **Browser** - Browser: [e.g. Chrome] - Version: [e.g. 80.0.3987.132] + + diff --git a/.github/ISSUE_TEMPLATE/general-inquiry.md b/.github/ISSUE_TEMPLATE/general-inquiry.md deleted file mode 100644 index d3b8baf701..0000000000 --- a/.github/ISSUE_TEMPLATE/general-inquiry.md +++ /dev/null @@ -1,12 +0,0 @@ ---- -name: General inquiry -about: Free form communication. -title: "[Inquiry]" -labels: question -assignees: '' - ---- - -We do encourage you to take a look at [FreeRTOS official site](https://www.freertos.org) for general information and [FreeRTOS forum](https://forums.freertos.org) to access our community. - -If still needed, could create a general inquiry report here. diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_ARP.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_ARP.c index 9104a72361..7e7f504923 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_ARP.c +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_ARP.c @@ -1,5 +1,5 @@ /* - * FreeRTOS+TCP V2.2.1 + * FreeRTOS+TCP V2.2.2 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of @@ -96,7 +96,7 @@ uint32_t ulTargetProtocolAddress, ulSenderProtocolAddress; pxARPHeader = &( pxARPFrame->xARPHeader ); /* The field ulSenderProtocolAddress is badly aligned, copy byte-by-byte. */ - ( void ) memcpy( &( ulSenderProtocolAddress ), pxARPHeader->ucSenderProtocolAddress, sizeof( ulSenderProtocolAddress ) ); + ( void ) memcpy( ( void * ) ( &( ulSenderProtocolAddress ) ), ( const void * ) ( pxARPHeader->ucSenderProtocolAddress ), sizeof( ulSenderProtocolAddress ) ); /* The field ulTargetProtocolAddress is well-aligned, a 32-bits copy. */ ulTargetProtocolAddress = pxARPHeader->ulTargetProtocolAddress; @@ -135,8 +135,8 @@ uint32_t ulTargetProtocolAddress, ulSenderProtocolAddress; ( void ) memcpy( pxARPHeader->xTargetHardwareAddress.ucBytes, pxARPHeader->xSenderHardwareAddress.ucBytes, sizeof( MACAddress_t ) ); pxARPHeader->ulTargetProtocolAddress = ulSenderProtocolAddress; } - ( void ) memcpy( pxARPHeader->xSenderHardwareAddress.ucBytes, ipLOCAL_MAC_ADDRESS, sizeof( MACAddress_t ) ); - ( void ) memcpy( pxARPHeader->ucSenderProtocolAddress, ipLOCAL_IP_ADDRESS_POINTER, sizeof( pxARPHeader->ucSenderProtocolAddress ) ); + ( void ) memcpy( ( void * ) ( pxARPHeader->xSenderHardwareAddress.ucBytes ), ( const void * ) ( ipLOCAL_MAC_ADDRESS ), sizeof( MACAddress_t ) ); + ( void ) memcpy( ( void * ) ( pxARPHeader->ucSenderProtocolAddress ), ( const void * ) ( ipLOCAL_IP_ADDRESS_POINTER ), sizeof( pxARPHeader->ucSenderProtocolAddress ) ); eReturn = eReturnEthernetFrame; } @@ -656,7 +656,7 @@ ARPPacket_t *pxARPPacket; configASSERT( pxNetworkBuffer != NULL ); configASSERT( pxNetworkBuffer->xDataLength >= sizeof(ARPPacket_t) ); - pxARPPacket = ipPOINTER_CAST( ARPPacket_t *, pxNetworkBuffer->pucEthernetBuffer ); + pxARPPacket = ipCAST_PTR_TO_TYPE_PTR( ARPPacket_t, pxNetworkBuffer->pucEthernetBuffer ); /* memcpy the const part of the header information into the correct location in the packet. This copies: @@ -669,11 +669,11 @@ ARPPacket_t *pxARPPacket; xARPHeader.usOperation; xARPHeader.xTargetHardwareAddress; */ - ( void ) memcpy( pxARPPacket, xDefaultPartARPPacketHeader, sizeof( xDefaultPartARPPacketHeader ) ); - ( void ) memcpy( pxARPPacket->xEthernetHeader.xSourceAddress.ucBytes , ipLOCAL_MAC_ADDRESS, ( size_t ) ipMAC_ADDRESS_LENGTH_BYTES ); - ( void ) memcpy( pxARPPacket->xARPHeader.xSenderHardwareAddress.ucBytes, ipLOCAL_MAC_ADDRESS, ( size_t ) ipMAC_ADDRESS_LENGTH_BYTES ); + ( void ) memcpy( ( void * ) pxARPPacket, ( const void * ) xDefaultPartARPPacketHeader, sizeof( xDefaultPartARPPacketHeader ) ); + ( void ) memcpy( ( void * ) ( pxARPPacket->xEthernetHeader.xSourceAddress.ucBytes ) , ( const void * ) ipLOCAL_MAC_ADDRESS, ( size_t ) ipMAC_ADDRESS_LENGTH_BYTES ); + ( void ) memcpy( ( void * ) ( pxARPPacket->xARPHeader.xSenderHardwareAddress.ucBytes ), ( const void * ) ipLOCAL_MAC_ADDRESS, ( size_t ) ipMAC_ADDRESS_LENGTH_BYTES ); - ( void ) memcpy( pxARPPacket->xARPHeader.ucSenderProtocolAddress, ipLOCAL_IP_ADDRESS_POINTER, sizeof( pxARPPacket->xARPHeader.ucSenderProtocolAddress ) ); + ( void ) memcpy( ( void * ) ( pxARPPacket->xARPHeader.ucSenderProtocolAddress ), ( const void * ) ipLOCAL_IP_ADDRESS_POINTER, sizeof( pxARPPacket->xARPHeader.ucSenderProtocolAddress ) ); pxARPPacket->xARPHeader.ulTargetProtocolAddress = pxNetworkBuffer->ulIPAddress; pxNetworkBuffer->xDataLength = sizeof( ARPPacket_t ); @@ -693,7 +693,7 @@ BaseType_t xCheckLoopback( NetworkBufferDescriptor_t * const pxDescriptor, BaseT { BaseType_t xResult = pdFALSE; NetworkBufferDescriptor_t * pxUseDescriptor = pxDescriptor; -const IPPacket_t *pxIPPacket = ipPOINTER_CAST( IPPacket_t *, pxUseDescriptor->pucEthernetBuffer ); +const IPPacket_t *pxIPPacket = ipCAST_PTR_TO_TYPE_PTR( IPPacket_t, pxUseDescriptor->pucEthernetBuffer ); /* This function will check if the target IP-address belongs to this device. * If so, the packet will be passed to the IP-stack, who will answer it. diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_DHCP.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_DHCP.c index e12db9162c..c12557e7a4 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_DHCP.c +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_DHCP.c @@ -1,5 +1,5 @@ /* - * FreeRTOS+TCP V2.2.1 + * FreeRTOS+TCP V2.2.2 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of @@ -154,6 +154,16 @@ struct xDHCPMessage_IPv4 #include "pack_struct_end.h" typedef struct xDHCPMessage_IPv4 DHCPMessage_IPv4_t; +static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( DHCPMessage_IPv4_t ) +{ + return ( DHCPMessage_IPv4_t *)pvArgument; +} +static portINLINE ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( DHCPMessage_IPv4_t ) +{ + return ( const DHCPMessage_IPv4_t *) pvArgument; +} + + /* The UDP socket used for all incoming and outgoing DHCP traffic. */ _static Socket_t xDHCPSocket; @@ -639,7 +649,7 @@ const uint32_t ulMandatoryOptions = 2UL; /* DHCP server address, and the correct if( lBytes > 0 ) { /* Map a DHCP structure onto the received data. */ - pxDHCPMessage = ipPOINTER_CAST( const DHCPMessage_IPv4_t *, pucUDPPayload ); + pxDHCPMessage = ipCAST_CONST_PTR_TO_CONST_TYPE_PTR( DHCPMessage_IPv4_t, pucUDPPayload ); /* Sanity check. */ if( lBytes < ( int32_t ) sizeof( DHCPMessage_IPv4_t ) ) @@ -716,8 +726,8 @@ const uint32_t ulMandatoryOptions = 2UL; /* DHCP server address, and the correct just get it once here and use later. */ if( uxLength >= sizeof( ulParameter ) ) { - ( void ) memcpy( &( ulParameter ), - &( pucByte[ uxIndex ] ), + ( void ) memcpy( ( void * ) ( &( ulParameter ) ), + ( const void * ) ( &( pucByte[ uxIndex ] ) ), ( size_t ) sizeof( ulParameter ) ); /* 'uxIndex' will be increased at the end of this loop. */ } @@ -887,7 +897,7 @@ uint8_t *pucUDPPayloadBuffer; /* Leave space for the UPD header. */ pucUDPPayloadBuffer = &( pxNetworkBuffer->pucEthernetBuffer[ ipUDP_PAYLOAD_OFFSET_IPv4 ] ); - pxDHCPMessage = ipPOINTER_CAST( DHCPMessage_IPv4_t *, pucUDPPayloadBuffer ); + pxDHCPMessage = ipCAST_PTR_TO_TYPE_PTR( DHCPMessage_IPv4_t, pucUDPPayloadBuffer ); /* Most fields need to be zero. */ ( void ) memset( pxDHCPMessage, 0x00, sizeof( DHCPMessage_IPv4_t ) ); @@ -921,7 +931,7 @@ uint8_t *pucUDPPayloadBuffer; pucPtr = &( pucUDPPayloadBuffer[ dhcpFIRST_OPTION_BYTE_OFFSET + ( *pxOptionsArraySize - 1U ) ] ); pucPtr[ 0U ] = dhcpIPv4_DNS_HOSTNAME_OPTIONS_CODE; pucPtr[ 1U ] = ( uint8_t ) uxNameLength; - ( void ) memcpy( &( pucPtr[ 2U ] ), pucHostName, uxNameLength ); + ( void ) memcpy( ( void * ) ( &( pucPtr[ 2U ] ) ), ( const void * ) pucHostName, uxNameLength ); pucPtr[ 2U + uxNameLength ] = ( uint8_t ) dhcpOPTION_END_BYTE; *pxOptionsArraySize += ( size_t ) ( 2U + uxNameLength ); } @@ -962,13 +972,13 @@ size_t uxOptionsLength = sizeof( ucDHCPRequestOptions ); &( uxOptionsLength ) ); /* Copy in the IP address being requested. */ - ( void ) memcpy( &( pucUDPPayloadBuffer[ dhcpFIRST_OPTION_BYTE_OFFSET + dhcpREQUESTED_IP_ADDRESS_OFFSET ] ), - &( EP_DHCPData.ulOfferedIPAddress ), + ( void ) memcpy( ( void * ) ( &( pucUDPPayloadBuffer[ dhcpFIRST_OPTION_BYTE_OFFSET + dhcpREQUESTED_IP_ADDRESS_OFFSET ] ) ), + ( const void * ) ( &( EP_DHCPData.ulOfferedIPAddress ) ), sizeof( EP_DHCPData.ulOfferedIPAddress ) ); /* Copy in the address of the DHCP server being used. */ - ( void ) memcpy( &( pucUDPPayloadBuffer[ dhcpFIRST_OPTION_BYTE_OFFSET + dhcpDHCP_SERVER_IP_ADDRESS_OFFSET ] ), - &( EP_DHCPData.ulDHCPServerAddress ), + ( void ) memcpy( ( void * ) ( &( pucUDPPayloadBuffer[ dhcpFIRST_OPTION_BYTE_OFFSET + dhcpDHCP_SERVER_IP_ADDRESS_OFFSET ] ) ), + ( const void * ) ( &( EP_DHCPData.ulDHCPServerAddress ) ), sizeof( EP_DHCPData.ulDHCPServerAddress ) ); FreeRTOS_debug_printf( ( "vDHCPProcess: reply %lxip\n", FreeRTOS_ntohl( EP_DHCPData.ulOfferedIPAddress ) ) ); diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_DNS.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_DNS.c index c63ba537a2..c4d7040104 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_DNS.c +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_DNS.c @@ -1,5 +1,5 @@ /* - * FreeRTOS+TCP V2.2.1 + * FreeRTOS+TCP V2.2.2 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of @@ -250,6 +250,15 @@ struct xDNSMessage #include "pack_struct_end.h" typedef struct xDNSMessage DNSMessage_t; +static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( DNSMessage_t ) +{ + return ( DNSMessage_t *)pvArgument; +} +static portINLINE ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( DNSMessage_t ) +{ + return ( const DNSMessage_t *) pvArgument; +} + /* A DNS query consists of a header, as described in 'struct xDNSMessage' It is followed by 1 or more queries, each one consisting of a name and a tail, with two fields: type and class @@ -263,6 +272,11 @@ struct xDNSTail #include "pack_struct_end.h" typedef struct xDNSTail DNSTail_t; +static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( DNSTail_t ) +{ + return ( DNSTail_t * ) pvArgument; +} + /* DNS answer record header. */ #include "pack_struct_start.h" struct xDNSAnswerRecord @@ -275,6 +289,11 @@ struct xDNSAnswerRecord #include "pack_struct_end.h" typedef struct xDNSAnswerRecord DNSAnswerRecord_t; +static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( DNSAnswerRecord_t ) +{ + return ( DNSAnswerRecord_t * ) pvArgument; +} + #if( ipconfigUSE_LLMNR == 1 ) #include "pack_struct_start.h" @@ -291,6 +310,12 @@ typedef struct xDNSAnswerRecord DNSAnswerRecord_t; #include "pack_struct_end.h" typedef struct xLLMNRAnswer LLMNRAnswer_t; + static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( LLMNRAnswer_t ) + { + return ( LLMNRAnswer_t *)pvArgument; + } + + #endif /* ipconfigUSE_LLMNR == 1 */ #if( ipconfigUSE_NBNS == 1 ) @@ -326,6 +351,11 @@ typedef struct xDNSAnswerRecord DNSAnswerRecord_t; #include "pack_struct_end.h" typedef struct xNBNSAnswer NBNSAnswer_t; + static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( NBNSAnswer_t ) + { + return ( NBNSAnswer_t *)pvArgument; + } + #endif /* ipconfigUSE_NBNS == 1 */ /*-----------------------------------------------------------*/ @@ -353,6 +383,11 @@ typedef struct xDNSAnswerRecord DNSAnswerRecord_t; char pcName[ 1 ]; } DNSCallback_t; + static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( DNSCallback_t ) + { + return ( DNSCallback_t *)pvArgument; + } + static List_t xCallbackList; /* Define FreeRTOS_gethostbyname() as a normal blocking call. */ @@ -377,7 +412,7 @@ typedef struct xDNSAnswerRecord DNSAnswerRecord_t; void vDNSCheckCallBack( void *pvSearchID ) { const ListItem_t * pxIterator; - const ListItem_t * xEnd = ipPOINTER_CAST( const ListItem_t *, listGET_END_MARKER( &xCallbackList ) ); + const ListItem_t * xEnd = listGET_END_MARKER( &xCallbackList ); vTaskSuspendAll(); { @@ -385,7 +420,7 @@ typedef struct xDNSAnswerRecord DNSAnswerRecord_t; pxIterator != xEnd; ) { - DNSCallback_t *pxCallback = ipPOINTER_CAST( DNSCallback_t *, listGET_LIST_ITEM_OWNER( pxIterator ) ); + DNSCallback_t *pxCallback = ipCAST_PTR_TO_TYPE_PTR( DNSCallback_t, listGET_LIST_ITEM_OWNER( pxIterator ) ); /* Move to the next item because we might remove this item */ pxIterator = ( const ListItem_t * ) listGET_NEXT( pxIterator ); if( ( pvSearchID != NULL ) && ( pvSearchID == pxCallback->pvSearchID ) ) @@ -430,7 +465,7 @@ typedef struct xDNSAnswerRecord DNSAnswerRecord_t; TickType_t uxIdentifier ) { size_t lLength = strlen( pcHostName ); - DNSCallback_t *pxCallback = ipPOINTER_CAST( DNSCallback_t *, pvPortMalloc( sizeof( *pxCallback ) + lLength ) ); + DNSCallback_t *pxCallback = ipCAST_PTR_TO_TYPE_PTR( DNSCallback_t, pvPortMalloc( sizeof( *pxCallback ) + lLength ) ); /* Translate from ms to number of clock ticks. */ uxTimeout /= portTICK_PERIOD_MS; @@ -448,7 +483,7 @@ typedef struct xDNSAnswerRecord DNSAnswerRecord_t; pxCallback->pvSearchID = pvSearchID; pxCallback->uxRemaningTime = uxTimeout; vTaskSetTimeOutState( &pxCallback->uxTimeoutState ); - listSET_LIST_ITEM_OWNER( &( pxCallback->xListItem ), ipPOINTER_CAST( void *, pxCallback ) ); + listSET_LIST_ITEM_OWNER( &( pxCallback->xListItem ), ( void *) pxCallback ); listSET_LIST_ITEM_VALUE( &( pxCallback->xListItem ), uxIdentifier ); vTaskSuspendAll(); { @@ -467,7 +502,7 @@ typedef struct xDNSAnswerRecord DNSAnswerRecord_t; { BaseType_t xResult = pdFALSE; const ListItem_t * pxIterator; - const ListItem_t * xEnd = ipPOINTER_CAST( const ListItem_t *, listGET_END_MARKER( &xCallbackList ) ); + const ListItem_t * xEnd = listGET_END_MARKER( &xCallbackList ); vTaskSuspendAll(); { @@ -477,7 +512,7 @@ typedef struct xDNSAnswerRecord DNSAnswerRecord_t; { if( listGET_LIST_ITEM_VALUE( pxIterator ) == uxIdentifier ) { - DNSCallback_t *pxCallback = ipPOINTER_CAST( DNSCallback_t *, listGET_LIST_ITEM_OWNER( pxIterator ) ); + DNSCallback_t *pxCallback = ipCAST_PTR_TO_TYPE_PTR( DNSCallback_t, listGET_LIST_ITEM_OWNER( pxIterator ) ); pxCallback->pCallbackFunction( pcName, pxCallback->pvSearchID, ulIPAddress ); ( void ) uxListRemove( &pxCallback->xListItem ); @@ -549,8 +584,8 @@ TickType_t uxIdentifier = 0U; else { FreeRTOS_printf( ( "prvPrepareLookup: name is too long ( %lu > %lu )\n", - ( unsigned long ) xLength, - ( unsigned long ) ipconfigDNS_CACHE_NAME_LENGTH ) ); + ( uint32_t ) xLength, + ( uint32_t ) ipconfigDNS_CACHE_NAME_LENGTH ) ); } } } @@ -709,7 +744,7 @@ TickType_t uxWriteTimeOut_ticks = ipconfigDNS_SEND_BLOCK_TIME_TICKS; if( bHasDot == pdFALSE ) { /* Use LLMNR addressing. */ - ( ipPOINTER_CAST( DNSMessage_t *, pucUDPPayloadBuffer ) )->usFlags = 0; + ( ipCAST_PTR_TO_TYPE_PTR( DNSMessage_t, pucUDPPayloadBuffer ) )->usFlags = 0; xAddress.sin_addr = ipLLMNR_IP_ADDR; /* Is in network byte order. */ xAddress.sin_port = ipLLMNR_PORT; xAddress.sin_port = FreeRTOS_ntohs( xAddress.sin_port ); @@ -732,7 +767,7 @@ TickType_t uxWriteTimeOut_ticks = ipconfigDNS_SEND_BLOCK_TIME_TICKS; if( lBytes > 0 ) { BaseType_t xExpected; - const DNSMessage_t *pxDNSMessageHeader = ipPOINTER_CAST( DNSMessage_t *, pucReceiveBuffer ); + const DNSMessage_t *pxDNSMessageHeader = ipCAST_CONST_PTR_TO_CONST_TYPE_PTR( DNSMessage_t, pucReceiveBuffer ); /* See if the identifiers match. */ if( uxIdentifier == ( TickType_t ) pxDNSMessageHeader->usIdentifier ) @@ -811,11 +846,11 @@ static const DNSMessage_t xDefaultPartDNSHeader = /* Copy in the const part of the header. Intentionally using different * pointers with memcpy() to put the information in to correct place. */ - ( void ) memcpy( pucUDPPayloadBuffer, &( xDefaultPartDNSHeader ), sizeof( xDefaultPartDNSHeader ) ); + ( void ) memcpy( ( void * ) pucUDPPayloadBuffer, ( const void * ) ( &( xDefaultPartDNSHeader ) ), sizeof( xDefaultPartDNSHeader ) ); /* Write in a unique identifier. Cast the Payload Buffer to DNSMessage_t * to easily access fields of the DNS Message. */ - pxDNSMessageHeader = ipPOINTER_CAST( DNSMessage_t *, pucUDPPayloadBuffer ); + pxDNSMessageHeader = ipCAST_PTR_TO_TYPE_PTR( DNSMessage_t, pucUDPPayloadBuffer ); pxDNSMessageHeader->usIdentifier = ( uint16_t ) uxIdentifier; /* Create the resource record at the end of the header. First @@ -856,7 +891,7 @@ static const DNSMessage_t xDefaultPartDNSHeader = /* Finish off the record. Cast the record onto DNSTail_t stucture to easily * access the fields of the DNS Message. */ - pxTail = ipPOINTER_CAST(DNSTail_t *, &( pucByte[ 1 ] ) ); + pxTail = ipCAST_PTR_TO_TYPE_PTR( DNSTail_t, &( pucByte[ 1 ] ) ); #if defined( _lint ) || defined( __COVERITY__ ) ( void ) pxTail; @@ -1051,7 +1086,7 @@ size_t uxPayloadSize; if( uxPayloadSize >= sizeof( DNSMessage_t ) ) { pxDNSMessageHeader = - ipPOINTER_CAST( DNSMessage_t *, &( pxNetworkBuffer->pucEthernetBuffer [ sizeof( UDPPacket_t ) ] ) ); + ipCAST_PTR_TO_TYPE_PTR( DNSMessage_t, pxNetworkBuffer->pucEthernetBuffer ); /* The parameter pdFALSE indicates that the reply was not expected. */ ( void ) prvParseDNSReply( ( uint8_t * ) pxDNSMessageHeader, @@ -1069,7 +1104,7 @@ size_t uxPayloadSize; uint32_t ulNBNSHandlePacket( NetworkBufferDescriptor_t * pxNetworkBuffer ) { - UDPPacket_t *pxUDPPacket = ipPOINTER_CAST( UDPPacket_t *, pxNetworkBuffer->pucEthernetBuffer ); + UDPPacket_t *pxUDPPacket = ipCAST_PTR_TO_TYPE_PTR( UDPPacket_t, pxNetworkBuffer->pucEthernetBuffer ); uint8_t *pucUDPPayloadBuffer = &( pxNetworkBuffer->pucEthernetBuffer[ sizeof( *pxUDPPacket ) ] ); prvTreatNBNS( pucUDPPayloadBuffer, @@ -1119,7 +1154,7 @@ BaseType_t xReturn = pdTRUE; /* Parse the DNS message header. Map the byte stream onto a structure * for easier access. */ - pxDNSMessageHeader = ipPOINTER_CAST( DNSMessage_t *, pucUDPPayloadBuffer ); + pxDNSMessageHeader = ipCAST_PTR_TO_TYPE_PTR( DNSMessage_t, pucUDPPayloadBuffer ); /* Introduce a do {} while (0) to allow the use of breaks. */ do @@ -1217,10 +1252,16 @@ BaseType_t xReturn = pdTRUE; const uint16_t usCount = ( uint16_t ) ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY; uint16_t usNumARecordsStored = 0; - for( x = 0U; ( x < pxDNSMessageHeader->usAnswers ) && ( usNumARecordsStored < usCount ); x++ ) + for( x = 0U; x < pxDNSMessageHeader->usAnswers; x++ ) { BaseType_t xDoAccept; + if( usNumARecordsStored >= usCount ) + { + /* Only count ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY number of records. */ + break; + } + uxResult = prvSkipNameField( pucByte, uxSourceBytesRemaining ); @@ -1266,15 +1307,15 @@ BaseType_t xReturn = pdTRUE; /* This is the required record type and is of sufficient size. */ /* Mapping pucByte to a DNSAnswerRecord allows easy access of the * fields of the structure. */ - pxDNSAnswerRecord = ipPOINTER_CAST( DNSAnswerRecord_t *, pucByte ); + pxDNSAnswerRecord = ipCAST_PTR_TO_TYPE_PTR( DNSAnswerRecord_t, pucByte ); /* Sanity check the data length of an IPv4 answer. */ if( FreeRTOS_ntohs( pxDNSAnswerRecord->usDataLength ) == ( uint16_t ) sizeof( uint32_t ) ) { /* Copy the IP address out of the record. Using different pointers * to copy only the portion we want is intentional here. */ - ( void ) memcpy( &( ulIPAddress ), - &( pucByte[ sizeof( DNSAnswerRecord_t ) ] ), + ( void ) memcpy( ( void * ) ( &( ulIPAddress ) ), + ( const void * ) ( &( pucByte[ sizeof( DNSAnswerRecord_t ) ] ) ), sizeof( uint32_t ) ); #if( ipconfigDNS_USE_CALLBACKS == 1 ) @@ -1319,7 +1360,7 @@ BaseType_t xReturn = pdTRUE; /* It's not an A record, so skip it. Get the header location and then jump over the header. */ /* Cast the response to DNSAnswerRecord for easy access to fields of the DNS response. */ - pxDNSAnswerRecord = ipPOINTER_CAST( DNSAnswerRecord_t *, pucByte ); + pxDNSAnswerRecord = ipCAST_PTR_TO_TYPE_PTR( DNSAnswerRecord_t, pucByte ); pucByte = &( pucByte[ sizeof( DNSAnswerRecord_t ) ] ); uxSourceBytesRemaining -= sizeof( DNSAnswerRecord_t ); @@ -1380,7 +1421,7 @@ BaseType_t xReturn = pdTRUE; pucByte = &( pucNewBuffer[ xOffset1 ] ); pcRequestedName = ( char * ) &( pucNewBuffer[ xOffset2 ] ); - pxDNSMessageHeader = ipPOINTER_CAST( DNSMessage_t *, pucNewBuffer ); + pxDNSMessageHeader = ipCAST_PTR_TO_TYPE_PTR( DNSMessage_t, pucNewBuffer ); } else { @@ -1392,7 +1433,7 @@ BaseType_t xReturn = pdTRUE; /* The test on 'pucNewBuffer' is only to satisfy lint. */ if( ( pxNetworkBuffer != NULL ) && ( pucNewBuffer != NULL ) ) { - pxAnswer = ipPOINTER_CAST( LLMNRAnswer_t *, pucByte ); + pxAnswer = ipCAST_PTR_TO_TYPE_PTR( LLMNRAnswer_t, pucByte ); /* We leave 'usIdentifier' and 'usQuestions' untouched */ #ifndef _lint @@ -1568,7 +1609,7 @@ BaseType_t xReturn = pdTRUE; /* Should not occur: pucUDPPayloadBuffer is part of a xNetworkBufferDescriptor */ if( pxNetworkBuffer != NULL ) { - pxMessage = ipPOINTER_CAST( DNSMessage_t *, pucUDPPayloadBuffer ); + pxMessage = ipCAST_PTR_TO_TYPE_PTR( DNSMessage_t, pucUDPPayloadBuffer ); /* As the fields in the structures are not word-aligned, we have to copy the values byte-by-byte using macro's vSetField16() and vSetField32() */ @@ -1581,8 +1622,8 @@ BaseType_t xReturn = pdTRUE; #else ( void ) pxMessage; #endif - - pxAnswer = ipPOINTER_CAST( NBNSAnswer_t *, &( pucUDPPayloadBuffer[ offsetof( NBNSRequest_t, usType ) ] ) ); + + pxAnswer = ipCAST_PTR_TO_TYPE_PTR( NBNSAnswer_t, &( pucUDPPayloadBuffer[ offsetof( NBNSRequest_t, usType ) ] ) ); #ifndef _lint vSetField16( pxAnswer, NBNSAnswer_t, usType, usType ); /* Type */ @@ -1615,7 +1656,7 @@ BaseType_t xReturn; /* This must be the first time this function has been called. Create the socket. */ xSocket = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_DGRAM, FREERTOS_IPPROTO_UDP ); - if( ( xSocket == FREERTOS_INVALID_SOCKET ) || ( xSocket == NULL ) ) + if( prvSocketValid( xSocket ) != pdTRUE ) { /* There was an error, return NULL. */ xSocket = NULL; @@ -1652,7 +1693,7 @@ BaseType_t xReturn; UDPHeader_t *pxUDPHeader; size_t uxDataLength; - pxUDPPacket = ipPOINTER_CAST( UDPPacket_t *, pxNetworkBuffer->pucEthernetBuffer ); + pxUDPPacket = ipCAST_PTR_TO_TYPE_PTR( UDPPacket_t, pxNetworkBuffer->pucEthernetBuffer ); pxIPHeader = &pxUDPPacket->xIPHeader; pxUDPHeader = &pxUDPPacket->xUDPHeader; /* HT: started using defines like 'ipSIZE_OF_xxx' */ @@ -1700,7 +1741,7 @@ BaseType_t xReturn; { BaseType_t x; BaseType_t xFound = pdFALSE; - uint32_t ulCurrentTimeSeconds = ( xTaskGetTickCount() / portTICK_PERIOD_MS ) / 1000U; + uint32_t ulCurrentTimeSeconds = ( xTaskGetTickCount() / portTICK_PERIOD_MS ) / 1000UL; uint32_t ulIPAddressIndex = 0; static BaseType_t xFreeEntry = 0; diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_IP.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_IP.c index bfd2a9c156..0b89fdea64 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_IP.c +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_IP.c @@ -1,5 +1,5 @@ /* - * FreeRTOS+TCP V2.2.1 + * FreeRTOS+TCP V2.2.2 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of @@ -158,6 +158,16 @@ typedef union _xUnionPtr uint8_t *u8ptr; } xUnionPtr; + +static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( NetworkBufferDescriptor_t ) +{ + return ( NetworkBufferDescriptor_t *)pvArgument; +} +static portINLINE ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( NetworkBufferDescriptor_t ) +{ + return ( const NetworkBufferDescriptor_t *) pvArgument; +} + /*-----------------------------------------------------------*/ /* @@ -362,7 +372,7 @@ struct freertos_sockaddr xAddress; /* 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, ipPOINTER_CAST( void *, &xReceivedEvent ), xNextIPSleep ) == pdFALSE ) + if ( xQueueReceive( xNetworkEventQueue, ( void *) &xReceivedEvent, xNextIPSleep ) == pdFALSE ) { xReceivedEvent.eEventType = eNoEvent; } @@ -395,14 +405,14 @@ struct freertos_sockaddr xAddress; case eNetworkRxEvent: /* The network hardware driver has received a new packet. A pointer to the received buffer is located in the pvData member - of the received event structure. */ - prvHandleEthernetPacket( ipPOINTER_CAST( NetworkBufferDescriptor_t *, xReceivedEvent.pvData ) ); + of the received event structure. */ + prvHandleEthernetPacket( ipCAST_PTR_TO_TYPE_PTR( NetworkBufferDescriptor_t, xReceivedEvent.pvData ) ); break; case eNetworkTxEvent: /* Send a network packet. The ownership will be transferred to the driver, which will release it after delivery. */ - ( void ) xNetworkInterfaceOutput( ipPOINTER_CAST( NetworkBufferDescriptor_t *, xReceivedEvent.pvData ), pdTRUE ); + ( void ) xNetworkInterfaceOutput( ipCAST_PTR_TO_TYPE_PTR( NetworkBufferDescriptor_t, xReceivedEvent.pvData ), pdTRUE ); break; case eARPTimerEvent : @@ -416,7 +426,7 @@ struct freertos_sockaddr xAddress; usLocalPort. vSocketBind() will actually bind the socket and the API will unblock as soon as the eSOCKET_BOUND event is triggered. */ - pxSocket = ipPOINTER_CAST( FreeRTOS_Socket_t *, xReceivedEvent.pvData ); + pxSocket = ipCAST_PTR_TO_TYPE_PTR( FreeRTOS_Socket_t, xReceivedEvent.pvData ); xAddress.sin_addr = 0U; /* For the moment. */ xAddress.sin_port = FreeRTOS_ntohs( pxSocket->usLocalPort ); pxSocket->usLocalPort = 0U; @@ -434,14 +444,14 @@ struct freertos_sockaddr xAddress; IP-task to actually close a socket. This is handled in vSocketClose(). As the socket gets closed, there is no way to report back to the API, so the API won't wait for the result */ - ( void ) vSocketClose( ipPOINTER_CAST( FreeRTOS_Socket_t *, xReceivedEvent.pvData ) ); + ( void ) vSocketClose( ipCAST_PTR_TO_TYPE_PTR( FreeRTOS_Socket_t, xReceivedEvent.pvData ) ); break; case eStackTxEvent : /* The network stack has generated a packet to send. A pointer to the generated buffer is located in the pvData member of the received event structure. */ - vProcessGeneratedUDPPacket( ipPOINTER_CAST( NetworkBufferDescriptor_t *, xReceivedEvent.pvData ) ); + vProcessGeneratedUDPPacket( ipCAST_PTR_TO_TYPE_PTR( NetworkBufferDescriptor_t, xReceivedEvent.pvData ) ); break; case eDHCPEvent: @@ -462,13 +472,13 @@ struct freertos_sockaddr xAddress; { #if( ipconfigSELECT_USES_NOTIFY != 0 ) { - SocketSelectMessage_t *pxMessage = ipPOINTER_CAST( SocketSelectMessage_t *, xReceivedEvent.pvData ); + SocketSelectMessage_t *pxMessage = ipCAST_PTR_TO_TYPE_PTR( SocketSelectMessage_t, xReceivedEvent.pvData ); vSocketSelect( pxMessage->pxSocketSet ); ( void ) xTaskNotifyGive( pxMessage->xTaskhandle ); } #else - { - vSocketSelect( ipPOINTER_CAST( SocketSelect_t *, xReceivedEvent.pvData ) ); + { + vSocketSelect( ipCAST_PTR_TO_TYPE_PTR( SocketSelect_t, xReceivedEvent.pvData ) ); } #endif /* ( ipconfigSELECT_USES_NOTIFY != 0 ) */ } @@ -501,7 +511,7 @@ struct freertos_sockaddr xAddress; received a new connection. */ #if( ipconfigUSE_TCP == 1 ) { - pxSocket = ipPOINTER_CAST( FreeRTOS_Socket_t *, xReceivedEvent.pvData ); + pxSocket = ipCAST_PTR_TO_TYPE_PTR( FreeRTOS_Socket_t, xReceivedEvent.pvData ); if( xTCPCheckNewClient( pxSocket ) != pdFALSE ) { @@ -944,7 +954,7 @@ NetworkBufferDescriptor_t *pxResult; /* The following statement may trigger a: warning: cast increases required alignment of target type [-Wcast-align]. It has been confirmed though that the alignment is suitable. */ - pxResult = * ( ipPOINTER_CAST( NetworkBufferDescriptor_t **, pucBuffer ) ); + pxResult = * ( ( const NetworkBufferDescriptor_t **) pucBuffer ); } else { @@ -1153,11 +1163,10 @@ void FreeRTOS_SetAddressConfiguration( const uint32_t *pulIPAddress, } if( ( uxGetNumberOfFreeNetworkBuffers() >= 3U ) && ( uxNumberOfBytesToSend >= 1U ) && ( xEnoughSpace != pdFALSE ) ) { - pxEthernetHeader = ipPOINTER_CAST( EthernetHeader_t *, pxNetworkBuffer->pucEthernetBuffer ); + pxEthernetHeader = ipCAST_PTR_TO_TYPE_PTR( EthernetHeader_t, pxNetworkBuffer->pucEthernetBuffer ); pxEthernetHeader->usFrameType = ipIPv4_FRAME_TYPE; - - pxICMPHeader = ipPOINTER_CAST( ICMPHeader_t *, &( pxNetworkBuffer->pucEthernetBuffer[ ipIP_PAYLOAD_OFFSET ] ) ); + pxICMPHeader = ipCAST_PTR_TO_TYPE_PTR( ICMPHeader_t, &( pxNetworkBuffer->pucEthernetBuffer[ ipIP_PAYLOAD_OFFSET ] ) ); usSequenceNumber++; /* Fill in the basic header information. */ @@ -1289,7 +1298,7 @@ eFrameProcessingResult_t eReturn; const EthernetHeader_t *pxEthernetHeader; /* Map the buffer onto Ethernet Header struct for easy access to fields. */ - pxEthernetHeader = ipPOINTER_CAST( const EthernetHeader_t *, pucEthernetBuffer ); + pxEthernetHeader = ipCAST_CONST_PTR_TO_CONST_TYPE_PTR( EthernetHeader_t, pucEthernetBuffer ); if( memcmp( ipLOCAL_MAC_ADDRESS, pxEthernetHeader->xDestinationAddress.ucBytes, sizeof( MACAddress_t ) ) == 0 ) { @@ -1430,7 +1439,7 @@ eFrameProcessingResult_t eReturned = eReleaseBuffer; eReturned = ipCONSIDER_FRAME_FOR_PROCESSING( pxNetworkBuffer->pucEthernetBuffer ); /* Map the buffer onto the Ethernet Header struct for easy access to the fields. */ - pxEthernetHeader = ipPOINTER_CAST( const EthernetHeader_t *, pxNetworkBuffer->pucEthernetBuffer ); + pxEthernetHeader = ipCAST_CONST_PTR_TO_CONST_TYPE_PTR( EthernetHeader_t, pxNetworkBuffer->pucEthernetBuffer ); /* The condition "eReturned == eProcessBuffer" must be true. */ #if( ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES == 0 ) @@ -1444,7 +1453,7 @@ eFrameProcessingResult_t eReturned = eReleaseBuffer; /* The Ethernet frame contains an ARP packet. */ if( pxNetworkBuffer->xDataLength >= sizeof( ARPPacket_t ) ) { - eReturned = eARPProcessPacket( ipPOINTER_CAST( ARPPacket_t *, pxNetworkBuffer->pucEthernetBuffer ) ); + eReturned = eARPProcessPacket( ipCAST_PTR_TO_TYPE_PTR( ARPPacket_t, pxNetworkBuffer->pucEthernetBuffer ) ); } else { @@ -1456,7 +1465,7 @@ eFrameProcessingResult_t eReturned = eReleaseBuffer; /* The Ethernet frame contains an IP packet. */ if( pxNetworkBuffer->xDataLength >= sizeof( IPPacket_t ) ) { - eReturned = prvProcessIPPacket( ipPOINTER_CAST( IPPacket_t *, pxNetworkBuffer->pucEthernetBuffer ), pxNetworkBuffer ); + eReturned = prvProcessIPPacket( ipCAST_PTR_TO_TYPE_PTR( IPPacket_t, pxNetworkBuffer->pucEthernetBuffer ), pxNetworkBuffer ); } else { @@ -1643,7 +1652,7 @@ eFrameProcessingResult_t eReturn = eProcessBuffer; const uint16_t *pusChecksum; /* pxProtPack will point to the offset were the protocols begin. */ - pxProtPack = ipPOINTER_CAST( ProtocolPacket_t *, &( pxNetworkBuffer->pucEthernetBuffer[ uxHeaderLength - ipSIZE_OF_IPv4_HEADER ] ) ); + pxProtPack = ipCAST_PTR_TO_TYPE_PTR( ProtocolPacket_t, &( pxNetworkBuffer->pucEthernetBuffer[ uxHeaderLength - ipSIZE_OF_IPv4_HEADER ] ) ); pusChecksum = ( const uint16_t * ) ( &( pxProtPack->xUDPPacket.xUDPHeader.usChecksum ) ); if( *pusChecksum == ( uint16_t ) 0U ) { @@ -1762,7 +1771,7 @@ uint8_t ucProtocol; { /* Map the buffer onto a ICMP-Packet struct to easily access the * fields of ICMP packet. */ - ICMPPacket_t *pxICMPPacket = ipPOINTER_CAST( ICMPPacket_t *, pxNetworkBuffer->pucEthernetBuffer ); + ICMPPacket_t *pxICMPPacket = ipCAST_PTR_TO_TYPE_PTR( ICMPPacket_t, pxNetworkBuffer->pucEthernetBuffer ); if( pxIPHeader->ulDestinationIPAddress == *ipLOCAL_IP_ADDRESS_POINTER ) { eReturn = prvProcessICMPPacket( pxICMPPacket ); @@ -1782,7 +1791,7 @@ uint8_t ucProtocol; /* Map the buffer onto a UDP-Packet struct to easily access the * fields of UDP packet. */ - const UDPPacket_t *pxUDPPacket = ipPOINTER_CAST( const UDPPacket_t *, pxNetworkBuffer->pucEthernetBuffer ); + const UDPPacket_t *pxUDPPacket = ipCAST_CONST_PTR_TO_CONST_TYPE_PTR( UDPPacket_t, pxNetworkBuffer->pucEthernetBuffer ); uint16_t usLength; /* Note the header values required prior to the checksum @@ -1991,7 +2000,7 @@ uint8_t ucProtocol; size_t uxLength; const IPPacket_t * pxIPPacket; UBaseType_t uxIPHeaderLength; - ProtocolPacket_t *pxProtPack; + const ProtocolPacket_t *pxProtPack; uint8_t ucProtocol; uint16_t usLength; uint16_t ucVersionHeaderLength; @@ -2010,7 +2019,7 @@ uint8_t ucProtocol; /* Map the buffer onto a IP-Packet struct to easily access the * fields of the IP packet. */ - pxIPPacket = ipPOINTER_CAST( const IPPacket_t *, pucEthernetBuffer ); + pxIPPacket = ipCAST_CONST_PTR_TO_CONST_TYPE_PTR( IPPacket_t, pucEthernetBuffer ); ucVersionHeaderLength = pxIPPacket->xIPHeader.ucVersionHeaderLength; /* Test if the length of the IP-header is between 20 and 60 bytes, @@ -2049,7 +2058,7 @@ uint8_t ucProtocol; of this calculation. */ /* Map the Buffer onto the Protocol Packet struct for easy access to the * struct fields. */ - pxProtPack = ipPOINTER_CAST( ProtocolPacket_t *, &( pucEthernetBuffer[ uxIPHeaderLength - ipSIZE_OF_IPv4_HEADER ] ) ); + pxProtPack = ipCAST_CONST_PTR_TO_CONST_TYPE_PTR( ProtocolPacket_t, &( pucEthernetBuffer[ uxIPHeaderLength - ipSIZE_OF_IPv4_HEADER ] ) ); /* Switch on the Layer 3/4 protocol. */ if( ucProtocol == ( uint8_t ) ipPROTOCOL_UDP ) @@ -2096,6 +2105,11 @@ uint8_t ucProtocol; if( xResult != pdPASS ) { FreeRTOS_printf( ( "xCheckSizeFields: location %ld\n", xLocation ) ); + + /* If FreeRTOS_printf is not defined, not using xLocation will be a violation of MISRA + * rule 2.2 as the value assigned to xLocation will not be used. The below statement uses + * the variable without modifying the logic of the source. */ + ( void ) xLocation; } return xResult; @@ -2109,7 +2123,7 @@ uint32_t ulLength; uint16_t usChecksum, *pusChecksum; const IPPacket_t * pxIPPacket; UBaseType_t uxIPHeaderLength; -ProtocolPacket_t *pxProtPack; +const ProtocolPacket_t *pxProtPack; uint8_t ucProtocol; #if( ipconfigHAS_DEBUG_PRINTF != 0 ) const char *pcType; @@ -2133,7 +2147,7 @@ BaseType_t location = 0; } /* Parse the packet length. */ - pxIPPacket = ipPOINTER_CAST( const IPPacket_t *, pucEthernetBuffer ); + pxIPPacket = ipCAST_CONST_PTR_TO_CONST_TYPE_PTR( IPPacket_t, pucEthernetBuffer ); /* Per https://tools.ietf.org/html/rfc791, the four-bit Internet Header Length field contains the length of the internet header in 32-bit words. */ @@ -2165,7 +2179,7 @@ BaseType_t location = 0; and IP headers incorrectly aligned. However, either way, the "third" protocol (Layer 3 or 4) header will be aligned, which is the convenience of this calculation. */ - pxProtPack = ipPOINTER_CAST( ProtocolPacket_t *, &( pucEthernetBuffer[ uxIPHeaderLength - ipSIZE_OF_IPv4_HEADER ] ) ); + pxProtPack = ipCAST_CONST_PTR_TO_CONST_TYPE_PTR( ProtocolPacket_t, &( pucEthernetBuffer[ uxIPHeaderLength - ipSIZE_OF_IPv4_HEADER ] ) ); /* Switch on the Layer 3/4 protocol. */ if( ucProtocol == ( uint8_t ) ipPROTOCOL_UDP ) @@ -2301,7 +2315,7 @@ BaseType_t location = 0; /* ICMP/IGMP do not have a pseudo header for CRC-calculation. */ usChecksum = ( uint16_t ) ( ~usGenerateChecksum( 0U, - ( uint8_t * ) &( pxProtPack->xTCPPacket.xTCPHeader ), ( size_t ) ulLength ) ); + ( const uint8_t * ) &( pxProtPack->xTCPPacket.xTCPHeader ), ( size_t ) ulLength ) ); } else { @@ -2370,6 +2384,11 @@ BaseType_t location = 0; ( usChecksum == ipINVALID_LENGTH ) ) { FreeRTOS_printf( ( "CRC error: %04x location %ld\n", usChecksum, location ) ); + + /* If FreeRTOS_printf is not defined, not using 'location' will be a violation of MISRA + * rule 2.2 as the value assigned to 'location' will not be used. The below statement uses + * the variable without modifying the logic of the source. */ + ( void ) location; } return usChecksum; @@ -2578,11 +2597,11 @@ EthernetHeader_t *pxEthernetHeader; #endif { /* Map the Buffer to Ethernet Header struct for easy access to fields. */ - pxEthernetHeader = ipPOINTER_CAST( EthernetHeader_t *, pxNetworkBuffer->pucEthernetBuffer ); + pxEthernetHeader = ipCAST_PTR_TO_TYPE_PTR( EthernetHeader_t, pxNetworkBuffer->pucEthernetBuffer ); /* Swap source and destination MAC addresses. */ - ( void ) memcpy( &( pxEthernetHeader->xDestinationAddress ), &( pxEthernetHeader->xSourceAddress ), sizeof( pxEthernetHeader->xDestinationAddress ) ); - ( void ) memcpy( &( pxEthernetHeader->xSourceAddress) , ipLOCAL_MAC_ADDRESS, ( size_t ) ipMAC_ADDRESS_LENGTH_BYTES ); + ( void ) memcpy( ( void * ) &( pxEthernetHeader->xDestinationAddress ), ( const void * ) ( &( pxEthernetHeader->xSourceAddress ) ), sizeof( pxEthernetHeader->xDestinationAddress ) ); + ( void ) memcpy( ( void * ) &( pxEthernetHeader->xSourceAddress) , ( const void * ) ipLOCAL_MAC_ADDRESS, ( size_t ) ipMAC_ADDRESS_LENGTH_BYTES ); /* Send! */ ( void ) xNetworkInterfaceOutput( pxNetworkBuffer, xReleaseAfterSend ); diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_Sockets.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_Sockets.c index 25d1dbd755..9a85bb3be3 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_Sockets.c +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_Sockets.c @@ -1,5 +1,5 @@ /* - * FreeRTOS+TCP V2.2.1 + * FreeRTOS+TCP V2.2.2 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of @@ -87,7 +87,28 @@ range 1024-65535" excluding those already in use (inbound or outbound). */ #define sock80_PERCENT 80U #define sock100_PERCENT 100U +#if( ipconfigUSE_CALLBACKS != 0 ) + static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( F_TCP_UDP_Handler_t ) + { + return ( F_TCP_UDP_Handler_t *)pvArgument; + } + static portINLINE ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( F_TCP_UDP_Handler_t ) + { + return ( const F_TCP_UDP_Handler_t *) pvArgument; + } +#endif + +static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( NetworkBufferDescriptor_t ) +{ + return ( NetworkBufferDescriptor_t *)pvArgument; +} + + +static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( StreamBuffer_t ) +{ + return ( StreamBuffer_t *)pvArgument; +} /*-----------------------------------------------------------*/ /* @@ -280,7 +301,7 @@ FreeRTOS_Socket_t const *pxSocket = NULL; Socket_t FreeRTOS_socket( BaseType_t xDomain, BaseType_t xType, BaseType_t xProtocol ) { FreeRTOS_Socket_t *pxSocket; -size_t uxSocketSize; +size_t uxSocketSize = 0; EventGroupHandle_t xEventGroup; Socket_t xReturn; @@ -290,11 +311,11 @@ Socket_t xReturn; } else { - /* Allocate the structure that will hold the socket information. The - size depends on the type of socket: UDP sockets need less space. A + /* Allocate the structure that will hold the socket information. The + size depends on the type of socket: UDP sockets need less space. A define 'pvPortMallocSocket' will used to allocate the necessary space. By default it points to the FreeRTOS function 'pvPortMalloc()'. */ - pxSocket = ipPOINTER_CAST( FreeRTOS_Socket_t *, pvPortMallocSocket( uxSocketSize ) ); + pxSocket = ipCAST_PTR_TO_TYPE_PTR( FreeRTOS_Socket_t, pvPortMallocSocket( uxSocketSize ) ); if( pxSocket == NULL ) { @@ -394,7 +415,7 @@ Socket_t xReturn; { SocketSelect_t *pxSocketSet; - pxSocketSet = ipPOINTER_CAST( SocketSelect_t *, pvPortMalloc( sizeof( *pxSocketSet ) ) ); + pxSocketSet = ipCAST_PTR_TO_TYPE_PTR( SocketSelect_t, pvPortMalloc( sizeof( *pxSocketSet ) ) ); if( pxSocketSet != NULL ) { @@ -639,12 +660,14 @@ int32_t FreeRTOS_recvfrom( Socket_t xSocket, void *pvBuffer, size_t uxBufferLeng { BaseType_t lPacketCount; NetworkBufferDescriptor_t *pxNetworkBuffer; +const void *pvCopySource; FreeRTOS_Socket_t const * pxSocket = xSocket; TickType_t xRemainingTime = ( TickType_t ) 0; /* Obsolete assignment, but some compilers output a warning if its not done. */ BaseType_t xTimed = pdFALSE; TimeOut_t xTimeOut; int32_t lReturn; EventBits_t xEventBits = ( EventBits_t ) 0; +size_t uxPayloadLength; if( prvValidSocket( pxSocket, FREERTOS_IPPROTO_UDP, pdTRUE ) == pdFALSE ) { @@ -733,7 +756,7 @@ EventBits_t xEventBits = ( EventBits_t ) 0; taskENTER_CRITICAL(); { /* The owner of the list item is the network buffer. */ - pxNetworkBuffer = ipPOINTER_CAST( NetworkBufferDescriptor_t *, listGET_OWNER_OF_HEAD_ENTRY( &( pxSocket->u.xUDP.xWaitingPacketsList ) ) ); + pxNetworkBuffer = ipCAST_PTR_TO_TYPE_PTR( NetworkBufferDescriptor_t, listGET_OWNER_OF_HEAD_ENTRY( &( pxSocket->u.xUDP.xWaitingPacketsList ) ) ); if( ( ( UBaseType_t ) xFlags & ( UBaseType_t ) FREERTOS_MSG_PEEK ) == 0U ) { @@ -748,7 +771,8 @@ EventBits_t xEventBits = ( EventBits_t ) 0; calculated at the total packet size minus the headers. The validity of `xDataLength` prvProcessIPPacket has been confirmed in 'prvProcessIPPacket()'. */ - lReturn = ( int32_t ) ( pxNetworkBuffer->xDataLength - sizeof( UDPPacket_t ) ); + uxPayloadLength = pxNetworkBuffer->xDataLength - sizeof( UDPPacket_t ); + lReturn = ( int32_t ) uxPayloadLength; if( pxSourceAddress != NULL ) { @@ -768,7 +792,8 @@ EventBits_t xEventBits = ( EventBits_t ) 0; /* Copy the received data into the provided buffer, then release the network buffer. */ - ( void ) memcpy( pvBuffer, &( pxNetworkBuffer->pucEthernetBuffer[ ipUDP_PAYLOAD_OFFSET_IPv4 ] ), ( size_t )lReturn ); + pvCopySource = ( const void *) &pxNetworkBuffer->pucEthernetBuffer[ ipUDP_PAYLOAD_OFFSET_IPv4 ]; + ( void ) memcpy( pvBuffer, pvCopySource, ( size_t )lReturn ); if( ( ( UBaseType_t ) xFlags & ( UBaseType_t ) FREERTOS_MSG_PEEK ) == 0U ) { @@ -806,6 +831,7 @@ EventBits_t xEventBits = ( EventBits_t ) 0; int32_t FreeRTOS_sendto( Socket_t xSocket, const void *pvBuffer, size_t uxTotalDataLength, BaseType_t xFlags, const struct freertos_sockaddr *pxDestinationAddress, socklen_t xDestinationAddressLength ) { NetworkBufferDescriptor_t *pxNetworkBuffer; +void *pvCopyDest; IPStackEvent_t xStackTxEvent = { eStackTxEvent, NULL }; TimeOut_t xTimeOut; TickType_t xTicksToWait; @@ -862,7 +888,8 @@ const size_t uxPayloadOffset = ( size_t ) ipUDP_PAYLOAD_OFFSET_IPv4; if( pxNetworkBuffer != NULL ) { - ( void ) memcpy( &( pxNetworkBuffer->pucEthernetBuffer[ uxPayloadOffset ] ), pvBuffer, uxTotalDataLength ); + pvCopyDest = ( void * ) &pxNetworkBuffer->pucEthernetBuffer[ uxPayloadOffset ]; + ( void ) memcpy( pvCopyDest, pvBuffer, uxTotalDataLength ); if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdTRUE ) { @@ -876,7 +903,7 @@ const size_t uxPayloadOffset = ( size_t ) ipUDP_PAYLOAD_OFFSET_IPv4; /* When zero copy is used, pvBuffer is a pointer to the payload of a buffer that has already been obtained from the stack. Obtain the network buffer pointer from the buffer. */ - pxNetworkBuffer = pxUDPPayloadBuffer_to_NetworkBuffer( ( void * ) pvBuffer ); + pxNetworkBuffer = pxUDPPayloadBuffer_to_NetworkBuffer( pvBuffer ); } if( pxNetworkBuffer != NULL ) @@ -1273,7 +1300,7 @@ NetworkBufferDescriptor_t *pxNetworkBuffer; { while( listCURRENT_LIST_LENGTH( &( pxSocket->u.xUDP.xWaitingPacketsList ) ) > 0U ) { - pxNetworkBuffer = ipPOINTER_CAST( NetworkBufferDescriptor_t *, listGET_OWNER_OF_HEAD_ENTRY( &( pxSocket->u.xUDP.xWaitingPacketsList ) ) ); + pxNetworkBuffer = ipCAST_PTR_TO_TYPE_PTR( NetworkBufferDescriptor_t, listGET_OWNER_OF_HEAD_ENTRY( &( pxSocket->u.xUDP.xWaitingPacketsList ) ) ); ( void ) uxListRemove( &( pxNetworkBuffer->xBufferListItem ) ); vReleaseNetworkBufferAndDescriptor( pxNetworkBuffer ); } @@ -1317,7 +1344,7 @@ NetworkBufferDescriptor_t *pxNetworkBuffer; static void prvTCPSetSocketCount( FreeRTOS_Socket_t const * pxSocketToDelete ) { const ListItem_t *pxIterator; - const ListItem_t *pxEnd = ipPOINTER_CAST( const ListItem_t *, listGET_END_MARKER( &xBoundTCPSocketsList ) ); + const ListItem_t *pxEnd = listGET_END_MARKER( &xBoundTCPSocketsList ); FreeRTOS_Socket_t *pxOtherSocket; uint16_t usLocalPort = pxSocketToDelete->usLocalPort; @@ -1325,7 +1352,7 @@ NetworkBufferDescriptor_t *pxNetworkBuffer; pxIterator != pxEnd; pxIterator = listGET_NEXT( pxIterator ) ) { - pxOtherSocket = ipPOINTER_CAST( FreeRTOS_Socket_t *, listGET_LIST_ITEM_OWNER( pxIterator ) ); + pxOtherSocket = ipCAST_PTR_TO_TYPE_PTR( FreeRTOS_Socket_t, listGET_LIST_ITEM_OWNER( pxIterator ) ); if( ( pxOtherSocket->u.xTCP.ucTCPState == ( uint8_t ) eTCP_LISTEN ) && ( pxOtherSocket->usLocalPort == usLocalPort ) && ( pxOtherSocket->u.xTCP.usChildCount != 0U ) ) @@ -1409,12 +1436,12 @@ FreeRTOS_Socket_t *pxSocket; { case FREERTOS_SO_RCVTIMEO : /* Receive time out. */ - pxSocket->xReceiveBlockTime = *( ipPOINTER_CAST( const TickType_t *, pvOptionValue ) ); + pxSocket->xReceiveBlockTime = *( ( const TickType_t *) pvOptionValue ); xReturn = 0; break; case FREERTOS_SO_SNDTIMEO : - pxSocket->xSendBlockTime = *( ipPOINTER_CAST( const TickType_t *, pvOptionValue ) ); + pxSocket->xSendBlockTime = *( ( const TickType_t *) pvOptionValue ); if( pxSocket->ucProtocol == ( uint8_t ) FREERTOS_IPPROTO_UDP ) { /* The send time out is capped for the reason stated in the @@ -1498,20 +1525,20 @@ FreeRTOS_Socket_t *pxSocket; { #if ipconfigUSE_TCP == 1 case FREERTOS_SO_TCP_CONN_HANDLER: - pxSocket->u.xTCP.pxHandleConnected = ipPOINTER_CAST( const F_TCP_UDP_Handler_t *, pvOptionValue )->pxOnTCPConnected; + pxSocket->u.xTCP.pxHandleConnected = ipCAST_CONST_PTR_TO_CONST_TYPE_PTR( F_TCP_UDP_Handler_t, pvOptionValue )->pxOnTCPConnected; break; case FREERTOS_SO_TCP_RECV_HANDLER: - pxSocket->u.xTCP.pxHandleReceive = ipPOINTER_CAST( const F_TCP_UDP_Handler_t *, pvOptionValue )->pxOnTCPReceive; + pxSocket->u.xTCP.pxHandleReceive = ipCAST_CONST_PTR_TO_CONST_TYPE_PTR( F_TCP_UDP_Handler_t, pvOptionValue )->pxOnTCPReceive; break; case FREERTOS_SO_TCP_SENT_HANDLER: - pxSocket->u.xTCP.pxHandleSent = ipPOINTER_CAST( const F_TCP_UDP_Handler_t *, pvOptionValue )->pxOnTCPSent; + pxSocket->u.xTCP.pxHandleSent = ipCAST_CONST_PTR_TO_CONST_TYPE_PTR( F_TCP_UDP_Handler_t, pvOptionValue )->pxOnTCPSent; break; #endif /* ipconfigUSE_TCP */ case FREERTOS_SO_UDP_RECV_HANDLER: - pxSocket->u.xUDP.pxHandleReceive = ipPOINTER_CAST( const F_TCP_UDP_Handler_t *, pvOptionValue )->pxOnUDPReceive; + pxSocket->u.xUDP.pxHandleReceive = ipCAST_CONST_PTR_TO_CONST_TYPE_PTR( F_TCP_UDP_Handler_t, pvOptionValue )->pxOnUDPReceive; break; case FREERTOS_SO_UDP_SENT_HANDLER: - pxSocket->u.xUDP.pxHandleSent = ipPOINTER_CAST( const F_TCP_UDP_Handler_t *, pvOptionValue )->pxOnUDPSent; + pxSocket->u.xUDP.pxHandleSent = ipCAST_CONST_PTR_TO_CONST_TYPE_PTR( F_TCP_UDP_Handler_t, pvOptionValue )->pxOnUDPSent; break; default: /* Should it throw an error here? */ @@ -1640,7 +1667,7 @@ FreeRTOS_Socket_t *pxSocket; { break; /* will return -pdFREERTOS_ERRNO_EINVAL */ } - if( *( ipPOINTER_CAST( const BaseType_t *, pvOptionValue ) ) != 0 ) + if( *( ( const BaseType_t * ) pvOptionValue ) != 0 ) { pxSocket->u.xTCP.bits.bReuseSocket = pdTRUE; } @@ -1659,7 +1686,7 @@ FreeRTOS_Socket_t *pxSocket; break; /* will return -pdFREERTOS_ERRNO_EINVAL */ } - if( *( ipPOINTER_CAST( const BaseType_t *, pvOptionValue ) ) != 0 ) + if( *( ( const BaseType_t * ) pvOptionValue ) != 0 ) { pxSocket->u.xTCP.bits.bCloseAfterSend = pdTRUE; } @@ -1678,7 +1705,7 @@ FreeRTOS_Socket_t *pxSocket; break; /* will return -pdFREERTOS_ERRNO_EINVAL */ } - if( *( ipPOINTER_CAST( const BaseType_t *, pvOptionValue ) ) != 0 ) + if( *( ( const BaseType_t *) pvOptionValue ) != 0 ) { pxSocket->u.xTCP.xTCPWindow.u.bits.bSendFullSize = pdTRUE; } @@ -1704,7 +1731,7 @@ FreeRTOS_Socket_t *pxSocket; { break; /* will return -pdFREERTOS_ERRNO_EINVAL */ } - if( *( ipPOINTER_CAST( const BaseType_t *, pvOptionValue ) ) != 0 ) + if( *( ( const BaseType_t * ) pvOptionValue ) != 0 ) { pxSocket->u.xTCP.bits.bRxStopped = pdTRUE; } @@ -1803,7 +1830,7 @@ const ListItem_t * pxResult = NULL; if( ( xIPIsNetworkTaskReady() != pdFALSE ) && ( pxList != NULL ) ) { const ListItem_t *pxIterator; - const ListItem_t *pxEnd = ipPOINTER_CAST( const ListItem_t*, listGET_END_MARKER( pxList ) ); + const ListItem_t *pxEnd = listGET_END_MARKER( pxList ); for( pxIterator = listGET_NEXT( pxEnd ); pxIterator != pxEnd; pxIterator = listGET_NEXT( pxIterator ) ) @@ -1835,7 +1862,7 @@ FreeRTOS_Socket_t *pxSocket = NULL; if( pxListItem != NULL ) { /* The owner of the list item is the socket itself. */ - pxSocket = ipPOINTER_CAST( FreeRTOS_Socket_t *, listGET_LIST_ITEM_OWNER( pxListItem ) ); + pxSocket = ipCAST_PTR_TO_TYPE_PTR( FreeRTOS_Socket_t, listGET_LIST_ITEM_OWNER( pxListItem ) ); configASSERT( pxSocket != NULL ); } return pxSocket; @@ -1858,7 +1885,7 @@ const socklen_t uxSize = 16; { uint8_t pucDigits[ sockDIGIT_COUNT ]; uint8_t ucValue = pucAddress[ uxNibble ]; - socklen_t uxSource = sockDIGIT_COUNT - 1; + socklen_t uxSource = ( socklen_t ) sockDIGIT_COUNT - ( socklen_t ) 1U; socklen_t uxNeeded; for( ;; ) @@ -1874,7 +1901,7 @@ const socklen_t uxSize = 16; pucDigits[ 0 ] = ucValue; /* Skip leading zeros. */ - for( uxSource = 0; uxSource < ( socklen_t ) ( sockDIGIT_COUNT - 1 ); uxSource++ ) + for( uxSource = 0; uxSource < ( ( socklen_t ) sockDIGIT_COUNT - ( socklen_t ) 1U ); uxSource++ ) { if( pucDigits[ uxSource ] != 0U ) { @@ -1950,6 +1977,7 @@ const char *pcResult; const char *FreeRTOS_inet_ntop4( const void *pvSource, char *pcDestination, socklen_t uxSize ) { uint32_t ulIPAddress; +void *pvCopyDest; const char *pcReturn; if( uxSize < 16U ) @@ -1959,7 +1987,8 @@ const char *pcReturn; } else { - ( void ) memcpy( &( ulIPAddress ), pvSource, sizeof( ulIPAddress ) ); + pvCopyDest = ( void * ) &ulIPAddress; + ( void ) memcpy( pvCopyDest, pvSource, sizeof( ulIPAddress ) ); ( void ) FreeRTOS_inet_ntoa( ulIPAddress, pcDestination ); pcReturn = pcDestination; } @@ -1975,6 +2004,7 @@ uint32_t ulReturn = 0UL, ulValue; UBaseType_t uxOctetNumber; BaseType_t xResult = pdPASS; const char *pcIPAddress = pcSource; +const void *pvCopySource; /* Translate "192.168.2.100" to a 32-bit number, network-endian. */ for( uxOctetNumber = 0U; uxOctetNumber < socketMAX_IP_ADDRESS_OCTETS; uxOctetNumber++ ) @@ -2055,7 +2085,8 @@ const char *pcIPAddress = pcSource; { ulReturn = 0UL; } - ( void ) memcpy( pvDestination, &( ulReturn ), sizeof( ulReturn ) ); + pvCopySource = ( const void * ) &ulReturn; + ( void ) memcpy( pvDestination, pvCopySource, sizeof( ulReturn ) ); return xResult; } @@ -3058,7 +3089,7 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) TickType_t xNow = xTaskGetTickCount(); static TickType_t xLastTime = 0U; TickType_t xDelta = xNow - xLastTime; - const ListItem_t* pxEnd = ipPOINTER_CAST( const ListItem_t *, listGET_END_MARKER( &xBoundTCPSocketsList ) ); + const ListItem_t* pxEnd = listGET_END_MARKER( &xBoundTCPSocketsList ); const ListItem_t *pxIterator = ( const ListItem_t * ) listGET_HEAD_ENTRY( &xBoundTCPSocketsList ); xLastTime = xNow; @@ -3070,7 +3101,7 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) while( pxIterator != pxEnd ) { - pxSocket = ipPOINTER_CAST( FreeRTOS_Socket_t *, listGET_LIST_ITEM_OWNER( pxIterator ) ); + pxSocket = ipCAST_PTR_TO_TYPE_PTR( FreeRTOS_Socket_t, listGET_LIST_ITEM_OWNER( pxIterator ) ); pxIterator = ( ListItem_t * ) listGET_NEXT( pxIterator ); /* Sockets with 'tmout == 0' do not need any regular attention. */ @@ -3142,7 +3173,7 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) { const ListItem_t *pxIterator; FreeRTOS_Socket_t *pxResult = NULL, *pxListenSocket = NULL; - const ListItem_t *pxEnd = ipPOINTER_CAST( const ListItem_t *, listGET_END_MARKER( &xBoundTCPSocketsList ) ); + const ListItem_t *pxEnd = listGET_END_MARKER( &xBoundTCPSocketsList ); /* Parameter not yet supported. */ ( void ) ulLocalIP; @@ -3151,7 +3182,7 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) pxIterator != pxEnd; pxIterator = listGET_NEXT( pxIterator ) ) { - FreeRTOS_Socket_t *pxSocket = ipPOINTER_CAST( FreeRTOS_Socket_t *, listGET_LIST_ITEM_OWNER( pxIterator ) ); + FreeRTOS_Socket_t *pxSocket = ipCAST_PTR_TO_TYPE_PTR( FreeRTOS_Socket_t, listGET_LIST_ITEM_OWNER( pxIterator ) ); if( pxSocket->usLocalPort == ( uint16_t ) uxLocalPort ) { @@ -3245,7 +3276,7 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) uxSize = ( sizeof( *pxBuffer ) + uxLength ) - sizeof( pxBuffer->ucArray ); - pxBuffer = ipPOINTER_CAST( StreamBuffer_t *, pvPortMallocLarge( uxSize ) ); + pxBuffer = ipCAST_PTR_TO_TYPE_PTR( StreamBuffer_t, pvPortMallocLarge( uxSize ) ); if( pxBuffer == NULL ) { @@ -3701,14 +3732,14 @@ BaseType_t FreeRTOS_udp_rx_size( Socket_t xSocket ) } else { - const ListItem_t *pxEndTCP = ipPOINTER_CAST( const ListItem_t *, listGET_END_MARKER( &xBoundTCPSocketsList ) ); - const ListItem_t *pxEndUDP = ipPOINTER_CAST( const ListItem_t *, listGET_END_MARKER( &xBoundUDPSocketsList ) ); + const ListItem_t *pxEndTCP = listGET_END_MARKER( &xBoundTCPSocketsList ); + const ListItem_t *pxEndUDP = listGET_END_MARKER( &xBoundUDPSocketsList ); FreeRTOS_printf( ( "Prot Port IP-Remote : Port R/T Status Alive tmout Child\n" ) ); for( pxIterator = listGET_HEAD_ENTRY( &xBoundTCPSocketsList ); pxIterator != pxEndTCP; pxIterator = listGET_NEXT( pxIterator ) ) { - const FreeRTOS_Socket_t *pxSocket = ipPOINTER_CAST( const FreeRTOS_Socket_t *, listGET_LIST_ITEM_OWNER( pxIterator ) ); + const FreeRTOS_Socket_t *pxSocket = ipCAST_CONST_PTR_TO_CONST_TYPE_PTR( FreeRTOS_Socket_t, listGET_LIST_ITEM_OWNER( pxIterator ) ); #if( ipconfigTCP_KEEP_ALIVE == 1 ) TickType_t age = xTaskGetTickCount() - pxSocket->u.xTCP.xLastAliveTime; #else @@ -3782,19 +3813,19 @@ BaseType_t FreeRTOS_udp_rx_size( Socket_t xSocket ) const ListItem_t *pxEnd; if( xRound == 0 ) { - pxEnd = ipPOINTER_CAST( const ListItem_t *, listGET_END_MARKER( &xBoundUDPSocketsList ) ); + pxEnd = listGET_END_MARKER( &xBoundUDPSocketsList ); } #if ipconfigUSE_TCP == 1 else { - pxEnd = ipPOINTER_CAST( const ListItem_t *, listGET_END_MARKER( &xBoundTCPSocketsList ) ); + pxEnd = listGET_END_MARKER( &xBoundTCPSocketsList ); } #endif /* ipconfigUSE_TCP == 1 */ for( pxIterator = listGET_NEXT( pxEnd ); pxIterator != pxEnd; pxIterator = listGET_NEXT( pxIterator ) ) { - FreeRTOS_Socket_t *pxSocket = ipPOINTER_CAST( FreeRTOS_Socket_t *, listGET_LIST_ITEM_OWNER( pxIterator ) ); + FreeRTOS_Socket_t *pxSocket = ipCAST_PTR_TO_TYPE_PTR( FreeRTOS_Socket_t, listGET_LIST_ITEM_OWNER( pxIterator ) ); if( pxSocket->pxSocketSet != pxSocketSet ) { /* Socket does not belong to this select group. */ diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_Stream_Buffer.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_Stream_Buffer.c index 5501da30ac..97931a0d7d 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_Stream_Buffer.c +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_Stream_Buffer.c @@ -1,5 +1,5 @@ /* - * FreeRTOS+TCP V2.2.1 + * FreeRTOS+TCP V2.2.2 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_TCP_IP.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_TCP_IP.c index 0ce010d429..4de4170be7 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_TCP_IP.c +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_TCP_IP.c @@ -1,5 +1,5 @@ /* - * FreeRTOS+TCP V2.2.1 + * FreeRTOS+TCP V2.2.2 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of @@ -581,7 +581,7 @@ BaseType_t xReady = pdFALSE; static int32_t prvTCPSendPacket( FreeRTOS_Socket_t *pxSocket ) { int32_t lResult = 0; -UBaseType_t uxOptionsLength; +UBaseType_t uxOptionsLength, uxIntermediateResult = 0; NetworkBufferDescriptor_t *pxNetworkBuffer; if( pxSocket->u.xTCP.ucTCPState != ( uint8_t ) eCONNECT_SYN ) @@ -618,7 +618,7 @@ NetworkBufferDescriptor_t *pxNetworkBuffer; now, proceed to send the packet with the SYN flag. prvTCPPrepareConnect() prepares 'xPacket' and returns pdTRUE if the Ethernet address of the peer or the gateway is found. */ - pxProtocolHeaders = ipPOINTER_CAST( ProtocolHeaders_t *, &( pxSocket->u.xTCP.xPacket.u.ucLastPacket[ ipSIZE_OF_ETH_HEADER + uxHeaderSize ] ) ); + pxProtocolHeaders = ipCAST_PTR_TO_TYPE_PTR( ProtocolHeaders_t, &( pxSocket->u.xTCP.xPacket.u.ucLastPacket[ ipSIZE_OF_ETH_HEADER + uxHeaderSize ] ) ); /* About to send a SYN packet. Call prvSetSynAckOptions() to set the proper options: The size of MSS and whether SACK's are @@ -626,7 +626,8 @@ NetworkBufferDescriptor_t *pxNetworkBuffer; uxOptionsLength = prvSetSynAckOptions( pxSocket, &( pxProtocolHeaders->xTCPHeader ) ); /* Return the number of bytes to be sent. */ - lResult = ipNUMERIC_CAST( BaseType_t, uxIPHeaderSizeSocket( pxSocket ) + ipSIZE_OF_TCP_HEADER + uxOptionsLength ); + uxIntermediateResult = uxIPHeaderSizeSocket( pxSocket ) + ipSIZE_OF_TCP_HEADER + uxOptionsLength; + lResult = ( int32_t ) uxIntermediateResult; /* Set the TCP offset field: ipSIZE_OF_TCP_HEADER equals 20 and uxOptionsLength is always a multiple of 4. The complete expression @@ -743,7 +744,7 @@ NetworkBufferDescriptor_t xTempBuffer; #endif { /* Map the ethernet buffer onto a TCPPacket_t struct for easy access to the fields. */ - pxTCPPacket = ipPOINTER_CAST( TCPPacket_t *, pxNetworkBuffer->pucEthernetBuffer ); + pxTCPPacket = ipCAST_PTR_TO_TYPE_PTR( TCPPacket_t, pxNetworkBuffer->pucEthernetBuffer ); pxIPHeader = &pxTCPPacket->xIPHeader; pxEthernetHeader = &pxTCPPacket->xEthernetHeader; @@ -907,12 +908,12 @@ NetworkBufferDescriptor_t xTempBuffer; #endif /* Fill in the destination MAC addresses. */ - ( void ) memcpy( &( pxEthernetHeader->xDestinationAddress ), - &( pxEthernetHeader->xSourceAddress ), + ( void ) memcpy( ( void * ) ( &( pxEthernetHeader->xDestinationAddress ) ), + ( const void * ) ( &( pxEthernetHeader->xSourceAddress ) ), sizeof( pxEthernetHeader->xDestinationAddress ) ); /* The source MAC addresses is fixed to 'ipLOCAL_MAC_ADDRESS'. */ - ( void ) memcpy( &( pxEthernetHeader->xSourceAddress ), ipLOCAL_MAC_ADDRESS, ( size_t ) ipMAC_ADDRESS_LENGTH_BYTES ); + ( void ) memcpy( ( void * ) ( &( pxEthernetHeader->xSourceAddress ) ), ( const void * ) ipLOCAL_MAC_ADDRESS, ( size_t ) ipMAC_ADDRESS_LENGTH_BYTES ); #if defined( ipconfigETHERNET_MINIMUM_PACKET_BYTES ) { @@ -938,7 +939,7 @@ NetworkBufferDescriptor_t xTempBuffer; containing the packet header. */ vFlip_16( pxTCPPacket->xTCPHeader.usSourcePort, pxTCPPacket->xTCPHeader.usDestinationPort); pxTCPPacket->xIPHeader.ulSourceIPAddress = pxTCPPacket->xIPHeader.ulDestinationIPAddress; - ( void ) memcpy( pxEthernetHeader->xSourceAddress.ucBytes, pxEthernetHeader->xDestinationAddress.ucBytes, ( size_t ) ipMAC_ADDRESS_LENGTH_BYTES ); + ( void ) memcpy( ( void * ) ( pxEthernetHeader->xSourceAddress.ucBytes ), ( const void * ) ( pxEthernetHeader->xDestinationAddress.ucBytes ), ( size_t ) ipMAC_ADDRESS_LENGTH_BYTES ); } else { @@ -1051,7 +1052,7 @@ uint32_t ulInitialSequenceNumber = 0; /* The MAC-address of the peer (or gateway) has been found, * now prepare the initial TCP packet and some fields in the socket. Map * the buffer onto the TCPPacket_t struct to easily access it's field. */ - pxTCPPacket = ipPOINTER_CAST( TCPPacket_t *, pxSocket->u.xTCP.xPacket.u.ucLastPacket ); + pxTCPPacket = ipCAST_PTR_TO_TYPE_PTR( TCPPacket_t, pxSocket->u.xTCP.xPacket.u.ucLastPacket ); pxIPHeader = &pxTCPPacket->xIPHeader; /* reset the retry counter to zero. */ @@ -1066,7 +1067,7 @@ uint32_t ulInitialSequenceNumber = 0; /* Write the Ethernet address in Source, because it will be swapped by prvTCPReturnPacket(). */ - ( void ) memcpy( &pxTCPPacket->xEthernetHeader.xSourceAddress, &xEthAddress, sizeof( xEthAddress ) ); + ( void ) memcpy( ( void * ) ( &pxTCPPacket->xEthernetHeader.xSourceAddress ), ( const void * ) ( &xEthAddress ), sizeof( xEthAddress ) ); /* 'ipIPv4_FRAME_TYPE' is already in network-byte-order. */ pxTCPPacket->xEthernetHeader.usFrameType = ipIPv4_FRAME_TYPE; @@ -1145,7 +1146,7 @@ uint32_t ulInitialSequenceNumber = 0; _static void prvCheckOptions( FreeRTOS_Socket_t *pxSocket, const NetworkBufferDescriptor_t *pxNetworkBuffer ) { size_t uxTCPHeaderOffset = ipSIZE_OF_ETH_HEADER + xIPHeaderSize( pxNetworkBuffer ); -const ProtocolHeaders_t *pxProtocolHeaders = ipPOINTER_CAST( ProtocolHeaders_t *, +const ProtocolHeaders_t *pxProtocolHeaders = ipCAST_PTR_TO_TYPE_PTR( ProtocolHeaders_t, &( pxNetworkBuffer->pucEthernetBuffer[ uxTCPHeaderOffset ] ) ); const TCPHeader_t * pxTCPHeader; const uint8_t *pucPtr; @@ -1785,6 +1786,7 @@ uint32_t ulDataGot, ulDistance; TCPWindow_t *pxTCPWindow; NetworkBufferDescriptor_t *pxNewBuffer; int32_t lStreamPos; +UBaseType_t uxIntermediateResult = 0; if( ( *ppxNetworkBuffer ) != NULL ) { @@ -1798,7 +1800,7 @@ int32_t lStreamPos; } /* Map the ethernet buffer onto the ProtocolHeader_t struct for easy access to the fields. */ - pxProtocolHeaders = ipPOINTER_CAST( ProtocolHeaders_t *, &( pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + uxIPHeaderSizeSocket( pxSocket ) ] ) ); + pxProtocolHeaders = ipCAST_PTR_TO_TYPE_PTR( ProtocolHeaders_t, &( pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + uxIPHeaderSizeSocket( pxSocket ) ] ) ); pxTCPWindow = &( pxSocket->u.xTCP.xTCPWindow ); lDataLen = 0; lStreamPos = 0; @@ -1828,7 +1830,7 @@ int32_t lStreamPos; /* Map the byte stream onto ProtocolHeaders_t struct for easy * access to the fields. */ - pxProtocolHeaders = ipPOINTER_CAST( ProtocolHeaders_t *, &( pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + uxIPHeaderSizeSocket( pxSocket ) ] ) ); + pxProtocolHeaders = ipCAST_PTR_TO_TYPE_PTR( ProtocolHeaders_t, &( pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + uxIPHeaderSizeSocket( pxSocket ) ] ) ); pucSendData = &( pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + uxIPHeaderSizeSocket( pxSocket ) + ipSIZE_OF_TCP_HEADER + uxOptionsLength ] ); @@ -1957,7 +1959,8 @@ int32_t lStreamPos; pxProtocolHeaders->xTCPHeader.ucTCPFlags |= ( uint8_t ) tcpTCP_FLAG_PSH; } - lDataLen += ipNUMERIC_CAST( int32_t, uxIPHeaderSizeSocket( pxSocket ) + ipSIZE_OF_TCP_HEADER + uxOptionsLength ); + uxIntermediateResult = uxIPHeaderSizeSocket( pxSocket ) + ipSIZE_OF_TCP_HEADER + uxOptionsLength; + lDataLen += ( int32_t ) uxIntermediateResult; } return lDataLen; @@ -2074,10 +2077,10 @@ int32_t lCount, lLength; static BaseType_t prvTCPHandleFin( FreeRTOS_Socket_t *pxSocket, const NetworkBufferDescriptor_t *pxNetworkBuffer ) { /* Map the ethernet buffer onto the ProtocolHeader_t struct for easy access to the fields. */ -ProtocolHeaders_t *pxProtocolHeaders = ipPOINTER_CAST( ProtocolHeaders_t *, +ProtocolHeaders_t *pxProtocolHeaders = ipCAST_PTR_TO_TYPE_PTR( ProtocolHeaders_t, &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + xIPHeaderSize( pxNetworkBuffer ) ] ) ); TCPHeader_t *pxTCPHeader = &( pxProtocolHeaders->xTCPHeader ); -uint8_t ucTCPFlags = pxTCPHeader->ucTCPFlags; +uint8_t ucIntermediateResult = 0, ucTCPFlags = pxTCPHeader->ucTCPFlags; TCPWindow_t *pxTCPWindow = &pxSocket->u.xTCP.xTCPWindow; BaseType_t xSendLength = 0; uint32_t ulAckNr = FreeRTOS_ntohl( pxTCPHeader->ulAckNr ); @@ -2143,7 +2146,8 @@ uint32_t ulAckNr = FreeRTOS_ntohl( pxTCPHeader->ulAckNr ); if( pxTCPHeader->ucTCPFlags != 0U ) { - xSendLength = ipNUMERIC_CAST( BaseType_t, uxIPHeaderSizeSocket( pxSocket ) + ipSIZE_OF_TCP_HEADER + pxTCPWindow->ucOptionLength ); + ucIntermediateResult = uxIPHeaderSizeSocket( pxSocket ) + ipSIZE_OF_TCP_HEADER + pxTCPWindow->ucOptionLength; + xSendLength = ( BaseType_t ) ucIntermediateResult; } pxTCPHeader->ucTCPOffset = ( uint8_t ) ( ( ipSIZE_OF_TCP_HEADER + pxTCPWindow->ucOptionLength ) << 2 ); @@ -2171,15 +2175,16 @@ uint32_t ulAckNr = FreeRTOS_ntohl( pxTCPHeader->ulAckNr ); static BaseType_t prvCheckRxData( const NetworkBufferDescriptor_t *pxNetworkBuffer, uint8_t **ppucRecvData ) { /* Map the ethernet buffer onto the ProtocolHeader_t struct for easy access to the fields. */ -const ProtocolHeaders_t *pxProtocolHeaders = ipPOINTER_CAST( ProtocolHeaders_t *, +const ProtocolHeaders_t *pxProtocolHeaders = ipCAST_PTR_TO_TYPE_PTR( ProtocolHeaders_t, &( pxNetworkBuffer->pucEthernetBuffer[ ( size_t ) ipSIZE_OF_ETH_HEADER + xIPHeaderSize( pxNetworkBuffer ) ] ) ); const TCPHeader_t *pxTCPHeader = &( pxProtocolHeaders->xTCPHeader ); int32_t lLength, lTCPHeaderLength, lReceiveLength, lUrgentLength; /* Map the buffer onto an IPHeader_t struct for easy access to fields. */ -const IPHeader_t *pxIPHeader = ipPOINTER_CAST( const IPHeader_t *, &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER ] ) ); +const IPHeader_t *pxIPHeader = ipCAST_CONST_PTR_TO_CONST_TYPE_PTR( IPHeader_t, &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER ] ) ); const size_t xIPHeaderLength = ipSIZE_OF_IPv4_HEADER; uint16_t usLength; +uint8_t ucIntermediateResult = 0; /* Determine the length and the offset of the user-data sent to this node. @@ -2187,7 +2192,8 @@ uint16_t usLength; The size of the TCP header is given in a multiple of 4-byte words (single byte, needs no ntoh() translation). A shift-right 2: is the same as (offset >> 4) * 4. */ - lTCPHeaderLength = ipNUMERIC_CAST( BaseType_t, ( pxTCPHeader->ucTCPOffset & tcpVALID_BITS_IN_TCP_OFFSET_BYTE ) >> 2 ); + ucIntermediateResult = ( pxTCPHeader->ucTCPOffset & tcpVALID_BITS_IN_TCP_OFFSET_BYTE ) >> 2; + lTCPHeaderLength = ( int32_t ) ucIntermediateResult; /* Let pucRecvData point to the first byte received. */ *ppucRecvData = &( pxNetworkBuffer->pucEthernetBuffer[ ( size_t ) ipSIZE_OF_ETH_HEADER + xIPHeaderLength + ( size_t ) lTCPHeaderLength ] ); @@ -2246,7 +2252,7 @@ static BaseType_t prvStoreRxData( FreeRTOS_Socket_t *pxSocket, const uint8_t *pu NetworkBufferDescriptor_t *pxNetworkBuffer, uint32_t ulReceiveLength ) { /* Map the ethernet buffer onto the ProtocolHeader_t struct for easy access to the fields. */ -const ProtocolHeaders_t *pxProtocolHeaders = ipPOINTER_CAST( const ProtocolHeaders_t *, +const ProtocolHeaders_t *pxProtocolHeaders = ipCAST_CONST_PTR_TO_CONST_TYPE_PTR( ProtocolHeaders_t, &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + xIPHeaderSize( pxNetworkBuffer ) ] ) ); const TCPHeader_t *pxTCPHeader = &pxProtocolHeaders->xTCPHeader; TCPWindow_t *pxTCPWindow = &pxSocket->u.xTCP.xTCPWindow; @@ -2324,7 +2330,7 @@ BaseType_t xResult = 0; static UBaseType_t prvSetOptions( FreeRTOS_Socket_t *pxSocket, const NetworkBufferDescriptor_t *pxNetworkBuffer ) { /* Map the ethernet buffer onto the ProtocolHeader_t struct for easy access to the fields. */ -ProtocolHeaders_t *pxProtocolHeaders = ipPOINTER_CAST( ProtocolHeaders_t *, +ProtocolHeaders_t *pxProtocolHeaders = ipCAST_PTR_TO_TYPE_PTR( ProtocolHeaders_t, &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + xIPHeaderSize( pxNetworkBuffer ) ] ) ); TCPHeader_t *pxTCPHeader = &pxProtocolHeaders->xTCPHeader; const TCPWindow_t *pxTCPWindow = &pxSocket->u.xTCP.xTCPWindow; @@ -2344,7 +2350,7 @@ UBaseType_t uxOptionsLength = pxTCPWindow->ucOptionLength; FreeRTOS_ntohl( pxTCPWindow->ulOptionsData[ 1 ] ) - pxSocket->u.xTCP.xTCPWindow.rx.ulFirstSequenceNumber, FreeRTOS_ntohl( pxTCPWindow->ulOptionsData[ 2 ] ) - pxSocket->u.xTCP.xTCPWindow.rx.ulFirstSequenceNumber ) ); } - ( void ) memcpy( pxTCPHeader->ucOptdata, pxTCPWindow->ulOptionsData, ( size_t ) uxOptionsLength ); + ( void ) memcpy( ( void * ) ( pxTCPHeader->ucOptdata ), ( const void * ) ( pxTCPWindow->ulOptionsData ), ( size_t ) uxOptionsLength ); /* The header length divided by 4, goes into the higher nibble, effectively a shift-left 2. */ @@ -2387,13 +2393,14 @@ static BaseType_t prvHandleSynReceived( FreeRTOS_Socket_t *pxSocket, const Netwo uint32_t ulReceiveLength, UBaseType_t uxOptionsLength ) { /* Map the ethernet buffer onto the ProtocolHeader_t struct for easy access to the fields. */ -ProtocolHeaders_t *pxProtocolHeaders = ipPOINTER_CAST( ProtocolHeaders_t *, +ProtocolHeaders_t *pxProtocolHeaders = ipCAST_PTR_TO_TYPE_PTR( ProtocolHeaders_t, &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + uxIPHeaderSizeSocket( pxSocket ) ] ) ); TCPHeader_t *pxTCPHeader = &pxProtocolHeaders->xTCPHeader; TCPWindow_t *pxTCPWindow = &pxSocket->u.xTCP.xTCPWindow; uint8_t ucTCPFlags = pxTCPHeader->ucTCPFlags; uint32_t ulSequenceNumber = FreeRTOS_ntohl( pxTCPHeader->ulSequenceNumber ); BaseType_t xSendLength = 0; +UBaseType_t uxIntermediateResult = 0; /* Either expect a ACK or a SYN+ACK. */ uint8_t ucExpect = tcpTCP_FLAG_ACK; @@ -2418,7 +2425,10 @@ BaseType_t xSendLength = 0; pxTCPWindow->rx.ulCurrentSequenceNumber = ulSequenceNumber; pxTCPHeader->ucTCPFlags |= tcpTCP_FLAG_RST; - xSendLength = ipNUMERIC_CAST( BaseType_t, uxIPHeaderSizeSocket( pxSocket ) + ipSIZE_OF_TCP_HEADER + uxOptionsLength ); + + uxIntermediateResult = uxIPHeaderSizeSocket( pxSocket ) + ipSIZE_OF_TCP_HEADER + uxOptionsLength; + xSendLength = ( BaseType_t ) uxIntermediateResult; + pxTCPHeader->ucTCPOffset = ( uint8_t )( ( ipSIZE_OF_TCP_HEADER + uxOptionsLength ) << 2 ); } else @@ -2429,7 +2439,7 @@ BaseType_t xSendLength = 0; if( pxSocket->u.xTCP.ucTCPState == ( uint8_t ) eCONNECT_SYN ) { /* Map the Last packet onto the ProtocolHeader_t struct for easy access to the fields. */ - ProtocolHeaders_t *pxLastHeaders = ipPOINTER_CAST( ProtocolHeaders_t *, + ProtocolHeaders_t *pxLastHeaders = ipCAST_PTR_TO_TYPE_PTR( ProtocolHeaders_t, &( pxSocket->u.xTCP.xPacket.u.ucLastPacket[ ipSIZE_OF_ETH_HEADER + uxIPHeaderSizeSocket( pxSocket ) ] ) ); /* Clear the SYN flag in lastPacket. */ @@ -2472,7 +2482,9 @@ BaseType_t xSendLength = 0; if( ( pxSocket->u.xTCP.ucTCPState == ( EventBits_t ) eCONNECT_SYN ) || ( ulReceiveLength != 0UL ) ) { pxTCPHeader->ucTCPFlags = tcpTCP_FLAG_ACK; - xSendLength = ipNUMERIC_CAST( BaseType_t, uxIPHeaderSizeSocket( pxSocket ) + ( size_t ) ipSIZE_OF_TCP_HEADER + uxOptionsLength ); + + uxIntermediateResult = uxIPHeaderSizeSocket( pxSocket ) + ( size_t ) ipSIZE_OF_TCP_HEADER + uxOptionsLength; + xSendLength = ( BaseType_t ) uxIntermediateResult; pxTCPHeader->ucTCPOffset = ( uint8_t ) ( ( ipSIZE_OF_TCP_HEADER + uxOptionsLength ) << 2 ); } #if( ipconfigUSE_TCP_WIN != 0 ) @@ -2507,15 +2519,16 @@ static BaseType_t prvHandleEstablished( FreeRTOS_Socket_t *pxSocket, NetworkBuff uint32_t ulReceiveLength, UBaseType_t uxOptionsLength ) { /* Map the buffer onto the ProtocolHeader_t struct for easy access to the fields. */ -ProtocolHeaders_t *pxProtocolHeaders = ipPOINTER_CAST( ProtocolHeaders_t *, +ProtocolHeaders_t *pxProtocolHeaders = ipCAST_PTR_TO_TYPE_PTR( ProtocolHeaders_t, &( ( *ppxNetworkBuffer )->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + uxIPHeaderSizeSocket( pxSocket ) ] ) ); TCPHeader_t *pxTCPHeader = &pxProtocolHeaders->xTCPHeader; TCPWindow_t *pxTCPWindow = &pxSocket->u.xTCP.xTCPWindow; uint8_t ucTCPFlags = pxTCPHeader->ucTCPFlags; -uint32_t ulSequenceNumber = FreeRTOS_ntohl( pxTCPHeader->ulSequenceNumber ), ulCount; +uint32_t ulSequenceNumber = FreeRTOS_ntohl( pxTCPHeader->ulSequenceNumber ), ulCount, ulIntermediateResult = 0; BaseType_t xSendLength = 0, xMayClose = pdFALSE, bRxComplete, bTxDone; int32_t lDistance, lSendResult; uint16_t usWindow; +UBaseType_t uxIntermediateResult = 0; /* Remember the window size the peer is advertising. */ usWindow = FreeRTOS_ntohs( pxTCPHeader->usWindow ); @@ -2598,7 +2611,8 @@ uint16_t usWindow; } else { - lDistance = ipNUMERIC_CAST( int32_t, ulSequenceNumber + ulReceiveLength - pxTCPWindow->rx.ulCurrentSequenceNumber ); + ulIntermediateResult = ulSequenceNumber + ulReceiveLength - pxTCPWindow->rx.ulCurrentSequenceNumber; + lDistance = ( int32_t ) ulIntermediateResult; if( lDistance > 1 ) { @@ -2631,7 +2645,8 @@ uint16_t usWindow; if( ulReceiveLength != 0U ) { - xSendLength = ipNUMERIC_CAST( BaseType_t, uxIPHeaderSizeSocket( pxSocket ) + ipSIZE_OF_TCP_HEADER + uxOptionsLength ); + uxIntermediateResult = uxIPHeaderSizeSocket( pxSocket ) + ipSIZE_OF_TCP_HEADER + uxOptionsLength; + xSendLength = ( BaseType_t ) uxIntermediateResult; /* TCP-offsett equals '( ( length / 4 ) << 4 )', resulting in a shift-left 2 */ pxTCPHeader->ucTCPOffset = ( uint8_t )( ( ipSIZE_OF_TCP_HEADER + uxOptionsLength ) << 2 ); @@ -2671,13 +2686,15 @@ static BaseType_t prvSendData( FreeRTOS_Socket_t *pxSocket, NetworkBufferDescrip uint32_t ulReceiveLength, BaseType_t xByteCount ) { /* Map the buffer onto the ProtocolHeader_t struct for easy access to the fields. */ -const ProtocolHeaders_t *pxProtocolHeaders = ipPOINTER_CAST( ProtocolHeaders_t *, +const ProtocolHeaders_t *pxProtocolHeaders = ipCAST_PTR_TO_TYPE_PTR( ProtocolHeaders_t, &( ( *ppxNetworkBuffer )->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + xIPHeaderSize( *ppxNetworkBuffer ) ] ) ); const TCPHeader_t *pxTCPHeader = &pxProtocolHeaders->xTCPHeader; const TCPWindow_t *pxTCPWindow = &pxSocket->u.xTCP.xTCPWindow; /* Find out what window size we may advertised. */ int32_t lRxSpace; BaseType_t xSendLength = xByteCount; +uint32_t ulRxBufferSpace; + #if( ipconfigUSE_TCP_WIN == 1 ) #if( ipconfigTCP_ACK_EARLIER_PACKET == 0 ) const int32_t lMinLength = 0; @@ -2688,7 +2705,9 @@ BaseType_t xSendLength = xByteCount; /* Set the time-out field, so that we'll be called by the IP-task in case no next message will be received. */ - lRxSpace = ipNUMERIC_CAST( int32_t, pxSocket->u.xTCP.ulHighestRxAllowed - pxTCPWindow->rx.ulCurrentSequenceNumber ); + ulRxBufferSpace = pxSocket->u.xTCP.ulHighestRxAllowed - pxTCPWindow->rx.ulCurrentSequenceNumber; + lRxSpace = ( int32_t ) ulRxBufferSpace; + #if ipconfigUSE_TCP_WIN == 1 { @@ -2816,7 +2835,7 @@ BaseType_t xSendLength = xByteCount; static BaseType_t prvTCPHandleState( FreeRTOS_Socket_t *pxSocket, NetworkBufferDescriptor_t **ppxNetworkBuffer ) { /* Map the buffer onto the ProtocolHeader_t struct for easy access to the fields. */ -ProtocolHeaders_t *pxProtocolHeaders = ipPOINTER_CAST( ProtocolHeaders_t *, +ProtocolHeaders_t *pxProtocolHeaders = ipCAST_PTR_TO_TYPE_PTR( ProtocolHeaders_t, &( ( *ppxNetworkBuffer )->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + xIPHeaderSize( *ppxNetworkBuffer ) ] ) ); TCPHeader_t *pxTCPHeader = &( pxProtocolHeaders->xTCPHeader ); BaseType_t xSendLength = 0; @@ -2832,6 +2851,7 @@ uint32_t ulSequenceNumber = FreeRTOS_ntohl (pxTCPHeader->ulSequenceNumber); UBaseType_t uxOptionsLength = 0U; uint8_t ucTCPFlags = pxTCPHeader->ucTCPFlags; TCPWindow_t *pxTCPWindow = &( pxSocket->u.xTCP.xTCPWindow ); +UBaseType_t uxIntermediateResult = 0; /* First get the length and the position of the received data, if any. pucRecvData will point to the first byte of the TCP payload. */ @@ -2912,7 +2932,8 @@ TCPWindow_t *pxTCPWindow = &( pxSocket->u.xTCP.xTCPWindow ); uxOptionsLength = prvSetSynAckOptions( pxSocket, pxTCPHeader ); pxTCPHeader->ucTCPFlags = ( uint8_t ) tcpTCP_FLAG_SYN | ( uint8_t ) tcpTCP_FLAG_ACK; - xSendLength = ipNUMERIC_CAST( BaseType_t, uxIPHeaderSizeSocket( pxSocket ) + ipSIZE_OF_TCP_HEADER + uxOptionsLength ); + uxIntermediateResult = uxIPHeaderSizeSocket( pxSocket ) + ipSIZE_OF_TCP_HEADER + uxOptionsLength; + xSendLength = ( BaseType_t ) uxIntermediateResult; /* Set the TCP offset field: ipSIZE_OF_TCP_HEADER equals 20 and uxOptionsLength is a multiple of 4. The complete expression is: @@ -3001,7 +3022,7 @@ static BaseType_t prvTCPSendSpecialPacketHelper( NetworkBufferDescriptor_t *pxNe #else { /* Map the ethernet buffer onto the TCPPacket_t struct for easy access to the fields. */ - TCPPacket_t *pxTCPPacket = ipPOINTER_CAST( TCPPacket_t *, pxNetworkBuffer->pucEthernetBuffer ); + TCPPacket_t *pxTCPPacket = ipCAST_PTR_TO_TYPE_PTR( TCPPacket_t, pxNetworkBuffer->pucEthernetBuffer ); const uint32_t ulSendLength = ( uint32_t ) ( ipSIZE_OF_IPv4_HEADER + ipSIZE_OF_TCP_HEADER ); /* Plus 0 options. */ @@ -3065,7 +3086,7 @@ BaseType_t xProcessReceivedTCPPacket( NetworkBufferDescriptor_t *pxDescriptor ) NetworkBufferDescriptor_t *pxNetworkBuffer = pxDescriptor; /* Map the buffer onto a ProtocolHeaders_t struct for easy access to the fields. */ -const ProtocolHeaders_t *pxProtocolHeaders = ipPOINTER_CAST( const ProtocolHeaders_t *, +const ProtocolHeaders_t *pxProtocolHeaders = ipCAST_CONST_PTR_TO_CONST_TYPE_PTR( ProtocolHeaders_t, &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + xIPHeaderSize( pxNetworkBuffer ) ] ) ); FreeRTOS_Socket_t *pxSocket; uint16_t ucTCPFlags = pxProtocolHeaders->xTCPHeader.ucTCPFlags; @@ -3088,7 +3109,7 @@ const IPHeader_t *pxIPHeader; else { /* Map the ethernet buffer onto the IPHeader_t struct for easy access to the fields. */ - pxIPHeader = ipPOINTER_CAST( const IPHeader_t *, &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER ] ) ); + pxIPHeader = ipCAST_CONST_PTR_TO_CONST_TYPE_PTR( IPHeader_t, &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER ] ) ); ulLocalIP = FreeRTOS_htonl( pxIPHeader->ulDestinationIPAddress ); ulRemoteIP = FreeRTOS_htonl( pxIPHeader->ulSourceIPAddress ); @@ -3215,8 +3236,8 @@ const IPHeader_t *pxIPHeader; headers). It might be used later on, whenever data must be sent to the peer. */ const size_t lOffset = ipNUMERIC_CAST( size_t, ipSIZE_OF_ETH_HEADER + uxIPHeaderSizeSocket( pxSocket ) ); - ( void ) memcpy( &( pxSocket->u.xTCP.xPacket.u.ucLastPacket[ lOffset ] ), - &( pxNetworkBuffer->pucEthernetBuffer[ lOffset ] ), + ( void ) memcpy( ( void * ) ( &( pxSocket->u.xTCP.xPacket.u.ucLastPacket[ lOffset ] ) ), + ( const void * ) ( &( pxNetworkBuffer->pucEthernetBuffer[ lOffset ] ) ), ipSIZE_OF_TCP_HEADER ); } } @@ -3296,7 +3317,7 @@ const IPHeader_t *pxIPHeader; static FreeRTOS_Socket_t *prvHandleListen( FreeRTOS_Socket_t *pxSocket, NetworkBufferDescriptor_t *pxNetworkBuffer ) { /* Map the ethernet buffer onto a TCPPacket_t struct for easy access to the fields. */ -const TCPPacket_t * pxTCPPacket = ipPOINTER_CAST( const TCPPacket_t *, pxNetworkBuffer->pucEthernetBuffer ); +const TCPPacket_t * pxTCPPacket = ipCAST_CONST_PTR_TO_CONST_TYPE_PTR( TCPPacket_t, pxNetworkBuffer->pucEthernetBuffer ); FreeRTOS_Socket_t *pxReturn = NULL; uint32_t ulInitialSequenceNumber; @@ -3363,7 +3384,7 @@ uint32_t ulInitialSequenceNumber; if( ( ulInitialSequenceNumber != 0U ) && ( pxReturn != NULL ) ) { /* Map the byte stream onto the ProtocolHeaders_t for easy access to the fields. */ - const ProtocolHeaders_t *pxProtocolHeaders = ipPOINTER_CAST( const ProtocolHeaders_t *, + const ProtocolHeaders_t *pxProtocolHeaders = ipCAST_CONST_PTR_TO_CONST_TYPE_PTR( ProtocolHeaders_t, &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + xIPHeaderSize( pxNetworkBuffer ) ] ) ); pxReturn->u.xTCP.usRemotePort = FreeRTOS_htons( pxTCPPacket->xTCPHeader.usSourcePort ); @@ -3380,7 +3401,7 @@ uint32_t ulInitialSequenceNumber; /* Make a copy of the header up to the TCP header. It is needed later on, whenever data must be sent to the peer. */ - ( void ) memcpy( pxReturn->u.xTCP.xPacket.u.ucLastPacket, pxNetworkBuffer->pucEthernetBuffer, sizeof( pxReturn->u.xTCP.xPacket.u.ucLastPacket ) ); + ( void ) memcpy( ( void * ) ( pxReturn->u.xTCP.xPacket.u.ucLastPacket ), ( const void * ) ( pxNetworkBuffer->pucEthernetBuffer ), sizeof( pxReturn->u.xTCP.xPacket.u.ucLastPacket ) ); } return pxReturn; } @@ -3529,7 +3550,7 @@ TickType_t uxLocalPort = ( TickType_t ) FreeRTOS_htons( pxSocket->usLocalPort ); const ListItem_t *pxIterator; FreeRTOS_Socket_t *pxFound; BaseType_t xResult = pdFALSE; -const ListItem_t *pxEndTCP = ipPOINTER_CAST( const ListItem_t *, listGET_END_MARKER( &xBoundTCPSocketsList ) ); +const ListItem_t *pxEndTCP = listGET_END_MARKER( &xBoundTCPSocketsList ); /* Here xBoundTCPSocketsList can be accessed safely IP-task is the only one who has access. */ @@ -3539,7 +3560,7 @@ const ListItem_t *pxEndTCP = ipPOINTER_CAST( const ListItem_t *, listGET_END_MAR { if( listGET_LIST_ITEM_VALUE( pxIterator ) == ( configLIST_VOLATILE TickType_t ) uxLocalPort ) { - pxFound = ipPOINTER_CAST( FreeRTOS_Socket_t *, listGET_LIST_ITEM_OWNER( pxIterator ) ); + pxFound = ipCAST_PTR_TO_TYPE_PTR( FreeRTOS_Socket_t, listGET_LIST_ITEM_OWNER( pxIterator ) ); if( ( pxFound->ucProtocol == ( uint8_t ) FREERTOS_IPPROTO_TCP ) && ( pxFound->u.xTCP.bits.bPassAccept != pdFALSE_UNSIGNED ) ) { pxSocket->u.xTCP.pxPeerSocket = pxFound; diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_TCP_WIN.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_TCP_WIN.c index 5adcc9f314..8ec488ab44 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_TCP_WIN.c +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_TCP_WIN.c @@ -1,5 +1,5 @@ /* - * FreeRTOS+TCP V2.2.1 + * FreeRTOS+TCP V2.2.2 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of @@ -55,6 +55,12 @@ #define winSRTT_DECREMENT_CURRENT 7 #define winSRTT_CAP_mS 50 +static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( TCPSegment_t ) +{ + return ( TCPSegment_t *)pvArgument; +} + + #if( ipconfigUSE_TCP_WIN == 1 ) #define xTCPWindowRxNew( pxWindow, ulSequenceNumber, lCount ) xTCPWindowNew( pxWindow, ulSequenceNumber, lCount, pdTRUE ) @@ -309,7 +315,7 @@ static void vListInsertGeneric( List_t * const pxList, ListItem_t * const pxNewL /* Insert a new list item into pxList, it does not sort the list, but it puts the item just before xListEnd, so it will be the last item returned by listGET_HEAD_ENTRY() */ - pxNewListItem->pxNext = ipPOINTER_CAST(struct xLIST_ITEM * configLIST_VOLATILE, pxWhere ); + pxNewListItem->pxNext = ( struct xLIST_ITEM * configLIST_VOLATILE )pxWhere; pxNewListItem->pxPrevious = pxWhere->pxPrevious; pxWhere->pxPrevious->pxNext = pxNewListItem; pxWhere->pxPrevious = pxNewListItem; @@ -330,7 +336,7 @@ static void vListInsertGeneric( List_t * const pxList, ListItem_t * const pxNewL /* Allocate space for 'xTCPSegments' and store them in 'xSegmentList'. */ vListInitialise( &xSegmentList ); - xTCPSegments = ipPOINTER_CAST( TCPSegment_t *, pvPortMallocLarge( ( size_t ) ipconfigTCP_WIN_SEG_COUNT * sizeof( xTCPSegments[ 0 ] ) ) ); + xTCPSegments = ipCAST_PTR_TO_TYPE_PTR( TCPSegment_t, pvPortMallocLarge( ( size_t ) ipconfigTCP_WIN_SEG_COUNT * sizeof( xTCPSegments[ 0 ] ) ) ); if( xTCPSegments == NULL ) { @@ -348,8 +354,8 @@ static void vListInsertGeneric( List_t * const pxList, ListItem_t * const pxNewL { /* Could call vListInitialiseItem here but all data has been nulled already. Set the owner to a segment descriptor. */ - listSET_LIST_ITEM_OWNER( &( xTCPSegments[ xIndex ].xSegmentItem ), ipPOINTER_CAST( void *, &( xTCPSegments[ xIndex ] ) ) ); - listSET_LIST_ITEM_OWNER( &( xTCPSegments[ xIndex ].xQueueItem ), ipPOINTER_CAST( void *, &( xTCPSegments[ xIndex ] ) ) ); + listSET_LIST_ITEM_OWNER( &( xTCPSegments[ xIndex ].xSegmentItem ),( void * ) &( xTCPSegments[ xIndex ] ) ); + listSET_LIST_ITEM_OWNER( &( xTCPSegments[ xIndex ].xQueueItem ), ( void * ) &( xTCPSegments[ xIndex ] ) ); /* And add it to the pool of available segments */ vListInsertFifo( &xSegmentList, &( xTCPSegments[xIndex].xSegmentItem ) ); @@ -374,13 +380,13 @@ static void vListInsertGeneric( List_t * const pxList, ListItem_t * const pxNewL /* Find a segment with a given sequence number in the list of received segments. */ - pxEnd = ipPOINTER_CAST( const ListItem_t *, listGET_END_MARKER( &pxWindow->xRxSegments ) ); + pxEnd = listGET_END_MARKER( &pxWindow->xRxSegments ); for( pxIterator = listGET_NEXT( pxEnd ); pxIterator != pxEnd; pxIterator = listGET_NEXT( pxIterator ) ) { - pxSegment = ipPOINTER_CAST( TCPSegment_t *, listGET_LIST_ITEM_OWNER( pxIterator ) ); + pxSegment = ipCAST_PTR_TO_TYPE_PTR( TCPSegment_t, listGET_LIST_ITEM_OWNER( pxIterator ) ); if( pxSegment->ulSequenceNumber == ulSequenceNumber ) { @@ -416,7 +422,7 @@ static void vListInsertGeneric( List_t * const pxList, ListItem_t * const pxNewL /* Pop the item at the head of the list. Semaphore protection is not required as only the IP task will call these functions. */ pxItem = ( ListItem_t * ) listGET_HEAD_ENTRY( &xSegmentList ); - pxSegment = ipPOINTER_CAST( TCPSegment_t *, listGET_LIST_ITEM_OWNER( pxItem ) ); + pxSegment = ipCAST_PTR_TO_TYPE_PTR( TCPSegment_t, listGET_LIST_ITEM_OWNER( pxItem ) ); configASSERT( pxItem != NULL ); configASSERT( pxSegment != NULL ); @@ -512,7 +518,7 @@ static void vListInsertGeneric( List_t * const pxList, ListItem_t * const pxNewL else { pxItem = ( ListItem_t * ) listGET_HEAD_ENTRY( pxList ); - pxSegment = ipPOINTER_CAST( TCPSegment_t *, listGET_LIST_ITEM_OWNER( pxItem ) ); + pxSegment = ipCAST_PTR_TO_TYPE_PTR( TCPSegment_t, listGET_LIST_ITEM_OWNER( pxItem ) ); ( void ) uxListRemove( pxItem ); } @@ -538,7 +544,7 @@ static void vListInsertGeneric( List_t * const pxList, ListItem_t * const pxNewL else { pxItem = ( ListItem_t * ) listGET_HEAD_ENTRY( pxList ); - pxReturn = ipPOINTER_CAST( TCPSegment_t *, listGET_LIST_ITEM_OWNER( pxItem ) ); + pxReturn = ipCAST_PTR_TO_TYPE_PTR( TCPSegment_t, listGET_LIST_ITEM_OWNER( pxItem ) ); } return pxReturn; @@ -604,7 +610,7 @@ static void vListInsertGeneric( List_t * const pxList, ListItem_t * const pxNewL { while( listCURRENT_LIST_LENGTH( pxSegments ) > 0U ) { - pxSegment = ipPOINTER_CAST( TCPSegment_t *, listGET_OWNER_OF_HEAD_ENTRY( pxSegments ) ); + pxSegment = ipCAST_PTR_TO_TYPE_PTR( TCPSegment_t, listGET_OWNER_OF_HEAD_ENTRY( pxSegments ) ); vTCPWindowFree( pxSegment ); } } @@ -741,7 +747,7 @@ const int32_t l500ms = 500; TCPSegment_t *pxBest = NULL; const ListItem_t *pxIterator; uint32_t ulNextSequenceNumber = ulSequenceNumber + ulLength; - const ListItem_t * pxEnd = ipPOINTER_CAST( const ListItem_t *, listGET_END_MARKER( &pxWindow->xRxSegments ) ); + const ListItem_t * pxEnd = listGET_END_MARKER( &pxWindow->xRxSegments ); TCPSegment_t *pxSegment; /* A segment has been received with sequence number 'ulSequenceNumber', @@ -757,7 +763,7 @@ const int32_t l500ms = 500; pxIterator != pxEnd; pxIterator = listGET_NEXT( pxIterator ) ) { - pxSegment = ipPOINTER_CAST( TCPSegment_t *, listGET_LIST_ITEM_OWNER( pxIterator ) ); + pxSegment = ipCAST_PTR_TO_TYPE_PTR( TCPSegment_t, listGET_LIST_ITEM_OWNER( pxIterator ) ); /* And see if there is a segment for which: 'ulSequenceNumber' <= 'pxSegment->ulSequenceNumber' < 'ulNextSequenceNumber' If there are more matching segments, the one with the lowest sequence number @@ -795,7 +801,7 @@ const int32_t l500ms = 500; int32_t lTCPWindowRxCheck( TCPWindow_t *pxWindow, uint32_t ulSequenceNumber, uint32_t ulLength, uint32_t ulSpace ) { - uint32_t ulCurrentSequenceNumber, ulLast, ulSavedSequenceNumber; + uint32_t ulCurrentSequenceNumber, ulLast, ulSavedSequenceNumber, ulIntermediateResult = 0; int32_t lReturn, lDistance; TCPSegment_t *pxFound; @@ -903,9 +909,10 @@ const int32_t l500ms = 500; /* An "out-of-sequence" segment was received, must have missed one. Prepare a SACK (Selective ACK). */ ulLast = ulSequenceNumber + ulLength; - /* The cast from unsigned long to signed long is on purpose. - The macro 'ipNUMERIC_CAST' will prevent PC-lint from complaining. */ - lDistance = ipNUMERIC_CAST( int32_t, ulLast - ulCurrentSequenceNumber ); + + ulIntermediateResult = ulLast - ulCurrentSequenceNumber; + /* The cast from unsigned long to signed long is on purpose. */ + lDistance = ( int32_t ) ulIntermediateResult; if( lDistance <= 0 ) { @@ -999,7 +1006,8 @@ const int32_t l500ms = 500; /* Return a positive value. The packet may be accepted and stored but an earlier packet is still missing. */ - lReturn = ipNUMERIC_CAST( int32_t, ulSequenceNumber - ulCurrentSequenceNumber ); + ulIntermediateResult = ulSequenceNumber - ulCurrentSequenceNumber; + lReturn = ( int32_t ) ulIntermediateResult; } } } @@ -1495,7 +1503,7 @@ const int32_t l500ms = 500; uint32_t ulBytesConfirmed = 0U; uint32_t ulSequenceNumber = ulFirst, ulDataLength; const ListItem_t *pxIterator; - const ListItem_t *pxEnd = ipPOINTER_CAST( const ListItem_t *, listGET_END_MARKER( &pxWindow->xTxSegments ) ); + const ListItem_t *pxEnd = listGET_END_MARKER( &pxWindow->xTxSegments ); BaseType_t xDoUnlink; TCPSegment_t *pxSegment; /* An acknowledgement or a selective ACK (SACK) was received. See if some outstanding data @@ -1523,7 +1531,7 @@ const int32_t l500ms = 500; while( ( pxIterator != pxEnd ) && ( xSequenceLessThan( ulSequenceNumber, ulLast ) != 0 ) ) { xDoUnlink = pdFALSE; - pxSegment = ipPOINTER_CAST( TCPSegment_t *, listGET_LIST_ITEM_OWNER( pxIterator ) ); + pxSegment = ipCAST_PTR_TO_TYPE_PTR( TCPSegment_t, listGET_LIST_ITEM_OWNER( pxIterator ) ); /* Move to the next item because the current item might get removed. */ @@ -1650,14 +1658,14 @@ const int32_t l500ms = 500; /* A higher Tx block has been acknowledged. Now iterate through the xWaitQueue to find a possible condition for a FAST retransmission. */ - pxEnd = ipPOINTER_CAST( const ListItem_t *, listGET_END_MARKER( &( pxWindow->xWaitQueue ) ) ); + pxEnd = listGET_END_MARKER( &( pxWindow->xWaitQueue ) ); pxIterator = listGET_NEXT( pxEnd ); while( pxIterator != pxEnd ) { /* Get the owner, which is a TCP segment. */ - pxSegment = ipPOINTER_CAST( TCPSegment_t *, listGET_LIST_ITEM_OWNER( pxIterator ) ); + pxSegment = ipCAST_PTR_TO_TYPE_PTR( TCPSegment_t, listGET_LIST_ITEM_OWNER( pxIterator ) ); /* Hop to the next item before the current gets unlinked. */ pxIterator = listGET_NEXT( pxIterator ); diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_UDP_IP.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_UDP_IP.c index 715a2b1c6c..62e6baf7c0 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_UDP_IP.c +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_UDP_IP.c @@ -1,5 +1,5 @@ /* - * FreeRTOS+TCP V2.2.1 + * FreeRTOS+TCP V2.2.2 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of @@ -82,7 +82,7 @@ uint32_t ulIPAddress = pxNetworkBuffer->ulIPAddress; size_t uxPayloadSize; /* Map the UDP packet onto the start of the frame. */ - pxUDPPacket = ipPOINTER_CAST( UDPPacket_t *, pxNetworkBuffer->pucEthernetBuffer ); + pxUDPPacket = ipCAST_PTR_TO_TYPE_PTR( UDPPacket_t, pxNetworkBuffer->pucEthernetBuffer ); #if ipconfigSUPPORT_OUTGOING_PINGS == 1 if( pxNetworkBuffer->usPort == ( uint16_t ) ipPACKET_CONTAINS_ICMP_DATA ) @@ -154,7 +154,7 @@ size_t uxPayloadSize; */ /* The Ethernet source address is at offset 6. */ char *pxUdpSrcAddrOffset = ( char *) ( &( pxNetworkBuffer->pucEthernetBuffer[ sizeof( MACAddress_t ) ] ) ); - ( void ) memcpy( pxUdpSrcAddrOffset, xDefaultPartUDPPacketHeader.ucBytes, sizeof( xDefaultPartUDPPacketHeader ) ); + ( void ) memcpy( ( void * ) pxUdpSrcAddrOffset, ( const void * ) ( xDefaultPartUDPPacketHeader.ucBytes ), sizeof( xDefaultPartUDPPacketHeader ) ); #if ipconfigSUPPORT_OUTGOING_PINGS == 1 if( pxNetworkBuffer->usPort == ( uint16_t ) ipPACKET_CONTAINS_ICMP_DATA ) @@ -258,7 +258,7 @@ configASSERT( pxNetworkBuffer != NULL ); configASSERT( pxNetworkBuffer->pucEthernetBuffer != NULL ); /* Map the ethernet buffer to the UDPPacket_t struct for easy access to the fields. */ -const UDPPacket_t *pxUDPPacket = ipPOINTER_CAST( const UDPPacket_t *, pxNetworkBuffer->pucEthernetBuffer ); +const UDPPacket_t *pxUDPPacket = ipCAST_CONST_PTR_TO_CONST_TYPE_PTR( UDPPacket_t, pxNetworkBuffer->pucEthernetBuffer ); /* Caller must check for minimum packet size. */ pxSocket = pxUDPSocketLookup( usPort ); diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/History.txt b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/History.txt index 0bbfaa505f..f79e1213b9 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/History.txt +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/History.txt @@ -1,3 +1,41 @@ +Changes between V2.2.1 and V2.2.2 releases: + + Updated the source code to adhere to stricter MISRA compliance. + +Changes between V2.0.0 and V2.2.1 releases: + + Improved security by giving users the option to reject UDP packets with a + checksum of zero even though the UDP spec allows it. + + Improved robustness by checking packet lengths in software even if the check + has already been performed in the hardware. + + Added ipconfigIP_PASS_PACKETS_WITH_IP_OPTIONS macro to enable users to + drop/accept IP Packets containing IP options (IP options are not supported). + + Modified xDataLength to always mean "total number of bytes" to impart more + clarity. + + Replaced the ipconfigRAND32 macro with a function + xApplicationGetRandomNumber(). The return value indicates if the randomiser + is broken or working properly. Before this, a random value of 0 was treated + as invalid, whereas 0 can be a proper random value. + + Made changes in DNS to make asynchronous lookup work. + + Made FreeRTOS_OutputARPRequest() available for application code. Now the + application can start an ARP request directly by sending a UDP packet. + + Made Socket_t and SocketSet_t point to a struct in stead of void. + + Corrected the DNSs protocol-checksum calculation length. + + Corrected length-check in usGenerateProtocolChecksum(). + + Modified pxGetNetworkBufferWithDescriptor() function to check if a counting + semaphore has been created. Earlier when a user tried to get a Network + Buffer before the IP-task started, the function could crash. + + Made TCP low-water/high-water limits configurable with a socket option. + + The 'ucFirstOptionByte' was counted twice in earlier releases, subtract 1 + byte to send the correct amount of bytes. + + Corrected the WIN size reporting to the TCP peer. The WIN size as reported + to the TCP peer was sometimes running slightly behind. + + Added a function FreeRTOS_dnsclear() which invalidates the entire DNS cache. + + Added DNS response transaction ID check. The DNS cache shall only be updated + when the ID in the reply comes from the device. + +Changes between 180821 and V2.0.0 releases: + + Move the TCP source code from FreeRTOS/FreeRTOS-Labs to FreeRTOS/FreeRTOS + repository. + Changes between 160919 and 180821 releases: + Multiple security improvements and fixes in packet parsing routines, DNS diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOSIPConfigDefaults.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOSIPConfigDefaults.h index 7194df3eee..a49f25a4cd 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOSIPConfigDefaults.h +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOSIPConfigDefaults.h @@ -1,5 +1,5 @@ /* - * FreeRTOS+TCP V2.2.1 + * FreeRTOS+TCP V2.2.2 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_ARP.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_ARP.h index 3615b68b51..6d9a2824ff 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_ARP.h +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_ARP.h @@ -1,5 +1,5 @@ /* - * FreeRTOS+TCP V2.2.1 + * FreeRTOS+TCP V2.2.2 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_DHCP.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_DHCP.h index d70327d564..40d05109aa 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_DHCP.h +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_DHCP.h @@ -1,5 +1,5 @@ /* - * FreeRTOS+TCP V2.2.1 + * FreeRTOS+TCP V2.2.2 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_DNS.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_DNS.h index 0168d3477b..9affdce4e7 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_DNS.h +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_DNS.h @@ -1,5 +1,5 @@ /* - * FreeRTOS+TCP V2.2.1 + * FreeRTOS+TCP V2.2.2 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_IP.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_IP.h index 7b37f955e5..b0cbf25d9d 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_IP.h +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_IP.h @@ -1,5 +1,5 @@ /* - * FreeRTOS+TCP V2.2.1 + * FreeRTOS+TCP V2.2.2 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of @@ -313,11 +313,16 @@ BaseType_t FreeRTOS_IsNetworkUp( void ); * Socket has had activity, reset the timer so it will not be closed * because of inactivity */ -const char *FreeRTOS_GetTCPStateName( UBaseType_t ulState); +#if( ( ipconfigHAS_DEBUG_PRINTF != 0 ) || ( ipconfigHAS_PRINTF != 0 ) ) + const char *FreeRTOS_GetTCPStateName( UBaseType_t ulState); +#endif /* _HT_ Temporary: show all valid ARP entries */ -void FreeRTOS_PrintARPCache( void ); +#if( ipconfigHAS_PRINTF != 0 ) || ( ipconfigHAS_DEBUG_PRINTF != 0 ) + void FreeRTOS_PrintARPCache( void ); +#endif + void FreeRTOS_ClearARP( void ); /* Return pdTRUE if the IPv4 address is a multicast address. */ diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_IP_Private.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_IP_Private.h index e59ee63da1..c2f8c4c2c7 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_IP_Private.h +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_IP_Private.h @@ -1,5 +1,5 @@ /* - * FreeRTOS+TCP V2.2.1 + * FreeRTOS+TCP V2.2.2 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of @@ -45,6 +45,20 @@ extern "C" { #include "event_groups.h" +/*-----------------------------------------------------------*/ +/* Utility macros for marking casts as recognized during */ +/* static analysis. */ +/*-----------------------------------------------------------*/ +#define ipCAST_PTR_TO_TYPE_PTR( TYPE, pointer ) ( vCastPointerTo_##TYPE( ( void * )( pointer ) ) ) +#define ipCAST_CONST_PTR_TO_CONST_TYPE_PTR( TYPE, pointer ) ( vCastConstPointerTo_##TYPE( ( const void * )( pointer ) ) ) + +/*-----------------------------------------------------------*/ +/* Utility macros for declaring cast utility functions in */ +/* order to centralize typecasting for static analysis. */ +/*-----------------------------------------------------------*/ +#define ipDECL_CAST_PTR_FUNC_FOR_TYPE( TYPE ) TYPE * vCastPointerTo_##TYPE( void * pvArgument ) +#define ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( TYPE ) const TYPE * vCastConstPointerTo_##TYPE( const void * pvArgument ) + typedef struct xNetworkAddressingParameters { uint32_t ulDefaultIPAddress; @@ -71,6 +85,17 @@ struct xETH_HEADER #include "pack_struct_end.h" typedef struct xETH_HEADER EthernetHeader_t; +static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( EthernetHeader_t ) +{ + return ( EthernetHeader_t *)pvArgument; +} + +static portINLINE ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( EthernetHeader_t ) +{ + return ( const EthernetHeader_t *) pvArgument; +} + + #include "pack_struct_start.h" struct xARP_HEADER { @@ -104,6 +129,16 @@ struct xIP_HEADER #include "pack_struct_end.h" typedef struct xIP_HEADER IPHeader_t; +static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( IPHeader_t ) +{ + return ( IPHeader_t *)pvArgument; +} +static portINLINE ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( IPHeader_t ) +{ + return ( const IPHeader_t *) pvArgument; +} + + #include "pack_struct_start.h" struct xICMP_HEADER { @@ -116,6 +151,16 @@ struct xICMP_HEADER #include "pack_struct_end.h" typedef struct xICMP_HEADER ICMPHeader_t; +static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( ICMPHeader_t ) +{ + return ( ICMPHeader_t *)pvArgument; +} +static portINLINE ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( ICMPHeader_t ) +{ + return ( const ICMPHeader_t *) pvArgument; +} + + #include "pack_struct_start.h" struct xUDP_HEADER { @@ -160,6 +205,16 @@ struct xARP_PACKET #include "pack_struct_end.h" typedef struct xARP_PACKET ARPPacket_t; +static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( ARPPacket_t ) +{ + return ( ARPPacket_t *)pvArgument; +} +static portINLINE ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( ARPPacket_t ) +{ + return ( const ARPPacket_t *) pvArgument; +} + + #include "pack_struct_start.h" struct xIP_PACKET { @@ -169,6 +224,16 @@ struct xIP_PACKET #include "pack_struct_end.h" typedef struct xIP_PACKET IPPacket_t; +static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( IPPacket_t ) +{ + return ( IPPacket_t *)pvArgument; +} +static portINLINE ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( IPPacket_t ) +{ + return ( const IPPacket_t *) pvArgument; +} + + #include "pack_struct_start.h" struct xICMP_PACKET { @@ -179,6 +244,12 @@ struct xICMP_PACKET #include "pack_struct_end.h" typedef struct xICMP_PACKET ICMPPacket_t; +static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( ICMPPacket_t ) +{ + return ( ICMPPacket_t *)pvArgument; +} + + #include "pack_struct_start.h" struct xUDP_PACKET { @@ -189,6 +260,15 @@ struct xUDP_PACKET #include "pack_struct_end.h" typedef struct xUDP_PACKET UDPPacket_t; +static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( UDPPacket_t ) +{ + return ( UDPPacket_t *)pvArgument; +} +static portINLINE ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( UDPPacket_t ) +{ + return ( const UDPPacket_t *) pvArgument; +} + #include "pack_struct_start.h" struct xTCP_PACKET { @@ -199,6 +279,17 @@ struct xTCP_PACKET #include "pack_struct_end.h" typedef struct xTCP_PACKET TCPPacket_t; +static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( TCPPacket_t ) +{ + return ( TCPPacket_t *)pvArgument; +} + +static portINLINE ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( TCPPacket_t ) +{ + return ( const TCPPacket_t *) pvArgument; +} + + typedef union XPROT_PACKET { ARPPacket_t xARPPacket; @@ -207,6 +298,15 @@ typedef union XPROT_PACKET ICMPPacket_t xICMPPacket; } ProtocolPacket_t; +static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( ProtocolPacket_t ) +{ + return ( ProtocolPacket_t *)pvArgument; +} +static portINLINE ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( ProtocolPacket_t ) +{ + return ( const ProtocolPacket_t *) pvArgument; +} + typedef union xPROT_HEADERS { ICMPHeader_t xICMPHeader; @@ -214,6 +314,15 @@ typedef union xPROT_HEADERS TCPHeader_t xTCPHeader; } ProtocolHeaders_t; +static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( ProtocolHeaders_t ) +{ + return ( ProtocolHeaders_t *)pvArgument; +} + +static portINLINE ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( ProtocolHeaders_t ) +{ + return ( const ProtocolHeaders_t *) pvArgument; +} /* The maximum UDP payload length. */ #define ipMAX_UDP_PAYLOAD_LENGTH ( ( ipconfigNETWORK_MTU - ipSIZE_OF_IPv4_HEADER ) - ipSIZE_OF_UDP_HEADER ) @@ -406,13 +515,6 @@ socket events. */ #define ARRAY_SIZE(x) ( ( BaseType_t ) ( sizeof( x ) / sizeof( ( x )[ 0 ] ) ) ) #endif -/* - * A version of FreeRTOS_GetReleaseNetworkBuffer() that can be called from an - * interrupt. If a non zero value is returned, then the calling ISR should - * perform a context switch before exiting the ISR. - */ -BaseType_t FreeRTOS_ReleaseFreeNetworkBufferFromISR( void ); - /* * Create a message that contains a command to initialise the network interface. * This is used during initialisation, and at any time the network interface @@ -476,7 +578,9 @@ BaseType_t xIPIsNetworkTaskReady( void ); * Actually a user thing, but because xBoundTCPSocketsList, let it do by the * IP-task */ - void vTCPNetStat( void ); + #if( ipconfigHAS_PRINTF != 0 ) + void vTCPNetStat( void ); + #endif /* * At least one socket needs to check for timeouts @@ -665,6 +769,15 @@ typedef struct xSOCKET } u; } FreeRTOS_Socket_t; +static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( FreeRTOS_Socket_t ) +{ + return ( FreeRTOS_Socket_t *)pvArgument; +} +static portINLINE ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( FreeRTOS_Socket_t ) +{ + return ( const FreeRTOS_Socket_t *) pvArgument; +} + #if( ipconfigUSE_TCP == 1 ) /* * Lookup a TCP socket, using a multiple matching: both port numbers and @@ -801,6 +914,15 @@ typedef struct xSOCKET_SET EventGroupHandle_t xSelectGroup; } SocketSelect_t; +static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( SocketSelect_t ) +{ + return ( SocketSelect_t *)pvArgument; +} +static portINLINE ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( SocketSelect_t ) +{ + return ( const SocketSelect_t *) pvArgument; +} + extern void vSocketSelect( SocketSelect_t *pxSocketSet ); /* Define the data that must be passed for a 'eSocketSelectEvent'. */ @@ -810,6 +932,15 @@ typedef struct xSocketSelectMessage SocketSelect_t *pxSocketSet; } SocketSelectMessage_t; +static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( SocketSelectMessage_t ) +{ + return ( SocketSelectMessage_t *)pvArgument; +} +static portINLINE ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( SocketSelectMessage_t ) +{ + return ( const SocketSelectMessage_t *) pvArgument; +} + #endif /* ipconfigSUPPORT_SELECT_FUNCTION */ void vIPSetDHCPTimerEnableState( BaseType_t xEnableState ); @@ -828,15 +959,3 @@ void vIPNetworkUpCalls( void ); #endif /* FREERTOS_IP_PRIVATE_H */ - - - - - - - - - - - - diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_Sockets.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_Sockets.h index a6329ebc39..c9580fed18 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_Sockets.h +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_Sockets.h @@ -1,5 +1,5 @@ /* - * FreeRTOS+TCP V2.2.1 + * FreeRTOS+TCP V2.2.2 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of @@ -205,6 +205,12 @@ struct xSOCKET; typedef struct xSOCKET *Socket_t; typedef struct xSOCKET const * ConstSocket_t; +static portINLINE unsigned int prvSocketValid( Socket_t xSocket ) +{ + /* coverity[misra_c_2012_rule_11_4_violation] */ + return ( ( xSocket != FREERTOS_INVALID_SOCKET ) && ( xSocket != NULL ) ); +} + #if( ipconfigSUPPORT_SELECT_FUNCTION == 1 ) /* The SocketSet_t type is the equivalent to the fd_set type used by the Berkeley API. */ @@ -417,15 +423,3 @@ void FreeRTOS_netstat( void ); #endif /* FREERTOS_SOCKETS_H */ - - - - - - - - - - - - diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_Stream_Buffer.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_Stream_Buffer.h index b56ecdbeb6..317c96f546 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_Stream_Buffer.h +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_Stream_Buffer.h @@ -1,5 +1,5 @@ /* - * FreeRTOS+TCP V2.2.1 + * FreeRTOS+TCP V2.2.2 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_TCP_IP.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_TCP_IP.h index 5e64e9743c..06a4014530 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_TCP_IP.h +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_TCP_IP.h @@ -1,5 +1,5 @@ /* - * FreeRTOS+TCP V2.2.1 + * FreeRTOS+TCP V2.2.2 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_TCP_WIN.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_TCP_WIN.h index 9368e08019..cd455162c7 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_TCP_WIN.h +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_TCP_WIN.h @@ -1,5 +1,5 @@ /* - * FreeRTOS+TCP V2.2.1 + * FreeRTOS+TCP V2.2.2 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_UDP_IP.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_UDP_IP.h index 0da86a7df8..898e84e7c6 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_UDP_IP.h +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_UDP_IP.h @@ -1,5 +1,5 @@ /* - * FreeRTOS+TCP V2.2.1 + * FreeRTOS+TCP V2.2.2 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_errno_TCP.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_errno_TCP.h index 9105b0f812..07c310daa4 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_errno_TCP.h +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_errno_TCP.h @@ -1,5 +1,5 @@ /* - * FreeRTOS+TCP V2.2.1 + * FreeRTOS+TCP V2.2.2 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/IPTraceMacroDefaults.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/IPTraceMacroDefaults.h index fc100c9fdd..e255233b68 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/IPTraceMacroDefaults.h +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/IPTraceMacroDefaults.h @@ -1,5 +1,5 @@ /* - * FreeRTOS+TCP V2.2.1 + * FreeRTOS+TCP V2.2.2 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/NetworkBufferManagement.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/NetworkBufferManagement.h index 7d8d574a60..a5a2e621f0 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/NetworkBufferManagement.h +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/NetworkBufferManagement.h @@ -1,5 +1,5 @@ /* - * FreeRTOS+TCP V2.2.1 + * FreeRTOS+TCP V2.2.2 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/NetworkInterface.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/NetworkInterface.h index 51e9a29427..9f910dc5d5 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/NetworkInterface.h +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/NetworkInterface.h @@ -1,5 +1,5 @@ /* - * FreeRTOS+TCP V2.2.1 + * FreeRTOS+TCP V2.2.2 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/tcp_dump_packets.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/tcp_dump_packets.h index 7dd3690233..8dc641a773 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/tcp_dump_packets.h +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/tcp_dump_packets.h @@ -1,5 +1,5 @@ /* - * FreeRTOS+TCP V2.2.1 + * FreeRTOS+TCP V2.2.2 * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/tcp_mem_stats.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/tcp_mem_stats.h index d07956f4a9..fea8e43757 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/tcp_mem_stats.h +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/tcp_mem_stats.h @@ -1,5 +1,5 @@ /* - * FreeRTOS+TCP V2.2.1 + * FreeRTOS+TCP V2.2.2 * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/BufferManagement/BufferAllocation_1.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/BufferManagement/BufferAllocation_1.c index cf0fa11054..a7d6b73105 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/BufferManagement/BufferAllocation_1.c +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/BufferManagement/BufferAllocation_1.c @@ -1,5 +1,5 @@ /* -FreeRTOS+TCP V2.2.1 +FreeRTOS+TCP V2.2.2 Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of @@ -161,7 +161,8 @@ section macros. */ BaseType_t xNetworkBuffersInitialise( void ) { -BaseType_t xReturn, x; +BaseType_t xReturn; +uint32_t x; /* Only initialise the buffers and their associated kernel objects if they have not been initialised before. */ @@ -182,7 +183,7 @@ BaseType_t xReturn, x; from the network interface, and different hardware has different requirements. */ vNetworkInterfaceAllocateRAMToBuffers( xNetworkBuffers ); - for( x = 0; x < ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS; x++ ) + for( x = 0U; x < ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS; x++ ) { /* Initialise and set the owner of the buffer list items. */ vListInitialiseItem( &( xNetworkBuffers[ x ].xBufferListItem ) ); diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/BufferManagement/BufferAllocation_2.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/BufferManagement/BufferAllocation_2.c index d8d95e64f4..8d5ce8a6aa 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/BufferManagement/BufferAllocation_2.c +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/BufferManagement/BufferAllocation_2.c @@ -1,5 +1,5 @@ /* - * FreeRTOS+TCP V2.2.1 + * FreeRTOS+TCP V2.2.2 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of @@ -95,7 +95,8 @@ static SemaphoreHandle_t xNetworkBufferSemaphore = NULL; BaseType_t xNetworkBuffersInitialise( void ) { -BaseType_t xReturn, x; +BaseType_t xReturn; +uint32_t x; /* Only initialise the buffers and their associated kernel objects if they have not been initialised before. */ @@ -126,7 +127,7 @@ BaseType_t xReturn, x; /* Initialise all the network buffers. No storage is allocated to the buffers yet. */ - for( x = 0; x < ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS; x++ ) + for( x = 0U; x < ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS; x++ ) { /* Initialise and set the owner of the buffer list items. */ xNetworkBufferDescriptors[ x ].pucEthernetBuffer = NULL; @@ -248,7 +249,7 @@ size_t uxCount; /* Allocate storage of exactly the requested size to the buffer. */ configASSERT( pxReturn->pucEthernetBuffer == NULL ); - if( xRequestedSizeBytes > 0 ) + if( xRequestedSizeBytes > 0U ) { /* Extra space is obtained so a pointer to the network buffer can be stored at the beginning of the buffer. */ diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/CompilerName/pack_struct_end.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/CompilerName/pack_struct_end.h index 5128b7a433..2312db49cb 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/CompilerName/pack_struct_end.h +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/CompilerName/pack_struct_end.h @@ -1,5 +1,5 @@ /* -FreeRTOS+TCP V2.2.1 +FreeRTOS+TCP V2.2.2 Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/CompilerName/pack_struct_start.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/CompilerName/pack_struct_start.h index dedf3d2451..6e875dfaa6 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/CompilerName/pack_struct_start.h +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/CompilerName/pack_struct_start.h @@ -1,5 +1,5 @@ /* -FreeRTOS+TCP V2.2.1 +FreeRTOS+TCP V2.2.2 Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/GCC/pack_struct_end.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/GCC/pack_struct_end.h index fa9dacae73..9d2f72eaf6 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/GCC/pack_struct_end.h +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/GCC/pack_struct_end.h @@ -1,5 +1,5 @@ /* -FreeRTOS+TCP V2.2.1 +FreeRTOS+TCP V2.2.2 Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/GCC/pack_struct_start.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/GCC/pack_struct_start.h index c928843bdd..c244d0f7b2 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/GCC/pack_struct_start.h +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/GCC/pack_struct_start.h @@ -1,5 +1,5 @@ /* -FreeRTOS+TCP V2.2.1 +FreeRTOS+TCP V2.2.2 Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/IAR/pack_struct_end.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/IAR/pack_struct_end.h index 0ce830b0a4..3e521c8733 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/IAR/pack_struct_end.h +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/IAR/pack_struct_end.h @@ -1,5 +1,5 @@ /* -FreeRTOS+TCP V2.2.1 +FreeRTOS+TCP V2.2.2 Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/IAR/pack_struct_start.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/IAR/pack_struct_start.h index a2f7067bdf..574dd013a1 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/IAR/pack_struct_start.h +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/IAR/pack_struct_start.h @@ -1,5 +1,5 @@ /* -FreeRTOS+TCP V2.2.1 +FreeRTOS+TCP V2.2.2 Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/Keil/pack_struct_end.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/Keil/pack_struct_end.h index 4038d6d6cb..cebc68a4e8 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/Keil/pack_struct_end.h +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/Keil/pack_struct_end.h @@ -1,5 +1,5 @@ /* -FreeRTOS+TCP V2.2.1 +FreeRTOS+TCP V2.2.2 Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/Keil/pack_struct_start.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/Keil/pack_struct_start.h index 58b94dc25a..923edb82a4 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/Keil/pack_struct_start.h +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/Keil/pack_struct_start.h @@ -1,5 +1,5 @@ /* -FreeRTOS+TCP V2.2.1 +FreeRTOS+TCP V2.2.2 Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/MSVC/pack_struct_end.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/MSVC/pack_struct_end.h index 9ff11b17fd..5a505c17ce 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/MSVC/pack_struct_end.h +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/MSVC/pack_struct_end.h @@ -1,5 +1,5 @@ /* -FreeRTOS+TCP V2.2.1 +FreeRTOS+TCP V2.2.2 Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/MSVC/pack_struct_start.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/MSVC/pack_struct_start.h index f20565e0c8..0c82e4bfd8 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/MSVC/pack_struct_start.h +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/MSVC/pack_struct_start.h @@ -1,5 +1,5 @@ /* -FreeRTOS+TCP V2.2.1 +FreeRTOS+TCP V2.2.2 Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/Renesas/pack_struct_end.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/Renesas/pack_struct_end.h index eab452ba08..ecbb3e81cb 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/Renesas/pack_struct_end.h +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/Renesas/pack_struct_end.h @@ -1,5 +1,5 @@ /* -FreeRTOS+TCP V2.2.1 +FreeRTOS+TCP V2.2.2 Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/Renesas/pack_struct_start.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/Renesas/pack_struct_start.h index 1044e53d17..efe54ae91c 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/Renesas/pack_struct_start.h +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/Renesas/pack_struct_start.h @@ -1,5 +1,5 @@ /* -FreeRTOS+TCP V2.2.1 +FreeRTOS+TCP V2.2.2 Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/ATSAM4E/NetworkInterface.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/ATSAM4E/NetworkInterface.c index dc70ed9935..987d11a08e 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/ATSAM4E/NetworkInterface.c +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/ATSAM4E/NetworkInterface.c @@ -1,5 +1,5 @@ /* -FreeRTOS+TCP V2.2.1 +FreeRTOS+TCP V2.2.2 Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/DriverSAM/NetworkInterface.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/DriverSAM/NetworkInterface.c index 543cc1d626..6157acb935 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/DriverSAM/NetworkInterface.c +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/DriverSAM/NetworkInterface.c @@ -1,5 +1,5 @@ /* -FreeRTOS+TCP V2.2.1 +FreeRTOS+TCP V2.2.2 Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/LPC17xx/NetworkInterface.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/LPC17xx/NetworkInterface.c index 8bd5396148..b2bd88e9f9 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/LPC17xx/NetworkInterface.c +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/LPC17xx/NetworkInterface.c @@ -1,5 +1,5 @@ /* -FreeRTOS+TCP V2.2.1 +FreeRTOS+TCP V2.2.2 Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/LPC18xx/NetworkInterface.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/LPC18xx/NetworkInterface.c index e01602b9de..35daa493ee 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/LPC18xx/NetworkInterface.c +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/LPC18xx/NetworkInterface.c @@ -1,5 +1,5 @@ /* -FreeRTOS+TCP V2.2.1 +FreeRTOS+TCP V2.2.2 Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/M487/NetworkInterface.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/M487/NetworkInterface.c index 2149a7bdd3..09a2aa2c0b 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/M487/NetworkInterface.c +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/M487/NetworkInterface.c @@ -1,5 +1,5 @@ /* -FreeRTOS+TCP V2.2.1 +FreeRTOS+TCP V2.2.2 Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/SH2A/NetworkInterface.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/SH2A/NetworkInterface.c index 92b1573f7d..4a5a850c85 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/SH2A/NetworkInterface.c +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/SH2A/NetworkInterface.c @@ -1,5 +1,5 @@ /* -FreeRTOS+TCP V2.2.1 +FreeRTOS+TCP V2.2.2 Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/STM32Fxx/NetworkInterface.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/STM32Fxx/NetworkInterface.c index aa3a1f58ed..21fb3cdab4 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/STM32Fxx/NetworkInterface.c +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/STM32Fxx/NetworkInterface.c @@ -4,7 +4,7 @@ */ /* -FreeRTOS+TCP V2.2.1 +FreeRTOS+TCP V2.2.2 Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/WinPCap/NetworkInterface.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/WinPCap/NetworkInterface.c index 511b27859e..66b9f1cb94 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/WinPCap/NetworkInterface.c +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/WinPCap/NetworkInterface.c @@ -1,5 +1,5 @@ /* -FreeRTOS+TCP V2.2.1 +FreeRTOS+TCP V2.2.2 Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/board_family/NetworkInterface.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/board_family/NetworkInterface.c index 251640d7e8..4564ad95f9 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/board_family/NetworkInterface.c +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/board_family/NetworkInterface.c @@ -1,5 +1,5 @@ /* -FreeRTOS+TCP V2.2.1 +FreeRTOS+TCP V2.2.2 Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/ksz8851snl/NetworkInterface.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/ksz8851snl/NetworkInterface.c index 4df3ac3702..1b6f3aac70 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/ksz8851snl/NetworkInterface.c +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/ksz8851snl/NetworkInterface.c @@ -1,5 +1,5 @@ /* -FreeRTOS+TCP V2.2.1 +FreeRTOS+TCP V2.2.2 Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/linux/NetworkInterface.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/linux/NetworkInterface.c index 41f28a0d27..4669ad35d7 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/linux/NetworkInterface.c +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/linux/NetworkInterface.c @@ -44,12 +44,11 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include #include #include -#include #include #include /* ========================== Local includes =================================*/ -#include "utils/wait_for_event.h" +#include /* ======================== Macro Definitions =============================== */ #if ( ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES == 0 ) diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/mw300_rd/NetworkInterface.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/mw300_rd/NetworkInterface.c index f6d152a8c8..fdb0933528 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/mw300_rd/NetworkInterface.c +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/mw300_rd/NetworkInterface.c @@ -1,5 +1,5 @@ /* -FreeRTOS+TCP V2.2.1 +FreeRTOS+TCP V2.2.2 Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/tools/tcp_dump_packets.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/tools/tcp_dump_packets.c index 8ac6cdb1f2..876e6c9970 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/tools/tcp_dump_packets.c +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/tools/tcp_dump_packets.c @@ -1,5 +1,5 @@ /* - * FreeRTOS+TCP V2.2.1 + * FreeRTOS+TCP V2.2.2 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/tools/tcp_mem_stats.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/tools/tcp_mem_stats.c index d4929b3fa0..d387294c74 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/tools/tcp_mem_stats.c +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/tools/tcp_mem_stats.c @@ -1,5 +1,5 @@ /* - * FreeRTOS+TCP V2.2.1 + * FreeRTOS+TCP V2.2.2 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of diff --git a/FreeRTOS-Plus/Test/CBMC/include/queue_init.h b/FreeRTOS-Plus/Test/CBMC/include/queue_init.h index f05d18830e..10b7e5607f 100644 --- a/FreeRTOS-Plus/Test/CBMC/include/queue_init.h +++ b/FreeRTOS-Plus/Test/CBMC/include/queue_init.h @@ -43,6 +43,7 @@ if( xSet ) { xSet->cTxLock = nondet_int8_t(); + __CPROVER_assume(xSet->cTxLock != 127); xSet->cRxLock = nondet_int8_t(); xSet->uxMessagesWaiting = nondet_UBaseType_t(); xSet->xTasksWaitingToReceive.uxNumberOfItems = nondet_UBaseType_t(); @@ -73,6 +74,7 @@ QueueHandle_t xUnconstrainedQueueBoundedItemSize( UBaseType_t uxItemSizeBound ) xQueueGenericCreate(uxQueueLength, uxItemSize, ucQueueType); if(xQueue){ xQueue->cTxLock = nondet_int8_t(); + __CPROVER_assume(xQueue->cTxLock != 127); xQueue->cRxLock = nondet_int8_t(); xQueue->uxMessagesWaiting = nondet_UBaseType_t(); /* This is an invariant checked with a couple of asserts in the code base. @@ -105,6 +107,7 @@ QueueHandle_t xUnconstrainedQueue( void ) { if(xQueue){ xQueue->cTxLock = nondet_int8_t(); + __CPROVER_assume(xQueue->cTxLock != 127); xQueue->cRxLock = nondet_int8_t(); xQueue->uxMessagesWaiting = nondet_UBaseType_t(); /* This is an invariant checked with a couple of asserts in the code base. @@ -126,6 +129,7 @@ QueueHandle_t xUnconstrainedMutex( void ) { xQueueCreateMutex(ucQueueType); if(xQueue){ xQueue->cTxLock = nondet_int8_t(); + __CPROVER_assume(xQueue->cTxLock != 127); xQueue->cRxLock = nondet_int8_t(); xQueue->uxMessagesWaiting = nondet_UBaseType_t(); /* This is an invariant checked with a couple of asserts in the code base. diff --git a/FreeRTOS-Plus/Test/CBMC/proofs/prvProcessEthernetPacket/Makefile.json b/FreeRTOS-Plus/Test/CBMC/proofs/prvProcessEthernetPacket/Makefile.json new file mode 100644 index 0000000000..7c7af99859 --- /dev/null +++ b/FreeRTOS-Plus/Test/CBMC/proofs/prvProcessEthernetPacket/Makefile.json @@ -0,0 +1,32 @@ +{ + "ENTRY": "prvProcessEthernetPacket", + "CBMCFLAGS": + [ + "--unwind 1", + "--unwindset prvTCPSendRepeated.0:13", + "--nondet-static", + "--flush" + ], + "OBJS": + [ + "$(ENTRY)_harness.goto", + "$(FREERTOS)/../FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_IP.goto" + ], + "INSTFLAGS": + [ + ], + "OPT": + [ + "--export-file-local-symbols" + ], + "DEF": + [ + "FREERTOS_TCP_ENABLE_VERIFICATION" + ], + "INC": + [ + "$(FREERTOS)/../FreeRTOS-Plus/Test/CBMC/include", + "$(FREERTOS)/../FreeRTOS-Plus/Test/CBMC/proofs/utility", + "$(FREERTOS)/../FreeRTOS-Plus/Test/CBMC/stubs" + ] +} diff --git a/FreeRTOS-Plus/Test/CBMC/proofs/prvProcessEthernetPacket/prvProcessEthernetPacket_harness.c b/FreeRTOS-Plus/Test/CBMC/proofs/prvProcessEthernetPacket/prvProcessEthernetPacket_harness.c new file mode 100644 index 0000000000..c70bfaa94e --- /dev/null +++ b/FreeRTOS-Plus/Test/CBMC/proofs/prvProcessEthernetPacket/prvProcessEthernetPacket_harness.c @@ -0,0 +1,63 @@ +/* Standard includes. */ +#include +#include + +/* FreeRTOS includes. */ +#include "FreeRTOS.h" +#include "task.h" +#include "queue.h" +#include "semphr.h" + +/* FreeRTOS+TCP includes. */ +#include "FreeRTOS_IP.h" +#include "FreeRTOS_Sockets.h" +#include "FreeRTOS_IP_Private.h" +#include "FreeRTOS_UDP_IP.h" +#include "FreeRTOS_DHCP.h" +#include "NetworkInterface.h" +#include "NetworkBufferManagement.h" +#include "FreeRTOS_ARP.h" + +#include "memory_assignments.c" +#include "freertos_api.c" + +/**************************************************************** + * Signature of function under test + ****************************************************************/ +void __CPROVER_file_local_FreeRTOS_IP_c_prvProcessEthernetPacket( NetworkBufferDescriptor_t * const pxNetworkBuffer ); + + +/* This function has been proved to be memory safe in another proof (in ARP/ARPRefreshCacheEntry). Hence we assume it to be correct here. */ +void vARPRefreshCacheEntry( const MACAddress_t * pxMACAddress, const uint32_t ulIPAddress ) +{ + /* pxMACAddress can be NULL or non-NULL. No need to assert. */ +} + +/* This function has been proved to be memory safe in another proof (in ARP/ARPProcessPacket). Hence we assume it to be correct here. */ +eFrameProcessingResult_t eARPProcessPacket( ARPPacket_t * const pxARPFrame ) +{ + __CPROVER_assert( pxARPFrame != NULL, "pxARPFrame cannot be NULL" ); + + eFrameProcessingResult_t eReturn; + return eReturn; +} + +/* This function has been proved to be memory safe in another proof (in parsing/ProcessIPPacket). Hence we assume it to be correct here. */ +eFrameProcessingResult_t __CPROVER_file_local_FreeRTOS_IP_c_prvProcessIPPacket( IPPacket_t * pxIPPacket, NetworkBufferDescriptor_t * const pxNetworkBuffer ) +{ + __CPROVER_assert( pxIPPacket != NULL, "pxIPPacket cannot be NULL" ); + __CPROVER_assert( pxNetworkBuffer != NULL, "pxNetworkBuffer cannot be NULL" ); + + eFrameProcessingResult_t result; + return result; +} + +void harness() { + + NetworkBufferDescriptor_t * const pxNetworkBuffer = pxGetNetworkBufferWithDescriptor( ipTOTAL_ETHERNET_FRAME_SIZE, 0 ); + + /* The network buffer cannot be NULL for this function call. If it is, it will hit an assert in the function. */ + __CPROVER_assume( pxNetworkBuffer != NULL ); + + __CPROVER_file_local_FreeRTOS_IP_c_prvProcessEthernetPacket( pxNetworkBuffer ); +} diff --git a/FreeRTOS-Plus/Test/CBMC/proofs/utility/memory_assignments.c b/FreeRTOS-Plus/Test/CBMC/proofs/utility/memory_assignments.c index 6bcb9319a2..9866eff264 100644 --- a/FreeRTOS-Plus/Test/CBMC/proofs/utility/memory_assignments.c +++ b/FreeRTOS-Plus/Test/CBMC/proofs/utility/memory_assignments.c @@ -1,3 +1,5 @@ +#include + #define ensure_memory_is_valid( px, length ) (px != NULL) && __CPROVER_w_ok((px), length) /* Implementation of safe malloc which returns NULL if the requested size is 0. diff --git a/FreeRTOS-Plus/Test/CBMC/windows2/winbase.h b/FreeRTOS-Plus/Test/CBMC/windows2/winbase.h new file mode 100644 index 0000000000..c89d1caa5e --- /dev/null +++ b/FreeRTOS-Plus/Test/CBMC/windows2/winbase.h @@ -0,0 +1 @@ +/* Empty file for CBMC. */ diff --git a/FreeRTOS/Demo/AVR_ATMega4809_Atmel_Studio/RTOSDemo/main.c b/FreeRTOS/Demo/AVR_ATMega4809_Atmel_Studio/RTOSDemo/main.c index aa2dd84d93..e7e32f0943 100644 --- a/FreeRTOS/Demo/AVR_ATMega4809_Atmel_Studio/RTOSDemo/main.c +++ b/FreeRTOS/Demo/AVR_ATMega4809_Atmel_Studio/RTOSDemo/main.c @@ -51,7 +51,7 @@ int main( void ) #elif ( mainSELECTED_APPLICATION == 2 ) main_full(); #endif - + return 0; } @@ -78,7 +78,7 @@ This is usefull in application development, for debugging. To use this hook, uncomment it, and set configCHECK_FOR_STACK_OVERFLOW to 1 in "FreeRTOSConfig.h" header file. */ -// void vApplicationStackOverflowHook(TaskHandle_t *pxTask, signed char *pcTaskName ) +// void vApplicationStackOverflowHook(TaskHandle_t *pxTask, char *pcTaskName ) // { // for( ;; ); // } diff --git a/FreeRTOS/Demo/AVR_ATMega4809_IAR/main.c b/FreeRTOS/Demo/AVR_ATMega4809_IAR/main.c index 27e816e106..a19870dc52 100644 --- a/FreeRTOS/Demo/AVR_ATMega4809_IAR/main.c +++ b/FreeRTOS/Demo/AVR_ATMega4809_IAR/main.c @@ -43,7 +43,7 @@ extern void init_full( void ); int main( void ) { prvSetupHardware(); - + #if ( mainSELECTED_APPLICATION == 0 ) main_blinky(); #elif ( mainSELECTED_APPLICATION == 1 ) @@ -51,7 +51,7 @@ int main( void ) #elif ( mainSELECTED_APPLICATION == 2 ) main_full(); #endif - + return 0; } @@ -78,7 +78,7 @@ This is usefull in application development, for debugging. To use this hook, uncomment it, and set configCHECK_FOR_STACK_OVERFLOW to 1 in "FreeRTOSConfig.h" header file. */ -// void vApplicationStackOverflowHook(TaskHandle_t *pxTask, signed char *pcTaskName ) +// void vApplicationStackOverflowHook(TaskHandle_t *pxTask, char *pcTaskName ) // { // for( ;; ); // } diff --git a/FreeRTOS/Demo/AVR_ATMega4809_MPLAB.X/main.c b/FreeRTOS/Demo/AVR_ATMega4809_MPLAB.X/main.c index aa2dd84d93..e7e32f0943 100644 --- a/FreeRTOS/Demo/AVR_ATMega4809_MPLAB.X/main.c +++ b/FreeRTOS/Demo/AVR_ATMega4809_MPLAB.X/main.c @@ -51,7 +51,7 @@ int main( void ) #elif ( mainSELECTED_APPLICATION == 2 ) main_full(); #endif - + return 0; } @@ -78,7 +78,7 @@ This is usefull in application development, for debugging. To use this hook, uncomment it, and set configCHECK_FOR_STACK_OVERFLOW to 1 in "FreeRTOSConfig.h" header file. */ -// void vApplicationStackOverflowHook(TaskHandle_t *pxTask, signed char *pcTaskName ) +// void vApplicationStackOverflowHook(TaskHandle_t *pxTask, char *pcTaskName ) // { // for( ;; ); // } diff --git a/FreeRTOS/Demo/AVR_ATmega328PB_Xplained_mini_GCC/RTOSDemo/main.c b/FreeRTOS/Demo/AVR_ATmega328PB_Xplained_mini_GCC/RTOSDemo/main.c index fe5702f05c..1a968b2652 100644 --- a/FreeRTOS/Demo/AVR_ATmega328PB_Xplained_mini_GCC/RTOSDemo/main.c +++ b/FreeRTOS/Demo/AVR_ATmega328PB_Xplained_mini_GCC/RTOSDemo/main.c @@ -59,10 +59,10 @@ int main(void) /* Initializes MCU, drivers and middleware. This is generated from Atmel START project. */ atmel_start_init(); - + /* Standard register test. */ vStartRegTestTasks(); - + /* Optionally enable below tests. This port only has 2KB RAM. */ vStartIntegerMathTasks( tskIDLE_PRIORITY ); vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY ); @@ -102,7 +102,7 @@ BaseType_t xFirstTimeCheck = pdTRUE; { uxErrorHasOccurred |= ( 0x01U << 2); } - + /* When check task runs before any other tasks, all above checks shall fail. To avoid false alarm, clear errors upon first entry. */ if ( xFirstTimeCheck == pdTRUE ) @@ -110,7 +110,7 @@ BaseType_t xFirstTimeCheck = pdTRUE; uxErrorHasOccurred = 0; xFirstTimeCheck = pdFALSE; } - + /* Could set break point at below line to verify uxErrorHasOccurred. */ vTaskDelay( mainCHECK_PERIOD ); } @@ -126,7 +126,7 @@ static void vBlinkOnboardUserLED( void *pvParameters ) for( ;; ) { vParTestToggleLED( 0 ); - + vTaskDelay( mainBLINK_LED_OK_HALF_PERIOD ); } @@ -141,9 +141,9 @@ void vApplicationIdleHook( void ) /*-----------------------------------------------------------*/ -void vApplicationStackOverflowHook( TaskHandle_t xTask, signed char *pcTaskName ) +void vApplicationStackOverflowHook( TaskHandle_t xTask, char *pcTaskName ) { - /* When stack overflow happens, trap instead of attempting to recover. + /* When stack overflow happens, trap instead of attempting to recover. Read input arguments to learn about the offending task. */ for( ;; ) { diff --git a/FreeRTOS/Demo/AVR_Dx_Atmel_Studio/RTOSDemo/main.c b/FreeRTOS/Demo/AVR_Dx_Atmel_Studio/RTOSDemo/main.c index aa2dd84d93..e7e32f0943 100644 --- a/FreeRTOS/Demo/AVR_Dx_Atmel_Studio/RTOSDemo/main.c +++ b/FreeRTOS/Demo/AVR_Dx_Atmel_Studio/RTOSDemo/main.c @@ -51,7 +51,7 @@ int main( void ) #elif ( mainSELECTED_APPLICATION == 2 ) main_full(); #endif - + return 0; } @@ -78,7 +78,7 @@ This is usefull in application development, for debugging. To use this hook, uncomment it, and set configCHECK_FOR_STACK_OVERFLOW to 1 in "FreeRTOSConfig.h" header file. */ -// void vApplicationStackOverflowHook(TaskHandle_t *pxTask, signed char *pcTaskName ) +// void vApplicationStackOverflowHook(TaskHandle_t *pxTask, char *pcTaskName ) // { // for( ;; ); // } diff --git a/FreeRTOS/Demo/AVR_Dx_IAR/main.c b/FreeRTOS/Demo/AVR_Dx_IAR/main.c index 27e816e106..a19870dc52 100644 --- a/FreeRTOS/Demo/AVR_Dx_IAR/main.c +++ b/FreeRTOS/Demo/AVR_Dx_IAR/main.c @@ -43,7 +43,7 @@ extern void init_full( void ); int main( void ) { prvSetupHardware(); - + #if ( mainSELECTED_APPLICATION == 0 ) main_blinky(); #elif ( mainSELECTED_APPLICATION == 1 ) @@ -51,7 +51,7 @@ int main( void ) #elif ( mainSELECTED_APPLICATION == 2 ) main_full(); #endif - + return 0; } @@ -78,7 +78,7 @@ This is usefull in application development, for debugging. To use this hook, uncomment it, and set configCHECK_FOR_STACK_OVERFLOW to 1 in "FreeRTOSConfig.h" header file. */ -// void vApplicationStackOverflowHook(TaskHandle_t *pxTask, signed char *pcTaskName ) +// void vApplicationStackOverflowHook(TaskHandle_t *pxTask, char *pcTaskName ) // { // for( ;; ); // } diff --git a/FreeRTOS/Demo/AVR_Dx_MPLAB.X/main.c b/FreeRTOS/Demo/AVR_Dx_MPLAB.X/main.c index aa2dd84d93..8d7412fe11 100644 --- a/FreeRTOS/Demo/AVR_Dx_MPLAB.X/main.c +++ b/FreeRTOS/Demo/AVR_Dx_MPLAB.X/main.c @@ -78,7 +78,7 @@ This is usefull in application development, for debugging. To use this hook, uncomment it, and set configCHECK_FOR_STACK_OVERFLOW to 1 in "FreeRTOSConfig.h" header file. */ -// void vApplicationStackOverflowHook(TaskHandle_t *pxTask, signed char *pcTaskName ) +// void vApplicationStackOverflowHook(TaskHandle_t *pxTask, char *pcTaskName ) // { // for( ;; ); // } diff --git a/FreeRTOS/Demo/CORTEX_LM3S6965_GCC_QEMU/.settings/language.settings.xml b/FreeRTOS/Demo/CORTEX_LM3S6965_GCC_QEMU/.settings/language.settings.xml index fe0e11ea46..19d9a19240 100644 --- a/FreeRTOS/Demo/CORTEX_LM3S6965_GCC_QEMU/.settings/language.settings.xml +++ b/FreeRTOS/Demo/CORTEX_LM3S6965_GCC_QEMU/.settings/language.settings.xml @@ -5,7 +5,7 @@ - + diff --git a/FreeRTOS/Demo/CORTEX_LM3S6965_GCC_QEMU/RTOSDemo Debug.launch b/FreeRTOS/Demo/CORTEX_LM3S6965_GCC_QEMU/RTOSDemo Debug.launch index 8833e2ab5e..38afff0e1b 100644 --- a/FreeRTOS/Demo/CORTEX_LM3S6965_GCC_QEMU/RTOSDemo Debug.launch +++ b/FreeRTOS/Demo/CORTEX_LM3S6965_GCC_QEMU/RTOSDemo Debug.launch @@ -31,7 +31,7 @@ - + diff --git a/FreeRTOS/Demo/CORTEX_LM3S6965_GCC_QEMU/main.c b/FreeRTOS/Demo/CORTEX_LM3S6965_GCC_QEMU/main.c index 13443156d4..29d9d3031f 100644 --- a/FreeRTOS/Demo/CORTEX_LM3S6965_GCC_QEMU/main.c +++ b/FreeRTOS/Demo/CORTEX_LM3S6965_GCC_QEMU/main.c @@ -158,7 +158,7 @@ extern void vSetupHighFrequencyTimer( void ); /* * Hook functions that can get called by the kernel. */ -void vApplicationStackOverflowHook( TaskHandle_t *pxTask, signed char *pcTaskName ); +void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName ); void vApplicationTickHook( void ); /* @@ -379,8 +379,8 @@ void ( *vOLEDClear )( void ) = NULL; } /*-----------------------------------------------------------*/ -volatile signed char *pcOverflowedTask = NULL; /* Prevent task name being optimised away. */ -void vApplicationStackOverflowHook( TaskHandle_t *pxTask, signed char *pcTaskName ) +volatile char *pcOverflowedTask = NULL; /* Prevent task name being optimised away. */ +void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName ) { ( void ) pxTask; pcOverflowedTask = pcTaskName; diff --git a/FreeRTOS/Demo/CORTEX_LM3Sxxxx_IAR_Keil/main.c b/FreeRTOS/Demo/CORTEX_LM3Sxxxx_IAR_Keil/main.c index 4e39a252c0..e0be52c690 100644 --- a/FreeRTOS/Demo/CORTEX_LM3Sxxxx_IAR_Keil/main.c +++ b/FreeRTOS/Demo/CORTEX_LM3Sxxxx_IAR_Keil/main.c @@ -185,7 +185,7 @@ extern void vSetupHighFrequencyTimer( void ); /* * Hook functions that can get called by the kernel. */ -void vApplicationStackOverflowHook( TaskHandle_t *pxTask, signed char *pcTaskName ); +void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName ); void vApplicationTickHook( void ); static void prvPrintString( const char * pcString ); @@ -453,8 +453,8 @@ void ( *vOLEDClear )( void ) = NULL; } /*-----------------------------------------------------------*/ -volatile signed char *pcOverflowedTask = NULL; -void vApplicationStackOverflowHook( TaskHandle_t *pxTask, signed char *pcTaskName ) +volatile char *pcOverflowedTask = NULL; +void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName ) { ( void ) pxTask; pcOverflowedTask = pcTaskName; diff --git a/FreeRTOS/Demo/CORTEX_MPU_M23_Nuvoton_NuMaker_PFM_M2351_IAR_GCC/Projects/IAR/NonSecure/main_ns.c b/FreeRTOS/Demo/CORTEX_MPU_M23_Nuvoton_NuMaker_PFM_M2351_IAR_GCC/Projects/IAR/NonSecure/main_ns.c index 47ddbf6015..39151caaf4 100644 --- a/FreeRTOS/Demo/CORTEX_MPU_M23_Nuvoton_NuMaker_PFM_M2351_IAR_GCC/Projects/IAR/NonSecure/main_ns.c +++ b/FreeRTOS/Demo/CORTEX_MPU_M23_Nuvoton_NuMaker_PFM_M2351_IAR_GCC/Projects/IAR/NonSecure/main_ns.c @@ -88,7 +88,7 @@ static void prvCreateTasks( void ) /*-----------------------------------------------------------*/ /* Stack overflow hook. */ -void vApplicationStackOverflowHook( TaskHandle_t xTask, signed char *pcTaskName ) +void vApplicationStackOverflowHook( TaskHandle_t xTask, char *pcTaskName ) { /* Force an assert. */ configASSERT( pcTaskName == 0 ); diff --git a/FreeRTOS/Demo/CORTEX_MPU_M23_Nuvoton_NuMaker_PFM_M2351_IAR_GCC/Projects/Keil/NonSecure/main_ns.c b/FreeRTOS/Demo/CORTEX_MPU_M23_Nuvoton_NuMaker_PFM_M2351_IAR_GCC/Projects/Keil/NonSecure/main_ns.c index 757524f01a..6f63f48eb9 100644 --- a/FreeRTOS/Demo/CORTEX_MPU_M23_Nuvoton_NuMaker_PFM_M2351_IAR_GCC/Projects/Keil/NonSecure/main_ns.c +++ b/FreeRTOS/Demo/CORTEX_MPU_M23_Nuvoton_NuMaker_PFM_M2351_IAR_GCC/Projects/Keil/NonSecure/main_ns.c @@ -131,7 +131,7 @@ static void prvCreateTasks( void ) /*-----------------------------------------------------------*/ /* Stack overflow hook. */ -void vApplicationStackOverflowHook( TaskHandle_t xTask, signed char *pcTaskName ) +void vApplicationStackOverflowHook( TaskHandle_t xTask, char *pcTaskName ) { /* Force an assert. */ configASSERT( pcTaskName == 0 ); diff --git a/FreeRTOS/Demo/CORTEX_MPU_M33F_NXP_LPC55S69_MCUXpresso/Projects/MCUXpresso/NonSecure/main_ns.c b/FreeRTOS/Demo/CORTEX_MPU_M33F_NXP_LPC55S69_MCUXpresso/Projects/MCUXpresso/NonSecure/main_ns.c index 834fbe80f3..e426bf5b03 100644 --- a/FreeRTOS/Demo/CORTEX_MPU_M33F_NXP_LPC55S69_MCUXpresso/Projects/MCUXpresso/NonSecure/main_ns.c +++ b/FreeRTOS/Demo/CORTEX_MPU_M33F_NXP_LPC55S69_MCUXpresso/Projects/MCUXpresso/NonSecure/main_ns.c @@ -101,7 +101,7 @@ void SystemInit( void ) /*-----------------------------------------------------------*/ /* Stack overflow hook. */ -void vApplicationStackOverflowHook( TaskHandle_t xTask, signed char *pcTaskName ) +void vApplicationStackOverflowHook( TaskHandle_t xTask, char *pcTaskName ) { /* Force an assert. */ configASSERT( pcTaskName == 0 ); diff --git a/FreeRTOS/Demo/CORTEX_MPU_M33F_Simulator_Keil_GCC/NonSecure/main_ns.c b/FreeRTOS/Demo/CORTEX_MPU_M33F_Simulator_Keil_GCC/NonSecure/main_ns.c index da49146546..c0eb37de3d 100644 --- a/FreeRTOS/Demo/CORTEX_MPU_M33F_Simulator_Keil_GCC/NonSecure/main_ns.c +++ b/FreeRTOS/Demo/CORTEX_MPU_M33F_Simulator_Keil_GCC/NonSecure/main_ns.c @@ -126,7 +126,7 @@ static void prvCreateTasks( void ) /*-----------------------------------------------------------*/ /* Stack overflow hook. */ -void vApplicationStackOverflowHook( TaskHandle_t xTask, signed char *pcTaskName ) +void vApplicationStackOverflowHook( TaskHandle_t xTask, char *pcTaskName ) { /* Force an assert. */ configASSERT( pcTaskName == 0 ); diff --git a/FreeRTOS/Demo/ColdFire_MCF52221_CodeWarrior/sources/main.c b/FreeRTOS/Demo/ColdFire_MCF52221_CodeWarrior/sources/main.c index ebdf052714..39f9556961 100644 --- a/FreeRTOS/Demo/ColdFire_MCF52221_CodeWarrior/sources/main.c +++ b/FreeRTOS/Demo/ColdFire_MCF52221_CodeWarrior/sources/main.c @@ -238,7 +238,7 @@ void prvSetupHardware( void ) } /*-----------------------------------------------------------*/ -void vApplicationStackOverflowHook( TaskHandle_t *pxTask, signed char *pcTaskName ) +void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName ) { /* This will get called if a stack overflow is detected during the context switch. Set configCHECK_FOR_STACK_OVERFLOWS to 2 to also check for stack diff --git a/FreeRTOS/Demo/ColdFire_MCF52233_Eclipse/RTOSDemo/main.c b/FreeRTOS/Demo/ColdFire_MCF52233_Eclipse/RTOSDemo/main.c index 562aa911e0..99b2830eab 100644 --- a/FreeRTOS/Demo/ColdFire_MCF52233_Eclipse/RTOSDemo/main.c +++ b/FreeRTOS/Demo/ColdFire_MCF52233_Eclipse/RTOSDemo/main.c @@ -285,7 +285,7 @@ static const unsigned long _cfm[6] = { } /*-----------------------------------------------------------*/ -void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed char *pcTaskName ) +void vApplicationStackOverflowHook( xTaskHandle pxTask, char *pcTaskName ) { /* This will get called if a stack overflow is detected during the context switch. Set configCHECK_FOR_STACK_OVERFLOWS to 2 to also check for stack diff --git a/FreeRTOS/Demo/ColdFire_MCF52259_CodeWarrior/main.c b/FreeRTOS/Demo/ColdFire_MCF52259_CodeWarrior/main.c index 9b3fe51082..5d331d33dc 100644 --- a/FreeRTOS/Demo/ColdFire_MCF52259_CodeWarrior/main.c +++ b/FreeRTOS/Demo/ColdFire_MCF52259_CodeWarrior/main.c @@ -253,7 +253,7 @@ void prvSetupHardware( void ) } /*-----------------------------------------------------------*/ -void vApplicationStackOverflowHook( TaskHandle_t *pxTask, signed char *pcTaskName ) +void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName ) { /* This will get called if a stack overflow is detected during the context switch. Set configCHECK_FOR_STACK_OVERFLOWS to 2 to also check for stack diff --git a/FreeRTOS/Demo/Common/Minimal/TaskNotifyArray.c b/FreeRTOS/Demo/Common/Minimal/TaskNotifyArray.c index a8789e3018..0990710ab4 100644 --- a/FreeRTOS/Demo/Common/Minimal/TaskNotifyArray.c +++ b/FreeRTOS/Demo/Common/Minimal/TaskNotifyArray.c @@ -1131,7 +1131,7 @@ const TickType_t xDontBlock = 0; void xNotifyArrayTaskFromISR( void ) { -static BaseType_t xCallCount = 0, xAPIToUse = 0; +static BaseType_t xAPIToUse = 0; uint32_t ulPreviousValue; const uint32_t ulUnexpectedValue = 0xff; static UBaseType_t uxIndexToNotify = 0; @@ -1146,9 +1146,6 @@ static UBaseType_t uxIndexToNotify = 0; { xSendNotificationFromISR = pdFALSE; - /* It is time to 'give' the notification again. */ - xCallCount = 0; - /* Test using both vTaskNotifyGiveFromISR(), xTaskNotifyFromISR() and xTaskNotifyAndQueryFromISR(). The notification is set to the task notification at index uxIndexToNotify within the array of task diff --git a/FreeRTOS/Demo/NEC_78K0R_IAR/main.c b/FreeRTOS/Demo/NEC_78K0R_IAR/main.c index ecc2223b6d..00b5d3b6fa 100644 --- a/FreeRTOS/Demo/NEC_78K0R_IAR/main.c +++ b/FreeRTOS/Demo/NEC_78K0R_IAR/main.c @@ -150,11 +150,11 @@ short main( void ) /* Create the RegTest tasks as described at the top of this file. */ xTaskCreate( vRegTest1, "Reg1", configMINIMAL_STACK_SIZE, NULL, 0, NULL ); - xTaskCreate( vRegTest2, "Reg2", configMINIMAL_STACK_SIZE, NULL, 0, NULL ); - + xTaskCreate( vRegTest2, "Reg2", configMINIMAL_STACK_SIZE, NULL, 0, NULL ); + /* Create the button push task as described at the top of this file. */ - xTaskCreate( vButtonTask, "Button", configMINIMAL_STACK_SIZE, NULL, mainBUTTON_PRIORITY, NULL ); - + xTaskCreate( vButtonTask, "Button", configMINIMAL_STACK_SIZE, NULL, mainBUTTON_PRIORITY, NULL ); + /* Create the 'check' task as described at the top of this file. */ xTaskCreate( vErrorChecks, "Check", configMINIMAL_STACK_SIZE, ( void* )mainCHECK_PARAMETER_VALUE, mainCHECK_TASK_PRIORITY, NULL ); @@ -167,7 +167,7 @@ short main( void ) vCreateBlockTimeTasks(); } #endif - + /* Finally start the scheduler running. */ vTaskStartScheduler(); @@ -218,24 +218,24 @@ TickType_t xToggleRate = mainNO_ERROR_TOGGLE_PERIOD, xLastWakeTime; { xToggleRate = mainERROR_TOGGLE_PERIOD; } - + if( xAreSemaphoreTasksStillRunning() != pdTRUE) { xToggleRate = mainERROR_TOGGLE_PERIOD; } - + if( xAreGenericQueueTasksStillRunning() != pdTRUE ) { xToggleRate = mainERROR_TOGGLE_PERIOD; - } - + } + if( xAreBlockTimeTestTasksStillRunning() != pdTRUE ) { xToggleRate = mainERROR_TOGGLE_PERIOD; - } + } } #endif - + /* Toggle the LED. The toggle rate will depend on whether or not an error has been found in any tasks. */ mainLED_0 = !mainLED_0; @@ -281,24 +281,24 @@ unsigned char ucResetFlag = RESF; X1 and X2 pin in crystal resonator mode High speed oszillation frequency 10MHz < fMX <= 20MHz */ CMC = 0x41; - + /* Set oscillation stabilization time. */ OSTS = 0x07; - + /* Set speed mode: fMX > 10MHz for Flash memory high speed operation. */ OSMC = 0x01; - + /* Start up X1 oscillator operation Internal high-speed oscillator operating. */ MSTOP = 0; - + /* Check oscillation stabilization time status. */ while(OSTC < 0x07) { /* Wait until X1 clock stabilization time. */ portNOP(); } - + /* Switch CPU clock to X1 oscillator. */ MCM0 = 1; while(MCS != 1) @@ -309,10 +309,10 @@ unsigned char ucResetFlag = RESF; /* Stop the internal high-speed oscillator operation. */ HIOSTOP = 1; - + /* Stop the XT1 oscillator operation. */ XTSTOP = 1; - + /* Operating frequency f = fx Change clock generator setting, if necessary. */ CKC &= 0xF8; @@ -320,31 +320,31 @@ unsigned char ucResetFlag = RESF; /* From here onwards the X1 oscillator is supplied to the CPU. */ } #endif - + /* LED port initialization - set port register. */ P7 = 0x80; - + /* Set port mode register. */ PM7 = 0x3F; - + /* Switch pin initialization - enable pull-up resistor. */ PU12_bit.no0 = 1; /* INTP0 is used by the button on the target board. */ - + /* INTP0 disable. */ - PMK0 = 1; - + PMK0 = 1; + /* INTP0 IF clear. */ - PIF0 = 0; + PIF0 = 0; EGN0_bit.no0 = 1; - + /* INTP0 priority low. */ PPR10 = 0; PPR00 = 1; - + /* Enable ext. INTP0 interrupt */ - PMK0 = 0; + PMK0 = 0; return pdTRUE; } @@ -362,8 +362,11 @@ void vRegTestError( void ) } /*-----------------------------------------------------------*/ -void vApplicationStackOverflowHook( void ) +void vApplicationStackOverflowHook( TaskHandle_t xTask, char *pcTaskName ) { + ( void ) xTask; + ( void ) pcTaskName; + /* This will get called if an overflow is detected in the stack of a task. Inspect pxCurrentTCB to see which was the offending task. */ for( ;; ); diff --git a/FreeRTOS/Demo/NEC_V850ES_IAR/main.c b/FreeRTOS/Demo/NEC_V850ES_IAR/main.c index 684bf5d6a2..fec73376e4 100644 --- a/FreeRTOS/Demo/NEC_V850ES_IAR/main.c +++ b/FreeRTOS/Demo/NEC_V850ES_IAR/main.c @@ -124,7 +124,7 @@ void main( void ) vStartSemaphoreTasks( mainSEM_TEST_PRIORITY ); vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY ); vStartQueuePeekTasks(); - + /* Create the check task as described at the top of this file. */ xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE, mainCHECK_PARAMETER, mainCHECK_TASK_PRIORITY, NULL ); @@ -135,22 +135,22 @@ void main( void ) #ifdef __IAR_V850ES_Fx3__ { /* The extra IO required for the com test and led flashing tasks is only - available on the application board, not the target boards. */ + available on the application board, not the target boards. */ vAltStartComTestTasks( mainCOMTEST_PRIORITY, mainBAUD_RATE, mainCOMTEST_LED ); vStartLEDFlashTasks( mainFLASH_PRIORITY ); - + /* The Fx3 also has enough RAM to run loads more tasks. */ vStartRecursiveMutexTasks(); vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY ); - vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY ); + vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY ); } - #endif - + #endif + /* The suicide tasks must be created last as they need to know how many tasks were running prior to their creation in order to ascertain whether or not the correct/expected number of tasks are running at any given time. */ vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY ); - + /* Start the scheduler. */ vTaskStartScheduler(); @@ -170,23 +170,23 @@ unsigned portBASE_TYPE uxLEDToUse = 0; { xDelayPeriod = mainERROR_DELAY; } - + /* Initialise xLastWakeTime before it is used. After this point it is not written to directly. */ xLastWakeTime = xTaskGetTickCount(); - + /* Cycle for ever, delaying then checking all the other tasks are still operating without error. */ for( ;; ) { /* Wait until it is time to check all the other tasks again. */ vTaskDelayUntil( &xLastWakeTime, xDelayPeriod ); - + if( lRegTestStatus != pdPASS ) { xDelayPeriod = mainERROR_DELAY; } - + if( xAreGenericQueueTasksStillRunning() != pdTRUE ) { xDelayPeriod = mainERROR_DELAY; @@ -207,14 +207,14 @@ unsigned portBASE_TYPE uxLEDToUse = 0; xDelayPeriod = mainERROR_DELAY; } - /* The Fx3 runs more tasks, so more checks are performed. */ + /* The Fx3 runs more tasks, so more checks are performed. */ #ifdef __IAR_V850ES_Fx3__ { if( xAreComTestTasksStillRunning() != pdTRUE ) { xDelayPeriod = mainERROR_DELAY; } - + if( xArePollingQueuesStillRunning() != pdTRUE ) { xDelayPeriod = mainERROR_DELAY; @@ -224,12 +224,12 @@ unsigned portBASE_TYPE uxLEDToUse = 0; { xDelayPeriod = mainERROR_DELAY; } - + if( xAreRecursiveMutexTasksStillRunning() != pdTRUE ) { xDelayPeriod = mainERROR_DELAY; - } - + } + /* The application board has more LEDs and uses the flash tasks so the check task instead uses LED3 as LED3 is still spare. */ uxLEDToUse = 3; @@ -252,8 +252,11 @@ static void prvSetupHardware( void ) } /*-----------------------------------------------------------*/ -void vApplicationStackOverflowHook( void ) +void vApplicationStackOverflowHook( TaskHandle_t xTask, char *pcTaskName ) { + ( void ) xTask; + ( void ) pcTaskName; + /* This will be called if a task overflows its stack. pxCurrentTCB can be inspected to see which is the offending task. */ for( ;; ); @@ -265,7 +268,7 @@ void vRegTestFailed( void ) /* Called by the RegTest tasks if an error is found. lRegTestStatus is inspected by the check task. */ lRegTestStatus = pdFAIL; - + /* Do not return from here as the reg test tasks clobber all registers so function calls may not function correctly. */ for( ;; ); diff --git a/FreeRTOS/Demo/NiosII_CycloneIII_DBC3C40_GCC/RTOSDemo/main.c b/FreeRTOS/Demo/NiosII_CycloneIII_DBC3C40_GCC/RTOSDemo/main.c index b91d78da83..bf37aaa3d9 100644 --- a/FreeRTOS/Demo/NiosII_CycloneIII_DBC3C40_GCC/RTOSDemo/main.c +++ b/FreeRTOS/Demo/NiosII_CycloneIII_DBC3C40_GCC/RTOSDemo/main.c @@ -31,13 +31,13 @@ * defined and/or created within this file: * * "Check" task - This only executes every five seconds but has the highest - * priority so is guaranteed to get processor time. Its main function is to + * priority so is guaranteed to get processor time. Its main function is to * check that all the standard demo tasks are still operational. The check * task will write an error message to the console should an error be detected * within any of the demo tasks. The check task also toggles the LED defined * by mainCHECK_LED every 5 seconds while the system is error free, with the * toggle rate increasing to every 500ms should an error occur. - * + * * "Reg test" tasks - These fill the registers with known values, then check * that each register still contains its expected value. Each task uses * different values. The tasks run with very low priority so get preempted very @@ -92,7 +92,7 @@ error has been detected. */ /* The LED toggled by the Check task. */ #define mainCHECK_LED ( 7 ) -/* The first LED used by the ComTest tasks. One LED toggles each time a +/* The first LED used by the ComTest tasks. One LED toggles each time a character is transmitted, and one each time a character is received and verified as being the expected character. */ #define mainCOMTEST_LED ( 4 ) @@ -125,7 +125,7 @@ static void prvSetupHardware( void ); /* * Execute all of the check functions to ensure the tests haven't failed. - */ + */ static void prvCheckTask( void *pvParameters ); /* @@ -149,7 +149,7 @@ int main( void ) { /* Configure any hardware required for this demo. */ prvSetupHardware(); - + /* Create all the other standard demo tasks. These serve no purpose other than to test the port and demonstrate the use of the FreeRTOS API. */ vStartLEDFlashTasks( tskIDLE_PRIORITY ); @@ -164,10 +164,10 @@ int main( void ) vStartCountingSemaphoreTasks(); vStartRecursiveMutexTasks(); vAltStartComTestTasks( mainCOM_TEST_PRIORITY, 0, mainCOMTEST_LED ); - + /* prvCheckTask uses sprintf so requires more stack. */ xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL ); - + /* The RegTest tasks as described at the top of this file. */ xTaskCreate( prvFirstRegTestTask, "Rreg1", configMINIMAL_STACK_SIZE, mainREG_TEST_1_PARAMETER, mainREG_TEST_PRIORITY, NULL ); xTaskCreate( prvSecondRegTestTask, "Rreg2", configMINIMAL_STACK_SIZE, mainREG_TEST_2_PARAMETER, mainREG_TEST_PRIORITY, NULL ); @@ -178,7 +178,7 @@ int main( void ) /* Finally start the scheduler. */ vTaskStartScheduler(); - + /* Will only reach here if there is insufficient heap available to start the scheduler. */ for( ;; ); @@ -192,8 +192,11 @@ static void prvSetupHardware( void ) } /*-----------------------------------------------------------*/ -void vApplicationStackOverflowHook( void ) +void vApplicationStackOverflowHook( TaskHandle_t xTask, char *pcTaskName ) { + ( void ) xTask; + ( void ) pcTaskName; + /* Look at pxCurrentTCB to see which task overflowed its stack. */ for( ;; ) { @@ -204,7 +207,7 @@ void vApplicationStackOverflowHook( void ) void _general_exception_handler( unsigned long ulCause, unsigned long ulStatus ) { - /* This overrides the definition provided by the kernel. Other exceptions + /* This overrides the definition provided by the kernel. Other exceptions should be handled here. */ for( ;; ) { @@ -227,8 +230,8 @@ const char * pcMessage; { /* Wait until it is time to run the tests again. */ vTaskDelayUntil( &xLastExecutionTime, ulTicksToWait ); - - /* Have any of the standard demo tasks detected an error in their + + /* Have any of the standard demo tasks detected an error in their operation? */ if( xAreIntegerMathsTaskStillRunning() != pdTRUE ) { @@ -300,7 +303,7 @@ const char * pcMessage; else if( ulLastRegTest2 == ulRegTest2Counter ) { /* ulRegTest2Counter is no longer being incremented, indicating - that an error has been discovered in prvSecondRegTestTask(). */ + that an error has been discovered in prvSecondRegTestTask(). */ ulTicksToWait = mainERROR_PERIOD; pcMessage = "Error: Reg Test2.\n"; } @@ -308,19 +311,19 @@ const char * pcMessage; { pcMessage = NULL; } - + /* Remember the counter values this time around so a counter failing to be incremented correctly can be spotted. */ ulLastRegTest1 = ulRegTest1Counter; ulLastRegTest2 = ulRegTest2Counter; - - /* Print out an error message if there is one. Mutual exclusion is + + /* Print out an error message if there is one. Mutual exclusion is not used as this is the only task accessing stdout. */ if( pcMessage != NULL ) { printf( pcMessage ); } - + /* Provide visual feedback of the system status. If the LED is toggled every 5 seconds then no errors have been found. If the LED is toggled every 500ms then at least one error has been found. */ @@ -334,17 +337,17 @@ static void prvFirstRegTestTask( void *pvParameters ) /* Check the parameters are passed in as expected. */ if( pvParameters != mainREG_TEST_1_PARAMETER ) { - /* Don't execute any further so an error is recognised by the check + /* Don't execute any further so an error is recognised by the check task. */ vTaskDelete( NULL ); } - + /* Fill registers with known values, then check that each register still contains its expected value. An incorrect value is indicative of an error - in the context switching process. - + in the context switching process. + If no errors are found ulRegTest1Counter is incremented. The check task - will recognise an error if ulRegTest1Counter stops being incremented. + will recognise an error if ulRegTest1Counter stops being incremented. This task also performs a manual yield in the middle of its execution, just to increase the test coverage. */ asm volatile ( @@ -438,15 +441,15 @@ static void prvSecondRegTestTask( void *pvParameters ) /* Check the parameters are passed in as expected. */ if( pvParameters != mainREG_TEST_2_PARAMETER ) { - /* Don't execute any further so an error is recognised by the check + /* Don't execute any further so an error is recognised by the check task. */ vTaskDelete( NULL ); } - + /* Fill registers with known values, then check that each register still contains its expected value. An incorrect value is indicative of an error - in the context switching process. - + in the context switching process. + If no errors are found ulRegTest2Counter is incremented. The check task will recognise an error if ulRegTest2Counter stops being incremented. */ asm volatile ( diff --git a/FreeRTOS/Demo/PPC440_DP_FPU_Xilinx_Virtex5_GCC/RTOSDemo/main.c b/FreeRTOS/Demo/PPC440_DP_FPU_Xilinx_Virtex5_GCC/RTOSDemo/main.c index 5fedf1f785..482a284908 100644 --- a/FreeRTOS/Demo/PPC440_DP_FPU_Xilinx_Virtex5_GCC/RTOSDemo/main.c +++ b/FreeRTOS/Demo/PPC440_DP_FPU_Xilinx_Virtex5_GCC/RTOSDemo/main.c @@ -653,8 +653,8 @@ static void prvRegTestTask2( void *pvParameters ) /* This hook function will get called if there is a suspected stack overflow. An overflow can cause the task name to be corrupted, in which case the task handle needs to be used to determine the offending task. */ -void vApplicationStackOverflowHook( TaskHandle_t xTask, signed char *pcTaskName ); -void vApplicationStackOverflowHook( TaskHandle_t xTask, signed char *pcTaskName ) +void vApplicationStackOverflowHook( TaskHandle_t xTask, char *pcTaskName ); +void vApplicationStackOverflowHook( TaskHandle_t xTask, char *pcTaskName ) { /* To prevent the optimiser removing the variables. */ volatile TaskHandle_t xTaskIn = xTask; diff --git a/FreeRTOS/Demo/PPC440_SP_FPU_Xilinx_Virtex5_GCC/RTOSDemo/main.c b/FreeRTOS/Demo/PPC440_SP_FPU_Xilinx_Virtex5_GCC/RTOSDemo/main.c index 25dad61d80..03e652bbdf 100644 --- a/FreeRTOS/Demo/PPC440_SP_FPU_Xilinx_Virtex5_GCC/RTOSDemo/main.c +++ b/FreeRTOS/Demo/PPC440_SP_FPU_Xilinx_Virtex5_GCC/RTOSDemo/main.c @@ -653,8 +653,8 @@ static void prvRegTestTask2( void *pvParameters ) /* This hook function will get called if there is a suspected stack overflow. An overflow can cause the task name to be corrupted, in which case the task handle needs to be used to determine the offending task. */ -void vApplicationStackOverflowHook( TaskHandle_t xTask, signed char *pcTaskName ); -void vApplicationStackOverflowHook( TaskHandle_t xTask, signed char *pcTaskName ) +void vApplicationStackOverflowHook( TaskHandle_t xTask, char *pcTaskName ); +void vApplicationStackOverflowHook( TaskHandle_t xTask, char *pcTaskName ) { /* To prevent the optimiser removing the variables. */ volatile TaskHandle_t xTaskIn = xTask; diff --git a/FreeRTOS/Demo/PPC440_Xilinx_Virtex5_GCC/RTOSDemo/main.c b/FreeRTOS/Demo/PPC440_Xilinx_Virtex5_GCC/RTOSDemo/main.c index 66a65e55a1..d94ab8190f 100644 --- a/FreeRTOS/Demo/PPC440_Xilinx_Virtex5_GCC/RTOSDemo/main.c +++ b/FreeRTOS/Demo/PPC440_Xilinx_Virtex5_GCC/RTOSDemo/main.c @@ -659,8 +659,8 @@ static void prvRegTestTask2( void *pvParameters ) /* This hook function will get called if there is a suspected stack overflow. An overflow can cause the task name to be corrupted, in which case the task handle needs to be used to determine the offending task. */ -void vApplicationStackOverflowHook( TaskHandle_t xTask, signed char *pcTaskName ); -void vApplicationStackOverflowHook( TaskHandle_t xTask, signed char *pcTaskName ) +void vApplicationStackOverflowHook( TaskHandle_t xTask, char *pcTaskName ); +void vApplicationStackOverflowHook( TaskHandle_t xTask, char *pcTaskName ) { /* To prevent the optimiser removing the variables. */ volatile TaskHandle_t xTaskIn = xTask; diff --git a/FreeRTOS/Demo/Posix_GCC/FreeRTOS-simulator-for-Linux.url b/FreeRTOS/Demo/Posix_GCC/FreeRTOS-simulator-for-Linux.url new file mode 100644 index 0000000000..60f7ee8c30 --- /dev/null +++ b/FreeRTOS/Demo/Posix_GCC/FreeRTOS-simulator-for-Linux.url @@ -0,0 +1,5 @@ +[{000214A0-0000-0000-C000-000000000046}] +Prop3=19,11 +[InternetShortcut] +IDList= +URL=https://www.freertos.org/FreeRTOS-simulator-for-Linux.html diff --git a/FreeRTOS/Demo/Posix_GCC/src/FreeRTOSConfig.h b/FreeRTOS/Demo/Posix_GCC/FreeRTOSConfig.h similarity index 100% rename from FreeRTOS/Demo/Posix_GCC/src/FreeRTOSConfig.h rename to FreeRTOS/Demo/Posix_GCC/FreeRTOSConfig.h diff --git a/FreeRTOS/Demo/Posix_GCC/src/FreeRTOSIPConfig.h b/FreeRTOS/Demo/Posix_GCC/FreeRTOSIPConfig.h similarity index 97% rename from FreeRTOS/Demo/Posix_GCC/src/FreeRTOSIPConfig.h rename to FreeRTOS/Demo/Posix_GCC/FreeRTOSIPConfig.h index 261774fad9..c04394bad5 100644 --- a/FreeRTOS/Demo/Posix_GCC/src/FreeRTOSIPConfig.h +++ b/FreeRTOS/Demo/Posix_GCC/FreeRTOSIPConfig.h @@ -1,307 +1,307 @@ -/* - * FreeRTOS Kernel V10.3.0 - * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * 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 URL for configuration information. - * http://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html - * - *****************************************************************************/ - -#ifndef FREERTOS_IP_CONFIG_H -#define FREERTOS_IP_CONFIG_H - -/* Prototype for the function used to print out. In this case it prints to the -console before the network is connected then a UDP port after the network has -connected. */ -extern void vLoggingPrintf( const char *pcFormatString, ... ); - -/* Set to 1 to print out debug messages. If ipconfigHAS_DEBUG_PRINTF is set to -1 then FreeRTOS_debug_printf should be defined to the function used to print -out the debugging messages. */ -#define ipconfigHAS_DEBUG_PRINTF 1 -#if( ipconfigHAS_DEBUG_PRINTF == 1 ) - #define FreeRTOS_debug_printf(X) vLoggingPrintf X -#endif - -/* Set to 1 to print out non debugging messages, for example the output of the -FreeRTOS_netstat() command, and ping replies. If ipconfigHAS_PRINTF is set to 1 -then FreeRTOS_printf should be set to the function used to print out the -messages. */ -#define ipconfigHAS_PRINTF 1 -#if( ipconfigHAS_PRINTF == 1 ) - #define FreeRTOS_printf(X) vLoggingPrintf X -#endif - -/* Define the byte order of the target MCU (the MCU FreeRTOS+TCP is executing -on). Valid options are pdFREERTOS_BIG_ENDIAN and pdFREERTOS_LITTLE_ENDIAN. */ -#define ipconfigBYTE_ORDER pdFREERTOS_LITTLE_ENDIAN - -/* If the network card/driver includes checksum offloading (IP/TCP/UDP checksums) -then set ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM to 1 to prevent the software -stack repeating the checksum calculations. */ -#define ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM 1 - -/* Several API's will block until the result is known, or the action has been -performed, for example FreeRTOS_send() and FreeRTOS_recv(). The timeouts can be -set per socket, using setsockopt(). If not set, the times below will be -used as defaults. */ -#define ipconfigSOCK_DEFAULT_RECEIVE_BLOCK_TIME ( 5000 ) -#define ipconfigSOCK_DEFAULT_SEND_BLOCK_TIME ( 5000 ) - -/* Include support for LLMNR: Link-local Multicast Name Resolution -(non-Microsoft) */ -#define ipconfigUSE_LLMNR ( 1 ) - -/* Include support for NBNS: NetBIOS Name Service (Microsoft) */ -#define ipconfigUSE_NBNS ( 1 ) - -/* Include support for DNS caching. For TCP, having a small DNS cache is very -useful. When a cache is present, ipconfigDNS_REQUEST_ATTEMPTS can be kept low -and also DNS may use small timeouts. If a DNS reply comes in after the DNS -socket has been destroyed, the result will be stored into the cache. The next -call to FreeRTOS_gethostbyname() will return immediately, without even creating -a socket. */ -#define ipconfigUSE_DNS_CACHE ( 1 ) -#define ipconfigDNS_CACHE_NAME_LENGTH ( 16 ) -#define ipconfigDNS_CACHE_ENTRIES ( 4 ) -#define ipconfigDNS_REQUEST_ATTEMPTS ( 2 ) - -/* The IP stack executes it its own task (although any application task can make -use of its services through the published sockets API). ipconfigUDP_TASK_PRIORITY -sets the priority of the task that executes the IP stack. The priority is a -standard FreeRTOS task priority so can take any value from 0 (the lowest -priority) to (configMAX_PRIORITIES - 1) (the highest priority). -configMAX_PRIORITIES is a standard FreeRTOS configuration parameter defined in -FreeRTOSConfig.h, not FreeRTOSIPConfig.h. Consideration needs to be given as to -the priority assigned to the task executing the IP stack relative to the -priority assigned to tasks that use the IP stack. */ -#define ipconfigIP_TASK_PRIORITY ( configMAX_PRIORITIES - 2 ) - -/* The size, in words (not bytes), of the stack allocated to the FreeRTOS+TCP -task. This setting is less important when the FreeRTOS Win32 simulator is used -as the Win32 simulator only stores a fixed amount of information on the task -stack. FreeRTOS includes optional stack overflow detection, see: -http://www.freertos.org/Stacks-and-stack-overflow-checking.html */ -#define ipconfigIP_TASK_STACK_SIZE_WORDS ( configMINIMAL_STACK_SIZE * 5 ) - -/* ipconfigRAND32() is called by the IP stack to generate random numbers for -things such as a DHCP transaction number or initial sequence number. Random -number generation is performed via this macro to allow applications to use their -own random number generation method. For example, it might be possible to -generate a random number by sampling noise on an analogue input. */ -extern UBaseType_t uxRand(); -#define ipconfigRAND32() uxRand() - -/* If ipconfigUSE_NETWORK_EVENT_HOOK is set to 1 then FreeRTOS+TCP will call the -network event hook at the appropriate times. If ipconfigUSE_NETWORK_EVENT_HOOK -is not set to 1 then the network event hook will never be called. See -http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_UDP/API/vApplicationIPNetworkEventHook.shtml -*/ -#define ipconfigUSE_NETWORK_EVENT_HOOK 1 - -/* Sockets have a send block time attribute. If FreeRTOS_sendto() is called but -a network buffer cannot be obtained then the calling task is held in the Blocked -state (so other tasks can continue to executed) until either a network buffer -becomes available or the send block time expires. If the send block time expires -then the send operation is aborted. The maximum allowable send block time is -capped to the value set by ipconfigMAX_SEND_BLOCK_TIME_TICKS. Capping the -maximum allowable send block time prevents prevents a deadlock occurring when -all the network buffers are in use and the tasks that process (and subsequently -free) the network buffers are themselves blocked waiting for a network buffer. -ipconfigMAX_SEND_BLOCK_TIME_TICKS is specified in RTOS ticks. A time in -milliseconds can be converted to a time in ticks by dividing the time in -milliseconds by portTICK_PERIOD_MS. */ -#define ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS ( 5000U / portTICK_PERIOD_MS ) - -/* If ipconfigUSE_DHCP is 1 then FreeRTOS+TCP will attempt to retrieve an IP -address, netmask, DNS server address and gateway address from a DHCP server. If -ipconfigUSE_DHCP is 0 then FreeRTOS+TCP will use a static IP address. The -stack will revert to using the static IP address even when ipconfigUSE_DHCP is -set to 1 if a valid configuration cannot be obtained from a DHCP server for any -reason. The static configuration used is that passed into the stack by the -FreeRTOS_IPInit() function call. */ -#define ipconfigUSE_DHCP 0 - -/* When ipconfigUSE_DHCP is set to 1, DHCP requests will be sent out at -increasing time intervals until either a reply is received from a DHCP server -and accepted, or the interval between transmissions reaches -ipconfigMAXIMUM_DISCOVER_TX_PERIOD. The IP stack will revert to using the -static IP address passed as a parameter to FreeRTOS_IPInit() if the -re-transmission time interval reaches ipconfigMAXIMUM_DISCOVER_TX_PERIOD without -a DHCP reply being received. */ -#define ipconfigMAXIMUM_DISCOVER_TX_PERIOD ( 120000U / portTICK_PERIOD_MS ) - -/* The ARP cache is a table that maps IP addresses to MAC addresses. The IP -stack can only send a UDP message to a remove IP address if it knowns the MAC -address associated with the IP address, or the MAC address of the router used to -contact the remote IP address. When a UDP message is received from a remote IP -address the MAC address and IP address are added to the ARP cache. When a UDP -message is sent to a remote IP address that does not already appear in the ARP -cache then the UDP message is replaced by a ARP message that solicits the -required MAC address information. ipconfigARP_CACHE_ENTRIES defines the maximum -number of entries that can exist in the ARP table at any one time. */ -#define ipconfigARP_CACHE_ENTRIES 6 - -/* ARP requests that do not result in an ARP response will be re-transmitted a -maximum of ipconfigMAX_ARP_RETRANSMISSIONS times before the ARP request is -aborted. */ -#define ipconfigMAX_ARP_RETRANSMISSIONS ( 5 ) - -/* ipconfigMAX_ARP_AGE defines the maximum time between an entry in the ARP -table being created or refreshed and the entry being removed because it is stale. -New ARP requests are sent for ARP cache entries that are nearing their maximum -age. ipconfigMAX_ARP_AGE is specified in tens of seconds, so a value of 150 is -equal to 1500 seconds (or 25 minutes). */ -#define ipconfigMAX_ARP_AGE 150 - -/* Implementing FreeRTOS_inet_addr() necessitates the use of string handling -routines, which are relatively large. To save code space the full -FreeRTOS_inet_addr() implementation is made optional, and a smaller and faster -alternative called FreeRTOS_inet_addr_quick() is provided. FreeRTOS_inet_addr() -takes an IP in decimal dot format (for example, "192.168.0.1") as its parameter. -FreeRTOS_inet_addr_quick() takes an IP address as four separate numerical octets -(for example, 192, 168, 0, 1) as its parameters. If -ipconfigINCLUDE_FULL_INET_ADDR is set to 1 then both FreeRTOS_inet_addr() and -FreeRTOS_indet_addr_quick() are available. If ipconfigINCLUDE_FULL_INET_ADDR is -not set to 1 then only FreeRTOS_indet_addr_quick() is available. */ -#define ipconfigINCLUDE_FULL_INET_ADDR 1 - -/* ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS defines the total number of network buffer that -are available to the IP stack. The total number of network buffers is limited -to ensure the total amount of RAM that can be consumed by the IP stack is capped -to a pre-determinable value. */ -#define ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS 60 - -/* A FreeRTOS queue is used to send events from application tasks to the IP -stack. ipconfigEVENT_QUEUE_LENGTH sets the maximum number of events that can -be queued for processing at any one time. The event queue must be a minimum of -5 greater than the total number of network buffers. */ -#define ipconfigEVENT_QUEUE_LENGTH ( ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS + 5 ) - -/* The address of a socket is the combination of its IP address and its port -number. FreeRTOS_bind() is used to manually allocate a port number to a socket -(to 'bind' the socket to a port), but manual binding is not normally necessary -for client sockets (those sockets that initiate outgoing connections rather than -wait for incoming connections on a known port number). If -ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND is set to 1 then calling -FreeRTOS_sendto() on a socket that has not yet been bound will result in the IP -stack automatically binding the socket to a port number from the range -socketAUTO_PORT_ALLOCATION_START_NUMBER to 0xffff. If -ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND is set to 0 then calling FreeRTOS_sendto() -on a socket that has not yet been bound will result in the send operation being -aborted. */ -#define ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND 1 - -/* Defines the Time To Live (TTL) values used in outgoing UDP packets. */ -#define ipconfigUDP_TIME_TO_LIVE 128 -#define ipconfigTCP_TIME_TO_LIVE 128 /* also defined in FreeRTOSIPConfigDefaults.h */ - -/* USE_TCP: Use TCP and all its features */ -#define ipconfigUSE_TCP ( 1 ) - -/* USE_WIN: Let TCP use windowing mechanism. */ -#define ipconfigUSE_TCP_WIN ( 1 ) - -/* The MTU is the maximum number of bytes the payload of a network frame can -contain. For normal Ethernet V2 frames the maximum MTU is 1500. Setting a -lower value can save RAM, depending on the buffer management scheme used. If -ipconfigCAN_FRAGMENT_OUTGOING_PACKETS is 1 then (ipconfigNETWORK_MTU - 28) must -be divisible by 8. */ -#define ipconfigNETWORK_MTU 1200U - -/* Set ipconfigUSE_DNS to 1 to include a basic DNS client/resolver. DNS is used -through the FreeRTOS_gethostbyname() API function. */ -#define ipconfigUSE_DNS 1 - -/* If ipconfigREPLY_TO_INCOMING_PINGS is set to 1 then the IP stack will -generate replies to incoming ICMP echo (ping) requests. */ -#define ipconfigREPLY_TO_INCOMING_PINGS 1 - -/* If ipconfigSUPPORT_OUTGOING_PINGS is set to 1 then the -FreeRTOS_SendPingRequest() API function is available. */ -#define ipconfigSUPPORT_OUTGOING_PINGS 0 - -/* If ipconfigSUPPORT_SELECT_FUNCTION is set to 1 then the FreeRTOS_select() -(and associated) API function is available. */ -#define ipconfigSUPPORT_SELECT_FUNCTION 1 - -/* If ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES is set to 1 then Ethernet frames -that are not in Ethernet II format will be dropped. This option is included for -potential future IP stack developments. */ -#define ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES 1 - -/* If ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES is set to 1 then it is the -responsibility of the Ethernet interface to filter out packets that are of no -interest. If the Ethernet interface does not implement this functionality, then -set ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES to 0 to have the IP stack -perform the filtering instead (it is much less efficient for the stack to do it -because the packet will already have been passed into the stack). If the -Ethernet driver does all the necessary filtering in hardware then software -filtering can be removed by using a value other than 1 or 0. */ -#define ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES 1 - -/* The windows simulator cannot really simulate MAC interrupts, and needs to -block occasionally to allow other tasks to run. */ -#define configWINDOWS_MAC_INTERRUPT_SIMULATOR_DELAY ( 20 / portTICK_PERIOD_MS ) - -/* Advanced only: in order to access 32-bit fields in the IP packets with -32-bit memory instructions, all packets will be stored 32-bit-aligned, plus 16-bits. -This has to do with the contents of the IP-packets: all 32-bit fields are -32-bit-aligned, plus 16-bit(!) */ -#define ipconfigPACKET_FILLER_SIZE 2U - -/* Define the size of the pool of TCP window descriptors. On the average, each -TCP socket will use up to 2 x 6 descriptors, meaning that it can have 2 x 6 -outstanding packets (for Rx and Tx). When using up to 10 TP sockets -simultaneously, one could define TCP_WIN_SEG_COUNT as 120. */ -#define ipconfigTCP_WIN_SEG_COUNT 240 - -/* Each TCP socket has a circular buffers for Rx and Tx, which have a fixed -maximum size. Define the size of Rx buffer for TCP sockets. */ -#define ipconfigTCP_RX_BUFFER_LENGTH ( 1000 ) - -/* Define the size of Tx buffer for TCP sockets. */ -#define ipconfigTCP_TX_BUFFER_LENGTH ( 1000 ) - -/* When using call-back handlers, the driver may check if the handler points to -real program memory (RAM or flash) or just has a random non-zero value. */ -#define ipconfigIS_VALID_PROG_ADDRESS(x) ( (x) != NULL ) - -/* Include support for TCP hang protection. All sockets in a connecting or -disconnecting stage will timeout after a period of non-activity. */ -#define ipconfigTCP_HANG_PROTECTION ( 1 ) -#define ipconfigTCP_HANG_PROTECTION_TIME ( 30 ) - -/* Include support for TCP keep-alive messages. */ -#define ipconfigTCP_KEEP_ALIVE ( 1 ) -#define ipconfigTCP_KEEP_ALIVE_INTERVAL ( 20 ) /* in seconds */ - -#define portINLINE __inline - -#endif /* FREERTOS_IP_CONFIG_H */ +/* + * FreeRTOS Kernel V10.3.0 + * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * 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 URL for configuration information. + * http://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html + * + *****************************************************************************/ + +#ifndef FREERTOS_IP_CONFIG_H +#define FREERTOS_IP_CONFIG_H + +/* Prototype for the function used to print out. In this case it prints to the +console before the network is connected then a UDP port after the network has +connected. */ +extern void vLoggingPrintf( const char *pcFormatString, ... ); + +/* Set to 1 to print out debug messages. If ipconfigHAS_DEBUG_PRINTF is set to +1 then FreeRTOS_debug_printf should be defined to the function used to print +out the debugging messages. */ +#define ipconfigHAS_DEBUG_PRINTF 1 +#if( ipconfigHAS_DEBUG_PRINTF == 1 ) + #define FreeRTOS_debug_printf(X) vLoggingPrintf X +#endif + +/* Set to 1 to print out non debugging messages, for example the output of the +FreeRTOS_netstat() command, and ping replies. If ipconfigHAS_PRINTF is set to 1 +then FreeRTOS_printf should be set to the function used to print out the +messages. */ +#define ipconfigHAS_PRINTF 0 +#if( ipconfigHAS_PRINTF == 1 ) + #define FreeRTOS_printf(X) vLoggingPrintf X +#endif + +/* Define the byte order of the target MCU (the MCU FreeRTOS+TCP is executing +on). Valid options are pdFREERTOS_BIG_ENDIAN and pdFREERTOS_LITTLE_ENDIAN. */ +#define ipconfigBYTE_ORDER pdFREERTOS_LITTLE_ENDIAN + +/* If the network card/driver includes checksum offloading (IP/TCP/UDP checksums) +then set ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM to 1 to prevent the software +stack repeating the checksum calculations. */ +#define ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM 1 + +/* Several API's will block until the result is known, or the action has been +performed, for example FreeRTOS_send() and FreeRTOS_recv(). The timeouts can be +set per socket, using setsockopt(). If not set, the times below will be +used as defaults. */ +#define ipconfigSOCK_DEFAULT_RECEIVE_BLOCK_TIME ( 5000 ) +#define ipconfigSOCK_DEFAULT_SEND_BLOCK_TIME ( 5000 ) + +/* Include support for LLMNR: Link-local Multicast Name Resolution +(non-Microsoft) */ +#define ipconfigUSE_LLMNR ( 1 ) + +/* Include support for NBNS: NetBIOS Name Service (Microsoft) */ +#define ipconfigUSE_NBNS ( 1 ) + +/* Include support for DNS caching. For TCP, having a small DNS cache is very +useful. When a cache is present, ipconfigDNS_REQUEST_ATTEMPTS can be kept low +and also DNS may use small timeouts. If a DNS reply comes in after the DNS +socket has been destroyed, the result will be stored into the cache. The next +call to FreeRTOS_gethostbyname() will return immediately, without even creating +a socket. */ +#define ipconfigUSE_DNS_CACHE ( 1 ) +#define ipconfigDNS_CACHE_NAME_LENGTH ( 16 ) +#define ipconfigDNS_CACHE_ENTRIES ( 4 ) +#define ipconfigDNS_REQUEST_ATTEMPTS ( 2 ) + +/* The IP stack executes it its own task (although any application task can make +use of its services through the published sockets API). ipconfigUDP_TASK_PRIORITY +sets the priority of the task that executes the IP stack. The priority is a +standard FreeRTOS task priority so can take any value from 0 (the lowest +priority) to (configMAX_PRIORITIES - 1) (the highest priority). +configMAX_PRIORITIES is a standard FreeRTOS configuration parameter defined in +FreeRTOSConfig.h, not FreeRTOSIPConfig.h. Consideration needs to be given as to +the priority assigned to the task executing the IP stack relative to the +priority assigned to tasks that use the IP stack. */ +#define ipconfigIP_TASK_PRIORITY ( configMAX_PRIORITIES - 2 ) + +/* The size, in words (not bytes), of the stack allocated to the FreeRTOS+TCP +task. This setting is less important when the FreeRTOS Win32 simulator is used +as the Win32 simulator only stores a fixed amount of information on the task +stack. FreeRTOS includes optional stack overflow detection, see: +http://www.freertos.org/Stacks-and-stack-overflow-checking.html */ +#define ipconfigIP_TASK_STACK_SIZE_WORDS ( configMINIMAL_STACK_SIZE * 5 ) + +/* ipconfigRAND32() is called by the IP stack to generate random numbers for +things such as a DHCP transaction number or initial sequence number. Random +number generation is performed via this macro to allow applications to use their +own random number generation method. For example, it might be possible to +generate a random number by sampling noise on an analogue input. */ +extern UBaseType_t uxRand(); +#define ipconfigRAND32() uxRand() + +/* If ipconfigUSE_NETWORK_EVENT_HOOK is set to 1 then FreeRTOS+TCP will call the +network event hook at the appropriate times. If ipconfigUSE_NETWORK_EVENT_HOOK +is not set to 1 then the network event hook will never be called. See +http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_UDP/API/vApplicationIPNetworkEventHook.shtml +*/ +#define ipconfigUSE_NETWORK_EVENT_HOOK 1 + +/* Sockets have a send block time attribute. If FreeRTOS_sendto() is called but +a network buffer cannot be obtained then the calling task is held in the Blocked +state (so other tasks can continue to executed) until either a network buffer +becomes available or the send block time expires. If the send block time expires +then the send operation is aborted. The maximum allowable send block time is +capped to the value set by ipconfigMAX_SEND_BLOCK_TIME_TICKS. Capping the +maximum allowable send block time prevents prevents a deadlock occurring when +all the network buffers are in use and the tasks that process (and subsequently +free) the network buffers are themselves blocked waiting for a network buffer. +ipconfigMAX_SEND_BLOCK_TIME_TICKS is specified in RTOS ticks. A time in +milliseconds can be converted to a time in ticks by dividing the time in +milliseconds by portTICK_PERIOD_MS. */ +#define ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS ( 5000U / portTICK_PERIOD_MS ) + +/* If ipconfigUSE_DHCP is 1 then FreeRTOS+TCP will attempt to retrieve an IP +address, netmask, DNS server address and gateway address from a DHCP server. If +ipconfigUSE_DHCP is 0 then FreeRTOS+TCP will use a static IP address. The +stack will revert to using the static IP address even when ipconfigUSE_DHCP is +set to 1 if a valid configuration cannot be obtained from a DHCP server for any +reason. The static configuration used is that passed into the stack by the +FreeRTOS_IPInit() function call. */ +#define ipconfigUSE_DHCP 0 + +/* When ipconfigUSE_DHCP is set to 1, DHCP requests will be sent out at +increasing time intervals until either a reply is received from a DHCP server +and accepted, or the interval between transmissions reaches +ipconfigMAXIMUM_DISCOVER_TX_PERIOD. The IP stack will revert to using the +static IP address passed as a parameter to FreeRTOS_IPInit() if the +re-transmission time interval reaches ipconfigMAXIMUM_DISCOVER_TX_PERIOD without +a DHCP reply being received. */ +#define ipconfigMAXIMUM_DISCOVER_TX_PERIOD ( 120000U / portTICK_PERIOD_MS ) + +/* The ARP cache is a table that maps IP addresses to MAC addresses. The IP +stack can only send a UDP message to a remove IP address if it knowns the MAC +address associated with the IP address, or the MAC address of the router used to +contact the remote IP address. When a UDP message is received from a remote IP +address the MAC address and IP address are added to the ARP cache. When a UDP +message is sent to a remote IP address that does not already appear in the ARP +cache then the UDP message is replaced by a ARP message that solicits the +required MAC address information. ipconfigARP_CACHE_ENTRIES defines the maximum +number of entries that can exist in the ARP table at any one time. */ +#define ipconfigARP_CACHE_ENTRIES 6 + +/* ARP requests that do not result in an ARP response will be re-transmitted a +maximum of ipconfigMAX_ARP_RETRANSMISSIONS times before the ARP request is +aborted. */ +#define ipconfigMAX_ARP_RETRANSMISSIONS ( 5 ) + +/* ipconfigMAX_ARP_AGE defines the maximum time between an entry in the ARP +table being created or refreshed and the entry being removed because it is stale. +New ARP requests are sent for ARP cache entries that are nearing their maximum +age. ipconfigMAX_ARP_AGE is specified in tens of seconds, so a value of 150 is +equal to 1500 seconds (or 25 minutes). */ +#define ipconfigMAX_ARP_AGE 150 + +/* Implementing FreeRTOS_inet_addr() necessitates the use of string handling +routines, which are relatively large. To save code space the full +FreeRTOS_inet_addr() implementation is made optional, and a smaller and faster +alternative called FreeRTOS_inet_addr_quick() is provided. FreeRTOS_inet_addr() +takes an IP in decimal dot format (for example, "192.168.0.1") as its parameter. +FreeRTOS_inet_addr_quick() takes an IP address as four separate numerical octets +(for example, 192, 168, 0, 1) as its parameters. If +ipconfigINCLUDE_FULL_INET_ADDR is set to 1 then both FreeRTOS_inet_addr() and +FreeRTOS_indet_addr_quick() are available. If ipconfigINCLUDE_FULL_INET_ADDR is +not set to 1 then only FreeRTOS_indet_addr_quick() is available. */ +#define ipconfigINCLUDE_FULL_INET_ADDR 1 + +/* ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS defines the total number of network buffer that +are available to the IP stack. The total number of network buffers is limited +to ensure the total amount of RAM that can be consumed by the IP stack is capped +to a pre-determinable value. */ +#define ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS 60 + +/* A FreeRTOS queue is used to send events from application tasks to the IP +stack. ipconfigEVENT_QUEUE_LENGTH sets the maximum number of events that can +be queued for processing at any one time. The event queue must be a minimum of +5 greater than the total number of network buffers. */ +#define ipconfigEVENT_QUEUE_LENGTH ( ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS + 5 ) + +/* The address of a socket is the combination of its IP address and its port +number. FreeRTOS_bind() is used to manually allocate a port number to a socket +(to 'bind' the socket to a port), but manual binding is not normally necessary +for client sockets (those sockets that initiate outgoing connections rather than +wait for incoming connections on a known port number). If +ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND is set to 1 then calling +FreeRTOS_sendto() on a socket that has not yet been bound will result in the IP +stack automatically binding the socket to a port number from the range +socketAUTO_PORT_ALLOCATION_START_NUMBER to 0xffff. If +ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND is set to 0 then calling FreeRTOS_sendto() +on a socket that has not yet been bound will result in the send operation being +aborted. */ +#define ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND 1 + +/* Defines the Time To Live (TTL) values used in outgoing UDP packets. */ +#define ipconfigUDP_TIME_TO_LIVE 128 +#define ipconfigTCP_TIME_TO_LIVE 128 /* also defined in FreeRTOSIPConfigDefaults.h */ + +/* USE_TCP: Use TCP and all its features */ +#define ipconfigUSE_TCP ( 1 ) + +/* USE_WIN: Let TCP use windowing mechanism. */ +#define ipconfigUSE_TCP_WIN ( 1 ) + +/* The MTU is the maximum number of bytes the payload of a network frame can +contain. For normal Ethernet V2 frames the maximum MTU is 1500. Setting a +lower value can save RAM, depending on the buffer management scheme used. If +ipconfigCAN_FRAGMENT_OUTGOING_PACKETS is 1 then (ipconfigNETWORK_MTU - 28) must +be divisible by 8. */ +#define ipconfigNETWORK_MTU 1200U + +/* Set ipconfigUSE_DNS to 1 to include a basic DNS client/resolver. DNS is used +through the FreeRTOS_gethostbyname() API function. */ +#define ipconfigUSE_DNS 1 + +/* If ipconfigREPLY_TO_INCOMING_PINGS is set to 1 then the IP stack will +generate replies to incoming ICMP echo (ping) requests. */ +#define ipconfigREPLY_TO_INCOMING_PINGS 1 + +/* If ipconfigSUPPORT_OUTGOING_PINGS is set to 1 then the +FreeRTOS_SendPingRequest() API function is available. */ +#define ipconfigSUPPORT_OUTGOING_PINGS 0 + +/* If ipconfigSUPPORT_SELECT_FUNCTION is set to 1 then the FreeRTOS_select() +(and associated) API function is available. */ +#define ipconfigSUPPORT_SELECT_FUNCTION 1 + +/* If ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES is set to 1 then Ethernet frames +that are not in Ethernet II format will be dropped. This option is included for +potential future IP stack developments. */ +#define ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES 1 + +/* If ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES is set to 1 then it is the +responsibility of the Ethernet interface to filter out packets that are of no +interest. If the Ethernet interface does not implement this functionality, then +set ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES to 0 to have the IP stack +perform the filtering instead (it is much less efficient for the stack to do it +because the packet will already have been passed into the stack). If the +Ethernet driver does all the necessary filtering in hardware then software +filtering can be removed by using a value other than 1 or 0. */ +#define ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES 1 + +/* The Linux simulator cannot really simulate MAC interrupts, and needs to +block occasionally to allow other tasks to run. */ +#define configWINDOWS_MAC_INTERRUPT_SIMULATOR_DELAY ( 20 / portTICK_PERIOD_MS ) + +/* Advanced only: in order to access 32-bit fields in the IP packets with +32-bit memory instructions, all packets will be stored 32-bit-aligned, plus 16-bits. +This has to do with the contents of the IP-packets: all 32-bit fields are +32-bit-aligned, plus 16-bit(!) */ +#define ipconfigPACKET_FILLER_SIZE 2U + +/* Define the size of the pool of TCP window descriptors. On the average, each +TCP socket will use up to 2 x 6 descriptors, meaning that it can have 2 x 6 +outstanding packets (for Rx and Tx). When using up to 10 TP sockets +simultaneously, one could define TCP_WIN_SEG_COUNT as 120. */ +#define ipconfigTCP_WIN_SEG_COUNT 240 + +/* Each TCP socket has a circular buffers for Rx and Tx, which have a fixed +maximum size. Define the size of Rx buffer for TCP sockets. */ +#define ipconfigTCP_RX_BUFFER_LENGTH ( 1000 ) + +/* Define the size of Tx buffer for TCP sockets. */ +#define ipconfigTCP_TX_BUFFER_LENGTH ( 1000 ) + +/* When using call-back handlers, the driver may check if the handler points to +real program memory (RAM or flash) or just has a random non-zero value. */ +#define ipconfigIS_VALID_PROG_ADDRESS(x) ( (x) != NULL ) + +/* Include support for TCP hang protection. All sockets in a connecting or +disconnecting stage will timeout after a period of non-activity. */ +#define ipconfigTCP_HANG_PROTECTION ( 1 ) +#define ipconfigTCP_HANG_PROTECTION_TIME ( 30 ) + +/* Include support for TCP keep-alive messages. */ +#define ipconfigTCP_KEEP_ALIVE ( 1 ) +#define ipconfigTCP_KEEP_ALIVE_INTERVAL ( 20 ) /* in seconds */ + +#define portINLINE __inline + +#endif /* FREERTOS_IP_CONFIG_H */ diff --git a/FreeRTOS/Demo/Posix_GCC/Makefile b/FreeRTOS/Demo/Posix_GCC/Makefile new file mode 100644 index 0000000000..1e21f23e62 --- /dev/null +++ b/FreeRTOS/Demo/Posix_GCC/Makefile @@ -0,0 +1,107 @@ +CC := gcc +BIN := posix_demo + +BUILD_DIR := build + +FREERTOS_DIR_REL := ../../../FreeRTOS +FREERTOS_DIR := $(abspath $(FREERTOS_DIR_REL)) + +FREERTOS_PLUS_DIR_REL := ../../../FreeRTOS-Plus +FREERTOS_PLUS_DIR := $(abspath $(FREERTOS_PLUS_DIR_REL)) + +INCLUDE_DIRS := -I. +INCLUDE_DIRS += -I${FREERTOS_DIR}/Source/include +INCLUDE_DIRS += -I${FREERTOS_DIR}/Source/portable/ThirdParty/GCC/Posix +INCLUDE_DIRS += -I${FREERTOS_DIR}/Source/portable/ThirdParty/GCC/Posix/utils +INCLUDE_DIRS += -I${FREERTOS_DIR}/Demo/Common/include +INCLUDE_DIRS += -I${FREERTOS_PLUS_DIR}/Source/FreeRTOS-Plus-Trace/Include +INCLUDE_DIRS += -I${FREERTOS_PLUS_DIR}/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/linux/ +INCLUDE_DIRS += -I${FREERTOS_PLUS_DIR}/Source/FreeRTOS-Plus-TCP/include/ +INCLUDE_DIRS += -I${FREERTOS_PLUS_DIR}/Source/FreeRTOS-Plus-TCP/portable/Compiler/GCC/ + +SOURCE_FILES := $(wildcard *.c) +SOURCE_FILES += $(wildcard ${FREERTOS_DIR}/Source/*.c) +# Memory manager (use malloc() / free() ) +SOURCE_FILES += ${FREERTOS_DIR}/Source/portable/MemMang/heap_3.c +# posix port +SOURCE_FILES += ${FREERTOS_DIR}/Source/portable/ThirdParty/GCC/Posix/utils/wait_for_event.c +SOURCE_FILES += ${FREERTOS_DIR}/Source/portable/ThirdParty/GCC/Posix/port.c + +# FreeRTOS TCP +SOURCE_FILES += ${FREERTOS_PLUS_DIR}/Source/FreeRTOS-Plus-TCP/FreeRTOS_DNS.c +SOURCE_FILES += ${FREERTOS_PLUS_DIR}/Source/FreeRTOS-Plus-TCP/FreeRTOS_DHCP.c +SOURCE_FILES += ${FREERTOS_PLUS_DIR}/Source/FreeRTOS-Plus-TCP/FreeRTOS_ARP.c +SOURCE_FILES += ${FREERTOS_PLUS_DIR}/Source/FreeRTOS-Plus-TCP/FreeRTOS_TCP_WIN.c +SOURCE_FILES += ${FREERTOS_PLUS_DIR}/Source/FreeRTOS-Plus-TCP/FreeRTOS_Stream_Buffer.c +SOURCE_FILES += ${FREERTOS_PLUS_DIR}/Source/FreeRTOS-Plus-TCP/portable/BufferManagement/BufferAllocation_2.c +SOURCE_FILES += ${FREERTOS_PLUS_DIR}/Source/FreeRTOS-Plus-TCP/FreeRTOS_IP.c +SOURCE_FILES += ${FREERTOS_PLUS_DIR}/Source/FreeRTOS-Plus-TCP/FreeRTOS_TCP_IP.c +SOURCE_FILES += ${FREERTOS_PLUS_DIR}/Source/FreeRTOS-Plus-TCP/FreeRTOS_UDP_IP.c +SOURCE_FILES += ${FREERTOS_PLUS_DIR}/Source/FreeRTOS-Plus-TCP/FreeRTOS_Sockets.c +SOURCE_FILES += ${FREERTOS_PLUS_DIR}/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/linux/NetworkInterface.c + +# Demo library. +SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/AbortDelay.c +SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/BlockQ.c +SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/blocktim.c +SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/countsem.c +SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/death.c +SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/dynamic.c +SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/EventGroupsDemo.c +SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/flop.c +SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/GenQTest.c +SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/integer.c +SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/IntSemTest.c +SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/MessageBufferAMP.c +SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/MessageBufferDemo.c +SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/PollQ.c +SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/QPeek.c +SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/QueueOverwrite.c +SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/QueueSet.c +SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/QueueSetPolling.c +SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/recmutex.c +SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/semtest.c +SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/StaticAllocation.c +SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/StreamBufferDemo.c +SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/StreamBufferInterrupt.c +SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/TaskNotify.c +SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/TimerDemo.c + +# Trace library. +SOURCE_FILES += ${FREERTOS_PLUS_DIR}/Source/FreeRTOS-Plus-Trace/trcKernelPort.c +SOURCE_FILES += ${FREERTOS_PLUS_DIR}/Source/FreeRTOS-Plus-Trace/trcSnapshotRecorder.c +SOURCE_FILES += ${FREERTOS_PLUS_DIR}/Source/FreeRTOS-Plus-Trace/trcStreamingRecorder.c +SOURCE_FILES += ${FREERTOS_PLUS_DIR}/Source/FreeRTOS-Plus-Trace/streamports/File/trcStreamingPort.c + + +CFLAGS := -ggdb3 -O0 -DprojCOVERAGE_TEST=0 -D_WINDOWS_ +LDFLAGS := -ggdb3 -O0 -pthread -lpcap + +OBJ_FILES = $(SOURCE_FILES:%.c=$(BUILD_DIR)/%.o) + +DEP_FILE = $(OBJ_FILES:%.o=%.d) + +${BIN} : $(BUILD_DIR)/$(BIN) + +${BUILD_DIR}/${BIN} : ${OBJ_FILES} + -mkdir -p ${@D} + $(CC) $^ $(CFLAGS) $(INCLUDE_DIRS) ${LDFLAGS} -o $@ + + +-include ${DEP_FILE} + +${BUILD_DIR}/%.o : %.c + -mkdir -p $(@D) + $(CC) $(CFLAGS) ${INCLUDE_DIRS} -MMD -c $< -o $@ + +.PHONY: clean + +clean: + -rm -rf $(BUILD_DIR) + + + + + + + diff --git a/FreeRTOS/Demo/Posix_GCC/SConstruct b/FreeRTOS/Demo/Posix_GCC/SConstruct deleted file mode 100644 index e055a3c253..0000000000 --- a/FreeRTOS/Demo/Posix_GCC/SConstruct +++ /dev/null @@ -1,52 +0,0 @@ -# FreeRTOS Kernel V10.3.0 -# Copyright (C) 2020 Cambridge Consultants Ltd. -# -# 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 -# -# This is the main SCons (https://scons.org/) build file for the -# Posix/GCC demo application. - -import os - -# Create a symlink to the FreeRTOS sources. -if not os.path.exists("src/FreeRTOS"): - os.symlink("../../..", "src/FreeRTOS") -if not os.path.exists("src/FreeRTOS-Plus"): - os.symlink("../../../../FreeRTOS-Plus", "src/FreeRTOS-Plus") - -AddOption("--simple", - action='store_true', - help="build the simple 'blinky' demo application") - -AddOption("--coverage", - action='store_true', - help="enable code coverage") - -env = Environment() -Export("env") - -env.Append(CFLAGS = [ - "-g", - "-Wall", - "-O2", -]) - -SConscript("src/SConscript", variant_dir="build", duplicate=0) diff --git a/FreeRTOS/Demo/Posix_GCC/src/SimpleTCPEchoServer.c b/FreeRTOS/Demo/Posix_GCC/SimpleTCPEchoServer.c similarity index 97% rename from FreeRTOS/Demo/Posix_GCC/src/SimpleTCPEchoServer.c rename to FreeRTOS/Demo/Posix_GCC/SimpleTCPEchoServer.c index 2a2c704d74..ef690b894f 100644 --- a/FreeRTOS/Demo/Posix_GCC/src/SimpleTCPEchoServer.c +++ b/FreeRTOS/Demo/Posix_GCC/SimpleTCPEchoServer.c @@ -1,288 +1,288 @@ -/* - FreeRTOS V9.0.0 - Copyright (C) 2016 Real Time Engineers Ltd. - All rights reserved - - VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. - - This file is part of the FreeRTOS distribution. - - FreeRTOS is free software; you can redistribute it and/or modify it under - the terms of the GNU General Public License (version 2) as published by the - Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception. - - *************************************************************************** - >>! NOTE: The modification to the GPL is included to allow you to !<< - >>! distribute a combined work that includes FreeRTOS without being !<< - >>! obliged to provide the source code for proprietary components !<< - >>! outside of the FreeRTOS kernel. !<< - *************************************************************************** - - FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. Full license text is available on the following - link: http://www.freertos.org/a00114.html - - *************************************************************************** - * * - * FreeRTOS provides completely free yet professionally developed, * - * robust, strictly quality controlled, supported, and cross * - * platform software that is more than just the market leader, it * - * is the industry's de facto standard. * - * * - * Help yourself get started quickly while simultaneously helping * - * to support the FreeRTOS project by purchasing a FreeRTOS * - * tutorial book, reference manual, or both: * - * http://www.FreeRTOS.org/Documentation * - * * - *************************************************************************** - - http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading - the FAQ page "My application does not run, what could be wrong?". Have you - defined configASSERT()? - - http://www.FreeRTOS.org/support - In return for receiving this top quality - embedded software for free we request you assist our global community by - participating in the support forum. - - http://www.FreeRTOS.org/training - Investing in training allows your team to - be as productive as possible as early as possible. Now you can receive - FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers - Ltd, and the world's leading authority on the world's leading RTOS. - - http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, - including FreeRTOS+Trace - an indispensable productivity tool, a DOS - compatible FAT file system, and our tiny thread aware UDP/IP stack. - - http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate. - Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS. - - http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High - Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS - licenses offer ticketed support, indemnification and commercial middleware. - - http://www.SafeRTOS.com - High Integrity Systems also provide a safety - engineered and independently SIL3 certified version for use in safety and - mission critical applications that require provable dependability. - - 1 tab == 4 spaces! -*/ - -/* - * FreeRTOS tasks are used with FreeRTOS+TCP to create a TCP echo server on the - * standard echo port number (7). - * - * See the following web page for essential demo usage and configuration - * details: - * http://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_Echo_Server.html - */ - -/* Standard includes. */ -#include -#include - -/* FreeRTOS includes. */ -#include "FreeRTOS.h" -#include "task.h" -#include "semphr.h" - -/* FreeRTOS+TCP includes. */ -#include "FreeRTOS_IP.h" -#include "FreeRTOS_Sockets.h" - -/* Remove the whole file if FreeRTOSIPConfig.h is set to exclude TCP. */ -#if( ipconfigUSE_TCP == 1 ) - -/* The maximum time to wait for a closing socket to close. */ -#define tcpechoSHUTDOWN_DELAY ( pdMS_TO_TICKS( 5000 ) ) - -/* The standard echo port number. */ -#define tcpechoPORT_NUMBER 7 - -/* If ipconfigUSE_TCP_WIN is 1 then the Tx sockets will use a buffer size set by -ipconfigTCP_TX_BUFFER_LENGTH, and the Tx window size will be -configECHO_SERVER_TX_WINDOW_SIZE times the buffer size. Note -ipconfigTCP_TX_BUFFER_LENGTH is set in FreeRTOSIPConfig.h as it is a standard TCP/IP -stack constant, whereas configECHO_SERVER_TX_WINDOW_SIZE is set in -FreeRTOSConfig.h as it is a demo application constant. */ -#ifndef configECHO_SERVER_TX_WINDOW_SIZE - #define configECHO_SERVER_TX_WINDOW_SIZE 2 -#endif - -/* If ipconfigUSE_TCP_WIN is 1 then the Rx sockets will use a buffer size set by -ipconfigTCP_RX_BUFFER_LENGTH, and the Rx window size will be -configECHO_SERVER_RX_WINDOW_SIZE times the buffer size. Note -ipconfigTCP_RX_BUFFER_LENGTH is set in FreeRTOSIPConfig.h as it is a standard TCP/IP -stack constant, whereas configECHO_SERVER_RX_WINDOW_SIZE is set in -FreeRTOSConfig.h as it is a demo application constant. */ -#ifndef configECHO_SERVER_RX_WINDOW_SIZE - #define configECHO_SERVER_RX_WINDOW_SIZE 2 -#endif - -/*-----------------------------------------------------------*/ - -/* - * Uses FreeRTOS+TCP to listen for incoming echo connections, creating a task - * to handle each connection. - */ -static void prvConnectionListeningTask( void *pvParameters ); - -/* - * Created by the connection listening task to handle a single connection. - */ -static void prvServerConnectionInstance( void *pvParameters ); - -/*-----------------------------------------------------------*/ - -/* Stores the stack size passed into vStartSimpleTCPServerTasks() so it can be -reused when the server listening task creates tasks to handle connections. */ -static uint16_t usUsedStackSize = 0; - -/*-----------------------------------------------------------*/ - -void vStartSimpleTCPServerTasks( uint16_t usStackSize, UBaseType_t uxPriority ) -{ - /* Create the TCP echo server. */ - xTaskCreate( prvConnectionListeningTask, "ServerListener", usStackSize, NULL, uxPriority + 1, NULL ); - - /* Remember the requested stack size so it can be re-used by the server - listening task when it creates tasks to handle connections. */ - usUsedStackSize = usStackSize; -} -/*-----------------------------------------------------------*/ - -static void prvConnectionListeningTask( void *pvParameters ) -{ -struct freertos_sockaddr xClient, xBindAddress; -Socket_t xListeningSocket, xConnectedSocket; -socklen_t xSize = sizeof( xClient ); -static const TickType_t xReceiveTimeOut = portMAX_DELAY; -const BaseType_t xBacklog = 20; - -#if( ipconfigUSE_TCP_WIN == 1 ) - WinProperties_t xWinProps; - - /* Fill in the buffer and window sizes that will be used by the socket. */ - xWinProps.lTxBufSize = ipconfigTCP_TX_BUFFER_LENGTH; - xWinProps.lTxWinSize = configECHO_SERVER_TX_WINDOW_SIZE; - xWinProps.lRxBufSize = ipconfigTCP_RX_BUFFER_LENGTH; - xWinProps.lRxWinSize = configECHO_SERVER_RX_WINDOW_SIZE; -#endif /* ipconfigUSE_TCP_WIN */ - - /* Just to prevent compiler warnings. */ - ( void ) pvParameters; - - /* Attempt to open the socket. */ - xListeningSocket = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_STREAM, FREERTOS_IPPROTO_TCP ); - configASSERT( xListeningSocket != FREERTOS_INVALID_SOCKET ); - - /* Set a time out so accept() will just wait for a connection. */ - FreeRTOS_setsockopt( xListeningSocket, 0, FREERTOS_SO_RCVTIMEO, &xReceiveTimeOut, sizeof( xReceiveTimeOut ) ); - - /* Set the window and buffer sizes. */ - #if( ipconfigUSE_TCP_WIN == 1 ) - { - FreeRTOS_setsockopt( xListeningSocket, 0, FREERTOS_SO_WIN_PROPERTIES, ( void * ) &xWinProps, sizeof( xWinProps ) ); - } - #endif /* ipconfigUSE_TCP_WIN */ - - /* Bind the socket to the port that the client task will send to, then - listen for incoming connections. */ - xBindAddress.sin_port = tcpechoPORT_NUMBER; - xBindAddress.sin_port = FreeRTOS_htons( xBindAddress.sin_port ); - FreeRTOS_bind( xListeningSocket, &xBindAddress, sizeof( xBindAddress ) ); - FreeRTOS_listen( xListeningSocket, xBacklog ); - - for( ;; ) - { - /* Wait for a client to connect. */ - xConnectedSocket = FreeRTOS_accept( xListeningSocket, &xClient, &xSize ); - configASSERT( xConnectedSocket != FREERTOS_INVALID_SOCKET ); - - /* Spawn a task to handle the connection. */ - xTaskCreate( prvServerConnectionInstance, "EchoServer", usUsedStackSize, ( void * ) xConnectedSocket, tskIDLE_PRIORITY, NULL ); - } -} -/*-----------------------------------------------------------*/ - -static void prvServerConnectionInstance( void *pvParameters ) -{ -int32_t lBytes, lSent, lTotalSent; -Socket_t xConnectedSocket; -static const TickType_t xReceiveTimeOut = pdMS_TO_TICKS( 5000 ); -static const TickType_t xSendTimeOut = pdMS_TO_TICKS( 5000 ); -TickType_t xTimeOnShutdown; -uint8_t *pucRxBuffer; - - xConnectedSocket = ( Socket_t ) pvParameters; - - /* Attempt to create the buffer used to receive the string to be echoed - back. This could be avoided using a zero copy interface that just returned - the same buffer. */ - pucRxBuffer = ( uint8_t * ) pvPortMalloc( ipconfigTCP_MSS ); - - if( pucRxBuffer != NULL ) - { - FreeRTOS_setsockopt( xConnectedSocket, 0, FREERTOS_SO_RCVTIMEO, &xReceiveTimeOut, sizeof( xReceiveTimeOut ) ); - FreeRTOS_setsockopt( xConnectedSocket, 0, FREERTOS_SO_SNDTIMEO, &xSendTimeOut, sizeof( xReceiveTimeOut ) ); - - for( ;; ) - { - /* Zero out the receive array so there is NULL at the end of the string - when it is printed out. */ - memset( pucRxBuffer, 0x00, ipconfigTCP_MSS ); - - /* Receive data on the socket. */ - lBytes = FreeRTOS_recv( xConnectedSocket, pucRxBuffer, ipconfigTCP_MSS, 0 ); - - /* If data was received, echo it back. */ - if( lBytes >= 0 ) - { - lSent = 0; - lTotalSent = 0; - - /* Call send() until all the data has been sent. */ - while( ( lSent >= 0 ) && ( lTotalSent < lBytes ) ) - { - lSent = FreeRTOS_send( xConnectedSocket, pucRxBuffer, lBytes - lTotalSent, 0 ); - lTotalSent += lSent; - } - - if( lSent < 0 ) - { - /* Socket closed? */ - break; - } - } - else - { - /* Socket closed? */ - break; - } - } - } - - /* Initiate a shutdown in case it has not already been initiated. */ - FreeRTOS_shutdown( xConnectedSocket, FREERTOS_SHUT_RDWR ); - - /* Wait for the shutdown to take effect, indicated by FreeRTOS_recv() - returning an error. */ - xTimeOnShutdown = xTaskGetTickCount(); - do - { - if( FreeRTOS_recv( xConnectedSocket, pucRxBuffer, ipconfigTCP_MSS, 0 ) < 0 ) - { - break; - } - } while( ( xTaskGetTickCount() - xTimeOnShutdown ) < tcpechoSHUTDOWN_DELAY ); - - /* Finished with the socket, buffer, the task. */ - vPortFree( pucRxBuffer ); - FreeRTOS_closesocket( xConnectedSocket ); - - vTaskDelete( NULL ); -} -/*-----------------------------------------------------------*/ - -/* The whole file is excluded if TCP is not compiled in. */ -#endif /* ipconfigUSE_TCP */ - +/* + FreeRTOS V9.0.0 - Copyright (C) 2016 Real Time Engineers Ltd. + All rights reserved + + VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. + + This file is part of the FreeRTOS distribution. + + FreeRTOS is free software; you can redistribute it and/or modify it under + the terms of the GNU General Public License (version 2) as published by the + Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception. + + *************************************************************************** + >>! NOTE: The modification to the GPL is included to allow you to !<< + >>! distribute a combined work that includes FreeRTOS without being !<< + >>! obliged to provide the source code for proprietary components !<< + >>! outside of the FreeRTOS kernel. !<< + *************************************************************************** + + FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. Full license text is available on the following + link: http://www.freertos.org/a00114.html + + *************************************************************************** + * * + * FreeRTOS provides completely free yet professionally developed, * + * robust, strictly quality controlled, supported, and cross * + * platform software that is more than just the market leader, it * + * is the industry's de facto standard. * + * * + * Help yourself get started quickly while simultaneously helping * + * to support the FreeRTOS project by purchasing a FreeRTOS * + * tutorial book, reference manual, or both: * + * http://www.FreeRTOS.org/Documentation * + * * + *************************************************************************** + + http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading + the FAQ page "My application does not run, what could be wrong?". Have you + defined configASSERT()? + + http://www.FreeRTOS.org/support - In return for receiving this top quality + embedded software for free we request you assist our global community by + participating in the support forum. + + http://www.FreeRTOS.org/training - Investing in training allows your team to + be as productive as possible as early as possible. Now you can receive + FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers + Ltd, and the world's leading authority on the world's leading RTOS. + + http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, + including FreeRTOS+Trace - an indispensable productivity tool, a DOS + compatible FAT file system, and our tiny thread aware UDP/IP stack. + + http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate. + Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS. + + http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High + Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS + licenses offer ticketed support, indemnification and commercial middleware. + + http://www.SafeRTOS.com - High Integrity Systems also provide a safety + engineered and independently SIL3 certified version for use in safety and + mission critical applications that require provable dependability. + + 1 tab == 4 spaces! +*/ + +/* + * FreeRTOS tasks are used with FreeRTOS+TCP to create a TCP echo server on the + * standard echo port number (7). + * + * See the following web page for essential demo usage and configuration + * details: + * http://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_Echo_Server.html + */ + +/* Standard includes. */ +#include +#include + +/* FreeRTOS includes. */ +#include "FreeRTOS.h" +#include "task.h" +#include "semphr.h" + +/* FreeRTOS+TCP includes. */ +#include "FreeRTOS_IP.h" +#include "FreeRTOS_Sockets.h" + +/* Remove the whole file if FreeRTOSIPConfig.h is set to exclude TCP. */ +#if( ipconfigUSE_TCP == 1 ) + +/* The maximum time to wait for a closing socket to close. */ +#define tcpechoSHUTDOWN_DELAY ( pdMS_TO_TICKS( 5000 ) ) + +/* The standard echo port number. */ +#define tcpechoPORT_NUMBER 7 + +/* If ipconfigUSE_TCP_WIN is 1 then the Tx sockets will use a buffer size set by +ipconfigTCP_TX_BUFFER_LENGTH, and the Tx window size will be +configECHO_SERVER_TX_WINDOW_SIZE times the buffer size. Note +ipconfigTCP_TX_BUFFER_LENGTH is set in FreeRTOSIPConfig.h as it is a standard TCP/IP +stack constant, whereas configECHO_SERVER_TX_WINDOW_SIZE is set in +FreeRTOSConfig.h as it is a demo application constant. */ +#ifndef configECHO_SERVER_TX_WINDOW_SIZE + #define configECHO_SERVER_TX_WINDOW_SIZE 2 +#endif + +/* If ipconfigUSE_TCP_WIN is 1 then the Rx sockets will use a buffer size set by +ipconfigTCP_RX_BUFFER_LENGTH, and the Rx window size will be +configECHO_SERVER_RX_WINDOW_SIZE times the buffer size. Note +ipconfigTCP_RX_BUFFER_LENGTH is set in FreeRTOSIPConfig.h as it is a standard TCP/IP +stack constant, whereas configECHO_SERVER_RX_WINDOW_SIZE is set in +FreeRTOSConfig.h as it is a demo application constant. */ +#ifndef configECHO_SERVER_RX_WINDOW_SIZE + #define configECHO_SERVER_RX_WINDOW_SIZE 2 +#endif + +/*-----------------------------------------------------------*/ + +/* + * Uses FreeRTOS+TCP to listen for incoming echo connections, creating a task + * to handle each connection. + */ +static void prvConnectionListeningTask( void *pvParameters ); + +/* + * Created by the connection listening task to handle a single connection. + */ +static void prvServerConnectionInstance( void *pvParameters ); + +/*-----------------------------------------------------------*/ + +/* Stores the stack size passed into vStartSimpleTCPServerTasks() so it can be +reused when the server listening task creates tasks to handle connections. */ +static uint16_t usUsedStackSize = 0; + +/*-----------------------------------------------------------*/ + +void vStartSimpleTCPServerTasks( uint16_t usStackSize, UBaseType_t uxPriority ) +{ + /* Create the TCP echo server. */ + xTaskCreate( prvConnectionListeningTask, "ServerListener", usStackSize, NULL, uxPriority + 1, NULL ); + + /* Remember the requested stack size so it can be re-used by the server + listening task when it creates tasks to handle connections. */ + usUsedStackSize = usStackSize; +} +/*-----------------------------------------------------------*/ + +static void prvConnectionListeningTask( void *pvParameters ) +{ +struct freertos_sockaddr xClient, xBindAddress; +Socket_t xListeningSocket, xConnectedSocket; +socklen_t xSize = sizeof( xClient ); +static const TickType_t xReceiveTimeOut = portMAX_DELAY; +const BaseType_t xBacklog = 20; + +#if( ipconfigUSE_TCP_WIN == 1 ) + WinProperties_t xWinProps; + + /* Fill in the buffer and window sizes that will be used by the socket. */ + xWinProps.lTxBufSize = ipconfigTCP_TX_BUFFER_LENGTH; + xWinProps.lTxWinSize = configECHO_SERVER_TX_WINDOW_SIZE; + xWinProps.lRxBufSize = ipconfigTCP_RX_BUFFER_LENGTH; + xWinProps.lRxWinSize = configECHO_SERVER_RX_WINDOW_SIZE; +#endif /* ipconfigUSE_TCP_WIN */ + + /* Just to prevent compiler warnings. */ + ( void ) pvParameters; + + /* Attempt to open the socket. */ + xListeningSocket = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_STREAM, FREERTOS_IPPROTO_TCP ); + configASSERT( xListeningSocket != FREERTOS_INVALID_SOCKET ); + + /* Set a time out so accept() will just wait for a connection. */ + FreeRTOS_setsockopt( xListeningSocket, 0, FREERTOS_SO_RCVTIMEO, &xReceiveTimeOut, sizeof( xReceiveTimeOut ) ); + + /* Set the window and buffer sizes. */ + #if( ipconfigUSE_TCP_WIN == 1 ) + { + FreeRTOS_setsockopt( xListeningSocket, 0, FREERTOS_SO_WIN_PROPERTIES, ( void * ) &xWinProps, sizeof( xWinProps ) ); + } + #endif /* ipconfigUSE_TCP_WIN */ + + /* Bind the socket to the port that the client task will send to, then + listen for incoming connections. */ + xBindAddress.sin_port = tcpechoPORT_NUMBER; + xBindAddress.sin_port = FreeRTOS_htons( xBindAddress.sin_port ); + FreeRTOS_bind( xListeningSocket, &xBindAddress, sizeof( xBindAddress ) ); + FreeRTOS_listen( xListeningSocket, xBacklog ); + + for( ;; ) + { + /* Wait for a client to connect. */ + xConnectedSocket = FreeRTOS_accept( xListeningSocket, &xClient, &xSize ); + configASSERT( xConnectedSocket != FREERTOS_INVALID_SOCKET ); + + /* Spawn a task to handle the connection. */ + xTaskCreate( prvServerConnectionInstance, "EchoServer", usUsedStackSize, ( void * ) xConnectedSocket, tskIDLE_PRIORITY, NULL ); + } +} +/*-----------------------------------------------------------*/ + +static void prvServerConnectionInstance( void *pvParameters ) +{ +int32_t lBytes, lSent, lTotalSent; +Socket_t xConnectedSocket; +static const TickType_t xReceiveTimeOut = pdMS_TO_TICKS( 5000 ); +static const TickType_t xSendTimeOut = pdMS_TO_TICKS( 5000 ); +TickType_t xTimeOnShutdown; +uint8_t *pucRxBuffer; + + xConnectedSocket = ( Socket_t ) pvParameters; + + /* Attempt to create the buffer used to receive the string to be echoed + back. This could be avoided using a zero copy interface that just returned + the same buffer. */ + pucRxBuffer = ( uint8_t * ) pvPortMalloc( ipconfigTCP_MSS ); + + if( pucRxBuffer != NULL ) + { + FreeRTOS_setsockopt( xConnectedSocket, 0, FREERTOS_SO_RCVTIMEO, &xReceiveTimeOut, sizeof( xReceiveTimeOut ) ); + FreeRTOS_setsockopt( xConnectedSocket, 0, FREERTOS_SO_SNDTIMEO, &xSendTimeOut, sizeof( xReceiveTimeOut ) ); + + for( ;; ) + { + /* Zero out the receive array so there is NULL at the end of the string + when it is printed out. */ + memset( pucRxBuffer, 0x00, ipconfigTCP_MSS ); + + /* Receive data on the socket. */ + lBytes = FreeRTOS_recv( xConnectedSocket, pucRxBuffer, ipconfigTCP_MSS, 0 ); + + /* If data was received, echo it back. */ + if( lBytes >= 0 ) + { + lSent = 0; + lTotalSent = 0; + + /* Call send() until all the data has been sent. */ + while( ( lSent >= 0 ) && ( lTotalSent < lBytes ) ) + { + lSent = FreeRTOS_send( xConnectedSocket, pucRxBuffer, lBytes - lTotalSent, 0 ); + lTotalSent += lSent; + } + + if( lSent < 0 ) + { + /* Socket closed? */ + break; + } + } + else + { + /* Socket closed? */ + break; + } + } + } + + /* Initiate a shutdown in case it has not already been initiated. */ + FreeRTOS_shutdown( xConnectedSocket, FREERTOS_SHUT_RDWR ); + + /* Wait for the shutdown to take effect, indicated by FreeRTOS_recv() + returning an error. */ + xTimeOnShutdown = xTaskGetTickCount(); + do + { + if( FreeRTOS_recv( xConnectedSocket, pucRxBuffer, ipconfigTCP_MSS, 0 ) < 0 ) + { + break; + } + } while( ( xTaskGetTickCount() - xTimeOnShutdown ) < tcpechoSHUTDOWN_DELAY ); + + /* Finished with the socket, buffer, the task. */ + vPortFree( pucRxBuffer ); + FreeRTOS_closesocket( xConnectedSocket ); + + vTaskDelete( NULL ); +} +/*-----------------------------------------------------------*/ + +/* The whole file is excluded if TCP is not compiled in. */ +#endif /* ipconfigUSE_TCP */ + diff --git a/FreeRTOS/Demo/Posix_GCC/src/TCPEchoClient_SingleTasks.c b/FreeRTOS/Demo/Posix_GCC/TCPEchoClient_SingleTasks.c similarity index 97% rename from FreeRTOS/Demo/Posix_GCC/src/TCPEchoClient_SingleTasks.c rename to FreeRTOS/Demo/Posix_GCC/TCPEchoClient_SingleTasks.c index 4fc2fc08af..5497d14033 100644 --- a/FreeRTOS/Demo/Posix_GCC/src/TCPEchoClient_SingleTasks.c +++ b/FreeRTOS/Demo/Posix_GCC/TCPEchoClient_SingleTasks.c @@ -1,372 +1,372 @@ -/* - * FreeRTOS Kernel V10.3.0 - * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * 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! - */ - -/* - * A set of tasks are created that send TCP echo requests to the standard echo - * port (port 7) on the IP address set by the configECHO_SERVER_ADDR0 to - * configECHO_SERVER_ADDR3 constants, then wait for and verify the reply - * (another demo is avilable that demonstrates the reception being performed in - * a task other than that from with the request was made). - * - * See the following web page for essential demo usage and configuration - * details: - * http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/examples_FreeRTOS_simulator.html - */ - -/* Standard includes. */ -#include -#include -#include - -/* FreeRTOS includes. */ -#include "FreeRTOS.h" -#include "task.h" -#include "queue.h" - -/* FreeRTOS+TCP includes. */ -#include "FreeRTOS_IP.h" -#include "FreeRTOS_Sockets.h" - -/* Exclude the whole file if FreeRTOSIPConfig.h is configured to use UDP only. */ -#if ( ipconfigUSE_TCP == 1 ) - -/* The echo tasks create a socket, send out a number of echo requests, listen -for the echo reply, then close the socket again before starting over. This -delay is used between each iteration to ensure the network does not get too -congested. */ - #define echoLOOP_DELAY ( ( TickType_t ) 150 / portTICK_PERIOD_MS ) - -/* The echo server is assumed to be on port 7, which is the standard echo -protocol port. */ - #define echoECHO_PORT ( 7 ) - -/* The size of the buffers is a multiple of the MSS - the length of the data -sent is a pseudo random size between 20 and echoBUFFER_SIZES. */ - #define echoBUFFER_SIZE_MULTIPLIER ( 3 ) - #define echoBUFFER_SIZES ( ipconfigTCP_MSS * echoBUFFER_SIZE_MULTIPLIER ) - -/* The number of instances of the echo client task to create. */ - #define echoNUM_ECHO_CLIENTS ( 1 ) - -/*-----------------------------------------------------------*/ - -/* - * Uses a socket to send data to, then receive data from, the standard echo - * port number 7. - */ - static void prvEchoClientTask( void *pvParameters ); - -/* - * Creates a pseudo random sized buffer of data to send to the echo server. - */ - static BaseType_t prvCreateTxData( char *ucBuffer, - uint32_t ulBufferLength ); - -/*-----------------------------------------------------------*/ - -/* Rx and Tx time outs are used to ensure the sockets do not wait too long for -missing data. */ - static const TickType_t xReceiveTimeOut = pdMS_TO_TICKS( 4000 ); - static const TickType_t xSendTimeOut = pdMS_TO_TICKS( 2000 ); - -/* Counters for each created task - for inspection only. */ - static uint32_t ulTxRxCycles[ echoNUM_ECHO_CLIENTS ] = { 0 }, - ulTxRxFailures[ echoNUM_ECHO_CLIENTS ] = { 0 }, - ulConnections[ echoNUM_ECHO_CLIENTS ] = { 0 }; - -/* Rx and Tx buffers for each created task. */ - static char cTxBuffers[ echoNUM_ECHO_CLIENTS ][ echoBUFFER_SIZES ], - cRxBuffers[ echoNUM_ECHO_CLIENTS ][ echoBUFFER_SIZES ]; - -/*-----------------------------------------------------------*/ - - void vStartTCPEchoClientTasks_SingleTasks( uint16_t usTaskStackSize, - UBaseType_t uxTaskPriority ) - { - BaseType_t x; - - /* Create the echo client tasks. */ - for( x = 0; x < echoNUM_ECHO_CLIENTS; x++ ) - { - xTaskCreate( prvEchoClientTask, /* The function that implements the task. */ - "Echo0", /* Just a text name for the task to aid debugging. */ - usTaskStackSize, /* The stack size is defined in FreeRTOSIPConfig.h. */ - ( void * ) x, /* The task parameter, not used in this case. */ - uxTaskPriority, /* The priority assigned to the task is defined in FreeRTOSConfig.h. */ - NULL ); /* The task handle is not used. */ - } - } -/*-----------------------------------------------------------*/ - - static void prvEchoClientTask( void *pvParameters ) - { - Socket_t xSocket; - struct freertos_sockaddr xEchoServerAddress; - int32_t lLoopCount = 0UL; - const int32_t lMaxLoopCount = 1; - volatile uint32_t ulTxCount = 0UL; - BaseType_t xReceivedBytes, xReturned, xInstance; - BaseType_t lTransmitted, lStringLength; - char *pcTransmittedString, *pcReceivedString; - WinProperties_t xWinProps; - TickType_t xTimeOnEntering; - BaseType_t ret; - - /* Fill in the buffer and window sizes that will be used by the socket. */ - xWinProps.lTxBufSize = 6 * ipconfigTCP_MSS; - xWinProps.lTxWinSize = 3; - xWinProps.lRxBufSize = 6 * ipconfigTCP_MSS; - xWinProps.lRxWinSize = 3; - - /* This task can be created a number of times. Each instance is numbered - to enable each instance to use a different Rx and Tx buffer. The number is - passed in as the task's parameter. */ - xInstance = ( BaseType_t ) pvParameters; - - /* Point to the buffers to be used by this instance of this task. */ - pcTransmittedString = &( cTxBuffers[ xInstance ][ 0 ] ); - pcReceivedString = &( cRxBuffers[ xInstance ][ 0 ] ); - - /* Echo requests are sent to the echo server. The address of the echo - server is configured by the constants configECHO_SERVER_ADDR0 to - configECHO_SERVER_ADDR3 in FreeRTOSConfig.h. */ - xEchoServerAddress.sin_port = FreeRTOS_htons( echoECHO_PORT ); - xEchoServerAddress.sin_addr = FreeRTOS_inet_addr_quick( configECHO_SERVER_ADDR0, - configECHO_SERVER_ADDR1, - configECHO_SERVER_ADDR2, - configECHO_SERVER_ADDR3 ); - - for( ; ; ) - { - /* Create a TCP socket. */ - xSocket = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_STREAM, FREERTOS_IPPROTO_TCP ); - configASSERT( xSocket != FREERTOS_INVALID_SOCKET ); - - /* Set a time out so a missing reply does not cause the task to block - indefinitely. */ - FreeRTOS_setsockopt( xSocket, 0, FREERTOS_SO_RCVTIMEO, &xReceiveTimeOut, sizeof( xReceiveTimeOut ) ); - FreeRTOS_setsockopt( xSocket, 0, FREERTOS_SO_SNDTIMEO, &xSendTimeOut, sizeof( xSendTimeOut ) ); - - /* Set the window and buffer sizes. */ - FreeRTOS_setsockopt( xSocket, 0, FREERTOS_SO_WIN_PROPERTIES, ( void * ) &xWinProps, sizeof( xWinProps ) ); - - /* Connect to the echo server. */ - printf( "connecting to echo server....\n" ); - - ret = FreeRTOS_connect( xSocket, &xEchoServerAddress, sizeof( xEchoServerAddress ) ); - - if( ret == 0 ) - { - printf( "Connected to server.. \n" ); - ulConnections[ xInstance ]++; - - /* Send a number of echo requests. */ - for( lLoopCount = 0; lLoopCount < lMaxLoopCount; lLoopCount++ ) - { - /* Create the string that is sent to the echo server. */ - lStringLength = prvCreateTxData( pcTransmittedString, echoBUFFER_SIZES ); - - /* Add in some unique text at the front of the string. */ - sprintf( pcTransmittedString, "TxRx message number %u", ulTxCount ); - ulTxCount++; - - printf( "sending data to the echo server \n" ); - /* Send the string to the socket. */ - lTransmitted = FreeRTOS_send( xSocket, /* The socket being sent to. */ - ( void * ) pcTransmittedString, /* The data being sent. */ - lStringLength, /* The length of the data being sent. */ - 0 ); /* No flags. */ - - if( lTransmitted < 0 ) - { - /* Error? */ - break; - } - - /* Clear the buffer into which the echoed string will be - placed. */ - memset( ( void * ) pcReceivedString, 0x00, echoBUFFER_SIZES ); - xReceivedBytes = 0; - - /* Receive data echoed back to the socket. */ - while( xReceivedBytes < lTransmitted ) - { - xReturned = FreeRTOS_recv( xSocket, /* The socket being received from. */ - &( pcReceivedString[ xReceivedBytes ] ), /* The buffer into which the received data will be written. */ - lStringLength - xReceivedBytes, /* The size of the buffer provided to receive the data. */ - 0 ); /* No flags. */ - - if( xReturned < 0 ) - { - /* Error occurred. Latch it so it can be detected - below. */ - xReceivedBytes = xReturned; - break; - } - else if( xReturned == 0 ) - { - /* Timed out. */ - break; - } - else - { - /* Keep a count of the bytes received so far. */ - xReceivedBytes += xReturned; - } - } - - /* If an error occurred it will be latched in xReceivedBytes, - otherwise xReceived bytes will be just that - the number of - bytes received from the echo server. */ - if( xReceivedBytes > 0 ) - { - /* Compare the transmitted string to the received string. */ - configASSERT( strncmp( pcReceivedString, pcTransmittedString, lTransmitted ) == 0 ); - - if( strncmp( pcReceivedString, pcTransmittedString, lTransmitted ) == 0 ) - { - /* The echo reply was received without error. */ - ulTxRxCycles[ xInstance ]++; - } - else - { - /* The received string did not match the transmitted - string. */ - ulTxRxFailures[ xInstance ]++; - break; - } - } - else if( xReceivedBytes < 0 ) - { - /* FreeRTOS_recv() returned an error. */ - break; - } - else - { - /* Timed out without receiving anything? */ - break; - } - } - - /* Finished using the connected socket, initiate a graceful close: - FIN, FIN+ACK, ACK. */ - FreeRTOS_shutdown( xSocket, FREERTOS_SHUT_RDWR ); - - /* Expect FreeRTOS_recv() to return an error once the shutdown is - complete. */ - xTimeOnEntering = xTaskGetTickCount(); - - do - { - xReturned = FreeRTOS_recv( xSocket, /* The socket being received from. */ - &( pcReceivedString[ 0 ] ), /* The buffer into which the received data will be written. */ - echoBUFFER_SIZES, /* The size of the buffer provided to receive the data. */ - 0 ); - - if( xReturned < 0 ) - { - break; - } - } while( ( xTaskGetTickCount() - xTimeOnEntering ) < xReceiveTimeOut ); - } - else - { - printf( "Could not connect to server %ld\n", ret ); - } - - /* Close this socket before looping back to create another. */ - FreeRTOS_closesocket( xSocket ); - - /* Pause for a short while to ensure the network is not too - congested. */ - vTaskDelay( echoLOOP_DELAY ); - } - } -/*-----------------------------------------------------------*/ - - static BaseType_t prvCreateTxData( char *cBuffer, - uint32_t ulBufferLength ) - { - BaseType_t lCharactersToAdd, lCharacter; - char cChar = '0'; - const BaseType_t lMinimumLength = 60; - - /* Randomise the number of characters that will be sent in the echo - request. */ - do - { - lCharactersToAdd = ipconfigRAND32() % ( ulBufferLength - 20UL ); - } while( ( lCharactersToAdd == 0 ) || ( lCharactersToAdd < lMinimumLength ) ); /* Must be at least enough to add the unique text to the start of the string later. */ - - /* Fill the buffer. */ - for( lCharacter = 0; lCharacter < lCharactersToAdd; lCharacter++ ) - { - cBuffer[ lCharacter ] = cChar; - cChar++; - - if( cChar > '~' ) - { - cChar = '0'; - } - } - - return lCharactersToAdd; - } -/*-----------------------------------------------------------*/ - - BaseType_t xAreSingleTaskTCPEchoClientsStillRunning( void ) - { - static uint32_t ulLastEchoSocketCount[ echoNUM_ECHO_CLIENTS ] = { 0 }, ulLastConnections[ echoNUM_ECHO_CLIENTS ] = { 0 }; - BaseType_t xReturn = pdPASS, x; - - /* Return fail is the number of cycles does not increment between - consecutive calls. */ - for( x = 0; x < echoNUM_ECHO_CLIENTS; x++ ) - { - if( ulTxRxCycles[ x ] == ulLastEchoSocketCount[ x ] ) - { - xReturn = pdFAIL; - } - else - { - ulLastEchoSocketCount[ x ] = ulTxRxCycles[ x ]; - } - - if( ulConnections[ x ] == ulLastConnections[ x ] ) - { - xReturn = pdFAIL; - } - else - { - ulConnections[ x ] = ulLastConnections[ x ]; - } - } - - return xReturn; - } - -#endif /* ipconfigUSE_TCP */ +/* + * FreeRTOS Kernel V10.3.0 + * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * 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! + */ + +/* + * A set of tasks are created that send TCP echo requests to the standard echo + * port (port 7) on the IP address set by the configECHO_SERVER_ADDR0 to + * configECHO_SERVER_ADDR3 constants, then wait for and verify the reply + * (another demo is avilable that demonstrates the reception being performed in + * a task other than that from with the request was made). + * + * See the following web page for essential demo usage and configuration + * details: + * http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/examples_FreeRTOS_simulator.html + */ + +/* Standard includes. */ +#include +#include +#include + +/* FreeRTOS includes. */ +#include "FreeRTOS.h" +#include "task.h" +#include "queue.h" + +/* FreeRTOS+TCP includes. */ +#include "FreeRTOS_IP.h" +#include "FreeRTOS_Sockets.h" + +/* Exclude the whole file if FreeRTOSIPConfig.h is configured to use UDP only. */ +#if ( ipconfigUSE_TCP == 1 ) + +/* The echo tasks create a socket, send out a number of echo requests, listen +for the echo reply, then close the socket again before starting over. This +delay is used between each iteration to ensure the network does not get too +congested. */ + #define echoLOOP_DELAY ( ( TickType_t ) 150 / portTICK_PERIOD_MS ) + +/* The echo server is assumed to be on port 7, which is the standard echo +protocol port. */ + #define echoECHO_PORT ( 7 ) + +/* The size of the buffers is a multiple of the MSS - the length of the data +sent is a pseudo random size between 20 and echoBUFFER_SIZES. */ + #define echoBUFFER_SIZE_MULTIPLIER ( 3 ) + #define echoBUFFER_SIZES ( ipconfigTCP_MSS * echoBUFFER_SIZE_MULTIPLIER ) + +/* The number of instances of the echo client task to create. */ + #define echoNUM_ECHO_CLIENTS ( 1 ) + +/*-----------------------------------------------------------*/ + +/* + * Uses a socket to send data to, then receive data from, the standard echo + * port number 7. + */ + static void prvEchoClientTask( void *pvParameters ); + +/* + * Creates a pseudo random sized buffer of data to send to the echo server. + */ + static BaseType_t prvCreateTxData( char *ucBuffer, + uint32_t ulBufferLength ); + +/*-----------------------------------------------------------*/ + +/* Rx and Tx time outs are used to ensure the sockets do not wait too long for +missing data. */ + static const TickType_t xReceiveTimeOut = pdMS_TO_TICKS( 4000 ); + static const TickType_t xSendTimeOut = pdMS_TO_TICKS( 2000 ); + +/* Counters for each created task - for inspection only. */ + static uint32_t ulTxRxCycles[ echoNUM_ECHO_CLIENTS ] = { 0 }, + ulTxRxFailures[ echoNUM_ECHO_CLIENTS ] = { 0 }, + ulConnections[ echoNUM_ECHO_CLIENTS ] = { 0 }; + +/* Rx and Tx buffers for each created task. */ + static char cTxBuffers[ echoNUM_ECHO_CLIENTS ][ echoBUFFER_SIZES ], + cRxBuffers[ echoNUM_ECHO_CLIENTS ][ echoBUFFER_SIZES ]; + +/*-----------------------------------------------------------*/ + + void vStartTCPEchoClientTasks_SingleTasks( uint16_t usTaskStackSize, + UBaseType_t uxTaskPriority ) + { + BaseType_t x; + + /* Create the echo client tasks. */ + for( x = 0; x < echoNUM_ECHO_CLIENTS; x++ ) + { + xTaskCreate( prvEchoClientTask, /* The function that implements the task. */ + "Echo0", /* Just a text name for the task to aid debugging. */ + usTaskStackSize, /* The stack size is defined in FreeRTOSIPConfig.h. */ + ( void * ) x, /* The task parameter, not used in this case. */ + uxTaskPriority, /* The priority assigned to the task is defined in FreeRTOSConfig.h. */ + NULL ); /* The task handle is not used. */ + } + } +/*-----------------------------------------------------------*/ + + static void prvEchoClientTask( void *pvParameters ) + { + Socket_t xSocket; + struct freertos_sockaddr xEchoServerAddress; + int32_t lLoopCount = 0UL; + const int32_t lMaxLoopCount = 1; + volatile uint32_t ulTxCount = 0UL; + BaseType_t xReceivedBytes, xReturned, xInstance; + BaseType_t lTransmitted, lStringLength; + char *pcTransmittedString, *pcReceivedString; + WinProperties_t xWinProps; + TickType_t xTimeOnEntering; + BaseType_t ret; + + /* Fill in the buffer and window sizes that will be used by the socket. */ + xWinProps.lTxBufSize = 6 * ipconfigTCP_MSS; + xWinProps.lTxWinSize = 3; + xWinProps.lRxBufSize = 6 * ipconfigTCP_MSS; + xWinProps.lRxWinSize = 3; + + /* This task can be created a number of times. Each instance is numbered + to enable each instance to use a different Rx and Tx buffer. The number is + passed in as the task's parameter. */ + xInstance = ( BaseType_t ) pvParameters; + + /* Point to the buffers to be used by this instance of this task. */ + pcTransmittedString = &( cTxBuffers[ xInstance ][ 0 ] ); + pcReceivedString = &( cRxBuffers[ xInstance ][ 0 ] ); + + /* Echo requests are sent to the echo server. The address of the echo + server is configured by the constants configECHO_SERVER_ADDR0 to + configECHO_SERVER_ADDR3 in FreeRTOSConfig.h. */ + xEchoServerAddress.sin_port = FreeRTOS_htons( echoECHO_PORT ); + xEchoServerAddress.sin_addr = FreeRTOS_inet_addr_quick( configECHO_SERVER_ADDR0, + configECHO_SERVER_ADDR1, + configECHO_SERVER_ADDR2, + configECHO_SERVER_ADDR3 ); + + for( ; ; ) + { + /* Create a TCP socket. */ + xSocket = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_STREAM, FREERTOS_IPPROTO_TCP ); + configASSERT( xSocket != FREERTOS_INVALID_SOCKET ); + + /* Set a time out so a missing reply does not cause the task to block + indefinitely. */ + FreeRTOS_setsockopt( xSocket, 0, FREERTOS_SO_RCVTIMEO, &xReceiveTimeOut, sizeof( xReceiveTimeOut ) ); + FreeRTOS_setsockopt( xSocket, 0, FREERTOS_SO_SNDTIMEO, &xSendTimeOut, sizeof( xSendTimeOut ) ); + + /* Set the window and buffer sizes. */ + FreeRTOS_setsockopt( xSocket, 0, FREERTOS_SO_WIN_PROPERTIES, ( void * ) &xWinProps, sizeof( xWinProps ) ); + + /* Connect to the echo server. */ + printf( "connecting to echo server....\n" ); + + ret = FreeRTOS_connect( xSocket, &xEchoServerAddress, sizeof( xEchoServerAddress ) ); + + if( ret == 0 ) + { + printf( "Connected to server.. \n" ); + ulConnections[ xInstance ]++; + + /* Send a number of echo requests. */ + for( lLoopCount = 0; lLoopCount < lMaxLoopCount; lLoopCount++ ) + { + /* Create the string that is sent to the echo server. */ + lStringLength = prvCreateTxData( pcTransmittedString, echoBUFFER_SIZES ); + + /* Add in some unique text at the front of the string. */ + sprintf( pcTransmittedString, "TxRx message number %u", ulTxCount ); + ulTxCount++; + + printf( "sending data to the echo server \n" ); + /* Send the string to the socket. */ + lTransmitted = FreeRTOS_send( xSocket, /* The socket being sent to. */ + ( void * ) pcTransmittedString, /* The data being sent. */ + lStringLength, /* The length of the data being sent. */ + 0 ); /* No flags. */ + + if( lTransmitted < 0 ) + { + /* Error? */ + break; + } + + /* Clear the buffer into which the echoed string will be + placed. */ + memset( ( void * ) pcReceivedString, 0x00, echoBUFFER_SIZES ); + xReceivedBytes = 0; + + /* Receive data echoed back to the socket. */ + while( xReceivedBytes < lTransmitted ) + { + xReturned = FreeRTOS_recv( xSocket, /* The socket being received from. */ + &( pcReceivedString[ xReceivedBytes ] ), /* The buffer into which the received data will be written. */ + lStringLength - xReceivedBytes, /* The size of the buffer provided to receive the data. */ + 0 ); /* No flags. */ + + if( xReturned < 0 ) + { + /* Error occurred. Latch it so it can be detected + below. */ + xReceivedBytes = xReturned; + break; + } + else if( xReturned == 0 ) + { + /* Timed out. */ + break; + } + else + { + /* Keep a count of the bytes received so far. */ + xReceivedBytes += xReturned; + } + } + + /* If an error occurred it will be latched in xReceivedBytes, + otherwise xReceived bytes will be just that - the number of + bytes received from the echo server. */ + if( xReceivedBytes > 0 ) + { + /* Compare the transmitted string to the received string. */ + configASSERT( strncmp( pcReceivedString, pcTransmittedString, lTransmitted ) == 0 ); + + if( strncmp( pcReceivedString, pcTransmittedString, lTransmitted ) == 0 ) + { + /* The echo reply was received without error. */ + ulTxRxCycles[ xInstance ]++; + } + else + { + /* The received string did not match the transmitted + string. */ + ulTxRxFailures[ xInstance ]++; + break; + } + } + else if( xReceivedBytes < 0 ) + { + /* FreeRTOS_recv() returned an error. */ + break; + } + else + { + /* Timed out without receiving anything? */ + break; + } + } + + /* Finished using the connected socket, initiate a graceful close: + FIN, FIN+ACK, ACK. */ + FreeRTOS_shutdown( xSocket, FREERTOS_SHUT_RDWR ); + + /* Expect FreeRTOS_recv() to return an error once the shutdown is + complete. */ + xTimeOnEntering = xTaskGetTickCount(); + + do + { + xReturned = FreeRTOS_recv( xSocket, /* The socket being received from. */ + &( pcReceivedString[ 0 ] ), /* The buffer into which the received data will be written. */ + echoBUFFER_SIZES, /* The size of the buffer provided to receive the data. */ + 0 ); + + if( xReturned < 0 ) + { + break; + } + } while( ( xTaskGetTickCount() - xTimeOnEntering ) < xReceiveTimeOut ); + } + else + { + printf( "Could not connect to server %ld\n", ret ); + } + + /* Close this socket before looping back to create another. */ + FreeRTOS_closesocket( xSocket ); + + /* Pause for a short while to ensure the network is not too + congested. */ + vTaskDelay( echoLOOP_DELAY ); + } + } +/*-----------------------------------------------------------*/ + + static BaseType_t prvCreateTxData( char *cBuffer, + uint32_t ulBufferLength ) + { + BaseType_t lCharactersToAdd, lCharacter; + char cChar = '0'; + const BaseType_t lMinimumLength = 60; + + /* Randomise the number of characters that will be sent in the echo + request. */ + do + { + lCharactersToAdd = ipconfigRAND32() % ( ulBufferLength - 20UL ); + } while( ( lCharactersToAdd == 0 ) || ( lCharactersToAdd < lMinimumLength ) ); /* Must be at least enough to add the unique text to the start of the string later. */ + + /* Fill the buffer. */ + for( lCharacter = 0; lCharacter < lCharactersToAdd; lCharacter++ ) + { + cBuffer[ lCharacter ] = cChar; + cChar++; + + if( cChar > '~' ) + { + cChar = '0'; + } + } + + return lCharactersToAdd; + } +/*-----------------------------------------------------------*/ + + BaseType_t xAreSingleTaskTCPEchoClientsStillRunning( void ) + { + static uint32_t ulLastEchoSocketCount[ echoNUM_ECHO_CLIENTS ] = { 0 }, ulLastConnections[ echoNUM_ECHO_CLIENTS ] = { 0 }; + BaseType_t xReturn = pdPASS, x; + + /* Return fail is the number of cycles does not increment between + consecutive calls. */ + for( x = 0; x < echoNUM_ECHO_CLIENTS; x++ ) + { + if( ulTxRxCycles[ x ] == ulLastEchoSocketCount[ x ] ) + { + xReturn = pdFAIL; + } + else + { + ulLastEchoSocketCount[ x ] = ulTxRxCycles[ x ]; + } + + if( ulConnections[ x ] == ulLastConnections[ x ] ) + { + xReturn = pdFAIL; + } + else + { + ulConnections[ x ] = ulLastConnections[ x ]; + } + } + + return xReturn; + } + +#endif /* ipconfigUSE_TCP */ diff --git a/FreeRTOS/Demo/Posix_GCC/src/TCPEchoClient_SingleTasks.h b/FreeRTOS/Demo/Posix_GCC/TCPEchoClient_SingleTasks.h similarity index 97% rename from FreeRTOS/Demo/Posix_GCC/src/TCPEchoClient_SingleTasks.h rename to FreeRTOS/Demo/Posix_GCC/TCPEchoClient_SingleTasks.h index 864a3a10f2..0c692e02e7 100644 --- a/FreeRTOS/Demo/Posix_GCC/src/TCPEchoClient_SingleTasks.h +++ b/FreeRTOS/Demo/Posix_GCC/TCPEchoClient_SingleTasks.h @@ -1,40 +1,40 @@ -/* - * FreeRTOS Kernel V10.3.0 - * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * 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! - */ - -#ifndef SINGLE_TASK_TCP_ECHO_CLIENTS_H -#define SINGLE_TASK_TCP_ECHO_CLIENTS_H - -/* - * Create the TCP echo client tasks. This is the version where an echo request - * is made from the same task that listens for the echo reply. - */ -void vStartTCPEchoClientTasks_SingleTasks( uint16_t usTaskStackSize, UBaseType_t uxTaskPriority ); -BaseType_t xAreSingleTaskTCPEchoClientsStillRunning( void ); - -#endif /* SINGLE_TASK_TCP_ECHO_CLIENTS_H */ - - +/* + * FreeRTOS Kernel V10.3.0 + * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * 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! + */ + +#ifndef SINGLE_TASK_TCP_ECHO_CLIENTS_H +#define SINGLE_TASK_TCP_ECHO_CLIENTS_H + +/* + * Create the TCP echo client tasks. This is the version where an echo request + * is made from the same task that listens for the echo reply. + */ +void vStartTCPEchoClientTasks_SingleTasks( uint16_t usTaskStackSize, UBaseType_t uxTaskPriority ); +BaseType_t xAreSingleTaskTCPEchoClientsStillRunning( void ); + +#endif /* SINGLE_TASK_TCP_ECHO_CLIENTS_H */ + + diff --git a/FreeRTOS/Demo/Posix_GCC/src/code_coverage_additions.c b/FreeRTOS/Demo/Posix_GCC/code_coverage_additions.c similarity index 100% rename from FreeRTOS/Demo/Posix_GCC/src/code_coverage_additions.c rename to FreeRTOS/Demo/Posix_GCC/code_coverage_additions.c diff --git a/FreeRTOS/Demo/Posix_GCC/src/console.c b/FreeRTOS/Demo/Posix_GCC/console.c similarity index 100% rename from FreeRTOS/Demo/Posix_GCC/src/console.c rename to FreeRTOS/Demo/Posix_GCC/console.c diff --git a/FreeRTOS/Demo/Posix_GCC/src/console.h b/FreeRTOS/Demo/Posix_GCC/console.h similarity index 100% rename from FreeRTOS/Demo/Posix_GCC/src/console.h rename to FreeRTOS/Demo/Posix_GCC/console.h diff --git a/FreeRTOS/Demo/Posix_GCC/src/main.c b/FreeRTOS/Demo/Posix_GCC/main.c similarity index 84% rename from FreeRTOS/Demo/Posix_GCC/src/main.c rename to FreeRTOS/Demo/Posix_GCC/main.c index dd2406ac41..cf3ea76483 100644 --- a/FreeRTOS/Demo/Posix_GCC/src/main.c +++ b/FreeRTOS/Demo/Posix_GCC/main.c @@ -19,32 +19,37 @@ * 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 + * https://www.FreeRTOS.org + * https://github.com/FreeRTOS * * 1 tab == 4 spaces! */ /****************************************************************************** - * This project provides two demo applications. A simple blinky style project, - * and a more comprehensive test and demo application. The - * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is used to select between the two. - * The simply blinky demo is implemented and described in main_blinky.c. The - * more comprehensive test and demo application is implemented and described in - * main_full.c. + * This project provides three demo applications. A simple blinky style project, + * a more comprehensive test and demo application, and a TCP echo demo. + * The mainSELECTED_APPLICATION setting is used to select between + * the three + * + * If mainSELECTED_APPLICATION = BLINKY_DEMO the simple blinky demo will be built. + * The simply blinky demo is implemented and described in main_blinky.c. + * + * If mainSELECTED_APPLICATION = FULL_DEMO the more comprehensive test and demo + * application built. This is implemented and described in main_full.c. + * + * If mainSELECTED_APPLICATION = ECHO_CLIENT_DEMO the tcp echo demo will be built. + * This is implemented and described in main_networking.c * * This file implements the code that is not demo specific, including the * hardware setup and FreeRTOS hook functions. * ******************************************************************************* - * NOTE: Windows will not be running the FreeRTOS demo threads continuously, so - * do not expect to get real time behaviour from the FreeRTOS Windows port, or + * NOTE: Linux will not be running the FreeRTOS demo threads continuously, so + * do not expect to get real time behaviour from the FreeRTOS Linux port, or * this demo application. Also, the timing information in the FreeRTOS+Trace - * logs have no meaningful units. See the documentation page for the Windows + * logs have no meaningful units. See the documentation page for the Linux * port for further information: - * http://www.freertos.org/FreeRTOS-Windows-Simulator-Emulator-for-Visual-Studio-and-Eclipse-MingW.html - * - + * https://freertos.org/FreeRTOS-simulator-for-Linux.html * ******************************************************************************* */ @@ -62,36 +67,19 @@ /* Local includes. */ #include "console.h" -/* This project provides two demo applications. A simple blinky style demo -application, and a more comprehensive test and demo application. The -mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is used to select between the two. +#define BLINKY_DEMO 0 +#define FULL_DEMO 1 +#define ECHO_CLIENT_DEMO 2 -If mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is 1 then the blinky demo will be built. -The blinky demo is implemented and described in main_blinky.c. - -If mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is not 1 then the comprehensive test and -demo application will be built. The comprehensive test and demo application is -implemented and described in main_full.c. */ -#ifndef mainCREATE_SIMPLE_BLINKY_DEMO_ONLY - #define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY 0 -#endif - -#ifndef mainCREATE_TCP_ECHO_TASKS_SINGLE - #define mainCREATE_TCP_ECHO_TASKS_SINGLE 1 -#endif +#define mainSELECTED_APPLICATION FULL_DEMO /* This demo uses heap_3.c (the libc provided malloc() and free()). */ /*-----------------------------------------------------------*/ - -/* - * main_blinky() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1. - * main_full() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 0. - */ extern void main_blinky( void ); extern void main_full( void ); extern void main_tcp_echo_client_tasks( void ); - +static void traceOnEnter( void ); /* * Only the comprehensive demo uses application hook (callback) functions. See * http://www.freertos.org/a00016.html for more information. @@ -147,25 +135,32 @@ int main( void ) /* Start the trace recording - the recording is written to a file if configASSERT() is called. */ printf( "\r\nTrace started.\r\nThe trace will be dumped to disk if a call to configASSERT() fails.\r\n" ); - printf( "Uncomment the call to kbhit() in this file to also dump trace with a key press.\r\n" ); + printf( "\r\nThe trace will be dumped to disk if Enter is hit.\r\n" ); uiTraceStart(); } #endif console_init(); - #if ( mainCREATE_TCP_ECHO_TASKS_SINGLE == 1 ) + #if ( mainSELECTED_APPLICATION == ECHO_CLIENT_DEMO ) { + console_print("Starting echo client demo\n"); main_tcp_echo_client_tasks(); } - #elif ( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 ) + #elif ( mainSELECTED_APPLICATION == BLINKY_DEMO ) { + console_print("Starting echo blinky demo\n"); main_blinky(); } + #elif ( mainSELECTED_APPLICATION == FULL_DEMO) + { + console_print("Starting full demo\n"); + main_full(); + } #else { - main_full(); + #error "The selected demo is not valid" } - #endif /* if ( mainCREATE_TCP_ECHO_TASKS_SINGLE == 1 ) */ + #endif /* if ( mainSELECTED_APPLICATION ) */ return 0; } @@ -199,15 +194,17 @@ void vApplicationIdleHook( void ) vTaskDelete() API function to delete themselves then it is also important that vApplicationIdleHook() is permitted to return to its calling function, because it is the responsibility of the idle task to clean up memory - allocated by the kernel to any task that has since deleted itself. */ + allocated by the kernel to any task that has since deleted itself. */ - sleep( 1 ); - #if ( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY != 1 ) + usleep(15000); + traceOnEnter(); + + #if ( mainSELECTED_APPLICATION == FULL_DEMO ) { /* Call the idle task processing used by the full demo. The simple blinky demo does not use the idle task hook. */ - /*vFullDemoIdleFunction();*/ + vFullDemoIdleFunction(); } #endif } @@ -223,7 +220,7 @@ void vApplicationStackOverflowHook( TaskHandle_t pxTask, configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook function is called if a stack overflow is detected. This function is provided as an example only as stack overflow checking does not function - when running the FreeRTOS Windows port. */ + when running the FreeRTOS POSIX port. */ vAssertCalled( __FILE__, __LINE__ ); } /*-----------------------------------------------------------*/ @@ -236,12 +233,31 @@ void vApplicationTickHook( void ) code must not attempt to block, and only the interrupt safe FreeRTOS API functions can be used (those that end in FromISR()). */ - #if ( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY != 1 && \ - mainCREATE_TCP_ECHO_TASKS_SINGLE != 1 ) - { - vFullDemoTickHookFunction(); - } - #endif /* mainCREATE_SIMPLE_BLINKY_DEMO_ONLY */ + #if (mainSELECTED_APPLICATION == FULL_DEMO ) + { + vFullDemoTickHookFunction(); + } + #endif /* mainSELECTED_APPLICATION */ +} + +void traceOnEnter() +{ + int ret; + struct timeval tv = { 0L, 0L }; + fd_set fds; + FD_ZERO(&fds); + FD_SET(0, &fds); + ret = select(1, &fds, NULL, NULL, &tv); + if ( ret > 0 ) + { + if( xTraceRunning == pdTRUE ) + { + prvSaveTraceFile(); + } + /* clear the buffer */ + char buffer[200]; + read(1, &buffer, 200); + } } void vLoggingPrintf( const char *pcFormat, @@ -296,8 +312,8 @@ volatile uint32_t ulSetToNonZeroInDebuggerToContinue = 0; value. */ while( ulSetToNonZeroInDebuggerToContinue == 0 ) { - __asm volatile ( "NOP" ); - __asm volatile ( "NOP" ); + __asm volatile ( "NOP" ); + __asm volatile ( "NOP" ); } } taskEXIT_CRITICAL(); diff --git a/FreeRTOS/Demo/Posix_GCC/src/main_blinky.c b/FreeRTOS/Demo/Posix_GCC/main_blinky.c similarity index 93% rename from FreeRTOS/Demo/Posix_GCC/src/main_blinky.c rename to FreeRTOS/Demo/Posix_GCC/main_blinky.c index 69c7e7e237..168dc3d76e 100644 --- a/FreeRTOS/Demo/Posix_GCC/src/main_blinky.c +++ b/FreeRTOS/Demo/Posix_GCC/main_blinky.c @@ -19,19 +19,18 @@ * 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 + * https://www.FreeRTOS.org + * https://github.com/FreeRTOS * - * 1 tab == 4 spaces! */ /****************************************************************************** - * NOTE 1: Windows will not be running the FreeRTOS demo threads continuously, so - * do not expect to get real time behaviour from the FreeRTOS Windows port, or + * NOTE 1: The FreeRTOS demo threads will not be running continuously, so + * do not expect to get real time behaviour from the FreeRTOS Linux port, or * this demo application. Also, the timing information in the FreeRTOS+Trace - * logs have no meaningful units. See the documentation page for the Windows + * logs have no meaningful units. See the documentation page for the Linux * port for further information: - * http://www.freertos.org/FreeRTOS-Windows-Simulator-Emulator-for-Visual-Studio-and-Eclipse-MingW.html + * https://freertos.org/FreeRTOS-simulator-for-Linux.html * * NOTE 2: This project provides two demo applications. A simple blinky style * project, and a more comprehensive test and demo application. The @@ -52,7 +51,7 @@ * The queue send task is implemented by the prvQueueSendTask() function in * this file. It uses vTaskDelayUntil() to create a periodic task that sends * the value 100 to the queue every 200 milliseconds (please read the notes - * above regarding the accuracy of timing under Windows). + * above regarding the accuracy of timing under Linux). * * The Queue Send Software Timer: * The timer is an auto-reload timer with a period of two seconds. The timer's @@ -75,10 +74,10 @@ * pressed then the queue receive task will output a message indicating that * data was received on the queue from the queue send software timer. * - * NOTE: Console input and output relies on Windows system calls, which can - * interfere with the execution of the FreeRTOS Windows port. This demo only - * uses Windows system call occasionally. Heavier use of Windows system calls - * can crash the port. + * NOTE: Console input and output relies on Linux system calls, which can + * interfere with the execution of the FreeRTOS Linux port. This demo only + * uses Linux system call occasionally. Heavier use of Linux system calls + * may crash the port. */ #include @@ -246,7 +245,7 @@ uint32_t ulReceivedValue; is it an expected value? Normally calling printf() from a task is not a good idea. Here there is lots of stack space and only one task is using console IO so it is ok. However, note the comments at the top of - this file about the risks of making Windows system calls (such as + this file about the risks of making Linux system calls (such as console output) from a FreeRTOS task. */ if( ulReceivedValue == mainVALUE_SENT_FROM_TASK ) { diff --git a/FreeRTOS/Demo/Posix_GCC/src/main_full.c b/FreeRTOS/Demo/Posix_GCC/main_full.c similarity index 91% rename from FreeRTOS/Demo/Posix_GCC/src/main_full.c rename to FreeRTOS/Demo/Posix_GCC/main_full.c index 3bdfe98241..92b3bd3a1c 100644 --- a/FreeRTOS/Demo/Posix_GCC/src/main_full.c +++ b/FreeRTOS/Demo/Posix_GCC/main_full.c @@ -27,16 +27,16 @@ /* ******************************************************************************* - * NOTE 1: The Win32 port is a simulation (or is that emulation?) only! Do not - * expect to get real time behaviour from the Win32 port or this demo + * NOTE 1: The POSIX port is a simulation (or is that emulation?) only! Do not + * expect to get real time behaviour from the POSIX port or this demo * application. It is provided as a convenient development and demonstration * test bed only. * - * Windows will not be running the FreeRTOS simulator threads continuously, so + * Linux will not be running the FreeRTOS simulator threads continuously, so * the timing information in the FreeRTOS+Trace logs have no meaningful units. - * See the documentation page for the Windows simulator for an explanation of + * See the documentation page for the Linux simulator for an explanation of * the slow timing: - * http://www.freertos.org/FreeRTOS-Windows-Simulator-Emulator-for-Visual-Studio-and-Eclipse-MingW.html + * https://freertos-wordpress.corp.amazon.com/FreeRTOS-simulator-for-Linux.html * - READ THE WEB DOCUMENTATION FOR THIS PORT FOR MORE INFORMATION ON USING IT - * * NOTE 2: This project provides two demo applications. A simple blinky style @@ -106,6 +106,7 @@ #include "StreamBufferDemo.h" #include "StreamBufferInterrupt.h" #include "MessageBufferAMP.h" +#include "console.h" /* Priorities at which the tasks are created. */ #define mainCHECK_TASK_PRIORITY ( configMAX_PRIORITIES - 2 ) @@ -182,7 +183,7 @@ static void prvReloadModeTestTimerCallback( TimerHandle_t xTimer ); /*-----------------------------------------------------------*/ /* The variable into which error messages are latched. */ -static char *pcStatusMessage = "No errors"; +static char *pcStatusMessage = "OK: No errors"; /* This semaphore is created purely to test using the vSemaphoreDelete() and semaphore tracing API functions. It has no other purpose. */ @@ -197,6 +198,7 @@ int main_full( void ) /* Create the standard demo tasks. */ vStartTaskNotifyTask(); + // vStartTaskNotifyArrayTask(); vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY ); vStartSemaphoreTasks( mainSEM_TEST_PRIORITY ); vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY ); @@ -207,24 +209,27 @@ int main_full( void ) vStartRecursiveMutexTasks(); vStartCountingSemaphoreTasks(); vStartDynamicPriorityTasks(); - vStartQueueSetTasks(); vStartQueueOverwriteTask( mainQUEUE_OVERWRITE_PRIORITY ); - xTaskCreate( prvDemoQueueSpaceFunctions, NULL, configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL ); /* Name is null for code coverage. */ vStartEventGroupTasks(); vStartInterruptSemaphoreTasks(); - vStartQueueSetPollingTask(); vCreateBlockTimeTasks(); vCreateAbortDelayTasks(); xTaskCreate( prvDemoQueueSpaceFunctions, "QSpace", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL ); xTaskCreate( prvPermanentlyBlockingSemaphoreTask, "BlockSem", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL ); xTaskCreate( prvPermanentlyBlockingNotificationTask, "BlockNoti", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL ); - xTaskCreate( prvDemonstrateChangingTimerReloadMode, "TimerMode", configMINIMAL_STACK_SIZE, NULL, configMAX_PRIORITIES - 1, NULL ); vStartMessageBufferTasks( configMINIMAL_STACK_SIZE ); - /* vStartStreamBufferTasks(); */ - /* vStartStreamBufferInterruptDemo(); */ + vStartStreamBufferTasks(); + vStartStreamBufferInterruptDemo(); vStartMessageBufferAMPTasks( configMINIMAL_STACK_SIZE ); + #if( configUSE_QUEUE_SETS == 1 ) + { + vStartQueueSetTasks(); + vStartQueueSetPollingTask(); + } + #endif + #if( configSUPPORT_STATIC_ALLOCATION == 1 ) { vStartStaticallyAllocatedTasks(); @@ -234,7 +239,7 @@ int main_full( void ) #if( configUSE_PREEMPTION != 0 ) { /* Don't expect these tasks to pass when preemption is not used. */ - //vStartTimerDemoTask( mainTIMER_TEST_PERIOD ); + vStartTimerDemoTask( mainTIMER_TEST_PERIOD ); } #endif @@ -260,7 +265,8 @@ int main_full( void ) static void prvCheckTask( void *pvParameters ) { TickType_t xNextWakeTime; -const TickType_t xCycleFrequency = pdMS_TO_TICKS( 2500UL ); +const TickType_t xCycleFrequency = pdMS_TO_TICKS( 10000UL ); +HeapStats_t xHeapStats; /* Just to remove compiler warning. */ ( void ) pvParameters; @@ -274,21 +280,21 @@ const TickType_t xCycleFrequency = pdMS_TO_TICKS( 2500UL ); vTaskDelayUntil( &xNextWakeTime, xCycleFrequency ); /* Check the standard demo tasks are running without error. */ - /* #if( configUSE_PREEMPTION != 0 ) */ - /* { */ - /* /\* These tasks are only created when preemption is used. *\/ */ - /* if( xAreTimerDemoTasksStillRunning( xCycleFrequency ) != pdTRUE ) */ - /* { */ - /* pcStatusMessage = "Error: TimerDemo"; */ - /* } */ - /* } */ - /* #endif */ + #if( configUSE_PREEMPTION != 0 ) + { + /* These tasks are only created when preemption is used. */ + if( xAreTimerDemoTasksStillRunning( xCycleFrequency ) != pdTRUE ) + { + pcStatusMessage = "Error: TimerDemo"; + } + } + #endif - /* if( xAreStreamBufferTasksStillRunning() != pdTRUE ) */ - /* { */ - /* pcStatusMessage = "Error: StreamBuffer"; */ - /* } */ - /* else */if( xAreMessageBufferTasksStillRunning() != pdTRUE ) + if( xAreStreamBufferTasksStillRunning() != pdTRUE ) + { + pcStatusMessage = "Error: StreamBuffer"; + } + else if( xAreMessageBufferTasksStillRunning() != pdTRUE ) { pcStatusMessage = "Error: MessageBuffer"; } @@ -296,6 +302,10 @@ const TickType_t xCycleFrequency = pdMS_TO_TICKS( 2500UL ); { pcStatusMessage = "Error: Notification"; } + // else if( xAreTaskNotificationArrayTasksStillRunning() != pdTRUE ) + // { + // pcStatusMessage = "Error: NotificationArray"; + // } else if( xAreInterruptSemaphoreTasksStillRunning() != pdTRUE ) { pcStatusMessage = "Error: IntSem"; @@ -348,18 +358,10 @@ const TickType_t xCycleFrequency = pdMS_TO_TICKS( 2500UL ); { pcStatusMessage = "Error: Dynamic"; } - else if( xAreQueueSetTasksStillRunning() != pdPASS ) - { - pcStatusMessage = "Error: Queue set"; - } else if( xIsQueueOverwriteTaskStillRunning() != pdPASS ) { pcStatusMessage = "Error: Queue overwrite"; } - else if( xAreQueueSetPollTasksStillRunning() != pdPASS ) - { - pcStatusMessage = "Error: Queue set polling"; - } else if( xAreBlockTimeTestTasksStillRunning() != pdPASS ) { pcStatusMessage = "Error: Block time"; @@ -368,21 +370,39 @@ const TickType_t xCycleFrequency = pdMS_TO_TICKS( 2500UL ); { pcStatusMessage = "Error: Abort delay"; } - /* else if( xIsInterruptStreamBufferDemoStillRunning() != pdPASS ) */ - /* { */ - /* pcStatusMessage = "Error: Stream buffer interrupt"; */ - /* } */ + else if( xIsInterruptStreamBufferDemoStillRunning() != pdPASS ) + { + pcStatusMessage = "Error: Stream buffer interrupt"; + } else if( xAreMessageBufferAMPTasksStillRunning() != pdPASS ) { pcStatusMessage = "Error: Message buffer AMP"; } + #if( configUSE_QUEUE_SETS == 1 ) + else if( xAreQueueSetTasksStillRunning() != pdPASS ) + { + pcStatusMessage = "Error: Queue set"; + } + else if( xAreQueueSetPollTasksStillRunning() != pdPASS ) + { + pcStatusMessage = "Error: Queue set polling"; + } + #endif + #if( configSUPPORT_STATIC_ALLOCATION == 1 ) else if( xAreStaticAllocationTasksStillRunning() != pdPASS ) { pcStatusMessage = "Error: Static allocation"; } #endif /* configSUPPORT_STATIC_ALLOCATION */ + + printf( "%s - tick count %u \r\n", + pcStatusMessage, + xTaskGetTickCount() ); + + // Reset the error condition + pcStatusMessage = "OK: No errors"; } } /*-----------------------------------------------------------*/ @@ -486,20 +506,24 @@ TaskHandle_t xTimerTask; /* Call the periodic timer test, which tests the timer API functions that can be called from an ISR. */ - /* #if( configUSE_PREEMPTION != 0 ) */ - /* { */ - /* /\* Only created when preemption is used. *\/ */ - /* vTimerPeriodicISRTests(); */ - /* } */ - /* #endif */ + #if( configUSE_PREEMPTION != 0 ) + { + /* Only created when preemption is used. */ + vTimerPeriodicISRTests(); + } + #endif /* Call the periodic queue overwrite from ISR demo. */ vQueueOverwritePeriodicISRDemo(); - /* Write to a queue that is in use as part of the queue set demo to - demonstrate using queue sets from an ISR. */ - vQueueSetAccessQueueSetFromISR(); - vQueueSetPollingInterruptAccess(); + #if( configUSE_QUEUE_SETS == 1 ) /* Remove the tests if queue sets are not defined. */ + { + /* Write to a queue that is in use as part of the queue set demo to + demonstrate using queue sets from an ISR. */ + vQueueSetAccessQueueSetFromISR(); + vQueueSetPollingInterruptAccess(); + } + #endif /* Exercise event groups from interrupts. */ vPeriodicEventGroupsProcessing(); @@ -509,19 +533,19 @@ TaskHandle_t xTimerTask; /* Exercise using task notifications from an interrupt. */ xNotifyTaskFromISR(); + // xNotifyArrayTaskFromISR(); /* Writes to stream buffer byte by byte to test the stream buffer trigger level functionality. */ - /* vPeriodicStreamBufferProcessing(); */ + vPeriodicStreamBufferProcessing(); /* Writes a string to a string buffer four bytes at a time to demonstrate a stream being sent from an interrupt to a task. */ - /* vBasicStreamBufferSendFromISR(); */ + vBasicStreamBufferSendFromISR(); /* For code coverage purposes. */ xTimerTask = xTimerGetTimerDaemonTaskHandle(); configASSERT( uxTaskPriorityGetFromISR( xTimerTask ) == configTIMER_TASK_PRIORITY ); - ( void ) xTimerTask; /* In case configASSERT() is not defined. */ } /*-----------------------------------------------------------*/ @@ -616,8 +640,6 @@ static portBASE_TYPE xPerformedOneShotTests = pdFALSE; TaskHandle_t xTestTask; TaskStatus_t xTaskInfo; extern StackType_t uxTimerTaskStack[]; -static uint32_t ulLastIdleExecutionTime = 0; -uint32_t ulIdleExecutionTime; /* Demonstrate the use of the xTimerGetTimerDaemonTaskHandle() and xTaskGetIdleTaskHandle() functions. Also try using the function that sets @@ -716,13 +738,6 @@ uint32_t ulIdleExecutionTime; } } } - - ulIdleExecutionTime = ulTaskGetIdleRunTimeCounter(); - if( ulIdleExecutionTime == ulLastIdleExecutionTime ) - { - pcStatusMessage = "Error: Total amount of Idle task execution time did not change"; - } - ulLastIdleExecutionTime = ulIdleExecutionTime; } /*-----------------------------------------------------------*/ diff --git a/FreeRTOS/Demo/Posix_GCC/src/main_networking.c b/FreeRTOS/Demo/Posix_GCC/main_networking.c similarity index 99% rename from FreeRTOS/Demo/Posix_GCC/src/main_networking.c rename to FreeRTOS/Demo/Posix_GCC/main_networking.c index edb5897204..373e96e565 100644 --- a/FreeRTOS/Demo/Posix_GCC/src/main_networking.c +++ b/FreeRTOS/Demo/Posix_GCC/main_networking.c @@ -158,7 +158,7 @@ const uint32_t ulLongTime_ms = pdMS_TO_TICKS( 1000UL ); there was insufficient FreeRTOS heap memory available for the idle and/or timer tasks to be created. See the memory management section on the FreeRTOS web site for more details (this is standard text that is not not - really applicable to the Win32 simulator port). */ + really applicable to the Linux simulator port). */ for( ; ; ) { usleep( ulLongTime_ms * 1000 ); diff --git a/FreeRTOS/Demo/Posix_GCC/src/run-time-stats-utils.c b/FreeRTOS/Demo/Posix_GCC/run-time-stats-utils.c similarity index 100% rename from FreeRTOS/Demo/Posix_GCC/src/run-time-stats-utils.c rename to FreeRTOS/Demo/Posix_GCC/run-time-stats-utils.c diff --git a/FreeRTOS/Demo/Posix_GCC/src/SConscript b/FreeRTOS/Demo/Posix_GCC/src/SConscript deleted file mode 100644 index 5768f64d0c..0000000000 --- a/FreeRTOS/Demo/Posix_GCC/src/SConscript +++ /dev/null @@ -1,150 +0,0 @@ -# FreeRTOS Kernel V10.3.0 -# Copyright (C) 2020 Cambridge Consultants Ltd. -# -# 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 - -Import("env") - -env.Append(CPPPATH = [ - ".", - "./utils", - "FreeRTOS/Source/include", - "FreeRTOS/Source/portable/ThirdParty/GCC/Posix", - "FreeRTOS/Demo/Common/include", - "FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/Include", - "FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/linux/", - "FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/", - "FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/GCC/", -]) - -env.Append(LIBS = [ - "pthread", - "pcap", -]) - -src = [ - "console.c", - "main.c", - "main_blinky.c", - "main_full.c", - "main_networking.c", - "run-time-stats-utils.c", - "utils/wait_for_event.c", - "SimpleTCPEchoServer.c", - "TCPEchoClient_SingleTasks.c", - - # FreeRTOS kernel - "FreeRTOS/Source/event_groups.c", - "FreeRTOS/Source/list.c", - "FreeRTOS/Source/queue.c", - "FreeRTOS/Source/stream_buffer.c", - "FreeRTOS/Source/tasks.c", - "FreeRTOS/Source/timers.c", - - # Memory manager (use malloc()/free()). - "FreeRTOS/Source/portable/MemMang/heap_3.c", - - # Posix port. - "FreeRTOS/Source/portable/ThirdParty/GCC/Posix/port.c", - - # FreeRTOS TCP - "FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_DNS.c", - "FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_DHCP.c", - "FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_ARP.c", - "FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_TCP_WIN.c", - "FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_Stream_Buffer.c", - "FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/BufferManagement/BufferAllocation_2.c", - "FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_IP.c", - "FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_TCP_IP.c", - "FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_UDP_IP.c", - "FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_Sockets.c", - "FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/linux/NetworkInterface.c", - - # Demo library. - "FreeRTOS/Demo/Common/Minimal/AbortDelay.c", - "FreeRTOS/Demo/Common/Minimal/BlockQ.c", - "FreeRTOS/Demo/Common/Minimal/blocktim.c", - "FreeRTOS/Demo/Common/Minimal/countsem.c", - "FreeRTOS/Demo/Common/Minimal/death.c", - "FreeRTOS/Demo/Common/Minimal/dynamic.c", - "FreeRTOS/Demo/Common/Minimal/EventGroupsDemo.c", - "FreeRTOS/Demo/Common/Minimal/flop.c", - "FreeRTOS/Demo/Common/Minimal/GenQTest.c", - "FreeRTOS/Demo/Common/Minimal/integer.c", - "FreeRTOS/Demo/Common/Minimal/IntSemTest.c", - "FreeRTOS/Demo/Common/Minimal/MessageBufferAMP.c", - "FreeRTOS/Demo/Common/Minimal/MessageBufferDemo.c", - "FreeRTOS/Demo/Common/Minimal/PollQ.c", - "FreeRTOS/Demo/Common/Minimal/QPeek.c", - "FreeRTOS/Demo/Common/Minimal/QueueOverwrite.c", - "FreeRTOS/Demo/Common/Minimal/QueueSet.c", - "FreeRTOS/Demo/Common/Minimal/QueueSetPolling.c", - "FreeRTOS/Demo/Common/Minimal/recmutex.c", - "FreeRTOS/Demo/Common/Minimal/semtest.c", - "FreeRTOS/Demo/Common/Minimal/StaticAllocation.c", - "FreeRTOS/Demo/Common/Minimal/StreamBufferDemo.c", - "FreeRTOS/Demo/Common/Minimal/StreamBufferInterrupt.c", - "FreeRTOS/Demo/Common/Minimal/TaskNotify.c", - "FreeRTOS/Demo/Common/Minimal/TimerDemo.c", -] - -if GetOption("coverage"): - env.Append(CPPDEFINES = [ - "projCOVERAGE_TEST=1", - ]) - - env.Append(CFLAGS = [ - "-fprofile-arcs", - "-ftest-coverage", - "-ggdb3", - "-Og", - ]) - env.Append(LINKFLAGS = [ - "-fprofile-arcs", - "-ftest-coverage", - "-ggdb3", - "-Og", - ]) - - src += [ - "code_coverage_additions.c", - ] -else: - env.Append(CPPDEFINES = [ - "projCOVERAGE_TEST=0", - ]) - - src += [ - # Trace library. - "FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/trcKernelPort.c", - "FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/trcSnapshotRecorder.c", - "FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/trcStreamingRecorder.c", - "FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/streamports/File/trcStreamingPort.c", - ] - -# Build the simple "blinky" demo application, or the full test -# applicaton? -if GetOption("simple"): - env.Append(CPPDEFINES = [ - "mainCREATE_SIMPLE_BLINKY_DEMO_ONLY=1", - ]) - -env.Program("posix_demo", src) diff --git a/FreeRTOS/Demo/Posix_GCC/src/utils/wait_for_event.c b/FreeRTOS/Demo/Posix_GCC/src/utils/wait_for_event.c deleted file mode 100644 index 6d0bfffda3..0000000000 --- a/FreeRTOS/Demo/Posix_GCC/src/utils/wait_for_event.c +++ /dev/null @@ -1,75 +0,0 @@ -#include -#include -#include - -#include "wait_for_event.h" - -struct event -{ - pthread_mutex_t mutex; - pthread_cond_t cond; - bool event_triggered; -}; - -struct event * event_create() -{ - struct event * ev = malloc( sizeof( struct event ) ); - - ev->event_triggered = false; - pthread_mutex_init( &ev->mutex, NULL ); - pthread_cond_init( &ev->cond, NULL ); - return ev; -} - -void event_delete( struct event * ev ) -{ - pthread_mutex_destroy( &ev->mutex ); - pthread_cond_destroy( &ev->cond ); - free( ev ); -} - -bool event_wait( struct event * ev ) -{ - pthread_mutex_lock( &ev->mutex ); - - while( ev->event_triggered == false ) - { - pthread_cond_wait( &ev->cond, &ev->mutex ); - } - - pthread_mutex_unlock( &ev->mutex ); - return true; -} -bool event_wait_timed( struct event * ev, - time_t ms ) -{ - struct timespec ts; - int ret = 0; - - clock_gettime( CLOCK_REALTIME, &ts ); - //ts.tv_sec += ms; - ts.tv_nsec += (ms * 1000000); - pthread_mutex_lock( &ev->mutex ); - - while( (ev->event_triggered == false) && (ret == 0) ) - { - ret = pthread_cond_timedwait( &ev->cond, &ev->mutex, &ts ); - - if( ( ret == -1 ) && ( errno == ETIMEDOUT ) ) - { - return false; - } - } - - ev->event_triggered = false; - pthread_mutex_unlock( &ev->mutex ); - return true; -} - -void event_signal( struct event * ev ) -{ - pthread_mutex_lock( &ev->mutex ); - ev->event_triggered = true; - pthread_cond_signal( &ev->cond ); - pthread_mutex_unlock( &ev->mutex ); -} diff --git a/FreeRTOS/Demo/Posix_GCC/src/utils/wait_for_event.h b/FreeRTOS/Demo/Posix_GCC/src/utils/wait_for_event.h deleted file mode 100644 index 2693a0d8ca..0000000000 --- a/FreeRTOS/Demo/Posix_GCC/src/utils/wait_for_event.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef _WAIT_FOR_EVENT_H_ -#define _WAIT_FOR_EVENT_H_ - -#include -#include - -struct event; - -struct event * event_create(); -void event_delete( struct event * ); -bool event_wait( struct event * ev ); -bool event_wait_timed( struct event * ev, - time_t ms ); -void event_signal( struct event * ev ); - - - -#endif /* ifndef _WAIT_FOR_EVENT_H_ */ diff --git a/FreeRTOS/Demo/Posix_GCC/src/trcConfig.h b/FreeRTOS/Demo/Posix_GCC/trcConfig.h similarity index 99% rename from FreeRTOS/Demo/Posix_GCC/src/trcConfig.h rename to FreeRTOS/Demo/Posix_GCC/trcConfig.h index 5e1ed6a290..133971c0b5 100644 --- a/FreeRTOS/Demo/Posix_GCC/src/trcConfig.h +++ b/FreeRTOS/Demo/Posix_GCC/trcConfig.h @@ -113,7 +113,7 @@ extern "C" { * TRC_FREERTOS_VERSION_9_0_2 If using FreeRTOS v9.0.2 * TRC_FREERTOS_VERSION_10_0_0 If using FreeRTOS v10.0.0 or later *****************************************************************************/ -#define TRC_CFG_FREERTOS_VERSION TRC_FREERTOS_VERSION_10_0_0 +#define TRC_CFG_FREERTOS_VERSION TRC_FREERTOS_VERSION_10_4_0 /******************************************************************************* * TRC_CFG_SCHEDULING_ONLY diff --git a/FreeRTOS/Demo/Posix_GCC/src/trcSnapshotConfig.h b/FreeRTOS/Demo/Posix_GCC/trcSnapshotConfig.h similarity index 99% rename from FreeRTOS/Demo/Posix_GCC/src/trcSnapshotConfig.h rename to FreeRTOS/Demo/Posix_GCC/trcSnapshotConfig.h index 9c43cd051d..45c920584c 100644 --- a/FreeRTOS/Demo/Posix_GCC/src/trcSnapshotConfig.h +++ b/FreeRTOS/Demo/Posix_GCC/trcSnapshotConfig.h @@ -82,7 +82,7 @@ * Default value is 1000, which means that 4000 bytes is allocated for the * event buffer. ******************************************************************************/ -#define TRC_CFG_EVENT_BUFFER_SIZE 15000 +#define TRC_CFG_EVENT_BUFFER_SIZE 32000 /******************************************************************************* * TRC_CFG_NTASK, TRC_CFG_NISR, TRC_CFG_NQUEUE, TRC_CFG_NSEMAPHORE... @@ -113,8 +113,8 @@ #define TRC_CFG_NMUTEX 90 #define TRC_CFG_NTIMER 250 #define TRC_CFG_NEVENTGROUP 90 -#define TRC_CFG_NSTREAMBUFFER 5 -#define TRC_CFG_NMESSAGEBUFFER 5 +#define TRC_CFG_NSTREAMBUFFER 100 +#define TRC_CFG_NMESSAGEBUFFER 100 /****************************************************************************** @@ -149,7 +149,7 @@ * * Default value is 800. ******************************************************************************/ -#define TRC_CFG_SYMBOL_TABLE_SIZE 5000 +#define TRC_CFG_SYMBOL_TABLE_SIZE 32000 #if (TRC_CFG_SYMBOL_TABLE_SIZE == 0) #error "TRC_CFG_SYMBOL_TABLE_SIZE may not be zero!" diff --git a/FreeRTOS/Demo/RISC-V-Qemu-sifive_e-Eclipse-GCC/.cproject b/FreeRTOS/Demo/RISC-V-Qemu-sifive_e-Eclipse-GCC/.cproject index 3598301483..cc74c9c9f6 100644 --- a/FreeRTOS/Demo/RISC-V-Qemu-sifive_e-Eclipse-GCC/.cproject +++ b/FreeRTOS/Demo/RISC-V-Qemu-sifive_e-Eclipse-GCC/.cproject @@ -19,7 +19,7 @@ - + - + - +