]> git.sur5r.net Git - freertos/blob - FreeRTOS-Plus/Demo/FreeRTOS_Plus_Reliance_Edge_and_CLI_Windows_Simulator/main.c
Update to MIT licensed FreeRTOS V10.0.0 - see https://www.freertos.org/History.txt
[freertos] / FreeRTOS-Plus / Demo / FreeRTOS_Plus_Reliance_Edge_and_CLI_Windows_Simulator / main.c
1 /*\r
2  * FreeRTOS Kernel V10.0.0\r
3  * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
4  *\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
11  *\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
15  *\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
22  *\r
23  * http://www.FreeRTOS.org\r
24  * http://aws.amazon.com/freertos\r
25  *\r
26  * 1 tab == 4 spaces!\r
27  */\r
28 \r
29 /******************************************************************************\r
30  *\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
34  *\r
35  ******************************************************************************/\r
36 \r
37 /* Standard includes. */\r
38 #include <stdio.h>\r
39 #include <stdint.h>\r
40 \r
41 /* FreeRTOS includes. */\r
42 #include <FreeRTOS.h>\r
43 #include "task.h"\r
44 #include "queue.h"\r
45 #include "semphr.h"\r
46 \r
47 /* Priorities at which the tasks are created. */\r
48 #define mainUDP_CLI_TASK_PRIORITY                       ( tskIDLE_PRIORITY )\r
49 \r
50 /*-----------------------------------------------------------*/\r
51 \r
52 /*\r
53  * Register the generic commands that can be used with FreeRTOS+CLI.\r
54  */\r
55 extern void vRegisterSampleCLICommands( void );\r
56 \r
57 /*\r
58  * Register the file system commands that can be used with FreeRTOS+CLI.\r
59  */\r
60 extern void vRegisterFileSystemCLICommands( void );\r
61 \r
62 /*\r
63  * The task that implements the UDP command interpreter using FreeRTOS+CLI.\r
64  */\r
65 extern void vUDPCommandInterpreterTask( void *pvParameters );\r
66 \r
67 /*\r
68  * Creates and verifies different files on the volume, demonstrating the use of\r
69  * various different API functions.\r
70  */\r
71 extern void vCreateAndVerifySampleFiles( void );\r
72 \r
73 /*-----------------------------------------------------------*/\r
74 \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
77 \r
78 int main( void )\r
79 {\r
80 const uint32_t ulLongTime_ms = 250UL;\r
81 \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
85         connected. */\r
86         vCreateAndVerifySampleFiles();\r
87 \r
88         /* Register generic commands with the FreeRTOS+CLI command interpreter. */\r
89         vRegisterSampleCLICommands();\r
90 \r
91         /* Register file system related commands with the FreeRTOS+CLI command\r
92         interpreter. */\r
93         vRegisterFileSystemCLICommands();\r
94 \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
102 \r
103         /* Start the RTOS scheduler. */\r
104         vTaskStartScheduler();\r
105 \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
112         for( ;; )\r
113         {\r
114                 Sleep( ulLongTime_ms );\r
115         }\r
116 }\r
117 /*-----------------------------------------------------------*/\r
118 \r
119 void vApplicationIdleHook( void )\r
120 {\r
121 const unsigned long ulMSToSleep = 5;\r
122 \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
125         load. */\r
126         Sleep( ulMSToSleep );\r
127 }\r
128 /*-----------------------------------------------------------*/\r
129 \r
130 void vAssertCalled( const char *pcFile, unsigned long ulLine )\r
131 {\r
132 volatile uint32_t ulSetToNonZeroToExitLoop = 0;\r
133 \r
134         printf( "ASSERT FAILED: File %s, line %u\r\n", pcFile, ulLine );\r
135 \r
136         taskENTER_CRITICAL();\r
137         {\r
138                 while( ulSetToNonZeroToExitLoop == 0 )\r
139                 {\r
140                         /* Do not leave the assert function unless the debugger is used to\r
141                         set ulSetToNonZeroToExitLoop to a non-zero value. */\r
142                 }\r
143         }\r
144         taskEXIT_CRITICAL();\r
145 }\r
146 /*-----------------------------------------------------------*/\r
147 \r
148 void vApplicationMallocFailedHook( void )\r
149 {\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
160         be fragmented). */\r
161         taskDISABLE_INTERRUPTS();\r
162         for( ;; );\r
163 }\r
164 \r
165 \r
166 \r