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