]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/RX600_RX63N-RDK_Renesas/RTOSDemo/main-blinky.c
Update version number to 9.0.0rc2.
[freertos] / FreeRTOS / Demo / RX600_RX63N-RDK_Renesas / RTOSDemo / 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, one queue, and one \r
72  * software timer.  For a much more complete and complex example select either \r
73  * the Debug or Debug_with_optimisation build configurations within the HEW,\r
74  * which build main_full.c in place of this file.\r
75  * \r
76  * One task (the queue receive task) blocks on the queue to wait for data to \r
77  * arrive, toggling LED0 each time '100' is received.  The other task (the \r
78  * queue send task) repeatedly blocks for a fixed period before sending '100' \r
79  * to the queue (causing the first task to toggle the LED). \r
80  *\r
81  * The software timer is configured to auto-reload.  The timer callback \r
82  * function periodically toggles LED1.\r
83  */\r
84 \r
85 /* Kernel includes. */\r
86 #include "FreeRTOS.h"\r
87 #include "task.h"\r
88 #include "timers.h"\r
89 #include "queue.h"\r
90 \r
91 /* Priorities at which the tasks are created. */\r
92 #define configQUEUE_RECEIVE_TASK_PRIORITY       ( tskIDLE_PRIORITY + 1 )\r
93 #define configQUEUE_SEND_TASK_PRIORITY          ( tskIDLE_PRIORITY + 2 )\r
94 \r
95 /* The rate at which data is sent to the queue, specified in milliseconds. */\r
96 #define mainQUEUE_SEND_PERIOD_MS                        ( 500 / portTICK_PERIOD_MS )\r
97 \r
98 /* The period of the software timer, specified in milliseconds. */\r
99 #define mainSOFTWARE_TIMER_PERIOD_MS            ( 150 / portTICK_PERIOD_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 /* The LEDs toggle by the task and timer respectively. */\r
107 #define mainTASK_LED                                            ( 0 )\r
108 #define mainTIMER_LED                                           ( 1 )\r
109 \r
110 /*\r
111  * The tasks as defined at the top of this file.\r
112  */\r
113 static void prvQueueReceiveTask( void *pvParameters );\r
114 static void prvQueueSendTask( void *pvParameters );\r
115 \r
116 /*\r
117  * The callback function used by the software timer.\r
118  */\r
119 static void prvBlinkyTimerCallback( TimerHandle_t xTimer );\r
120 \r
121 /* The queue used by both tasks. */\r
122 static QueueHandle_t xQueue = NULL;\r
123 \r
124 /* This variable is not used by this simple Blinky example.  It is defined \r
125 purely to allow the project to link as it is used by the full project. */\r
126 volatile unsigned long ulHighFrequencyTickCount = 0UL;\r
127 /*-----------------------------------------------------------*/\r
128 \r
129 void main(void)\r
130 {\r
131 TimerHandle_t xTimer;\r
132 \r
133         /* Turn all LEDs off. */\r
134         vParTestInitialise();\r
135         \r
136         /* Create the queue. */\r
137         xQueue = xQueueCreate( mainQUEUE_LENGTH, sizeof( unsigned long ) );\r
138 \r
139         /* Create the software timer, as described at the top of this file. */\r
140         xTimer = xTimerCreate( "BlinkyTimer",                                   /* Just a text name to make debugging easier - not used by the scheduler. */\r
141                                                         mainSOFTWARE_TIMER_PERIOD_MS,   /* The timer period. */\r
142                                                         pdTRUE,                                                 /* Set to pdTRUE for periodic timer, or pdFALSE for one-shot timer. */\r
143                                                         NULL,                                                   /* The timer ID is not required. */\r
144                                                         prvBlinkyTimerCallback );               /* The function executed when the timer expires. */\r
145                                                         \r
146         if( xTimer != NULL )\r
147         {\r
148                 /* Start the timer - it will not actually start running until the\r
149                 scheduler has started.  The block time is set to 0, although, because\r
150                 xTimerStart() is being called before the scheduler has been started,\r
151                 the any block time specified would be ignored anyway. */\r
152                 xTimerStart( xTimer, 0UL );\r
153         }\r
154         \r
155         if( xQueue != NULL )\r
156         {\r
157                 /* Start the two tasks as described at the top of this file. */\r
158                 xTaskCreate( prvQueueReceiveTask,                                       /* The function that implements the task. */\r
159                                          "Rx",                                                                  /* Just a text name to make debugging easier - not used by the scheduler. */\r
160                                          configMINIMAL_STACK_SIZE,                              /* The size of the task stack, in words. */\r
161                                          NULL,                                                                  /* The task parameter is not used. */\r
162                                          configQUEUE_RECEIVE_TASK_PRIORITY,     /* The priority assigned to the task when it is created. */\r
163                                          NULL );                                                                /* The task handle is not used. */\r
164                                          \r
165                 xTaskCreate( prvQueueSendTask, "TX", configMINIMAL_STACK_SIZE, NULL, configQUEUE_SEND_TASK_PRIORITY, NULL );\r
166 \r
167                 /* Start the tasks running. */\r
168                 vTaskStartScheduler();\r
169         }\r
170         \r
171         /* If all is well we will never reach here as the scheduler will now be\r
172         running.  If we do reach here then it is likely that there was insufficient\r
173         heap available for the idle task to be created. */\r
174         for( ;; );\r
175 }\r
176 /*-----------------------------------------------------------*/\r
177 \r
178 static void prvQueueSendTask( void *pvParameters )\r
179 {\r
180 TickType_t xNextWakeTime;\r
181 const unsigned long ulValueToSend = 100UL;\r
182 \r
183         /* Initialise xNextWakeTime - this only needs to be done once. */\r
184         xNextWakeTime = xTaskGetTickCount();\r
185 \r
186         for( ;; )\r
187         {\r
188                 /* Place this task in the blocked state until it is time to run again. \r
189                 The block state is specified in ticks, the constant used converts ticks\r
190                 to ms. */\r
191                 vTaskDelayUntil( &xNextWakeTime, mainQUEUE_SEND_PERIOD_MS );\r
192 \r
193                 /* Send to the queue - causing the queue receive task to flash its LED.  0\r
194                 is used so the send does not block - it shouldn't need to as the queue\r
195                 should always be empty here. */\r
196                 xQueueSend( xQueue, &ulValueToSend, 0 );\r
197         }\r
198 }\r
199 /*-----------------------------------------------------------*/\r
200 \r
201 static void prvQueueReceiveTask( void *pvParameters )\r
202 {\r
203 unsigned long ulReceivedValue;\r
204 \r
205         for( ;; )\r
206         {\r
207                 /* Wait until something arives in the queue - this will block \r
208                 indefinitely provided INCLUDE_vTaskSuspend is set to 1 in\r
209                 FreeRTOSConfig.h. */\r
210                 xQueueReceive( xQueue, &ulReceivedValue, portMAX_DELAY );\r
211 \r
212                 /*  To get here something must have arrived, but is it the expected\r
213                 value?  If it is, toggle the LED. */\r
214                 if( ulReceivedValue == 100UL )\r
215                 {\r
216                         vParTestToggleLED( mainTASK_LED );\r
217                 }\r
218         }\r
219 }\r
220 /*-----------------------------------------------------------*/\r
221 \r
222 static void prvBlinkyTimerCallback( TimerHandle_t xTimer )\r
223 {\r
224         /* The software timer does nothing but toggle an LED. */\r
225         vParTestToggleLED( mainTIMER_LED );\r
226 }\r
227 /*-----------------------------------------------------------*/\r
228 \r
229 void vApplicationSetupTimerInterrupt( void )\r
230 {\r
231         /* Enable compare match timer 0. */\r
232         MSTP( CMT0 ) = 0;\r
233         \r
234         /* Interrupt on compare match. */\r
235         CMT0.CMCR.BIT.CMIE = 1;\r
236         \r
237         /* Set the compare match value. */\r
238         CMT0.CMCOR = ( unsigned short ) ( ( ( configPERIPHERAL_CLOCK_HZ / configTICK_RATE_HZ ) -1 ) / 8 );\r
239         \r
240         /* Divide the PCLK by 8. */\r
241         CMT0.CMCR.BIT.CKS = 0;\r
242         \r
243         /* Enable the interrupt... */\r
244         _IEN( _CMT0_CMI0 ) = 1;\r
245         \r
246         /* ...and set its priority to the application defined kernel priority. */\r
247         _IPR( _CMT0_CMI0 ) = configKERNEL_INTERRUPT_PRIORITY;\r
248         \r
249         /* Start the timer. */\r
250         CMT.CMSTR0.BIT.STR0 = 1;\r
251 }\r
252 /*-----------------------------------------------------------*/\r
253 \r
254 /* This function is explained by the comments above its prototype at the top\r
255 of this file. */\r
256 void vApplicationMallocFailedHook( void )\r
257 {\r
258         for( ;; );\r
259 }\r
260 /*-----------------------------------------------------------*/\r
261 \r
262 /* This function is explained by the comments above its prototype at the top\r
263 of this file. */\r
264 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )\r
265 {\r
266         for( ;; );\r
267 }\r
268 /*-----------------------------------------------------------*/\r
269 \r
270 /* This function is explained by the comments above its prototype at the top\r
271 of this file. */\r
272 void vApplicationIdleHook( void )\r
273 {\r
274         /* Just to prevent the variable getting optimised away. */\r
275         ( void ) ulHighFrequencyTickCount;\r
276 }\r
277 /*-----------------------------------------------------------*/\r