]> git.sur5r.net Git - freertos/blob - Demo/lwIP_Demo_Rowley_ARM7/EMAC/SAM7_EMAC_ISR.c
Update in preparation for the V4.3.1 release.
[freertos] / Demo / lwIP_Demo_Rowley_ARM7 / EMAC / SAM7_EMAC_ISR.c
1 /*\r
2         FreeRTOS.org V4.3.1 - Copyright (C) 2003-2007 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         Also see http://www.SafeRTOS.com for an IEC 61508 compliant version along\r
32         with commercial development and support options.\r
33         ***************************************************************************\r
34 */\r
35 \r
36 /* \r
37 Changes from V3.2.4\r
38 \r
39         + Also read the EMAC_RSR register in the EMAC ISR as a work around the \r
40           the EMAC bug that can reset the RX bit in EMAC_ISR register before the\r
41           bit has been read.\r
42 \r
43 Changes from V4.0.1\r
44 \r
45         + Only check the interrupt status register to see if an EMAC Tx interrupt\r
46           has occurred.  Previously the TSR register was also inspected.\r
47 */\r
48 \r
49 #include "FreeRTOS.h"\r
50 #include "task.h"\r
51 #include "semphr.h"\r
52 #include "SAM7_EMAC.h"\r
53 #include "AT91SAM7X256.h"\r
54 \r
55 /*-----------------------------------------------------------*/\r
56 \r
57 /* The semaphore used to signal the arrival of new data to the interface\r
58 task. */\r
59 static xSemaphoreHandle xSemaphore = NULL;\r
60 \r
61 void vEMACISR( void ) __attribute__((naked));\r
62 \r
63 /*-----------------------------------------------------------*/\r
64 /*\r
65  * The EMAC ISR.  Handles both Tx and Rx complete interrupts.\r
66  */\r
67 void vEMACISR( void )\r
68 {\r
69         /* This ISR can cause a context switch, so the first statement must be a\r
70         call to the portENTER_SWITCHING_ISR() macro.  This must be BEFORE any\r
71         variable declarations. */\r
72         portENTER_SWITCHING_ISR();\r
73 \r
74         /* Variable definitions can be made now. */\r
75         volatile unsigned portLONG ulIntStatus, ulEventStatus;\r
76         portBASE_TYPE xSwitchRequired = pdFALSE;\r
77     extern void vClearEMACTxBuffer( void );\r
78 \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
82 \r
83         if( ( ulIntStatus & AT91C_EMAC_RCOMP ) || ( ulEventStatus & AT91C_EMAC_REC ) )\r
84         {\r
85                 /* A frame has been received, signal the lwIP task so it can process\r
86                 the Rx descriptors. */\r
87                 xSwitchRequired = xSemaphoreGiveFromISR( xSemaphore, pdFALSE );\r
88                 AT91C_BASE_EMAC->EMAC_RSR = AT91C_EMAC_REC;\r
89         }\r
90 \r
91         if( ulIntStatus & AT91C_EMAC_TCOMP )\r
92         {\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
97         }\r
98 \r
99         /* Clear the interrupt. */\r
100         AT91C_BASE_AIC->AIC_EOICR = 0;\r
101 \r
102         /* If a task was woken by either a frame being received then we may need to \r
103         switch to another task. */\r
104         portEXIT_SWITCHING_ISR( xSwitchRequired );\r
105 }\r
106 /*-----------------------------------------------------------*/\r
107 \r
108 void vPassEMACSemaphore( xSemaphoreHandle xCreatedSemaphore )\r
109 {\r
110         /* Simply store the semaphore that should be used by the ISR. */\r
111         xSemaphore = xCreatedSemaphore;\r
112 }\r
113 \r