]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/RX600_RX62N-RDK_GNURX/RTOSDemo/main-blinky.c
Update version number.
[freertos] / FreeRTOS / Demo / RX600_RX62N-RDK_GNURX / RTOSDemo / main-blinky.c
1 /*\r
2     FreeRTOS V7.5.1 - Copyright (C) 2013 Real Time Engineers Ltd.\r
3 \r
4     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
5 \r
6     ***************************************************************************\r
7      *                                                                       *\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
11      *                                                                       *\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
15      *                                                                       *\r
16      *    Thank you!                                                         *\r
17      *                                                                       *\r
18     ***************************************************************************\r
19 \r
20     This file is part of the FreeRTOS distribution.\r
21 \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
25 \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
29     >>! kernel.\r
30 \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
35 \r
36     1 tab == 4 spaces!\r
37 \r
38     ***************************************************************************\r
39      *                                                                       *\r
40      *    Having a problem?  Start by reading the FAQ "My application does   *\r
41      *    not run, what could be wrong?"                                     *\r
42      *                                                                       *\r
43      *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
44      *                                                                       *\r
45     ***************************************************************************\r
46 \r
47     http://www.FreeRTOS.org - Documentation, books, training, latest versions,\r
48     license and Real Time Engineers Ltd. contact details.\r
49 \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
53 \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
57 \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
61 \r
62     1 tab == 4 spaces!\r
63 */\r
64 \r
65 /* \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
71  *\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
74 */\r
75 \r
76 /* Hardware specific includes. */\r
77 #include "iodefine.h"\r
78 \r
79 /* Kernel includes. */\r
80 #include "FreeRTOS.h"\r
81 #include "task.h"\r
82 #include "queue.h"\r
83 \r
84 /* Demo includes. */\r
85 #include "ParTest.h"\r
86 \r
87 /* Priorities at which the tasks are created. */\r
88 #define         configQUEUE_RECEIVE_TASK_PRIORITY       ( tskIDLE_PRIORITY + 2 )\r
89 #define         configQUEUE_SEND_TASK_PRIORITY          ( tskIDLE_PRIORITY + 1 )\r
90 \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
93 \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
96 queue empty. */\r
97 #define mainQUEUE_LENGTH                                                ( 1 )\r
98 \r
99 /*\r
100  * The tasks as defined at the top of this file.\r
101  */\r
102 static void prvQueueReceiveTask( void *pvParameters );\r
103 static void prvQueueSendTask( void *pvParameters );\r
104 \r
105 /* The queue used by both tasks. */\r
106 static xQueueHandle xQueue = NULL;\r
107 \r
108 /*-----------------------------------------------------------*/\r
109 \r
110 int main(void)\r
111 {\r
112 extern void HardwareSetup( void );\r
113 \r
114         /* Renesas provided CPU configuration routine.  The clocks are configured in\r
115         here. */\r
116         HardwareSetup();\r
117         \r
118         /* Turn all LEDs off. */\r
119         vParTestInitialise();\r
120         \r
121         /* Create the queue. */\r
122         xQueue = xQueueCreate( mainQUEUE_LENGTH, sizeof( unsigned long ) );\r
123 \r
124         if( xQueue != NULL )\r
125         {\r
126                 /* Start the two tasks as described at the top of this file. */\r
127                 xTaskCreate( prvQueueReceiveTask, ( signed char * ) "Rx", configMINIMAL_STACK_SIZE, NULL, configQUEUE_RECEIVE_TASK_PRIORITY, NULL );\r
128                 xTaskCreate( prvQueueSendTask, ( signed char * ) "TX", configMINIMAL_STACK_SIZE, NULL, configQUEUE_SEND_TASK_PRIORITY, NULL );\r
129 \r
130                 /* Start the tasks running. */\r
131                 vTaskStartScheduler();\r
132         }\r
133         \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
137         for( ;; );\r
138 }\r
139 /*-----------------------------------------------------------*/\r
140 \r
141 static void prvQueueSendTask( void *pvParameters )\r
142 {\r
143 portTickType xNextWakeTime;\r
144 const unsigned long ulValueToSend = 100UL;\r
145 \r
146         /* Initialise xNextWakeTime - this only needs to be done once. */\r
147         xNextWakeTime = xTaskGetTickCount();\r
148 \r
149         for( ;; )\r
150         {\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
153                 to ms. */\r
154                 vTaskDelayUntil( &xNextWakeTime, mainQUEUE_SEND_FREQUENCY_MS );\r
155 \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
160         }\r
161 }\r
162 /*-----------------------------------------------------------*/\r
163 \r
164 static void prvQueueReceiveTask( void *pvParameters )\r
165 {\r
166 unsigned long ulReceivedValue;\r
167 \r
168         for( ;; )\r
169         {\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
174 \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
178                 {\r
179                         vParTestToggleLED( 0 );\r
180                 }\r
181         }\r
182 }\r
183 /*-----------------------------------------------------------*/\r
184 \r
185 void vApplicationSetupTimerInterrupt( void )\r
186 {\r
187         /* Enable compare match timer 0. */\r
188         MSTP( CMT0 ) = 0;\r
189         \r
190         /* Interrupt on compare match. */\r
191         CMT0.CMCR.BIT.CMIE = 1;\r
192         \r
193         /* Set the compare match value. */\r
194         CMT0.CMCOR = ( unsigned short ) ( ( ( configPERIPHERAL_CLOCK_HZ / configTICK_RATE_HZ ) -1 ) / 8 );\r
195         \r
196         /* Divide the PCLK by 8. */\r
197         CMT0.CMCR.BIT.CKS = 0;\r
198         \r
199         /* Enable the interrupt... */\r
200         _IEN( _CMT0_CMI0 ) = 1;\r
201         \r
202         /* ...and set its priority to the application defined kernel priority. */\r
203         _IPR( _CMT0_CMI0 ) = configKERNEL_INTERRUPT_PRIORITY;\r
204         \r
205         /* Start the timer. */\r
206         CMT.CMSTR0.BIT.STR0 = 1;\r
207 }\r
208 /*-----------------------------------------------------------*/\r
209 \r
210 /* This function is explained by the comments above its prototype at the top\r
211 of this file. */\r
212 void vApplicationMallocFailedHook( void )\r
213 {\r
214         for( ;; );\r
215 }\r
216 /*-----------------------------------------------------------*/\r
217 \r
218 /* This function is explained by the comments above its prototype at the top\r
219 of this file. */\r
220 void vApplicationStackOverflowHook( xTaskHandle pxTask, signed char *pcTaskName )\r
221 {\r
222         for( ;; );\r
223 }\r
224 /*-----------------------------------------------------------*/\r
225 \r
226 /* This function is explained by the comments above its prototype at the top\r
227 of this file. */\r
228 void vApplicationIdleHook( void )\r
229 {\r
230 }\r
231 /*-----------------------------------------------------------*/\r
232 \r
233 /* The following four functions are here just to allow all three build \r
234 configurations to use the same vector table.  They are not used in this\r
235 demo, but linker errors will result if they are not defined.  They can\r
236 be ignored. */\r
237 void vT0_1_ISR_Handler( void ) {}\r
238 void vT2_3_ISR_Handler( void ) {}\r
239 void vEMAC_ISR_Handler( void ) {}\r
240 void vTimer2_ISR_Handler( void ) {}\r
241 volatile unsigned long ulHighFrequencyTickCount = 0;