2 FreeRTOS V7.5.1 - Copyright (C) 2013 Real Time Engineers Ltd.
\r
4 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
6 ***************************************************************************
\r
8 * FreeRTOS provides completely free yet professionally developed, *
\r
9 * robust, strictly quality controlled, supported, and cross *
\r
10 * platform software that has become a de facto standard. *
\r
12 * Help yourself get started quickly and support the FreeRTOS *
\r
13 * project by purchasing a FreeRTOS tutorial book, reference *
\r
14 * manual, or both from: http://www.FreeRTOS.org/Documentation *
\r
18 ***************************************************************************
\r
20 This file is part of the FreeRTOS distribution.
\r
22 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
23 the terms of the GNU General Public License (version 2) as published by the
\r
24 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
26 >>! NOTE: The modification to the GPL is included to allow you to distribute
\r
27 >>! a combined work that includes FreeRTOS without being obliged to provide
\r
28 >>! the source code for proprietary components outside of the FreeRTOS
\r
31 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
32 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
33 FOR A PARTICULAR PURPOSE. Full license text is available from the following
\r
34 link: http://www.freertos.org/a00114.html
\r
38 ***************************************************************************
\r
40 * Having a problem? Start by reading the FAQ "My application does *
\r
41 * not run, what could be wrong?" *
\r
43 * http://www.FreeRTOS.org/FAQHelp.html *
\r
45 ***************************************************************************
\r
47 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
48 license and Real Time Engineers Ltd. contact details.
\r
50 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
51 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
52 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
54 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
55 Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
56 licenses offer ticketed support, indemnification and middleware.
\r
58 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
59 engineered and independently SIL3 certified version for use in safety and
\r
60 mission critical applications that require provable dependability.
\r
66 * This is a very simple demo that creates two tasks and one queue. One task
\r
67 * (the queue receive task) blocks on the queue to wait for data to arrive,
\r
68 * toggling an LED each time '100' is received. The other task (the queue send
\r
69 * task) repeatedly blocks for a fixed period before sending '100' to the queue
\r
70 * (causing the first task to toggle the LED).
\r
72 * For a much more complete and complex example select either the Debug or
\r
73 * Debug_with_optimisation build configurations within the HEW IDE.
\r
76 /* Hardware specific includes. */
\r
77 #include <iorx62n.h>
\r
79 /* Kernel includes. */
\r
80 #include "FreeRTOS.h"
\r
84 /* Demo includes. */
\r
85 #include "partest.h"
\r
87 /* Priorities at which the tasks are created. */
\r
88 #define configQUEUE_RECEIVE_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
89 #define configQUEUE_SEND_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
91 /* The rate at which data is sent to the queue, specified in milliseconds. */
\r
92 #define mainQUEUE_SEND_FREQUENCY_MS ( 500 / portTICK_RATE_MS )
\r
94 /* The number of items the queue can hold. This is 1 as the receive task
\r
95 will remove items as they are added so the send task should always find the
\r
97 #define mainQUEUE_LENGTH ( 1 )
\r
100 * The tasks as defined at the top of this file.
\r
102 static void prvQueueReceiveTask( void *pvParameters );
\r
103 static void prvQueueSendTask( void *pvParameters );
\r
105 /* The queue used by both tasks. */
\r
106 static xQueueHandle xQueue = NULL;
\r
108 /* This variable is not used by this simple Blinky example. It is defined
\r
109 purely to allow the project to link as it is used by the full project. */
\r
110 volatile unsigned long ulHighFrequencyTickCount = 0UL;
\r
111 /*-----------------------------------------------------------*/
\r
115 extern void HardwareSetup( void );
\r
117 /* Renesas provided CPU configuration routine. The clocks are configured in
\r
121 /* Create the queue. */
\r
122 xQueue = xQueueCreate( mainQUEUE_LENGTH, sizeof( unsigned long ) );
\r
124 if( xQueue != NULL )
\r
126 /* Start the two tasks as described at the top of this file. */
\r
127 xTaskCreate( prvQueueReceiveTask, "Rx", configMINIMAL_STACK_SIZE, NULL, configQUEUE_RECEIVE_TASK_PRIORITY, NULL );
\r
128 xTaskCreate( prvQueueSendTask, "TX", configMINIMAL_STACK_SIZE, NULL, configQUEUE_SEND_TASK_PRIORITY, NULL );
\r
130 /* Start the tasks running. */
\r
131 vTaskStartScheduler();
\r
134 /* If all is well we will never reach here as the scheduler will now be
\r
135 running. If we do reach here then it is likely that there was insufficient
\r
136 heap available for the idle task to be created. */
\r
139 /*-----------------------------------------------------------*/
\r
141 static void prvQueueSendTask( void *pvParameters )
\r
143 portTickType xNextWakeTime;
\r
144 const unsigned long ulValueToSend = 100UL;
\r
146 /* Initialise xNextWakeTime - this only needs to be done once. */
\r
147 xNextWakeTime = xTaskGetTickCount();
\r
151 /* Place this task in the blocked state until it is time to run again.
\r
152 The block state is specified in ticks, the constant used converts ticks
\r
154 vTaskDelayUntil( &xNextWakeTime, mainQUEUE_SEND_FREQUENCY_MS );
\r
156 /* Send to the queue - causing the queue receive task to flash its LED. 0
\r
157 is used so the send does not block - it shouldn't need to as the queue
\r
158 should always be empty here. */
\r
159 xQueueSend( xQueue, &ulValueToSend, 0 );
\r
162 /*-----------------------------------------------------------*/
\r
164 static void prvQueueReceiveTask( void *pvParameters )
\r
166 unsigned long ulReceivedValue;
\r
170 /* Wait until something arives in the queue - this will block
\r
171 indefinitely provided INCLUDE_vTaskSuspend is set to 1 in
\r
172 FreeRTOSConfig.h. */
\r
173 xQueueReceive( xQueue, &ulReceivedValue, portMAX_DELAY );
\r
175 /* To get here something must have arrived, but is it the expected
\r
176 value? If it is, toggle the LED. */
\r
177 if( ulReceivedValue == 100UL )
\r
179 vParTestToggleLED( 0 );
\r
183 /*-----------------------------------------------------------*/
\r
185 void vApplicationSetupTimerInterrupt( void )
\r
187 /* Enable compare match timer 0. */
\r
190 /* Interrupt on compare match. */
\r
191 CMT0.CMCR.BIT.CMIE = 1;
\r
193 /* Set the compare match value. */
\r
194 CMT0.CMCOR = ( unsigned short ) ( ( ( configPERIPHERAL_CLOCK_HZ / configTICK_RATE_HZ ) -1 ) / 8 );
\r
196 /* Divide the PCLK by 8. */
\r
197 CMT0.CMCR.BIT.CKS = 0;
\r
199 /* Enable the interrupt... */
\r
200 _IEN( _CMT0_CMI0 ) = 1;
\r
202 /* ...and set its priority to the application defined kernel priority. */
\r
203 _IPR( _CMT0_CMI0 ) = configKERNEL_INTERRUPT_PRIORITY;
\r
205 /* Start the timer. */
\r
206 CMT.CMSTR0.BIT.STR0 = 1;
\r
208 /*-----------------------------------------------------------*/
\r
210 /* This function is explained by the comments above its prototype at the top
\r
212 void vApplicationMallocFailedHook( void )
\r
216 /*-----------------------------------------------------------*/
\r
218 /* This function is explained by the comments above its prototype at the top
\r
220 void vApplicationStackOverflowHook( xTaskHandle pxTask, signed char *pcTaskName )
\r
224 /*-----------------------------------------------------------*/
\r
226 /* This function is explained by the comments above its prototype at the top
\r
228 void vApplicationIdleHook( void )
\r
230 /* Just to prevent the variable getting optimised away. */
\r
231 ( void ) ulHighFrequencyTickCount;
\r
233 /*-----------------------------------------------------------*/
\r
235 /* The following two functions are here just to allow all three build
\r
236 configurations to use the same vector table. They are not used in this
\r
237 demo, but linker errors will result if they are not defined. They can
\r
239 void vT0_1InterruptHandler( void ) {}
\r
240 void vT2_3InterruptHandler( void ) {}