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