]> git.sur5r.net Git - freertos/blobdiff - Demo/CORTEX_LPC1768_GCC_Rowley/main.c
Comment the command line interpreter and lwIP sockets based server code.
[freertos] / Demo / CORTEX_LPC1768_GCC_Rowley / main.c
index 049897b41059d94f31e03aebb5607f97168c18d7..dd9de74d4078409f1f05ccb9c6b8bd89a099a51d 100644 (file)
@@ -1,52 +1,54 @@
 /*\r
-       FreeRTOS.org V5.3.1 - Copyright (C) 2003-2009 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 it\r
-       under the terms of the GNU General Public License (version 2) as published\r
-       by the Free Software Foundation and modified by the FreeRTOS exception.\r
-       **NOTE** The exception to the GPL is included to allow you to distribute a\r
-       combined work that includes FreeRTOS.org without being obliged to provide\r
-       the source code for any proprietary components.  Alternative commercial\r
-       license and support terms are also available upon request.  See the\r
-       licensing section of http://www.FreeRTOS.org for full details.\r
-\r
-       FreeRTOS.org 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.\r
-\r
-       You should have received a copy of the GNU General Public License along\r
-       with FreeRTOS.org; if not, write to the Free Software Foundation, Inc., 59\r
-       Temple Place, Suite 330, Boston, MA  02111-1307  USA.\r
-\r
-\r
-       ***************************************************************************\r
-       *                                                                         *\r
-       * Get the FreeRTOS eBook!  See http://www.FreeRTOS.org/Documentation      *\r
-       *                                                                         *\r
-       * This is a concise, step by step, 'hands on' guide that describes both   *\r
-       * general multitasking concepts and FreeRTOS specifics. It presents and   *\r
-       * explains numerous examples that are written using the FreeRTOS API.     *\r
-       * Full source code for all the examples is provided in an accompanying    *\r
-       * .zip file.                                                              *\r
-       *                                                                         *\r
-       ***************************************************************************\r
-\r
-       1 tab == 4 spaces!\r
-\r
-       Please ensure to read the configuration and relevant port sections of the\r
-       online documentation.\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
+    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
  * In addition to the standard demo tasks, the following tasks and tests are\r
  * defined and/or created within this file:\r
  *\r
- * "LCD" task - the LCD task is a 'gatekeeper' task.  It is the only task that\r
- * is permitted to access the display directly.  Other tasks wishing to write a\r
- * message to the LCD send the message on a queue to the LCD task instead of\r
- * accessing the LCD themselves.  The LCD task just blocks on the queue waiting\r
- * for messages - waking and displaying the messages as they arrive.  The use\r
- * of a gatekeeper in this manner permits both tasks and interrupts to write to\r
- * the LCD without worrying about mutual exclusion.  This is demonstrated by the\r
- * check hook (see below) which sends messages to the display even though it\r
- * executes from an interrupt context.\r
- *\r
  * "Check" hook -  This only executes fully every five seconds from the tick\r
  * hook.  Its main function is to check that all the standard demo tasks are\r
- * still operational.  Should any unexpected behaviour be discovered within a\r
- * demo task then the tick hook will write an error to the LCD (via the LCD task).\r
- * If all the demo tasks are executing with their expected behaviour then the\r
- * check hook writes PASS to the LCD (again via the LCD task), as described above.\r
- * The check hook also toggles LED 4 each time it executes.\r
- *\r
- * LED tasks - These just demonstrate how multiple instances of a single task\r
- * definition can be created.  Each LED task simply toggles an LED.  The task\r
- * parameter is used to pass the number of the LED to be toggled into the task.\r
+ * still operational.  The status can be viewed using on the Task Stats page\r
+ * served by the WEB server.\r
  *\r
  * "uIP" task -  This is the task that handles the uIP stack.  All TCP/IP\r
  * processing is performed in this task.\r
+ * \r
+ * "USB" task - Enumerates the USB device as a CDC class, then echoes back all\r
+ * received characters with a configurable offset (for example, if the offset\r
+ * is 1 and 'A' is received then 'B' will be sent back).  A dumb terminal such\r
+ * as Hyperterminal can be used to talk to the USB task.\r
  */\r
 \r
-/* Standard includes. */\r
-#include <stdio.h>\r
-\r
 /* Scheduler includes. */\r
 #include "FreeRTOS.h"\r
 #include "task.h"\r
-#include "queue.h"\r
-#include "semphr.h"\r
-\r
-/* Hardware library includes. */\r
-#include "LPC17xx_defs.h"\r
 \r
 /* Demo app includes. */\r
 #include "BlockQ.h"\r
 \r
 /*-----------------------------------------------------------*/\r
 \r
-/* The number of LED tasks that will be created. */\r
-#define mainNUM_LED_TASKS                                      ( 6 )\r
-\r
 /* The time between cycles of the 'check' functionality (defined within the\r
-tick hook. */\r
+tick hook). */\r
 #define mainCHECK_DELAY                                                ( ( portTickType ) 5000 / portTICK_RATE_MS )\r
 \r
 /* Task priorities. */\r
@@ -123,7 +102,6 @@ tick hook. */
 #define mainSEM_TEST_PRIORITY                          ( tskIDLE_PRIORITY + 1 )\r
 #define mainBLOCK_Q_PRIORITY                           ( tskIDLE_PRIORITY + 2 )\r
 #define mainUIP_TASK_PRIORITY                          ( tskIDLE_PRIORITY + 3 )\r
-#define mainLCD_TASK_PRIORITY                          ( tskIDLE_PRIORITY + 2 )\r
 #define mainINTEGER_TASK_PRIORITY           ( tskIDLE_PRIORITY )\r
 #define mainGEN_QUEUE_TASK_PRIORITY                    ( tskIDLE_PRIORITY )\r
 #define mainFLASH_TASK_PRIORITY                                ( tskIDLE_PRIORITY + 2 )\r
@@ -132,11 +110,10 @@ tick hook. */
 handling library calls. */\r
 #define mainBASIC_WEB_STACK_SIZE            ( configMINIMAL_STACK_SIZE * 4 )\r
 \r
-/* The length of the queue used to send messages to the LCD task. */\r
-#define mainQUEUE_SIZE                                         ( 3 )\r
+/* The message displayed by the WEB server when all tasks are executing\r
+without an error being reported. */\r
+#define mainPASS_STATUS_MESSAGE                                "All tasks are executing without error."\r
 \r
-/* The task that is toggled by the check task. */\r
-#define mainCHECK_TASK_LED                                     ( 4 )\r
 /*-----------------------------------------------------------*/\r
 \r
 /*\r
@@ -144,11 +121,6 @@ handling library calls. */
  */\r
 static void prvSetupHardware( void );\r
 \r
-/*\r
- * Very simple task that toggles an LED.\r
- */\r
-static void vLEDTask( void *pvParameters );\r
-\r
 /*\r
  * The task that handles the uIP stack.  All TCP/IP processing is performed in\r
  * this task.\r
@@ -156,23 +128,24 @@ static void vLEDTask( void *pvParameters );
 extern void vuIP_Task( void *pvParameters );\r
 \r
 /*\r
- * The LCD gatekeeper task as described in the comments at the top of this file.\r
- * */\r
-static void vLCDTask( void *pvParameters );\r
-\r
-/*-----------------------------------------------------------*/\r
+ * The task that handles the USB stack.\r
+ */\r
+extern void vUSBTask( void *pvParameters );\r
 \r
-/* The queue used to send messages to the LCD task. */\r
-xQueueHandle xLCDQueue;\r
+/*\r
+ * Simply returns the current status message for display on served WEB pages.\r
+ */\r
+char *pcGetTaskStatusMessage( void );\r
 \r
+/*-----------------------------------------------------------*/\r
 \r
+/* Holds the status message displayed by the WEB server. */\r
+static char *pcStatusMessage = mainPASS_STATUS_MESSAGE;\r
 \r
 /*-----------------------------------------------------------*/\r
 \r
 int main( void )\r
 {\r
-long l;\r
-\r
        /* Configure the hardware for use by this demo. */\r
        prvSetupHardware();\r
 \r
@@ -186,20 +159,14 @@ long l;
     vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );\r
     vStartQueuePeekTasks();\r
     vStartRecursiveMutexTasks();\r
-\r
        vStartLEDFlashTasks( mainFLASH_TASK_PRIORITY );\r
 \r
+    /* Create the USB task. */\r
+    xTaskCreate( vUSBTask, ( signed char * ) "USB", configMINIMAL_STACK_SIZE, ( void * ) NULL, tskIDLE_PRIORITY, NULL );\r
+       \r
        /* Create the uIP task.  The WEB server runs in this task. */\r
     xTaskCreate( vuIP_Task, ( signed char * ) "uIP", mainBASIC_WEB_STACK_SIZE, ( void * ) NULL, mainUIP_TASK_PRIORITY, NULL );\r
 \r
-       /* Create the queue used by the LCD task.  Messages for display on the LCD\r
-       are received via this queue. */\r
-       xLCDQueue = xQueueCreate( mainQUEUE_SIZE, sizeof( xLCDMessage ) );\r
-\r
-       /* Start the LCD gatekeeper task - as described in the comments at the top\r
-       of this file. */\r
-       xTaskCreate( vLCDTask, ( signed portCHAR * ) "LCD", configMINIMAL_STACK_SIZE * 2, NULL, mainLCD_TASK_PRIORITY, NULL );\r
-\r
     /* Start the scheduler. */\r
        vTaskStartScheduler();\r
 \r
@@ -209,35 +176,9 @@ long l;
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-void vLCDTask( void *pvParameters )\r
-{\r
-xLCDMessage xMessage;\r
-unsigned long ulRow = 0;\r
-char cIPAddr[ 17 ]; /* To fit max IP address length of xxx.xxx.xxx.xxx\0 */\r
-\r
-       ( void ) pvParameters;\r
-\r
-       /* The LCD gatekeeper task as described in the comments at the top of this\r
-       file. */\r
-\r
-       /* Initialise the LCD and display a startup message that includes the\r
-       configured IP address. */\r
-    sprintf( cIPAddr, "%d.%d.%d.%d", configIP_ADDR0, configIP_ADDR1, configIP_ADDR2, configIP_ADDR3 );\r
-\r
-       for( ;; )\r
-       {\r
-               /* Wait for a message to arrive to be displayed. */\r
-               while( xQueueReceive( xLCDQueue, &xMessage, portMAX_DELAY ) != pdPASS );\r
-\r
-       }\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
 void vApplicationTickHook( void )\r
 {\r
-static xLCDMessage xMessage = { "PASS" };\r
-static unsigned portLONG ulTicksSinceLastDisplay = 0;\r
-portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;\r
+static unsigned long ulTicksSinceLastDisplay = 0;\r
 \r
        /* Called from every tick interrupt as described in the comments at the top\r
        of this file.\r
@@ -254,116 +195,67 @@ portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
                /* Has an error been found in any task? */\r
                if( xAreGenericQueueTasksStillRunning() != pdTRUE )\r
                {\r
-                       xMessage.pcMessage = "ERROR: GEN Q";\r
+                       pcStatusMessage = "An error has been detected in the Generic Queue test/demo.";\r
                }\r
                else if( xAreQueuePeekTasksStillRunning() != pdTRUE )\r
                {\r
-                       xMessage.pcMessage = "ERROR: PEEK Q";\r
+                       pcStatusMessage = "An error has been detected in the Peek Queue test/demo.";\r
                }\r
                else if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
                {\r
-                       xMessage.pcMessage = "ERROR: BLOCK Q";\r
+                       pcStatusMessage = "An error has been detected in the Block Queue test/demo.";\r
                }\r
                else if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )\r
                {\r
-                       xMessage.pcMessage = "ERROR: BLOCK TIME";\r
+                       pcStatusMessage = "An error has been detected in the Block Time test/demo.";\r
                }\r
            else if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
            {\r
-               xMessage.pcMessage = "ERROR: SEMAPHR";\r
+               pcStatusMessage = "An error has been detected in the Semaphore test/demo.";\r
            }\r
            else if( xArePollingQueuesStillRunning() != pdTRUE )\r
            {\r
-               xMessage.pcMessage = "ERROR: POLL Q";\r
+               pcStatusMessage = "An error has been detected in the Poll Queue test/demo.";\r
            }\r
            else if( xAreIntegerMathsTaskStillRunning() != pdTRUE )\r
            {\r
-               xMessage.pcMessage = "ERROR: INT MATH";\r
+               pcStatusMessage = "An error has been detected in the Int Math test/demo.";\r
            }\r
            else if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )\r
            {\r
-               xMessage.pcMessage = "ERROR: REC MUTEX";\r
+               pcStatusMessage = "An error has been detected in the Mutex test/demo.";\r
            }\r
-\r
-               /* Send the message to the OLED gatekeeper for display.  The\r
-               xHigherPriorityTaskWoken parameter is not actually used here\r
-               as this function is running in the tick interrupt anyway - but\r
-               it must still be supplied. */\r
-               xHigherPriorityTaskWoken = pdFALSE;\r
-               xQueueSendFromISR( xLCDQueue, &xMessage, &xHigherPriorityTaskWoken );\r
-\r
-               /* Also toggle and LED.  This can be done from here because in this port\r
-               the LED toggling functions don't use critical sections. */\r
-        vParTestToggleLED( mainCHECK_TASK_LED );\r
        }\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
+char *pcGetTaskStatusMessage( void )\r
+{\r
+       /* Not bothered about a critical section here. */\r
+       return pcStatusMessage;\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
 void prvSetupHardware( void )\r
 {\r
        /* Disable peripherals power. */\r
-       PCONP = 0;\r
+       SC->PCONP = 0;\r
 \r
        /* Enable GPIO power. */\r
-       PCONP = PCONP_PCGPIO;\r
+       SC->PCONP = PCONP_PCGPIO;\r
 \r
        /* Disable TPIU. */\r
-       PINSEL10 = 0;\r
-\r
-       /* Disconnect the main PLL. */\r
-       PLL0CON &= ~PLLCON_PLLC;\r
-       PLL0FEED = PLLFEED_FEED1;\r
-       PLL0FEED = PLLFEED_FEED2;\r
-       while ((PLL0STAT & PLLSTAT_PLLC) != 0);\r
-\r
-       /* Turn off the main PLL. */\r
-       PLL0CON &= ~PLLCON_PLLE;\r
-       PLL0FEED = PLLFEED_FEED1;\r
-       PLL0FEED = PLLFEED_FEED2;\r
-       while ((PLL0STAT & PLLSTAT_PLLE) != 0);\r
-\r
-       /* No CPU clock divider. */\r
-       CCLKCFG = 0;\r
-\r
-       /* OSCEN. */\r
-       SCS = 0x20;\r
-       while ((SCS & 0x40) == 0);\r
-\r
-       /* Use main oscillator. */\r
-       CLKSRCSEL = 1;\r
-       PLL0CFG = (PLLCFG_MUL16 | PLLCFG_DIV1);\r
-\r
-       PLL0FEED = PLLFEED_FEED1;\r
-       PLL0FEED = PLLFEED_FEED2;\r
-\r
-       /*  Activate the PLL by turning it on then feeding the correct\r
-       sequence of bytes. */\r
-       PLL0CON  = PLLCON_PLLE;\r
-       PLL0FEED = PLLFEED_FEED1;\r
-       PLL0FEED = PLLFEED_FEED2;\r
-\r
-       /* 6x CPU clock divider (64 MHz) */\r
-       CCLKCFG = 5;\r
-\r
-       /*  Wait for the PLL to lock. */\r
-       while ((PLL0STAT & PLLSTAT_PLOCK) == 0);\r
-\r
-       /*  Connect the PLL. */\r
-       PLL0CON  = PLLCON_PLLC | PLLCON_PLLE;\r
-       PLL0FEED = PLLFEED_FEED1;\r
-       PLL0FEED = PLLFEED_FEED2;\r
+       PINCON->PINSEL10 = 0;\r
 \r
        /*  Setup the peripheral bus to be the same as the PLL output (64 MHz). */\r
-       PCLKSEL0 = 0x05555555;\r
+       SC->PCLKSEL0 = 0x05555555;\r
 \r
-       /* Configure LED GPIOs as outputs. */\r
-       FIO2DIR  = 0xff;\r
-       FIO2CLR  = 0xff;\r
-       FIO2MASK = 0;\r
+       /* Configure the LEDs. */\r
+       vParTestInitialise();\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed portCHAR *pcTaskName )\r
+void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed char *pcTaskName )\r
 {\r
        /* This function will get called if a task overflows its stack. */\r
 \r
@@ -382,24 +274,24 @@ const unsigned long TCR_COUNT_RESET = 2, CTCR_CTM_TIMER = 0x00, TCR_COUNT_ENABLE
        collecting run time statistical information - basically the percentage\r
        of CPU time that each task is utilising.  It is called automatically when\r
        the scheduler is started (assuming configGENERATE_RUN_TIME_STATS is set\r
-       to 1. */\r
+       to 1). */\r
 \r
        /* Power up and feed the timer. */\r
-       PCONP |= 0x02UL;\r
-       PCLKSEL0 = (PCLKSEL0 & (~(0x3<<2))) | (0x01 << 2);\r
+       SC->PCONP |= 0x02UL;\r
+       SC->PCLKSEL0 = (SC->PCLKSEL0 & (~(0x3<<2))) | (0x01 << 2);\r
 \r
        /* Reset Timer 0 */\r
-       T0TCR = TCR_COUNT_RESET;\r
+       TIM0->TCR = TCR_COUNT_RESET;\r
 \r
        /* Just count up. */\r
-       T0CTCR = CTCR_CTM_TIMER;\r
+       TIM0->CTCR = CTCR_CTM_TIMER;\r
 \r
        /* Prescale to a frequency that is good enough to get a decent resolution,\r
        but not too fast so as to overflow all the time. */\r
-       T0PR =  ( configCPU_CLOCK_HZ / 10000UL ) - 1UL;\r
+       TIM0->PR =  ( configCPU_CLOCK_HZ / 10000UL ) - 1UL;\r
 \r
        /* Start the counter. */\r
-       T0TCR = TCR_COUNT_ENABLE;\r
+       TIM0->TCR = TCR_COUNT_ENABLE;\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r