2 * FreeRTOS Kernel V10.0.0
\r
3 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
\r
5 * Permission is hereby granted, free of charge, to any person obtaining a copy of
\r
6 * this software and associated documentation files (the "Software"), to deal in
\r
7 * the Software without restriction, including without limitation the rights to
\r
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
\r
9 * the Software, and to permit persons to whom the Software is furnished to do so,
\r
10 * subject to the following conditions:
\r
12 * The above copyright notice and this permission notice shall be included in all
\r
13 * copies or substantial portions of the Software. If you wish to use our Amazon
\r
14 * FreeRTOS name, please do so in a fair use way that does not cause confusion.
\r
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
18 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
19 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
20 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
23 * http://www.FreeRTOS.org
\r
24 * http://aws.amazon.com/freertos
\r
26 * 1 tab == 4 spaces!
\r
29 /******************************************************************************
\r
31 * This demo is described on the following web page:
\r
32 * TODO: This link describes the FAT version of this demo.
\r
33 * http://www.freertos.org/FreeRTOS-Plus/Fail_Safe_File_System/Fail_Safe_Embedded_File_System_demo.shtml
\r
35 ******************************************************************************/
\r
37 /* Standard includes. */
\r
41 /* FreeRTOS includes. */
\r
42 #include <FreeRTOS.h>
\r
47 /* Priorities at which the tasks are created. */
\r
48 #define mainUDP_CLI_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
50 /*-----------------------------------------------------------*/
\r
53 * Register the generic commands that can be used with FreeRTOS+CLI.
\r
55 extern void vRegisterSampleCLICommands( void );
\r
58 * Register the file system commands that can be used with FreeRTOS+CLI.
\r
60 extern void vRegisterFileSystemCLICommands( void );
\r
63 * The task that implements the UDP command interpreter using FreeRTOS+CLI.
\r
65 extern void vUDPCommandInterpreterTask( void *pvParameters );
\r
68 * Creates and verifies different files on the volume, demonstrating the use of
\r
69 * various different API functions.
\r
71 extern void vCreateAndVerifySampleFiles( void );
\r
73 /*-----------------------------------------------------------*/
\r
75 /* See http://www.freertos.org/FreeRTOS-Plus/Fail_Safe_File_System/Fail_Safe_Embedded_File_System_demo.shtml
\r
76 for instructions. */
\r
80 const uint32_t ulLongTime_ms = 250UL;
\r
82 /* Initialise the drive and file system, then create a few example
\r
83 files. The output from this function just goes to the stdout window,
\r
84 allowing the output to be viewed when the UDP command console is not
\r
86 vCreateAndVerifySampleFiles();
\r
88 /* Register generic commands with the FreeRTOS+CLI command interpreter. */
\r
89 vRegisterSampleCLICommands();
\r
91 /* Register file system related commands with the FreeRTOS+CLI command
\r
93 vRegisterFileSystemCLICommands();
\r
95 /* Create the task that handles the CLI on a UDP port. The port number
\r
96 is set using the configUDP_CLI_PORT_NUMBER setting in FreeRTOSConfig.h. */
\r
97 xTaskCreate( vUDPCommandInterpreterTask, /* The function that implements the command interpreter IO handling. */
\r
98 "CLI", /* The name of the task - just to assist debugging. */
\r
99 configMINIMAL_STACK_SIZE, NULL, /* The size of the stack allocated to the task. */
\r
100 mainUDP_CLI_TASK_PRIORITY, /* The priority at which the task will run. */
\r
101 NULL ); /* A handle to the task is not required, so NULL is passed. */
\r
103 /* Start the RTOS scheduler. */
\r
104 vTaskStartScheduler();
\r
106 /* If all is well, the scheduler will now be running, and the following
\r
107 line will never be reached. If the following line does execute, then
\r
108 there was insufficient FreeRTOS heap memory available for the idle and/or
\r
109 timer tasks to be created. See the memory management section on the
\r
110 FreeRTOS web site for more details (this is standard text that is not
\r
111 really applicable to the Win32 simulator port). */
\r
114 Sleep( ulLongTime_ms );
\r
117 /*-----------------------------------------------------------*/
\r
119 void vApplicationIdleHook( void )
\r
121 const unsigned long ulMSToSleep = 5;
\r
123 /* This function is called on each cycle of the idle task if
\r
124 configUSE_IDLE_HOOK is set to 1 in FreeRTOSConfig.h. Sleep to reduce CPU
\r
126 Sleep( ulMSToSleep );
\r
128 /*-----------------------------------------------------------*/
\r
130 void vAssertCalled( const char *pcFile, unsigned long ulLine )
\r
132 volatile uint32_t ulSetToNonZeroToExitLoop = 0;
\r
134 printf( "ASSERT FAILED: File %s, line %u\r\n", pcFile, ulLine );
\r
136 taskENTER_CRITICAL();
\r
138 while( ulSetToNonZeroToExitLoop == 0 )
\r
140 /* Do not leave the assert function unless the debugger is used to
\r
141 set ulSetToNonZeroToExitLoop to a non-zero value. */
\r
144 taskEXIT_CRITICAL();
\r
146 /*-----------------------------------------------------------*/
\r
148 void vApplicationMallocFailedHook( void )
\r
150 /* vApplicationMallocFailedHook() will only be called if
\r
151 configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h. It is a hook
\r
152 function that will get called if a call to pvPortMalloc() fails.
\r
153 pvPortMalloc() is called internally by the kernel whenever a task, queue,
\r
154 timer or semaphore is created. It is also called by various parts of the
\r
155 demo application. If heap_1.c, heap_2.c or heap_4.c are used, then the
\r
156 size of the heap available to pvPortMalloc() is defined by
\r
157 configTOTAL_HEAP_SIZE in FreeRTOSConfig.h, and the xPortGetFreeHeapSize()
\r
158 API function can be used to query the size of free heap space that remains
\r
159 (although it does not provide information on how the remaining heap might
\r
161 taskDISABLE_INTERRUPTS();
\r