]> git.sur5r.net Git - freertos/blob - Demo/lwIP_Demo_Rowley_ARM7/EMAC/SAM7_EMAC_ISR.c
Update to V5.0.2
[freertos] / Demo / lwIP_Demo_Rowley_ARM7 / EMAC / SAM7_EMAC_ISR.c
1 /*\r
2         FreeRTOS.org V5.0.2 - Copyright (C) 2003-2008 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     ***************************************************************************\r
28     *                                                                         *\r
29     * SAVE TIME AND MONEY!  We can port FreeRTOS.org to your own hardware,    *\r
30     * and even write all or part of your application on your behalf.          *\r
31     * See http://www.OpenRTOS.com for details of the services we provide to   *\r
32     * expedite your project.                                                  *\r
33     *                                                                         *\r
34     ***************************************************************************\r
35     ***************************************************************************\r
36 \r
37         Please ensure to read the configuration and relevant port sections of the\r
38         online documentation.\r
39 \r
40         http://www.FreeRTOS.org - Documentation, latest information, license and \r
41         contact details.\r
42 \r
43         http://www.SafeRTOS.com - A version that is certified for use in safety \r
44         critical systems.\r
45 \r
46         http://www.OpenRTOS.com - Commercial support, development, porting, \r
47         licensing and training services.\r
48 */\r
49 \r
50 \r
51 #include "FreeRTOS.h"\r
52 #include "task.h"\r
53 #include "semphr.h"\r
54 #include "SAM7_EMAC.h"\r
55 #include "AT91SAM7X256.h"\r
56 \r
57 /*-----------------------------------------------------------*/\r
58 \r
59 /* The semaphore used to signal the arrival of new data to the interface\r
60 task. */\r
61 static xSemaphoreHandle xSemaphore = NULL;\r
62 \r
63 /* The interrupt entry point is naked so we can control the context saving. */\r
64 void vEMACISR_Wrapper( void ) __attribute__((naked));\r
65 \r
66 /* The interrupt handler function must be separate from the entry function\r
67 to ensure the correct stack frame is set up. */\r
68 void vEMACISR_Handler( void );\r
69 \r
70 /*-----------------------------------------------------------*/\r
71 /*\r
72  * The EMAC ISR.  Handles both Tx and Rx complete interrupts.\r
73  */\r
74 void vEMACISR_Handler( void )\r
75 {\r
76 volatile unsigned portLONG ulIntStatus, ulEventStatus;\r
77 portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;\r
78 extern void vClearEMACTxBuffer( void );\r
79 \r
80         /* Find the cause of the interrupt. */\r
81         ulIntStatus = AT91C_BASE_EMAC->EMAC_ISR;\r
82         ulEventStatus = AT91C_BASE_EMAC->EMAC_RSR;\r
83 \r
84         if( ( ulIntStatus & AT91C_EMAC_RCOMP ) || ( ulEventStatus & AT91C_EMAC_REC ) )\r
85         {\r
86                 /* A frame has been received, signal the lwIP task so it can process\r
87                 the Rx descriptors. */\r
88                 xSemaphoreGiveFromISR( xSemaphore, &xHigherPriorityTaskWoken );\r
89                 AT91C_BASE_EMAC->EMAC_RSR = AT91C_EMAC_REC;\r
90         }\r
91 \r
92         if( ulIntStatus & AT91C_EMAC_TCOMP )\r
93         {\r
94                 /* A frame has been transmitted.  Mark all the buffers used by the\r
95                 frame just transmitted as free again. */\r
96                 vClearEMACTxBuffer();\r
97                 AT91C_BASE_EMAC->EMAC_TSR = AT91C_EMAC_COMP;\r
98         }\r
99 \r
100         /* Clear the interrupt. */\r
101         AT91C_BASE_AIC->AIC_EOICR = 0;\r
102 \r
103         /* If a task was woken by either a frame being received then we may need to \r
104         switch to another task.  If the unblocked task was of higher priority then\r
105         the interrupted task it will then execute immediately that the ISR\r
106         completes. */\r
107         if( xHigherPriorityTaskWoken )\r
108         {\r
109                 portYIELD_FROM_ISR();\r
110         }\r
111 }\r
112 /*-----------------------------------------------------------*/\r
113 \r
114 void  vEMACISR_Wrapper( void )\r
115 {\r
116         /* Save the context of the interrupted task. */\r
117         portSAVE_CONTEXT();\r
118 \r
119         /* Call the handler to do the work.  This must be a separate\r
120         function to ensure the stack frame is set up correctly. */\r
121         vEMACISR_Handler();\r
122 \r
123         /* Restore the context of whichever task will execute next. */\r
124         portRESTORE_CONTEXT();\r
125 }\r
126 /*-----------------------------------------------------------*/\r
127 \r
128 void vPassEMACSemaphore( xSemaphoreHandle xCreatedSemaphore )\r
129 {\r
130         /* Simply store the semaphore that should be used by the ISR. */\r
131         xSemaphore = xCreatedSemaphore;\r
132 }\r
133 \r