]> git.sur5r.net Git - freertos/blob - FreeRTOS-Plus/Source/FreeRTOS-Plus-UDP/portable/NetworkInterface/SH2A/NetworkInterface.c
***IMMINENT RELEASE NOTICE***
[freertos] / FreeRTOS-Plus / Source / FreeRTOS-Plus-UDP / portable / NetworkInterface / SH2A / NetworkInterface.c
1 /*\r
2  * FreeRTOS+UDP V1.0.4 (C) 2014 Real Time Engineers ltd.\r
3  * All rights reserved\r
4  *\r
5  * This file is part of the FreeRTOS+UDP distribution.  The FreeRTOS+UDP license\r
6  * terms are different to the FreeRTOS license terms.\r
7  *\r
8  * FreeRTOS+UDP uses a dual license model that allows the software to be used\r
9  * under a standard GPL open source license, or a commercial license.  The\r
10  * standard GPL license (unlike the modified GPL license under which FreeRTOS\r
11  * itself is distributed) requires that all software statically linked with\r
12  * FreeRTOS+UDP is also distributed under the same GPL V2 license terms.\r
13  * Details of both license options follow:\r
14  *\r
15  * - Open source licensing -\r
16  * FreeRTOS+UDP is a free download and may be used, modified, evaluated and\r
17  * distributed without charge provided the user adheres to version two of the\r
18  * GNU General Public License (GPL) and does not remove the copyright notice or\r
19  * this text.  The GPL V2 text is available on the gnu.org web site, and on the\r
20  * following URL: http://www.FreeRTOS.org/gpl-2.0.txt.\r
21  *\r
22  * - Commercial licensing -\r
23  * Businesses and individuals that for commercial or other reasons cannot comply\r
24  * with the terms of the GPL V2 license must obtain a commercial license before\r
25  * incorporating FreeRTOS+UDP into proprietary software for distribution in any\r
26  * form.  Commercial licenses can be purchased from http://shop.freertos.org/udp\r
27  * and do not require any source files to be changed.\r
28  *\r
29  * FreeRTOS+UDP is distributed in the hope that it will be useful.  You cannot\r
30  * use FreeRTOS+UDP unless you agree that you use the software 'as is'.\r
31  * FreeRTOS+UDP is provided WITHOUT ANY WARRANTY; without even the implied\r
32  * warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A PARTICULAR\r
33  * PURPOSE. Real Time Engineers Ltd. disclaims all conditions and terms, be they\r
34  * implied, expressed, or statutory.\r
35  *\r
36  * 1 tab == 4 spaces!\r
37  *\r
38  * http://www.FreeRTOS.org\r
39  * http://www.FreeRTOS.org/udp\r
40  *\r
41  */\r
42 \r
43 /* Standard includes. */\r
44 #include <stdint.h>\r
45 \r
46 /* FreeRTOS includes. */\r
47 #include "FreeRTOS.h"\r
48 #include "task.h"\r
49 #include "queue.h"\r
50 #include "semphr.h"\r
51 \r
52 /* FreeRTOS+UDP includes. */\r
53 #include "FreeRTOS_UDP_IP.h"\r
54 #include "FreeRTOS_IP_Private.h"\r
55 #include "FreeRTOS_Sockets.h"\r
56 #include "NetworkBufferManagement.h"\r
57 \r
58 /* Hardware includes. */\r
59 #include "hwEthernet.h"\r
60 \r
61 /* Demo includes. */\r
62 #include "NetworkInterface.h"\r
63 \r
64 #if ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES != 1\r
65         #define ipCONSIDER_FRAME_FOR_PROCESSING( pucEthernetBuffer ) eProcessBuffer\r
66 #else\r
67         #define ipCONSIDER_FRAME_FOR_PROCESSING( pucEthernetBuffer ) eConsiderFrameForProcessing( ( pucEthernetBuffer ) )\r
68 #endif\r
69 \r
70 /* When a packet is ready to be sent, if it cannot be sent immediately then the\r
71 task performing the transmit will block for niTX_BUFFER_FREE_WAIT\r
72 milliseconds.  It will do this a maximum of niMAX_TX_ATTEMPTS before giving\r
73 up. */\r
74 #define niTX_BUFFER_FREE_WAIT   ( ( TickType_t ) 2UL / portTICK_RATE_MS )\r
75 #define niMAX_TX_ATTEMPTS               ( 5 )\r
76 \r
77 /* The length of the queue used to send interrupt status words from the\r
78 interrupt handler to the deferred handler task. */\r
79 #define niINTERRUPT_QUEUE_LENGTH        ( 10 )\r
80 \r
81 /*-----------------------------------------------------------*/\r
82 \r
83 /*\r
84  * A deferred interrupt handler task that processes\r
85  */\r
86 extern void vEMACHandlerTask( void *pvParameters );\r
87 \r
88 /*-----------------------------------------------------------*/\r
89 \r
90 /* The queue used to communicate Ethernet events with the IP task. */\r
91 extern xQueueHandle xNetworkEventQueue;\r
92 \r
93 /* The semaphore used to wake the deferred interrupt handler task when an Rx\r
94 interrupt is received. */\r
95 xSemaphoreHandle xEMACRxEventSemaphore = NULL;\r
96 /*-----------------------------------------------------------*/\r
97 \r
98 BaseType_t xNetworkInterfaceInitialise( void )\r
99 {\r
100 BaseType_t xStatus, xReturn;\r
101 extern uint8_t ucMACAddress[ 6 ];\r
102 \r
103         /* Initialise the MAC. */\r
104         vInitEmac();\r
105 \r
106         while( lEMACWaitForLink() != pdPASS )\r
107     {\r
108         vTaskDelay( 20 );\r
109     }\r
110 \r
111         vSemaphoreCreateBinary( xEMACRxEventSemaphore );\r
112         configASSERT( xEMACRxEventSemaphore );\r
113 \r
114         /* The handler task is created at the highest possible priority to\r
115         ensure the interrupt handler can return directly to it. */\r
116         xTaskCreate( vEMACHandlerTask, "EMAC", configMINIMAL_STACK_SIZE, NULL, configMAX_PRIORITIES - 1, NULL );\r
117         xReturn = pdPASS;\r
118 \r
119         return xReturn;\r
120 }\r
121 /*-----------------------------------------------------------*/\r
122 \r
123 BaseType_t xNetworkInterfaceOutput( xNetworkBufferDescriptor_t * const pxNetworkBuffer )\r
124 {\r
125 extern void vEMACCopyWrite( uint8_t * pucBuffer, uint16_t usLength );\r
126 \r
127         vEMACCopyWrite( pxNetworkBuffer->pucEthernetBuffer, pxNetworkBuffer->xDataLength );\r
128 \r
129         /* Finished with the network buffer. */\r
130         vNetworkBufferRelease( pxNetworkBuffer );\r
131 \r
132         return pdTRUE;\r
133 }\r
134 /*-----------------------------------------------------------*/\r
135 \r
136 \r