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