2 FreeRTOS V7.6.0 - 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
66 /******************************************************************************
\r
67 * NOTE 1: This project provides two demo applications. A simple blinky style
\r
68 * project, and a more comprehensive demo application that makes use of some
\r
69 * add-on components. The mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting in main.c
\r
70 * is used to select between the two. See the notes on using
\r
71 * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY in main.c. This file implements the
\r
72 * simply blinky style version.
\r
74 * NOTE 2: This file only contains the source code that is specific to the
\r
75 * basic demo. Generic functions, such FreeRTOS hook functions, and functions
\r
76 * required to configure the hardware, are defined in main.c.
\r
77 ******************************************************************************
\r
79 * main_blinky() creates one queue, and two tasks and one software timer. It
\r
80 * then starts the scheduler.
\r
82 * The Queue Send Task:
\r
83 * The queue send task is implemented by the prvQueueSendTask() function in
\r
84 * this file. The task sits in a loop that sends a value to the queue every
\r
87 * The Queue Receive Task:
\r
88 * The queue receive task is implemented by the prvQueueReceiveTask() function
\r
89 * in this file. The task sits in a loop that blocks on the queue to wait for
\r
90 * data to arrive (it does not use any CPU time while it is in the Blocked
\r
91 * state), toggling an LED each time it receives the value sent by the queue
\r
92 * send task. As the queue send task writes to the queue every 200 milliseconds
\r
93 * the LED will toggle every 200 milliseconds.
\r
97 /* Kernel includes. */
\r
98 #include "FreeRTOS.h"
\r
101 #include "timers.h"
\r
103 /* Priorities at which the tasks are created. */
\r
104 #define mainQUEUE_RECEIVE_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
105 #define mainQUEUE_SEND_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
107 /* The rate at which data is sent to the queue. The 200ms value is converted
\r
108 to ticks using the portTICK_RATE_MS constant. */
\r
109 #define mainQUEUE_SEND_FREQUENCY_MS ( 200 / portTICK_RATE_MS )
\r
111 /* The number of items the queue can hold. This is 1 as the receive task
\r
112 will remove items as they are added, meaning the send task should always find
\r
113 the queue empty. */
\r
114 #define mainQUEUE_LENGTH ( 1 )
\r
116 /* Values passed to the two tasks just to check the task parameter
\r
118 #define mainQUEUE_SEND_PARAMETER ( 0x1111UL )
\r
119 #define mainQUEUE_RECEIVE_PARAMETER ( 0x22UL )
\r
121 /* The period of the blinky software timer. The period is specified in ms and
\r
122 converted to ticks using the portTICK_RATE_MS constant. */
\r
123 #define mainBLINKY_TIMER_PERIOD ( 50 / portTICK_RATE_MS )
\r
125 /* A block time of zero simply means "don't block". */
\r
126 #define mainDONT_BLOCK ( 0 )
\r
128 /* The LEDs toggled by the timer and queue receive task respectively. */
\r
129 #define mainTIMER_LED LED0_GPIO
\r
130 #define mainTASK_LED LED1_GPIO
\r
132 /*-----------------------------------------------------------*/
\r
135 * The tasks as described in the comments at the top of this file.
\r
137 static void prvQueueReceiveTask( void *pvParameters );
\r
138 static void prvQueueSendTask( void *pvParameters );
\r
141 * The callback function for the blinky software timer, as described at the top
\r
144 static void prvBlinkyTimerCallback( xTimerHandle xTimer );
\r
147 * Called by main() to create the simply blinky style application if
\r
148 * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1.
\r
150 void main_blinky( void );
\r
152 /*-----------------------------------------------------------*/
\r
154 /* The queue used by both tasks. */
\r
155 static xQueueHandle xQueue = NULL;
\r
157 /*-----------------------------------------------------------*/
\r
159 void main_blinky( void )
\r
161 xTimerHandle xTimer;
\r
163 /* Create the queue. */
\r
164 xQueue = xQueueCreate( mainQUEUE_LENGTH, sizeof( unsigned long ) );
\r
166 if( xQueue != NULL )
\r
168 /* Start the two tasks as described in the comments at the top of this
\r
170 xTaskCreate( prvQueueReceiveTask, /* The function that implements the task. */
\r
171 ( signed char * ) "Rx", /* The text name assigned to the task - for debug only as it is not used by the kernel. */
\r
172 configMINIMAL_STACK_SIZE, /* The size of the stack to allocate to the task. */
\r
173 ( void * ) mainQUEUE_RECEIVE_PARAMETER, /* The parameter passed to the task - just to check the functionality. */
\r
174 mainQUEUE_RECEIVE_TASK_PRIORITY, /* The priority assigned to the task. */
\r
175 NULL ); /* The task handle is not required, so NULL is passed. */
\r
177 xTaskCreate( prvQueueSendTask, ( signed char * ) "TX", configMINIMAL_STACK_SIZE, ( void * ) mainQUEUE_SEND_PARAMETER, mainQUEUE_SEND_TASK_PRIORITY, NULL );
\r
179 /* Create the blinky software timer as described at the top of this
\r
181 xTimer = xTimerCreate( ( const signed char * ) "Blinky",/* A text name, purely to help debugging. */
\r
182 ( mainBLINKY_TIMER_PERIOD ), /* The timer period. */
\r
183 pdTRUE, /* This is an auto-reload timer, so xAutoReload is set to pdTRUE. */
\r
184 ( void * ) 0, /* The ID is not used, so can be set to anything. */
\r
185 prvBlinkyTimerCallback ); /* The callback function that inspects the status of all the other tasks. */
\r
187 configASSERT( xTimer );
\r
189 if( xTimer != NULL )
\r
191 xTimerStart( xTimer, mainDONT_BLOCK );
\r
194 /* Start the tasks and timer running. */
\r
195 vTaskStartScheduler();
\r
198 /* If all is well, the scheduler will now be running, and the following
\r
199 line will never be reached. If the following line does execute, then
\r
200 there was insufficient FreeRTOS heap memory available for the idle and/or
\r
201 timer tasks to be created. See the memory management section on the
\r
202 FreeRTOS web site for more details. */
\r
205 /*-----------------------------------------------------------*/
\r
207 static void prvQueueSendTask( void *pvParameters )
\r
209 portTickType xNextWakeTime;
\r
210 const unsigned long ulValueToSend = 100UL;
\r
212 /* Check the task parameter is as expected. */
\r
213 configASSERT( ( ( unsigned long ) pvParameters ) == mainQUEUE_SEND_PARAMETER );
\r
215 /* Initialise xNextWakeTime - this only needs to be done once. */
\r
216 xNextWakeTime = xTaskGetTickCount();
\r
220 /* Place this task in the blocked state until it is time to run again.
\r
221 The block time is specified in ticks, the constant used converts ticks
\r
222 to ms. While in the Blocked state this task will not consume any CPU
\r
224 vTaskDelayUntil( &xNextWakeTime, mainQUEUE_SEND_FREQUENCY_MS );
\r
226 /* Send to the queue - causing the queue receive task to unblock and
\r
227 toggle the LED. 0 is used as the block time so the sending operation
\r
228 will not block - it shouldn't need to block as the queue should always
\r
229 be empty at this point in the code. */
\r
230 xQueueSend( xQueue, &ulValueToSend, 0U );
\r
233 /*-----------------------------------------------------------*/
\r
235 static void prvQueueReceiveTask( void *pvParameters )
\r
237 unsigned long ulReceivedValue;
\r
239 /* Check the task parameter is as expected. */
\r
240 configASSERT( ( ( unsigned long ) pvParameters ) == mainQUEUE_RECEIVE_PARAMETER );
\r
244 /* Wait until something arrives in the queue - this task will block
\r
245 indefinitely provided INCLUDE_vTaskSuspend is set to 1 in
\r
246 FreeRTOSConfig.h. */
\r
247 xQueueReceive( xQueue, &ulReceivedValue, portMAX_DELAY );
\r
249 /* To get here something must have been received from the queue, but
\r
250 is it the expected value? If it is, toggle the LED. */
\r
251 if( ulReceivedValue == 100UL )
\r
253 ioport_toggle_pin_level( mainTASK_LED );
\r
254 ulReceivedValue = 0U;
\r
258 /*-----------------------------------------------------------*/
\r
260 static void prvBlinkyTimerCallback( xTimerHandle xTimer )
\r
262 /* Avoid compiler warnings. */
\r
265 /* This function is called when the blinky software time expires. All the
\r
266 function does is toggle the LED. LED mainTIMER_LED should therefore toggle
\r
267 with the period set by mainBLINKY_TIMER_PERIOD. */
\r
268 ioport_toggle_pin_level( mainTIMER_LED );
\r
270 /*-----------------------------------------------------------*/
\r