From 6bc33dc62f9ca378ba04415776da7382cacbce29 Mon Sep 17 00:00:00 2001 From: richardbarry Date: Mon, 7 Oct 2013 20:13:02 +0000 Subject: [PATCH] Update FreeRTOS_FD_SET() to check there is enough space in the queue before adding the socket to the socket set. git-svn-id: https://svn.code.sf.net/p/freertos/code/trunk@2053 1d2547de-c912-0410-9cb9-b8ca96c0e9e2 --- .../TraceMacros/Example1/DemoIPTrace.c | 5 ++- .../TraceMacros/Example1/DemoIPTrace.h | 28 +++++++------ .../Source/FreeRTOS-Plus-Nabto/readme.txt | 6 +++ .../FreeRTOS-Plus-UDP/FreeRTOS_Sockets.c | 42 +++++++++++++------ .../include/FreeRTOSIPConfigDefaults.h | 4 ++ 5 files changed, 59 insertions(+), 26 deletions(-) create mode 100644 FreeRTOS-Plus/Source/FreeRTOS-Plus-Nabto/readme.txt diff --git a/FreeRTOS-Plus/Demo/Common/FreeRTOS_Plus_UDP_Demos/TraceMacros/Example1/DemoIPTrace.c b/FreeRTOS-Plus/Demo/Common/FreeRTOS_Plus_UDP_Demos/TraceMacros/Example1/DemoIPTrace.c index 4e9d09a25..78a722e50 100644 --- a/FreeRTOS-Plus/Demo/Common/FreeRTOS_Plus_UDP_Demos/TraceMacros/Example1/DemoIPTrace.c +++ b/FreeRTOS-Plus/Demo/Common/FreeRTOS_Plus_UDP_Demos/TraceMacros/Example1/DemoIPTrace.c @@ -105,17 +105,18 @@ xExampleDebugStatEntry_t xIPTraceValues[] = { /* Comment out array entries to remove individual trace items. */ + { iptraceID_NETWORK_INTERFACE_RECEIVE, ( const uint8_t * const ) "Packets received by the network interface", prvIncrementEventCount, 0 }, + { iptraceID_NETWORK_INTERFACE_TRANSMIT, ( const uint8_t * const ) "Count of transmitted packets", prvIncrementEventCount, 0 }, + { iptraceID_PACKET_DROPPED_TO_GENERATE_ARP, ( const uint8_t * const ) "Count of packets dropped to generate ARP", prvIncrementEventCount, 0 }, { iptraceID_NETWORK_BUFFER_OBTAINED, ( const uint8_t * const ) "Lowest ever available network buffers", prvStoreLowest, 0xffffUL }, { iptraceID_NETWORK_EVENT_RECEIVED, ( const uint8_t * const ) "Lowest ever free space in network event queue", prvStoreLowest, 0xffffUL }, { iptraceID_FAILED_TO_OBTAIN_NETWORK_BUFFER, ( const uint8_t * const ) "Count of failed attempts to obtain a network buffer",prvIncrementEventCount, 0 }, { iptraceID_ARP_TABLE_ENTRY_EXPIRED, ( const uint8_t * const ) "Count of expired ARP entries", prvIncrementEventCount, 0 }, - { iptraceID_PACKET_DROPPED_TO_GENERATE_ARP, ( const uint8_t * const ) "Count of packets dropped to generate ARP", prvIncrementEventCount, 0 }, { iptraceID_FAILED_TO_CREATE_SOCKET, ( const uint8_t * const ) "Count of failures to create a socket", prvIncrementEventCount, 0 }, { iptraceID_RECVFROM_DISCARDING_BYTES, ( const uint8_t * const ) "Count of times recvfrom() has discarding bytes", prvIncrementEventCount, 0 }, { iptraceID_ETHERNET_RX_EVENT_LOST, ( const uint8_t * const ) "Count of lost Ethenret Rx events (event queue full?)",prvIncrementEventCount, 0 }, { iptraceID_STACK_TX_EVENT_LOST, ( const uint8_t * const ) "Count of lost IP stack events (event queue full?)", prvIncrementEventCount, 0 }, { ipconfigID_BIND_FAILED, ( const uint8_t * const ) "Count of failed calls to bind()", prvIncrementEventCount, 0 }, - { iptraceID_NETWORK_INTERFACE_TRANSMIT, ( const uint8_t * const ) "Count of transmitted packets", prvIncrementEventCount, 0 }, { iptraceID_RECVFROM_TIMEOUT, ( const uint8_t * const ) "Count of receive timeouts", prvIncrementEventCount, 0 }, { iptraceID_SENDTO_DATA_TOO_LONG, ( const uint8_t * const ) "Count of failed sends due to oversized payload", prvIncrementEventCount, 0 }, { iptraceID_SENDTO_SOCKET_NOT_BOUND, ( const uint8_t * const ) "Count of failed sends due to unbound socket", prvIncrementEventCount, 0 }, diff --git a/FreeRTOS-Plus/Demo/Common/FreeRTOS_Plus_UDP_Demos/TraceMacros/Example1/DemoIPTrace.h b/FreeRTOS-Plus/Demo/Common/FreeRTOS_Plus_UDP_Demos/TraceMacros/Example1/DemoIPTrace.h index 8c14962ee..e4205c312 100644 --- a/FreeRTOS-Plus/Demo/Common/FreeRTOS_Plus_UDP_Demos/TraceMacros/Example1/DemoIPTrace.h +++ b/FreeRTOS-Plus/Demo/Common/FreeRTOS_Plus_UDP_Demos/TraceMacros/Example1/DemoIPTrace.h @@ -85,18 +85,21 @@ typedef struct ExampleDebugStatEntry /* Unique identifiers used to locate the entry for each trace macro in the xIPTraceValues[] table defined in DemoIPTrace.c. */ -#define iptraceID_NETWORK_BUFFER_OBTAINED 1 -#define iptraceID_NETWORK_BUFFER_OBTAINED_FROM_ISR 2 -#define iptraceID_NETWORK_EVENT_RECEIVED 3 -#define iptraceID_FAILED_TO_OBTAIN_NETWORK_BUFFER 4 -#define iptraceID_ARP_TABLE_ENTRY_EXPIRED 5 -#define iptraceID_PACKET_DROPPED_TO_GENERATE_ARP 6 -#define iptraceID_FAILED_TO_CREATE_SOCKET 7 -#define iptraceID_RECVFROM_DISCARDING_BYTES 8 -#define iptraceID_ETHERNET_RX_EVENT_LOST 9 -#define iptraceID_STACK_TX_EVENT_LOST 10 -#define ipconfigID_BIND_FAILED 11 -#define iptraceID_NETWORK_INTERFACE_TRANSMIT 12 +#define iptraceID_NETWORK_INTERFACE_RECEIVE 0 +#define iptraceID_NETWORK_INTERFACE_TRANSMIT 1 +#define iptraceID_PACKET_DROPPED_TO_GENERATE_ARP 2 +/* Do not change IDs above this line as the ID is shared with a FreeRTOS+Nabto +demo. */ +#define iptraceID_NETWORK_BUFFER_OBTAINED 3 +#define iptraceID_NETWORK_BUFFER_OBTAINED_FROM_ISR 4 +#define iptraceID_NETWORK_EVENT_RECEIVED 5 +#define iptraceID_FAILED_TO_OBTAIN_NETWORK_BUFFER 6 +#define iptraceID_ARP_TABLE_ENTRY_EXPIRED 7 +#define iptraceID_FAILED_TO_CREATE_SOCKET 8 +#define iptraceID_RECVFROM_DISCARDING_BYTES 9 +#define iptraceID_ETHERNET_RX_EVENT_LOST 10 +#define iptraceID_STACK_TX_EVENT_LOST 11 +#define ipconfigID_BIND_FAILED 12 #define iptraceID_RECVFROM_TIMEOUT 13 #define iptraceID_SENDTO_DATA_TOO_LONG 14 #define iptraceID_SENDTO_SOCKET_NOT_BOUND 15 @@ -136,6 +139,7 @@ configINCLUDE_DEMO_DEBUG_STATS setting in FreeRTOSIPConfig.h. */ #define iptraceNO_BUFFER_FOR_SENDTO() vExampleDebugStatUpdate( iptraceID_NO_BUFFER_FOR_SENDTO, 0 ) #define iptraceWAITING_FOR_TX_DMA_DESCRIPTOR() vExampleDebugStatUpdate( iptraceID_WAIT_FOR_TX_DMA_DESCRIPTOR, 0 ) #define iptraceFAILED_TO_NOTIFY_SELECT_GROUP( xSocket ) vExampleDebugStatUpdate( iptraceID_FAILED_TO_NOTIFY_SELECT_GROUP, 0 ) + #define iptraceNETWORK_INTERFACE_RECEIVE() vExampleDebugStatUpdate( iptraceID_NETWORK_INTERFACE_RECEIVE, 0 ) /* * The function that updates a line in the xIPTraceValues table. diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-Nabto/readme.txt b/FreeRTOS-Plus/Source/FreeRTOS-Plus-Nabto/readme.txt new file mode 100644 index 000000000..b5d1bc561 --- /dev/null +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-Nabto/readme.txt @@ -0,0 +1,6 @@ +FreeRTOS+Nabto projects are currently provided in a separate +download. Following are links to the download page and the +documentation for the demo that is included in the download. + +http://www.freertos.org/FreeRTOS-Plus/Nabto/download_freertos_plus_nabto.shtml +http://www.freertos.org/FreeRTOS-Plus/Nabto/getting_started_with_FreeRTOS_Plus_Nabto.shtml \ No newline at end of file diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-UDP/FreeRTOS_Sockets.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-UDP/FreeRTOS_Sockets.c index 314c4daa4..16c2e870a 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-UDP/FreeRTOS_Sockets.c +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-UDP/FreeRTOS_Sockets.c @@ -186,21 +186,39 @@ xFreeRTOS_Socket_t *pxSocket; portBASE_TYPE FreeRTOS_FD_SET( xSocket_t xSocket, xSocketSet_t xSocketSet ) { xFreeRTOS_Socket_t *pxSocket = ( xFreeRTOS_Socket_t * ) xSocket; - portBASE_TYPE xReturn; - + portBASE_TYPE xReturn = pdFALSE; + unsigned portBASE_TYPE uxMessagesWaiting; + + configASSERT( xSocket ); + /* Is the socket already a member of a select group? */ if( pxSocket->xSelectQueue == NULL ) { - /* Store a pointer to the select group in the socket for future - reference. */ - pxSocket->xSelectQueue = ( xQueueHandle ) xSocketSet; - xReturn = pdPASS; - } - else - { - /* The socket is already a member of a select group so cannot be added - to another. */ - xReturn = pdFAIL; + taskENTER_CRITICAL(); + { + /* Are there packets queued on the socket already? */ + uxMessagesWaiting = uxQueueMessagesWaiting( pxSocket->xWaitingPacketSemaphore ); + + /* Are there enough notification spaces in the select queue for the + number of packets already queued on the socket? */ + if( uxQueueSpacesAvailable( ( xQueueHandle ) xSocketSet ) >= uxMessagesWaiting ) + { + /* Store a pointer to the select group in the socket for + future reference. */ + pxSocket->xSelectQueue = ( xQueueHandle ) xSocketSet; + + while( uxMessagesWaiting > 0 ) + { + /* Add notifications of the number of packets that are + already queued on the socket to the select queue. */ + xQueueSendFromISR( pxSocket->xSelectQueue, &pxSocket, NULL ); + uxMessagesWaiting--; + } + + xReturn = pdPASS; + } + } + taskEXIT_CRITICAL(); } return xReturn; diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-UDP/include/FreeRTOSIPConfigDefaults.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-UDP/include/FreeRTOSIPConfigDefaults.h index 913cb4947..6671ec211 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-UDP/include/FreeRTOSIPConfigDefaults.h +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-UDP/include/FreeRTOSIPConfigDefaults.h @@ -147,4 +147,8 @@ from the FreeRTOSIPConfig.h configuration header file. */ #define ipconfigNABTO_TASK_PRIORITY ( ipconfigUDP_TASK_PRIORITY + 1 ) #endif +#ifndef ipconfigSUPPORT_SELECT_FUNCTION + #define ipconfigSUPPORT_SELECT_FUNCTION 0 +#endif + #endif /* FREERTOS_DEFAULT_IP_CONFIG_H */ -- 2.39.5