2 FreeRTOS V8.2.3 - Copyright (C) 2015 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 This file is part of the FreeRTOS distribution.
\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
13 ***************************************************************************
\r
14 >>! NOTE: The modification to the GPL is included to allow you to !<<
\r
15 >>! distribute a combined work that includes FreeRTOS without being !<<
\r
16 >>! obliged to provide the source code for proprietary components !<<
\r
17 >>! outside of the FreeRTOS kernel. !<<
\r
18 ***************************************************************************
\r
20 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
21 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
22 FOR A PARTICULAR PURPOSE. Full license text is available on the following
\r
23 link: http://www.freertos.org/a00114.html
\r
25 ***************************************************************************
\r
27 * FreeRTOS provides completely free yet professionally developed, *
\r
28 * robust, strictly quality controlled, supported, and cross *
\r
29 * platform software that is more than just the market leader, it *
\r
30 * is the industry's de facto standard. *
\r
32 * Help yourself get started quickly while simultaneously helping *
\r
33 * to support the FreeRTOS project by purchasing a FreeRTOS *
\r
34 * tutorial book, reference manual, or both: *
\r
35 * http://www.FreeRTOS.org/Documentation *
\r
37 ***************************************************************************
\r
39 http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
\r
40 the FAQ page "My application does not run, what could be wrong?". Have you
\r
41 defined configASSERT()?
\r
43 http://www.FreeRTOS.org/support - In return for receiving this top quality
\r
44 embedded software for free we request you assist our global community by
\r
45 participating in the support forum.
\r
47 http://www.FreeRTOS.org/training - Investing in training allows your team to
\r
48 be as productive as possible as early as possible. Now you can receive
\r
49 FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
\r
50 Ltd, and the world's leading authority on the world's leading RTOS.
\r
52 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
53 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
54 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
56 http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
\r
57 Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
\r
59 http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
\r
60 Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
61 licenses offer ticketed support, indemnification and commercial middleware.
\r
63 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
64 engineered and independently SIL3 certified version for use in safety and
\r
65 mission critical applications that require provable dependability.
\r
70 /* FreeRTOS includes. */
\r
71 #include "FreeRTOS.h"
\r
76 /* Library includes. */
\r
77 #include "stm32fxxx_eth.h"
\r
78 #include "stm32f10x_gpio.h"
\r
79 #include "stm32f10x_rcc.h"
\r
80 #include "stm32f10x_nvic.h"
\r
82 /*-----------------------------------------------------------*/
\r
84 /* Hardware specifics. */
\r
85 #define uipRCC_MAC_CLOCK ( 1UL << 14UL )
\r
86 #define uipRCC_MAC_TX_CLOCK ( 1UL << 15UL )
\r
87 #define uipRCC_MAC_RX_CLOCK ( 1UL << 16UL )
\r
88 #define uipPHY_ADDRESS ( 1 )
\r
89 #define uipENET_IRQ_NUM ( 61 )
\r
90 #define uipMODE_MII ( 1UL << 23UL )
\r
91 #define uipREMAP_MAC_IO ( 1UL << 21UL )
\r
93 /* The number of descriptors to chain together for use by the Rx DMA. */
\r
94 #define uipNUM_RX_DESCRIPTORS 4
\r
96 /* The total number of buffers to be available. At most (?) there should be
\r
97 one available for each Rx descriptor, one for current use, and one that is
\r
98 in the process of being transmitted. */
\r
99 #define uipNUM_BUFFERS ( uipNUM_RX_DESCRIPTORS + 2 )
\r
101 /* Each buffer is sized to fit an entire Ethernet packet. This is for
\r
102 simplicity and speed, but could waste RAM. */
\r
103 #define uipMAX_PACKET_SIZE 1520
\r
105 /* The field in the descriptor that is unused by this configuration is used to
\r
106 hold the send count. This is just #defined to a meaningful name. */
\r
107 #define SendCount Buffer2NextDescAddr
\r
109 /* If no buffers are available, then wait this long before looking again.... */
\r
110 #define uipBUFFER_WAIT_DELAY ( 3 / portTICK_PERIOD_MS )
\r
112 /* ...and don't look more than this many times. */
\r
113 #define uipBUFFER_WAIT_ATTEMPTS ( 30 )
\r
115 /* Let the DMA know that a new descriptor has been made available to it. */
\r
116 #define prvRxDescriptorAvailable() ETH_DMA->DMARPDR = 0
\r
118 /*-----------------------------------------------------------*/
\r
121 * Configure the IO for Ethernet use.
\r
123 static void prvSetupEthGPIO( void );
\r
126 * Return a pointer to an unused buffer, marking the returned buffer as now
\r
129 static unsigned char *prvGetNextBuffer( void );
\r
131 /*-----------------------------------------------------------*/
\r
133 /* Allocate the Rx descriptors used by the DMA. */
\r
134 static ETH_DMADESCTypeDef xRxDescriptors[ uipNUM_RX_DESCRIPTORS ] __attribute__((aligned(4)));
\r
136 /* Allocate the descriptor used for transmitting. It might be that better
\r
137 performance could be achieved by having more than one Tx descriptor, but
\r
138 in this simple case only one is used. */
\r
139 static volatile ETH_DMADESCTypeDef xTxDescriptor __attribute__((aligned(4)));
\r
141 /* Buffers used for receiving and transmitting data. */
\r
142 static unsigned char ucMACBuffers[ uipNUM_BUFFERS ][ uipMAX_PACKET_SIZE ] __attribute__((aligned(4)));
\r
144 /* Each ucBufferInUse index corresponds to a position in the same index in the
\r
145 ucMACBuffers array. If the index contains a 1 then the buffer within
\r
146 ucMACBuffers is in use, if it contains a 0 then the buffer is free. */
\r
147 static unsigned char ucBufferInUse[ uipNUM_BUFFERS ] = { 0 };
\r
149 /* Index to the Rx descriptor to inspect next when looking for a received
\r
151 static unsigned long ulNextDescriptor;
\r
153 /* The uip_buffer is not a fixed array, but instead gets pointed to the buffers
\r
154 allocated within this file. */
\r
155 extern unsigned char * uip_buf;
\r
157 /*-----------------------------------------------------------*/
\r
159 portBASE_TYPE xEthInitialise( void )
\r
161 static ETH_InitTypeDef xEthInit; /* Static so as not to take up too much stack space. */
\r
162 NVIC_InitTypeDef xNVICInit;
\r
163 const unsigned char ucMACAddress[] = { configMAC_ADDR0, configMAC_ADDR1, configMAC_ADDR2, configMAC_ADDR3, configMAC_ADDR4, configMAC_ADDR5 };
\r
164 portBASE_TYPE xReturn;
\r
167 /* Start with things in a safe known state. */
\r
169 for( ul = 0; ul < uipNUM_RX_DESCRIPTORS; ul++ )
\r
171 ETH_DMARxDescReceiveITConfig( &( xRxDescriptors[ ul ] ), DISABLE );
\r
174 /* Route clock to the peripheral. */
\r
175 RCC->AHBENR |= ( uipRCC_MAC_CLOCK | uipRCC_MAC_TX_CLOCK | uipRCC_MAC_RX_CLOCK );
\r
177 /* Set the MAC address. */
\r
178 ETH_MACAddressConfig( ETH_MAC_Address0, ( unsigned char * ) ucMACAddress );
\r
180 /* Use MII mode. */
\r
181 AFIO->MAPR &= ~( uipMODE_MII );
\r
183 /* Configure all the GPIO as required for MAC/PHY interfacing. */
\r
186 /* Reset the peripheral. */
\r
187 ETH_SoftwareReset();
\r
188 while( ETH_GetSoftwareResetStatus() == SET );
\r
190 /* Initialise using the whopping big structure. Code space could be saved
\r
191 by making this a const struct, however that would mean changes to the
\r
192 structure within the library header files could break the code, so for now
\r
193 just set everything manually at run time. */
\r
194 xEthInit.ETH_AutoNegotiation = ETH_AutoNegotiation_Enable;
\r
195 xEthInit.ETH_Watchdog = ETH_Watchdog_Disable;
\r
196 xEthInit.ETH_Jabber = ETH_Jabber_Disable;
\r
197 xEthInit.ETH_JumboFrame = ETH_JumboFrame_Disable;
\r
198 xEthInit.ETH_InterFrameGap = ETH_InterFrameGap_96Bit;
\r
199 xEthInit.ETH_CarrierSense = ETH_CarrierSense_Enable;
\r
200 xEthInit.ETH_Speed = ETH_Speed_10M;
\r
201 xEthInit.ETH_ReceiveOwn = ETH_ReceiveOwn_Disable;
\r
202 xEthInit.ETH_LoopbackMode = ETH_LoopbackMode_Disable;
\r
203 xEthInit.ETH_Mode = ETH_Mode_HalfDuplex;
\r
204 xEthInit.ETH_ChecksumOffload = ETH_ChecksumOffload_Disable;
\r
205 xEthInit.ETH_RetryTransmission = ETH_RetryTransmission_Disable;
\r
206 xEthInit.ETH_AutomaticPadCRCStrip = ETH_AutomaticPadCRCStrip_Disable;
\r
207 xEthInit.ETH_BackOffLimit = ETH_BackOffLimit_10;
\r
208 xEthInit.ETH_DeferralCheck = ETH_DeferralCheck_Disable;
\r
209 xEthInit.ETH_ReceiveAll = ETH_ReceiveAll_Enable;
\r
210 xEthInit.ETH_SourceAddrFilter = ETH_SourceAddrFilter_Disable;
\r
211 xEthInit.ETH_PassControlFrames = ETH_PassControlFrames_ForwardPassedAddrFilter;
\r
212 xEthInit.ETH_BroadcastFramesReception = ETH_BroadcastFramesReception_Disable;
\r
213 xEthInit.ETH_DestinationAddrFilter = ETH_DestinationAddrFilter_Normal;
\r
214 xEthInit.ETH_PromiscuousMode = ETH_PromiscuousMode_Disable;
\r
215 xEthInit.ETH_MulticastFramesFilter = ETH_MulticastFramesFilter_Perfect;
\r
216 xEthInit.ETH_UnicastFramesFilter = ETH_UnicastFramesFilter_Perfect;
\r
217 xEthInit.ETH_HashTableHigh = 0x0;
\r
218 xEthInit.ETH_HashTableLow = 0x0;
\r
219 xEthInit.ETH_PauseTime = 0x0;
\r
220 xEthInit.ETH_ZeroQuantaPause = ETH_ZeroQuantaPause_Disable;
\r
221 xEthInit.ETH_PauseLowThreshold = ETH_PauseLowThreshold_Minus4;
\r
222 xEthInit.ETH_UnicastPauseFrameDetect = ETH_UnicastPauseFrameDetect_Disable;
\r
223 xEthInit.ETH_ReceiveFlowControl = ETH_ReceiveFlowControl_Disable;
\r
224 xEthInit.ETH_TransmitFlowControl = ETH_TransmitFlowControl_Disable;
\r
225 xEthInit.ETH_VLANTagComparison = ETH_VLANTagComparison_16Bit;
\r
226 xEthInit.ETH_VLANTagIdentifier = 0x0;
\r
227 xEthInit.ETH_DropTCPIPChecksumErrorFrame = ETH_DropTCPIPChecksumErrorFrame_Disable;
\r
228 xEthInit.ETH_ReceiveStoreForward = ETH_ReceiveStoreForward_Enable;
\r
229 xEthInit.ETH_FlushReceivedFrame = ETH_FlushReceivedFrame_Disable;
\r
230 xEthInit.ETH_TransmitStoreForward = ETH_TransmitStoreForward_Enable;
\r
231 xEthInit.ETH_TransmitThresholdControl = ETH_TransmitThresholdControl_64Bytes;
\r
232 xEthInit.ETH_ForwardErrorFrames = ETH_ForwardErrorFrames_Disable;
\r
233 xEthInit.ETH_ForwardUndersizedGoodFrames = ETH_ForwardUndersizedGoodFrames_Disable;
\r
234 xEthInit.ETH_ReceiveThresholdControl = ETH_ReceiveThresholdControl_64Bytes;
\r
235 xEthInit.ETH_SecondFrameOperate = ETH_SecondFrameOperate_Disable;
\r
236 xEthInit.ETH_AddressAlignedBeats = ETH_AddressAlignedBeats_Enable;
\r
237 xEthInit.ETH_FixedBurst = ETH_FixedBurst_Disable;
\r
238 xEthInit.ETH_RxDMABurstLength = ETH_RxDMABurstLength_1Beat;
\r
239 xEthInit.ETH_TxDMABurstLength = ETH_TxDMABurstLength_1Beat;
\r
240 xEthInit.ETH_DescriptorSkipLength = 0x0;
\r
241 xEthInit.ETH_DMAArbitration = ETH_DMAArbitration_RoundRobin_RxTx_1_1;
\r
243 xReturn = ETH_Init( &xEthInit, uipPHY_ADDRESS );
\r
245 /* Check a link was established. */
\r
246 if( xReturn != pdFAIL )
\r
248 /* Rx and Tx interrupts are used. */
\r
249 ETH_DMAITConfig( ETH_DMA_IT_NIS | ETH_DMA_IT_R | ETH_DMA_IT_T, ENABLE );
\r
251 /* Only a single Tx descriptor is used. For now it is set to use an Rx
\r
252 buffer, but will get updated to point to where ever uip_buf is
\r
253 pointing prior to its use. */
\r
254 ETH_DMATxDescChainInit( ( void * ) &xTxDescriptor, ( void * ) ucMACBuffers, 1 );
\r
255 ETH_DMARxDescChainInit( xRxDescriptors, ( void * ) ucMACBuffers, uipNUM_RX_DESCRIPTORS );
\r
256 for( ul = 0; ul < uipNUM_RX_DESCRIPTORS; ul++ )
\r
258 /* Ensure received data generates an interrupt. */
\r
259 ETH_DMARxDescReceiveITConfig( &( xRxDescriptors[ ul ] ), ENABLE );
\r
261 /* Fix up the addresses used by the descriptors.
\r
262 The way ETH_DMARxDescChainInit() is not compatible with the buffer
\r
263 declarations in this file. */
\r
264 xRxDescriptors[ ul ].Buffer1Addr = ( unsigned long ) &( ucMACBuffers[ ul ][ 0 ] );
\r
266 /* Mark the buffer used by this descriptor as in use. */
\r
267 ucBufferInUse[ ul ] = pdTRUE;
\r
270 /* When receiving data, start at the first descriptor. */
\r
271 ulNextDescriptor = 0;
\r
273 /* Initialise uip_buf to ensure it points somewhere valid. */
\r
274 uip_buf = prvGetNextBuffer();
\r
276 /* SendCount must be initialised to 2 to ensure the Tx descriptor looks
\r
277 as if its available (as if it has already been sent twice. */
\r
278 xTxDescriptor.SendCount = 2;
\r
280 /* Switch on the interrupts in the NVIC. */
\r
281 xNVICInit.NVIC_IRQChannel = uipENET_IRQ_NUM;
\r
282 xNVICInit.NVIC_IRQChannelPreemptionPriority = configLIBRARY_KERNEL_INTERRUPT_PRIORITY;
\r
283 xNVICInit.NVIC_IRQChannelSubPriority = 0;
\r
284 xNVICInit.NVIC_IRQChannelCmd = ENABLE;
\r
285 NVIC_Init( &xNVICInit );
\r
287 /* Buffers and descriptors are all set up, now enable the MAC. */
\r
290 /* Let the DMA know there are Rx descriptors available. */
\r
291 prvRxDescriptorAvailable();
\r
296 /*-----------------------------------------------------------*/
\r
298 static unsigned char *prvGetNextBuffer( void )
\r
301 unsigned char *ucReturn = NULL;
\r
302 unsigned long ulAttempts = 0;
\r
304 while( ucReturn == NULL )
\r
306 /* Look through the buffers to find one that is not in use by
\r
308 for( x = 0; x < uipNUM_BUFFERS; x++ )
\r
310 if( ucBufferInUse[ x ] == pdFALSE )
\r
312 ucBufferInUse[ x ] = pdTRUE;
\r
313 ucReturn = &( ucMACBuffers[ x ][ 0 ] );
\r
318 /* Was a buffer found? */
\r
319 if( ucReturn == NULL )
\r
323 if( ulAttempts >= uipBUFFER_WAIT_ATTEMPTS )
\r
328 /* Wait then look again. */
\r
329 vTaskDelay( uipBUFFER_WAIT_DELAY );
\r
335 /*-----------------------------------------------------------*/
\r
337 unsigned short usGetMACRxData( void )
\r
339 unsigned short usReturn;
\r
341 if( ( xRxDescriptors[ ulNextDescriptor ].Status & ETH_DMARxDesc_ES ) != 0 )
\r
343 /* Error in Rx. Discard the frame and give it back to the DMA. */
\r
344 xRxDescriptors[ ulNextDescriptor ].Status = ETH_DMARxDesc_OWN;
\r
345 prvRxDescriptorAvailable();
\r
347 /* No data to return. */
\r
350 /* Start from the next descriptor the next time this function is called. */
\r
351 ulNextDescriptor++;
\r
352 if( ulNextDescriptor >= uipNUM_RX_DESCRIPTORS )
\r
354 ulNextDescriptor = 0UL;
\r
357 else if( ( xRxDescriptors[ ulNextDescriptor ].Status & ETH_DMARxDesc_OWN ) == 0 )
\r
359 /* Mark the current buffer as free as uip_buf is going to be set to
\r
360 the buffer that contains the received data. */
\r
361 vReturnBuffer( uip_buf );
\r
363 /* Get the received data length from the top 2 bytes of the Status
\r
364 word and the data itself. */
\r
365 usReturn = ( unsigned short ) ( ( xRxDescriptors[ ulNextDescriptor ].Status & ETH_DMARxDesc_FL ) >> 16UL );
\r
366 uip_buf = ( unsigned char * ) ( xRxDescriptors[ ulNextDescriptor ].Buffer1Addr );
\r
368 /* Allocate a new buffer to the descriptor. */
\r
369 xRxDescriptors[ ulNextDescriptor ].Buffer1Addr = ( unsigned long ) prvGetNextBuffer();
\r
371 /* Give the descriptor back to the DMA. */
\r
372 xRxDescriptors[ ulNextDescriptor ].Status = ETH_DMARxDesc_OWN;
\r
373 prvRxDescriptorAvailable();
\r
375 /* Start from the next descriptor the next time this function is called. */
\r
376 ulNextDescriptor++;
\r
377 if( ulNextDescriptor >= uipNUM_RX_DESCRIPTORS )
\r
379 ulNextDescriptor = 0UL;
\r
384 /* No received data at all. */
\r
390 /*-----------------------------------------------------------*/
\r
392 void vSendMACData( unsigned short usDataLen )
\r
394 unsigned long ulAttempts = 0UL;
\r
396 /* Check to see if the Tx descriptor is free. The check against <2 is to
\r
397 ensure the buffer has been sent twice and in so doing preventing a race
\r
398 condition with the DMA on the ETH_DMATxDesc_OWN bit. */
\r
399 while( ( xTxDescriptor.SendCount < 2 ) && ( xTxDescriptor.Status & ETH_DMATxDesc_OWN ) == ETH_DMATxDesc_OWN )
\r
401 /* Wait for the Tx descriptor to become available. */
\r
402 vTaskDelay( uipBUFFER_WAIT_DELAY );
\r
405 if( ulAttempts > uipBUFFER_WAIT_ATTEMPTS )
\r
407 /* Something has gone wrong as the Tx descriptor is still in use.
\r
408 Clear it down manually, the data it was sending will probably be
\r
410 xTxDescriptor.Status &= ~ETH_DMATxDesc_OWN;
\r
411 vReturnBuffer( ( unsigned char * ) xTxDescriptor.Buffer1Addr );
\r
416 /* Setup the Tx descriptor for transmission. */
\r
417 xTxDescriptor.SendCount = 0;
\r
418 xTxDescriptor.Buffer1Addr = ( unsigned long ) uip_buf;
\r
419 xTxDescriptor.ControlBufferSize = ( unsigned long ) usDataLen;
\r
420 xTxDescriptor.Status = ETH_DMATxDesc_OWN | ETH_DMATxDesc_LS | ETH_DMATxDesc_FS | ETH_DMATxDesc_TER | ETH_DMATxDesc_TCH | ETH_DMATxDesc_IC;
\r
421 ETH_DMA->DMASR = ETH_DMASR_TBUS;
\r
422 ETH_DMA->DMATPDR = 0;
\r
424 /* uip_buf is being sent by the Tx descriptor. Allocate a new buffer. */
\r
425 uip_buf = prvGetNextBuffer();
\r
427 /*-----------------------------------------------------------*/
\r
429 static void prvSetupEthGPIO( void )
\r
431 GPIO_InitTypeDef xEthInit;
\r
433 /* Remap MAC IO. */
\r
434 AFIO->MAPR |= ( uipREMAP_MAC_IO );
\r
436 /* Set PA2, PA8, PB5, PB8, PB11, PB12, PB13, PC1 and PC2 for Ethernet
\r
438 xEthInit.GPIO_Pin = GPIO_Pin_2;/* | GPIO_Pin_8; This should be set when the 25MHz is generated by MCO. */
\r
439 xEthInit.GPIO_Speed = GPIO_Speed_50MHz;
\r
440 xEthInit.GPIO_Mode = GPIO_Mode_AF_PP;
\r
441 GPIO_Init( GPIOA, &xEthInit );
\r
443 xEthInit.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_8 | GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13; /*5*/
\r
444 GPIO_Init( GPIOB, &xEthInit );
\r
446 xEthInit.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_2;
\r
447 GPIO_Init( GPIOC, &xEthInit );
\r
450 /* Configure PA0, PA1, PA3, PB10, PC3, PD8, PD9, PD10, PD11 and PD12 as
\r
452 xEthInit.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_3;
\r
453 xEthInit.GPIO_Mode = GPIO_Mode_IN_FLOATING;
\r
454 GPIO_Init( GPIOA, &xEthInit );
\r
456 xEthInit.GPIO_Pin = GPIO_Pin_10;
\r
457 GPIO_Init( GPIOB, &xEthInit );
\r
459 xEthInit.GPIO_Pin = GPIO_Pin_3;
\r
460 GPIO_Init( GPIOC, &xEthInit );
\r
462 xEthInit.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12;
\r
463 GPIO_Init( GPIOD, &xEthInit );
\r
465 /*-----------------------------------------------------------*/
\r
467 void vReturnBuffer( unsigned char *pucBuffer )
\r
471 /* Mark a buffer as free for use. */
\r
472 for( ul = 0; ul < uipNUM_BUFFERS; ul++ )
\r
474 if( ucMACBuffers[ ul ] == pucBuffer )
\r
476 ucBufferInUse[ ul ] = pdFALSE;
\r
481 /*-----------------------------------------------------------*/
\r
483 void vMAC_ISR( void )
\r
485 unsigned long ulStatus;
\r
486 extern SemaphoreHandle_t xEMACSemaphore;
\r
487 long xHigherPriorityTaskWoken = pdFALSE;
\r
489 /* What caused the interrupt? */
\r
490 ulStatus = ETH_DMA->DMASR;
\r
492 /* Clear everything before leaving. */
\r
493 ETH_DMA->DMASR = ulStatus;
\r
495 if( ulStatus & ETH_DMA_IT_R )
\r
497 /* Data was received. Ensure the uIP task is not blocked as data has
\r
499 xSemaphoreGiveFromISR( xEMACSemaphore, &xHigherPriorityTaskWoken );
\r
502 if( ulStatus & ETH_DMA_IT_T )
\r
504 /* Data was transmitted. */
\r
505 if( xTxDescriptor.SendCount == 0 )
\r
508 ( xTxDescriptor.SendCount )++;
\r
510 xTxDescriptor.Status = ETH_DMATxDesc_OWN | ETH_DMATxDesc_LS | ETH_DMATxDesc_FS | ETH_DMATxDesc_TER | ETH_DMATxDesc_TCH | ETH_DMATxDesc_IC;
\r
511 ETH_DMA->DMASR = ETH_DMASR_TBUS;
\r
512 ETH_DMA->DMATPDR = 0;
\r
516 /* The Tx buffer is no longer required. */
\r
517 vReturnBuffer( ( unsigned char * ) xTxDescriptor.Buffer1Addr );
\r
521 /* If xSemaphoreGiveFromISR() unblocked a task, and the unblocked task has
\r
522 a higher priority than the currently executing task, then
\r
523 xHigherPriorityTaskWoken will have been set to pdTRUE and this ISR should
\r
524 return directly to the higher priority unblocked task. */
\r
525 portEND_SWITCHING_ISR( xHigherPriorityTaskWoken );
\r