2 FreeRTOS V8.2.1 - Copyright (C) 2015 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
71 * This is a very simple demo that creates two tasks and one queue. One task
\r
72 * (the queue receive task) blocks on the queue to wait for data to arrive,
\r
73 * toggling an LED each time '100' is received. The other task (the queue send
\r
74 * task) repeatedly blocks for a fixed period before sending '100' to the queue
\r
75 * (causing the first task to toggle the LED).
\r
77 * For a much more complete and complex example select either the Debug or
\r
78 * Debug_with_optimisation build configurations within the HEW IDE.
\r
81 /* Hardware specific includes. */
\r
82 #include "iodefine.h"
\r
84 /* Kernel includes. */
\r
85 #include "FreeRTOS.h"
\r
89 /* Priorities at which the tasks are created. */
\r
90 #define configQUEUE_RECEIVE_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
91 #define configQUEUE_SEND_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
93 /* The rate at which data is sent to the queue, specified in milliseconds. */
\r
94 #define mainQUEUE_SEND_FREQUENCY_MS ( 500 / portTICK_PERIOD_MS )
\r
96 /* The number of items the queue can hold. This is 1 as the receive task
\r
97 will remove items as they are added so the send task should always find the
\r
99 #define mainQUEUE_LENGTH ( 1 )
\r
102 * The tasks as defined at the top of this file.
\r
104 static void prvQueueReceiveTask( void *pvParameters );
\r
105 static void prvQueueSendTask( void *pvParameters );
\r
107 /* The queue used by both tasks. */
\r
108 static QueueHandle_t xQueue = NULL;
\r
110 /* This variable is not used by this simple Blinky example. It is defined
\r
111 purely to allow the project to link as it is used by the full build
\r
113 volatile unsigned long ulHighFrequencyTickCount = 0UL;
\r
115 /*-----------------------------------------------------------*/
\r
119 extern void HardwareSetup( void );
\r
121 /* Renesas provided CPU configuration routine. The clocks are configured in
\r
125 /* Turn all LEDs off. */
\r
126 vParTestInitialise();
\r
128 /* Create the queue. */
\r
129 xQueue = xQueueCreate( mainQUEUE_LENGTH, sizeof( unsigned long ) );
\r
131 if( xQueue != NULL )
\r
133 /* Start the two tasks as described at the top of this file. */
\r
134 xTaskCreate( prvQueueReceiveTask, "Rx", configMINIMAL_STACK_SIZE, NULL, configQUEUE_RECEIVE_TASK_PRIORITY, NULL );
\r
135 xTaskCreate( prvQueueSendTask, "TX", configMINIMAL_STACK_SIZE, NULL, configQUEUE_SEND_TASK_PRIORITY, NULL );
\r
137 /* Start the tasks running. */
\r
138 vTaskStartScheduler();
\r
141 /* If all is well the next line of code will not be reached as the scheduler
\r
142 will be running. If the next line is reached then it is likely that there was
\r
143 insufficient heap available for the idle task to be created. */
\r
146 /*-----------------------------------------------------------*/
\r
148 static void prvQueueSendTask( void *pvParameters )
\r
150 TickType_t xNextWakeTime;
\r
151 const unsigned long ulValueToSend = 100UL;
\r
153 /* Initialise xNextWakeTime - this only needs to be done once. */
\r
154 xNextWakeTime = xTaskGetTickCount();
\r
158 /* Place this task in the blocked state until it is time to run again.
\r
159 The block state is specified in ticks, the constant used converts ticks
\r
161 vTaskDelayUntil( &xNextWakeTime, mainQUEUE_SEND_FREQUENCY_MS );
\r
163 /* Send to the queue - causing the queue receive task to flash its LED. 0
\r
164 is used so the send does not block - it shouldn't need to as the queue
\r
165 should always be empty here (it should always be empty because the task
\r
166 removing items from the queue has a higher priority than the task adding
\r
167 things to the queue). */
\r
168 xQueueSend( xQueue, &ulValueToSend, 0UL );
\r
171 /*-----------------------------------------------------------*/
\r
173 static void prvQueueReceiveTask( void *pvParameters )
\r
175 unsigned long ulReceivedValue;
\r
179 /* Wait until something arives in the queue - this will block
\r
180 indefinitely provided INCLUDE_vTaskSuspend is set to 1 in
\r
181 FreeRTOSConfig.h. */
\r
182 xQueueReceive( xQueue, &ulReceivedValue, portMAX_DELAY );
\r
184 /* To get here something must have arrived, but is it the expected
\r
185 value? If it is, toggle the LED. */
\r
186 if( ulReceivedValue == 100UL )
\r
188 vParTestToggleLED( 0 );
\r
192 /*-----------------------------------------------------------*/
\r
194 /* A callback function named vApplicationSetupTimerInterrupt() must be defined
\r
195 to configure a tick interrupt source, and configTICK_VECTOR set in
\r
196 FreeRTOSConfig.h to install the tick interrupt handler in the correct position
\r
197 in the vector table. This example uses a compare match timer. It can be
\r
198 into any FreeRTOS project, provided the same compare match timer is available. */
\r
199 void vApplicationSetupTimerInterrupt( void )
\r
201 /* Enable compare match timer 0. */
\r
204 /* Interrupt on compare match. */
\r
205 CMT0.CMCR.BIT.CMIE = 1;
\r
207 /* Set the compare match value. */
\r
208 CMT0.CMCOR = ( unsigned short ) ( ( ( configPERIPHERAL_CLOCK_HZ / configTICK_RATE_HZ ) -1 ) / 8 );
\r
210 /* Divide the PCLK by 8. */
\r
211 CMT0.CMCR.BIT.CKS = 0;
\r
213 /* Enable the interrupt... */
\r
214 _IEN( _CMT0_CMI0 ) = 1;
\r
216 /* ...and set its priority to the application defined kernel priority. */
\r
217 _IPR( _CMT0_CMI0 ) = configKERNEL_INTERRUPT_PRIORITY;
\r
219 /* Start the timer. */
\r
220 CMT.CMSTR0.BIT.STR0 = 1;
\r
222 /*-----------------------------------------------------------*/
\r
224 /* If configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h, then this
\r
225 function will be called if pvPortMalloc() returns NULL because it has exhausted
\r
226 the available FreeRTOS heap space. See http://www.freertos.org/a00111.html. */
\r
227 void vApplicationMallocFailedHook( void )
\r
231 /*-----------------------------------------------------------*/
\r
233 /* If configCHECK_FOR_STACK_OVERFLOW is set to either 1 or 2 in
\r
234 FreeRTOSConfig.h, then this function will be called if a task overflows its
\r
236 http://www.freertos.org/Stacks-and-stack-overflow-checking.html. */
\r
237 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
\r
241 /*-----------------------------------------------------------*/
\r
243 /* If configUSE_IDLE_HOOK is set to 1 in FreeRTOSConfig.h, then this function
\r
244 will be called on each iteration of the idle task. See
\r
245 http://www.freertos.org/a00016.html */
\r
246 void vApplicationIdleHook( void )
\r
248 /* Just to prevent the variable getting optimised away. */
\r
249 ( void ) ulHighFrequencyTickCount;
\r
251 /*-----------------------------------------------------------*/
\r