2 FreeRTOS V9.0.0rc1 - Copyright (C) 2016 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 This file is part of the FreeRTOS distribution.
\r
9 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
10 the terms of the GNU General Public License (version 2) as published by the
\r
11 Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.
\r
13 ***************************************************************************
\r
14 >>! NOTE: The modification to the GPL is included to allow you to !<<
\r
15 >>! distribute a combined work that includes FreeRTOS without being !<<
\r
16 >>! obliged to provide the source code for proprietary components !<<
\r
17 >>! outside of the FreeRTOS kernel. !<<
\r
18 ***************************************************************************
\r
20 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
21 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
22 FOR A PARTICULAR PURPOSE. Full license text is available on the following
\r
23 link: http://www.freertos.org/a00114.html
\r
25 ***************************************************************************
\r
27 * FreeRTOS provides completely free yet professionally developed, *
\r
28 * robust, strictly quality controlled, supported, and cross *
\r
29 * platform software that is more than just the market leader, it *
\r
30 * is the industry's de facto standard. *
\r
32 * Help yourself get started quickly while simultaneously helping *
\r
33 * to support the FreeRTOS project by purchasing a FreeRTOS *
\r
34 * tutorial book, reference manual, or both: *
\r
35 * http://www.FreeRTOS.org/Documentation *
\r
37 ***************************************************************************
\r
39 http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
\r
40 the FAQ page "My application does not run, what could be wrong?". Have you
\r
41 defined configASSERT()?
\r
43 http://www.FreeRTOS.org/support - In return for receiving this top quality
\r
44 embedded software for free we request you assist our global community by
\r
45 participating in the support forum.
\r
47 http://www.FreeRTOS.org/training - Investing in training allows your team to
\r
48 be as productive as possible as early as possible. Now you can receive
\r
49 FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
\r
50 Ltd, and the world's leading authority on the world's leading RTOS.
\r
52 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
53 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
54 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
56 http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
\r
57 Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
\r
59 http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
\r
60 Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
61 licenses offer ticketed support, indemnification and commercial middleware.
\r
63 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
64 engineered and independently SIL3 certified version for use in safety and
\r
65 mission critical applications that require provable dependability.
\r
70 /******************************************************************************
\r
71 * NOTE 1: This project provides two demo applications. A simple blinky demo
\r
72 * that demonstrates tickless low power operation, and a more comprehensive
\r
73 * test and demo application. The configCREATE_LOW_POWER_DEMO setting in
\r
74 * FreeRTOSConfig.h is used to select between the two, and to select the clock
\r
75 * used when tickless low power operation is demonstrated. See the notes on
\r
76 * using configCREATE_LOW_POWER_DEMO in main.c. This file implements the low
\r
79 * NOTE 2: This file only contains the source code that is specific to the
\r
80 * low power demo. Generic functions, such FreeRTOS hook functions, and
\r
81 * functions required to configure the hardware are defined in main.c.
\r
82 ******************************************************************************
\r
84 * main_low_power() creates one queue, and two tasks. It then starts the
\r
87 * The Queue Send Task:
\r
88 * The queue send task is implemented by the prvQueueSendTask() function in
\r
89 * this file. It sends the value 100 to the queue every second.
\r
91 * The Queue Receive Task:
\r
92 * The queue receive task is implemented by the prvQueueReceiveTask() function
\r
93 * in this file. prvQueueReceiveTask() blocks on the queue, blipping (quickly
\r
94 * turn on then off again) the LED each time it received the value 100 from the
\r
95 * queue send task. The queue send task writes to the queue every second, so
\r
96 * the LED will blip once a second.
\r
98 * The RTOS tick is turned off when the queue send task and queue receive task
\r
99 * are both in the Blocked state.
\r
104 /* Kernel includes. */
\r
105 #include "FreeRTOS.h"
\r
107 #include "semphr.h"
\r
109 /* SiLabs includes. */
\r
112 /* Priorities at which the tasks are created. */
\r
113 #define mainQUEUE_RECEIVE_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
114 #define mainQUEUE_SEND_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
116 /* The rate at which data is sent to the queue. The 200ms value is converted
\r
117 to ticks using the portTICK_PERIOD_MS constant. */
\r
118 #define mainQUEUE_SEND_FREQUENCY_MS pdMS_TO_TICKS( 1000 )
\r
120 /* The number of items the queue can hold. This is 1 as the receive task
\r
121 will remove items as they are added, meaning the send task should always find
\r
122 the queue empty. */
\r
123 #define mainQUEUE_LENGTH ( 1 )
\r
125 /* The LED toggled by the Rx task. */
\r
126 #define mainTASK_LED ( 0 )
\r
128 /*-----------------------------------------------------------*/
\r
131 * Called by main when mainCREATE_LOW_POWER_DEMO is set to 1 in
\r
134 void main_low_power( void );
\r
137 * The tasks as described in the comments at the top of this file.
\r
139 static void prvQueueReceiveTask( void *pvParameters );
\r
140 static void prvQueueSendTask( void *pvParameters );
\r
142 /*-----------------------------------------------------------*/
\r
144 /* The queue used by both tasks. */
\r
145 static QueueHandle_t xQueue = NULL;
\r
147 /*-----------------------------------------------------------*/
\r
149 void main_low_power( void )
\r
151 /* Create the queue. */
\r
152 xQueue = xQueueCreate( mainQUEUE_LENGTH, sizeof( uint32_t ) );
\r
154 if( xQueue != NULL )
\r
156 /* Start the two tasks as described in the comments at the top of this
\r
158 xTaskCreate( prvQueueReceiveTask, /* The function that implements the task. */
\r
159 "Rx", /* The text name assigned to the task - for debug only as it is not used by the kernel. */
\r
160 configMINIMAL_STACK_SIZE, /* The size of the stack to allocate to the task. */
\r
161 NULL, /* The parameter passed to the task - not used in this case. */
\r
162 mainQUEUE_RECEIVE_TASK_PRIORITY, /* The priority assigned to the task. */
\r
163 NULL ); /* The task handle is not required, so NULL is passed. */
\r
165 xTaskCreate( prvQueueSendTask, "TX", configMINIMAL_STACK_SIZE, NULL, mainQUEUE_SEND_TASK_PRIORITY, NULL );
\r
167 /* Start the tasks and timer running. */
\r
168 vTaskStartScheduler();
\r
171 /* If all is well, the scheduler will now be running, and the following
\r
172 line will never be reached. If the following line does execute, then
\r
173 there was insufficient FreeRTOS heap memory available for the Idle and/or
\r
174 timer tasks to be created. See the memory management section on the
\r
175 FreeRTOS web site for more details on the FreeRTOS heap
\r
176 http://www.freertos.org/a00111.html. */
\r
179 /*-----------------------------------------------------------*/
\r
181 static void prvQueueSendTask( void *pvParameters )
\r
183 TickType_t xNextWakeTime;
\r
184 const uint32_t ulValueToSend = 100UL;
\r
186 /* Remove compiler warning about unused parameter. */
\r
187 ( void ) pvParameters;
\r
189 /* Initialise xNextWakeTime - this only needs to be done once. */
\r
190 xNextWakeTime = xTaskGetTickCount();
\r
194 /* Place this task in the blocked state until it is time to run again. */
\r
195 vTaskDelayUntil( &xNextWakeTime, mainQUEUE_SEND_FREQUENCY_MS );
\r
197 /* Send to the queue - causing the queue receive task to unblock and
\r
198 toggle the LED. 0 is used as the block time so the sending operation
\r
199 will not block - it shouldn't need to block as the queue should always
\r
200 be empty at this point in the code. */
\r
201 xQueueSend( xQueue, &ulValueToSend, 0U );
\r
204 /*-----------------------------------------------------------*/
\r
206 static void prvQueueReceiveTask( void *pvParameters )
\r
208 uint32_t ulReceivedValue;
\r
209 const uint32_t ulExpectedValue = 100UL;
\r
210 const TickType_t xShortDelay = pdMS_TO_TICKS( 10 );
\r
212 /* Remove compiler warning about unused parameter. */
\r
213 ( void ) pvParameters;
\r
217 /* Wait until something arrives in the queue - this task will block
\r
218 indefinitely provided INCLUDE_vTaskSuspend is set to 1 in
\r
219 FreeRTOSConfig.h. */
\r
220 xQueueReceive( xQueue, &ulReceivedValue, portMAX_DELAY );
\r
222 /* To get here something must have been received from the queue, but
\r
223 is it the expected value? If it is, toggle the LED. */
\r
224 if( ulReceivedValue == ulExpectedValue )
\r
226 /* Turn the LED on for a brief time only so it doens't distort the
\r
228 BSP_LedSet( mainTASK_LED );
\r
229 vTaskDelay( xShortDelay );
\r
230 BSP_LedClear( mainTASK_LED );
\r
231 ulReceivedValue = 0U;
\r
235 /*-----------------------------------------------------------*/
\r