]> git.sur5r.net Git - freertos/blob - FreeRTOS-Plus/Demo/FreeRTOS_Plus_Reliance_Edge_and_CLI_Windows_Simulator/main.c
Update version numbers in preparation for new release.
[freertos] / FreeRTOS-Plus / Demo / FreeRTOS_Plus_Reliance_Edge_and_CLI_Windows_Simulator / main.c
1 /*\r
2     FreeRTOS V8.2.2 - Copyright (C) 2015 Real Time Engineers Ltd.\r
3     All rights reserved\r
4 \r
5     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
6 \r
7     This file is part of the FreeRTOS distribution.\r
8 \r
9     FreeRTOS is free software; you can redistribute it and/or modify it under\r
10     the terms of the GNU General Public License (version 2) as published by the\r
11     Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.\r
12 \r
13     ***************************************************************************\r
14     >>!   NOTE: The modification to the GPL is included to allow you to     !<<\r
15     >>!   distribute a combined work that includes FreeRTOS without being   !<<\r
16     >>!   obliged to provide the source code for proprietary components     !<<\r
17     >>!   outside of the FreeRTOS kernel.                                   !<<\r
18     ***************************************************************************\r
19 \r
20     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
21     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
22     FOR A PARTICULAR PURPOSE.  Full license text is available on the following\r
23     link: http://www.freertos.org/a00114.html\r
24 \r
25     ***************************************************************************\r
26      *                                                                       *\r
27      *    FreeRTOS provides completely free yet professionally developed,    *\r
28      *    robust, strictly quality controlled, supported, and cross          *\r
29      *    platform software that is more than just the market leader, it     *\r
30      *    is the industry's de facto standard.                               *\r
31      *                                                                       *\r
32      *    Help yourself get started quickly while simultaneously helping     *\r
33      *    to support the FreeRTOS project by purchasing a FreeRTOS           *\r
34      *    tutorial book, reference manual, or both:                          *\r
35      *    http://www.FreeRTOS.org/Documentation                              *\r
36      *                                                                       *\r
37     ***************************************************************************\r
38 \r
39     http://www.FreeRTOS.org/FAQHelp.html - Having a problem?  Start by reading\r
40     the FAQ page "My application does not run, what could be wrong?".  Have you\r
41     defined configASSERT()?\r
42 \r
43     http://www.FreeRTOS.org/support - In return for receiving this top quality\r
44     embedded software for free we request you assist our global community by\r
45     participating in the support forum.\r
46 \r
47     http://www.FreeRTOS.org/training - Investing in training allows your team to\r
48     be as productive as possible as early as possible.  Now you can receive\r
49     FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers\r
50     Ltd, and the world's leading authority on the world's leading RTOS.\r
51 \r
52     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
53     including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
54     compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
55 \r
56     http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.\r
57     Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.\r
58 \r
59     http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High\r
60     Integrity Systems ltd. to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
61     licenses offer ticketed support, indemnification and commercial middleware.\r
62 \r
63     http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
64     engineered and independently SIL3 certified version for use in safety and\r
65     mission critical applications that require provable dependability.\r
66 \r
67     1 tab == 4 spaces!\r
68 */\r
69 \r
70 /******************************************************************************\r
71  *\r
72  * This demo is described on the following web page:\r
73  * TODO: This link describes the FAT version of this demo.\r
74  * http://FreeRTOS-Plus/Fail_Safe_File_System/Fail_Safe_Embedded_File_System_demo.shtml\r
75  *\r
76  ******************************************************************************/\r
77 \r
78 /* Standard includes. */\r
79 #include <stdio.h>\r
80 #include <stdint.h>\r
81 \r
82 /* FreeRTOS includes. */\r
83 #include <FreeRTOS.h>\r
84 #include "task.h"\r
85 #include "queue.h"\r
86 #include "semphr.h"\r
87 \r
88 /* Priorities at which the tasks are created. */\r
89 #define mainUDP_CLI_TASK_PRIORITY                       ( tskIDLE_PRIORITY )\r
90 \r
91 /*-----------------------------------------------------------*/\r
92 \r
93 /*\r
94  * Register the generic commands that can be used with FreeRTOS+CLI.\r
95  */\r
96 extern void vRegisterSampleCLICommands( void );\r
97 \r
98 /*\r
99  * Register the file system commands that can be used with FreeRTOS+CLI.\r
100  */\r
101 extern void vRegisterFileSystemCLICommands( void );\r
102 \r
103 /*\r
104  * The task that implements the UDP command interpreter using FreeRTOS+CLI.\r
105  */\r
106 extern void vUDPCommandInterpreterTask( void *pvParameters );\r
107 \r
108 /*\r
109  * Creates and verifies different files on the volume, demonstrating the use of\r
110  * various different API functions.\r
111  */\r
112 extern void vCreateAndVerifySampleFiles( void );\r
113 \r
114 /*-----------------------------------------------------------*/\r
115 #pragma warning - add link to documentation page\r
116 int main( void )\r
117 {\r
118 const uint32_t ulLongTime_ms = 250UL;\r
119 \r
120         /* Initialise the drive and file system, then create a few example\r
121         files.  The output from this function just goes to the stdout window,\r
122         allowing the output to be viewed when the UDP command console is not\r
123         connected. */\r
124         vCreateAndVerifySampleFiles();\r
125 \r
126         /* Register generic commands with the FreeRTOS+CLI command interpreter. */\r
127         vRegisterSampleCLICommands();\r
128 \r
129         /* Register file system related commands with the FreeRTOS+CLI command\r
130         interpreter. */\r
131         vRegisterFileSystemCLICommands();\r
132 \r
133         /* Create the task that handles the CLI on a UDP port.  The port number\r
134         is set using the configUDP_CLI_PORT_NUMBER setting in FreeRTOSConfig.h. */\r
135         xTaskCreate( vUDPCommandInterpreterTask,        /* The function that implements the command interpreter IO handling. */\r
136                                 "CLI",                                                  /* The name of the task - just to assist debugging. */\r
137                                 configMINIMAL_STACK_SIZE, NULL, /* The size of the stack allocated to the task. */\r
138                                 mainUDP_CLI_TASK_PRIORITY,              /* The priority at which the task will run. */\r
139                                 NULL );                                                 /* A handle to the task is not required, so NULL is passed. */\r
140 \r
141         /* Start the RTOS scheduler. */\r
142         vTaskStartScheduler();\r
143 \r
144         /* If all is well, the scheduler will now be running, and the following\r
145         line will never be reached.  If the following line does execute, then\r
146         there was insufficient FreeRTOS heap memory available for the idle and/or\r
147         timer tasks     to be created.  See the memory management section on the\r
148         FreeRTOS web site for more details (this is standard text that is not not\r
149         really applicable to the Win32 simulator port). */\r
150         for( ;; )\r
151         {\r
152                 Sleep( ulLongTime_ms );\r
153         }\r
154 }\r
155 /*-----------------------------------------------------------*/\r
156 \r
157 void vApplicationIdleHook( void )\r
158 {\r
159 const unsigned long ulMSToSleep = 5;\r
160 \r
161         /* This function is called on each cycle of the idle task if\r
162         configUSE_IDLE_HOOK is set to 1 in FreeRTOSConfig.h.  Sleep to reduce CPU\r
163         load. */\r
164         Sleep( ulMSToSleep );\r
165 }\r
166 /*-----------------------------------------------------------*/\r
167 \r
168 void vAssertCalled( const char *pcFile, unsigned long ulLine )\r
169 {\r
170 volatile uint32_t ulSetToNonZeroToExitLoop = 0;\r
171 \r
172         printf( "ASSERT FAILED: File %s, line %u\r\n", pcFile, ulLine );\r
173 \r
174         taskENTER_CRITICAL();\r
175         {\r
176                 while( ulSetToNonZeroToExitLoop == 0 )\r
177                 {\r
178                         /* Do not leave the assert function unless the debugger is used to\r
179                         set ulSetToNonZeroToExitLoop to a non-zero value. */\r
180                 }\r
181         }\r
182         taskEXIT_CRITICAL();\r
183 }\r
184 /*-----------------------------------------------------------*/\r
185 \r
186 void vApplicationMallocFailedHook( void )\r
187 {\r
188         /* vApplicationMallocFailedHook() will only be called if\r
189         configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h.  It is a hook\r
190         function that will get called if a call to pvPortMalloc() fails.\r
191         pvPortMalloc() is called internally by the kernel whenever a task, queue,\r
192         timer or semaphore is created.  It is also called by various parts of the\r
193         demo application.  If heap_1.c, heap_2.c or heap_4.c are used, then the\r
194         size of the heap available to pvPortMalloc() is defined by\r
195         configTOTAL_HEAP_SIZE in FreeRTOSConfig.h, and the xPortGetFreeHeapSize()\r
196         API function can be used to query the size of free heap space that remains\r
197         (although it does not provide information on how the remaining heap might\r
198         be fragmented). */\r
199         taskDISABLE_INTERRUPTS();\r
200         for( ;; );\r
201 }\r
202 \r
203 \r
204 \r