2 FreeRTOS V6.0.5 - Copyright (C) 2010 Real Time Engineers Ltd.
\r
4 ***************************************************************************
\r
8 * + New to FreeRTOS, *
\r
9 * + Wanting to learn FreeRTOS or multitasking in general quickly *
\r
10 * + Looking for basic training, *
\r
11 * + Wanting to improve your FreeRTOS skills and productivity *
\r
13 * then take a look at the FreeRTOS eBook *
\r
15 * "Using the FreeRTOS Real Time Kernel - a Practical Guide" *
\r
16 * http://www.FreeRTOS.org/Documentation *
\r
18 * A pdf reference manual is also available. Both are usually delivered *
\r
19 * to your inbox within 20 minutes to two hours when purchased between 8am *
\r
20 * and 8pm GMT (although please allow up to 24 hours in case of *
\r
21 * exceptional circumstances). Thank you for your support! *
\r
23 ***************************************************************************
\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 exception to the GPL is included to allow you to distribute
\r
31 a combined work that includes FreeRTOS without being obliged to provide the
\r
32 source code for proprietary components outside of the FreeRTOS kernel.
\r
33 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT
\r
34 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
\r
35 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 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
47 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
50 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
51 licensing and training services.
\r
55 * This is a very simple demo that creates two tasks and one queue. One task
\r
56 * (the queue receive task) blocks on the queue to wait for data to arrive,
\r
57 * toggling an LED each time '100' is received. The other task (the queue send
\r
58 * task) repeatedly blocks for a fixed period before sending '100' to the queue
\r
59 * (causing the first task to toggle the LED).
\r
61 * For a much more complete and complex example select either the Debug or
\r
62 * Debug_with_optimisation build configurations within the HEW IDE.
\r
65 /* Hardware specific includes. */
\r
66 #include "iodefine.h"
\r
68 /* Kernel includes. */
\r
69 #include "FreeRTOS.h"
\r
73 /* Priorities at which the tasks are created. */
\r
74 #define configQUEUE_RECEIVE_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
75 #define configQUEUE_SEND_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
77 /* The rate at which data is sent to the queue, specified in milliseconds. */
\r
78 #define mainQUEUE_SEND_FREQUENCY_MS ( 500 / portTICK_RATE_MS )
\r
80 /* The number of items the queue can hold. This is 1 as the receive task
\r
81 will remove items as they are added so the send task should always find the
\r
83 #define mainQUEUE_LENGTH ( 1 )
\r
86 * The tasks as defined at the top of this file.
\r
88 static void prvQueueReceiveTask( void *pvParameters );
\r
89 static void prvQueueSendTask( void *pvParameters );
\r
91 /* The queue used by both tasks. */
\r
92 static xQueueHandle xQueue = NULL;
\r
94 /*-----------------------------------------------------------*/
\r
98 extern void HardwareSetup( void );
\r
100 /* Renesas provided CPU configuration routine. The clocks are configured in
\r
104 /* Turn all LEDs off. */
\r
105 vParTestInitialise();
\r
107 /* Create the queue. */
\r
108 xQueue = xQueueCreate( mainQUEUE_LENGTH, sizeof( unsigned long ) );
\r
110 if( xQueue != NULL )
\r
112 /* Start the two tasks as described at the top of this file. */
\r
113 xTaskCreate( prvQueueReceiveTask, "Rx", configMINIMAL_STACK_SIZE, NULL, configQUEUE_RECEIVE_TASK_PRIORITY, NULL );
\r
114 xTaskCreate( prvQueueSendTask, "TX", configMINIMAL_STACK_SIZE, NULL, configQUEUE_SEND_TASK_PRIORITY, NULL );
\r
116 /* Start the tasks running. */
\r
117 vTaskStartScheduler();
\r
120 /* If all is well we will never reach here as the scheduler will now be
\r
121 running. If we do reach here then it is likely that there was insufficient
\r
122 heap available for the idle task to be created. */
\r
125 /*-----------------------------------------------------------*/
\r
127 static void prvQueueSendTask( void *pvParameters )
\r
129 portTickType xNextWakeTime;
\r
130 const unsigned long ulValueToSend = 100UL;
\r
132 /* Initialise xNextWakeTime - this only needs to be done once. */
\r
133 xNextWakeTime = xTaskGetTickCount();
\r
137 /* Place this task in the blocked state until it is time to run again.
\r
138 The block state is specified in ticks, the constant used converts ticks
\r
140 vTaskDelayUntil( &xNextWakeTime, mainQUEUE_SEND_FREQUENCY_MS );
\r
142 /* Send to the queue - causing the queue receive task to flash its LED. 0
\r
143 is used so the send does not block - it shouldn't need to as the queue
\r
144 should always be empty here. */
\r
145 xQueueSend( xQueue, &ulValueToSend, 0 );
\r
148 /*-----------------------------------------------------------*/
\r
150 static void prvQueueReceiveTask( void *pvParameters )
\r
152 unsigned long ulReceivedValue;
\r
156 /* Wait until something arives in the queue - this will block
\r
157 indefinitely provided INCLUDE_vTaskSuspend is set to 1 in
\r
158 FreeRTOSConfig.h. */
\r
159 xQueueReceive( xQueue, &ulReceivedValue, portMAX_DELAY );
\r
161 /* To get here something must have arrived, but is it the expected
\r
162 value? If it is, toggle the LED. */
\r
163 if( ulReceivedValue == 100UL )
\r
165 vParTestToggleLED( 0 );
\r
169 /*-----------------------------------------------------------*/
\r
171 void vApplicationSetupTimerInterrupt( void )
\r
173 /* Enable compare match timer 0. */
\r
176 /* Interrupt on compare match. */
\r
177 CMT0.CMCR.BIT.CMIE = 1;
\r
179 /* Set the compare match value. */
\r
180 CMT0.CMCOR = ( unsigned short ) ( ( ( configPERIPHERAL_CLOCK_HZ / configTICK_RATE_HZ ) -1 ) / 8 );
\r
182 /* Divide the PCLK by 8. */
\r
183 CMT0.CMCR.BIT.CKS = 0;
\r
185 /* Enable the interrupt... */
\r
186 _IEN( _CMT0_CMI0 ) = 1;
\r
188 /* ...and set its priority to the application defined kernel priority. */
\r
189 _IPR( _CMT0_CMI0 ) = configKERNEL_INTERRUPT_PRIORITY;
\r
191 /* Start the timer. */
\r
192 CMT.CMSTR0.BIT.STR0 = 1;
\r
194 /*-----------------------------------------------------------*/
\r
196 /* This function is explained by the comments above its prototype at the top
\r
198 void vApplicationMallocFailedHook( void )
\r
202 /*-----------------------------------------------------------*/
\r
204 /* This function is explained by the comments above its prototype at the top
\r
206 void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed char *pcTaskName )
\r
210 /*-----------------------------------------------------------*/
\r
212 /* This function is explained by the comments above its prototype at the top
\r
214 void vApplicationIdleHook( void )
\r
217 /*-----------------------------------------------------------*/
\r
219 /* The following four functions are here just to allow all three build
\r
220 configurations to use the same vector table. They are not used in this
\r
221 demo, but linker errors will result if they are not defined. They can
\r
223 void vT0_1_ISR_Wrapper( void ) {}
\r
224 void vT2_3_ISR_Wrapper( void ) {}
\r
225 void vEMAC_ISR_Wrapper( void ) {}
\r
226 void vTimer2_ISR_Wrapper( void ) {}
\r
227 volatile unsigned long ulHighFrequencyTickCount = 0;