2 FreeRTOS V4.0.1 - Copyright (C) 2003-2006 Richard Barry.
\r
4 This file is part of the FreeRTOS distribution.
\r
6 FreeRTOS is free software; you can redistribute it and/or modify
\r
7 it under the terms of the GNU General Public License as published by
\r
8 the Free Software Foundation; either version 2 of the License, or
\r
9 (at your option) any later version.
\r
11 FreeRTOS is distributed in the hope that it will be useful,
\r
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 GNU General Public License for more details.
\r
16 You should have received a copy of the GNU General Public License
\r
17 along with FreeRTOS; if not, write to the Free Software
\r
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
20 A special exception to the GPL can be applied should you wish to distribute
\r
21 a combined work that includes FreeRTOS, without being obliged to provide
\r
22 the source code for any proprietary components. See the licensing section
\r
23 of http://www.FreeRTOS.org for full details of how and when the exception
\r
26 ***************************************************************************
\r
27 See http://www.FreeRTOS.org for documentation, latest information, license
\r
28 and contact details. Please ensure to read the configuration and relevant
\r
29 port sections of the online documentation.
\r
30 ***************************************************************************
\r
36 + Also read the EMAC_RSR register in the EMAC ISR as a work around the
\r
37 the EMAC bug that can reset the RX bit in EMAC_ISR register before the
\r
41 #include "FreeRTOS.h"
\r
44 #include "SAM7_EMAC.h"
\r
45 #include "AT91SAM7X256.h"
\r
47 /*-----------------------------------------------------------*/
\r
49 /* The semaphore used to signal the arrival of new data to the interface
\r
51 static xSemaphoreHandle xSemaphore = NULL;
\r
53 void vEMACISR( void ) __attribute__((naked));
\r
55 /*-----------------------------------------------------------*/
\r
57 * The EMAC ISR. Handles both Tx and Rx complete interrupts.
\r
59 void vEMACISR( void )
\r
61 /* This ISR can cause a context switch, so the first statement must be a
\r
62 call to the portENTER_SWITCHING_ISR() macro. This must be BEFORE any
\r
63 variable declarations. */
\r
64 portENTER_SWITCHING_ISR();
\r
66 /* Variable definitions can be made now. */
\r
67 volatile unsigned portLONG ulIntStatus, ulEventStatus;
\r
68 portBASE_TYPE xSwitchRequired = pdFALSE;
\r
69 extern void vClearEMACTxBuffer( void );
\r
71 /* Find the cause of the interrupt. */
\r
72 ulIntStatus = AT91C_BASE_EMAC->EMAC_ISR;
\r
73 ulEventStatus = AT91C_BASE_EMAC->EMAC_RSR;
\r
75 if( ( ulIntStatus & AT91C_EMAC_RCOMP ) || ( ulEventStatus & AT91C_EMAC_REC ) )
\r
77 /* A frame has been received, signal the lwIP task so it can process
\r
78 the Rx descriptors. */
\r
79 xSwitchRequired = xSemaphoreGiveFromISR( xSemaphore, pdFALSE );
\r
80 AT91C_BASE_EMAC->EMAC_RSR = AT91C_EMAC_REC;
\r
83 ulEventStatus = AT91C_BASE_EMAC->EMAC_TSR;
\r
84 if( ( ulIntStatus & AT91C_EMAC_TCOMP ) || ( ulEventStatus & AT91C_EMAC_COMP ) )
\r
86 /* A frame has been transmitted. Mark all the buffers used by the
\r
87 frame just transmitted as free again. */
\r
88 vClearEMACTxBuffer();
\r
89 AT91C_BASE_EMAC->EMAC_TSR = AT91C_EMAC_COMP;
\r
92 /* Clear the interrupt. */
\r
93 AT91C_BASE_AIC->AIC_EOICR = 0;
\r
95 /* If a task was woken by either a frame being received then we may need to
\r
96 switch to another task. */
\r
97 portEXIT_SWITCHING_ISR( xSwitchRequired );
\r
99 /*-----------------------------------------------------------*/
\r
101 void vPassEMACSemaphore( xSemaphoreHandle xCreatedSemaphore )
\r
103 /* Simply store the semaphore that should be used by the ISR. */
\r
104 xSemaphore = xCreatedSemaphore;
\r