]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/SuperH_SH7216_Renesas/RTOSDemo/webserver/EMAC.c
a5ecf0500f5f602dbec8d12765d42686e7660e5b
[freertos] / FreeRTOS / Demo / SuperH_SH7216_Renesas / RTOSDemo / webserver / EMAC.c
1 /*\r
2  * FreeRTOS Kernel V10.1.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.\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 /* Hardware specific includes. */\r
29 #include "iodefine.h"\r
30 #include "typedefine.h"\r
31 #include "hwEthernet.h"\r
32 #include "hwEthernetPhy.h"\r
33 \r
34 /* FreeRTOS includes. */\r
35 #include "FreeRTOS.h"\r
36 #include "task.h"\r
37 #include "semphr.h"\r
38 \r
39 /* uIP includes. */\r
40 #include "net/uip.h"\r
41 \r
42 /* The time to wait between attempts to obtain a free buffer. */\r
43 #define emacBUFFER_WAIT_DELAY_ms                ( 3 / portTICK_PERIOD_MS )\r
44 \r
45 /* The number of times emacBUFFER_WAIT_DELAY_ms should be waited before giving\r
46 up on attempting to obtain a free buffer all together. */\r
47 #define emacBUFFER_WAIT_ATTEMPTS        ( 30 )\r
48 \r
49 /* The number of Rx descriptors. */\r
50 #define emacNUM_RX_DESCRIPTORS  3\r
51 \r
52 /* The number of Tx descriptors.  When using uIP there is not point in having\r
53 more than two. */\r
54 #define emacNUM_TX_BUFFERS      2\r
55 \r
56 /* The total number of EMAC buffers to allocate. */\r
57 #define emacNUM_BUFFERS         ( emacNUM_RX_DESCRIPTORS + emacNUM_TX_BUFFERS )\r
58 \r
59 /* The time to wait for the Tx descriptor to become free. */\r
60 #define emacTX_WAIT_DELAY_ms ( 10 / portTICK_PERIOD_MS )\r
61 \r
62 /* The total number of times to wait emacTX_WAIT_DELAY_ms for the Tx descriptor to\r
63 become free. */\r
64 #define emacTX_WAIT_ATTEMPTS ( 5 )\r
65 \r
66 /* Only Rx end and Tx end interrupts are used by this driver. */\r
67 #define emacTX_END_INTERRUPT    ( 1UL << 21UL )\r
68 #define emacRX_END_INTERRUPT    ( 1UL << 18UL )\r
69 \r
70 /*-----------------------------------------------------------*/\r
71 \r
72 /* The buffers and descriptors themselves. */\r
73 #pragma section RX_DESCR\r
74         ethfifo xRxDescriptors[ emacNUM_RX_DESCRIPTORS ];\r
75 #pragma section TX_DESCR\r
76         ethfifo xTxDescriptors[ emacNUM_TX_BUFFERS ];\r
77 #pragma section _ETHERNET_BUFFERS\r
78         char xEthernetBuffers[ emacNUM_BUFFERS ][ UIP_BUFSIZE ];\r
79 #pragma section\r
80 \r
81 /* Used to indicate which buffers are free and which are in use.  If an index\r
82 contains 0 then the corresponding buffer in xEthernetBuffers is free, otherwise \r
83 the buffer is in use or about to be used. */\r
84 static unsigned char ucBufferInUse[ emacNUM_BUFFERS ];\r
85 \r
86 /*-----------------------------------------------------------*/\r
87 \r
88 /*\r
89  * Initialise both the Rx and Tx descriptors.\r
90  */\r
91 static void prvInitialiseDescriptors( void );\r
92 \r
93 /*\r
94  * Return a pointer to a free buffer within xEthernetBuffers.\r
95  */\r
96 static unsigned char *prvGetNextBuffer( void );\r
97 \r
98 /*\r
99  * Return a buffer to the list of free buffers.\r
100  */\r
101 static void prvReturnBuffer( unsigned char *pucBuffer );\r
102 \r
103 /*\r
104  * Examine the status of the next Rx FIFO to see if it contains new data.\r
105  */\r
106 static unsigned long prvCheckRxFifoStatus( void );\r
107 \r
108 /*\r
109  * Setup the microcontroller for communication with the PHY.\r
110  */\r
111 static void prvSetupPortPinsAndReset( void );\r
112 \r
113 /*\r
114  * Configure the Ethernet interface peripherals.\r
115  */\r
116 static void prvConfigureEtherCAndEDMAC( void );\r
117 \r
118 /*\r
119  * Something has gone wrong with the descriptor usage.  Reset all the buffers\r
120  * and descriptors.\r
121  */\r
122 static void prvResetEverything( void );\r
123 \r
124 /*-----------------------------------------------------------*/\r
125 \r
126 /* Points to the Rx descriptor currently in use. */\r
127 static ethfifo *xCurrentRxDesc = NULL;\r
128 \r
129 /* The buffer used by the uIP stack to both receive and send.  This points to\r
130 one of the Ethernet buffers when its actually in use. */\r
131 unsigned char *uip_buf = NULL;\r
132 \r
133 /*-----------------------------------------------------------*/\r
134 \r
135 void vInitEmac( void )\r
136 {\r
137         /* Setup the SH hardware for MII communications. */\r
138         prvSetupPortPinsAndReset();\r
139         \r
140         /* Set the Rx and Tx descriptors into their initial state. */\r
141         prvInitialiseDescriptors();\r
142 \r
143         /* Set the MAC address into the ETHERC */\r
144         EtherC.MAHR =   ( ( unsigned long ) configMAC_ADDR0 << 24UL ) | \r
145                                         ( ( unsigned long ) configMAC_ADDR1 << 16UL ) | \r
146                                         ( ( unsigned long ) configMAC_ADDR2 << 8UL ) | \r
147                                         ( unsigned long ) configMAC_ADDR3;\r
148                                         \r
149         EtherC.MALR.BIT.MA = ( ( unsigned long ) configMAC_ADDR4 << 8UL ) |\r
150                                                  ( unsigned long ) configMAC_ADDR5;\r
151 \r
152         /* Perform rest of interface hardware configuration. */\r
153         prvConfigureEtherCAndEDMAC();\r
154         \r
155         /* Nothing received yet, so uip_buf points nowhere. */\r
156         uip_buf = NULL;\r
157 \r
158         /* Initialize the PHY */\r
159         phyReset();\r
160 }\r
161 /*-----------------------------------------------------------*/\r
162 \r
163 void vEMACWrite( void )\r
164 {\r
165 long x;\r
166 \r
167         /* Wait until the second transmission of the last packet has completed. */\r
168         for( x = 0; x < emacTX_WAIT_ATTEMPTS; x++ )\r
169         {\r
170                 if( ( xTxDescriptors[ 1 ].status & ACT ) != 0 )\r
171                 {\r
172                         /* Descriptor is still active. */\r
173                         vTaskDelay( emacTX_WAIT_DELAY_ms );\r
174                 }\r
175                 else\r
176                 {\r
177                         break;\r
178                 }\r
179         }\r
180         \r
181         /* Is the descriptor free after waiting for it? */\r
182         if( ( xTxDescriptors[ 1 ].status & ACT ) != 0 )\r
183         {\r
184                 /* Something has gone wrong. */\r
185                 prvResetEverything();\r
186         }\r
187         \r
188         /* Setup both descriptors to transmit the frame. */\r
189         xTxDescriptors[ 0 ].buf_p = ( char * ) uip_buf;\r
190         xTxDescriptors[ 0 ].bufsize = uip_len;  \r
191         xTxDescriptors[ 1 ].buf_p = ( char * ) uip_buf;\r
192         xTxDescriptors[ 1 ].bufsize = uip_len;\r
193 \r
194         /* uip_buf is being sent by the Tx descriptor.  Allocate a new buffer\r
195         for use by the stack. */\r
196         uip_buf = prvGetNextBuffer();\r
197 \r
198         /* Clear previous settings and go. */\r
199         xTxDescriptors[0].status &= ~( FP1 | FP0 );\r
200         xTxDescriptors[0].status |= ( FP1 | FP0 | ACT );\r
201         xTxDescriptors[1].status &= ~( FP1 | FP0 );\r
202         xTxDescriptors[1].status |= ( FP1 | FP0 | ACT );\r
203 \r
204         EDMAC.EDTRR.LONG = 0x00000001;\r
205 }\r
206 /*-----------------------------------------------------------*/\r
207 \r
208 unsigned long ulEMACRead( void )\r
209 {\r
210 unsigned long ulBytesReceived;\r
211 \r
212         ulBytesReceived = prvCheckRxFifoStatus();\r
213 \r
214         if( ulBytesReceived > 0 )\r
215         {\r
216                 xCurrentRxDesc->status &= ~( FP1 | FP0 );\r
217                 xCurrentRxDesc->status |= ACT;                  \r
218 \r
219                 if( EDMAC.EDRRR.LONG == 0x00000000L )\r
220                 {\r
221                         /* Restart Ethernet if it has stopped */\r
222                         EDMAC.EDRRR.LONG = 0x00000001L;\r
223                 }\r
224 \r
225                 /* Mark the pxDescriptor buffer as free as uip_buf is going to be set to\r
226                 the buffer that contains the received data. */\r
227                 prvReturnBuffer( uip_buf );\r
228                 \r
229                 uip_buf = ( void * ) xCurrentRxDesc->buf_p;\r
230 \r
231                 /* Move onto the next buffer in the ring. */\r
232                 xCurrentRxDesc = xCurrentRxDesc->next;\r
233         }\r
234 \r
235         return ulBytesReceived;\r
236 }\r
237 /*-----------------------------------------------------------*/\r
238 \r
239 long lEMACWaitForLink( void )\r
240 {\r
241 long lReturn;\r
242 \r
243         /* Set the link status. */\r
244         switch( phyStatus() )\r
245         {\r
246                 /* Half duplex link */\r
247                 case PHY_LINK_100H:\r
248                 case PHY_LINK_10H:\r
249                                                                 EtherC.ECMR.BIT.DM = 0;\r
250                                                                 lReturn = pdPASS;\r
251                                                                 break;\r
252 \r
253                 /* Full duplex link */\r
254                 case PHY_LINK_100F:\r
255                 case PHY_LINK_10F:\r
256                                                                 EtherC.ECMR.BIT.DM = 1;\r
257                                                                 lReturn = pdPASS;\r
258                                                                 break;\r
259 \r
260                 default:\r
261                                                                 lReturn = pdFAIL;\r
262                                                                 break;\r
263         }\r
264 \r
265         if( lReturn == pdPASS )\r
266         {\r
267                 /* Enable receive and transmit. */\r
268                 EtherC.ECMR.BIT.RE = 1;\r
269                 EtherC.ECMR.BIT.TE = 1;\r
270 \r
271                 /* Enable EDMAC receive */\r
272                 EDMAC.EDRRR.LONG = 0x1;\r
273         }\r
274         \r
275         return lReturn;\r
276 }\r
277 /*-----------------------------------------------------------*/\r
278 \r
279 static void prvInitialiseDescriptors( void )\r
280 {\r
281 ethfifo *pxDescriptor;\r
282 long x;\r
283 \r
284         for( x = 0; x < emacNUM_BUFFERS; x++ )\r
285         {\r
286                 /* Ensure none of the buffers are shown as in use at the start. */\r
287                 ucBufferInUse[ x ] = pdFALSE;\r
288         }\r
289 \r
290         /* Initialise the Rx descriptors. */\r
291         for( x = 0; x < emacNUM_RX_DESCRIPTORS; x++ )\r
292         {\r
293                 pxDescriptor = &( xRxDescriptors[ x ] );\r
294                 pxDescriptor->buf_p = &( xEthernetBuffers[ x ][ 0 ] );\r
295 \r
296                 pxDescriptor->bufsize = UIP_BUFSIZE;\r
297                 pxDescriptor->size = 0;\r
298                 pxDescriptor->status = ACT;\r
299                 pxDescriptor->next = &xRxDescriptors[ x + 1 ];  \r
300                 \r
301                 /* Mark this buffer as in use. */\r
302                 ucBufferInUse[ x ] = pdTRUE;\r
303         }\r
304 \r
305         /* The last descriptor points back to the start. */\r
306         pxDescriptor->status |= DL;\r
307         pxDescriptor->next = &xRxDescriptors[ 0 ];\r
308         \r
309         /* Initialise the Tx descriptors. */\r
310         for( x = 0; x < emacNUM_TX_BUFFERS; x++ )\r
311         {\r
312                 pxDescriptor = &( xTxDescriptors[ x ] );\r
313                 \r
314                 /* A buffer is not allocated to the Tx descriptor until a send is\r
315                 actually required. */\r
316                 pxDescriptor->buf_p = NULL;\r
317 \r
318                 pxDescriptor->bufsize = UIP_BUFSIZE;\r
319                 pxDescriptor->size = 0;\r
320                 pxDescriptor->status = 0;\r
321                 pxDescriptor->next = &xTxDescriptors[ x + 1 ];  \r
322         }\r
323 \r
324         /* The last descriptor points back to the start. */\r
325         pxDescriptor->status |= DL;\r
326         pxDescriptor->next = &( xTxDescriptors[ 0 ] );\r
327         \r
328         /* Use the first Rx descriptor to start with. */\r
329         xCurrentRxDesc = &( xRxDescriptors[ 0 ] );\r
330 }\r
331 /*-----------------------------------------------------------*/\r
332 \r
333 static unsigned char *prvGetNextBuffer( void )\r
334 {\r
335 long x;\r
336 unsigned char *pucReturn = NULL;\r
337 unsigned long ulAttempts = 0;\r
338 \r
339         while( pucReturn == NULL )\r
340         {\r
341                 /* Look through the buffers to find one that is not in use by\r
342                 anything else. */\r
343                 for( x = 0; x < emacNUM_BUFFERS; x++ )\r
344                 {\r
345                         if( ucBufferInUse[ x ] == pdFALSE )\r
346                         {\r
347                                 ucBufferInUse[ x ] = pdTRUE;\r
348                                 pucReturn = ( unsigned char * ) &( xEthernetBuffers[ x ][ 0 ] );\r
349                                 break;\r
350                         }\r
351                 }\r
352 \r
353                 /* Was a buffer found? */\r
354                 if( pucReturn == NULL )\r
355                 {\r
356                         ulAttempts++;\r
357 \r
358                         if( ulAttempts >= emacBUFFER_WAIT_ATTEMPTS )\r
359                         {\r
360                                 break;\r
361                         }\r
362 \r
363                         /* Wait then look again. */\r
364                         vTaskDelay( emacBUFFER_WAIT_DELAY_ms );\r
365                 }\r
366         }\r
367 \r
368         return pucReturn;\r
369 }\r
370 /*-----------------------------------------------------------*/\r
371 \r
372 static void prvReturnBuffer( unsigned char *pucBuffer )\r
373 {\r
374 unsigned long ul;\r
375 \r
376         /* Return a buffer to the pool of free buffers. */\r
377         for( ul = 0; ul < emacNUM_BUFFERS; ul++ )\r
378         {\r
379                 if( &( xEthernetBuffers[ ul ][ 0 ] ) == ( void * ) pucBuffer )\r
380                 {\r
381                         ucBufferInUse[ ul ] = pdFALSE;\r
382                         break;\r
383                 }\r
384         }\r
385 }\r
386 /*-----------------------------------------------------------*/\r
387 \r
388 static void prvResetEverything( void )\r
389 {\r
390         /* Temporary code just to see if this gets called.  This function has not\r
391         been implemented. */\r
392         portDISABLE_INTERRUPTS();\r
393         for( ;; );\r
394 }\r
395 /*-----------------------------------------------------------*/\r
396 \r
397 static unsigned long prvCheckRxFifoStatus( void )\r
398 {\r
399 unsigned long ulReturn = 0;\r
400 \r
401         if( ( xCurrentRxDesc->status & ACT ) != 0 )\r
402         {\r
403                 /* Current descriptor is still active. */\r
404         }\r
405         else if( ( xCurrentRxDesc->status & FE ) != 0 )\r
406         {\r
407                 /* Frame error.  Clear the error. */\r
408                 xCurrentRxDesc->status &= ~( FP1 | FP0 | FE );\r
409                 xCurrentRxDesc->status &= ~( RMAF | RRF | RTLF | RTSF | PRE | CERF );\r
410                 xCurrentRxDesc->status |= ACT;\r
411                 xCurrentRxDesc = xCurrentRxDesc->next;\r
412 \r
413                 if( EDMAC.EDRRR.LONG == 0x00000000UL )\r
414                 {\r
415                         /* Restart Ethernet if it has stopped. */\r
416                         EDMAC.EDRRR.LONG = 0x00000001UL;\r
417                 }       \r
418         }\r
419         else\r
420         {\r
421                 /* The descriptor contains a frame.  Because of the size of the buffers\r
422                 the frame should always be complete. */\r
423                 if( (xCurrentRxDesc->status & FP0) == FP0 )\r
424                 {\r
425                         ulReturn = xCurrentRxDesc->size;\r
426                 }\r
427                 else\r
428                 {\r
429                         /* Do not expect to get here. */\r
430                         prvResetEverything();\r
431                 }\r
432         }\r
433         \r
434         return ulReturn;\r
435 }\r
436 /*-----------------------------------------------------------*/\r
437 \r
438 static void prvSetupPortPinsAndReset( void )\r
439 {\r
440         /* Initialisation code taken from Renesas example project. */\r
441         \r
442         PFC.PACRL4.BIT.PA12MD = 0x7;            /* Set TX_CLK input      (EtherC) */\r
443         PFC.PACRL3.BIT.PA11MD = 0x7;            /* Set TX_EN output      (EtherC) */\r
444         PFC.PACRL3.BIT.PA10MD = 0x7;            /* Set MII_TXD0 output   (EtherC) */\r
445         PFC.PACRL3.BIT.PA9MD  = 0x7;            /* Set MII_TXD1 output   (EtherC) */\r
446         PFC.PACRL3.BIT.PA8MD  = 0x7;            /* Set MII_TXD2 output   (EtherC) */\r
447         PFC.PACRL2.BIT.PA7MD  = 0x7;            /* Set MII_TXD3 output   (EtherC) */\r
448         PFC.PACRL2.BIT.PA6MD  = 0x7;            /* Set TX_ER output      (EtherC) */\r
449         PFC.PDCRH4.BIT.PD31MD = 0x7;            /* Set RX_DV input       (EtherC) */\r
450         PFC.PDCRH4.BIT.PD30MD = 0x7;            /* Set RX_ER input       (EtherC) */\r
451         PFC.PDCRH4.BIT.PD29MD = 0x7;            /* Set MII_RXD3 input    (EtherC) */\r
452         PFC.PDCRH4.BIT.PD28MD = 0x7;            /* Set MII_RXD2 input    (EtherC) */\r
453         PFC.PDCRH3.BIT.PD27MD = 0x7;            /* Set MII_RXD1 input    (EtherC) */\r
454         PFC.PDCRH3.BIT.PD26MD = 0x7;            /* Set MII_RXD0 input    (EtherC) */\r
455         PFC.PDCRH3.BIT.PD25MD = 0x7;            /* Set RX_CLK input      (EtherC) */\r
456         PFC.PDCRH3.BIT.PD24MD = 0x7;            /* Set CRS input         (EtherC) */\r
457         PFC.PDCRH2.BIT.PD23MD = 0x7;            /* Set COL input         (EtherC) */\r
458         PFC.PDCRH2.BIT.PD22MD = 0x7;            /* Set WOL output        (EtherC) */\r
459         PFC.PDCRH2.BIT.PD21MD = 0x7;            /* Set EXOUT output      (EtherC) */\r
460         PFC.PDCRH2.BIT.PD20MD = 0x7;            /* Set MDC output        (EtherC) */\r
461         PFC.PDCRH1.BIT.PD19MD = 0x7;            /* Set LINKSTA input     (EtherC) */\r
462         PFC.PDCRH1.BIT.PD18MD = 0x7;            /* Set MDIO input/output (EtherC) */\r
463         \r
464         STB.CR4.BIT._ETHER = 0x0;       \r
465         EDMAC.EDMR.BIT.SWR = 1; \r
466         \r
467         /* Crude wait for reset to complete. */\r
468         vTaskDelay( 500 / portTICK_PERIOD_MS ); \r
469 }\r
470 /*-----------------------------------------------------------*/\r
471 \r
472 static void prvConfigureEtherCAndEDMAC( void )\r
473 {\r
474         /* Initialisation code taken from Renesas example project. */\r
475         \r
476         /* TODO:    Check   bit 5   */\r
477         EtherC.ECSR.LONG = 0x00000037;                          /* Clear all EtherC statuS BFR, PSRTO, LCHNG, MPD, ICD */\r
478 \r
479         /* TODO:    Check   bit 5   */\r
480         EtherC.ECSIPR.LONG = 0x00000020;                        /* Disable EtherC status change interrupt */\r
481         EtherC.RFLR.LONG = 1518;                                        /* Ether payload is 1500+ CRC */\r
482         EtherC.IPGR.LONG = 0x00000014;                          /* Intergap is 96-bit time */\r
483 \r
484         /* EDMAC */\r
485         EDMAC.EESR.LONG = 0x47FF0F9F;                           /* Clear all EtherC and EDMAC status bits */\r
486         EDMAC.RDLAR = ( void * ) xCurrentRxDesc;        /* Initialaize Rx Descriptor List Address */\r
487         EDMAC.TDLAR = &( xTxDescriptors[ 0 ] );         /* Initialaize Tx Descriptor List Address */\r
488         EDMAC.TRSCER.LONG = 0x00000000;                         /* Copy-back status is RFE & TFE only   */\r
489         EDMAC.TFTR.LONG = 0x00000000;                           /* Threshold of Tx_FIFO */\r
490         EDMAC.FDR.LONG = 0x00000000;                            /* Transmit fifo & receive fifo is 256 bytes */\r
491         EDMAC.RMCR.LONG = 0x00000003;                           /* Receive function is normal mode(continued) */\r
492 \r
493         /* Set the EDMAC interrupt priority - the interrupt priority must be\r
494         configKERNEL_INTERRUPT_PRIORITY no matter which peripheral is used to \r
495         generate the tick interrupt. */\r
496         INTC.IPR19.BIT._EDMAC = portKERNEL_INTERRUPT_PRIORITY;\r
497         EDMAC.EESIPR.LONG = emacTX_END_INTERRUPT | emacRX_END_INTERRUPT;        /* Enable Rx and Tx end interrupts. */\r
498 \r
499         /* Clear the interrupt flag. */\r
500         CMT0.CMCSR.BIT.CMF = 0;\r
501 }\r
502 /*-----------------------------------------------------------*/\r
503 \r
504 void vEMAC_ISR_Handler( void )\r
505 {\r
506 unsigned long ul = EDMAC.EESR.LONG;\r
507 long lHigherPriorityTaskWoken = pdFALSE;\r
508 extern SemaphoreHandle_t xEMACSemaphore;\r
509 static long ulTxEndInts = 0;\r
510 \r
511         /* Has a Tx end occurred? */\r
512         if( ul & emacTX_END_INTERRUPT )\r
513         {\r
514                 ++ulTxEndInts;\r
515                 if( ulTxEndInts >= 2 )\r
516                 {\r
517                         /* Only return the buffer to the pool once both Txes have completed. */\r
518                         prvReturnBuffer( ( void * ) xTxDescriptors[ 0 ].buf_p );\r
519                         ulTxEndInts = 0;\r
520                 }\r
521                 EDMAC.EESR.LONG = emacTX_END_INTERRUPT;\r
522         }\r
523 \r
524         /* Has an Rx end occurred? */\r
525         if( ul & emacRX_END_INTERRUPT )\r
526         {\r
527                 /* Make sure the Ethernet task is not blocked waiting for a packet. */\r
528                 xSemaphoreGiveFromISR( xEMACSemaphore, &lHigherPriorityTaskWoken );\r
529                 portYIELD_FROM_ISR( lHigherPriorityTaskWoken );\r
530                 EDMAC.EESR.LONG = emacRX_END_INTERRUPT;\r
531         }\r
532 }\r