]> git.sur5r.net Git - freertos/blob - FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/SH2A/NetworkInterface.c
Added +TCP code to main repo.
[freertos] / FreeRTOS-Plus / Source / FreeRTOS-Plus-TCP / portable / NetworkInterface / SH2A / NetworkInterface.c
1 /*\r
2  * FreeRTOS+TCP Labs Build 150406 (C) 2015 Real Time Engineers ltd.\r
3  * Authors include Hein Tibosch and Richard Barry\r
4  *\r
5  *******************************************************************************\r
6  ***** NOTE ******* NOTE ******* NOTE ******* NOTE ******* NOTE ******* NOTE ***\r
7  ***                                                                         ***\r
8  ***                                                                         ***\r
9  ***   FREERTOS+TCP IS STILL IN THE LAB:                                     ***\r
10  ***                                                                         ***\r
11  ***   This product is functional and is already being used in commercial    ***\r
12  ***   products.  Be aware however that we are still refining its design,    ***\r
13  ***   the source code does not yet fully conform to the strict coding and   ***\r
14  ***   style standards mandated by Real Time Engineers ltd., and the         ***\r
15  ***   documentation and testing is not necessarily complete.                ***\r
16  ***                                                                         ***\r
17  ***   PLEASE REPORT EXPERIENCES USING THE SUPPORT RESOURCES FOUND ON THE    ***\r
18  ***   URL: http://www.FreeRTOS.org/contact  Active early adopters may, at   ***\r
19  ***   the sole discretion of Real Time Engineers Ltd., be offered versions  ***\r
20  ***   under a license other than that described below.                      ***\r
21  ***                                                                         ***\r
22  ***                                                                         ***\r
23  ***** NOTE ******* NOTE ******* NOTE ******* NOTE ******* NOTE ******* NOTE ***\r
24  *******************************************************************************\r
25  *\r
26  * - Open source licensing -\r
27  * While FreeRTOS+TCP is in the lab it is provided only under version two of the\r
28  * GNU General Public License (GPL) (which is different to the standard FreeRTOS\r
29  * license).  FreeRTOS+TCP is free to download, use and distribute under the\r
30  * terms of that license provided the copyright notice and this text are not\r
31  * altered or removed from the source files.  The GPL V2 text is available on\r
32  * the gnu.org web site, and on the following\r
33  * URL: http://www.FreeRTOS.org/gpl-2.0.txt.  Active early adopters may, and\r
34  * solely at the discretion of Real Time Engineers Ltd., be offered versions\r
35  * under a license other then the GPL.\r
36  *\r
37  * FreeRTOS+TCP is distributed in the hope that it will be useful.  You cannot\r
38  * use FreeRTOS+TCP unless you agree that you use the software 'as is'.\r
39  * FreeRTOS+TCP is provided WITHOUT ANY WARRANTY; without even the implied\r
40  * warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A PARTICULAR\r
41  * PURPOSE. Real Time Engineers Ltd. disclaims all conditions and terms, be they\r
42  * implied, expressed, or statutory.\r
43  *\r
44  * 1 tab == 4 spaces!\r
45  *\r
46  * http://www.FreeRTOS.org\r
47  * http://www.FreeRTOS.org/plus\r
48  * http://www.FreeRTOS.org/labs\r
49  *\r
50  */\r
51 \r
52 /* Standard includes. */\r
53 #include <stdint.h>\r
54 \r
55 /* FreeRTOS includes. */\r
56 #include "FreeRTOS.h"\r
57 #include "task.h"\r
58 #include "queue.h"\r
59 #include "semphr.h"\r
60 \r
61 /* FreeRTOS+TCP includes. */\r
62 #include "FreeRTOS_UDP_IP.h"\r
63 #include "FreeRTOS_Sockets.h"\r
64 #include "NetworkBufferManagement.h"\r
65 \r
66 /* Hardware includes. */\r
67 #include "hwEthernet.h"\r
68 \r
69 /* Demo includes. */\r
70 #include "NetworkInterface.h"\r
71 \r
72 #if ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES != 1\r
73         #define ipCONSIDER_FRAME_FOR_PROCESSING( pucEthernetBuffer ) eProcessBuffer\r
74 #else\r
75         #define ipCONSIDER_FRAME_FOR_PROCESSING( pucEthernetBuffer ) eConsiderFrameForProcessing( ( pucEthernetBuffer ) )\r
76 #endif\r
77 \r
78 /* When a packet is ready to be sent, if it cannot be sent immediately then the\r
79 task performing the transmit will block for niTX_BUFFER_FREE_WAIT\r
80 milliseconds.  It will do this a maximum of niMAX_TX_ATTEMPTS before giving\r
81 up. */\r
82 #define niTX_BUFFER_FREE_WAIT   ( ( TickType_t ) 2UL / portTICK_PERIOD_MS )\r
83 #define niMAX_TX_ATTEMPTS               ( 5 )\r
84 \r
85 /* The length of the queue used to send interrupt status words from the\r
86 interrupt handler to the deferred handler task. */\r
87 #define niINTERRUPT_QUEUE_LENGTH        ( 10 )\r
88 \r
89 /*-----------------------------------------------------------*/\r
90 \r
91 /*\r
92  * A deferred interrupt handler task that processes\r
93  */\r
94 extern void vEMACHandlerTask( void *pvParameters );\r
95 \r
96 /*-----------------------------------------------------------*/\r
97 \r
98 /* The queue used to communicate Ethernet events with the IP task. */\r
99 extern QueueHandle_t xNetworkEventQueue;\r
100 \r
101 /* The semaphore used to wake the deferred interrupt handler task when an Rx\r
102 interrupt is received. */\r
103 SemaphoreHandle_t xEMACRxEventSemaphore = NULL;\r
104 /*-----------------------------------------------------------*/\r
105 \r
106 BaseType_t xNetworkInterfaceInitialise( void )\r
107 {\r
108 BaseType_t xStatus, xReturn;\r
109 extern uint8_t ucMACAddress[ 6 ];\r
110 \r
111         /* Initialise the MAC. */\r
112         vInitEmac();\r
113 \r
114         while( lEMACWaitForLink() != pdPASS )\r
115     {\r
116         vTaskDelay( 20 );\r
117     }\r
118 \r
119         vSemaphoreCreateBinary( xEMACRxEventSemaphore );\r
120         configASSERT( xEMACRxEventSemaphore );\r
121 \r
122         /* The handler task is created at the highest possible priority to\r
123         ensure the interrupt handler can return directly to it. */\r
124         xTaskCreate( vEMACHandlerTask, "EMAC", configMINIMAL_STACK_SIZE, NULL, configMAX_PRIORITIES - 1, NULL );\r
125         xReturn = pdPASS;\r
126 \r
127         return xReturn;\r
128 }\r
129 /*-----------------------------------------------------------*/\r
130 \r
131 BaseType_t xNetworkInterfaceOutput( NetworkBufferDescriptor_t * const pxNetworkBuffer )\r
132 {\r
133 extern void vEMACCopyWrite( uint8_t * pucBuffer, uint16_t usLength );\r
134 \r
135         vEMACCopyWrite( pxNetworkBuffer->pucBuffer, pxNetworkBuffer->xDataLength );\r
136 \r
137         /* Finished with the network buffer. */\r
138         vReleaseNetworkBufferAndDescriptor( pxNetworkBuffer );\r
139 \r
140         return pdTRUE;\r
141 }\r
142 /*-----------------------------------------------------------*/\r
143 \r
144 \r