2 FreeRTOS V7.1.1 - Copyright (C) 2012 Real Time Engineers Ltd.
\r
5 ***************************************************************************
\r
7 * FreeRTOS tutorial books are available in pdf and paperback. *
\r
8 * Complete, revised, and edited pdf reference manuals are also *
\r
11 * Purchasing FreeRTOS documentation will not only help you, by *
\r
12 * ensuring you get running as quickly as possible and with an *
\r
13 * in-depth knowledge of how to use FreeRTOS, it will also help *
\r
14 * the FreeRTOS project to continue with its mission of providing *
\r
15 * professional grade, cross platform, de facto standard solutions *
\r
16 * for microcontrollers - completely free of charge! *
\r
18 * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
\r
20 * Thank you for using FreeRTOS, and thank you for your support! *
\r
22 ***************************************************************************
\r
25 This file is part of the FreeRTOS distribution.
\r
27 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
28 the terms of the GNU General Public License (version 2) as published by the
\r
29 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
\r
30 >>>NOTE<<< The modification to the GPL is included to allow you to
\r
31 distribute a combined work that includes FreeRTOS without being obliged to
\r
32 provide the source code for proprietary components outside of the FreeRTOS
\r
33 kernel. FreeRTOS is distributed in the hope that it will be useful, but
\r
34 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
\r
35 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
36 more details. You should have received a copy of the GNU General Public
\r
37 License and the FreeRTOS license exception along with FreeRTOS; if not it
\r
38 can be viewed here: http://www.freertos.org/a00114.html and also obtained
\r
39 by writing to Richard Barry, contact details for whom are available on the
\r
44 ***************************************************************************
\r
46 * Having a problem? Start by reading the FAQ "My application does *
\r
47 * not run, what could be wrong? *
\r
49 * http://www.FreeRTOS.org/FAQHelp.html *
\r
51 ***************************************************************************
\r
54 http://www.FreeRTOS.org - Documentation, training, latest information,
\r
55 license and contact details.
\r
57 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
58 including FreeRTOS+Trace - an indispensable productivity tool.
\r
60 Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell
\r
61 the code with commercial support, indemnification, and middleware, under
\r
62 the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also
\r
63 provide a safety engineered and independently SIL3 certified version under
\r
64 the SafeRTOS brand: http://www.SafeRTOS.com.
\r
68 * This is a very simple demo that creates two tasks and one queue. One task
\r
69 * (the queue receive task) blocks on the queue to wait for data to arrive,
\r
70 * toggling an LED each time '100' is received. The other task (the queue send
\r
71 * task) repeatedly blocks for a fixed period before sending '100' to the queue
\r
72 * (causing the first task to toggle the LED).
\r
74 * For a much more complete and complex example select either the Debug or
\r
75 * Debug_with_optimisation build configurations within the Embedded Workbench
\r
79 /* Hardware specific includes. */
\r
80 #include <iorx62n.h>
\r
82 /* Kernel includes. */
\r
83 #include "FreeRTOS.h"
\r
87 /* Demo includes. */
\r
88 #include "partest.h"
\r
90 /* Priorities at which the tasks are created. */
\r
91 #define configQUEUE_RECEIVE_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
92 #define configQUEUE_SEND_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
94 /* The rate at which data is sent to the queue, specified in milliseconds. */
\r
95 #define mainQUEUE_SEND_FREQUENCY_MS ( 500 / portTICK_RATE_MS )
\r
97 /* The number of items the queue can hold. This is 1 as the receive task
\r
98 will remove items as they are added so the send task should always find the
\r
100 #define mainQUEUE_LENGTH ( 1 )
\r
103 * The tasks as defined at the top of this file.
\r
105 static void prvQueueReceiveTask( void *pvParameters );
\r
106 static void prvQueueSendTask( void *pvParameters );
\r
108 /* The queue used by both tasks. */
\r
109 static xQueueHandle xQueue = NULL;
\r
111 /* This variable is not used by this simple Blinky example. It is defined
\r
112 purely to allow the project to link as it is used by the full project. */
\r
113 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 /* Create the queue. */
\r
125 xQueue = xQueueCreate( mainQUEUE_LENGTH, sizeof( unsigned long ) );
\r
127 if( xQueue != NULL )
\r
129 /* Start the two tasks as described at the top of this file. */
\r
130 xTaskCreate( prvQueueReceiveTask, "Rx", configMINIMAL_STACK_SIZE, NULL, configQUEUE_RECEIVE_TASK_PRIORITY, NULL );
\r
131 xTaskCreate( prvQueueSendTask, "TX", configMINIMAL_STACK_SIZE, NULL, configQUEUE_SEND_TASK_PRIORITY, NULL );
\r
133 /* Start the tasks running. */
\r
134 vTaskStartScheduler();
\r
137 /* If all is well we will never reach here as the scheduler will now be
\r
138 running. If we do reach here then it is likely that there was insufficient
\r
139 heap available for the idle task to be created. */
\r
142 /*-----------------------------------------------------------*/
\r
144 static void prvQueueSendTask( void *pvParameters )
\r
146 portTickType xNextWakeTime;
\r
147 const unsigned long ulValueToSend = 100UL;
\r
149 /* Initialise xNextWakeTime - this only needs to be done once. */
\r
150 xNextWakeTime = xTaskGetTickCount();
\r
154 /* Place this task in the blocked state until it is time to run again.
\r
155 The block state is specified in ticks, the constant used converts ticks
\r
157 vTaskDelayUntil( &xNextWakeTime, mainQUEUE_SEND_FREQUENCY_MS );
\r
159 /* Send to the queue - causing the queue receive task to flash its LED. 0
\r
160 is used so the send does not block - it shouldn't need to as the queue
\r
161 should always be empty here. */
\r
162 xQueueSend( xQueue, &ulValueToSend, 0 );
\r
165 /*-----------------------------------------------------------*/
\r
167 static void prvQueueReceiveTask( void *pvParameters )
\r
169 unsigned long ulReceivedValue;
\r
173 /* Wait until something arives in the queue - this will block
\r
174 indefinitely provided INCLUDE_vTaskSuspend is set to 1 in
\r
175 FreeRTOSConfig.h. */
\r
176 xQueueReceive( xQueue, &ulReceivedValue, portMAX_DELAY );
\r
178 /* To get here something must have arrived, but is it the expected
\r
179 value? If it is, toggle the LED. */
\r
180 if( ulReceivedValue == 100UL )
\r
182 vParTestToggleLED( 0 );
\r
186 /*-----------------------------------------------------------*/
\r
188 void vApplicationSetupTimerInterrupt( void )
\r
190 /* Enable compare match timer 0. */
\r
193 /* Interrupt on compare match. */
\r
194 CMT0.CMCR.BIT.CMIE = 1;
\r
196 /* Set the compare match value. */
\r
197 CMT0.CMCOR = ( unsigned short ) ( ( ( configPERIPHERAL_CLOCK_HZ / configTICK_RATE_HZ ) -1 ) / 8 );
\r
199 /* Divide the PCLK by 8. */
\r
200 CMT0.CMCR.BIT.CKS = 0;
\r
202 /* Enable the interrupt... */
\r
203 _IEN( _CMT0_CMI0 ) = 1;
\r
205 /* ...and set its priority to the application defined kernel priority. */
\r
206 _IPR( _CMT0_CMI0 ) = configKERNEL_INTERRUPT_PRIORITY;
\r
208 /* Start the timer. */
\r
209 CMT.CMSTR0.BIT.STR0 = 1;
\r
211 /*-----------------------------------------------------------*/
\r
213 /* This function is explained by the comments above its prototype at the top
\r
215 void vApplicationMallocFailedHook( void )
\r
219 /*-----------------------------------------------------------*/
\r
221 /* This function is explained by the comments above its prototype at the top
\r
223 void vApplicationStackOverflowHook( xTaskHandle pxTask, signed char *pcTaskName )
\r
227 /*-----------------------------------------------------------*/
\r
229 /* This function is explained by the comments above its prototype at the top
\r
231 void vApplicationIdleHook( void )
\r
233 /* Just to prevent the variable getting optimised away. */
\r
234 ( void ) ulHighFrequencyTickCount;
\r
236 /*-----------------------------------------------------------*/
\r
238 /* The following two functions are here just to allow all three build
\r
239 configurations to use the same vector table. They are not used in this
\r
240 demo, but linker errors will result if they are not defined. They can
\r
242 void vT0_1InterruptHandler( void ) {}
\r
243 void vT2_3InterruptHandler( void ) {}