2 * FreeRTOS Kernel V10.2.1
\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.
\r
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
17 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
18 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
19 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
22 * http://www.FreeRTOS.org
\r
23 * http://aws.amazon.com/freertos
\r
25 * 1 tab == 4 spaces!
\r
28 /******************************************************************************
\r
30 * This demo is described on the following web page:
\r
31 * TODO: This link describes the FAT version of this demo.
\r
32 * http://www.freertos.org/FreeRTOS-Plus/Fail_Safe_File_System/Fail_Safe_Embedded_File_System_demo.shtml
\r
34 ******************************************************************************/
\r
36 /* Standard includes. */
\r
40 /* FreeRTOS includes. */
\r
41 #include <FreeRTOS.h>
\r
46 /* Priorities at which the tasks are created. */
\r
47 #define mainUDP_CLI_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
49 /*-----------------------------------------------------------*/
\r
52 * Register the generic commands that can be used with FreeRTOS+CLI.
\r
54 extern void vRegisterSampleCLICommands( void );
\r
57 * Register the file system commands that can be used with FreeRTOS+CLI.
\r
59 extern void vRegisterFileSystemCLICommands( void );
\r
62 * The task that implements the UDP command interpreter using FreeRTOS+CLI.
\r
64 extern void vUDPCommandInterpreterTask( void *pvParameters );
\r
67 * Creates and verifies different files on the volume, demonstrating the use of
\r
68 * various different API functions.
\r
70 extern void vCreateAndVerifySampleFiles( void );
\r
72 /*-----------------------------------------------------------*/
\r
74 /* See http://www.freertos.org/FreeRTOS-Plus/Fail_Safe_File_System/Fail_Safe_Embedded_File_System_demo.shtml
\r
75 for instructions. */
\r
79 const uint32_t ulLongTime_ms = 250UL;
\r
81 /* Initialise the drive and file system, then create a few example
\r
82 files. The output from this function just goes to the stdout window,
\r
83 allowing the output to be viewed when the UDP command console is not
\r
85 vCreateAndVerifySampleFiles();
\r
87 /* Register generic commands with the FreeRTOS+CLI command interpreter. */
\r
88 vRegisterSampleCLICommands();
\r
90 /* Register file system related commands with the FreeRTOS+CLI command
\r
92 vRegisterFileSystemCLICommands();
\r
94 /* Create the task that handles the CLI on a UDP port. The port number
\r
95 is set using the configUDP_CLI_PORT_NUMBER setting in FreeRTOSConfig.h. */
\r
96 xTaskCreate( vUDPCommandInterpreterTask, /* The function that implements the command interpreter IO handling. */
\r
97 "CLI", /* The name of the task - just to assist debugging. */
\r
98 configMINIMAL_STACK_SIZE, NULL, /* The size of the stack allocated to the task. */
\r
99 mainUDP_CLI_TASK_PRIORITY, /* The priority at which the task will run. */
\r
100 NULL ); /* A handle to the task is not required, so NULL is passed. */
\r
102 /* Start the RTOS scheduler. */
\r
103 vTaskStartScheduler();
\r
105 /* If all is well, the scheduler will now be running, and the following
\r
106 line will never be reached. If the following line does execute, then
\r
107 there was insufficient FreeRTOS heap memory available for the idle and/or
\r
108 timer tasks to be created. See the memory management section on the
\r
109 FreeRTOS web site for more details (this is standard text that is not
\r
110 really applicable to the Win32 simulator port). */
\r
113 Sleep( ulLongTime_ms );
\r
116 /*-----------------------------------------------------------*/
\r
118 void vApplicationIdleHook( void )
\r
120 const unsigned long ulMSToSleep = 5;
\r
122 /* This function is called on each cycle of the idle task if
\r
123 configUSE_IDLE_HOOK is set to 1 in FreeRTOSConfig.h. Sleep to reduce CPU
\r
125 Sleep( ulMSToSleep );
\r
127 /*-----------------------------------------------------------*/
\r
129 void vAssertCalled( const char *pcFile, unsigned long ulLine )
\r
131 volatile uint32_t ulSetToNonZeroToExitLoop = 0;
\r
133 printf( "ASSERT FAILED: File %s, line %u\r\n", pcFile, ulLine );
\r
135 taskENTER_CRITICAL();
\r
137 while( ulSetToNonZeroToExitLoop == 0 )
\r
139 /* Do not leave the assert function unless the debugger is used to
\r
140 set ulSetToNonZeroToExitLoop to a non-zero value. */
\r
143 taskEXIT_CRITICAL();
\r
145 /*-----------------------------------------------------------*/
\r
147 void vApplicationMallocFailedHook( void )
\r
149 /* vApplicationMallocFailedHook() will only be called if
\r
150 configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h. It is a hook
\r
151 function that will get called if a call to pvPortMalloc() fails.
\r
152 pvPortMalloc() is called internally by the kernel whenever a task, queue,
\r
153 timer or semaphore is created. It is also called by various parts of the
\r
154 demo application. If heap_1.c, heap_2.c or heap_4.c are used, then the
\r
155 size of the heap available to pvPortMalloc() is defined by
\r
156 configTOTAL_HEAP_SIZE in FreeRTOSConfig.h, and the xPortGetFreeHeapSize()
\r
157 API function can be used to query the size of free heap space that remains
\r
158 (although it does not provide information on how the remaining heap might
\r
160 taskDISABLE_INTERRUPTS();
\r