]> git.sur5r.net Git - freertos/blob - FreeRTOS-Plus/Demo/FreeRTOS_Plus_FAT_SL_and_CLI_Windows_Simulator/main.c
Update FreeRTOS+ version number ready for version 9 release candidate 1.
[freertos] / FreeRTOS-Plus / Demo / FreeRTOS_Plus_FAT_SL_and_CLI_Windows_Simulator / main.c
1 /*\r
2     FreeRTOS V9.0.0rc1 - Copyright (C) 2016 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  * http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_FAT_SL/Demos/File_System_Win32_Simulator_demo.shtml\r
74  *\r
75  ******************************************************************************/\r
76 \r
77 /* Standard includes. */\r
78 #include <stdio.h>\r
79 #include <stdint.h>\r
80 \r
81 /* FreeRTOS includes. */\r
82 #include <FreeRTOS.h>\r
83 #include "task.h"\r
84 #include "queue.h"\r
85 #include "semphr.h"\r
86 \r
87 /* File system includes. */\r
88 #include "config_fat_sl.h"\r
89 \r
90 /* Priorities at which the tasks are created. */\r
91 #define mainUDP_CLI_TASK_PRIORITY                       ( tskIDLE_PRIORITY )\r
92 \r
93 /*-----------------------------------------------------------*/\r
94 \r
95 /*\r
96  * Register the generic commands that can be used with FreeRTOS+CLI.\r
97  */\r
98 extern void vRegisterSampleCLICommands( void );\r
99 \r
100 /*\r
101  * Register the file system commands that can be used with FreeRTOS+CLI.\r
102  */\r
103 extern void vRegisterFileSystemCLICommands( void );\r
104 \r
105 /*\r
106  * The task that implements the UDP command interpreter using FreeRTOS+CLI.\r
107  */\r
108 extern void vUDPCommandInterpreterTask( void *pvParameters );\r
109 \r
110 /*\r
111  * Creates and verifies different files on the volume, demonstrating the use of\r
112  * various different API functions.\r
113  */\r
114 extern void vCreateAndVerifySampleFiles( void );\r
115 \r
116 /*-----------------------------------------------------------*/\r
117 \r
118 /******************************************************************************\r
119  *\r
120  * This demo is described on the following web page:\r
121  * http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_FAT_SL/Demos/File_System_Win32_Simulator_demo.shtml\r
122  *\r
123  ******************************************************************************/\r
124 \r
125 int main( void )\r
126 {\r
127 const uint32_t ulLongTime_ms = 250UL;\r
128 \r
129         /* If the file system is only going to be accessed from one task then\r
130         F_FS_THREAD_AWARE can be set to 0 and the set of example files are created\r
131         before the RTOS scheduler is started.  If the file system is going to be\r
132         access from more than one task then F_FS_THREAD_AWARE must be set to 1 and\r
133         the     set of sample files are created from the idle task hook function\r
134         vApplicationIdleHook() - which is defined in this file. */\r
135         #if F_FS_THREAD_AWARE == 0\r
136         {\r
137                 /* Initialise the drive and file system, then create a few example\r
138                 files.  The output from this function just goes to the stdout window,\r
139                 allowing the output to be viewed when the UDP command console is not\r
140                 connected. */\r
141                 vCreateAndVerifySampleFiles();\r
142         }\r
143         #endif\r
144 \r
145         /* Register generic commands with the FreeRTOS+CLI command interpreter. */\r
146         vRegisterSampleCLICommands();\r
147 \r
148         /* Register file system related commands with the FreeRTOS+CLI command\r
149         interpreter. */\r
150         vRegisterFileSystemCLICommands();\r
151 \r
152         /* Create the task that handles the CLI on a UDP port.  The port number\r
153         is set using the configUDP_CLI_PORT_NUMBER setting in FreeRTOSConfig.h. */\r
154         xTaskCreate( vUDPCommandInterpreterTask,        /* The function that implements the command interpreter IO handling. */\r
155                                 "CLI",                                                  /* The name of the task - just to assist debugging. */\r
156                                 configMINIMAL_STACK_SIZE, NULL, /* The size of the stack allocated to the task. */\r
157                                 mainUDP_CLI_TASK_PRIORITY,              /* The priority at which the task will run. */\r
158                                 NULL );                                                 /* A handle to the task is not required, so NULL is passed. */\r
159 \r
160         /* Start the RTOS scheduler. */\r
161         vTaskStartScheduler();\r
162 \r
163         /* If all is well, the scheduler will now be running, and the following\r
164         line will never be reached.  If the following line does execute, then\r
165         there was insufficient FreeRTOS heap memory available for the idle and/or\r
166         timer tasks     to be created.  See the memory management section on the\r
167         FreeRTOS web site for more details (this is standard text that is not not\r
168         really applicable to the Win32 simulator port). */\r
169         for( ;; )\r
170         {\r
171                 Sleep( ulLongTime_ms );\r
172         }\r
173 }\r
174 /*-----------------------------------------------------------*/\r
175 \r
176 void vApplicationIdleHook( void )\r
177 {\r
178 const unsigned long ulMSToSleep = 5;\r
179 \r
180         /* If the file system is only going to be accessed from one task then\r
181         F_FS_THREAD_AWARE can be set to 0 and the set of example files is created\r
182         before the RTOS scheduler is started.  If the file system is going to be\r
183         access from more than one task then F_FS_THREAD_AWARE must be set to 1 and\r
184         the     set of sample files are created from the idle task hook function. */\r
185         #if F_FS_THREAD_AWARE == 1\r
186         {\r
187                 static BaseType_t xCreatedSampleFiles = pdFALSE;\r
188 \r
189                 /* Initialise the drive and file system, then create a few example\r
190                 files.  The output from this function just goes to the stdout window,\r
191                 allowing the output to be viewed when the UDP command console is not\r
192                 connected. */\r
193                 if( xCreatedSampleFiles == pdFALSE )\r
194                 {\r
195                         vCreateAndVerifySampleFiles();\r
196                         xCreatedSampleFiles = pdTRUE;\r
197                 }\r
198         }\r
199         #endif\r
200 \r
201         /* This function is called on each cycle of the idle task if\r
202         configUSE_IDLE_HOOK is set to 1 in FreeRTOSConfig.h.  Sleep to reduce CPU\r
203         load. */\r
204         Sleep( ulMSToSleep );\r
205 }\r
206 /*-----------------------------------------------------------*/\r
207 \r
208 void vAssertCalled( const char *pcFile, unsigned long ulLine )\r
209 {\r
210         printf( "ASSERT FAILED: File %s, line %u\r\n", pcFile, ulLine );\r
211 }\r
212 /*-----------------------------------------------------------*/\r
213 \r
214 void vApplicationMallocFailedHook( void )\r
215 {\r
216         /* vApplicationMallocFailedHook() will only be called if\r
217         configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h.  It is a hook\r
218         function that will get called if a call to pvPortMalloc() fails.\r
219         pvPortMalloc() is called internally by the kernel whenever a task, queue,\r
220         timer or semaphore is created.  It is also called by various parts of the\r
221         demo application.  If heap_1.c, heap_2.c or heap_4.c are used, then the\r
222         size of the heap available to pvPortMalloc() is defined by\r
223         configTOTAL_HEAP_SIZE in FreeRTOSConfig.h, and the xPortGetFreeHeapSize()\r
224         API function can be used to query the size of free heap space that remains\r
225         (although it does not provide information on how the remaining heap might\r
226         be fragmented). */\r
227         taskDISABLE_INTERRUPTS();\r
228         for( ;; );\r
229 }\r
230 \r
231 \r
232 \r