]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/RX200_RX231-RSK_Renesas_e2studio/src/Blinky_Demo/main_blinky.c
86707a05a9dc776d65b3f882d51e551d27145e57
[freertos] / FreeRTOS / Demo / RX200_RX231-RSK_Renesas_e2studio / src / Blinky_Demo / main_blinky.c
1 /*\r
2     FreeRTOS V8.2.3 - Copyright (C) 2015 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  * NOTE 1:  This project provides two demo applications.  A simple blinky style\r
72  * project, and a more comprehensive test and demo application.  The\r
73  * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting in main.c is used to select\r
74  * between the two.  See the notes on using mainCREATE_SIMPLE_BLINKY_DEMO_ONLY\r
75  * in main.c.  This file implements the simply blinky style version.\r
76  *\r
77  * NOTE 2:  This file only contains the source code that is specific to the\r
78  * basic demo.  Generic functions, such FreeRTOS hook functions, and functions\r
79  * required to configure the hardware are defined in main.c.\r
80  ******************************************************************************\r
81  *\r
82  * main_blinky() creates one queue, and two tasks.  It then starts the\r
83  * scheduler.\r
84  *\r
85  * The Queue Send Task:\r
86  * The queue send task is implemented by the prvQueueSendTask() function in\r
87  * this file.  It sends the value 100 to the queue every 200 milliseconds.\r
88  *\r
89  * The Queue Receive Task:\r
90  * The queue receive task is implemented by the prvQueueReceiveTask() function\r
91  * in this file.  It blocks on the queue to wait for data to arrive from the\r
92  * queue send task - toggling the LED each time it receives the value 100.  The\r
93  * queue send task writes to the queue every 200ms, so the LED should toggle\r
94  * every 200ms.\r
95  */\r
96 \r
97 /* Kernel includes. */\r
98 #include "FreeRTOS.h"\r
99 #include "task.h"\r
100 #include "semphr.h"\r
101 \r
102 /* Renesas includes. */\r
103 #include "rskrx231def.h"\r
104 \r
105 /* Priorities at which the tasks are created. */\r
106 #define mainQUEUE_RECEIVE_TASK_PRIORITY         ( tskIDLE_PRIORITY + 2 )\r
107 #define mainQUEUE_SEND_TASK_PRIORITY            ( tskIDLE_PRIORITY + 1 )\r
108 \r
109 /* The rate at which data is sent to the queue.  The 200ms value is converted\r
110 to ticks using the portTICK_PERIOD_MS constant. */\r
111 #define mainQUEUE_SEND_FREQUENCY_MS                     ( pdMS_TO_TICKS( 200UL ) )\r
112 \r
113 /* The number of items the queue can hold.  This is 1 as the receive task\r
114 will remove items as they are added, meaning the send task should always find\r
115 the queue empty. */\r
116 #define mainQUEUE_LENGTH                                        ( 1 )\r
117 \r
118 /*-----------------------------------------------------------*/\r
119 \r
120 /*\r
121  * Called by main when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1 in\r
122  * main.c.\r
123  */\r
124 void main_blinky( void );\r
125 \r
126 /*\r
127  * The tasks as described in the comments at the top of this file.\r
128  */\r
129 static void prvQueueReceiveTask( void *pvParameters );\r
130 static void prvQueueSendTask( void *pvParameters );\r
131 \r
132 /*-----------------------------------------------------------*/\r
133 \r
134 /* The queue used by both tasks. */\r
135 static QueueHandle_t xQueue = NULL;\r
136 \r
137 /*-----------------------------------------------------------*/\r
138 \r
139 void main_blinky( void )\r
140 {\r
141         /* Create the queue. */\r
142         xQueue = xQueueCreate( mainQUEUE_LENGTH, sizeof( uint32_t ) );\r
143 \r
144         if( xQueue != NULL )\r
145         {\r
146                 /* Start the two tasks as described in the comments at the top of this\r
147                 file. */\r
148                 xTaskCreate( prvQueueReceiveTask,                               /* The function that implements the task. */\r
149                                         "Rx",                                                           /* The text name assigned to the task - for debug only as it is not used by the kernel. */\r
150                                         configMINIMAL_STACK_SIZE,                       /* The size of the stack to allocate to the task. */\r
151                                         NULL,                                                           /* The parameter passed to the task - not used in this case. */\r
152                                         mainQUEUE_RECEIVE_TASK_PRIORITY,        /* The priority assigned to the task. */\r
153                                         NULL );                                                         /* The task handle is not required, so NULL is passed. */\r
154 \r
155                 xTaskCreate( prvQueueSendTask, "TX", configMINIMAL_STACK_SIZE, NULL, mainQUEUE_SEND_TASK_PRIORITY, NULL );\r
156 \r
157                 /* Start the tasks and timer running. */\r
158                 vTaskStartScheduler();\r
159         }\r
160 \r
161         /* If all is well, the scheduler will now be running, and the following\r
162         line will never be reached.  If the following line does execute, then\r
163         there was either insufficient FreeRTOS heap memory available for the idle\r
164         and/or timer tasks to be created, or vTaskStartScheduler() was called from\r
165         User mode.  See the memory management section on the FreeRTOS web site for\r
166         more details on the FreeRTOS heap http://www.freertos.org/a00111.html.  The\r
167         mode from which main() is called is set in the C start up code and must be\r
168         a privileged mode (not user mode). */\r
169         for( ;; );\r
170 }\r
171 /*-----------------------------------------------------------*/\r
172 \r
173 static void prvQueueSendTask( void *pvParameters )\r
174 {\r
175 TickType_t xNextWakeTime;\r
176 const unsigned long ulValueToSend = 100UL;\r
177 \r
178         /* Remove compiler warning about unused parameter. */\r
179         ( void ) pvParameters;\r
180 \r
181         /* Initialise xNextWakeTime - this only needs to be done once. */\r
182         xNextWakeTime = xTaskGetTickCount();\r
183 \r
184         for( ;; )\r
185         {\r
186                 /* Place this task in the blocked state until it is time to run again. */\r
187                 vTaskDelayUntil( &xNextWakeTime, mainQUEUE_SEND_FREQUENCY_MS );\r
188 \r
189                 /* Send to the queue - causing the queue receive task to unblock and\r
190                 toggle the LED.  0 is used as the block time so the sending operation\r
191                 will not block - it shouldn't need to block as the queue should always\r
192                 be empty at this point in the code. */\r
193                 xQueueSend( xQueue, &ulValueToSend, 0U );\r
194         }\r
195 }\r
196 /*-----------------------------------------------------------*/\r
197 \r
198 static void prvQueueReceiveTask( void *pvParameters )\r
199 {\r
200 unsigned long ulReceivedValue;\r
201 const unsigned long ulExpectedValue = 100UL;\r
202 \r
203         /* Remove compiler warning about unused parameter. */\r
204         ( void ) pvParameters;\r
205 \r
206         for( ;; )\r
207         {\r
208                 /* Wait until something arrives in the queue - this task will block\r
209                 indefinitely provided INCLUDE_vTaskSuspend is set to 1 in\r
210                 FreeRTOSConfig.h. */\r
211                 xQueueReceive( xQueue, &ulReceivedValue, portMAX_DELAY );\r
212 \r
213                 /*  To get here something must have been received from the queue, but\r
214                 is it the expected value?  If it is, toggle the LED. */\r
215                 if( ulReceivedValue == ulExpectedValue )\r
216                 {\r
217                         LED0 = !LED0;\r
218                         ulReceivedValue = 0U;\r
219                 }\r
220         }\r
221 }\r
222 /*-----------------------------------------------------------*/\r
223 \r