]> git.sur5r.net Git - freertos/blobdiff - Demo/ARM7_LPC2129_IAR/serial/serial.c
Start to re-arrange files to include FreeRTOS+ in main download.
[freertos] / Demo / ARM7_LPC2129_IAR / serial / serial.c
index 53c8967a2246da11d5257b8e3f0045cce57a14e4..bbf686c5e7d92e99951e3a43d2e671b4e19f7533 100644 (file)
@@ -1,33 +1,67 @@
 /*\r
-       FreeRTOS.org V4.0.4 - Copyright (C) 2003-2006 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
+    FreeRTOS V7.1.1 - Copyright (C) 2012 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
+    ***************************************************************************\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
+    \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
 \r
 /*-----------------------------------------------------------*/\r
 \r
 /* Constants to setup and access the UART. */\r
-#define serDLAB                                                        ( ( unsigned portCHAR ) 0x80 )\r
-#define serENABLE_INTERRUPTS                   ( ( unsigned portCHAR ) 0x03 )\r
-#define serNO_PARITY                                   ( ( unsigned portCHAR ) 0x00 )\r
-#define ser1_STOP_BIT                                  ( ( unsigned portCHAR ) 0x00 )\r
-#define ser8_BIT_CHARS                                 ( ( unsigned portCHAR ) 0x03 )\r
-#define serFIFO_ON                                             ( ( unsigned portCHAR ) 0x01 )\r
-#define serCLEAR_FIFO                                  ( ( unsigned portCHAR ) 0x06 )\r
-#define serWANTED_CLOCK_SCALING                        ( ( unsigned portLONG ) 16 )\r
+#define serDLAB                                                        ( ( unsigned char ) 0x80 )\r
+#define serENABLE_INTERRUPTS                   ( ( unsigned char ) 0x03 )\r
+#define serNO_PARITY                                   ( ( unsigned char ) 0x00 )\r
+#define ser1_STOP_BIT                                  ( ( unsigned char ) 0x00 )\r
+#define ser8_BIT_CHARS                                 ( ( unsigned char ) 0x03 )\r
+#define serFIFO_ON                                             ( ( unsigned char ) 0x01 )\r
+#define serCLEAR_FIFO                                  ( ( unsigned char ) 0x06 )\r
+#define serWANTED_CLOCK_SCALING                        ( ( unsigned long ) 16 )\r
 \r
 /* Constants to setup and access the VIC. */\r
-#define serU0VIC_CHANNEL                               ( ( unsigned portLONG ) 0x0006 )\r
-#define serU0VIC_CHANNEL_BIT                   ( ( unsigned portLONG ) 0x0040 )\r
-#define serU0VIC_ENABLE                                        ( ( unsigned portLONG ) 0x0020 )\r
-#define serCLEAR_VIC_INTERRUPT                 ( ( unsigned portLONG ) 0 )\r
+#define serU0VIC_CHANNEL                               ( ( unsigned long ) 0x0006 )\r
+#define serU0VIC_CHANNEL_BIT                   ( ( unsigned long ) 0x0040 )\r
+#define serU0VIC_ENABLE                                        ( ( unsigned long ) 0x0020 )\r
+#define serCLEAR_VIC_INTERRUPT                 ( ( unsigned long ) 0 )\r
 \r
 /* Constants to determine the ISR source. */\r
-#define serSOURCE_THRE                                 ( ( unsigned portCHAR ) 0x02 )\r
-#define serSOURCE_RX_TIMEOUT                   ( ( unsigned portCHAR ) 0x0c )\r
-#define serSOURCE_ERROR                                        ( ( unsigned portCHAR ) 0x06 )\r
-#define serSOURCE_RX                                   ( ( unsigned portCHAR ) 0x04 )\r
-#define serINTERRUPT_SOURCE_MASK               ( ( unsigned portCHAR ) 0x0f )\r
+#define serSOURCE_THRE                                 ( ( unsigned char ) 0x02 )\r
+#define serSOURCE_RX_TIMEOUT                   ( ( unsigned char ) 0x0c )\r
+#define serSOURCE_ERROR                                        ( ( unsigned char ) 0x06 )\r
+#define serSOURCE_RX                                   ( ( unsigned char ) 0x04 )\r
+#define serINTERRUPT_SOURCE_MASK               ( ( unsigned char ) 0x0f )\r
 \r
 /* Misc. */\r
 #define serINVALID_QUEUE                               ( ( xQueueHandle ) 0 )\r
 transmitted. */\r
 static xQueueHandle xRxedChars;\r
 static xQueueHandle xCharsForTx;\r
-static volatile portLONG lTHREEmpty = pdFALSE;\r
+static volatile long lTHREEmpty = pdFALSE;\r
 \r
 /*-----------------------------------------------------------*/\r
 \r
@@ -93,15 +127,15 @@ __arm void vSerialISR( void );
 \r
 /*-----------------------------------------------------------*/\r
 \r
-xComPortHandle xSerialPortInitMinimal( unsigned portLONG ulWantedBaud, unsigned portBASE_TYPE uxQueueLength )\r
+xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud, unsigned portBASE_TYPE uxQueueLength )\r
 {\r
-unsigned portLONG ulDivisor, ulWantedClock;\r
+unsigned long ulDivisor, ulWantedClock;\r
 xComPortHandle xReturn = serHANDLE;\r
 extern void ( vSerialISREntry) ( void );\r
 \r
        /* Create the queues used to hold Rx and Tx characters. */\r
-       xRxedChars = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( signed portCHAR ) );\r
-       xCharsForTx = xQueueCreate( uxQueueLength + 1, ( unsigned portBASE_TYPE ) sizeof( signed portCHAR ) );\r
+       xRxedChars = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( signed char ) );\r
+       xCharsForTx = xQueueCreate( uxQueueLength + 1, ( unsigned portBASE_TYPE ) sizeof( signed char ) );\r
 \r
        /* Initialise the THRE empty flag. */\r
        lTHREEmpty = pdTRUE;\r
@@ -109,7 +143,7 @@ extern void ( vSerialISREntry) ( void );
        if(\r
                ( xRxedChars != serINVALID_QUEUE ) &&\r
                ( xCharsForTx != serINVALID_QUEUE ) &&\r
-               ( ulWantedBaud != ( unsigned portLONG ) 0 )\r
+               ( ulWantedBaud != ( unsigned long ) 0 )\r
          )\r
        {\r
                portENTER_CRITICAL();\r
@@ -122,9 +156,9 @@ extern void ( vSerialISREntry) ( void );
                        U0LCR |= serDLAB;\r
 \r
                        /* Setup the divisor. */\r
-                       U0DLL = ( unsigned portCHAR ) ( ulDivisor & ( unsigned portLONG ) 0xff );\r
+                       U0DLL = ( unsigned char ) ( ulDivisor & ( unsigned long ) 0xff );\r
                        ulDivisor >>= 8;\r
-                       U0DLM = ( unsigned portCHAR ) ( ulDivisor & ( unsigned portLONG ) 0xff );\r
+                       U0DLM = ( unsigned char ) ( ulDivisor & ( unsigned long ) 0xff );\r
 \r
                        /* Turn on the FIFO's and clear the buffers. */\r
                        U0FCR = ( serFIFO_ON | serCLEAR_FIFO );\r
@@ -135,7 +169,7 @@ extern void ( vSerialISREntry) ( void );
                        /* Setup the VIC for the UART. */\r
                        VICIntSelect &= ~( serU0VIC_CHANNEL_BIT );\r
                        VICIntEnable |= serU0VIC_CHANNEL_BIT;\r
-                       VICVectAddr1 = ( unsigned portLONG ) vSerialISREntry;\r
+                       VICVectAddr1 = ( unsigned long ) vSerialISREntry;\r
                        VICVectCntl1 = serU0VIC_CHANNEL | serU0VIC_ENABLE;\r
 \r
                        /* Enable UART0 interrupts. */\r
@@ -154,7 +188,7 @@ extern void ( vSerialISREntry) ( void );
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-signed portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, signed portCHAR *pcRxedChar, portTickType xBlockTime )\r
+signed portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, signed char *pcRxedChar, portTickType xBlockTime )\r
 {\r
        /* The port handle is not required as this driver only supports UART0. */\r
        ( void ) pxPort;\r
@@ -172,9 +206,9 @@ signed portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, signed portCHAR *pcR
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-void vSerialPutString( xComPortHandle pxPort, const signed portCHAR * const pcString, unsigned portSHORT usStringLength )\r
+void vSerialPutString( xComPortHandle pxPort, const signed char * const pcString, unsigned short usStringLength )\r
 {\r
-signed portCHAR *pxNext;\r
+signed char *pxNext;\r
 \r
        /* NOTE: This implementation does not handle the queue being full as no\r
        block time is used! */\r
@@ -184,7 +218,7 @@ signed portCHAR *pxNext;
        ( void ) usStringLength;\r
 \r
        /* Send each character in the string, one at a time. */\r
-       pxNext = ( signed portCHAR * ) pcString;\r
+       pxNext = ( signed char * ) pcString;\r
        while( *pxNext )\r
        {\r
                xSerialPutChar( pxPort, *pxNext, serNO_BLOCK );\r
@@ -193,7 +227,7 @@ signed portCHAR *pxNext;
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-signed portBASE_TYPE xSerialPutChar( xComPortHandle pxPort, signed portCHAR cOutChar, portTickType xBlockTime )\r
+signed portBASE_TYPE xSerialPutChar( xComPortHandle pxPort, signed char cOutChar, portTickType xBlockTime )\r
 {\r
 signed portBASE_TYPE xReturn;\r
 \r
@@ -203,7 +237,7 @@ signed portBASE_TYPE xReturn;
        portENTER_CRITICAL();\r
        {\r
                /* Is there space to write directly to the UART? */\r
-               if( lTHREEmpty == ( portLONG ) pdTRUE )\r
+               if( lTHREEmpty == ( long ) pdTRUE )\r
                {\r
                        /* We wrote the character directly to the UART, so was\r
                        successful. */\r
@@ -223,7 +257,7 @@ signed portBASE_TYPE xReturn;
                        were blocked waiting to post interrupts were not disabled.  It is\r
                        possible that the serial ISR has emptied the Tx queue, in which\r
                        case we need to start the Tx off again. */\r
-                       if( lTHREEmpty == ( portLONG ) pdTRUE )\r
+                       if( lTHREEmpty == ( long ) pdTRUE )\r
                        {\r
                                xQueueReceive( xCharsForTx, &cOutChar, serNO_BLOCK );\r
                                lTHREEmpty = pdFALSE;\r
@@ -239,8 +273,8 @@ signed portBASE_TYPE xReturn;
 \r
 __arm void vSerialISR( void )\r
 {\r
-signed portCHAR cChar;\r
-portBASE_TYPE xTaskWokenByRx = pdFALSE, xTaskWokenByTx = pdFALSE;\r
+signed char cChar;\r
+portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;\r
 \r
        /* What caused the interrupt? */\r
        switch( U0IIR & serINTERRUPT_SOURCE_MASK )\r
@@ -251,7 +285,7 @@ portBASE_TYPE xTaskWokenByRx = pdFALSE, xTaskWokenByTx = pdFALSE;
 \r
                case serSOURCE_THRE     :       /* The THRE is empty.  If there is another\r
                                                                character in the Tx queue, send it now. */\r
-                                                               if( xQueueReceiveFromISR( xCharsForTx, &cChar, &xTaskWokenByTx ) == pdTRUE )\r
+                                                               if( xQueueReceiveFromISR( xCharsForTx, &cChar, &xHigherPriorityTaskWoken ) == pdTRUE )\r
                                                                {\r
                                                                        U0THR = cChar;\r
                                                                }\r
@@ -268,10 +302,7 @@ portBASE_TYPE xTaskWokenByRx = pdFALSE, xTaskWokenByTx = pdFALSE;
                case serSOURCE_RX       :       /* A character was received.  Place it in\r
                                                                the queue of received characters. */\r
                                                                cChar = U0RBR;\r
-                                                               if( xQueueSendFromISR( xRxedChars, &cChar, pdFALSE ) )\r
-                                                               {\r
-                                                                       xTaskWokenByRx = pdTRUE;\r
-                                                               }\r
+                                                               xQueueSendFromISR( xRxedChars, &cChar, &xHigherPriorityTaskWoken );\r
                                                                break;\r
 \r
                default                         :       /* There is nothing to do, leave the ISR. */\r
@@ -280,7 +311,7 @@ portBASE_TYPE xTaskWokenByRx = pdFALSE, xTaskWokenByTx = pdFALSE;
 \r
        /* Exit the ISR.  If a task was woken by either a character being received\r
        or transmitted then a context switch will occur. */\r
-       portEND_SWITCHING_ISR( ( xTaskWokenByTx || xTaskWokenByRx ) );\r
+       portEND_SWITCHING_ISR( xHigherPriorityTaskWoken );\r
 \r
        /* Clear the ISR in the VIC. */\r
        VICVectAddr = serCLEAR_VIC_INTERRUPT;\r