- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

# SAM7_EMAC_ISR.c

    00001 /*
    00002   FreeRTOS.org V4.6.0 - Copyright (C) 2003-2007 Richard Barry.
    00003
    00004   This file is part of the FreeRTOS.org distribution.
    00005
    00006   FreeRTOS.org is free software; you can redistribute it and/or modify
    00007   it under the terms of the GNU General Public License as published by
    00008   the Free Software Foundation; either version 2 of the License, or
    00009   (at your option) any later version.
    00010
    00011   FreeRTOS.org is distributed in the hope that it will be useful,
    00012   but WITHOUT ANY WARRANTY; without even the implied warranty of
    00013   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00014   GNU General Public License for more details.
    00015
    00016   You should have received a copy of the GNU General Public License
    00017   along with FreeRTOS.org; if not, write to the Free Software
    00018   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    00019
    00020   A special exception to the GPL can be applied should you wish to distribute
    00021   a combined work that includes FreeRTOS.org, without being obliged to provide
    00022   the source code for any proprietary components.  See the licensing section
    00023   of http://www.FreeRTOS.org for full details of how and when the exception
    00024   can be applied.
    00025
    00026   ***************************************************************************
    00027   See http://www.FreeRTOS.org for documentation, latest information, license
    00028   and contact details.  Please ensure to read the configuration and relevant
    00029   port sections of the online documentation.
    00030
    00031   Also see http://www.SafeRTOS.com for an IEC 61508 compliant version along
    00032   with commercial development and support options.
    00033   ***************************************************************************
    00034 */
    00035
    00036 #include "config.h" // MakingThings.
    00037 #ifdef MAKE_CTRL_NETWORK
    00038
    00039 #include "FreeRTOS.h"
    00040 #include "task.h"
    00041 #include "semphr.h"
    00042 #include "SAM7_EMAC.h"
    00043 #include "AT91SAM7X256.h"
    00044
    00045 /*-----------------------------------------------------------*/
    00046
    00047 /* The semaphore used to signal the arrival of new data to the interface
    00048 task. */
    00049 static xSemaphoreHandle xSemaphore = NULL;
    00050
    00051 /* The interrupt entry point is naked so we can control the context saving. */
    00052 void vEMACISR_Wrapper( void ) __attribute__((naked));
    00053
    00054 /* The interrupt handler function must be separate from the entry function
    00055 to ensure the correct stack frame is set up. */
    00056 void vEMACISR_Handler( void );
    00057
    00058 /*-----------------------------------------------------------*/
    00059 /*
    00060  * The EMAC ISR.  Handles both Tx and Rx complete interrupts.
    00061  */
    00062 void vEMACISR_Handler( void )
    00063 {
    00064 volatile unsigned portLONG ulIntStatus, ulEventStatus;
    00065 portBASE_TYPE xSwitchRequired = pdFALSE;
    00066 extern void vClearEMACTxBuffer( void );
    00067
    00068   /* Find the cause of the interrupt. */
    00069   ulIntStatus = AT91C_BASE_EMAC->EMAC_ISR;
    00070   ulEventStatus = AT91C_BASE_EMAC->EMAC_RSR;
    00071
    00072   if( ( ulIntStatus & AT91C_EMAC_RCOMP ) || ( ulEventStatus & AT91C_EMAC_REC ) )
    00073   {
    00074     /* A frame has been received, signal the lwIP task so it can process
    00075     the Rx descriptors. */
    00076     xSwitchRequired = xSemaphoreGiveFromISR( xSemaphore, pdFALSE );
    00077     AT91C_BASE_EMAC->EMAC_RSR = AT91C_EMAC_REC;
    00078   }
    00079
    00080   if( ulIntStatus & AT91C_EMAC_TCOMP )
    00081   {
    00082     /* A frame has been transmitted.  Mark all the buffers used by the
    00083     frame just transmitted as free again. */
    00084     vClearEMACTxBuffer();
    00085     AT91C_BASE_EMAC->EMAC_TSR = AT91C_EMAC_COMP;
    00086   }
    00087
    00088   /* Clear the interrupt. */
    00089   AT91C_BASE_AIC->AIC_EOICR = 0;
    00090
    00091   /* If a task was woken by either a frame being received then we may need to
    00092   switch to another task.  If the unblocked task was of higher priority then
    00093   the interrupted task it will then execute immediately that the ISR
    00094   completes. */
    00095   if( xSwitchRequired )
    00096   {
    00097     portYIELD_FROM_ISR();
    00098   }
    00099 }
    00100 /*-----------------------------------------------------------*/
    00101
    00102 void  vEMACISR_Wrapper( void )
    00103 {
    00104   /* Save the context of the interrupted task. */
    00105   portSAVE_CONTEXT();
    00106
    00107   /* Call the handler to do the work.  This must be a separate
    00108   function to ensure the stack frame is set up correctly. */
    00109   vEMACISR_Handler();
    00110
    00111   /* Restore the context of whichever task will execute next. */
    00112   portRESTORE_CONTEXT();
    00113 }
    00114 /*-----------------------------------------------------------*/
    00115
    00116 void vPassEMACSemaphore( xSemaphoreHandle xCreatedSemaphore )
    00117 {
    00118   /* Simply store the semaphore that should be used by the ISR. */
    00119   xSemaphore = xCreatedSemaphore;
    00120 }
    00121
    00122 #endif // MAKE_CTRL_NETWORK
    00123

The Make Controller Kit is an open source project maintained by MakingThings.
MakingThings code is released under the Apache 2.0 license.
Bug tracker, development wiki and status can be found at http://dev.makingthings.com.
This document was last updated on 18 May 2009.