]> git.sur5r.net Git - freertos/blobdiff - Demo/WizNET_DEMO_GCC_ARM7/i2cISR.c
Update lwIP port layer for the Microblaze Ethernet Lite IP.
[freertos] / Demo / WizNET_DEMO_GCC_ARM7 / i2cISR.c
index 96f31b1addb4c3692e8a12075d4958bb707ff055..320ba6021d8ef3eb12551155e61f3caa227703be 100644 (file)
@@ -1,36 +1,54 @@
 /*\r
-       FreeRTOS.org V4.4.0 - Copyright (C) 2003-2007 Richard Barry.\r
-\r
-       This file is part of the FreeRTOS.org distribution.\r
-\r
-       FreeRTOS.org is free software; you can redistribute it and/or modify\r
-       it under the terms of the GNU General Public License as published by\r
-       the Free Software Foundation; either version 2 of the License, or\r
-       (at your option) any later version.\r
-\r
-       FreeRTOS.org is distributed in the hope that it will be useful,\r
-       but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
-       GNU General Public License for more details.\r
-\r
-       You should have received a copy of the GNU General Public License\r
-       along with FreeRTOS.org; if not, write to the Free Software\r
-       Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
-\r
-       A special exception to the GPL can be applied should you wish to distribute\r
-       a combined work that includes FreeRTOS.org, without being obliged to provide\r
-       the source code for any proprietary components.  See the licensing section \r
-       of http://www.FreeRTOS.org for full details of how and when the exception\r
-       can be applied.\r
-\r
-       ***************************************************************************\r
-       See http://www.FreeRTOS.org for documentation, latest information, license \r
-       and contact details.  Please ensure to read the configuration and relevant \r
-       port sections of the online documentation.\r
-\r
-       Also see http://www.SafeRTOS.com for an IEC 61508 compliant version along\r
-       with commercial development and support options.\r
-       ***************************************************************************\r
+    FreeRTOS V7.0.1 - Copyright (C) 2011 Real Time Engineers Ltd.\r
+       \r
+\r
+    ***************************************************************************\r
+     *                                                                       *\r
+     *    FreeRTOS tutorial books are available in pdf and paperback.        *\r
+     *    Complete, revised, and edited pdf reference manuals are also       *\r
+     *    available.                                                         *\r
+     *                                                                       *\r
+     *    Purchasing FreeRTOS documentation will not only help you, by       *\r
+     *    ensuring you get running as quickly as possible and with an        *\r
+     *    in-depth knowledge of how to use FreeRTOS, it will also help       *\r
+     *    the FreeRTOS project to continue with its mission of providing     *\r
+     *    professional grade, cross platform, de facto standard solutions    *\r
+     *    for microcontrollers - completely free of charge!                  *\r
+     *                                                                       *\r
+     *    >>> See http://www.FreeRTOS.org/Documentation for details. <<<     *\r
+     *                                                                       *\r
+     *    Thank you for using FreeRTOS, and thank you for your support!      *\r
+     *                                                                       *\r
+    ***************************************************************************\r
+\r
+\r
+    This file is part of the FreeRTOS distribution.\r
+\r
+    FreeRTOS is free software; you can redistribute it and/or modify it under\r
+    the terms of the GNU General Public License (version 2) as published by the\r
+    Free Software Foundation AND MODIFIED BY the FreeRTOS exception.\r
+    >>>NOTE<<< The modification to the GPL is included to allow you to\r
+    distribute a combined work that includes FreeRTOS without being obliged to\r
+    provide the source code for proprietary components outside of the FreeRTOS\r
+    kernel.  FreeRTOS is distributed in the hope that it will be useful, but\r
+    WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
+    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for\r
+    more details. You should have received a copy of the GNU General Public\r
+    License and the FreeRTOS license exception along with FreeRTOS; if not it\r
+    can be viewed here: http://www.freertos.org/a00114.html and also obtained\r
+    by writing to Richard Barry, contact details for whom are available on the\r
+    FreeRTOS WEB site.\r
+\r
+    1 tab == 4 spaces!\r
+\r
+    http://www.FreeRTOS.org - Documentation, latest information, license and\r
+    contact details.\r
+\r
+    http://www.SafeRTOS.com - A version that is certified for use in safety\r
+    critical systems.\r
+\r
+    http://www.OpenRTOS.com - Commercial support, development, porting,\r
+    licensing and training services.\r
 */\r
 \r
 \r
 /*-----------------------------------------------------------*/\r
 \r
 /* Bit definitions within the I2CONCLR register. */\r
-#define i2cSTA_BIT             ( ( unsigned portCHAR ) 0x20 )\r
-#define i2cSI_BIT              ( ( unsigned portCHAR ) 0x08 )\r
-#define i2cSTO_BIT             ( ( unsigned portCHAR ) 0x10 )\r
-#define i2cAA_BIT              ( ( unsigned portCHAR ) 0x04 )\r
+#define i2cSTA_BIT             ( ( unsigned char ) 0x20 )\r
+#define i2cSI_BIT              ( ( unsigned char ) 0x08 )\r
+#define i2cSTO_BIT             ( ( unsigned char ) 0x10 )\r
+#define i2cAA_BIT              ( ( unsigned char ) 0x04 )\r
 \r
 /* Status codes for the I2STAT register. */\r
 #define i2cSTATUS_START_TXED                   ( 0x08 )\r
@@ -98,16 +116,16 @@ volatile xI2CMessage *pxCurrentMessage = NULL;
 static xQueueHandle xMessagesForTx;\r
 \r
 /* Flag used to indicate whether or not the ISR is amid sending a message. */\r
-unsigned portLONG ulBusFree = ( unsigned portLONG ) pdTRUE;\r
+unsigned long ulBusFree = ( unsigned long ) pdTRUE;\r
 \r
 /* Setting this to true will cause the TCP task to think a message is \r
 complete and thus restart.  It can therefore be used under error states\r
 to force a restart. */\r
-volatile portLONG lTransactionCompleted = pdTRUE;\r
+volatile long lTransactionCompleted = pdTRUE;\r
 \r
 /*-----------------------------------------------------------*/\r
 \r
-void vI2CISRCreateQueues( unsigned portBASE_TYPE uxQueueLength, xQueueHandle *pxTxMessages, unsigned portLONG **ppulBusFree )\r
+void vI2CISRCreateQueues( unsigned portBASE_TYPE uxQueueLength, xQueueHandle *pxTxMessages, unsigned long **ppulBusFree )\r
 {\r
        /* Create the queues used to hold Rx and Tx characters. */\r
        xMessagesForTx = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( xI2CMessage * ) );\r
@@ -119,16 +137,36 @@ void vI2CISRCreateQueues( unsigned portBASE_TYPE uxQueueLength, xQueueHandle *px
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-void vI2C_ISR( void ) __attribute__ (( naked ));\r
-void vI2C_ISR( void )\r
+/* The ISR entry point. */\r
+void vI2C_ISR_Wrapper( void ) __attribute__ (( naked ));\r
+\r
+/* The ISR function to perform the actual work.  This must be a separate\r
+function from the wrapper to ensure the correct stack frame is set up. */\r
+void vI2C_ISR_Handler( void );\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
+void vI2C_ISR_Wrapper( void )\r
 {\r
-       portENTER_SWITCHING_ISR();\r
+       /* Save the context of the interrupted task. */\r
+       portSAVE_CONTEXT();\r
+\r
+       /* Call the handler to perform the actual work.  This must be a\r
+       separate function to ensure the correct stack frame is set up. */\r
+       vI2C_ISR_Handler();\r
 \r
-       /* Holds the current transmission state. */                                                     \r
-       static I2C_STATE eCurrentState = eSentStart;\r
-       static portLONG lMessageIndex = -i2cBUFFER_ADDRESS_BYTES; /* There are two address bytes to send prior to the data. */\r
-       portBASE_TYPE xTaskWokenByTx = pdFALSE;\r
-       portLONG lBytesLeft;\r
+       /* Restore the context of whichever task is going to run next. */\r
+       portRESTORE_CONTEXT();\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+void vI2C_ISR_Handler( void )\r
+{\r
+/* Holds the current transmission state. */                                                    \r
+static I2C_STATE eCurrentState = eSentStart;\r
+static long lMessageIndex = -i2cBUFFER_ADDRESS_BYTES; /* There are two address bytes to send prior to the data. */\r
+portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;\r
+long lBytesLeft;\r
 \r
        /* The action taken for this interrupt depends on our current state. */\r
        switch( eCurrentState )\r
@@ -224,7 +262,7 @@ void vI2C_ISR( void )
 \r
                                        /* How many more bytes are we expecting to receive? */\r
                                        lBytesLeft = pxCurrentMessage->lMessageLength - lMessageIndex;\r
-                                       if( lBytesLeft == ( unsigned portLONG ) 0 )\r
+                                       if( lBytesLeft == ( unsigned long ) 0 )\r
                                        {\r
                                                /* This was the last byte in the message. */\r
                                                i2cEND_TRANSMISSION( pdPASS );\r
@@ -234,11 +272,11 @@ void vI2C_ISR( void )
                                                must 'give' the semaphore so the task is woken.*/\r
                                                if( pxCurrentMessage->xMessageCompleteSemaphore )\r
                                                {\r
-                                                       xTaskWokenByTx = xSemaphoreGiveFromISR( pxCurrentMessage->xMessageCompleteSemaphore, xTaskWokenByTx );\r
+                                                       xSemaphoreGiveFromISR( pxCurrentMessage->xMessageCompleteSemaphore, &xHigherPriorityTaskWoken );\r
                                                }\r
 \r
                                                /* Are there any other messages to transact? */\r
-                                               if( xQueueReceiveFromISR( xMessagesForTx, &pxCurrentMessage, &xTaskWokenByTx ) == pdTRUE )\r
+                                               if( xQueueReceiveFromISR( xMessagesForTx, &pxCurrentMessage, &xHigherPriorityTaskWoken ) == pdTRUE )\r
                                                {\r
                                                        /* Start the next message - which was\r
                                                        retrieved from the queue. */\r
@@ -248,7 +286,7 @@ void vI2C_ISR( void )
                                                {\r
                                                        /* No more messages were found to be waiting for\r
                                                        transaction so the bus is free. */\r
-                                                       ulBusFree = ( unsigned portLONG ) pdTRUE;                       \r
+                                                       ulBusFree = ( unsigned long ) pdTRUE;                   \r
                                                }                                               \r
                                        }\r
                                        else\r
@@ -302,11 +340,11 @@ void vI2C_ISR( void )
                                                semaphore must be 'given' to wake the task. */\r
                                                if( pxCurrentMessage->xMessageCompleteSemaphore )\r
                                                {\r
-                                                       xTaskWokenByTx = xSemaphoreGiveFromISR( pxCurrentMessage->xMessageCompleteSemaphore, xTaskWokenByTx );\r
+                                                       xSemaphoreGiveFromISR( pxCurrentMessage->xMessageCompleteSemaphore, &xHigherPriorityTaskWoken );\r
                                                }\r
 \r
                                                /* Are there any other messages to transact? */\r
-                                               if( xQueueReceiveFromISR( xMessagesForTx, &pxCurrentMessage, &xTaskWokenByTx ) == pdTRUE )\r
+                                               if( xQueueReceiveFromISR( xMessagesForTx, &pxCurrentMessage, &xHigherPriorityTaskWoken ) == pdTRUE )\r
                                                {\r
                                                        /* Start the next message from the Tx queue. */\r
                                                        I2C_I2CONSET = i2cSTA_BIT;\r
@@ -315,7 +353,7 @@ void vI2C_ISR( void )
                                                {\r
                                                        /* No more message were queues for transaction so \r
                                                        the bus is free. */\r
-                                                       ulBusFree = ( unsigned portLONG ) pdTRUE;                       \r
+                                                       ulBusFree = ( unsigned long ) pdTRUE;                   \r
                                                }\r
                                        }\r
                                }\r
@@ -337,7 +375,10 @@ void vI2C_ISR( void )
        I2C_I2CONCLR = i2cSI_BIT;\r
        VICVectAddr = i2cCLEAR_VIC_INTERRUPT;\r
 \r
-       portEXIT_SWITCHING_ISR( ( xTaskWokenByTx ) );\r
+       if( xHigherPriorityTaskWoken )\r
+       {\r
+               portYIELD_FROM_ISR();\r
+       }\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r