+/*\r
+ FreeRTOS V7.5.2 - Copyright (C) 2013 Real Time Engineers Ltd.\r
+\r
+ VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
+\r
+ ***************************************************************************\r
+ * *\r
+ * FreeRTOS provides completely free yet professionally developed, *\r
+ * robust, strictly quality controlled, supported, and cross *\r
+ * platform software that has become a de facto standard. *\r
+ * *\r
+ * Help yourself get started quickly and support the FreeRTOS *\r
+ * project by purchasing a FreeRTOS tutorial book, reference *\r
+ * manual, or both from: http://www.FreeRTOS.org/Documentation *\r
+ * *\r
+ * Thank you! *\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
+\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
+\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
+ FOR A PARTICULAR PURPOSE. Full license text is available from the following\r
+ link: http://www.freertos.org/a00114.html\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, books, training, latest versions,\r
+ license and Real Time Engineers Ltd. contact details.\r
+\r
+ http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
+ including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
+ compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
+\r
+ http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High\r
+ Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS\r
+ licenses offer ticketed support, indemnification and middleware.\r
+\r
+ http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
+ engineered and independently SIL3 certified version for use in safety and\r
+ mission critical applications that require provable dependability.\r
+\r
+ 1 tab == 4 spaces!\r
+*/\r
+\r
+/******************************************************************************\r
+ * NOTE 1: This project provides two demo applications. A simple blinky style\r
+ * project, and a more comprehensive test and demo application. The\r
+ * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting in main.c is used to select\r
+ * between the two. See the notes on using mainCREATE_SIMPLE_BLINKY_DEMO_ONLY\r
+ * in main.c. This file implements the comprehensive test and demo version.\r
+ *\r
+ * NOTE 2: This file only contains the source code that is specific to the\r
+ * full demo. Generic functions, such FreeRTOS hook functions, and functions\r
+ * required to configure the hardware, are defined in main.c.\r
+ ******************************************************************************\r
+ *\r
+ * main_full() creates a set of standard demo tasks, some application specific\r
+ * tasks, and a timer. It then starts the scheduler. The web documentation\r
+ * provides more details of the standard demo application tasks, which provide\r
+ * no particular functionality, but do provide a good example of how to use the\r
+ * FreeRTOS API.\r
+ *\r
+ * In addition to the standard demo tasks, the following tasks and timer are\r
+ * defined and/or created within this file:\r
+ *\r
+ * "Reg test" tasks - These fill the registers with known values, then check\r
+ * that each register maintains its expected value for the lifetime of the\r
+ * task. Each task uses a different set of values. The reg test tasks execute\r
+ * with a very low priority, so get preempted very frequently. A register\r
+ * containing an unexpected value is indicative of an error in the context\r
+ * switching mechanism.\r
+ *\r
+ * "Check" software timer - The check timer period is initially set to three\r
+ * seconds. Its callback function checks that all the standard demo tasks, and\r
+ * the register check tasks, are not only still executing, but are executing\r
+ * without reporting any errors. If the check timer callback discovers that a\r
+ * task has either stalled, or reported an error, then it changes the period of\r
+ * the check timer from the initial three seconds, to just 200ms. The callback\r
+ * function also toggles the LED each time it is called. This provides a\r
+ * visual indication of the system status: If the LED toggles every three\r
+ * seconds then no issues have been discovered. If the LED toggles every 200ms,\r
+ * then an issue has been discovered with at least one task.\r
+ */\r
+\r
+/* Kernel includes. */\r
+#include "FreeRTOS.h"\r
+#include "task.h"\r
+#include "queue.h"\r
+#include "semphr.h"\r
+#include "timers.h"\r
+\r
+/* Common demo includes. */\r
+#include "blocktim.h"\r
+#include "countsem.h"\r
+#include "recmutex.h"\r
+#include "ParTest.h"\r
+#include "dynamic.h"\r
+#include "QueueOverwrite.h"\r
+#include "QueueSet.h"\r
+#include "GenQTest.h"\r
+#include "QPeek.h"\r
+\r
+/* The period after which the check timer will expire provided no errors have\r
+been reported by any of the standard demo tasks. ms are converted to the\r
+equivalent in ticks using the portTICK_RATE_MS constant. */\r
+#define mainCHECK_TIMER_PERIOD_MS ( 3000UL / portTICK_RATE_MS )\r
+\r
+/* The period at which the check timer will expire if an error has been\r
+reported in one of the standard demo tasks. ms are converted to the equivalent\r
+in ticks using the portTICK_RATE_MS constant. */\r
+#define mainERROR_CHECK_TIMER_PERIOD_MS ( 200UL / portTICK_RATE_MS )\r
+\r
+/* A block time of zero simply means "don't block". */\r
+#define mainDONT_BLOCK ( 0UL )\r
+\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
+/*\r
+ * Register check tasks, as described at the top of this file. The nature of\r
+ * these files necessitates that they are written in an assembly.\r
+ */\r
+extern void vRegTest1Task( void *pvParameters );\r
+extern void vRegTest2Task( void *pvParameters );\r
+\r
+/*\r
+ * Function that starts the command console.\r
+ */\r
+extern void vUARTCommandConsoleStart( uint16_t usStackSize, unsigned portBASE_TYPE uxPriority );\r
+\r
+/*\r
+ * The check timer callback function, as described at the top of this file.\r
+ */\r
+static void prvCheckTimerCallback( xTimerHandle xTimer );\r
+\r
+/*\r
+ * Called by main() to create the comprehensive test/demo application if\r
+ * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is not set to 1.\r
+ */\r
+void main_full( void );\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
+/* The following two variables are used to communicate the status of the\r
+register check tasks to the check software timer. If the variables keep\r
+incrementing, then the register check tasks has not discovered any errors. If\r
+a variable stops incrementing, then an error has been found. */\r
+volatile unsigned long ulRegTest1LoopCounter = 0UL, ulRegTest2LoopCounter = 0UL;\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
+void main_full( void )\r
+{\r
+xTimerHandle xTimer = NULL;\r
+\r
+/* The register test tasks are asm functions that don't use a stack. The\r
+stack allocated just has to be large enough to hold the task context, and\r
+for the additional required for the stack overflow checking to work (if\r
+configured). */\r
+const size_t xRegTestStackSize = 25U;\r
+\r
+ /* Create the standard demo tasks */\r
+ vCreateBlockTimeTasks();\r
+ vStartDynamicPriorityTasks();\r
+ vStartCountingSemaphoreTasks();\r
+ vStartRecursiveMutexTasks();\r
+ vStartQueueOverwriteTask( tskIDLE_PRIORITY );\r
+ vStartQueueSetTasks();\r
+ vStartGenericQueueTasks( tskIDLE_PRIORITY );\r
+ vStartQueuePeekTasks();\r
+ \r
+ /* Start the task that manages the command console for FreeRTOS+CLI. */\r
+ vUARTCommandConsoleStart( ( configMINIMAL_STACK_SIZE * 3 ), tskIDLE_PRIORITY ); \r
+\r
+ /* Create the register test tasks as described at the top of this file.\r
+ These are naked functions that don't use any stack. A stack still has\r
+ to be allocated to hold the task context. */\r
+ xTaskCreate( vRegTest1Task, /* Function that implements the task. */\r
+ ( signed char * ) "Reg1", /* Text name of the task. */\r
+ xRegTestStackSize, /* Stack allocated to the task. */\r
+ NULL, /* The task parameter is not used. */\r
+ tskIDLE_PRIORITY, /* The priority to assign to the task. */\r
+ NULL ); /* Don't receive a handle back, it is not needed. */\r
+\r
+ xTaskCreate( vRegTest2Task, /* Function that implements the task. */\r
+ ( signed char * ) "Reg2", /* Text name of the task. */\r
+ xRegTestStackSize, /* Stack allocated to the task. */\r
+ NULL, /* The task parameter is not used. */\r
+ tskIDLE_PRIORITY, /* The priority to assign to the task. */\r
+ NULL ); /* Don't receive a handle back, it is not needed. */\r
+\r
+ /* Create the software timer that performs the 'check' functionality,\r
+ as described at the top of this file. */\r
+ xTimer = xTimerCreate( ( const signed char * ) "CheckTimer",/* A text name, purely to help debugging. */\r
+ ( mainCHECK_TIMER_PERIOD_MS ), /* The timer period, in this case 3000ms (3s). */\r
+ pdTRUE, /* This is an auto-reload timer, so xAutoReload is set to pdTRUE. */\r
+ ( void * ) 0, /* The ID is not used, so can be set to anything. */\r
+ prvCheckTimerCallback /* The callback function that inspects the status of all the other tasks. */\r
+ );\r
+\r
+ /* If the software timer was created successfully, start it. It won't\r
+ actually start running until the scheduler starts. A block time of\r
+ zero is used in this call, although any value could be used as the block\r
+ time will be ignored because the scheduler has not started yet. */\r
+ if( xTimer != NULL )\r
+ {\r
+ xTimerStart( xTimer, mainDONT_BLOCK );\r
+ }\r
+\r
+ /* Start the kernel. From here on, only tasks and interrupts will run. */\r
+ vTaskStartScheduler();\r
+\r
+ /* If all is well, the scheduler will now be running, and the following\r
+ line will never be reached. If the following line does execute, then there\r
+ was insufficient FreeRTOS heap memory available for the idle and/or timer\r
+ tasks to be created. See the memory management section on the FreeRTOS web\r
+ site, or the FreeRTOS tutorial books for more details. */\r
+ for( ;; );\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+/* See the description at the top of this file. */\r
+static void prvCheckTimerCallback( xTimerHandle xTimer )\r
+{\r
+static long lChangedTimerPeriodAlready = pdFALSE;\r
+static unsigned long ulLastRegTest1Value = 0, ulLastRegTest2Value = 0;\r
+unsigned long ulErrorFound = pdFALSE;\r
+\r
+ /* Check all the demo and test tasks to ensure that they are all still\r
+ running, and that none have detected an error. */\r
+ if( xAreDynamicPriorityTasksStillRunning() != pdPASS )\r
+ {\r
+ ulErrorFound |= ( 0x01UL << 0UL );\r
+ }\r
+\r
+ if( xAreBlockTimeTestTasksStillRunning() != pdPASS )\r
+ {\r
+ ulErrorFound |= ( 0x01UL << 1UL );\r
+ }\r
+\r
+ if( xAreCountingSemaphoreTasksStillRunning() != pdPASS )\r
+ {\r
+ ulErrorFound |= ( 0x01UL << 2UL );\r
+ }\r
+\r
+ if( xAreRecursiveMutexTasksStillRunning() != pdPASS )\r
+ {\r
+ ulErrorFound |= ( 0x01UL << 3UL );\r
+ }\r
+\r
+ /* Check that the register test 1 task is still running. */\r
+ if( ulLastRegTest1Value == ulRegTest1LoopCounter )\r
+ {\r
+ ulErrorFound |= ( 0x01UL << 4UL );\r
+ }\r
+ ulLastRegTest1Value = ulRegTest1LoopCounter;\r
+\r
+ /* Check that the register test 2 task is still running. */\r
+ if( ulLastRegTest2Value == ulRegTest2LoopCounter )\r
+ {\r
+ ulErrorFound |= ( 0x01UL << 5UL );\r
+ }\r
+ ulLastRegTest2Value = ulRegTest2LoopCounter;\r
+\r
+ if( xAreQueueSetTasksStillRunning() != pdPASS )\r
+ {\r
+ ulErrorFound |= ( 0x01UL << 6UL );\r
+ }\r
+\r
+ if( xIsQueueOverwriteTaskStillRunning() != pdPASS )\r
+ {\r
+ ulErrorFound |= ( 0x01UL << 7UL );\r
+ }\r
+ \r
+ if( xAreGenericQueueTasksStillRunning() != pdPASS )\r
+ {\r
+ ulErrorFound |= ( 0x01UL << 8UL );\r
+ }\r
+ \r
+ if( xAreQueuePeekTasksStillRunning() != pdPASS )\r
+ {\r
+ ulErrorFound |= ( 0x01UL << 9UL );\r
+ }\r
+ \r
+ /* Toggle the check LED to give an indication of the system status. If\r
+ the LED toggles every mainCHECK_TIMER_PERIOD_MS milliseconds then\r
+ everything is ok. A faster toggle indicates an error. */\r
+ port_pin_toggle_output_level( LED_0_PIN );\r
+\r
+ /* Have any errors been latched in ulErrorFound? If so, shorten the\r
+ period of the check timer to mainERROR_CHECK_TIMER_PERIOD_MS milliseconds.\r
+ This will result in an increase in the rate at which the LED toggles. */\r
+ if( ulErrorFound != pdFALSE )\r
+ {\r
+ if( lChangedTimerPeriodAlready == pdFALSE )\r
+ {\r
+ lChangedTimerPeriodAlready = pdTRUE;\r
+\r
+ /* This call to xTimerChangePeriod() uses a zero block time.\r
+ Functions called from inside of a timer callback function must\r
+ *never* attempt to block. */\r
+ xTimerChangePeriod( xTimer, ( mainERROR_CHECK_TIMER_PERIOD_MS ), mainDONT_BLOCK );\r
+ }\r
+ }\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r