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