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