/*\r
- FreeRTOS V6.1.1 - Copyright (C) 2011 Real Time Engineers Ltd.\r
+ FreeRTOS V7.0.0 - Copyright (C) 2011 Real Time Engineers Ltd.\r
+\r
+\r
+ FreeRTOS supports many tools and architectures. V7.0.0 is sponsored by:\r
+ Atollic AB - Atollic provides professional embedded systems development\r
+ tools for C/C++ development, code analysis and test automation.\r
+ See http://www.atollic.com\r
+\r
\r
***************************************************************************\r
- * *\r
- * If you are: *\r
- * *\r
- * + New to FreeRTOS, *\r
- * + Wanting to learn FreeRTOS or multitasking in general quickly *\r
- * + Looking for basic training, *\r
- * + Wanting to improve your FreeRTOS skills and productivity *\r
- * *\r
- * then take a look at the FreeRTOS books - available as PDF or paperback *\r
- * *\r
- * "Using the FreeRTOS Real Time Kernel - a Practical Guide" *\r
- * http://www.FreeRTOS.org/Documentation *\r
- * *\r
- * A pdf reference manual is also available. Both are usually delivered *\r
- * to your inbox within 20 minutes to two hours when purchased between 8am *\r
- * and 8pm GMT (although please allow up to 24 hours in case of *\r
- * exceptional circumstances). Thank you for your support! *\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 exception to the GPL is included to allow you to distribute\r
- a combined work that includes FreeRTOS without being obliged to provide the\r
- source code for proprietary components outside of the FreeRTOS kernel.\r
- FreeRTOS 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
+ >>>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
*/\r
\r
/*\r
-* This simple demo project runs on the STM32 Discovery board, which is\r
-* populated with an STM32F100RB Cortex-M3 microcontroller. The discovery board \r
-* makes an ideal low cost evaluation platform, but the 8K of RAM provided on the\r
-* STM32F100RB does not allow the simple application to demonstrate all of all the \r
-* FreeRTOS kernel features. Therefore, this simple demo only actively \r
-* demonstrates task, queue, timer and interrupt functionality. In addition, the \r
-* demo is configured to include malloc failure, idle and stack overflow hook \r
-* functions.\r
-* \r
-* The idle hook function:\r
-* The idle hook function queries the amount of FreeRTOS heap space that is\r
-* remaining (see vApplicationIdleHook() defined in this file). The demo \r
-* application is configured use 7K or the available 8K of RAM as the FreeRTOS heap.\r
-* Memory is only allocated from this heap during initialisation, and this demo \r
-* only actually uses 1.6K bytes of the configured 7K available - leaving 5.4K \r
-* bytes of heap space unallocated.\r
-* \r
-* The main() Function:\r
-* main() creates one software timer, one queue, and two tasks. It then starts the\r
-* scheduler.\r
-* \r
-* The Queue Send Task:\r
-* The queue send task is implemented by the prvQueueSendTask() function in this \r
-* file. prvQueueSendTask() sits in a loop that causes it to repeatedly block for \r
-* 200 milliseconds, before sending the value 100 to the queue that was created \r
-* within main(). Once the value is sent, the task loops back around to block for\r
-* another 200 milliseconds.\r
-* \r
-* The Queue Receive Task:\r
-* The queue receive task is implemented by the prvQueueReceiveTask() function\r
-* in this file. prvQueueReceiveTask() sits in a loop that causes repeatedly \r
-* attempt to read data from the queue that was created within main(). When data \r
-* is received, the task checks the value of the data, and if the value equals \r
-* the expected 100, toggles the green LED. The 'block time' parameter passed to \r
-* the queue receive function specifies that the task should be held in the Blocked \r
-* state indefinitely to wait for data to be available on the queue. The queue \r
-* receive task will only leave the Blocked state when the queue send task writes \r
-* to the queue. As the queue send task writes to the queue every 200 \r
-* milliseconds, the queue receive task leaves the Blocked state every 200 \r
-* milliseconds, and therefore toggles the green LED every 200 milliseconds.\r
-* \r
-* The LED Software Timer and the Button Interrupt:\r
-* The user button B1 is configured to generate an interrupt each time it is\r
-* pressed. The interrupt service routine switches the red LED on, and resets the \r
-* LED software timer. The LED timer has a 5000 millisecond (5 second) period, and\r
-* uses a callback function that is defined to just turn the red LED off. \r
-* Therefore, pressing the user button will turn the red LED on, and the LED will \r
-* remain on until a full five seconds pass without the button being pressed.\r
-*/\r
+ * main-blinky.c is included when the "Blinky" build configuration is used.\r
+ * main-full.c is included when the "Full" build configuration is used.\r
+ *\r
+ * main-full.c (this file) defines a comprehensive demo that creates many\r
+ * tasks, queues, semaphores and timers. It also demonstrates how Cortex-M3\r
+ * interrupts can interact with FreeRTOS tasks/timers, and implements a simple\r
+ * and small interactive web server.\r
+ *\r
+ * This project runs on the SmartFusion A2F-EVAL-KIT evaluation board, which\r
+ * is populated with an A2F200M3F SmartFusion mixed signal FPGA. The A2F200M3F\r
+ * incorporates a Cortex-M3 microcontroller.\r
+ *\r
+ * The main() Function:\r
+ * main() creates two demo specific software timers, one demo specific queue,\r
+ * and two demo specific tasks. It then creates a whole host of 'standard demo'\r
+ * tasks/queues/semaphores, before starting the scheduler. The demo specific\r
+ * tasks and timers are described in the comments here. The standard demo\r
+ * tasks are described on the FreeRTOS.org web site.\r
+ *\r
+ * The standard demo tasks provide no specific functionality. They are\r
+ * included to both test the FreeRTOS port, and provide examples of how the\r
+ * various FreeRTOS API functions can be used.\r
+ *\r
+ * The Demo Specific Queue Send Task:\r
+ * The queue send task is implemented by the prvQueueSendTask() function in\r
+ * this file. prvQueueSendTask() sits in a loop that causes it to repeatedly\r
+ * block for 200 milliseconds, before sending the value 100 to the queue that\r
+ * was created within main(). Once the value is sent, the task loops back\r
+ * around to block for another 200 milliseconds.\r
+ *\r
+ * The Demo Specific Queue Receive Task:\r
+ * The queue receive task is implemented by the prvQueueReceiveTask() function\r
+ * in this file. prvQueueReceiveTask() sits in a loop that causes it to\r
+ * repeatedly attempt to read data from the queue that was created within\r
+ * main(). When data is received, the task checks the value of the data, and\r
+ * if the value equals the expected 100, toggles the green LED. The 'block\r
+ * time' parameter passed to the queue receive function specifies that the task\r
+ * should be held in the Blocked state indefinitely to wait for data to be\r
+ * available on the queue. The queue receive task will only leave the Blocked\r
+ * state when the queue send task writes to the queue. As the queue send task\r
+ * writes to the queue every 200 milliseconds, the queue receive task leaves\r
+ * the Blocked state every 200 milliseconds, and therefore toggles the LED\r
+ * every 200 milliseconds.\r
+ *\r
+ * The Demo Specific LED Software Timer and the Button Interrupt:\r
+ * The user button SW1 is configured to generate an interrupt each time it is\r
+ * pressed. The interrupt service routine switches an LED on, and resets the\r
+ * LED software timer. The LED timer has a 5000 millisecond (5 second) period,\r
+ * and uses a callback function that is defined to just turn the LED off again.\r
+ * Therefore, pressing the user button will turn the LED on, and the LED will\r
+ * remain on until a full five seconds pass without the button being pressed.\r
+ *\r
+ * The Demo Specific Idle Hook Function:\r
+ * The idle hook function demonstrates how to query the amount of FreeRTOS heap\r
+ * space that is remaining (see vApplicationIdleHook() defined in this file).\r
+ *\r
+ * The Demo Specific "Check" Callback Function:\r
+ * This is called each time the 'check' timer expires. The check timer\r
+ * callback function inspects all the standard demo tasks to see if they are\r
+ * all executing as expected. The check timer is initially configured to\r
+ * expire every three seconds, but will shorted this to every 500ms if an error\r
+ * is ever discovered. The check timer callback toggles the LED defined by\r
+ * the mainCHECK_LED definition each time it executes. Therefore, if LED\r
+ * mainCHECK_LED is toggling every three seconds, then no error have been found.\r
+ * If LED mainCHECK_LED is toggling every 500ms, then at least one error has\r
+ * been found. The task in which the error was discovered is displayed at the\r
+ * bottom of the "task stats" page that is served by the embedded web server.\r
+ *\r
+ * The Web Server Task:\r
+ * The IP address used by the SmartFusion target is configured by the\r
+ * definitions configIP_ADDR0 to configIP_ADDR3, which are located in the\r
+ * FreeRTOSConfig.h header file. See the documentation page for this example\r
+ * on the http://www.FreeRTOS.org web site for further connection information.\r
+ */\r
\r
/* Kernel includes. */\r
#include "FreeRTOS.h"\r
the queue empty. */\r
#define mainQUEUE_LENGTH ( 1 )\r
\r
+/* The LED toggled by the check timer callback function. */\r
#define mainCHECK_LED 0x07UL\r
+\r
+/* The LED turned on by the button interrupt, and turned off by the LED timer. */\r
#define mainTIMER_CONTROLLED_LED 0x06UL\r
+\r
+/* The LED toggle by the queue receive task. */\r
#define mainTASK_CONTROLLED_LED 0x05UL\r
\r
+/* Constant used by the standard timer test functions. */\r
#define mainTIMER_TEST_PERIOD ( 50 )\r
\r
+/* Priorities used by the various different tasks. */\r
#define mainCHECK_TASK_PRIORITY ( configMAX_PRIORITIES - 1 )\r
#define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 1 )\r
#define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )\r
stack than most of the other tasks. */\r
#define mainuIP_STACK_SIZE ( configMINIMAL_STACK_SIZE * 3 )\r
\r
+/* The period at which the check timer will expire, in ms, provided no errors\r
+have been reported by any of the standard demo tasks. */\r
+#define mainCHECK_TIMER_PERIOD_ms ( 3000UL )\r
+\r
+/* The period at which the check timer will expire, in ms, if an error has been\r
+reported in one of the standard demo tasks. */
+#define mainERROR_CHECK_TIMER_PERIOD_ms ( 500UL )\r
+\r
+/* A zero block time. */\r
+#define mainDONT_BLOCK ( 0UL )\r
/*-----------------------------------------------------------*/\r
\r
/*\r
*/\r
static void vLEDTimerCallback( xTimerHandle xTimer );\r
\r
+/*\r
+ * The check timer callback function, as described at the top of this file.
+ */\r
static void vCheckTimerCallback( xTimerHandle xTimer );\r
\r
/*\r
* This is not a 'standard' partest function, so the prototype is not in\r
- * partest.h.
+ * partest.h, and is instead included here.
*/\r
void vParTestSetLEDFromISR( unsigned portBASE_TYPE uxLED, signed portBASE_TYPE xValue );\r
\r
\r
/*-----------------------------------------------------------*/\r
\r
-/* The queue used by both tasks. */\r
+/* The queue used by both application specific demo tasks defined in this file. */\r
static xQueueHandle xQueue = NULL;\r
\r
-/* The LED software timer. This uses vLEDTimerCallback() as its callback\r
+/* The LED software timer. This uses vLEDTimerCallback() as it's callback\r
function. */\r
static xTimerHandle xLEDTimer = NULL;\r
\r
+/* The check timer. This uses vCheckTimerCallback() as it's callback\r
+function. */\r
static xTimerHandle xCheckTimer = NULL;\r
\r
/* The status message that is displayed at the bottom of the "task stats" web\r
page, which is served by the uIP task. This will report any errors picked up\r
-by the reg test task. */\r
+by the check timer callback. */\r
static const char *pcStatusMessage = NULL;\r
\r
\r
\r
if( xQueue != NULL )\r
{\r
- /* Start the two tasks as described in the comments at the top of this\r
- file. */\r
+ /* Start the two application specific demo tasks, as described in the\r
+ comments at the top of this file. */\r
xTaskCreate( prvQueueReceiveTask, ( signed char * ) "Rx", configMINIMAL_STACK_SIZE, NULL, mainQUEUE_RECEIVE_TASK_PRIORITY, NULL );\r
xTaskCreate( prvQueueSendTask, ( signed char * ) "TX", configMINIMAL_STACK_SIZE, NULL, mainQUEUE_SEND_TASK_PRIORITY, NULL );\r
\r
vLEDTimerCallback /* The callback function that switches the LED off. */\r
);\r
\r
+ /* Create the software timer that performs the 'check' functionality,\r
+ as described at the top of this file. */\r
xCheckTimer = xTimerCreate( ( const signed char * ) "CheckTimer", /* A text name, purely to help debugging. */\r
- ( 3000 / portTICK_RATE_MS ), /* The timer period, in this case 3000ms (3s). */\r
+ ( mainCHECK_TIMER_PERIOD_ms / portTICK_RATE_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
vCheckTimerCallback /* The callback function that inspects the status of all the other tasks. */\r
);\r
\r
+ /* Create a lot of 'standard demo' tasks. */\r
vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
vCreateBlockTimeTasks();\r
vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
vStartRecursiveMutexTasks();\r
vStartTimerDemoTask( mainTIMER_TEST_PERIOD );\r
\r
- /* The web server task. */\r
+ /* Create the web server task. */\r
xTaskCreate( vuIP_Task, ( signed char * ) "uIP", mainuIP_STACK_SIZE, NULL, mainuIP_TASK_PRIORITY, NULL );\r
\r
-\r
/* Start the tasks and timer running. */\r
vTaskStartScheduler();\r
}\r
\r
static void vCheckTimerCallback( xTimerHandle xTimer )\r
{\r
- /* Check the standard demo tasks are running without error. */\r
+ /* Check the standard demo tasks are running without error. Latch the\r
+ latest reported error in the pcStatusMessage character pointer. */\r
if( xAreGenericQueueTasksStillRunning() != pdTRUE )\r
{\r
- /* Increase the rate at which this task cycles, which will increase the\r
- rate at which mainCHECK_LED flashes to give visual feedback that an error\r
- has occurred. */\r
pcStatusMessage = "Error: GenQueue";\r
-// xPrintf( pcStatusMessage );\r
}\r
\r
if( xAreQueuePeekTasksStillRunning() != pdTRUE )\r
{\r
pcStatusMessage = "Error: QueuePeek\r\n";\r
-// xPrintf( pcStatusMessage );\r
}\r
\r
if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
{\r
pcStatusMessage = "Error: BlockQueue\r\n";\r
-// xPrintf( pcStatusMessage );\r
}\r
\r
if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )\r
{\r
pcStatusMessage = "Error: BlockTime\r\n";\r
-// xPrintf( pcStatusMessage );\r
}\r
\r
if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
{\r
pcStatusMessage = "Error: SemTest\r\n";\r
-// xPrintf( pcStatusMessage );\r
}\r
\r
if( xIsCreateTaskStillRunning() != pdTRUE )\r
{\r
pcStatusMessage = "Error: Death\r\n";\r
-// xPrintf( pcStatusMessage );\r
}\r
\r
if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )\r
{\r
pcStatusMessage = "Error: RecMutex\r\n";\r
-// xPrintf( pcStatusMessage );\r
}\r
\r
- if( xAreTimerDemoTasksStillRunning( ( 3000 / portTICK_RATE_MS ) ) != pdTRUE )\r
+ if( xAreTimerDemoTasksStillRunning( ( mainCHECK_TIMER_PERIOD_ms / portTICK_RATE_MS ) ) != pdTRUE )\r
{\r
pcStatusMessage = "Error: TimerDemo";\r
}\r
\r
/* Toggle the check LED to give an indication of the system status. If\r
- the LED toggles every 5 seconds then everything is ok. A faster toggle\r
- indicates an error. */\r
+ the LED toggles every mainCHECK_TIMER_PERIOD_ms milliseconds then\r
+ everything is ok. A faster toggle indicates an error. */\r
vParTestToggleLED( mainCHECK_LED );\r
\r
+ /* Have any errors been latch in pcStatusMessage? 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 mainCHECK_LED\r
+ toggles. */\r
if( pcStatusMessage != NULL )\r
{\r
- /* The block time is set to zero as a timer callback must *never*\r
- attempt to block. */\r
- xTimerChangePeriod( xCheckTimer, ( 500 / portTICK_RATE_MS ), 0 );\r
+ /* This call to xTimerChangePeriod() uses a zero block time. Functions\r
+ called from inside of a timer callback function must *never* attempt\r
+ to block. */\r
+ xTimerChangePeriod( xCheckTimer, ( mainERROR_CHECK_TIMER_PERIOD_ms / portTICK_RATE_MS ), mainDONT_BLOCK );\r
}\r
}\r
/*-----------------------------------------------------------*/\r
static void vLEDTimerCallback( xTimerHandle xTimer )\r
{\r
/* The timer has expired - so no button pushes have occurred in the last\r
- five seconds - turn the LED off. NOTE - accessing the LED port should use\r
- a critical section because it is accessed from multiple tasks, and the\r
- button interrupt - in this trivial case, for simplicity, the critical\r
- section is omitted. */\r
+ five seconds - turn the LED off. */\r
vParTestSetLED( mainTIMER_CONTROLLED_LED, pdFALSE );\r
}\r
/*-----------------------------------------------------------*/\r
portTickType xNextWakeTime;\r
const unsigned long ulValueToSend = 100UL;\r
\r
- /* The suicide tasks must be created last as they need to know how many\r
+ /* The suicide tasks must be created last, as they need to know how many\r
tasks were running prior to their creation in order to ascertain whether\r
- or not the correct/expected number of tasks are running at any given time. */\r
+ or not the correct/expected number of tasks are running at any given time.\r
+ Therefore the standard demo 'death' tasks are not created in main(), but\r
+ instead created here. */\r
vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );\r
\r
+ /* The check timer command queue will have been filled when the timer test\r
+ tasks were created in main() (this is part of the test they perform).\r
+ Therefore, while the check timer can be created in main(), it could not be\r
+ started from main(). Once the scheduler has started, the timer service\r
+ task will have drained the command queue, and now the check task can be\r
+ started successfully. */
xTimerStart( xCheckTimer, portMAX_DELAY );\r
\r
/* Initialise xNextWakeTime - this only needs to be done once. */\r
xQueueReceive( xQueue, &ulReceivedValue, portMAX_DELAY );\r
\r
/* To get here something must have been received from the queue, but\r
- is it the expected value? If it is, toggle the green LED. */\r
+ is it the expected value? If it is, toggle the LED. */\r
if( ulReceivedValue == 100UL )\r
{\r
- /* NOTE - accessing the LED port should use a critical section\r
- because it is accessed from multiple tasks, and the button interrupt \r
- - in this trivial case, for simplicity, the critical section is \r
- omitted. */\r
vParTestToggleLED( mainTASK_CONTROLLED_LED );\r
}\r
}\r
volatile size_t xFreeStackSpace;\r
\r
/* This function is called on each cycle of the idle task. In this case it\r
- does nothing useful, other than report the amout of FreeRTOS heap that \r
+ does nothing useful, other than report the amount of FreeRTOS heap that\r
remains unallocated. */\r
xFreeStackSpace = xPortGetFreeHeapSize();\r
\r
\r
char *pcGetTaskStatusMessage( void )\r
{\r
- /* Not bothered about a critical section here although technically because of\r
- the task priorities the pointer could change it will be atomic if not near\r
- atomic and its not critical. */\r
+ /* Not bothered about a critical section here although technically because\r
+ of the task priorities the pointer could change it will be atomic if not\r
+ near atomic and its not critical. */\r
if( pcStatusMessage == NULL )\r
{\r
return "All tasks running without error";\r