]> git.sur5r.net Git - freertos/blob - FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/SH2A/NetworkInterface.c
Roll up the minor changes checked into svn since V10.0.0 into new V10.0.1 ready for...
[freertos] / FreeRTOS-Plus / Source / FreeRTOS-Plus-TCP / portable / NetworkInterface / SH2A / NetworkInterface.c
1 /*\r
2  * FreeRTOS+TCP V2.0.1\r
3  * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
4  *\r
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
6  * this software and associated documentation files (the "Software"), to deal in\r
7  * the Software without restriction, including without limitation the rights to\r
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
9  * the Software, and to permit persons to whom the Software is furnished to do so,\r
10  * subject to the following conditions:\r
11  *\r
12  * The above copyright notice and this permission notice shall be included in all\r
13  * copies or substantial portions of the Software.\r
14  *\r
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
17  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
19  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
21  *\r
22  * http://www.FreeRTOS.org\r
23  * http://aws.amazon.com/freertos\r
24  *\r
25  * 1 tab == 4 spaces!\r
26  */\r
27 \r
28 /* Standard includes. */\r
29 #include <stdint.h>\r
30 \r
31 /* FreeRTOS includes. */\r
32 #include "FreeRTOS.h"\r
33 #include "task.h"\r
34 #include "queue.h"\r
35 #include "semphr.h"\r
36 \r
37 /* FreeRTOS+TCP includes. */\r
38 #include "FreeRTOS_UDP_IP.h"\r
39 #include "FreeRTOS_Sockets.h"\r
40 #include "NetworkBufferManagement.h"\r
41 \r
42 /* Hardware includes. */\r
43 #include "hwEthernet.h"\r
44 \r
45 /* Demo includes. */\r
46 #include "NetworkInterface.h"\r
47 \r
48 #if ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES != 1\r
49         #define ipCONSIDER_FRAME_FOR_PROCESSING( pucEthernetBuffer ) eProcessBuffer\r
50 #else\r
51         #define ipCONSIDER_FRAME_FOR_PROCESSING( pucEthernetBuffer ) eConsiderFrameForProcessing( ( pucEthernetBuffer ) )\r
52 #endif\r
53 \r
54 /* When a packet is ready to be sent, if it cannot be sent immediately then the\r
55 task performing the transmit will block for niTX_BUFFER_FREE_WAIT\r
56 milliseconds.  It will do this a maximum of niMAX_TX_ATTEMPTS before giving\r
57 up. */\r
58 #define niTX_BUFFER_FREE_WAIT   ( ( TickType_t ) 2UL / portTICK_PERIOD_MS )\r
59 #define niMAX_TX_ATTEMPTS               ( 5 )\r
60 \r
61 /* The length of the queue used to send interrupt status words from the\r
62 interrupt handler to the deferred handler task. */\r
63 #define niINTERRUPT_QUEUE_LENGTH        ( 10 )\r
64 \r
65 /*-----------------------------------------------------------*/\r
66 \r
67 /*\r
68  * A deferred interrupt handler task that processes\r
69  */\r
70 extern void vEMACHandlerTask( void *pvParameters );\r
71 \r
72 /*-----------------------------------------------------------*/\r
73 \r
74 /* The queue used to communicate Ethernet events with the IP task. */\r
75 extern QueueHandle_t xNetworkEventQueue;\r
76 \r
77 /* The semaphore used to wake the deferred interrupt handler task when an Rx\r
78 interrupt is received. */\r
79 SemaphoreHandle_t xEMACRxEventSemaphore = NULL;\r
80 /*-----------------------------------------------------------*/\r
81 \r
82 BaseType_t xNetworkInterfaceInitialise( void )\r
83 {\r
84 BaseType_t xStatus, xReturn;\r
85 extern uint8_t ucMACAddress[ 6 ];\r
86 \r
87         /* Initialise the MAC. */\r
88         vInitEmac();\r
89 \r
90         while( lEMACWaitForLink() != pdPASS )\r
91     {\r
92         vTaskDelay( 20 );\r
93     }\r
94 \r
95         vSemaphoreCreateBinary( xEMACRxEventSemaphore );\r
96         configASSERT( xEMACRxEventSemaphore );\r
97 \r
98         /* The handler task is created at the highest possible priority to\r
99         ensure the interrupt handler can return directly to it. */\r
100         xTaskCreate( vEMACHandlerTask, "EMAC", configMINIMAL_STACK_SIZE, NULL, configMAX_PRIORITIES - 1, NULL );\r
101         xReturn = pdPASS;\r
102 \r
103         return xReturn;\r
104 }\r
105 /*-----------------------------------------------------------*/\r
106 \r
107 BaseType_t xNetworkInterfaceOutput( NetworkBufferDescriptor_t * const pxNetworkBuffer )\r
108 {\r
109 extern void vEMACCopyWrite( uint8_t * pucBuffer, uint16_t usLength );\r
110 \r
111         vEMACCopyWrite( pxNetworkBuffer->pucBuffer, pxNetworkBuffer->xDataLength );\r
112 \r
113         /* Finished with the network buffer. */\r
114         vReleaseNetworkBufferAndDescriptor( pxNetworkBuffer );\r
115 \r
116         return pdTRUE;\r
117 }\r
118 /*-----------------------------------------------------------*/\r
119 \r
120 \r