]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/RX600_RX62N-RDK_Renesas/RTOSDemo/webserver/EMAC.c
Update version numbers in preparation for V8.2.0 release candidate 1.
[freertos] / FreeRTOS / Demo / RX600_RX62N-RDK_Renesas / RTOSDemo / webserver / EMAC.c
1 /*\r
2     FreeRTOS V8.2.0rc1 - Copyright (C) 2014 Real Time Engineers Ltd.\r
3     All rights reserved\r
4 \r
5     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
6 \r
7     This file is part of the FreeRTOS distribution.\r
8 \r
9     FreeRTOS is free software; you can redistribute it and/or modify it under\r
10     the terms of the GNU General Public License (version 2) as published by the\r
11     Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.\r
12 \r
13     >>!   NOTE: The modification to the GPL is included to allow you to     !<<\r
14     >>!   distribute a combined work that includes FreeRTOS without being   !<<\r
15     >>!   obliged to provide the source code for proprietary components     !<<\r
16     >>!   outside of the FreeRTOS kernel.                                   !<<\r
17 \r
18     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
19     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
20     FOR A PARTICULAR PURPOSE.  Full license text is available on the following\r
21     link: http://www.freertos.org/a00114.html\r
22 \r
23     1 tab == 4 spaces!\r
24 \r
25     ***************************************************************************\r
26      *                                                                       *\r
27      *    Having a problem?  Start by reading the FAQ "My application does   *\r
28      *    not run, what could be wrong?".  Have you defined configASSERT()?  *\r
29      *                                                                       *\r
30      *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
31      *                                                                       *\r
32     ***************************************************************************\r
33 \r
34     ***************************************************************************\r
35      *                                                                       *\r
36      *    FreeRTOS provides completely free yet professionally developed,    *\r
37      *    robust, strictly quality controlled, supported, and cross          *\r
38      *    platform software that is more than just the market leader, it     *\r
39      *    is the industry's de facto standard.                               *\r
40      *                                                                       *\r
41      *    Help yourself get started quickly while simultaneously helping     *\r
42      *    to support the FreeRTOS project by purchasing a FreeRTOS           *\r
43      *    tutorial book, reference manual, or both:                          *\r
44      *    http://www.FreeRTOS.org/Documentation                              *\r
45      *                                                                       *\r
46     ***************************************************************************\r
47 \r
48     ***************************************************************************\r
49      *                                                                       *\r
50      *   Investing in training allows your team to be as productive as       *\r
51      *   possible as early as possible, lowering your overall development    *\r
52      *   cost, and enabling you to bring a more robust product to market     *\r
53      *   earlier than would otherwise be possible.  Richard Barry is both    *\r
54      *   the architect and key author of FreeRTOS, and so also the world's   *\r
55      *   leading authority on what is the world's most popular real time     *\r
56      *   kernel for deeply embedded MCU designs.  Obtaining your training    *\r
57      *   from Richard ensures your team will gain directly from his in-depth *\r
58      *   product knowledge and years of usage experience.  Contact Real Time *\r
59      *   Engineers Ltd to enquire about the FreeRTOS Masterclass, presented  *\r
60      *   by Richard Barry:  http://www.FreeRTOS.org/contact\r
61      *                                                                       *\r
62     ***************************************************************************\r
63 \r
64     ***************************************************************************\r
65      *                                                                       *\r
66      *    You are receiving this top quality software for free.  Please play *\r
67      *    fair and reciprocate by reporting any suspected issues and         *\r
68      *    participating in the community forum:                              *\r
69      *    http://www.FreeRTOS.org/support                                    *\r
70      *                                                                       *\r
71      *    Thank you!                                                         *\r
72      *                                                                       *\r
73     ***************************************************************************\r
74 \r
75     http://www.FreeRTOS.org - Documentation, books, training, latest versions,\r
76     license and Real Time Engineers Ltd. contact details.\r
77 \r
78     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
79     including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
80     compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
81 \r
82     http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.\r
83     Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.\r
84 \r
85     http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High\r
86     Integrity Systems ltd. to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
87     licenses offer ticketed support, indemnification and commercial middleware.\r
88 \r
89     http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
90     engineered and independently SIL3 certified version for use in safety and\r
91     mission critical applications that require provable dependability.\r
92 \r
93     1 tab == 4 spaces!\r
94 */\r
95 \r
96 /* Hardware specific includes. */\r
97 #include "iodefine.h"\r
98 #include "typedefine.h"\r
99 #include "r_ether.h"\r
100 #include "phy.h"\r
101 \r
102 /* FreeRTOS includes. */\r
103 #include "FreeRTOS.h"\r
104 #include "task.h"\r
105 #include "semphr.h"\r
106 \r
107 /* uIP includes. */\r
108 #include "net/uip.h"\r
109 \r
110 /* The time to wait between attempts to obtain a free buffer. */\r
111 #define emacBUFFER_WAIT_DELAY_ms                ( 3 / portTICK_PERIOD_MS )\r
112 \r
113 /* The number of times emacBUFFER_WAIT_DELAY_ms should be waited before giving\r
114 up on attempting to obtain a free buffer all together. */\r
115 #define emacBUFFER_WAIT_ATTEMPTS        ( 30 )\r
116 \r
117 /* The number of Rx descriptors. */\r
118 #define emacNUM_RX_DESCRIPTORS  8\r
119 \r
120 /* The number of Tx descriptors.  When using uIP there is not point in having\r
121 more than two. */\r
122 #define emacNUM_TX_BUFFERS      2\r
123 \r
124 /* The total number of EMAC buffers to allocate. */\r
125 #define emacNUM_BUFFERS         ( emacNUM_RX_DESCRIPTORS + emacNUM_TX_BUFFERS )\r
126 \r
127 /* The time to wait for the Tx descriptor to become free. */\r
128 #define emacTX_WAIT_DELAY_ms ( 10 / portTICK_PERIOD_MS )\r
129 \r
130 /* The total number of times to wait emacTX_WAIT_DELAY_ms for the Tx descriptor to\r
131 become free. */\r
132 #define emacTX_WAIT_ATTEMPTS ( 50 )\r
133 \r
134 /* Only Rx end and Tx end interrupts are used by this driver. */\r
135 #define emacTX_END_INTERRUPT    ( 1UL << 21UL )\r
136 #define emacRX_END_INTERRUPT    ( 1UL << 18UL )\r
137 \r
138 /*-----------------------------------------------------------*/\r
139 \r
140 /* The buffers and descriptors themselves.  */\r
141 #pragma section _RX_DESC\r
142         volatile ethfifo xRxDescriptors[ emacNUM_RX_DESCRIPTORS ];\r
143 #pragma section _TX_DESC\r
144         volatile ethfifo xTxDescriptors[ emacNUM_TX_BUFFERS ];\r
145 #pragma section _ETHERNET_BUFFERS\r
146         struct\r
147         {\r
148                 unsigned long ulAlignmentVariable;\r
149                 char cBuffer[ emacNUM_BUFFERS ][ UIP_BUFSIZE ];\r
150         } xEthernetBuffers;\r
151 #pragma section\r
152 \r
153 \r
154 \r
155 \r
156 /* Used to indicate which buffers are free and which are in use.  If an index\r
157 contains 0 then the corresponding buffer in xEthernetBuffers is free, otherwise \r
158 the buffer is in use or about to be used. */\r
159 static unsigned char ucBufferInUse[ emacNUM_BUFFERS ];\r
160 \r
161 /*-----------------------------------------------------------*/\r
162 \r
163 /*\r
164  * Initialise both the Rx and Tx descriptors.\r
165  */\r
166 static void prvInitialiseDescriptors( void );\r
167 \r
168 /*\r
169  * Return a pointer to a free buffer within xEthernetBuffers.\r
170  */\r
171 static unsigned char *prvGetNextBuffer( void );\r
172 \r
173 /*\r
174  * Return a buffer to the list of free buffers.\r
175  */\r
176 static void prvReturnBuffer( unsigned char *pucBuffer );\r
177 \r
178 /*\r
179  * Examine the status of the next Rx FIFO to see if it contains new data.\r
180  */\r
181 static unsigned long prvCheckRxFifoStatus( void );\r
182 \r
183 /*\r
184  * Setup the microcontroller for communication with the PHY.\r
185  */\r
186 static void prvResetMAC( void );\r
187 \r
188 /*\r
189  * Configure the Ethernet interface peripherals.\r
190  */\r
191 static void prvConfigureEtherCAndEDMAC( void );\r
192 \r
193 /*\r
194  * Something has gone wrong with the descriptor usage.  Reset all the buffers\r
195  * and descriptors.\r
196  */\r
197 static void prvResetEverything( void );\r
198 \r
199 /*-----------------------------------------------------------*/\r
200 \r
201 /* Points to the Rx descriptor currently in use. */\r
202 static ethfifo *pxCurrentRxDesc = NULL;\r
203 \r
204 /* The buffer used by the uIP stack to both receive and send.  This points to\r
205 one of the Ethernet buffers when its actually in use. */\r
206 unsigned char *uip_buf = NULL;\r
207 \r
208 /*-----------------------------------------------------------*/\r
209 \r
210 void vInitEmac( void )\r
211 {\r
212         /* Software reset. */\r
213         prvResetMAC();\r
214         \r
215         /* Set the Rx and Tx descriptors into their initial state. */\r
216         prvInitialiseDescriptors();\r
217 \r
218         /* Set the MAC address into the ETHERC */\r
219         ETHERC.MAHR =   ( ( unsigned long ) configMAC_ADDR0 << 24UL ) | \r
220                                         ( ( unsigned long ) configMAC_ADDR1 << 16UL ) | \r
221                                         ( ( unsigned long ) configMAC_ADDR2 << 8UL ) | \r
222                                         ( unsigned long ) configMAC_ADDR3;\r
223                                         \r
224         ETHERC.MALR.BIT.MA = ( ( unsigned long ) configMAC_ADDR4 << 8UL ) |\r
225                                                  ( unsigned long ) configMAC_ADDR5;\r
226 \r
227         /* Perform rest of interface hardware configuration. */\r
228         prvConfigureEtherCAndEDMAC();\r
229         \r
230         /* Nothing received yet, so uip_buf points nowhere. */\r
231         uip_buf = NULL;\r
232 \r
233         /* Initialize the PHY */\r
234         phy_init();\r
235 }\r
236 /*-----------------------------------------------------------*/\r
237 \r
238 void vEMACWrite( void )\r
239 {\r
240 long x;\r
241 \r
242         /* Wait until the second transmission of the last packet has completed. */\r
243         for( x = 0; x < emacTX_WAIT_ATTEMPTS; x++ )\r
244         {\r
245                 if( ( xTxDescriptors[ 1 ].status & ACT ) != 0 )\r
246                 {\r
247                         /* Descriptor is still active. */\r
248                         vTaskDelay( emacTX_WAIT_DELAY_ms );\r
249                 }\r
250                 else\r
251                 {\r
252                         break;\r
253                 }\r
254         }\r
255         \r
256         /* Is the descriptor free after waiting for it? */\r
257         if( ( xTxDescriptors[ 1 ].status & ACT ) != 0 )\r
258         {\r
259                 /* Something has gone wrong. */\r
260                 prvResetEverything();\r
261         }\r
262         \r
263         /* Setup both descriptors to transmit the frame. */\r
264         xTxDescriptors[ 0 ].buf_p = ( char * ) uip_buf;\r
265         xTxDescriptors[ 0 ].bufsize = uip_len;  \r
266         xTxDescriptors[ 1 ].buf_p = ( char * ) uip_buf;\r
267         xTxDescriptors[ 1 ].bufsize = uip_len;\r
268 \r
269         /* uip_buf is being sent by the Tx descriptor.  Allocate a new buffer\r
270         for use by the stack. */\r
271         uip_buf = prvGetNextBuffer();\r
272 \r
273         /* Clear previous settings and go. */\r
274         xTxDescriptors[0].status &= ~( FP1 | FP0 );\r
275         xTxDescriptors[0].status |= ( FP1 | FP0 | ACT );\r
276         xTxDescriptors[1].status &= ~( FP1 | FP0 );\r
277         xTxDescriptors[1].status |= ( FP1 | FP0 | ACT );\r
278 \r
279         EDMAC.EDTRR.LONG = 0x00000001;\r
280 }\r
281 /*-----------------------------------------------------------*/\r
282 \r
283 unsigned long ulEMACRead( void )\r
284 {\r
285 unsigned long ulBytesReceived;\r
286 \r
287         ulBytesReceived = prvCheckRxFifoStatus();\r
288 \r
289         if( ulBytesReceived > 0 )\r
290         {\r
291                 /* Mark the pxDescriptor buffer as free as uip_buf is going to be set to\r
292                 the buffer that contains the received data. */\r
293                 prvReturnBuffer( uip_buf );\r
294 \r
295                 /* Point uip_buf to the data about ot be processed. */\r
296                 uip_buf = ( void * ) pxCurrentRxDesc->buf_p;\r
297                 \r
298                 /* Allocate a new buffer to the descriptor, as uip_buf is now using it's\r
299                 old descriptor. */\r
300                 pxCurrentRxDesc->buf_p = prvGetNextBuffer();\r
301 \r
302                 /* Prepare the descriptor to go again. */\r
303                 pxCurrentRxDesc->status &= ~( FP1 | FP0 );\r
304                 pxCurrentRxDesc->status |= ACT;\r
305 \r
306                 /* Move onto the next buffer in the ring. */\r
307                 pxCurrentRxDesc = pxCurrentRxDesc->next;\r
308                 \r
309                 if( EDMAC.EDRRR.LONG == 0x00000000L )\r
310                 {\r
311                         /* Restart Ethernet if it has stopped */\r
312                         EDMAC.EDRRR.LONG = 0x00000001L;\r
313                 }\r
314         }\r
315 \r
316         return ulBytesReceived;\r
317 }\r
318 /*-----------------------------------------------------------*/\r
319 \r
320 long lEMACWaitForLink( void )\r
321 {\r
322 long lReturn;\r
323 \r
324         /* Set the link status. */\r
325         switch( phy_set_autonegotiate() )\r
326         {\r
327                 /* Half duplex link */\r
328                 case PHY_LINK_100H:\r
329                                                                 ETHERC.ECMR.BIT.DM = 0;\r
330                                                                 ETHERC.ECMR.BIT.RTM = 1;\r
331                                                                 lReturn = pdPASS;\r
332                                                                 break;\r
333 \r
334                 case PHY_LINK_10H:\r
335                                                                 ETHERC.ECMR.BIT.DM = 0;\r
336                                                                 ETHERC.ECMR.BIT.RTM = 0;\r
337                                                                 lReturn = pdPASS;\r
338                                                                 break;\r
339 \r
340 \r
341                 /* Full duplex link */\r
342                 case PHY_LINK_100F:\r
343                                                                 ETHERC.ECMR.BIT.DM = 1;\r
344                                                                 ETHERC.ECMR.BIT.RTM = 1;\r
345                                                                 lReturn = pdPASS;\r
346                                                                 break;\r
347                 \r
348                 case PHY_LINK_10F:\r
349                                                                 ETHERC.ECMR.BIT.DM = 1;\r
350                                                                 ETHERC.ECMR.BIT.RTM = 0;\r
351                                                                 lReturn = pdPASS;\r
352                                                                 break;\r
353 \r
354                 default:\r
355                                                                 lReturn = pdFAIL;\r
356                                                                 break;\r
357         }\r
358 \r
359         if( lReturn == pdPASS )\r
360         {\r
361                 /* Enable receive and transmit. */\r
362                 ETHERC.ECMR.BIT.RE = 1;\r
363                 ETHERC.ECMR.BIT.TE = 1;\r
364 \r
365                 /* Enable EDMAC receive */\r
366                 EDMAC.EDRRR.LONG = 0x1;\r
367         }\r
368         \r
369         return lReturn;\r
370 }\r
371 /*-----------------------------------------------------------*/\r
372 \r
373 static void prvInitialiseDescriptors( void )\r
374 {\r
375 ethfifo *pxDescriptor;\r
376 long x;\r
377 \r
378         for( x = 0; x < emacNUM_BUFFERS; x++ )\r
379         {\r
380                 /* Ensure none of the buffers are shown as in use at the start. */\r
381                 ucBufferInUse[ x ] = pdFALSE;\r
382         }\r
383 \r
384         /* Initialise the Rx descriptors. */\r
385         for( x = 0; x < emacNUM_RX_DESCRIPTORS; x++ )\r
386         {\r
387                 pxDescriptor = &( xRxDescriptors[ x ] );\r
388                 pxDescriptor->buf_p = &( xEthernetBuffers.cBuffer[ x ][ 0 ] );\r
389 \r
390                 pxDescriptor->bufsize = UIP_BUFSIZE;\r
391                 pxDescriptor->size = 0;\r
392                 pxDescriptor->status = ACT;\r
393                 pxDescriptor->next = &xRxDescriptors[ x + 1 ];  \r
394                 \r
395                 /* Mark this buffer as in use. */\r
396                 ucBufferInUse[ x ] = pdTRUE;\r
397         }\r
398 \r
399         /* The last descriptor points back to the start. */\r
400         pxDescriptor->status |= DL;\r
401         pxDescriptor->next = &xRxDescriptors[ 0 ];\r
402         \r
403         /* Initialise the Tx descriptors. */\r
404         for( x = 0; x < emacNUM_TX_BUFFERS; x++ )\r
405         {\r
406                 pxDescriptor = &( xTxDescriptors[ x ] );\r
407                 \r
408                 /* A buffer is not allocated to the Tx descriptor until a send is\r
409                 actually required. */\r
410                 pxDescriptor->buf_p = NULL;\r
411 \r
412                 pxDescriptor->bufsize = UIP_BUFSIZE;\r
413                 pxDescriptor->size = 0;\r
414                 pxDescriptor->status = 0;\r
415                 pxDescriptor->next = &xTxDescriptors[ x + 1 ];  \r
416         }\r
417 \r
418         /* The last descriptor points back to the start. */\r
419         pxDescriptor->status |= DL;\r
420         pxDescriptor->next = &( xTxDescriptors[ 0 ] );\r
421         \r
422         /* Use the first Rx descriptor to start with. */\r
423         pxCurrentRxDesc = &( xRxDescriptors[ 0 ] );\r
424 }\r
425 /*-----------------------------------------------------------*/\r
426 \r
427 static unsigned char *prvGetNextBuffer( void )\r
428 {\r
429 long x;\r
430 unsigned char *pucReturn = NULL;\r
431 unsigned long ulAttempts = 0;\r
432 \r
433         while( pucReturn == NULL )\r
434         {\r
435                 /* Look through the buffers to find one that is not in use by\r
436                 anything else. */\r
437                 for( x = 0; x < emacNUM_BUFFERS; x++ )\r
438                 {\r
439                         if( ucBufferInUse[ x ] == pdFALSE )\r
440                         {\r
441                                 ucBufferInUse[ x ] = pdTRUE;\r
442                                 pucReturn = ( unsigned char * ) &( xEthernetBuffers.cBuffer[ x ][ 0 ] );\r
443                                 break;\r
444                         }\r
445                 }\r
446 \r
447                 /* Was a buffer found? */\r
448                 if( pucReturn == NULL )\r
449                 {\r
450                         ulAttempts++;\r
451 \r
452                         if( ulAttempts >= emacBUFFER_WAIT_ATTEMPTS )\r
453                         {\r
454                                 break;\r
455                         }\r
456 \r
457                         /* Wait then look again. */\r
458                         vTaskDelay( emacBUFFER_WAIT_DELAY_ms );\r
459                 }\r
460         }\r
461 \r
462         return pucReturn;\r
463 }\r
464 /*-----------------------------------------------------------*/\r
465 \r
466 static void prvReturnBuffer( unsigned char *pucBuffer )\r
467 {\r
468 unsigned long ul;\r
469 \r
470         /* Return a buffer to the pool of free buffers. */\r
471         for( ul = 0; ul < emacNUM_BUFFERS; ul++ )\r
472         {\r
473                 if( &( xEthernetBuffers.cBuffer[ ul ][ 0 ] ) == ( void * ) pucBuffer )\r
474                 {\r
475                         ucBufferInUse[ ul ] = pdFALSE;\r
476                         break;\r
477                 }\r
478         }\r
479 }\r
480 /*-----------------------------------------------------------*/\r
481 \r
482 static void prvResetEverything( void )\r
483 {\r
484         /* Temporary code just to see if this gets called.  This function has not\r
485         been implemented. */\r
486         portDISABLE_INTERRUPTS();\r
487         for( ;; );\r
488 }\r
489 /*-----------------------------------------------------------*/\r
490 \r
491 static unsigned long prvCheckRxFifoStatus( void )\r
492 {\r
493 unsigned long ulReturn = 0;\r
494 \r
495         if( ( pxCurrentRxDesc->status & ACT ) != 0 )\r
496         {\r
497                 /* Current descriptor is still active. */\r
498         }\r
499         else if( ( pxCurrentRxDesc->status & FE ) != 0 )\r
500         {\r
501                 /* Frame error.  Clear the error. */\r
502                 pxCurrentRxDesc->status &= ~( FP1 | FP0 | FE );\r
503                 pxCurrentRxDesc->status &= ~( RMAF | RRF | RTLF | RTSF | PRE | CERF );\r
504                 pxCurrentRxDesc->status |= ACT;\r
505                 pxCurrentRxDesc = pxCurrentRxDesc->next;\r
506 \r
507                 if( EDMAC.EDRRR.LONG == 0x00000000UL )\r
508                 {\r
509                         /* Restart Ethernet if it has stopped. */\r
510                         EDMAC.EDRRR.LONG = 0x00000001UL;\r
511                 }       \r
512         }\r
513         else\r
514         {\r
515                 /* The descriptor contains a frame.  Because of the size of the buffers\r
516                 the frame should always be complete. */\r
517                 if( ( pxCurrentRxDesc->status & FP0 ) == FP0 )\r
518                 {\r
519                         ulReturn = pxCurrentRxDesc->size;\r
520                 }\r
521                 else\r
522                 {\r
523                         /* Do not expect to get here. */\r
524                         prvResetEverything();\r
525                 }\r
526         }\r
527         \r
528         return ulReturn;\r
529 }\r
530 /*-----------------------------------------------------------*/\r
531 \r
532 static void prvResetMAC( void )\r
533 {\r
534         /* Ensure the EtherC and EDMAC are enabled. */\r
535         SYSTEM.MSTPCRB.BIT.MSTPB15 = 0;\r
536         vTaskDelay( 100 / portTICK_PERIOD_MS );\r
537         \r
538         EDMAC.EDMR.BIT.SWR = 1; \r
539         \r
540         /* Crude wait for reset to complete. */\r
541         vTaskDelay( 500 / portTICK_PERIOD_MS ); \r
542 }\r
543 /*-----------------------------------------------------------*/\r
544 \r
545 static void prvConfigureEtherCAndEDMAC( void )\r
546 {\r
547         /* Initialisation code taken from Renesas example project. */\r
548         \r
549         /* TODO:    Check   bit 5   */\r
550         ETHERC.ECSR.LONG = 0x00000037;                          /* Clear all ETHERC statuS BFR, PSRTO, LCHNG, MPD, ICD */\r
551 \r
552         /* Set the EDMAC interrupt priority. */\r
553         _IPR( _ETHER_EINT ) = configKERNEL_INTERRUPT_PRIORITY;\r
554 \r
555         /* Enable interrupts of interest only. */\r
556         EDMAC.EESIPR.LONG = emacTX_END_INTERRUPT | emacRX_END_INTERRUPT;\r
557         ETHERC.RFLR.LONG = 1518;                                        /* Ether payload is 1500+ CRC */\r
558         ETHERC.IPGR.LONG = 0x00000014;                          /* Intergap is 96-bit time */\r
559 \r
560         /* EDMAC */\r
561         EDMAC.EESR.LONG = 0x47FF0F9F;                           /* Clear all ETHERC and EDMAC status bits */\r
562         #ifdef __LIT\r
563                 EDMAC.EDMR.BIT.DE = 1;\r
564         #endif\r
565         EDMAC.RDLAR = ( void * ) pxCurrentRxDesc;       /* Initialaize Rx Descriptor List Address */\r
566         EDMAC.TDLAR = &( xTxDescriptors[ 0 ] );         /* Initialaize Tx Descriptor List Address */\r
567         EDMAC.TRSCER.LONG = 0x00000000;                         /* Copy-back status is RFE & TFE only   */\r
568         EDMAC.TFTR.LONG = 0x00000000;                           /* Threshold of Tx_FIFO */\r
569         EDMAC.FDR.LONG = 0x00000000;                            /* Transmit fifo & receive fifo is 256 bytes */\r
570         EDMAC.RMCR.LONG = 0x00000003;                           /* Receive function is normal mode(continued) */\r
571         ETHERC.ECMR.BIT.PRM = 0;                                        /* Ensure promiscuous mode is off. */\r
572                 \r
573         /* Enable the interrupt... */\r
574         _IEN( _ETHER_EINT ) = 1;        \r
575 }\r
576 /*-----------------------------------------------------------*/\r
577 \r
578 #pragma interrupt ( vEMAC_ISR_Handler( vect = VECT_ETHER_EINT, enable ) )\r
579 void vEMAC_ISR_Handler( void )\r
580 {\r
581 unsigned long ul = EDMAC.EESR.LONG;\r
582 long lHigherPriorityTaskWoken = pdFALSE;\r
583 extern QueueHandle_t xEMACEventQueue;\r
584 const unsigned long ulRxEvent = uipETHERNET_RX_EVENT;\r
585 \r
586         /* Has a Tx end occurred? */\r
587         if( ul & emacTX_END_INTERRUPT )\r
588         {\r
589                 /* Only return the buffer to the pool once both Txes have completed. */\r
590                 prvReturnBuffer( ( void * ) xTxDescriptors[ 0 ].buf_p );\r
591                 EDMAC.EESR.LONG = emacTX_END_INTERRUPT;\r
592         }\r
593 \r
594         /* Has an Rx end occurred? */\r
595         if( ul & emacRX_END_INTERRUPT )\r
596         {\r
597                 /* Make sure the Ethernet task is not blocked waiting for a packet. */\r
598                 xQueueSendFromISR( xEMACEventQueue, &ulRxEvent, &lHigherPriorityTaskWoken );\r
599                 portYIELD_FROM_ISR( lHigherPriorityTaskWoken );\r
600                 EDMAC.EESR.LONG = emacRX_END_INTERRUPT;\r
601         }\r
602 }\r
603 \r