]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/RX600_RX62N-RDK_IAR/main-blinky.c
Update version number to 9.0.0rc2.
[freertos] / FreeRTOS / Demo / RX600_RX62N-RDK_IAR / main-blinky.c
1 /*\r
2     FreeRTOS V9.0.0rc2 - Copyright (C) 2016 Real Time Engineers Ltd.\r
3     All rights reserved\r
4 \r
5     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
6 \r
7     This file is part of the FreeRTOS distribution.\r
8 \r
9     FreeRTOS is free software; you can redistribute it and/or modify it under\r
10     the terms of the GNU General Public License (version 2) as published by the\r
11     Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.\r
12 \r
13     ***************************************************************************\r
14     >>!   NOTE: The modification to the GPL is included to allow you to     !<<\r
15     >>!   distribute a combined work that includes FreeRTOS without being   !<<\r
16     >>!   obliged to provide the source code for proprietary components     !<<\r
17     >>!   outside of the FreeRTOS kernel.                                   !<<\r
18     ***************************************************************************\r
19 \r
20     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
21     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
22     FOR A PARTICULAR PURPOSE.  Full license text is available on the following\r
23     link: http://www.freertos.org/a00114.html\r
24 \r
25     ***************************************************************************\r
26      *                                                                       *\r
27      *    FreeRTOS provides completely free yet professionally developed,    *\r
28      *    robust, strictly quality controlled, supported, and cross          *\r
29      *    platform software that is more than just the market leader, it     *\r
30      *    is the industry's de facto standard.                               *\r
31      *                                                                       *\r
32      *    Help yourself get started quickly while simultaneously helping     *\r
33      *    to support the FreeRTOS project by purchasing a FreeRTOS           *\r
34      *    tutorial book, reference manual, or both:                          *\r
35      *    http://www.FreeRTOS.org/Documentation                              *\r
36      *                                                                       *\r
37     ***************************************************************************\r
38 \r
39     http://www.FreeRTOS.org/FAQHelp.html - Having a problem?  Start by reading\r
40     the FAQ page "My application does not run, what could be wrong?".  Have you\r
41     defined configASSERT()?\r
42 \r
43     http://www.FreeRTOS.org/support - In return for receiving this top quality\r
44     embedded software for free we request you assist our global community by\r
45     participating in the support forum.\r
46 \r
47     http://www.FreeRTOS.org/training - Investing in training allows your team to\r
48     be as productive as possible as early as possible.  Now you can receive\r
49     FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers\r
50     Ltd, and the world's leading authority on the world's leading RTOS.\r
51 \r
52     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
53     including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
54     compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
55 \r
56     http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.\r
57     Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.\r
58 \r
59     http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High\r
60     Integrity Systems ltd. to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
61     licenses offer ticketed support, indemnification and commercial middleware.\r
62 \r
63     http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
64     engineered and independently SIL3 certified version for use in safety and\r
65     mission critical applications that require provable dependability.\r
66 \r
67     1 tab == 4 spaces!\r
68 */\r
69 \r
70 /*\r
71  * This is a very simple demo that creates two tasks and one queue.  One task\r
72  * (the queue receive task) blocks on the queue to wait for data to arrive,\r
73  * toggling an LED each time '100' is received.  The other task (the queue send\r
74  * task) repeatedly blocks for a fixed period before sending '100' to the queue\r
75  * (causing the first task to toggle the LED).\r
76  *\r
77  * For a much more complete and complex example select either the Debug or\r
78  * Debug_with_optimisation build configurations within the Embedded Workbench\r
79  * IDE.\r
80 */\r
81 \r
82 /* Hardware specific includes. */\r
83 #include <iorx62n.h>\r
84 \r
85 /* Kernel includes. */\r
86 #include "FreeRTOS.h"\r
87 #include "task.h"\r
88 #include "queue.h"\r
89 \r
90 /* Demo includes. */\r
91 #include "partest.h"\r
92 \r
93 /* Priorities at which the tasks are created. */\r
94 #define configQUEUE_RECEIVE_TASK_PRIORITY       ( tskIDLE_PRIORITY + 1 )\r
95 #define configQUEUE_SEND_TASK_PRIORITY          ( tskIDLE_PRIORITY + 2 )\r
96 \r
97 /* The rate at which data is sent to the queue, specified in milliseconds. */\r
98 #define mainQUEUE_SEND_FREQUENCY_MS                     ( 500 / portTICK_PERIOD_MS )\r
99 \r
100 /* The number of items the queue can hold.  This is 1 as the receive task\r
101 will remove items as they are added so the send task should always find the\r
102 queue empty. */\r
103 #define mainQUEUE_LENGTH                                        ( 1 )\r
104 \r
105 /*\r
106  * The tasks as defined at the top of this file.\r
107  */\r
108 static void prvQueueReceiveTask( void *pvParameters );\r
109 static void prvQueueSendTask( void *pvParameters );\r
110 \r
111 /* The queue used by both tasks. */\r
112 static QueueHandle_t xQueue = NULL;\r
113 \r
114 /* This variable is not used by this simple Blinky example.  It is defined\r
115 purely to allow the project to link as it is used by the full project. */\r
116 volatile unsigned long ulHighFrequencyTickCount = 0UL;\r
117 /*-----------------------------------------------------------*/\r
118 \r
119 void main(void)\r
120 {\r
121 extern void HardwareSetup( void );\r
122 \r
123         /* Renesas provided CPU configuration routine.  The clocks are configured in\r
124         here. */\r
125         HardwareSetup();\r
126 \r
127         /* Create the queue. */\r
128         xQueue = xQueueCreate( mainQUEUE_LENGTH, sizeof( unsigned long ) );\r
129 \r
130         if( xQueue != NULL )\r
131         {\r
132                 /* Start the two tasks as described at the top of this file. */\r
133                 xTaskCreate( prvQueueReceiveTask, "Rx", configMINIMAL_STACK_SIZE, NULL, configQUEUE_RECEIVE_TASK_PRIORITY, NULL );\r
134                 xTaskCreate( prvQueueSendTask, "TX", configMINIMAL_STACK_SIZE, NULL, configQUEUE_SEND_TASK_PRIORITY, NULL );\r
135 \r
136                 /* Start the tasks running. */\r
137                 vTaskStartScheduler();\r
138         }\r
139 \r
140         /* If all is well we will never reach here as the scheduler will now be\r
141         running.  If we do reach here then it is likely that there was insufficient\r
142         heap available for the idle task to be created. */\r
143         for( ;; );\r
144 }\r
145 /*-----------------------------------------------------------*/\r
146 \r
147 static void prvQueueSendTask( void *pvParameters )\r
148 {\r
149 TickType_t xNextWakeTime;\r
150 const unsigned long ulValueToSend = 100UL;\r
151 \r
152         /* Initialise xNextWakeTime - this only needs to be done once. */\r
153         xNextWakeTime = xTaskGetTickCount();\r
154 \r
155         for( ;; )\r
156         {\r
157                 /* Place this task in the blocked state until it is time to run again.\r
158                 The block state is specified in ticks, the constant used converts ticks\r
159                 to ms. */\r
160                 vTaskDelayUntil( &xNextWakeTime, mainQUEUE_SEND_FREQUENCY_MS );\r
161 \r
162                 /* Send to the queue - causing the queue receive task to flash its LED.  0\r
163                 is used so the send does not block - it shouldn't need to as the queue\r
164                 should always be empty here. */\r
165                 xQueueSend( xQueue, &ulValueToSend, 0 );\r
166         }\r
167 }\r
168 /*-----------------------------------------------------------*/\r
169 \r
170 static void prvQueueReceiveTask( void *pvParameters )\r
171 {\r
172 unsigned long ulReceivedValue;\r
173 \r
174         for( ;; )\r
175         {\r
176                 /* Wait until something arives in the queue - this will block\r
177                 indefinitely provided INCLUDE_vTaskSuspend is set to 1 in\r
178                 FreeRTOSConfig.h. */\r
179                 xQueueReceive( xQueue, &ulReceivedValue, portMAX_DELAY );\r
180 \r
181                 /*  To get here something must have arrived, but is it the expected\r
182                 value?  If it is, toggle the LED. */\r
183                 if( ulReceivedValue == 100UL )\r
184                 {\r
185                         vParTestToggleLED( 0 );\r
186                 }\r
187         }\r
188 }\r
189 /*-----------------------------------------------------------*/\r
190 \r
191 void vApplicationSetupTimerInterrupt( void )\r
192 {\r
193         /* Enable compare match timer 0. */\r
194         MSTP( CMT0 ) = 0;\r
195 \r
196         /* Interrupt on compare match. */\r
197         CMT0.CMCR.BIT.CMIE = 1;\r
198 \r
199         /* Set the compare match value. */\r
200         CMT0.CMCOR = ( unsigned short ) ( ( ( configPERIPHERAL_CLOCK_HZ / configTICK_RATE_HZ ) -1 ) / 8 );\r
201 \r
202         /* Divide the PCLK by 8. */\r
203         CMT0.CMCR.BIT.CKS = 0;\r
204 \r
205         /* Enable the interrupt... */\r
206         _IEN( _CMT0_CMI0 ) = 1;\r
207 \r
208         /* ...and set its priority to the application defined kernel priority. */\r
209         _IPR( _CMT0_CMI0 ) = configKERNEL_INTERRUPT_PRIORITY;\r
210 \r
211         /* Start the timer. */\r
212         CMT.CMSTR0.BIT.STR0 = 1;\r
213 }\r
214 /*-----------------------------------------------------------*/\r
215 \r
216 /* This function is explained by the comments above its prototype at the top\r
217 of this file. */\r
218 void vApplicationMallocFailedHook( void )\r
219 {\r
220         for( ;; );\r
221 }\r
222 /*-----------------------------------------------------------*/\r
223 \r
224 /* This function is explained by the comments above its prototype at the top\r
225 of this file. */\r
226 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )\r
227 {\r
228         for( ;; );\r
229 }\r
230 /*-----------------------------------------------------------*/\r
231 \r
232 /* This function is explained by the comments above its prototype at the top\r
233 of this file. */\r
234 void vApplicationIdleHook( void )\r
235 {\r
236         /* Just to prevent the variable getting optimised away. */\r
237         ( void ) ulHighFrequencyTickCount;\r
238 }\r
239 /*-----------------------------------------------------------*/\r
240 \r
241 /* The following two functions are here just to allow all three build\r
242 configurations to use the same vector table.  They are not used in this\r
243 demo, but linker errors will result if they are not defined.  They can\r
244 be ignored. */\r
245 void vT0_1InterruptHandler( void ) {}\r
246 void vT2_3InterruptHandler( void ) {}