2 FreeRTOS V7.3.0 - Copyright (C) 2012 Real Time Engineers Ltd.
\r
4 FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT
\r
5 http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 ***************************************************************************
\r
9 * FreeRTOS tutorial books are available in pdf and paperback. *
\r
10 * Complete, revised, and edited pdf reference manuals are also *
\r
13 * Purchasing FreeRTOS documentation will not only help you, by *
\r
14 * ensuring you get running as quickly as possible and with an *
\r
15 * in-depth knowledge of how to use FreeRTOS, it will also help *
\r
16 * the FreeRTOS project to continue with its mission of providing *
\r
17 * professional grade, cross platform, de facto standard solutions *
\r
18 * for microcontrollers - completely free of charge! *
\r
20 * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
\r
22 * Thank you for using FreeRTOS, and thank you for your support! *
\r
24 ***************************************************************************
\r
27 This file is part of the FreeRTOS distribution.
\r
29 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
30 the terms of the GNU General Public License (version 2) as published by the
\r
31 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
\r
32 >>>NOTE<<< The modification to the GPL is included to allow you to
\r
33 distribute a combined work that includes FreeRTOS without being obliged to
\r
34 provide the source code for proprietary components outside of the FreeRTOS
\r
35 kernel. FreeRTOS is distributed in the hope that it will be useful, but
\r
36 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
\r
37 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
38 more details. You should have received a copy of the GNU General Public
\r
39 License and the FreeRTOS license exception along with FreeRTOS; if not it
\r
40 can be viewed here: http://www.freertos.org/a00114.html and also obtained
\r
41 by writing to Richard Barry, contact details for whom are available on the
\r
46 ***************************************************************************
\r
48 * Having a problem? Start by reading the FAQ "My application does *
\r
49 * not run, what could be wrong?" *
\r
51 * http://www.FreeRTOS.org/FAQHelp.html *
\r
53 ***************************************************************************
\r
56 http://www.FreeRTOS.org - Documentation, training, latest versions, license
\r
57 and contact details.
\r
59 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
60 including FreeRTOS+Trace - an indispensable productivity tool.
\r
62 Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell
\r
63 the code with commercial support, indemnification, and middleware, under
\r
64 the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also
\r
65 provide a safety engineered and independently SIL3 certified version under
\r
66 the SafeRTOS brand: http://www.SafeRTOS.com.
\r
70 * This is a very simple demo that creates two tasks and one queue. One task
\r
71 * (the queue receive task) blocks on the queue to wait for data to arrive,
\r
72 * toggling an LED each time '100' is received. The other task (the queue send
\r
73 * task) repeatedly blocks for a fixed period before sending '100' to the queue
\r
74 * (causing the first task to toggle the LED).
\r
76 * For a much more complete and complex example select either the Debug or
\r
77 * Debug_with_optimisation build configurations within the HEW IDE.
\r
80 /* Hardware specific includes. */
\r
81 #include "iodefine.h"
\r
83 /* Kernel includes. */
\r
84 #include "FreeRTOS.h"
\r
88 /* Priorities at which the tasks are created. */
\r
89 #define configQUEUE_RECEIVE_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
90 #define configQUEUE_SEND_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
92 /* The rate at which data is sent to the queue, specified in milliseconds. */
\r
93 #define mainQUEUE_SEND_FREQUENCY_MS ( 500 / portTICK_RATE_MS )
\r
95 /* The number of items the queue can hold. This is 1 as the receive task
\r
96 will remove items as they are added so the send task should always find the
\r
98 #define mainQUEUE_LENGTH ( 1 )
\r
101 * The tasks as defined at the top of this file.
\r
103 static void prvQueueReceiveTask( void *pvParameters );
\r
104 static void prvQueueSendTask( void *pvParameters );
\r
106 /* The queue used by both tasks. */
\r
107 static xQueueHandle xQueue = NULL;
\r
109 /* This variable is not used by this simple Blinky example. It is defined
\r
110 purely to allow the project to link as it is used by the full build
\r
112 volatile unsigned long ulHighFrequencyTickCount = 0UL;
\r
114 /*-----------------------------------------------------------*/
\r
118 extern void HardwareSetup( void );
\r
120 /* Renesas provided CPU configuration routine. The clocks are configured in
\r
124 /* Turn all LEDs off. */
\r
125 vParTestInitialise();
\r
127 /* Create the queue. */
\r
128 xQueue = xQueueCreate( mainQUEUE_LENGTH, sizeof( unsigned long ) );
\r
130 if( xQueue != NULL )
\r
132 /* Start the two tasks as described at the top of this file. */
\r
133 xTaskCreate( prvQueueReceiveTask, "Rx", configMINIMAL_STACK_SIZE, NULL, configQUEUE_RECEIVE_TASK_PRIORITY, NULL );
\r
134 xTaskCreate( prvQueueSendTask, "TX", configMINIMAL_STACK_SIZE, NULL, configQUEUE_SEND_TASK_PRIORITY, NULL );
\r
136 /* Start the tasks running. */
\r
137 vTaskStartScheduler();
\r
140 /* If all is well the next line of code will not be reached as the scheduler
\r
141 will be running. If the next line is reached then it is likely that there was
\r
142 insufficient heap available for the idle task to be created. */
\r
145 /*-----------------------------------------------------------*/
\r
147 static void prvQueueSendTask( void *pvParameters )
\r
149 portTickType xNextWakeTime;
\r
150 const unsigned long ulValueToSend = 100UL;
\r
152 /* Initialise xNextWakeTime - this only needs to be done once. */
\r
153 xNextWakeTime = xTaskGetTickCount();
\r
157 /* Place this task in the blocked state until it is time to run again.
\r
158 The block state is specified in ticks, the constant used converts ticks
\r
160 vTaskDelayUntil( &xNextWakeTime, mainQUEUE_SEND_FREQUENCY_MS );
\r
162 /* Send to the queue - causing the queue receive task to flash its LED. 0
\r
163 is used so the send does not block - it shouldn't need to as the queue
\r
164 should always be empty here (it should always be empty because the task
\r
165 removing items from the queue has a higher priority than the task adding
\r
166 things to the queue). */
\r
167 xQueueSend( xQueue, &ulValueToSend, 0UL );
\r
170 /*-----------------------------------------------------------*/
\r
172 static void prvQueueReceiveTask( void *pvParameters )
\r
174 unsigned long ulReceivedValue;
\r
178 /* Wait until something arives in the queue - this will block
\r
179 indefinitely provided INCLUDE_vTaskSuspend is set to 1 in
\r
180 FreeRTOSConfig.h. */
\r
181 xQueueReceive( xQueue, &ulReceivedValue, portMAX_DELAY );
\r
183 /* To get here something must have arrived, but is it the expected
\r
184 value? If it is, toggle the LED. */
\r
185 if( ulReceivedValue == 100UL )
\r
187 vParTestToggleLED( 0 );
\r
191 /*-----------------------------------------------------------*/
\r
193 /* A callback function named vApplicationSetupTimerInterrupt() must be defined
\r
194 to configure a tick interrupt source, and configTICK_VECTOR set in
\r
195 FreeRTOSConfig.h to install the tick interrupt handler in the correct position
\r
196 in the vector table. This example uses a compare match timer. It can be
\r
197 into any FreeRTOS project, provided the same compare match timer is available. */
\r
198 void vApplicationSetupTimerInterrupt( void )
\r
200 /* Enable compare match timer 0. */
\r
203 /* Interrupt on compare match. */
\r
204 CMT0.CMCR.BIT.CMIE = 1;
\r
206 /* Set the compare match value. */
\r
207 CMT0.CMCOR = ( unsigned short ) ( ( ( configPERIPHERAL_CLOCK_HZ / configTICK_RATE_HZ ) -1 ) / 8 );
\r
209 /* Divide the PCLK by 8. */
\r
210 CMT0.CMCR.BIT.CKS = 0;
\r
212 /* Enable the interrupt... */
\r
213 _IEN( _CMT0_CMI0 ) = 1;
\r
215 /* ...and set its priority to the application defined kernel priority. */
\r
216 _IPR( _CMT0_CMI0 ) = configKERNEL_INTERRUPT_PRIORITY;
\r
218 /* Start the timer. */
\r
219 CMT.CMSTR0.BIT.STR0 = 1;
\r
221 /*-----------------------------------------------------------*/
\r
223 /* If configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h, then this
\r
224 function will be called if pvPortMalloc() returns NULL because it has exhausted
\r
225 the available FreeRTOS heap space. See http://www.freertos.org/a00111.html. */
\r
226 void vApplicationMallocFailedHook( void )
\r
230 /*-----------------------------------------------------------*/
\r
232 /* If configCHECK_FOR_STACK_OVERFLOW is set to either 1 or 2 in
\r
233 FreeRTOSConfig.h, then this function will be called if a task overflows its
\r
235 http://www.freertos.org/Stacks-and-stack-overflow-checking.html. */
\r
236 void vApplicationStackOverflowHook( xTaskHandle pxTask, signed char *pcTaskName )
\r
240 /*-----------------------------------------------------------*/
\r
242 /* If configUSE_IDLE_HOOK is set to 1 in FreeRTOSConfig.h, then this function
\r
243 will be called on each iteration of the idle task. See
\r
244 http://www.freertos.org/a00016.html */
\r
245 void vApplicationIdleHook( void )
\r
247 /* Just to prevent the variable getting optimised away. */
\r
248 ( void ) ulHighFrequencyTickCount;
\r
250 /*-----------------------------------------------------------*/
\r