2 FreeRTOS V7.5.3 - Copyright (C) 2013 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 ***************************************************************************
\r
9 * FreeRTOS provides completely free yet professionally developed, *
\r
10 * robust, strictly quality controlled, supported, and cross *
\r
11 * platform software that has become a de facto standard. *
\r
13 * Help yourself get started quickly and support the FreeRTOS *
\r
14 * project by purchasing a FreeRTOS tutorial book, reference *
\r
15 * manual, or both from: http://www.FreeRTOS.org/Documentation *
\r
19 ***************************************************************************
\r
21 This file is part of the FreeRTOS distribution.
\r
23 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
24 the terms of the GNU General Public License (version 2) as published by the
\r
25 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
27 >>! NOTE: The modification to the GPL is included to allow you to distribute
\r
28 >>! a combined work that includes FreeRTOS without being obliged to provide
\r
29 >>! the source code for proprietary components outside of the FreeRTOS
\r
32 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
33 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
34 FOR A PARTICULAR PURPOSE. Full license text is available from the following
\r
35 link: http://www.freertos.org/a00114.html
\r
39 ***************************************************************************
\r
41 * Having a problem? Start by reading the FAQ "My application does *
\r
42 * not run, what could be wrong?" *
\r
44 * http://www.FreeRTOS.org/FAQHelp.html *
\r
46 ***************************************************************************
\r
48 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
49 license and Real Time Engineers Ltd. contact details.
\r
51 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
52 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
53 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
55 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
56 Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
57 licenses offer ticketed support, indemnification and middleware.
\r
59 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
60 engineered and independently SIL3 certified version for use in safety and
\r
61 mission critical applications that require provable dependability.
\r
67 ******************************************************************************
\r
68 * -NOTE- The Win32 port is a simulation (or is that emulation?) only! Do not
\r
69 * expect to get real time behaviour from the Win32 port or this demo
\r
70 * application. It is provided as a convenient development and demonstration
\r
71 * test bed only. This was tested using Windows XP on a dual core laptop.
\r
73 * In this example, one simulated millisecond will take approximately 40ms to
\r
74 * execute, and the timing information in the FreeRTOS+Trace logs have no
\r
75 * meaningful units. See the documentation page for the Windows simulator for
\r
76 * an explanation of the slow timing:
\r
77 * http://www.freertos.org/FreeRTOS-Windows-Simulator-Emulator-for-Visual-Studio-and-Eclipse-MingW.html
\r
79 * Documentation for this demo can be found on:
\r
80 * http://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_Trace/Free_RTOS_Plus_Trace_CLI_Example.shtml
\r
81 ******************************************************************************
\r
83 * This is a simple FreeRTOS Windows simulator project that makes it easy to
\r
84 * evaluate FreeRTOS+CLI and FreeRTOS+Trace on a standard desktop PC, without
\r
85 * any external hardware or interfaces being required.
\r
87 * To keep everything as simple as possible, the command line interface is
\r
88 * accessed through a UDP socket on the default Windows loopback IP address of
\r
89 * 127.0.0.1. Full instructions are provided on the documentation page
\r
92 * Commands are provided to both start and stop a FreeRTOS+Trace recording.
\r
93 * Stopping a recording will result in the recorded data being saved to the
\r
94 * hard disk, ready for viewing in the FreeRTOS+Trace graphical user interface.
\r
95 * Again, full instructions are provided on the documentation page referenced
\r
98 * A queue send task and a queue receive task are defined in this file. The
\r
99 * queue receive task spends most of its time blocked on the queue waiting for
\r
100 * messages to arrive. The queue send task periodically sends a message to the
\r
101 * queue, causing the queue receive task to exit the Blocked state. The
\r
102 * priority of the queue receive task is above that of the queue send task, so
\r
103 * it pre-empts the queue send task as soon as it leaves the Blocked state. It
\r
104 * then consumes the message from the queue and prints "message received" to
\r
105 * the screen before returning to block on the queue once again. This
\r
106 * sequencing is clearly visible in the recorded FreeRTOS+Trace data.
\r
110 /* Standard includes. */
\r
112 #include <stdint.h>
\r
114 /* FreeRTOS includes. */
\r
115 #include <FreeRTOS.h>
\r
119 /* FreeRTOS+Trace includes. */
\r
120 #include "trcUser.h"
\r
122 /* Priorities at which the tasks are created. */
\r
123 #define mainQUEUE_RECEIVE_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
124 #define mainQUEUE_SEND_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
125 #define mainUDP_CLI_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
127 /* The rate at which data is sent to the queue. The (simulated) 50ms value is
\r
128 converted to ticks using the portTICK_RATE_MS constant. */
\r
129 #define mainQUEUE_SEND_FREQUENCY_MS ( 50 / portTICK_RATE_MS )
\r
131 /* The number of items the queue can hold. This is 1 as the receive task
\r
132 will remove items as they are added, meaning the send task should always find
\r
133 the queue empty. */
\r
134 #define mainQUEUE_LENGTH ( 1 )
\r
136 /*-----------------------------------------------------------*/
\r
139 * The queue send and receive tasks as described in the comments at the top of
\r
142 static void prvQueueReceiveTask( void *pvParameters );
\r
143 static void prvQueueSendTask( void *pvParameters );
\r
146 * The task that implements the UDP command interpreter using FreeRTOS+CLI.
\r
148 extern void vUDPCommandInterpreterTask( void *pvParameters );
\r
151 * Register commands that can be used with FreeRTOS+CLI through the UDP socket.
\r
152 * The commands are defined in CLI-commands.c.
\r
154 extern void vRegisterCLICommands( void );
\r
156 /* The queue used by both tasks. */
\r
157 static xQueueHandle xQueue = NULL;
\r
159 /* The user trace event posted to the trace recording on each tick interrupt.
\r
160 Note tick events will not appear in the trace recording with regular period
\r
161 because this project runs in a Windows simulator, and does not therefore
\r
162 exhibit deterministic behaviour. */
\r
163 traceLabel xTickTraceUserEvent;
\r
165 /*-----------------------------------------------------------*/
\r
169 const uint32_t ulLongTime_ms = 250UL;
\r
171 /* Initialise the trace recorder and create the label used to post user
\r
172 events to the trace recording on each tick interrupt. */
\r
173 vTraceInitTraceData();
\r
174 xTickTraceUserEvent = xTraceOpenLabel( "tick" );
\r
176 /* Create the queue used to pass messages from the queue send task to the
\r
177 queue receive task. */
\r
178 xQueue = xQueueCreate( mainQUEUE_LENGTH, sizeof( unsigned long ) );
\r
180 /* Give the queue a name for the FreeRTOS+Trace log. */
\r
181 vTraceSetQueueName( xQueue, "DemoQ" );
\r
183 /* Start the two tasks as described in the comments at the top of this
\r
185 xTaskCreate( prvQueueReceiveTask, /* The function that implements the task. */
\r
186 ( signed char * ) "Rx", /* The text name assigned to the task - for debug only as it is not used by the kernel. */
\r
187 configMINIMAL_STACK_SIZE, /* The size of the stack to allocate to the task. Not actually used as a stack in the Win32 simulator port. */
\r
188 NULL, /* The parameter passed to the task - not used in this example. */
\r
189 mainQUEUE_RECEIVE_TASK_PRIORITY, /* The priority assigned to the task. */
\r
190 NULL ); /* The task handle is not required, so NULL is passed. */
\r
192 xTaskCreate( prvQueueSendTask, ( signed char * ) "TX", configMINIMAL_STACK_SIZE, NULL, mainQUEUE_SEND_TASK_PRIORITY, NULL );
\r
194 /* Create the task that handles the CLI on a UDP port. The port number
\r
195 is set using the configUDP_CLI_PORT_NUMBER setting in FreeRTOSConfig.h. */
\r
196 xTaskCreate( vUDPCommandInterpreterTask, ( signed char * ) "CLI", configMINIMAL_STACK_SIZE, NULL, mainUDP_CLI_TASK_PRIORITY, NULL );
\r
198 /* Register commands with the FreeRTOS+CLI command interpreter. */
\r
199 vRegisterCLICommands();
\r
201 /* Start the tasks and timer running. */
\r
202 vTaskStartScheduler();
\r
204 /* If all is well, the scheduler will now be running, and the following
\r
205 line will never be reached. If the following line does execute, then
\r
206 there was insufficient FreeRTOS heap memory available for the idle and/or
\r
207 timer tasks to be created. See the memory management section on the
\r
208 FreeRTOS web site for more details (this is standard text that is not not
\r
209 really applicable to the Win32 simulator port). */
\r
212 Sleep( ulLongTime_ms );
\r
215 /*-----------------------------------------------------------*/
\r
217 static void prvQueueSendTask( void *pvParameters )
\r
219 portTickType xNextWakeTime;
\r
220 const unsigned long ulValueToSend = 100UL;
\r
222 /* Remove warning about unused parameters. */
\r
223 ( void ) pvParameters;
\r
225 /* Initialise xNextWakeTime - this only needs to be done once. */
\r
226 xNextWakeTime = xTaskGetTickCount();
\r
230 /* Place this task in the blocked state until it is time to run again.
\r
231 While in the Blocked state this task will not consume any CPU time. */
\r
232 vTaskDelayUntil( &xNextWakeTime, mainQUEUE_SEND_FREQUENCY_MS );
\r
234 /* Send to the queue - causing the queue receive task to unblock and
\r
235 write a message to the display. 0 is used as the block time so the
\r
236 sending operation will not block - it shouldn't need to block as the
\r
237 queue should always be empty at this point in the code, and it is an
\r
238 error if it is not. */
\r
239 xQueueSend( xQueue, &ulValueToSend, 0U );
\r
242 /*-----------------------------------------------------------*/
\r
244 static void prvQueueReceiveTask( void *pvParameters )
\r
246 unsigned long ulReceivedValue;
\r
248 /* Remove warning about unused parameters. */
\r
249 ( void ) pvParameters;
\r
253 /* Wait until something arrives in the queue - this task will block
\r
254 indefinitely provided INCLUDE_vTaskSuspend is set to 1 in
\r
255 FreeRTOSConfig.h. */
\r
256 xQueueReceive( xQueue, &ulReceivedValue, portMAX_DELAY );
\r
258 /* To get here something must have been received from the queue, but
\r
259 is it the expected value? If it is, write the message to the
\r
260 display before looping back to block on the queue again. */
\r
261 if( ulReceivedValue == 100UL )
\r
263 printf( "Message received!\r\n" );
\r
264 ulReceivedValue = 0U;
\r
268 /*-----------------------------------------------------------*/
\r
270 void vApplicationIdleHook( void )
\r
272 const unsigned long ulMSToSleep = 5;
\r
274 /* This function is called on each cycle of the idle task if
\r
275 configUSE_IDLE_HOOK is set to 1 in FreeRTOSConfig.h. Sleep to reduce CPU
\r
277 Sleep( ulMSToSleep );
\r
279 /*-----------------------------------------------------------*/
\r
281 void vAssertCalled( void )
\r
283 const unsigned long ulLongSleep = 1000UL;
\r
285 taskDISABLE_INTERRUPTS();
\r
288 Sleep( ulLongSleep );
\r
291 /*-----------------------------------------------------------*/
\r
293 void vApplicationTickHook( void )
\r
295 /* Write a user event to the trace log.
\r
296 Note tick events will not appear in the trace recording with regular period
\r
297 because this project runs in a Windows simulator, and does not therefore
\r
298 exhibit deterministic behaviour. */
\r
299 vTraceUserEvent( xTickTraceUserEvent );
\r