]> git.sur5r.net Git - freertos/blob - Demo/lwIP_Demo_Rowley_ARM7/EMAC/SAM7_EMAC_ISR.c
Update version number to V4.1.1.
[freertos] / Demo / lwIP_Demo_Rowley_ARM7 / EMAC / SAM7_EMAC_ISR.c
1 /*\r
2         FreeRTOS.org V4.1.1 - Copyright (C) 2003-2006 Richard Barry.\r
3 \r
4         This file is part of the FreeRTOS.org distribution.\r
5 \r
6         FreeRTOS.org 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
10 \r
11         FreeRTOS.org 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
15 \r
16         You should have received a copy of the GNU General Public License\r
17         along with FreeRTOS.org; if not, write to the Free Software\r
18         Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
19 \r
20         A special exception to the GPL can be applied should you wish to distribute\r
21         a combined work that includes FreeRTOS.org, 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
24         can be applied.\r
25 \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
31 */\r
32 \r
33 /* \r
34 Changes from V3.2.4\r
35 \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
38           bit has been read.\r
39 \r
40 Changes from V4.0.1\r
41 \r
42         + Only check the interrupt status register to see if an EMAC Tx interrupt\r
43           has occurred.  Previously the TSR register was also inspected.\r
44 */\r
45 \r
46 #include "FreeRTOS.h"\r
47 #include "task.h"\r
48 #include "semphr.h"\r
49 #include "SAM7_EMAC.h"\r
50 #include "AT91SAM7X256.h"\r
51 \r
52 /*-----------------------------------------------------------*/\r
53 \r
54 /* The semaphore used to signal the arrival of new data to the interface\r
55 task. */\r
56 static xSemaphoreHandle xSemaphore = NULL;\r
57 \r
58 void vEMACISR( void ) __attribute__((naked));\r
59 \r
60 /*-----------------------------------------------------------*/\r
61 /*\r
62  * The EMAC ISR.  Handles both Tx and Rx complete interrupts.\r
63  */\r
64 void vEMACISR( void )\r
65 {\r
66         /* This ISR can cause a context switch, so the first statement must be a\r
67         call to the portENTER_SWITCHING_ISR() macro.  This must be BEFORE any\r
68         variable declarations. */\r
69         portENTER_SWITCHING_ISR();\r
70 \r
71         /* Variable definitions can be made now. */\r
72         volatile unsigned portLONG ulIntStatus, ulEventStatus;\r
73         portBASE_TYPE xSwitchRequired = pdFALSE;\r
74     extern void vClearEMACTxBuffer( void );\r
75 \r
76         /* Find the cause of the interrupt. */\r
77         ulIntStatus = AT91C_BASE_EMAC->EMAC_ISR;\r
78         ulEventStatus = AT91C_BASE_EMAC->EMAC_RSR;\r
79 \r
80         if( ( ulIntStatus & AT91C_EMAC_RCOMP ) || ( ulEventStatus & AT91C_EMAC_REC ) )\r
81         {\r
82                 /* A frame has been received, signal the lwIP task so it can process\r
83                 the Rx descriptors. */\r
84                 xSwitchRequired = xSemaphoreGiveFromISR( xSemaphore, pdFALSE );\r
85                 AT91C_BASE_EMAC->EMAC_RSR = AT91C_EMAC_REC;\r
86         }\r
87 \r
88         if( ulIntStatus & AT91C_EMAC_TCOMP )\r
89         {\r
90                 /* A frame has been transmitted.  Mark all the buffers used by the\r
91                 frame just transmitted as free again. */\r
92                 vClearEMACTxBuffer();\r
93                 AT91C_BASE_EMAC->EMAC_TSR = AT91C_EMAC_COMP;\r
94         }\r
95 \r
96         /* Clear the interrupt. */\r
97         AT91C_BASE_AIC->AIC_EOICR = 0;\r
98 \r
99         /* If a task was woken by either a frame being received then we may need to \r
100         switch to another task. */\r
101         portEXIT_SWITCHING_ISR( xSwitchRequired );\r
102 }\r
103 /*-----------------------------------------------------------*/\r
104 \r
105 void vPassEMACSemaphore( xSemaphoreHandle xCreatedSemaphore )\r
106 {\r
107         /* Simply store the semaphore that should be used by the ISR. */\r
108         xSemaphore = xCreatedSemaphore;\r
109 }\r
110 \r