]> git.sur5r.net Git - freertos/blob - Demo/lwIP_Demo_Rowley_ARM7/EMAC/SAM7_EMAC_ISR.c
First version under SVN is V4.0.1
[freertos] / Demo / lwIP_Demo_Rowley_ARM7 / EMAC / SAM7_EMAC_ISR.c
1 /*\r
2         FreeRTOS V4.0.1 - Copyright (C) 2003-2006 Richard Barry.\r
3 \r
4         This file is part of the FreeRTOS distribution.\r
5 \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
10 \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
15 \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
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, 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 \r
41 #include "FreeRTOS.h"\r
42 #include "task.h"\r
43 #include "semphr.h"\r
44 #include "SAM7_EMAC.h"\r
45 #include "AT91SAM7X256.h"\r
46 \r
47 /*-----------------------------------------------------------*/\r
48 \r
49 /* The semaphore used to signal the arrival of new data to the interface\r
50 task. */\r
51 static xSemaphoreHandle xSemaphore = NULL;\r
52 \r
53 void vEMACISR( void ) __attribute__((naked));\r
54 \r
55 /*-----------------------------------------------------------*/\r
56 /*\r
57  * The EMAC ISR.  Handles both Tx and Rx complete interrupts.\r
58  */\r
59 void vEMACISR( void )\r
60 {\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
65 \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
70 \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
74 \r
75         if( ( ulIntStatus & AT91C_EMAC_RCOMP ) || ( ulEventStatus & AT91C_EMAC_REC ) )\r
76         {\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
81         }\r
82 \r
83         ulEventStatus = AT91C_BASE_EMAC->EMAC_TSR;\r
84         if( ( ulIntStatus & AT91C_EMAC_TCOMP ) || ( ulEventStatus & AT91C_EMAC_COMP ) )\r
85         {\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
90         }\r
91 \r
92         /* Clear the interrupt. */\r
93         AT91C_BASE_AIC->AIC_EOICR = 0;\r
94 \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
98 }\r
99 /*-----------------------------------------------------------*/\r
100 \r
101 void vPassEMACSemaphore( xSemaphoreHandle xCreatedSemaphore )\r
102 {\r
103         /* Simply store the semaphore that should be used by the ISR. */\r
104         xSemaphore = xCreatedSemaphore;\r
105 }\r
106 \r