]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/RX200_RX210-RSK_Renesas/RTOSDemo/main-blinky.c
Update version numbers to V7.4.1.
[freertos] / FreeRTOS / Demo / RX200_RX210-RSK_Renesas / RTOSDemo / main-blinky.c
1 /*\r
2     FreeRTOS V7.4.1 - Copyright (C) 2013 Real Time Engineers Ltd.\r
3 \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
6 \r
7     ***************************************************************************\r
8      *                                                                       *\r
9      *    FreeRTOS tutorial books are available in pdf and paperback.        *\r
10      *    Complete, revised, and edited pdf reference manuals are also       *\r
11      *    available.                                                         *\r
12      *                                                                       *\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
19      *                                                                       *\r
20      *    >>> See http://www.FreeRTOS.org/Documentation for details. <<<     *\r
21      *                                                                       *\r
22      *    Thank you for using FreeRTOS, and thank you for your support!      *\r
23      *                                                                       *\r
24     ***************************************************************************\r
25 \r
26 \r
27     This file is part of the FreeRTOS distribution.\r
28 \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 \r
33     >>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to\r
34     distribute a combined work that includes FreeRTOS without being obliged to\r
35     provide the source code for proprietary components outside of the FreeRTOS\r
36     kernel.\r
37 \r
38     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
39     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
40     FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more\r
41     details. You should have received a copy of the GNU General Public License\r
42     and the FreeRTOS license exception along with FreeRTOS; if not it can be\r
43     viewed here: http://www.freertos.org/a00114.html and also obtained by\r
44     writing to Real Time Engineers Ltd., contact details for whom are available\r
45     on the FreeRTOS WEB site.\r
46 \r
47     1 tab == 4 spaces!\r
48 \r
49     ***************************************************************************\r
50      *                                                                       *\r
51      *    Having a problem?  Start by reading the FAQ "My application does   *\r
52      *    not run, what could be wrong?"                                     *\r
53      *                                                                       *\r
54      *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
55      *                                                                       *\r
56     ***************************************************************************\r
57 \r
58 \r
59     http://www.FreeRTOS.org - Documentation, books, training, latest versions, \r
60     license and Real Time Engineers Ltd. contact details.\r
61 \r
62     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
63     including FreeRTOS+Trace - an indispensable productivity tool, and our new\r
64     fully thread aware and reentrant UDP/IP stack.\r
65 \r
66     http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High \r
67     Integrity Systems, who sell the code with commercial support, \r
68     indemnification and middleware, under the OpenRTOS brand.\r
69     \r
70     http://www.SafeRTOS.com - High Integrity Systems also provide a safety \r
71     engineered and independently SIL3 certified version for use in safety and \r
72     mission critical applications that require provable dependability.\r
73 */\r
74 \r
75 /* \r
76  * This is a very simple demo that creates two tasks and one queue.  One task\r
77  * (the queue receive task) blocks on the queue to wait for data to arrive, \r
78  * toggling an LED each time '100' is received.  The other task (the queue send\r
79  * task) repeatedly blocks for a fixed period before sending '100' to the queue\r
80  * (causing the first task to toggle the LED). \r
81  *\r
82  * For a much more complete and complex example select either the Debug or\r
83  * Debug_with_optimisation build configurations within the HEW IDE. \r
84 */\r
85 \r
86 /* Hardware specific includes. */\r
87 #include "iodefine.h"\r
88 \r
89 /* Kernel includes. */\r
90 #include "FreeRTOS.h"\r
91 #include "task.h"\r
92 #include "queue.h"\r
93 \r
94 /* Priorities at which the tasks are created. */\r
95 #define configQUEUE_RECEIVE_TASK_PRIORITY       ( tskIDLE_PRIORITY + 1 )\r
96 #define configQUEUE_SEND_TASK_PRIORITY          ( tskIDLE_PRIORITY + 2 )\r
97 \r
98 /* The rate at which data is sent to the queue, specified in milliseconds. */\r
99 #define mainQUEUE_SEND_FREQUENCY_MS                     ( 500 / portTICK_RATE_MS )\r
100 \r
101 /* The number of items the queue can hold.  This is 1 as the receive task\r
102 will remove items as they are added so the send task should always find the\r
103 queue empty. */\r
104 #define mainQUEUE_LENGTH                                        ( 1 )\r
105 \r
106 /*\r
107  * The tasks as defined at the top of this file.\r
108  */\r
109 static void prvQueueReceiveTask( void *pvParameters );\r
110 static void prvQueueSendTask( void *pvParameters );\r
111 \r
112 /* The queue used by both tasks. */\r
113 static xQueueHandle xQueue = NULL;\r
114 \r
115 /* This variable is not used by this simple Blinky example.  It is defined \r
116 purely to allow the project to link as it is used by the full build \r
117 configuration. */\r
118 volatile unsigned long ulHighFrequencyTickCount = 0UL;\r
119 \r
120 /*-----------------------------------------------------------*/\r
121 \r
122 void main(void)\r
123 {\r
124 extern void HardwareSetup( void );\r
125 \r
126         /* Renesas provided CPU configuration routine.  The clocks are configured in\r
127         here. */\r
128         HardwareSetup();\r
129         \r
130         /* Turn all LEDs off. */\r
131         vParTestInitialise();\r
132         \r
133         /* Create the queue. */\r
134         xQueue = xQueueCreate( mainQUEUE_LENGTH, sizeof( unsigned long ) );\r
135 \r
136         if( xQueue != NULL )\r
137         {\r
138                 /* Start the two tasks as described at the top of this file. */\r
139                 xTaskCreate( prvQueueReceiveTask, "Rx", configMINIMAL_STACK_SIZE, NULL, configQUEUE_RECEIVE_TASK_PRIORITY, NULL );\r
140                 xTaskCreate( prvQueueSendTask, "TX", configMINIMAL_STACK_SIZE, NULL, configQUEUE_SEND_TASK_PRIORITY, NULL );\r
141 \r
142                 /* Start the tasks running. */\r
143                 vTaskStartScheduler();\r
144         }\r
145         \r
146         /* If all is well the next line of code will not be reached as the scheduler \r
147         will be running.  If the next line is reached then it is likely that there was \r
148         insufficient heap available for the idle task to be created. */\r
149         for( ;; );\r
150 }\r
151 /*-----------------------------------------------------------*/\r
152 \r
153 static void prvQueueSendTask( void *pvParameters )\r
154 {\r
155 portTickType xNextWakeTime;\r
156 const unsigned long ulValueToSend = 100UL;\r
157 \r
158         /* Initialise xNextWakeTime - this only needs to be done once. */\r
159         xNextWakeTime = xTaskGetTickCount();\r
160 \r
161         for( ;; )\r
162         {\r
163                 /* Place this task in the blocked state until it is time to run again. \r
164                 The block state is specified in ticks, the constant used converts ticks\r
165                 to ms. */\r
166                 vTaskDelayUntil( &xNextWakeTime, mainQUEUE_SEND_FREQUENCY_MS );\r
167 \r
168                 /* Send to the queue - causing the queue receive task to flash its LED.  0\r
169                 is used so the send does not block - it shouldn't need to as the queue\r
170                 should always be empty here (it should always be empty because the task\r
171                 removing items from the queue has a higher priority than the task adding\r
172                 things to the queue). */\r
173                 xQueueSend( xQueue, &ulValueToSend, 0UL );\r
174         }\r
175 }\r
176 /*-----------------------------------------------------------*/\r
177 \r
178 static void prvQueueReceiveTask( void *pvParameters )\r
179 {\r
180 unsigned long ulReceivedValue;\r
181 \r
182         for( ;; )\r
183         {\r
184                 /* Wait until something arives in the queue - this will block \r
185                 indefinitely provided INCLUDE_vTaskSuspend is set to 1 in\r
186                 FreeRTOSConfig.h. */\r
187                 xQueueReceive( xQueue, &ulReceivedValue, portMAX_DELAY );\r
188 \r
189                 /*  To get here something must have arrived, but is it the expected\r
190                 value?  If it is, toggle the LED. */\r
191                 if( ulReceivedValue == 100UL )\r
192                 {\r
193                         vParTestToggleLED( 0 );\r
194                 }\r
195         }\r
196 }\r
197 /*-----------------------------------------------------------*/\r
198 \r
199 /* A callback function named vApplicationSetupTimerInterrupt() must be defined\r
200 to configure a tick interrupt source, and configTICK_VECTOR set in \r
201 FreeRTOSConfig.h to install the tick interrupt handler in the correct position\r
202 in the vector table.  This example uses a compare match timer.  It can be\r
203 into any FreeRTOS project, provided the same compare match timer is available. */\r
204 void vApplicationSetupTimerInterrupt( void )\r
205 {\r
206         /* Enable compare match timer 0. */\r
207         MSTP( CMT0 ) = 0;\r
208         \r
209         /* Interrupt on compare match. */\r
210         CMT0.CMCR.BIT.CMIE = 1;\r
211         \r
212         /* Set the compare match value. */\r
213         CMT0.CMCOR = ( unsigned short ) ( ( ( configPERIPHERAL_CLOCK_HZ / configTICK_RATE_HZ ) -1 ) / 8 );\r
214         \r
215         /* Divide the PCLK by 8. */\r
216         CMT0.CMCR.BIT.CKS = 0;\r
217         \r
218         /* Enable the interrupt... */\r
219         _IEN( _CMT0_CMI0 ) = 1;\r
220         \r
221         /* ...and set its priority to the application defined kernel priority. */\r
222         _IPR( _CMT0_CMI0 ) = configKERNEL_INTERRUPT_PRIORITY;\r
223         \r
224         /* Start the timer. */\r
225         CMT.CMSTR0.BIT.STR0 = 1;\r
226 }\r
227 /*-----------------------------------------------------------*/\r
228 \r
229 /* If configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h, then this\r
230 function will be called if pvPortMalloc() returns NULL because it has exhausted\r
231 the available FreeRTOS heap space.  See http://www.freertos.org/a00111.html. */\r
232 void vApplicationMallocFailedHook( void )\r
233 {\r
234         for( ;; );\r
235 }\r
236 /*-----------------------------------------------------------*/\r
237 \r
238 /* If configCHECK_FOR_STACK_OVERFLOW is set to either 1 or 2 in \r
239 FreeRTOSConfig.h, then this function will be called if a task overflows its \r
240 stack space.  See \r
241 http://www.freertos.org/Stacks-and-stack-overflow-checking.html. */\r
242 void vApplicationStackOverflowHook( xTaskHandle pxTask, signed char *pcTaskName )\r
243 {\r
244         for( ;; );\r
245 }\r
246 /*-----------------------------------------------------------*/\r
247 \r
248 /* If configUSE_IDLE_HOOK is set to 1 in FreeRTOSConfig.h, then this function\r
249 will be called on each iteration of the idle task.  See \r
250 http://www.freertos.org/a00016.html */\r
251 void vApplicationIdleHook( void )\r
252 {\r
253         /* Just to prevent the variable getting optimised away. */\r
254         ( void ) ulHighFrequencyTickCount;\r
255 }\r
256 /*-----------------------------------------------------------*/\r