/*\r
* Return the checksum generated over usDataLengthBytes from pucNextData.\r
*/\r
-static uint16_t prvGenerateChecksum( const uint8_t * const pucNextData, const uint16_t usDataLengthBytes );\r
+static uint16_t prvGenerateChecksum( const uint8_t * const pucNextData, const uint16_t usDataLengthBytes, portBASE_TYPE xChecksumIsOffloaded );\r
\r
/*\r
* The callback function that is assigned to all periodic processing timers -\r
* Creates the pseudo header necessary then generate the checksum over the UDP\r
* packet. Returns the calculated checksum.\r
*/\r
-static uint16_t prvGenerateUDPChecksum( const xUDPPacket_t * const pxUDPPacket );\r
+static uint16_t prvGenerateUDPChecksum( const xUDPPacket_t * const pxUDPPacket, portBASE_TYPE xChecksumIsOffloaded );\r
\r
/*\r
* Look for ulIPAddress in the ARP cache. If the IP address exists, copy the\r
memset( ( void * ) pucChar, ( int ) ipECHO_DATA_FILL_BYTE, xNumberOfBytesToSend );\r
\r
/* The message is complete, calculate the checksum. */\r
- pxICMPHeader->usChecksum = prvGenerateChecksum( ( uint8_t * ) pxICMPHeader, ( uint16_t ) ( xNumberOfBytesToSend + sizeof( xICMPHeader_t ) ) );\r
+ pxICMPHeader->usChecksum = prvGenerateChecksum( ( uint8_t * ) pxICMPHeader, ( uint16_t ) ( xNumberOfBytesToSend + sizeof( xICMPHeader_t ) ), pdFALSE );\r
\r
/* Complete the network buffer information. */\r
pxNetworkBuffer->ulIPAddress = ulIPAddress;\r
\r
if( ( ucSocketOptions & FREERTOS_SO_UDPCKSUM_OUT ) != 0U )\r
{\r
- pxUDPHeader->usChecksum = prvGenerateUDPChecksum( pxUDPPacket );\r
+ pxUDPHeader->usChecksum = prvGenerateUDPChecksum( pxUDPPacket, ipconfigETHERNET_DRIVER_ADDS_UDP_CHECKSUM );\r
if( pxUDPHeader->usChecksum == 0x00 )\r
{\r
/* A calculated checksum of 0 must be inverted as 0 means the\r
pxIPHeader->usLength = FreeRTOS_htons( pxIPHeader->usLength );\r
pxIPHeader->ulDestinationIPAddress = pxNetworkBuffer->ulIPAddress;\r
pxIPHeader->usIdentification = usPacketIdentifier;\r
- pxIPHeader->usHeaderChecksum = prvGenerateChecksum( ( uint8_t * ) &( pxIPHeader->ucVersionHeaderLength ), ipIP_HEADER_LENGTH );\r
+ pxIPHeader->usHeaderChecksum = prvGenerateChecksum( ( uint8_t * ) &( pxIPHeader->ucVersionHeaderLength ), ipIP_HEADER_LENGTH, ipconfigETHERNET_DRIVER_ADDS_IP_CHECKSUM );\r
}\r
else if ( eReturned == eARPCacheMiss )\r
{\r
pxNetworkBuffer->xDataLength = pxIPHeader->usLength + sizeof( xEthernetHeader_t );\r
pxIPHeader->usLength = FreeRTOS_htons( pxIPHeader->usLength );\r
pxIPHeader->ulDestinationIPAddress = pxNetworkBuffer->ulIPAddress;\r
- pxIPHeader->usHeaderChecksum = prvGenerateChecksum( ( uint8_t * ) &( pxIPHeader->ucVersionHeaderLength ), ipIP_HEADER_LENGTH );\r
+ pxIPHeader->usHeaderChecksum = prvGenerateChecksum( ( uint8_t * ) &( pxIPHeader->ucVersionHeaderLength ), ipIP_HEADER_LENGTH, ipconfigETHERNET_DRIVER_ADDS_IP_CHECKSUM );\r
}\r
else if ( eReturned == eARPCacheMiss )\r
{\r
if( ( pxIPHeader->ucVersionHeaderLength == ipIP_VERSION_AND_HEADER_LENGTH_BYTE ) && ( ( pxIPHeader->usFragmentOffset & ipFRAGMENT_OFFSET_BIT_MASK ) == 0U ) )\r
{\r
/* Is the IP header checksum correct? */\r
- if( prvGenerateChecksum( ( uint8_t * ) &( pxIPHeader->ucVersionHeaderLength ), ipIP_HEADER_LENGTH ) == 0 )\r
+ if( prvGenerateChecksum( ( uint8_t * ) &( pxIPHeader->ucVersionHeaderLength ), ipIP_HEADER_LENGTH, ipconfigETHERNET_DRIVER_CHECKS_IP_CHECKSUM ) == 0 )\r
{\r
/* Add the IP and MAC addresses to the ARP table if they are not\r
already there - otherwise refresh the age of the existing\r
{\r
xChecksumIsCorrect = pdTRUE;\r
}\r
- else if( prvGenerateUDPChecksum( pxUDPPacket ) == 0 )\r
+ else if( prvGenerateUDPChecksum( pxUDPPacket, ipconfigETHERNET_DRIVER_CHECKS_UDP_CHECKSUM ) == 0 )\r
{\r
xChecksumIsCorrect = pdTRUE;\r
}\r
}\r
/*-----------------------------------------------------------*/\r
\r
-static uint16_t prvGenerateUDPChecksum( const xUDPPacket_t * const pxUDPPacket )\r
+static uint16_t prvGenerateUDPChecksum( const xUDPPacket_t * const pxUDPPacket, portBASE_TYPE xChecksumIsOffloaded )\r
{\r
xPseudoHeader_t *pxPseudoHeader;\r
uint16_t usLength, usReturn;\r
\r
- /* Map the pseudo header into the correct place within the real IP\r
- header. */\r
- pxPseudoHeader = ( xPseudoHeader_t * ) &( pxUDPPacket->xIPHeader.ucTimeToLive );\r
-\r
- /* Ordering here is important so as not to overwrite data that is required\r
- but has not yet been used as the pseudo header overlaps the information\r
- that is being copied into it. */\r
- pxPseudoHeader->ulSourceAddress = pxUDPPacket->xIPHeader.ulSourceIPAddress;\r
- pxPseudoHeader->ulDestinationAddress = pxUDPPacket->xIPHeader.ulDestinationIPAddress;\r
- pxPseudoHeader->ucZeros = 0x00;\r
- pxPseudoHeader->ucProtocol = ipPROTOCOL_UDP;\r
- pxPseudoHeader->usUDPLength = pxUDPPacket->xUDPHeader.usLength;\r
-\r
- usLength = FreeRTOS_ntohs( pxPseudoHeader->usUDPLength );\r
- usReturn = prvGenerateChecksum( ( uint8_t * ) pxPseudoHeader, usLength + sizeof( xPseudoHeader_t ) );\r
+ if( xChecksumIsOffloaded == pdFALSE )\r
+ {\r
+ /* Map the pseudo header into the correct place within the real IP\r
+ header. */\r
+ pxPseudoHeader = ( xPseudoHeader_t * ) &( pxUDPPacket->xIPHeader.ucTimeToLive );\r
+\r
+ /* Ordering here is important so as not to overwrite data that is required\r
+ but has not yet been used as the pseudo header overlaps the information\r
+ that is being copied into it. */\r
+ pxPseudoHeader->ulSourceAddress = pxUDPPacket->xIPHeader.ulSourceIPAddress;\r
+ pxPseudoHeader->ulDestinationAddress = pxUDPPacket->xIPHeader.ulDestinationIPAddress;\r
+ pxPseudoHeader->ucZeros = 0x00;\r
+ pxPseudoHeader->ucProtocol = ipPROTOCOL_UDP;\r
+ pxPseudoHeader->usUDPLength = pxUDPPacket->xUDPHeader.usLength;\r
+\r
+ usLength = FreeRTOS_ntohs( pxPseudoHeader->usUDPLength );\r
+ usReturn = prvGenerateChecksum( ( uint8_t * ) pxPseudoHeader, usLength + sizeof( xPseudoHeader_t ), pdFALSE );\r
+ }\r
+ else\r
+ {\r
+ /* The hardware will check the checksum. Returning 0 allows this \r
+ function to be used to both check an incoming checksum and set an\r
+ outgoing checksum in this case. */\r
+ usReturn = 0;\r
+ }\r
\r
return usReturn;\r
}\r
message itself. */\r
usDataLength -= sizeof( xIPHeader_t );\r
\r
- if( prvGenerateChecksum( ( uint8_t * ) &( pxICMPPacket->xICMPHeader ), usDataLength ) != 0 )\r
+ if( prvGenerateChecksum( ( uint8_t * ) &( pxICMPPacket->xICMPHeader ), usDataLength, pdFALSE ) != 0 )\r
{\r
eStatus = eInvalidChecksum;\r
}\r
#endif /* ( ipconfigREPLY_TO_INCOMING_PINGS == 1 ) || ( ipconfigSUPPORT_OUTGOING_PINGS == 1 ) */\r
/*-----------------------------------------------------------*/\r
\r
-static uint16_t prvGenerateChecksum( const uint8_t * const pucNextData, const uint16_t usDataLengthBytes )\r
+static uint16_t prvGenerateChecksum( const uint8_t * const pucNextData, const uint16_t usDataLengthBytes, portBASE_TYPE xChecksumIsOffloaded )\r
{\r
uint32_t ulChecksum = 0;\r
-uint16_t us, usDataLength16BitWords, *pusNextData;\r
+uint16_t us, usDataLength16BitWords, *pusNextData, usReturn;\r
\r
- /* There are half as many 16 bit words than bytes. */\r
- usDataLength16BitWords = ( usDataLengthBytes >> 1U );\r
+ if( xChecksumIsOffloaded == pdFALSE )\r
+ {\r
+ /* There are half as many 16 bit words than bytes. */\r
+ usDataLength16BitWords = ( usDataLengthBytes >> 1U );\r
\r
- pusNextData = ( uint16_t * ) pucNextData;\r
+ pusNextData = ( uint16_t * ) pucNextData;\r
\r
- for( us = 0U; us < usDataLength16BitWords; us++ )\r
- {\r
- ulChecksum += ( uint32_t ) pusNextData[ us ];\r
- }\r
+ for( us = 0U; us < usDataLength16BitWords; us++ )\r
+ {\r
+ ulChecksum += ( uint32_t ) pusNextData[ us ];\r
+ }\r
\r
- if( ( usDataLengthBytes & 0x01U ) != 0x00 )\r
- {\r
- /* There is one byte left over. */\r
- #if ipconfigBYTE_ORDER == FREERTOS_LITTLE_ENDIAN\r
+ if( ( usDataLengthBytes & 0x01U ) != 0x00 )\r
{\r
- ulChecksum += ( uint32_t ) pucNextData[ usDataLengthBytes - 1 ];\r
+ /* There is one byte left over. */\r
+ #if ipconfigBYTE_ORDER == FREERTOS_LITTLE_ENDIAN\r
+ {\r
+ ulChecksum += ( uint32_t ) pucNextData[ usDataLengthBytes - 1 ];\r
+ }\r
+ #else\r
+ {\r
+ us = ( uint16_t ) pucNextData[ usDataLengthBytes - 1 ];\r
+ ulChecksum += ( uint32_t ) ( us << 8 );\r
+ }\r
+ #endif\r
}\r
- #else\r
+\r
+ while( ( ulChecksum >> 16UL ) != 0x00UL )\r
{\r
- us = ( uint16_t ) pucNextData[ usDataLengthBytes - 1 ];\r
- ulChecksum += ( uint32_t ) ( us << 8 );\r
+ ulChecksum = ( ulChecksum & 0xffffUL ) + ( ulChecksum >> 16UL );\r
}\r
- #endif\r
+ \r
+ usReturn = ~( ( uint16_t ) ulChecksum );\r
}\r
-\r
- while( ( ulChecksum >> 16UL ) != 0x00UL )\r
+ else\r
{\r
- ulChecksum = ( ulChecksum & 0xffffUL ) + ( ulChecksum >> 16UL );\r
+ /* The checksum is calculated by the hardware. Return 0 here to ensure\r
+ this works for both incoming and outgoing checksums. */\r
+ usReturn = 0;\r
}\r
\r
- return ~( ( uint16_t ) ulChecksum );\r
+ return usReturn;\r
}\r
/*-----------------------------------------------------------*/\r
\r
+ Increase the size of the critical section in the function that obtains a\r
private port number.\r
+ Add defaults for more trace macros.\r
+ + Update network interfaces so all compile with latest code revision.\r
+ + Added the following definitions for improved performance on hardware that\r
+ has the ability to offload checksum generation and/or checking:\r
+ ipconfigETHERNET_DRIVER_ADDS_UDP_CHECKSUM\r
+ ipconfigETHERNET_DRIVER_ADDS_IP_CHECKSUM\r
+ ipconfigETHERNET_DRIVER_CHECKS_IP_CHECKSUM\r
+ ipconfigETHERNET_DRIVER_CHECKS_UDP_CHECKSUM\r
\r
Changes between V1.0.0 and V1.0.1\r
\r
* This file is part of the FreeRTOS+UDP distribution. The FreeRTOS+UDP license\r
* terms are different to the FreeRTOS license terms.\r
*\r
- * FreeRTOS+UDP uses a dual license model that allows the software to be used \r
- * under a standard GPL open source license, or a commercial license. The \r
- * standard GPL license (unlike the modified GPL license under which FreeRTOS \r
- * itself is distributed) requires that all software statically linked with \r
- * FreeRTOS+UDP is also distributed under the same GPL V2 license terms. \r
+ * FreeRTOS+UDP uses a dual license model that allows the software to be used\r
+ * under a standard GPL open source license, or a commercial license. The\r
+ * standard GPL license (unlike the modified GPL license under which FreeRTOS\r
+ * itself is distributed) requires that all software statically linked with\r
+ * FreeRTOS+UDP is also distributed under the same GPL V2 license terms.\r
* Details of both license options follow:\r
*\r
* - Open source licensing -\r
*\r
* - Commercial licensing -\r
* Businesses and individuals that for commercial or other reasons cannot comply\r
- * with the terms of the GPL V2 license must obtain a commercial license before \r
- * incorporating FreeRTOS+UDP into proprietary software for distribution in any \r
- * form. Commercial licenses can be purchased from http://shop.freertos.org/udp \r
+ * with the terms of the GPL V2 license must obtain a commercial license before\r
+ * incorporating FreeRTOS+UDP into proprietary software for distribution in any\r
+ * form. Commercial licenses can be purchased from http://shop.freertos.org/udp\r
* and do not require any source files to be changed.\r
*\r
* FreeRTOS+UDP is distributed in the hope that it will be useful. You cannot\r
#ifndef ipconfigSUPPORT_SELECT_FUNCTION\r
#define ipconfigSUPPORT_SELECT_FUNCTION 0\r
#endif\r
+ \r
+#ifndef ipconfigETHERNET_DRIVER_ADDS_UDP_CHECKSUM\r
+ #define ipconfigETHERNET_DRIVER_ADDS_UDP_CHECKSUM 0\r
+#endif\r
+\r
+#ifndef ipconfigETHERNET_DRIVER_ADDS_IP_CHECKSUM\r
+ #define ipconfigETHERNET_DRIVER_ADDS_IP_CHECKSUM 0\r
+#endif\r
+\r
+#ifndef ipconfigETHERNET_DRIVER_CHECKS_IP_CHECKSUM\r
+ #define ipconfigETHERNET_DRIVER_CHECKS_IP_CHECKSUM 0\r
+#endif\r
+\r
+#ifndef ipconfigETHERNET_DRIVER_CHECKS_UDP_CHECKSUM\r
+ #define ipconfigETHERNET_DRIVER_CHECKS_UDP_CHECKSUM 0\r
+#endif\r
\r
#endif /* FREERTOS_DEFAULT_IP_CONFIG_H */\r
\r
#define FreeRTOS_inet_ntoa( ulIPAddress, pucBuffer ) \\r
sprintf( ( char * ) ( pucBuffer ), "%d.%d.%d.%d", \\r
- ( ( ulIPAddress ) & 0xffUL ), \\r
- ( ( ( ulIPAddress ) >> 8UL ) & 0xffUL ), \\r
- ( ( ( ulIPAddress ) >> 16UL ) & 0xffUL ), \\r
- ( ( ( ulIPAddress ) >> 24UL ) & 0xffUL ) )\r
+ ( int ) ( ( ulIPAddress ) & 0xffUL ), \\r
+ ( int ) ( ( ( ulIPAddress ) >> 8UL ) & 0xffUL ),\\r
+ ( int ) ( ( ( ulIPAddress ) >> 16UL ) & 0xffUL ),\\r
+ ( int ) ( ( ( ulIPAddress ) >> 24UL ) & 0xffUL ) )\r
\r
#else /* ipconfigBYTE_ORDER */\r
\r
--- /dev/null
+/*\r
+ * FreeRTOS+UDP V1.0.2 (C) 2013 Real Time Engineers ltd.\r
+ * All rights reserved\r
+ *\r
+ * This file is part of the FreeRTOS+UDP distribution. The FreeRTOS+UDP license\r
+ * terms are different to the FreeRTOS license terms.\r
+ *\r
+ * FreeRTOS+UDP uses a dual license model that allows the software to be used\r
+ * under a pure GPL open source license (as opposed to the modified GPL license\r
+ * under which FreeRTOS is distributed) or a commercial license. Details of\r
+ * both license options follow:\r
+ *\r
+ * - Open source licensing -\r
+ * FreeRTOS+UDP is a free download and may be used, modified, evaluated and\r
+ * distributed without charge provided the user adheres to version two of the\r
+ * GNU General Public License (GPL) and does not remove the copyright notice or\r
+ * this text. The GPL V2 text is available on the gnu.org web site, and on the\r
+ * following URL: http://www.FreeRTOS.org/gpl-2.0.txt.\r
+ *\r
+ * - Commercial licensing -\r
+ * Businesses and individuals that for commercial or other reasons cannot comply\r
+ * with the terms of the GPL V2 license must obtain a commercial license before \r
+ * incorporating FreeRTOS+UDP into proprietary software for distribution in any \r
+ * form. Commercial licenses can be purchased from http://shop.freertos.org/udp \r
+ * and do not require any source files to be changed.\r
+ *\r
+ * FreeRTOS+UDP is distributed in the hope that it will be useful. You cannot\r
+ * use FreeRTOS+UDP unless you agree that you use the software 'as is'.\r
+ * FreeRTOS+UDP is provided WITHOUT ANY WARRANTY; without even the implied\r
+ * warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A PARTICULAR\r
+ * PURPOSE. Real Time Engineers Ltd. disclaims all conditions and terms, be they\r
+ * implied, expressed, or statutory.\r
+ *\r
+ * 1 tab == 4 spaces!\r
+ *\r
+ * http://www.FreeRTOS.org\r
+ * http://www.FreeRTOS.org/udp\r
+ *\r
+ */\r
+\r
+/* Standard includes. */\r
+#include <stdint.h>\r
+\r
+/* FreeRTOS includes. */\r
+#include "FreeRTOS.h"\r
+#include "task.h"\r
+#include "queue.h"\r
+#include "semphr.h"\r
+\r
+/* FreeRTOS+UDP includes. */\r
+#include "FreeRTOS_UDP_IP.h"\r
+#include "FreeRTOS_IP_Private.h"\r
+#include "FreeRTOS_Sockets.h"\r
+#include "NetworkBufferManagement.h"\r
+\r
+/* Demo includes. */\r
+#include "NetworkInterface.h"\r
+\r
+/* If a packet cannot be sent immediately then the task performing the send\r
+operation will be held in the Blocked state (so other tasks can execute) for\r
+niTX_BUFFER_FREE_WAIT ticks. It will do this a maximum of niMAX_TX_ATTEMPTS\r
+before giving up. */\r
+#define niTX_BUFFER_FREE_WAIT ( ( portTickType ) 2UL / portTICK_RATE_MS )\r
+#define niMAX_TX_ATTEMPTS ( 5 )\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
+/*\r
+ * A deferred interrupt handler task that processes received frames.\r
+ */\r
+static void prvGMACDeferredInterruptHandlerTask( void *pvParameters );\r
+\r
+/*\r
+ * Called by the ASF GMAC driver when a packet is received.\r
+ */\r
+static void prvGMACRxCallback( uint32_t ulStatus );\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
+/* The queue used to communicate Ethernet events to the IP task. */\r
+extern xQueueHandle xNetworkEventQueue;\r
+\r
+/* The semaphore used to wake the deferred interrupt handler task when an Rx\r
+interrupt is received. */\r
+static xSemaphoreHandle xGMACRxEventSemaphore = NULL;\r
+\r
+/* The GMAC driver instance. */\r
+static gmac_device_t xGMACStruct;\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
+portBASE_TYPE xNetworkInterfaceInitialise( void )\r
+{\r
+gmac_options_t xGMACOptions;\r
+extern uint8_t ucMACAddress[ 6 ];\r
+const portTickType xPHYDelay_400ms = 400UL;\r
+portBASE_TYPE xReturn = pdFALSE;\r
+\r
+ /* Ensure PHY is ready. */\r
+ vTaskDelay( xPHYDelay_400ms / portTICK_RATE_MS ); \r
+\r
+ /* Enable GMAC clock. */\r
+ pmc_enable_periph_clk( ID_GMAC );\r
+\r
+ /* Fill in GMAC options */\r
+ xGMACOptions.uc_copy_all_frame = 0;\r
+ xGMACOptions.uc_no_boardcast = 0;\r
+ memcpy( xGMACOptions.uc_mac_addr, ucMACAddress, sizeof( ucMACAddress ) );\r
+\r
+ xGMACStruct.p_hw = GMAC;\r
+\r
+ /* Init GMAC driver structure. */\r
+ gmac_dev_init( GMAC, &xGMACStruct, &xGMACOptions );\r
+\r
+ /* Init MAC PHY driver. */\r
+ if( ethernet_phy_init( GMAC, BOARD_GMAC_PHY_ADDR, sysclk_get_cpu_hz() ) == GMAC_OK )\r
+ {\r
+ /* Auto Negotiate, work in RMII mode. */\r
+ if( ethernet_phy_auto_negotiate( GMAC, BOARD_GMAC_PHY_ADDR ) == GMAC_OK ) \r
+ {\r
+ /* Establish Ethernet link. */\r
+ vTaskDelay( xPHYDelay_400ms * 2UL );\r
+ if( ethernet_phy_set_link( GMAC, BOARD_GMAC_PHY_ADDR, 1 ) == GMAC_OK )\r
+ {\r
+ /* Create the event semaphore if it has not already been \r
+ created. */\r
+ if( xGMACRxEventSemaphore == NULL )\r
+ {\r
+ vSemaphoreCreateBinary( xGMACRxEventSemaphore );\r
+ #if ipconfigINCLUDE_EXAMPLE_FREERTOS_PLUS_TRACE_CALLS == 1\r
+ {\r
+ /* If the trace recorder code is included name the semaphore for\r
+ viewing in FreeRTOS+Trace. */\r
+ vTraceSetQueueName( xGMACRxEventSemaphore, "MAC_RX" );\r
+ }\r
+ #endif /* ipconfigINCLUDE_EXAMPLE_FREERTOS_PLUS_TRACE_CALLS == 1 */\r
+ }\r
+ \r
+ /* Register the callbacks. */\r
+ gmac_dev_set_rx_callback( &xGMACStruct, prvGMACRxCallback );\r
+ \r
+ /* The Rx deferred interrupt handler task is created at the \r
+ highest possible priority to ensure the interrupt handler can \r
+ return directly to it no matter which task was running when the \r
+ interrupt occurred. */\r
+ xTaskCreate( prvGMACDeferredInterruptHandlerTask,/* The function that implements the task. */\r
+ ( const signed char * const ) "MACTsk",\r
+ configMINIMAL_STACK_SIZE, /* Stack allocated to the task (defined in words, not bytes). */\r
+ NULL, /* The task parameter is not used. */\r
+ configMAX_PRIORITIES - 1, /* The priority assigned to the task. */\r
+ NULL ); /* The handle is not required, so NULL is passed. */\r
+ \r
+ /* Enable the interrupt and set its priority as configured. \r
+ THIS DRIVER REQUIRES configMAC_INTERRUPT_PRIORITY TO BE DEFINED, \r
+ PREFERABLY IN FreeRTOSConfig.h. */\r
+ NVIC_SetPriority( GMAC_IRQn, configMAC_INTERRUPT_PRIORITY );\r
+ NVIC_EnableIRQ( GMAC_IRQn );\r
+ xReturn = pdPASS;\r
+ }\r
+ }\r
+ }\r
+\r
+ return xReturn;\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static void prvGMACRxCallback( uint32_t ulStatus )\r
+{\r
+portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;\r
+\r
+ /* Unblock the deferred interrupt handler task if the event was an Rx. */\r
+ if( ulStatus != 0 )\r
+ {\r
+ xSemaphoreGiveFromISR( xGMACRxEventSemaphore, &xHigherPriorityTaskWoken );\r
+ }\r
+\r
+ portEND_SWITCHING_ISR( xHigherPriorityTaskWoken );\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+portBASE_TYPE xNetworkInterfaceOutput( xNetworkBufferDescriptor_t * const pxNetworkBuffer )\r
+{\r
+portBASE_TYPE xReturn = pdFAIL;\r
+int32_t x;\r
+\r
+ /* Attempt to obtain access to a Tx descriptor. */\r
+ for( x = 0; x < niMAX_TX_ATTEMPTS; x++ )\r
+ {\r
+ if( gmac_dev_write( &xGMACStruct, pxNetworkBuffer->pucEthernetBuffer, ( uint32_t ) pxNetworkBuffer->xDataLength, NULL ) == GMAC_OK )\r
+ {\r
+ /* The Tx has been initiated. */\r
+ xReturn = pdPASS;\r
+ break;\r
+ }\r
+ else\r
+ {\r
+ iptraceWAITING_FOR_TX_DMA_DESCRIPTOR();\r
+ vTaskDelay( niTX_BUFFER_FREE_WAIT );\r
+ }\r
+ }\r
+\r
+ /* Finished with the network buffer. */\r
+ vNetworkBufferRelease( pxNetworkBuffer );\r
+\r
+ return xReturn;\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+void GMAC_Handler( void )\r
+{\r
+ gmac_handler( &xGMACStruct );\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static void prvGMACDeferredInterruptHandlerTask( void *pvParameters )\r
+{\r
+xNetworkBufferDescriptor_t *pxNetworkBuffer;\r
+xIPStackEvent_t xRxEvent = { eEthernetRxEvent, NULL };\r
+\r
+ ( void ) pvParameters;\r
+ configASSERT( xGMACRxEventSemaphore );\r
+\r
+ for( ;; )\r
+ {\r
+ /* Wait for the GMAC interrupt to indicate that another packet has been\r
+ received. The while() loop is only needed if INCLUDE_vTaskSuspend is\r
+ set to 0 in FreeRTOSConfig.h. If INCLUDE_vTaskSuspend is set to 1\r
+ then portMAX_DELAY would be an indefinite block time and\r
+ xSemaphoreTake() would only return when the semaphore was actually\r
+ obtained. */\r
+ while( xSemaphoreTake( xGMACRxEventSemaphore, portMAX_DELAY ) == pdFALSE );\r
+\r
+ /* The buffer filled by the DMA is going to be passed into the IP\r
+ stack. Allocate another buffer for the DMA descriptor. */\r
+ pxNetworkBuffer = pxNetworkBufferGet( ipTOTAL_ETHERNET_FRAME_SIZE, portMAX_DELAY );\r
+ \r
+ if( pxNetworkBuffer != NULL )\r
+ {\r
+ /* At least one packet has been received. */\r
+ if( gmac_dev_read( &xGMACStruct, pxNetworkBuffer->pucEthernetBuffer, ipTOTAL_ETHERNET_FRAME_SIZE, ( uint32_t * ) &( pxNetworkBuffer->xDataLength ) ) == GMAC_OK )\r
+ {\r
+ #if ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES == 1\r
+ {\r
+ if( pxNetworkBuffer->xDataLength > 0 )\r
+ {\r
+ /* If the frame would not be processed by the IP stack then\r
+ don't even bother sending it to the IP stack. */\r
+ if( eConsiderFrameForProcessing( pxNetworkBuffer->pucEthernetBuffer ) != eProcessBuffer )\r
+ {\r
+ pxNetworkBuffer->xDataLength = 0;\r
+ }\r
+ }\r
+ }\r
+ #endif\r
+\r
+ if( pxNetworkBuffer->xDataLength > 0 )\r
+ {\r
+ /* Store a pointer to the network buffer structure in the\r
+ padding space that was left in front of the Ethernet frame.\r
+ The pointer is needed to ensure the network buffer structure\r
+ can be located when it is time for it to be freed if the\r
+ Ethernet frame gets used as a zero copy buffer. */\r
+ *( ( xNetworkBufferDescriptor_t ** ) ( ( pxNetworkBuffer->pucEthernetBuffer - ipBUFFER_PADDING ) ) ) = pxNetworkBuffer;\r
+\r
+ /* Data was received and stored. Send it to the IP task\r
+ for processing. */\r
+ xRxEvent.pvData = ( void * ) pxNetworkBuffer;\r
+ if( xQueueSendToBack( xNetworkEventQueue, &xRxEvent, ( portTickType ) 0 ) == pdFALSE )\r
+ {\r
+ /* The buffer could not be sent to the IP task so the\r
+ buffer must be released. */\r
+ vNetworkBufferRelease( pxNetworkBuffer );\r
+ iptraceETHERNET_RX_EVENT_LOST();\r
+ }\r
+ else\r
+ {\r
+ iptraceNETWORK_INTERFACE_RECEIVE();\r
+ }\r
+ }\r
+ else\r
+ {\r
+ /* The buffer does not contain any data so there is no\r
+ point sending it to the IP task. Just release it. */\r
+ vNetworkBufferRelease( pxNetworkBuffer );\r
+ iptraceETHERNET_RX_EVENT_LOST();\r
+ }\r
+ }\r
+ else\r
+ {\r
+ iptraceETHERNET_RX_EVENT_LOST();\r
+ }\r
+ }\r
+ }\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r