]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Demo/WIN32-MingW/main.c
Update version number in preparation for maintenance release.
[freertos] / FreeRTOS / Demo / WIN32-MingW / main.c
index d76c9973dd98a677f9a97aeee698e73448c5fecc..58ee9a54b6d1e447f1e5f21cfbb3b44c581e52ae 100644 (file)
@@ -1,60 +1,64 @@
 /*\r
-    FreeRTOS V8.1.0 - Copyright (C) 2014 Real Time Engineers Ltd. \r
+    FreeRTOS V9.0.1 - Copyright (C) 2017 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
-    ***************************************************************************\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
+    Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.\r
 \r
+    ***************************************************************************\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
 \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
+    FOR A PARTICULAR PURPOSE.  Full license text is available on 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
+     *    FreeRTOS provides completely free yet professionally developed,    *\r
+     *    robust, strictly quality controlled, supported, and cross          *\r
+     *    platform software that is more than just the market leader, it     *\r
+     *    is the industry's de facto standard.                               *\r
      *                                                                       *\r
-     *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
+     *    Help yourself get started quickly while simultaneously helping     *\r
+     *    to support the FreeRTOS project by purchasing a FreeRTOS           *\r
+     *    tutorial book, reference manual, or both:                          *\r
+     *    http://www.FreeRTOS.org/Documentation                              *\r
      *                                                                       *\r
     ***************************************************************************\r
 \r
-    http://www.FreeRTOS.org - Documentation, books, training, latest versions,\r
-    license and Real Time Engineers Ltd. contact details.\r
+    http://www.FreeRTOS.org/FAQHelp.html - Having a problem?  Start by reading\r
+    the FAQ page "My application does not run, what could be wrong?".  Have you\r
+    defined configASSERT()?\r
+\r
+    http://www.FreeRTOS.org/support - In return for receiving this top quality\r
+    embedded software for free we request you assist our global community by\r
+    participating in the support forum.\r
+\r
+    http://www.FreeRTOS.org/training - Investing in training allows your team to\r
+    be as productive as possible as early as possible.  Now you can receive\r
+    FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers\r
+    Ltd, and the world's leading authority on the world's leading RTOS.\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
+    http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.\r
+    Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.\r
+\r
+    http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High\r
+    Integrity Systems ltd. to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
+    licenses offer ticketed support, indemnification and commercial 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
@@ -66,9 +70,9 @@
 /******************************************************************************\r
  * This project provides two demo applications.  A simple blinky style project,\r
  * and a more comprehensive test and demo application.  The\r
- * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is used to select between the two.  \r
- * The simply blinky demo is implemented and described in main_blinky.c.  The \r
- * more comprehensive test and demo application is implemented and described in \r
+ * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is used to select between the two.\r
+ * The simply blinky demo is implemented and described in main_blinky.c.  The\r
+ * more comprehensive test and demo application is implemented and described in\r
  * main_full.c.\r
  *\r
  * This file implements the code that is not demo specific, including the\r
@@ -80,9 +84,9 @@
  * application.  It is provided as a convenient development and demonstration\r
  * test bed only.  This was tested using Windows XP on a dual core laptop.\r
  *\r
- * Windows will not be running the FreeRTOS simulator threads continuously, so \r
- * the timing information in the FreeRTOS+Trace logs have no meaningful units.  \r
- * See the documentation page for the Windows simulator for an explanation of \r
+ * Windows will not be running the FreeRTOS simulator threads continuously, so\r
+ * the timing information in the FreeRTOS+Trace logs have no meaningful units.\r
+ * See the documentation page for the Windows simulator for an explanation of\r
  * the slow timing:\r
  * http://www.freertos.org/FreeRTOS-Windows-Simulator-Emulator-for-Visual-Studio-and-Eclipse-MingW.html\r
  * - READ THE WEB DOCUMENTATION FOR THIS PORT FOR MORE INFORMATION ON USING IT -\r
 \r
 /* This project provides two demo applications.  A simple blinky style project,\r
 and a more comprehensive test and demo application.  The\r
-mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is used to select between the two.  \r
-The simply blinky demo is implemented and described in main_blinky.c.  The more \r
-comprehensive test and demo application is implemented and described in \r
+mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is used to select between the two.\r
+The simply blinky demo is implemented and described in main_blinky.c.  The more\r
+comprehensive test and demo application is implemented and described in\r
 main_full.c. */\r
-#define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY     1\r
+#define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY     0\r
+\r
+/* This demo uses heap_5.c, and these constants define the sizes of the regions\r
+that make up the total heap.  This is only done to provide an example of heap_5\r
+being used as this demo could easily create one large heap region instead of\r
+multiple smaller heap regions - in which case heap_4.c would be the more\r
+appropriate choice. */\r
+#define mainREGION_1_SIZE      7001\r
+#define mainREGION_2_SIZE      18105\r
+#define mainREGION_3_SIZE      2807\r
 \r
 /*\r
  * main_blinky() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1.\r
@@ -114,15 +127,28 @@ main_full.c. */
 extern void main_blinky( void );\r
 extern void main_full( void );\r
 \r
-/* Some of the RTOS hook (callback) functions only need special processing when\r
-the full demo is being used.  The simply blinky demo has no special requirements,\r
-so these functions are called from the hook functions defined in this file, but\r
-are defined in main_full.c. */\r
+/*\r
+ * Some of the RTOS hook (callback) functions only need special processing when\r
+ * the full demo is being used.  The simply blinky demo has no special\r
+ * requirements, so these functions are called from the hook functions defined\r
+ * in this file, but are defined in main_full.c.\r
+ */\r
 void vFullDemoTickHookFunction( void );\r
 void vFullDemoIdleFunction( void );\r
 \r
-/* Prototypes for the standard FreeRTOS callback/hook functions implemented\r
-within this file. */\r
+/*\r
+ * This demo uses heap_5.c, so start by defining some heap regions.  This is\r
+ * only done to provide an example as this demo could easily create one large\r
+ * heap region instead of multiple smaller heap regions - in which case heap_4.c\r
+ * would be the more appropriate choice.  No initialisation is required when\r
+ * heap_4.c is used.\r
+ */\r
+static void  prvInitialiseHeap( void );\r
+\r
+/*\r
+ * Prototypes for the standard FreeRTOS callback/hook functions implemented\r
+ * within this file.\r
+ */\r
 void vApplicationMallocFailedHook( void );\r
 void vApplicationIdleHook( void );\r
 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );\r
@@ -145,6 +171,13 @@ static portBASE_TYPE xTraceRunning = pdTRUE;
 \r
 int main( void )\r
 {\r
+       /* This demo uses heap_5.c, so start by defining some heap regions.  This\r
+       is only done to provide an example as this demo could easily create one\r
+       large heap region instead of multiple smaller heap regions - in which case\r
+       heap_4.c would be the more appropriate choice.  No initialisation is\r
+       required when heap_4.c is used. */\r
+       prvInitialiseHeap();\r
+\r
        /* Initialise the trace recorder and create the label used to post user\r
        events to the trace recording on each tick interrupt. */\r
        vTraceInitTraceData();\r
@@ -251,10 +284,10 @@ void vApplicationTickHook( void )
        }\r
        #endif /* mainCREATE_SIMPLE_BLINKY_DEMO_ONLY */\r
 \r
-       /* Write a user event to the trace log.  \r
+       /* Write a user event to the trace log.\r
        Note tick events will not appear in the trace recording with regular period\r
        because this project runs in a Windows simulator, and does not therefore\r
-       exhibit deterministic behaviour.  Windows will run the simulator in \r
+       exhibit deterministic behaviour.  Windows will run the simulator in\r
        bursts. */\r
        vTraceUserEvent( xTickTraceUserEvent );\r
 }\r
@@ -263,26 +296,35 @@ void vApplicationTickHook( void )
 void vAssertCalled( unsigned long ulLine, const char * const pcFileName )\r
 {\r
 static portBASE_TYPE xPrinted = pdFALSE;\r
+volatile uint32_t ulSetToNonZeroInDebuggerToContinue = 0;\r
 \r
        /* Parameters are not used. */\r
        ( void ) ulLine;\r
        ( void ) pcFileName;\r
 \r
-       taskDISABLE_INTERRUPTS();\r
-       __asm volatile( "int $3" );\r
-\r
-       /* Stop the trace recording. */\r
-       if( xPrinted == pdFALSE )\r
+       taskENTER_CRITICAL();\r
        {\r
-               xPrinted = pdTRUE;\r
-               if( xTraceRunning == pdTRUE )\r
+               /* Stop the trace recording. */\r
+               if( xPrinted == pdFALSE )\r
                {\r
-               vTraceStop();\r
-               prvSaveTraceFile();\r
+                       xPrinted = pdTRUE;\r
+                       if( xTraceRunning == pdTRUE )\r
+                       {\r
+                               vTraceStop();\r
+                               prvSaveTraceFile();\r
+                       }\r
                }\r
-       }\r
 \r
-       taskENABLE_INTERRUPTS();\r
+               /* You can step out of this function to debug the assertion by using\r
+               the debugger to set ulSetToNonZeroInDebuggerToContinue to a non-zero\r
+               value. */\r
+               while( ulSetToNonZeroInDebuggerToContinue == 0 )\r
+               {\r
+                       __asm volatile( "NOP" );\r
+                       __asm volatile( "NOP" );\r
+               }\r
+       }\r
+       taskEXIT_CRITICAL();\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
@@ -303,3 +345,33 @@ FILE* pxOutputFile;
                printf( "\r\nFailed to create trace dump file\r\n" );\r
        }\r
 }\r
+/*-----------------------------------------------------------*/\r
+\r
+static void  prvInitialiseHeap( void )\r
+{\r
+/* This demo uses heap_5.c, so start by defining some heap regions.  This is\r
+only done to provide an example as this demo could easily create one large heap\r
+region instead of multiple smaller heap regions - in which case heap_4.c would\r
+be the more appropriate choice.  No initialisation is required when heap_4.c is\r
+used.  The xHeapRegions structure requires the regions to be defined in order,\r
+so this just creates one big array, then populates the structure with offsets\r
+into the array - with gaps in between and messy alignment just for test\r
+purposes. */\r
+static uint8_t ucHeap[ configTOTAL_HEAP_SIZE ];\r
+volatile uint32_t ulAdditionalOffset = 19; /* Just to prevent 'condition is always true' warnings in configASSERT(). */\r
+const HeapRegion_t xHeapRegions[] =\r
+{\r
+       /* Start address with dummy offsets                                             Size */\r
+       { ucHeap + 1,                                                                                   mainREGION_1_SIZE },\r
+       { ucHeap + 15 + mainREGION_1_SIZE,                                              mainREGION_2_SIZE },\r
+       { ucHeap + 19 + mainREGION_1_SIZE + mainREGION_2_SIZE,  mainREGION_3_SIZE },\r
+       { NULL, 0 }\r
+};\r
+\r
+       /* Sanity check that the sizes and offsets defined actually fit into the\r
+       array. */\r
+       configASSERT( ( ulAdditionalOffset + mainREGION_1_SIZE + mainREGION_2_SIZE + mainREGION_3_SIZE ) < configTOTAL_HEAP_SIZE );\r
+\r
+       vPortDefineHeapRegions( xHeapRegions );\r
+}\r
+/*-----------------------------------------------------------*/\r