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