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