]> git.sur5r.net Git - freertos/blob - FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/SH2A/NetworkInterface.c
Update to MIT licensed FreeRTOS V10.0.0 - see https://www.freertos.org/History.txt
[freertos] / FreeRTOS-Plus / Source / FreeRTOS-Plus-TCP / portable / NetworkInterface / SH2A / NetworkInterface.c
1 /*\r
2  * FreeRTOS+TCP V2.0.0\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. If you wish to use our Amazon\r
14  * FreeRTOS name, please do so in a fair use way that does not cause confusion.\r
15  *\r
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
18  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
19  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
20  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
21  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
22  *\r
23  * http://www.FreeRTOS.org\r
24  * http://aws.amazon.com/freertos\r
25  *\r
26  * 1 tab == 4 spaces!\r
27  */\r
28 \r
29 /* Standard includes. */\r
30 #include <stdint.h>\r
31 \r
32 /* FreeRTOS includes. */\r
33 #include "FreeRTOS.h"\r
34 #include "task.h"\r
35 #include "queue.h"\r
36 #include "semphr.h"\r
37 \r
38 /* FreeRTOS+TCP includes. */\r
39 #include "FreeRTOS_UDP_IP.h"\r
40 #include "FreeRTOS_Sockets.h"\r
41 #include "NetworkBufferManagement.h"\r
42 \r
43 /* Hardware includes. */\r
44 #include "hwEthernet.h"\r
45 \r
46 /* Demo includes. */\r
47 #include "NetworkInterface.h"\r
48 \r
49 #if ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES != 1\r
50         #define ipCONSIDER_FRAME_FOR_PROCESSING( pucEthernetBuffer ) eProcessBuffer\r
51 #else\r
52         #define ipCONSIDER_FRAME_FOR_PROCESSING( pucEthernetBuffer ) eConsiderFrameForProcessing( ( pucEthernetBuffer ) )\r
53 #endif\r
54 \r
55 /* When a packet is ready to be sent, if it cannot be sent immediately then the\r
56 task performing the transmit will block for niTX_BUFFER_FREE_WAIT\r
57 milliseconds.  It will do this a maximum of niMAX_TX_ATTEMPTS before giving\r
58 up. */\r
59 #define niTX_BUFFER_FREE_WAIT   ( ( TickType_t ) 2UL / portTICK_PERIOD_MS )\r
60 #define niMAX_TX_ATTEMPTS               ( 5 )\r
61 \r
62 /* The length of the queue used to send interrupt status words from the\r
63 interrupt handler to the deferred handler task. */\r
64 #define niINTERRUPT_QUEUE_LENGTH        ( 10 )\r
65 \r
66 /*-----------------------------------------------------------*/\r
67 \r
68 /*\r
69  * A deferred interrupt handler task that processes\r
70  */\r
71 extern void vEMACHandlerTask( void *pvParameters );\r
72 \r
73 /*-----------------------------------------------------------*/\r
74 \r
75 /* The queue used to communicate Ethernet events with the IP task. */\r
76 extern QueueHandle_t xNetworkEventQueue;\r
77 \r
78 /* The semaphore used to wake the deferred interrupt handler task when an Rx\r
79 interrupt is received. */\r
80 SemaphoreHandle_t xEMACRxEventSemaphore = NULL;\r
81 /*-----------------------------------------------------------*/\r
82 \r
83 BaseType_t xNetworkInterfaceInitialise( void )\r
84 {\r
85 BaseType_t xStatus, xReturn;\r
86 extern uint8_t ucMACAddress[ 6 ];\r
87 \r
88         /* Initialise the MAC. */\r
89         vInitEmac();\r
90 \r
91         while( lEMACWaitForLink() != pdPASS )\r
92     {\r
93         vTaskDelay( 20 );\r
94     }\r
95 \r
96         vSemaphoreCreateBinary( xEMACRxEventSemaphore );\r
97         configASSERT( xEMACRxEventSemaphore );\r
98 \r
99         /* The handler task is created at the highest possible priority to\r
100         ensure the interrupt handler can return directly to it. */\r
101         xTaskCreate( vEMACHandlerTask, "EMAC", configMINIMAL_STACK_SIZE, NULL, configMAX_PRIORITIES - 1, NULL );\r
102         xReturn = pdPASS;\r
103 \r
104         return xReturn;\r
105 }\r
106 /*-----------------------------------------------------------*/\r
107 \r
108 BaseType_t xNetworkInterfaceOutput( NetworkBufferDescriptor_t * const pxNetworkBuffer )\r
109 {\r
110 extern void vEMACCopyWrite( uint8_t * pucBuffer, uint16_t usLength );\r
111 \r
112         vEMACCopyWrite( pxNetworkBuffer->pucBuffer, pxNetworkBuffer->xDataLength );\r
113 \r
114         /* Finished with the network buffer. */\r
115         vReleaseNetworkBufferAndDescriptor( pxNetworkBuffer );\r
116 \r
117         return pdTRUE;\r
118 }\r
119 /*-----------------------------------------------------------*/\r
120 \r
121 \r