2 FreeRTOS V6.0.0 - Copyright (C) 2009 Real Time Engineers Ltd.
\r
4 This file is part of the FreeRTOS distribution.
\r
6 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
7 the terms of the GNU General Public License (version 2) as published by the
\r
8 Free Software Foundation and modified by the FreeRTOS exception.
\r
9 **NOTE** The exception to the GPL is included to allow you to distribute a
\r
10 combined work that includes FreeRTOS without being obliged to provide the
\r
11 source code for proprietary components outside of the FreeRTOS kernel.
\r
12 Alternative commercial license and support terms are also available upon
\r
13 request. See the licensing section of http://www.FreeRTOS.org for full
\r
16 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT
\r
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
\r
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
21 You should have received a copy of the GNU General Public License along
\r
22 with FreeRTOS; if not, write to the Free Software Foundation, Inc., 59
\r
23 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
\r
26 ***************************************************************************
\r
28 * The FreeRTOS eBook and reference manual are available to purchase for a *
\r
29 * small fee. Help yourself get started quickly while also helping the *
\r
30 * FreeRTOS project! See http://www.FreeRTOS.org/Documentation for details *
\r
32 ***************************************************************************
\r
36 Please ensure to read the configuration and relevant port sections of the
\r
37 online documentation.
\r
39 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
42 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
45 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
46 licensing and training services.
\r
50 #include "FreeRTOS.h"
\r
53 #include "SAM7_EMAC.h"
\r
54 #include "AT91SAM7X256.h"
\r
56 /*-----------------------------------------------------------*/
\r
58 /* The semaphore used to signal the arrival of new data to the interface
\r
60 static xSemaphoreHandle xSemaphore = NULL;
\r
62 /* The interrupt entry point is naked so we can control the context saving. */
\r
63 void vEMACISR_Wrapper( void ) __attribute__((naked));
\r
65 /* The interrupt handler function must be separate from the entry function
\r
66 to ensure the correct stack frame is set up. */
\r
67 void vEMACISR_Handler( void );
\r
69 /*-----------------------------------------------------------*/
\r
71 * The EMAC ISR. Handles both Tx and Rx complete interrupts.
\r
73 void vEMACISR_Handler( void )
\r
75 volatile unsigned long ulIntStatus, ulEventStatus;
\r
76 portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
\r
77 extern void vClearEMACTxBuffer( void );
\r
79 /* Find the cause of the interrupt. */
\r
80 ulIntStatus = AT91C_BASE_EMAC->EMAC_ISR;
\r
81 ulEventStatus = AT91C_BASE_EMAC->EMAC_RSR;
\r
83 if( ( ulIntStatus & AT91C_EMAC_RCOMP ) || ( ulEventStatus & AT91C_EMAC_REC ) )
\r
85 /* A frame has been received, signal the lwIP task so it can process
\r
86 the Rx descriptors. */
\r
87 xSemaphoreGiveFromISR( xSemaphore, &xHigherPriorityTaskWoken );
\r
88 AT91C_BASE_EMAC->EMAC_RSR = AT91C_EMAC_REC;
\r
91 if( ulIntStatus & AT91C_EMAC_TCOMP )
\r
93 /* A frame has been transmitted. Mark all the buffers used by the
\r
94 frame just transmitted as free again. */
\r
95 vClearEMACTxBuffer();
\r
96 AT91C_BASE_EMAC->EMAC_TSR = AT91C_EMAC_COMP;
\r
99 /* Clear the interrupt. */
\r
100 AT91C_BASE_AIC->AIC_EOICR = 0;
\r
102 /* If a task was woken by either a frame being received then we may need to
\r
103 switch to another task. If the unblocked task was of higher priority then
\r
104 the interrupted task it will then execute immediately that the ISR
\r
106 if( xHigherPriorityTaskWoken )
\r
108 portYIELD_FROM_ISR();
\r
111 /*-----------------------------------------------------------*/
\r
113 void vEMACISR_Wrapper( void )
\r
115 /* Save the context of the interrupted task. */
\r
116 portSAVE_CONTEXT();
\r
118 /* Call the handler to do the work. This must be a separate
\r
119 function to ensure the stack frame is set up correctly. */
\r
120 vEMACISR_Handler();
\r
122 /* Restore the context of whichever task will execute next. */
\r
123 portRESTORE_CONTEXT();
\r
125 /*-----------------------------------------------------------*/
\r
127 void vPassEMACSemaphore( xSemaphoreHandle xCreatedSemaphore )
\r
129 /* Simply store the semaphore that should be used by the ISR. */
\r
130 xSemaphore = xCreatedSemaphore;
\r