]> git.sur5r.net Git - freertos/blobdiff - Demo/WizNET_DEMO_TERN_186/serial/serial.c
Start to re-arrange files to include FreeRTOS+ in main download.
[freertos] / Demo / WizNET_DEMO_TERN_186 / serial / serial.c
index fa28711d8229bfdfdf623f1d46250f364c14cf1d..899fc13c617d35d8eb094dc1bb59ef19d44f396a 100644 (file)
@@ -1,36 +1,67 @@
 /*\r
-       FreeRTOS.org V4.3.1 - 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.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
@@ -42,7 +73,7 @@
 #include "task.h"\r
 #include "semphr.h"\r
 \r
-#define serMAX_PORTS                   ( ( unsigned portSHORT ) 2 )\r
+#define serMAX_PORTS                   ( ( unsigned short ) 2 )\r
 \r
 #define serPORT_0_INT_REG              ( 0xff44 )\r
 #define serPORT_0_BAUD_REG             ( 0xff88 )\r
 #define serPORT_1_CTRL_REG             ( 0xff10 )\r
 #define serPORT_1_IRQ                  ( 0x11 )\r
 \r
-#define serTX_EMPTY                            ( ( unsigned portSHORT ) 0x40 )\r
-#define serRX_READY                            ( ( unsigned portSHORT ) 0x80 )\r
+#define serTX_EMPTY                            ( ( unsigned short ) 0x40 )\r
+#define serRX_READY                            ( ( unsigned short ) 0x80 )\r
 \r
-#define serRESET_PIC( usEOI_TYPE )     portOUTPUT_WORD( ( unsigned portSHORT ) 0xff22, usEOI_TYPE )\r
-#define serTX_HOLD_EMPTY_INT           ( ( unsigned portSHORT ) 0x100 )\r
+#define serRESET_PIC( usEOI_TYPE )     portOUTPUT_WORD( ( unsigned short ) 0xff22, usEOI_TYPE )\r
+#define serTX_HOLD_EMPTY_INT           ( ( unsigned short ) 0x100 )\r
 \r
-#define serENABLE_INTERRUPTS           ( ( unsigned portSHORT ) 0x80 )\r
-#define serMODE                                                ( ( unsigned portSHORT ) 0x01 )\r
-#define serENABLE_TX_MACHINES          ( ( unsigned portSHORT ) 0x40 )\r
-#define serENABLE_RX_MACHINES          ( ( unsigned portSHORT ) 0x20 )\r
-#define serINTERRUPT_MASK                      ( ( unsigned portSHORT ) 0x08 )\r
-#define serCLEAR_ALL_STATUS_BITS       ( ( unsigned portSHORT ) 0x00 )\r
-#define serINTERRUPT_PRIORITY          ( ( unsigned portSHORT ) 0x01 ) /*< Just below the scheduler priority. */\r
+#define serENABLE_INTERRUPTS           ( ( unsigned short ) 0x80 )\r
+#define serMODE                                                ( ( unsigned short ) 0x01 )\r
+#define serENABLE_TX_MACHINES          ( ( unsigned short ) 0x40 )\r
+#define serENABLE_RX_MACHINES          ( ( unsigned short ) 0x20 )\r
+#define serINTERRUPT_MASK                      ( ( unsigned short ) 0x08 )\r
+#define serCLEAR_ALL_STATUS_BITS       ( ( unsigned short ) 0x00 )\r
+#define serINTERRUPT_PRIORITY          ( ( unsigned short ) 0x01 ) /*< Just below the scheduler priority. */\r
 \r
 #define serDONT_BLOCK                          ( ( portTickType ) 0 )\r
 \r
@@ -135,15 +166,15 @@ typedef enum
 typedef struct xCOM_PORT\r
 {\r
        /* Hardware parameters for this port. */\r
-       portSHORT sTxInterruptOn;\r
-       unsigned portSHORT usIntReg;\r
-       unsigned portSHORT usBaudReg;\r
-       unsigned portSHORT usRxReg;\r
-       unsigned portSHORT usTxReg;\r
-       unsigned portSHORT usStatusReg;\r
-       unsigned portSHORT usCtrlReg;\r
+       short sTxInterruptOn;\r
+       unsigned short usIntReg;\r
+       unsigned short usBaudReg;\r
+       unsigned short usRxReg;\r
+       unsigned short usTxReg;\r
+       unsigned short usStatusReg;\r
+       unsigned short usCtrlReg;\r
 \r
-       unsigned portSHORT usIRQVector;\r
+       unsigned short usIRQVector;\r
 \r
        /* Queues used for communications with com test task. */\r
        xQueueHandle xRxedChars; \r
@@ -166,22 +197,22 @@ typedef xComPort * xComPortHandle;
 /**\r
  * Lookup the baud rate from the enum.\r
  */\r
-static unsigned portLONG prvBaud( eBaud eWantedBaud ); \r
+static unsigned long prvBaud( eBaud eWantedBaud ); \r
 \r
 /* These prototypes are repeated here so we don't have to include the serial header.  This allows\r
 the xComPortHandle structure details to be private to this file. */\r
 xComPortHandle xSerialPortInit( eCOMPort ePort, eBaud eWantedBaud, eParity eWantedParity, eDataBits eWantedDataBits, eStopBits eWantedStopBits, unsigned portBASE_TYPE uxBufferLength );\r
-portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, portCHAR *pcRxedChar, portTickType xBlockTime );\r
-portBASE_TYPE xSerialPutChar( xComPortHandle pxPort, portCHAR cOutChar, portTickType xBlockTime );\r
+portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, char *pcRxedChar, portTickType xBlockTime );\r
+portBASE_TYPE xSerialPutChar( xComPortHandle pxPort, char cOutChar, portTickType xBlockTime );\r
 void vSerialClose( xComPortHandle xPort );\r
-portSHORT sSerialWaitForSemaphore( xComPortHandle xPort );\r
+short sSerialWaitForSemaphore( xComPortHandle xPort );\r
 /*-----------------------------------------------------------*/\r
 \r
-static portSHORT xComPortISR( xComPort * const pxPort );\r
+static short xComPortISR( xComPort * const pxPort );\r
 \r
 #define vInterruptOn( pxPort, usInterrupt )                                                                            \\r
 {                                                                                                                                                              \\r
-unsigned portSHORT usIn;                                                                                                               \\r
+unsigned short usIn;                                                                                                           \\r
                                                                                                                                                                \\r
        portENTER_CRITICAL();                                                                                                           \\r
        {                                                                                                                                                       \\r
@@ -199,7 +230,7 @@ unsigned portSHORT usIn;                                                                                                            \
 \r
 #define vInterruptOff( pxPort, usInterrupt )                                                                   \\r
 {                                                                                                                                                              \\r
-       unsigned portSHORT usIn = portINPUT_WORD( pxPort->usCtrlReg );                          \\r
+       unsigned short usIn = portINPUT_WORD( pxPort->usCtrlReg );                              \\r
        if( usIn & usInterrupt )                                                                                                        \\r
        {                                                                                                                                                       \\r
                portOUTPUT_WORD( pxPort->usCtrlReg, usIn & ~usInterrupt);                               \\r
@@ -232,7 +263,7 @@ static pxISR xISRs[ serMAX_PORTS ] =
 \r
 /*-----------------------------------------------------------*/\r
 \r
-static unsigned portLONG prvBaud( eBaud eWantedBaud )\r
+static unsigned long prvBaud( eBaud eWantedBaud )\r
 {\r
        switch( eWantedBaud )\r
     {\r
@@ -260,9 +291,9 @@ static unsigned portLONG prvBaud( eBaud eWantedBaud )
 \r
 xComPortHandle xSerialPortInit( eCOMPort ePort, eBaud eWantedBaud, eParity eWantedParity, eDataBits eWantedDataBits, eStopBits eWantedStopBits, unsigned portBASE_TYPE uxBufferLength )\r
 {\r
-unsigned portSHORT usPort;\r
+unsigned short usPort;\r
 xComPortHandle pxPort = NULL;\r
-unsigned portLONG ulBaudDiv;\r
+unsigned long ulBaudDiv;\r
 \r
        /* BAUDDIV = ( Microprocessor Clock / Baud Rate ) / 16 */\r
     ulBaudDiv = ( configCPU_CLOCK_HZ / prvBaud( eWantedBaud ) ) / 16UL;\r
@@ -275,7 +306,7 @@ unsigned portLONG ulBaudDiv;
 \r
        /* Currently only n,8,1 is supported. */\r
 \r
-       usPort = ( unsigned portSHORT ) ePort;\r
+       usPort = ( unsigned short ) ePort;\r
        \r
        if( usPort < serMAX_PORTS )\r
        {\r
@@ -283,24 +314,24 @@ unsigned portLONG ulBaudDiv;
 \r
                portENTER_CRITICAL();\r
                {\r
-                       unsigned portSHORT usInWord;\r
+                       unsigned short usInWord;\r
 \r
                        /* Create the queues used by the com test task. */\r
-                       pxPort->xRxedChars = xQueueCreate( uxBufferLength, ( unsigned portBASE_TYPE ) sizeof( portCHAR ) );\r
-                       pxPort->xCharsForTx = xQueueCreate( uxBufferLength, ( unsigned portBASE_TYPE ) sizeof( portCHAR ) );\r
+                       pxPort->xRxedChars = xQueueCreate( uxBufferLength, ( unsigned portBASE_TYPE ) sizeof( char ) );\r
+                       pxPort->xCharsForTx = xQueueCreate( uxBufferLength, ( unsigned portBASE_TYPE ) sizeof( char ) );\r
 \r
                        /* Create the test semaphore.  This does nothing useful except test a feature of the scheduler. */\r
                        vSemaphoreCreateBinary( pxPort->xTestSem );\r
 \r
                        /* There is no ISR here already to restore later. */\r
-                       setvect( ( portSHORT ) pxPort->usIRQVector, xISRs[ usPort ] );\r
+                       setvect( ( short ) pxPort->usIRQVector, xISRs[ usPort ] );\r
 \r
                        usInWord = portINPUT_WORD( pxPort->usIntReg );\r
                        usInWord &= ~serINTERRUPT_MASK;\r
                        usInWord |= serINTERRUPT_PRIORITY;\r
                        portOUTPUT_WORD( pxPort->usIntReg, usInWord );\r
 \r
-                       portOUTPUT_WORD( pxPort->usBaudReg, ( unsigned portSHORT ) ulBaudDiv );\r
+                       portOUTPUT_WORD( pxPort->usBaudReg, ( unsigned short ) ulBaudDiv );\r
                        portOUTPUT_WORD( pxPort->usCtrlReg, serENABLE_INTERRUPTS | serMODE | serENABLE_TX_MACHINES | serENABLE_RX_MACHINES );\r
 \r
                        portOUTPUT_WORD( pxPort->usStatusReg, serCLEAR_ALL_STATUS_BITS );\r
@@ -312,12 +343,12 @@ unsigned portLONG ulBaudDiv;
 } /*lint !e715 Some parameters are not used as only a subset of the serial port functionality is currently implemented. */\r
 /*-----------------------------------------------------------*/\r
 \r
-void vSerialPutString( xComPortHandle pxPort, const portCHAR * const pcString, unsigned portSHORT usStringLength )\r
+void vSerialPutString( xComPortHandle pxPort, const char * const pcString, unsigned short usStringLength )\r
 {\r
-unsigned portSHORT usByte;\r
-portCHAR *pcNextChar;\r
+unsigned short usByte;\r
+char *pcNextChar;\r
 \r
-       pcNextChar = ( portCHAR * ) pcString;\r
+       pcNextChar = ( char * ) pcString;\r
 \r
        for( usByte = 0; usByte < usStringLength; usByte++ )\r
        {\r
@@ -329,7 +360,7 @@ portCHAR *pcNextChar;
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, portCHAR *pcRxedChar, portTickType xBlockTime )\r
+portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, char *pcRxedChar, portTickType xBlockTime )\r
 {\r
        /* Get the next character from the buffer, note that this routine is only \r
        called having checked that the is (at least) one to get */\r
@@ -344,7 +375,7 @@ portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, portCHAR *pcRxedChar, portT
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-portBASE_TYPE xSerialPutChar( xComPortHandle pxPort, portCHAR cOutChar, portTickType xBlockTime )\r
+portBASE_TYPE xSerialPutChar( xComPortHandle pxPort, char cOutChar, portTickType xBlockTime )\r
 {\r
        if( xQueueSend( pxPort->xCharsForTx, &cOutChar, xBlockTime ) != pdPASS )\r
        {\r
@@ -369,7 +400,7 @@ const portTickType xBlockTime = ( portTickType ) 0xffff;
 \r
 void vSerialClose( xComPortHandle xPort )\r
 {\r
-unsigned portSHORT usOutput;\r
+unsigned short usOutput;\r
 \r
        /* Turn off the interrupts.  We may also want to delete the queues and/or\r
        re-install the original ISR. */\r
@@ -393,9 +424,9 @@ unsigned portSHORT usOutput;
 unsigned short usStatus;\r
 static portBASE_TYPE xComPortISR( xComPort * const pxPort )\r
 {\r
-unsigned portSHORT usStatusRegister;\r
-portCHAR cChar;\r
-portBASE_TYPE xTaskWokenByPost = pdFALSE, xAnotherTaskWokenByPost = pdFALSE, xTaskWokenByTx = pdFALSE;\r
+unsigned short usStatusRegister;\r
+char cChar;\r
+portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;\r
 \r
        /* NOTE:  THIS IS NOT AN EFFICIENT ISR AS IT IS DESIGNED SOLELY TO TEST\r
        THE SCHEDULER FUNCTIONALITY.  REAL APPLICATIONS SHOULD NOT USE THIS\r
@@ -405,17 +436,17 @@ portBASE_TYPE xTaskWokenByPost = pdFALSE, xAnotherTaskWokenByPost = pdFALSE, xTa
 \r
        if( usStatusRegister & serRX_READY )\r
        {\r
-               cChar = ( portCHAR ) portINPUT_WORD( pxPort->usRxReg );\r
-               xTaskWokenByPost = xQueueSendFromISR( pxPort->xRxedChars, &cChar, xTaskWokenByPost );\r
+               cChar = ( char ) portINPUT_WORD( pxPort->usRxReg );\r
+               xQueueSendFromISR( pxPort->xRxedChars, &cChar, &xHigherPriorityTaskWoken );\r
 \r
                /* Also release the semaphore - this does nothing interesting and is just a test. */\r
-               xAnotherTaskWokenByPost = xSemaphoreGiveFromISR( pxPort->xTestSem, xAnotherTaskWokenByPost );\r
+               xSemaphoreGiveFromISR( pxPort->xTestSem, &xHigherPriorityTaskWoken );\r
        }\r
        else if( pxPort->sTxInterruptOn && ( usStatusRegister & serTX_EMPTY ) )\r
        {\r
-               if( xQueueReceiveFromISR( pxPort->xCharsForTx, &cChar, &xTaskWokenByTx ) == pdTRUE )\r
+               if( xQueueReceiveFromISR( pxPort->xCharsForTx, &cChar, &xHigherPriorityTaskWoken ) == pdTRUE )\r
                {\r
-                       portOUTPUT_WORD( pxPort->usTxReg, ( unsigned portSHORT ) cChar );\r
+                       portOUTPUT_WORD( pxPort->usTxReg, ( unsigned short ) cChar );\r
                }\r
                else\r
                {\r
@@ -429,14 +460,7 @@ portBASE_TYPE xTaskWokenByPost = pdFALSE, xAnotherTaskWokenByPost = pdFALSE, xTa
        /* If posting to the queue woke a task that was blocked on the queue we may\r
        want to switch to the woken task - depending on its priority relative to\r
        the task interrupted by this ISR. */\r
-       if( xTaskWokenByPost || xAnotherTaskWokenByPost || xTaskWokenByTx)\r
-       {\r
-               return pdTRUE;\r
-       }\r
-       else\r
-       {\r
-               return pdFALSE;\r
-       }\r
+       return xHigherPriorityTaskWoken;\r
 }\r
 \r
 \r