]> git.sur5r.net Git - freertos/blobdiff - Demo/CORTEX_CY8C5588_PSoC_Creator_GCC/FreeRTOS_Demo.cydsn/Serial.c
Start to re-arrange files to include FreeRTOS+ in main download.
[freertos] / Demo / CORTEX_CY8C5588_PSoC_Creator_GCC / FreeRTOS_Demo.cydsn / Serial.c
index a82d0c00a345da24590b9b00be805393fb93fd18..4e27940f0d4c8e60b798d5622fd29dc67a0d69d1 100644 (file)
@@ -1,54 +1,67 @@
 /*\r
-    FreeRTOS V6.1.0 - Copyright (C) 2010 Real Time Engineers Ltd.\r
+    FreeRTOS V7.1.1 - Copyright (C) 2012 Real Time Engineers Ltd.\r
+       \r
 \r
     ***************************************************************************\r
-    *                                                                         *\r
-    * If you are:                                                             *\r
-    *                                                                         *\r
-    *    + New to FreeRTOS,                                                   *\r
-    *    + Wanting to learn FreeRTOS or multitasking in general quickly       *\r
-    *    + Looking for basic training,                                        *\r
-    *    + Wanting to improve your FreeRTOS skills and productivity           *\r
-    *                                                                         *\r
-    * then take a look at the FreeRTOS books - available as PDF or paperback  *\r
-    *                                                                         *\r
-    *        "Using the FreeRTOS Real Time Kernel - a Practical Guide"        *\r
-    *                  http://www.FreeRTOS.org/Documentation                  *\r
-    *                                                                         *\r
-    * A pdf reference manual is also available.  Both are usually delivered   *\r
-    * to your inbox within 20 minutes to two hours when purchased between 8am *\r
-    * and 8pm GMT (although please allow up to 24 hours in case of            *\r
-    * exceptional circumstances).  Thank you for your support!                *\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 exception to the GPL is included to allow you to distribute\r
-    a combined work that includes FreeRTOS without being obliged to provide the\r
-    source code for proprietary components outside of the FreeRTOS kernel.\r
-    FreeRTOS is distributed in the hope that it will be useful, but WITHOUT\r
-    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\r
-    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
+    >>>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
+    ***************************************************************************\r
+     *                                                                       *\r
+     *    Having a problem?  Start by reading the FAQ "My application does   *\r
+     *    not run, what could be wrong?                                      *\r
+     *                                                                       *\r
+     *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
+     *                                                                       *\r
+    ***************************************************************************\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
+    http://www.FreeRTOS.org - Documentation, training, latest information, \r
+    license and contact details.\r
+    \r
+    http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
+    including FreeRTOS+Trace - an indispensable productivity tool.\r
+\r
+    Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell \r
+    the code with commercial support, indemnification, and middleware, under \r
+    the OpenRTOS brand: http://www.OpenRTOS.com.  High Integrity Systems also\r
+    provide a safety engineered and independently SIL3 certified version under \r
+    the SafeRTOS brand: http://www.SafeRTOS.com.\r
 */\r
 \r
 #include <device.h>\r
@@ -61,8 +74,8 @@
 #define serialSTRING_DELAY_TICKS               ( portMAX_DELAY )\r
 /*---------------------------------------------------------------------------*/\r
 \r
-CY_ISR_PROTO(vUartRxISR);\r
-CY_ISR_PROTO(vUartTxISR);\r
+CY_ISR_PROTO( vUartRxISR );\r
+CY_ISR_PROTO( vUartTxISR );\r
 /*---------------------------------------------------------------------------*/\r
 \r
 static xQueueHandle xSerialTxQueue = NULL;\r
@@ -85,23 +98,24 @@ xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud, unsigned port
        UART_1_SetTxInterruptMode( 0 );\r
 \r
        /* Both configured successfully. */\r
-       return (xComPortHandle)( xSerialTxQueue && xSerialRxQueue );\r
+       return ( xComPortHandle )( xSerialTxQueue && xSerialRxQueue );\r
 }\r
 /*---------------------------------------------------------------------------*/\r
 \r
 void vSerialPutString( xComPortHandle pxPort, const signed char * const pcString, unsigned short usStringLength )\r
 {\r
 unsigned short usIndex = 0;\r
-       for ( usIndex = 0; usIndex < usStringLength; usIndex++ )\r
+\r
+       for( usIndex = 0; usIndex < usStringLength; usIndex++ )\r
        {\r
                /* Check for pre-mature end of line. */\r
-               if ( '\0' == pcString[ usIndex ] )\r
+               if( '\0' == pcString[ usIndex ] )\r
                {\r
                        break;\r
                }\r
                \r
                /* Send out, one character at a time. */\r
-               if ( pdTRUE != xSerialPutChar( NULL, pcString[ usIndex ], serialSTRING_DELAY_TICKS ) )\r
+               if( pdTRUE != xSerialPutChar( NULL, pcString[ usIndex ], serialSTRING_DELAY_TICKS ) )\r
                {\r
                        /* Failed to send, this will be picked up in the receive comtest task. */\r
                }\r
@@ -112,7 +126,8 @@ unsigned short usIndex = 0;
 signed portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, signed char *pcRxedChar, portTickType xBlockTime )\r
 {\r
 portBASE_TYPE xReturn = pdFALSE;\r
-       if ( pdTRUE == xQueueReceive( xSerialRxQueue, pcRxedChar, xBlockTime ) )\r
+\r
+       if( pdTRUE == xQueueReceive( xSerialRxQueue, pcRxedChar, xBlockTime ) )\r
        {\r
                /* Picked up a character. */\r
                xReturn = pdTRUE;\r
@@ -126,7 +141,7 @@ signed portBASE_TYPE xSerialPutChar( xComPortHandle pxPort, signed char cOutChar
 portBASE_TYPE xReturn = pdFALSE;\r
 \r
        /* The ISR is processing characters is so just add to the end of the queue. */\r
-       if ( pdTRUE == xQueueSend( xSerialTxQueue, &cOutChar, xBlockTime ) )\r
+       if( pdTRUE == xQueueSend( xSerialTxQueue, &cOutChar, xBlockTime ) )\r
        {       \r
                xReturn = pdTRUE;\r
        }\r
@@ -137,9 +152,8 @@ portBASE_TYPE xReturn = pdFALSE;
        }\r
 \r
        /* Make sure that the interrupt will fire in the case where:\r
-       *     Currently sending so the Tx Complete will fire.\r
-       *     Not sending so the Empty will fire.\r
-       */\r
+           Currently sending so the Tx Complete will fire.\r
+           Not sending so the Empty will fire. */\r
        taskENTER_CRITICAL();\r
                UART_1_SetTxInterruptMode( UART_1_TX_STS_COMPLETE | UART_1_TX_STS_FIFO_EMPTY );\r
        taskEXIT_CRITICAL();\r
@@ -150,7 +164,7 @@ portBASE_TYPE xReturn = pdFALSE;
 \r
 CY_ISR(vUartRxISR)\r
 {\r
-portBASE_TYPE xTaskWoken = pdFALSE;\r
+portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;\r
 volatile unsigned char ucStatus = 0;\r
 signed char cInChar = 0;\r
 unsigned long ulMask = 0;\r
@@ -159,7 +173,7 @@ unsigned long ulMask = 0;
        ucStatus = UART_1_ReadRxStatus();\r
 \r
        /* Only interested in a character being received. */\r
-       if ( 0 != ( ucStatus & UART_1_RX_STS_FIFO_NOTEMPTY ) )\r
+       if( 0 != ( ucStatus & UART_1_RX_STS_FIFO_NOTEMPTY ) )\r
        {\r
                /* Get the character. */\r
                cInChar = UART_1_GetChar();\r
@@ -168,7 +182,7 @@ unsigned long ulMask = 0;
                ulMask = portSET_INTERRUPT_MASK_FROM_ISR();\r
                {\r
                        /* Try to deliver the character. */\r
-                       if ( pdTRUE != xQueueSendFromISR( xSerialRxQueue, &cInChar, &xTaskWoken ) )\r
+                       if( pdTRUE != xQueueSendFromISR( xSerialRxQueue, &cInChar, &xHigherPriorityTaskWoken ) )\r
                        {\r
                                /* Run out of space. */\r
                        }\r
@@ -176,14 +190,20 @@ unsigned long ulMask = 0;
                portCLEAR_INTERRUPT_MASK_FROM_ISR( ulMask );\r
        }\r
 \r
-       /* If we delivered the character then a context switch might be required. */\r
-       portEND_SWITCHING_ISR( xTaskWoken );\r
+       /* If we delivered the character then a context switch might be required.\r
+       xHigherPriorityTaskWoken was set to pdFALSE on interrupt entry.  If calling \r
+       xQueueSendFromISR() caused a task to unblock, and the unblocked task has\r
+       a priority equal to or higher than the currently running task (the task this\r
+       ISR interrupted), then xHigherPriorityTaskWoken will have been set to pdTRUE and\r
+       portEND_SWITCHING_ISR() will request a context switch to the newly unblocked\r
+       task. */\r
+       portEND_SWITCHING_ISR( xHigherPriorityTaskWoken );\r
 }\r
 /*---------------------------------------------------------------------------*/\r
 \r
 CY_ISR(vUartTxISR)\r
 {\r
-portBASE_TYPE xTaskWoken = pdFALSE;\r
+portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;\r
 volatile unsigned char ucStatus = 0;\r
 signed char cOutChar = 0;\r
 unsigned long ulMask = 0;\r
@@ -192,35 +212,38 @@ unsigned long ulMask = 0;
        ucStatus = UART_1_ReadTxStatus();\r
        \r
        /* Check to see whether this is a genuine interrupt. */\r
-       if ( ( 0 != ( ucStatus & UART_1_TX_STS_COMPLETE ) )\r
-               || ( 0 != ( ucStatus & UART_1_TX_STS_FIFO_EMPTY ) ) )\r
+       if( ( 0 != ( ucStatus & UART_1_TX_STS_COMPLETE ) ) || ( 0 != ( ucStatus & UART_1_TX_STS_FIFO_EMPTY ) ) )\r
        {       \r
                /* Mask off the other RTOS interrupts to interact with the queue. */\r
                ulMask = portSET_INTERRUPT_MASK_FROM_ISR();\r
                {\r
-                       if ( pdTRUE == xQueueReceiveFromISR( xSerialTxQueue, &cOutChar, &xTaskWoken ) )\r
+                       if( pdTRUE == xQueueReceiveFromISR( xSerialTxQueue, &cOutChar, &xHigherPriorityTaskWoken ) )\r
                        {\r
                                /* Send the next character. */\r
                                UART_1_PutChar( cOutChar );                     \r
 \r
                                /* If we are firing, then the only interrupt we are interested in\r
-                               * is the Complete. The application code will add the Empty interrupt\r
-                               * when there is something else to be done.\r
-                               */\r
+                               is the Complete. The application code will add the Empty interrupt\r
+                               when there is something else to be done. */\r
                                UART_1_SetTxInterruptMode( UART_1_TX_STS_COMPLETE );\r
                        }\r
                        else\r
                        {\r
-                               /* There is no work left so disable the interrupt\r
-                                * until the application puts more into the queue.\r
-                                */\r
+                               /* There is no work left so disable the interrupt until the application \r
+                               puts more into the queue. */\r
                                UART_1_SetTxInterruptMode( 0 );\r
                        }\r
                }\r
                portCLEAR_INTERRUPT_MASK_FROM_ISR( ulMask );\r
        }\r
 \r
-       /* If we delivered the character then a context switch might be required. */\r
-       portEND_SWITCHING_ISR( xTaskWoken );\r
+       /* If we delivered the character then a context switch might be required.\r
+       xHigherPriorityTaskWoken was set to pdFALSE on interrupt entry.  If calling \r
+       xQueueSendFromISR() caused a task to unblock, and the unblocked task has\r
+       a priority equal to or higher than the currently running task (the task this\r
+       ISR interrupted), then xHigherPriorityTaskWoken will have been set to pdTRUE and\r
+       portEND_SWITCHING_ISR() will request a context switch to the newly unblocked\r
+       task. */\r
+       portEND_SWITCHING_ISR( xHigherPriorityTaskWoken );\r
 }\r
 /*---------------------------------------------------------------------------*/\r