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