]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Demo/CORTEX_M0+_Atmel_SAMD20_XPlained/RTOSDemo/src/UARTCommandConsole.c
Update version number ready for release.
[freertos] / FreeRTOS / Demo / CORTEX_M0+_Atmel_SAMD20_XPlained / RTOSDemo / src / UARTCommandConsole.c
index 9bbdca2ecac1af535d98fcd3f8da394ba21ef9a6..f1c32b5901097cd0caaf5039969664cb6c1f0c73 100644 (file)
@@ -1,5 +1,6 @@
 /*\r
-    FreeRTOS V7.5.2 - Copyright (C) 2013 Real Time Engineers Ltd.\r
+    FreeRTOS V8.0.1 - Copyright (C) 2014 Real Time Engineers Ltd.\r
+    All rights reserved\r
 \r
     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
 \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
 \r
-    >>! NOTE: The modification to the GPL is included to allow you to distribute\r
-    >>! a combined work that includes FreeRTOS without being obliged to provide\r
-    >>! the source code for proprietary components outside of the FreeRTOS\r
-    >>! kernel.\r
+    >>!   NOTE: The modification to the GPL is included to allow you to     !<<\r
+    >>!   distribute a combined work that includes FreeRTOS without being   !<<\r
+    >>!   obliged to provide the source code for proprietary components     !<<\r
+    >>!   outside of the FreeRTOS kernel.                                   !<<\r
 \r
     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
@@ -83,7 +84,7 @@
 #define cmdMAX_INPUT_SIZE              50\r
 \r
 /* The maximum time in ticks to wait for the UART access mutex. */\r
-#define cmdMAX_MUTEX_WAIT              ( 200 / portTICK_RATE_MS )\r
+#define cmdMAX_MUTEX_WAIT              ( 200 / portTICK_PERIOD_MS )\r
 \r
 /* Characters are only ever received slowly on the CLI so it is ok to pass\r
 received characters from the UART interrupt to the task on a queue.  This sets\r
@@ -102,40 +103,53 @@ static void prvUARTCommandConsoleTask( void *pvParameters );
 \r
 /*\r
  * Ensure a previous interrupt driven Tx has completed before sending the next\r
- * data block to the UART.
+ * data block to the UART.\r
  */\r
-static void prvSendBuffer( struct usart_module *pxCDCUsart, uint8_t * pcBuffer, size_t xBufferLength );\r
+static void prvSendBuffer( struct usart_module *pxCDCUsart, const char * pcBuffer, size_t xBufferLength );\r
 \r
 /*\r
- * A UART is used for printf() output and CLI input and output.  Configure the\r
- * UART and register prvUARTRxNotificationHandler() to handle UART Rx events.\r
+ * Register the 'standard' sample CLI commands with FreeRTOS+CLI.\r
+ */\r
+extern void vRegisterSampleCLICommands( void );\r
+\r
+/*\r
+ * Configure the UART used for IO.and register prvUARTRxNotificationHandler()\r
+ * to handle UART Rx events.\r
  */\r
 static void prvConfigureUART( struct usart_module *pxCDCUsart );\r
+\r
+/*\r
+ * Callback functions registered with the Atmel UART driver.  Both functions\r
+ * just 'give' a semaphore to unblock a task that may be waiting for a\r
+ * character to be received, or a transmission to complete.\r
+ */\r
 static void prvUARTTxNotificationHandler( const struct usart_module *const pxUSART );\r
 static void prvUARTRxNotificationHandler( const struct usart_module *const pxUSART );\r
 \r
 /*-----------------------------------------------------------*/\r
 \r
 /* Const messages output by the command console. */\r
-static uint8_t * const pcWelcomeMessage = ( uint8_t * ) "\r\n\r\nFreeRTOS command server.\r\nType Help to view a list of registered commands.\r\n\r\n>";\r
-static const uint8_t * const pcEndOfOutputMessage = ( uint8_t * ) "\r\n[Press ENTER to execute the previous command again]\r\n>";\r
-static const uint8_t * const pcNewLine = ( uint8_t * ) "\r\n";\r
+static char * const pcWelcomeMessage = "\r\n\r\nFreeRTOS command server.\r\nType Help to view a list of registered commands.\r\n\r\n>";\r
+static const char * const pcEndOfOutputMessage = "\r\n[Press ENTER to execute the previous command again]\r\n>";\r
+static const char * const pcNewLine = "\r\n";\r
 \r
 /* This semaphore is used to allow the task to wait for a Tx to complete\r
 without wasting any CPU time. */\r
-static xSemaphoreHandle xTxCompleteSemaphore = NULL;\r
+static SemaphoreHandle_t xTxCompleteSemaphore = NULL;\r
 \r
 /* This semaphore is sued to allow the task to wait for an Rx to complete\r
 without wasting any CPU time. */\r
-static xSemaphoreHandle xRxCompleteSemaphore = NULL;\r
+static SemaphoreHandle_t xRxCompleteSemaphore = NULL;\r
 \r
 /*-----------------------------------------------------------*/\r
 \r
 void vUARTCommandConsoleStart( uint16_t usStackSize, unsigned portBASE_TYPE uxPriority )\r
 {\r
+       vRegisterSampleCLICommands();\r
+\r
        /* Create that task that handles the console itself. */\r
        xTaskCreate(    prvUARTCommandConsoleTask,                      /* The task that implements the command console. */\r
-                                       ( const int8_t * const ) "CLI",         /* Text name assigned to the task.  This is just to assist debugging.  The kernel does not use this name itself. */\r
+                                       "CLI",                                                          /* Text name assigned to the task.  This is just to assist debugging.  The kernel does not use this name itself. */\r
                                        usStackSize,                                            /* The size of the stack allocated to the task. */\r
                                        NULL,                                                           /* The parameter is not used, so NULL is passed. */\r
                                        uxPriority,                                                     /* The priority allocated to the task. */\r
@@ -145,8 +159,9 @@ void vUARTCommandConsoleStart( uint16_t usStackSize, unsigned portBASE_TYPE uxPr
 \r
 static void prvUARTCommandConsoleTask( void *pvParameters )\r
 {\r
-uint8_t ucRxedChar, ucInputIndex = 0, *pucOutputString;\r
-static int8_t cInputString[ cmdMAX_INPUT_SIZE ], cLastInputString[ cmdMAX_INPUT_SIZE ];\r
+char cRxedChar, *pcOutputString;\r
+uint8_t ucInputIndex = 0;\r
+static char cInputString[ cmdMAX_INPUT_SIZE ], cLastInputString[ cmdMAX_INPUT_SIZE ];\r
 portBASE_TYPE xReturned;\r
 static struct usart_module xCDCUsart; /* Static so it doesn't take up too much stack. */\r
 \r
@@ -160,33 +175,33 @@ static struct usart_module xCDCUsart; /* Static so it doesn't take up too much s
        /* Obtain the address of the output buffer.  Note there is no mutual\r
        exclusion on this buffer as it is assumed only one command console\r
        interface will be used at any one time. */\r
-       pucOutputString = ( uint8_t * ) FreeRTOS_CLIGetOutputBuffer();\r
+       pcOutputString = FreeRTOS_CLIGetOutputBuffer();\r
 \r
        /* Send the welcome message. */\r
-       prvSendBuffer( &xCDCUsart, pcWelcomeMessage, strlen( ( char * ) pcWelcomeMessage ) );\r
+       prvSendBuffer( &xCDCUsart, pcWelcomeMessage, strlen( pcWelcomeMessage ) );\r
 \r
        for( ;; )\r
        {\r
                /* Wait for the next character to arrive.  A semaphore is used to\r
                ensure no CPU time is used until data has arrived. */\r
-               usart_read_buffer_job( &xCDCUsart, &ucRxedChar, sizeof( ucRxedChar ) );         \r
+               usart_read_buffer_job( &xCDCUsart, ( uint8_t * ) &cRxedChar, sizeof( cRxedChar ) );\r
                if( xSemaphoreTake( xRxCompleteSemaphore, portMAX_DELAY ) == pdPASS )\r
                {\r
                        /* Echo the character back. */\r
-                       prvSendBuffer( &xCDCUsart, ( uint8_t * ) &ucRxedChar, sizeof( ucRxedChar ) );\r
+                       prvSendBuffer( &xCDCUsart, &cRxedChar, sizeof( cRxedChar ) );\r
 \r
                        /* Was it the end of the line? */\r
-                       if( ucRxedChar == '\n' || ucRxedChar == '\r' )\r
+                       if( cRxedChar == '\n' || cRxedChar == '\r' )\r
                        {\r
                                /* Just to space the output from the input. */\r
-                               prvSendBuffer( &xCDCUsart, ( uint8_t * ) pcNewLine, strlen( ( char * ) pcNewLine ) );\r
+                               prvSendBuffer( &xCDCUsart, pcNewLine, strlen( pcNewLine ) );\r
 \r
                                /* See if the command is empty, indicating that the last command is\r
                                to be executed again. */\r
                                if( ucInputIndex == 0 )\r
                                {\r
                                        /* Copy the last command back into the input string. */\r
-                                       strcpy( ( char * ) cInputString, ( char * ) cLastInputString );\r
+                                       strcpy( cInputString, cLastInputString );\r
                                }\r
 \r
                                /* Pass the received command to the command interpreter.  The\r
@@ -196,10 +211,10 @@ static struct usart_module xCDCUsart; /* Static so it doesn't take up too much s
                                do\r
                                {\r
                                        /* Get the next output string from the command interpreter. */\r
-                                       xReturned = FreeRTOS_CLIProcessCommand( cInputString, ( int8_t * ) pucOutputString, configCOMMAND_INT_MAX_OUTPUT_SIZE );\r
+                                       xReturned = FreeRTOS_CLIProcessCommand( cInputString, pcOutputString, configCOMMAND_INT_MAX_OUTPUT_SIZE );\r
 \r
                                        /* Write the generated string to the UART. */\r
-                                       prvSendBuffer( &xCDCUsart, ( uint8_t * ) pucOutputString, strlen( ( char * ) pucOutputString ) );\r
+                                       prvSendBuffer( &xCDCUsart, pcOutputString, strlen( pcOutputString ) );\r
 \r
                                } while( xReturned != pdFALSE );\r
 \r
@@ -207,19 +222,19 @@ static struct usart_module xCDCUsart; /* Static so it doesn't take up too much s
                                Clear the input string ready to receive the next command.  Remember\r
                                the command that was just processed first in case it is to be\r
                                processed again. */\r
-                               strcpy( ( char * ) cLastInputString, ( char * ) cInputString );\r
+                               strcpy( cLastInputString, cInputString );\r
                                ucInputIndex = 0;\r
                                memset( cInputString, 0x00, cmdMAX_INPUT_SIZE );\r
 \r
-                               prvSendBuffer( &xCDCUsart, ( uint8_t * ) pcEndOfOutputMessage, strlen( ( char * ) pcEndOfOutputMessage ) );\r
+                               prvSendBuffer( &xCDCUsart, pcEndOfOutputMessage, strlen( pcEndOfOutputMessage ) );\r
                        }\r
                        else\r
                        {\r
-                               if( ucRxedChar == '\r' )\r
+                               if( cRxedChar == '\r' )\r
                                {\r
                                        /* Ignore the character. */\r
                                }\r
-                               else if( ( ucRxedChar == '\b' ) || ( ucRxedChar == cmdASCII_DEL ) )\r
+                               else if( ( cRxedChar == '\b' ) || ( cRxedChar == cmdASCII_DEL ) )\r
                                {\r
                                        /* Backspace was pressed.  Erase the last character in the\r
                                        string - if any. */\r
@@ -234,11 +249,11 @@ static struct usart_module xCDCUsart; /* Static so it doesn't take up too much s
                                        /* A character was entered.  Add it to the string\r
                                        entered so far.  When a \n is entered the complete\r
                                        string will be passed to the command interpreter. */\r
-                                       if( ( ucRxedChar >= ' ' ) && ( ucRxedChar <= '~' ) )\r
+                                       if( ( cRxedChar >= ' ' ) && ( cRxedChar <= '~' ) )\r
                                        {\r
                                                if( ucInputIndex < cmdMAX_INPUT_SIZE )\r
                                                {\r
-                                                       cInputString[ ucInputIndex ] = ucRxedChar;\r
+                                                       cInputString[ ucInputIndex ] = cRxedChar;\r
                                                        ucInputIndex++;\r
                                                }\r
                                        }\r
@@ -249,17 +264,17 @@ static struct usart_module xCDCUsart; /* Static so it doesn't take up too much s
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-static void prvSendBuffer( struct usart_module *pxCDCUsart, uint8_t * pcBuffer, size_t xBufferLength )\r
+static void prvSendBuffer( struct usart_module *pxCDCUsart, const char * pcBuffer, size_t xBufferLength )\r
 {\r
-const portTickType xBlockMax50ms = 50 / portTICK_RATE_MS;\r
+const TickType_t xBlockMax100ms = 100UL / portTICK_PERIOD_MS;\r
 \r
        if( xBufferLength > 0 )\r
-       {               \r
-               usart_write_buffer_job( pxCDCUsart, pcBuffer, xBufferLength );\r
-               \r
+       {\r
+               usart_write_buffer_job( pxCDCUsart, ( uint8_t * ) pcBuffer, xBufferLength );\r
+\r
                /* Wait for the Tx to complete so the buffer can be reused without\r
                corrupting the data that is being sent. */\r
-               xSemaphoreTake( xTxCompleteSemaphore, xBlockMax50ms );\r
+               xSemaphoreTake( xTxCompleteSemaphore, xBlockMax100ms );\r
        }\r
 }\r
 /*-----------------------------------------------------------*/\r
@@ -272,14 +287,14 @@ struct usart_config xUARTConfig;
        without wasting any CPU time. */\r
        vSemaphoreCreateBinary( xTxCompleteSemaphore );\r
        configASSERT( xTxCompleteSemaphore );\r
-       \r
+\r
        /* This semaphore is used to allow the task to block for an Rx to complete\r
        without wasting any CPU time. */\r
        vSemaphoreCreateBinary( xRxCompleteSemaphore );\r
        configASSERT( xRxCompleteSemaphore );\r
 \r
        /* Take the semaphores so they start in the wanted state.  A block time is\r
-       not necessary, and is therefore set to 0, as it is known that the semaphore s\r
+       not necessary, and is therefore set to 0, as it is known that the semaphores\r
        exists - they have just been created. */\r
        xSemaphoreTake( xTxCompleteSemaphore, 0 );\r
        xSemaphoreTake( xRxCompleteSemaphore, 0 );\r
@@ -292,13 +307,13 @@ struct usart_config xUARTConfig;
        xUARTConfig.pinmux_pad1 = EDBG_CDC_SERCOM_PINMUX_PAD1;\r
        xUARTConfig.pinmux_pad2 = EDBG_CDC_SERCOM_PINMUX_PAD2;\r
        xUARTConfig.pinmux_pad3 = EDBG_CDC_SERCOM_PINMUX_PAD3;\r
-       while( usart_init( pxCDCUsart, EDBG_CDC_MODULE, &xUARTConfig ) != STATUS_OK ) \r
+       while( usart_init( pxCDCUsart, EDBG_CDC_MODULE, &xUARTConfig ) != STATUS_OK )\r
        {\r
                /* Nothing to do here.  Should include a timeout really but this is\r
                init code only. */\r
        }\r
        usart_enable( pxCDCUsart );\r
-       \r
+\r
        /* Register the driver callbacks. */\r
        usart_register_callback( pxCDCUsart, prvUARTTxNotificationHandler, USART_CALLBACK_BUFFER_TRANSMITTED );\r
        usart_register_callback( pxCDCUsart, prvUARTRxNotificationHandler, USART_CALLBACK_BUFFER_RECEIVED );\r