]> git.sur5r.net Git - freertos/blob - FreeRTOS-Labs/Demo/FreeRTOS_IoT_Libraries/utilities/task_pool/main.c
fa9f5aababdfde351101b07df2766bbd9647cf72
[freertos] / FreeRTOS-Labs / Demo / FreeRTOS_IoT_Libraries / utilities / task_pool / main.c
1 /*\r
2  * FreeRTOS Kernel V10.3.0\r
3  * Copyright (C) 2020 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          * See https://www.FreeRTOS.org/task-pool/ for configuration and usage instructions.\r
30          ***/\r
31 \r
32 \r
33 /* Standard includes. */\r
34 #include <stdio.h>\r
35 #include <time.h>\r
36 \r
37 /* Visual studio intrinsics used so the __debugbreak() function is available\r
38 should an assert get hit. */\r
39 #include <intrin.h>\r
40 \r
41 /* FreeRTOS includes. */\r
42 #include <FreeRTOS.h>\r
43 #include "task.h"\r
44 \r
45 /* TCP/IP stack includes. */\r
46 #include "FreeRTOS_IP.h"\r
47 \r
48 /*\r
49  * Prototypes for the demos that can be started from this project.\r
50  */\r
51 extern void vStartSimpleTaskPoolDemo( void );\r
52 \r
53 /* This example is the first in a sequence that adds IoT functionality into\r
54 an existing TCP/IP project.  In this first project the TCP/IP stack is not\r
55 actually used, but it is still built, which requires this array to be\r
56 present. */\r
57 const uint8_t ucMACAddress[ 6 ] = { configMAC_ADDR0, configMAC_ADDR1, configMAC_ADDR2, configMAC_ADDR3, configMAC_ADDR4, configMAC_ADDR5 };\r
58 \r
59 /*-----------------------------------------------------------*/\r
60 \r
61 int main( void )\r
62 {\r
63         /***\r
64          * See https://www.FreeRTOS.org/task-pool/ for configuration and usage instructions.\r
65          ***/\r
66 \r
67         /* Create the example that demonstrates task pool functionality.  Examples\r
68         that demonstrate networking connectivity will be added in future projects\r
69         and get started after the network has connected (from within the\r
70         vApplicationIPNetworkEventHook() function).*/\r
71         vStartSimpleTaskPoolDemo();\r
72 \r
73         /* Start the scheduler - if all is well from this point on only FreeRTOS\r
74         tasks will execute. */\r
75         vTaskStartScheduler();\r
76 \r
77         /* If all is well, the scheduler will now be running, and the following\r
78         line will never be reached.  If the following line does execute, then\r
79         there was insufficient FreeRTOS heap memory available for the idle and/or\r
80         timer tasks to be created.  See the memory management section on the\r
81         FreeRTOS web site for more details (this is standard text that is not\r
82         really applicable to the Win32 simulator port). */\r
83         for( ;; )\r
84         {\r
85                 __debugbreak();\r
86         }\r
87 }\r
88 /*-----------------------------------------------------------*/\r
89 \r
90 void vAssertCalled( const char *pcFile, uint32_t ulLine )\r
91 {\r
92 volatile uint32_t ulBlockVariable = 0UL;\r
93 volatile char *pcFileName = ( volatile char *  ) pcFile;\r
94 volatile uint32_t ulLineNumber = ulLine;\r
95 \r
96         ( void ) pcFileName;\r
97         ( void ) ulLineNumber;\r
98 \r
99         printf( "vAssertCalled( %s, %u\n", pcFile, ulLine );\r
100 \r
101         /* Setting ulBlockVariable to a non-zero value in the debugger will allow\r
102         this function to be exited. */\r
103         taskDISABLE_INTERRUPTS();\r
104         {\r
105                 while( ulBlockVariable == 0UL )\r
106                 {\r
107                         __debugbreak();\r
108                 }\r
109         }\r
110         taskENABLE_INTERRUPTS();\r
111 }\r
112 /*-----------------------------------------------------------*/\r
113 \r
114 /* Called by FreeRTOS+TCP when the network connects or disconnects.  Disconnect\r
115 events are only received if implemented in the MAC driver. */\r
116 void vApplicationIPNetworkEventHook( eIPCallbackEvent_t eNetworkEvent )\r
117 {\r
118         /* This example is the first in a sequence that adds IoT functionality into\r
119         an existing TCP/IP project.  In this first project the TCP/IP stack is not\r
120         actually used, but it is still built, which requires this function to be\r
121         present.  For now this function does not need to do anything, so just ensure\r
122         the unused parameters don't cause compiler warnings and that calls to this\r
123         function are trapped by the debugger. */\r
124         __debugbreak();\r
125         ( void ) eNetworkEvent;\r
126 }\r
127 /*-----------------------------------------------------------*/\r
128 \r
129 extern uint32_t ulApplicationGetNextSequenceNumber( uint32_t ulSourceAddress,\r
130                                                                                                         uint16_t usSourcePort,\r
131                                                                                                         uint32_t ulDestinationAddress,\r
132                                                                                                         uint16_t usDestinationPort )\r
133 {\r
134         /* This example is the first in a sequence that adds IoT functionality into\r
135         an existing TCP/IP project.  In this first project the TCP/IP stack is not\r
136         actually used, but it is still built, which requires this function to be\r
137         present.  For now this function does not need to do anything, so just ensure\r
138         the unused parameters don't cause compiler warnings and that calls to this\r
139         function are trapped by the debugger. */\r
140         ( void ) ulSourceAddress;\r
141         ( void ) usSourcePort;\r
142         ( void ) ulDestinationAddress;\r
143         ( void ) usDestinationPort;\r
144         __debugbreak();\r
145         return 0;\r
146 }\r
147 /*-----------------------------------------------------------*/\r
148 \r
149 /*\r
150  * Supply a random number to FreeRTOS+TCP stack.\r
151  * THIS IS ONLY A DUMMY IMPLEMENTATION THAT RETURNS A PSEUDO RANDOM NUMBER\r
152  * SO IS NOT INTENDED FOR USE IN PRODUCTION SYSTEMS.\r
153  */\r
154 BaseType_t xApplicationGetRandomNumber(uint32_t* pulNumber)\r
155 {\r
156         /* This example is the first in a sequence that adds IoT functionality into\r
157         an existing TCP / IP project.In this first project the TCP / IP stack is not\r
158         actually used, but it is still built, which requires this function to be\r
159         present.For now this function does not need to do anything. */\r
160         __debugbreak();\r
161         *(pulNumber) = 0;\r
162         return pdFALSE;\r
163 }\r
164 /*-----------------------------------------------------------*/\r
165 \r
166 UBaseType_t uxRand( void )\r
167 {\r
168         /* This example is the first in a sequence that adds IoT functionality into\r
169         an existing TCP/IP project.  In this first project the TCP/IP stack is not\r
170         actually used, but it is still built, which requires this function to be\r
171         present.  For now this function does not need to do anything, so just ensure\r
172         the calls to the function are trapped by the debugger. */\r
173         __debugbreak();\r
174         return 0;\r
175 }\r
176 /*-----------------------------------------------------------*/\r
177 \r
178 /* configUSE_STATIC_ALLOCATION is set to 1, so the application must provide an\r
179 implementation of vApplicationGetIdleTaskMemory() to provide the memory that is\r
180 used by the Idle task. */\r
181 void vApplicationGetIdleTaskMemory( StaticTask_t** ppxIdleTaskTCBBuffer, StackType_t** ppxIdleTaskStackBuffer, uint32_t* pulIdleTaskStackSize )\r
182 {\r
183         /* If the buffers to be provided to the Idle task are declared inside this\r
184         function then they must be declared static - otherwise they will be allocated on\r
185         the stack and so not exists after this function exits. */\r
186         static StaticTask_t xIdleTaskTCB;\r
187         static StackType_t uxIdleTaskStack[configMINIMAL_STACK_SIZE];\r
188 \r
189         /* Pass out a pointer to the StaticTask_t structure in which the Idle task's\r
190         state will be stored. */\r
191         *ppxIdleTaskTCBBuffer = &xIdleTaskTCB;\r
192 \r
193         /* Pass out the array that will be used as the Idle task's stack. */\r
194         *ppxIdleTaskStackBuffer = uxIdleTaskStack;\r
195 \r
196         /* Pass out the size of the array pointed to by *ppxIdleTaskStackBuffer.\r
197         Note that, as the array is necessarily of type StackType_t,\r
198         configMINIMAL_STACK_SIZE is specified in words, not bytes. */\r
199         *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;\r
200 }\r
201 /*-----------------------------------------------------------*/\r
202 \r
203 /* configUSE_STATIC_ALLOCATION and configUSE_TIMERS are both set to 1, so the\r
204 application must provide an implementation of vApplicationGetTimerTaskMemory()\r
205 to provide the memory that is used by the Timer service task. */\r
206 void vApplicationGetTimerTaskMemory( StaticTask_t** ppxTimerTaskTCBBuffer, StackType_t** ppxTimerTaskStackBuffer, uint32_t* pulTimerTaskStackSize )\r
207 {\r
208         /* If the buffers to be provided to the Timer task are declared inside this\r
209         function then they must be declared static - otherwise they will be allocated on\r
210         the stack and so not exists after this function exits. */\r
211         static StaticTask_t xTimerTaskTCB;\r
212         static StackType_t uxTimerTaskStack[configTIMER_TASK_STACK_DEPTH];\r
213 \r
214         /* Pass out a pointer to the StaticTask_t structure in which the Timer\r
215         task's state will be stored. */\r
216         *ppxTimerTaskTCBBuffer = &xTimerTaskTCB;\r
217 \r
218         /* Pass out the array that will be used as the Timer task's stack. */\r
219         *ppxTimerTaskStackBuffer = uxTimerTaskStack;\r
220 \r
221         /* Pass out the size of the array pointed to by *ppxTimerTaskStackBuffer.\r
222         Note that, as the array is necessarily of type StackType_t,\r
223         configMINIMAL_STACK_SIZE is specified in words, not bytes. */\r
224         *pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;\r
225 }\r
226 \r
227 \r