]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/Zynq/x_emacpsif_dma.c
Update TCP/IP tack to latest form Git.
[freertos] / FreeRTOS-Plus / Source / FreeRTOS-Plus-TCP / portable / NetworkInterface / Zynq / x_emacpsif_dma.c
index 895564ca361ae9dc6804bca237b0a2759f908b68..e92c9c21fdfec28e3a6e65fd3b58d28930d9d4b1 100644 (file)
@@ -1,26 +1,26 @@
 /*\r
-FreeRTOS+TCP V2.0.11\r
-Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
-\r
-Permission is hereby granted, free of charge, to any person obtaining a copy of\r
-this software and associated documentation files (the "Software"), to deal in\r
-the Software without restriction, including without limitation the rights to\r
-use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
-the Software, and to permit persons to whom the Software is furnished to do so,\r
-subject to the following conditions:\r
-\r
-The above copyright notice and this permission notice shall be included in all\r
-copies or substantial portions of the Software.\r
-\r
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
-FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
-COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
-IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
-\r
- http://aws.amazon.com/freertos\r
- http://www.FreeRTOS.org\r
+ * FreeRTOS+TCP V2.0.11\r
+ * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
+ *\r
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
+ * this software and associated documentation files (the "Software"), to deal in\r
+ * the Software without restriction, including without limitation the rights to\r
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
+ * the Software, and to permit persons to whom the Software is furnished to do so,\r
+ * subject to the following conditions:\r
+ *\r
+ * The above copyright notice and this permission notice shall be included in all\r
+ * copies or substantial portions of the Software.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
+ * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
+ * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
+ *\r
http://aws.amazon.com/freertos\r
http://www.FreeRTOS.org\r
  */\r
 \r
 #include "FreeRTOS.h"\r
@@ -119,7 +119,6 @@ size_t uxCount = ( ( UBaseType_t ) ipconfigNIC_N_TX_DESC ) - uxSemaphoreGetCount
                        break;\r
                }\r
 #if( ipconfigZERO_COPY_TX_DRIVER != 0 )\r
-#warning ipconfigZERO_COPY_TX_DRIVER is defined\r
                {\r
                void *pvBuffer = pxDMA_tx_buffers[ tail ];\r
                NetworkBufferDescriptor_t *pxBuffer;\r
@@ -201,7 +200,6 @@ BaseType_t xReturn;
 XStatus emacps_send_message(xemacpsif_s *xemacpsif, NetworkBufferDescriptor_t *pxBuffer, int iReleaseAfterSend )\r
 {\r
 int head = xemacpsif->txHead;\r
-//int tail = xemacpsif->txTail;\r
 int iHasSent = 0;\r
 uint32_t ulBaseAddress = xemacpsif->emacps.Config.BaseAddress;\r
 TickType_t xBlockTimeTicks = pdMS_TO_TICKS( 5000u );\r
@@ -291,6 +289,8 @@ TickType_t xBlockTimeTicks = pdMS_TO_TICKS( 5000u );
                /* Start transmit */\r
                xemacpsif->txBusy = pdTRUE;\r
                XEmacPs_WriteReg( ulBaseAddress, XEMACPS_NWCTRL_OFFSET, ( ulValue | XEMACPS_NWCTRL_STARTTX_MASK ) );\r
+               /* Reading it back is important compiler is optimised. */\r
+               XEmacPs_ReadReg( ulBaseAddress, XEMACPS_NWCTRL_OFFSET );\r
        }\r
        dsb();\r
 \r
@@ -313,72 +313,51 @@ void emacps_recv_handler(void *arg)
        portYIELD_FROM_ISR( xHigherPriorityTaskWoken );\r
 }\r
 \r
-static void passEthMessages( NetworkBufferDescriptor_t *ethMsg )\r
+static void prvPassEthMessages( NetworkBufferDescriptor_t *pxDescriptor )\r
 {\r
 IPStackEvent_t xRxEvent;\r
 \r
        xRxEvent.eEventType = eNetworkRxEvent;\r
-       xRxEvent.pvData = ( void * ) ethMsg;\r
+       xRxEvent.pvData = ( void * ) pxDescriptor;\r
 \r
        if( xSendEventStructToIPTask( &xRxEvent, ( TickType_t ) 1000 ) != pdPASS )\r
        {\r
                /* The buffer could not be sent to the stack so must be released again.\r
                This is a deferred handler taskr, not a real interrupt, so it is ok to\r
                use the task level function here. */\r
-               do\r
+               #if( ipconfigUSE_LINKED_RX_MESSAGES != 0 )\r
                {\r
-                       NetworkBufferDescriptor_t *xNext = ethMsg->pxNextBuffer;\r
-                       vReleaseNetworkBufferAndDescriptor( ethMsg );\r
-                       ethMsg = xNext;\r
-               } while( ethMsg != NULL );\r
-\r
+                       do\r
+                       {\r
+                               NetworkBufferDescriptor_t *pxNext = pxDescriptor->pxNextBuffer;\r
+                               vReleaseNetworkBufferAndDescriptor( pxDescriptor );\r
+                               pxDescriptor = pxNext;\r
+                       } while( pxDescriptor != NULL );\r
+               }\r
+               #else\r
+               {\r
+                       vReleaseNetworkBufferAndDescriptor( pxDescriptor );\r
+               }\r
+               #endif  /* ipconfigUSE_LINKED_RX_MESSAGES */\r
                iptraceETHERNET_RX_EVENT_LOST();\r
-               FreeRTOS_printf( ( "passEthMessages: Can not queue return packet!\n" ) );\r
+               FreeRTOS_printf( ( "prvPassEthMessages: Can not queue return packet!\n" ) );\r
        }\r
 }\r
 \r
-TickType_t ack_reception_delay = 10;\r
-\r
 int emacps_check_rx( xemacpsif_s *xemacpsif )\r
 {\r
 NetworkBufferDescriptor_t *pxBuffer, *pxNewBuffer;\r
 int rx_bytes;\r
 volatile int msgCount = 0;\r
 int head = xemacpsif->rxHead;\r
-BaseType_t bHasDataPacket = pdFALSE;\r
-NetworkBufferDescriptor_t *ethMsg = NULL;\r
-NetworkBufferDescriptor_t *ethLast = NULL;\r
+#if( ipconfigUSE_LINKED_RX_MESSAGES != 0 )\r
+       NetworkBufferDescriptor_t *pxFirstDescriptor = NULL;\r
+       NetworkBufferDescriptor_t *pxLastDescriptor = NULL;\r
+#endif /* ipconfigUSE_LINKED_RX_MESSAGES */\r
 \r
        /* There seems to be an issue (SI# 692601), see comments below. */\r
        resetrx_on_no_rxdata(xemacpsif);\r
 \r
-       {\r
-               static int maxcount = 0;\r
-               int count = 0;\r
-               for( ;; )\r
-               {\r
-                       if( ( ( xemacpsif->rxSegments[ head ].address & XEMACPS_RXBUF_NEW_MASK ) == 0 ) ||\r
-                               ( pxDMA_rx_buffers[ head ] == NULL ) )\r
-                       {\r
-                               break;\r
-                       }\r
-                       count++;\r
-                       if( ++head == ipconfigNIC_N_RX_DESC )\r
-                       {\r
-                               head = 0;\r
-                       }\r
-                       if( head == xemacpsif->rxHead )\r
-                       {\r
-                               break;\r
-                       }\r
-               }\r
-               if (maxcount < count) {\r
-                       maxcount = count;\r
-                       FreeRTOS_printf( ( "emacps_check_rx: %d packets\n", maxcount ) );\r
-               }\r
-               head = xemacpsif->rxHead;\r
-       }\r
-\r
        /* This FreeRTOS+TCP driver shall be compiled with the option\r
        "ipconfigUSE_LINKED_RX_MESSAGES" enabled.  It allows the driver to send a\r
        chain of RX messages within one message to the IP-task. */\r
@@ -411,10 +390,6 @@ NetworkBufferDescriptor_t *ethLast = NULL;
                        rx_bytes = xemacpsif->rxSegments[ head ].flags & XEMACPS_RXBUF_LEN_MASK;\r
 \r
                        pxBuffer->xDataLength = rx_bytes;\r
-if( rx_bytes > 60 )\r
-{\r
-       bHasDataPacket = 1;\r
-}\r
                        if( ucIsCachedMemory( pxBuffer->pucEthernetBuffer ) != 0 )\r
                        {\r
                                Xil_DCacheInvalidateRange( ( ( uint32_t )pxBuffer->pucEthernetBuffer ) - ipconfigPACKET_FILLER_SIZE, (unsigned)rx_bytes );\r
@@ -423,20 +398,29 @@ if( rx_bytes > 60 )
                        /* store it in the receive queue, where it'll be processed by a\r
                        different handler. */\r
                        iptraceNETWORK_INTERFACE_RECEIVE();\r
-                       pxBuffer->pxNextBuffer = NULL;\r
-\r
-                       if( ethMsg == NULL )\r
+                       #if( ipconfigUSE_LINKED_RX_MESSAGES != 0 )\r
                        {\r
-                               // Becomes the first message\r
-                               ethMsg = pxBuffer;\r
+                               pxBuffer->pxNextBuffer = NULL;\r
+\r
+                               if( pxFirstDescriptor == NULL )\r
+                               {\r
+                                       // Becomes the first message\r
+                                       pxFirstDescriptor = pxBuffer;\r
+                               }\r
+                               else if( pxLastDescriptor != NULL )\r
+                               {\r
+                                       // Add to the tail\r
+                                       pxLastDescriptor->pxNextBuffer = pxBuffer;\r
+                               }\r
+\r
+                               pxLastDescriptor = pxBuffer;\r
                        }\r
-                       else if( ethLast != NULL )\r
+                       #else\r
                        {\r
-                               // Add to the tail\r
-                               ethLast->pxNextBuffer = pxBuffer;\r
+                               prvPassEthMessages( pxBuffer );\r
                        }\r
+                       #endif  /* ipconfigUSE_LINKED_RX_MESSAGES */\r
 \r
-                       ethLast = pxBuffer;\r
                        msgCount++;\r
                }\r
                {\r
@@ -453,7 +437,8 @@ if( rx_bytes > 60 )
                                /* Clearing 'XEMACPS_RXBUF_NEW_MASK'       0x00000001 *< Used bit.. */\r
                                xemacpsif->rxSegments[ head ].flags = 0;\r
                                xemacpsif->rxSegments[ head ].address = addr;\r
-                               if (xemacpsif->rxSegments[ head ].address) {\r
+                               if (xemacpsif->rxSegments[ head ].address)\r
+                               {\r
                                        // Just to read it\r
                                }\r
                        }\r
@@ -466,14 +451,14 @@ if( rx_bytes > 60 )
                xemacpsif->rxHead = head;\r
        }\r
 \r
-       if( ethMsg != NULL )\r
+       #if( ipconfigUSE_LINKED_RX_MESSAGES != 0 )\r
        {\r
-               if( bHasDataPacket == pdFALSE )\r
+               if( pxFirstDescriptor != NULL )\r
                {\r
-//                     vTaskDelay( ack_reception_delay );\r
+                       prvPassEthMessages( pxFirstDescriptor );\r
                }\r
-               passEthMessages( ethMsg );\r
        }\r
+       #endif  /* ipconfigUSE_LINKED_RX_MESSAGES */\r
 \r
        return msgCount;\r
 }\r
@@ -638,7 +623,6 @@ void resetrx_on_no_rxdata(xemacpsif_s *xemacpsif)
        tempcntr = XEmacPs_ReadReg( xemacpsif->emacps.Config.BaseAddress, XEMACPS_RXCNT_OFFSET );\r
        if ( ( tempcntr == 0 ) && ( xemacpsif->last_rx_frms_cntr == 0 ) )\r
        {\r
-FreeRTOS_printf( ( "resetrx_on_no_rxdata: RESET~\n" ) );\r
                regctrl = XEmacPs_ReadReg(xemacpsif->emacps.Config.BaseAddress,\r
                                XEMACPS_NWCTRL_OFFSET);\r
                regctrl &= (~XEMACPS_NWCTRL_RXEN_MASK);\r