2 FreeRTOS V8.1.2 - Copyright (C) 2014 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 ***************************************************************************
\r
9 * FreeRTOS provides completely free yet professionally developed, *
\r
10 * robust, strictly quality controlled, supported, and cross *
\r
11 * platform software that has become a de facto standard. *
\r
13 * Help yourself get started quickly and support the FreeRTOS *
\r
14 * project by purchasing a FreeRTOS tutorial book, reference *
\r
15 * manual, or both from: http://www.FreeRTOS.org/Documentation *
\r
19 ***************************************************************************
\r
21 This file is part of the FreeRTOS distribution.
\r
23 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
24 the terms of the GNU General Public License (version 2) as published by the
\r
25 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
27 >>! NOTE: The modification to the GPL is included to allow you to !<<
\r
28 >>! distribute a combined work that includes FreeRTOS without being !<<
\r
29 >>! obliged to provide the source code for proprietary components !<<
\r
30 >>! outside of the FreeRTOS kernel. !<<
\r
32 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
33 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
34 FOR A PARTICULAR PURPOSE. Full license text is available from the following
\r
35 link: http://www.freertos.org/a00114.html
\r
39 ***************************************************************************
\r
41 * Having a problem? Start by reading the FAQ "My application does *
\r
42 * not run, what could be wrong?" *
\r
44 * http://www.FreeRTOS.org/FAQHelp.html *
\r
46 ***************************************************************************
\r
48 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
49 license and Real Time Engineers Ltd. contact details.
\r
51 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
52 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
53 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
55 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
56 Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
57 licenses offer ticketed support, indemnification and middleware.
\r
59 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
60 engineered and independently SIL3 certified version for use in safety and
\r
61 mission critical applications that require provable dependability.
\r
67 * This is a very simple demo that creates two tasks and one queue. One task
\r
68 * (the queue receive task) blocks on the queue to wait for data to arrive,
\r
69 * toggling an LED each time '100' is received. The other task (the queue send
\r
70 * task) repeatedly blocks for a fixed period before sending '100' to the queue
\r
71 * (causing the first task to toggle the LED).
\r
73 * For a much more complete and complex example select either the Debug or
\r
74 * Debug_with_optimisation build configurations within the HEW IDE.
\r
77 /* Hardware specific includes. */
\r
78 #include <iorx62n.h>
\r
80 /* Kernel includes. */
\r
81 #include "FreeRTOS.h"
\r
85 /* Demo includes. */
\r
86 #include "partest.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_PERIOD_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 QueueHandle_t 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 project. */
\r
111 volatile unsigned long ulHighFrequencyTickCount = 0UL;
\r
112 /*-----------------------------------------------------------*/
\r
116 extern void HardwareSetup( void );
\r
118 /* Renesas provided CPU configuration routine. The clocks are configured in
\r
122 /* Create the queue. */
\r
123 xQueue = xQueueCreate( mainQUEUE_LENGTH, sizeof( unsigned long ) );
\r
125 if( xQueue != NULL )
\r
127 /* Start the two tasks as described at the top of this file. */
\r
128 xTaskCreate( prvQueueReceiveTask, "Rx", configMINIMAL_STACK_SIZE, NULL, configQUEUE_RECEIVE_TASK_PRIORITY, NULL );
\r
129 xTaskCreate( prvQueueSendTask, "TX", configMINIMAL_STACK_SIZE, NULL, configQUEUE_SEND_TASK_PRIORITY, NULL );
\r
131 /* Start the tasks running. */
\r
132 vTaskStartScheduler();
\r
135 /* If all is well we will never reach here as the scheduler will now be
\r
136 running. If we do reach here then it is likely that there was insufficient
\r
137 heap available for the idle task to be created. */
\r
140 /*-----------------------------------------------------------*/
\r
142 static void prvQueueSendTask( void *pvParameters )
\r
144 TickType_t xNextWakeTime;
\r
145 const unsigned long ulValueToSend = 100UL;
\r
147 /* Initialise xNextWakeTime - this only needs to be done once. */
\r
148 xNextWakeTime = xTaskGetTickCount();
\r
152 /* Place this task in the blocked state until it is time to run again.
\r
153 The block state is specified in ticks, the constant used converts ticks
\r
155 vTaskDelayUntil( &xNextWakeTime, mainQUEUE_SEND_FREQUENCY_MS );
\r
157 /* Send to the queue - causing the queue receive task to flash its LED. 0
\r
158 is used so the send does not block - it shouldn't need to as the queue
\r
159 should always be empty here. */
\r
160 xQueueSend( xQueue, &ulValueToSend, 0 );
\r
163 /*-----------------------------------------------------------*/
\r
165 static void prvQueueReceiveTask( void *pvParameters )
\r
167 unsigned long ulReceivedValue;
\r
171 /* Wait until something arives in the queue - this will block
\r
172 indefinitely provided INCLUDE_vTaskSuspend is set to 1 in
\r
173 FreeRTOSConfig.h. */
\r
174 xQueueReceive( xQueue, &ulReceivedValue, portMAX_DELAY );
\r
176 /* To get here something must have arrived, but is it the expected
\r
177 value? If it is, toggle the LED. */
\r
178 if( ulReceivedValue == 100UL )
\r
180 vParTestToggleLED( 0 );
\r
184 /*-----------------------------------------------------------*/
\r
186 void vApplicationSetupTimerInterrupt( void )
\r
188 /* Enable compare match timer 0. */
\r
191 /* Interrupt on compare match. */
\r
192 CMT0.CMCR.BIT.CMIE = 1;
\r
194 /* Set the compare match value. */
\r
195 CMT0.CMCOR = ( unsigned short ) ( ( ( configPERIPHERAL_CLOCK_HZ / configTICK_RATE_HZ ) -1 ) / 8 );
\r
197 /* Divide the PCLK by 8. */
\r
198 CMT0.CMCR.BIT.CKS = 0;
\r
200 /* Enable the interrupt... */
\r
201 _IEN( _CMT0_CMI0 ) = 1;
\r
203 /* ...and set its priority to the application defined kernel priority. */
\r
204 _IPR( _CMT0_CMI0 ) = configKERNEL_INTERRUPT_PRIORITY;
\r
206 /* Start the timer. */
\r
207 CMT.CMSTR0.BIT.STR0 = 1;
\r
209 /*-----------------------------------------------------------*/
\r
211 /* This function is explained by the comments above its prototype at the top
\r
213 void vApplicationMallocFailedHook( void )
\r
217 /*-----------------------------------------------------------*/
\r
219 /* This function is explained by the comments above its prototype at the top
\r
221 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
\r
225 /*-----------------------------------------------------------*/
\r
227 /* This function is explained by the comments above its prototype at the top
\r
229 void vApplicationIdleHook( void )
\r
231 /* Just to prevent the variable getting optimised away. */
\r
232 ( void ) ulHighFrequencyTickCount;
\r
234 /*-----------------------------------------------------------*/
\r
236 /* The following two functions are here just to allow all three build
\r
237 configurations to use the same vector table. They are not used in this
\r
238 demo, but linker errors will result if they are not defined. They can
\r
240 void vT0_1InterruptHandler( void ) {}
\r
241 void vT2_3InterruptHandler( void ) {}