]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/RX600_RX64M_RSK_GCC_e2studio/src/main_blinky.c
Update version number to 8.1.2 after moving the defaulting of configUSE_PORT_OPTIMISE...
[freertos] / FreeRTOS / Demo / RX600_RX64M_RSK_GCC_e2studio / src / main_blinky.c
1 /*\r
2     FreeRTOS V8.1.2 - Copyright (C) 2014 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     ***************************************************************************\r
8      *                                                                       *\r
9      *    FreeRTOS provides completely free yet professionally developed,    *\r
10      *    robust, strictly quality controlled, supported, and cross          *\r
11      *    platform software that has become a de facto standard.             *\r
12      *                                                                       *\r
13      *    Help yourself get started quickly and support the FreeRTOS         *\r
14      *    project by purchasing a FreeRTOS tutorial book, reference          *\r
15      *    manual, or both from: http://www.FreeRTOS.org/Documentation        *\r
16      *                                                                       *\r
17      *    Thank you!                                                         *\r
18      *                                                                       *\r
19     ***************************************************************************\r
20 \r
21     This file is part of the FreeRTOS distribution.\r
22 \r
23     FreeRTOS is free software; you can redistribute it and/or modify it under\r
24     the terms of the GNU General Public License (version 2) as published by the\r
25     Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.\r
26 \r
27     >>!   NOTE: The modification to the GPL is included to allow you to     !<<\r
28     >>!   distribute a combined work that includes FreeRTOS without being   !<<\r
29     >>!   obliged to provide the source code for proprietary components     !<<\r
30     >>!   outside of the FreeRTOS kernel.                                   !<<\r
31 \r
32     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
33     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
34     FOR A PARTICULAR PURPOSE.  Full license text is available from the following\r
35     link: http://www.freertos.org/a00114.html\r
36 \r
37     1 tab == 4 spaces!\r
38 \r
39     ***************************************************************************\r
40      *                                                                       *\r
41      *    Having a problem?  Start by reading the FAQ "My application does   *\r
42      *    not run, what could be wrong?"                                     *\r
43      *                                                                       *\r
44      *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
45      *                                                                       *\r
46     ***************************************************************************\r
47 \r
48     http://www.FreeRTOS.org - Documentation, books, training, latest versions,\r
49     license and Real Time Engineers Ltd. contact details.\r
50 \r
51     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
52     including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
53     compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
54 \r
55     http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High\r
56     Integrity Systems to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
57     licenses offer ticketed support, indemnification and middleware.\r
58 \r
59     http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
60     engineered and independently SIL3 certified version for use in safety and\r
61     mission critical applications that require provable dependability.\r
62 \r
63     1 tab == 4 spaces!\r
64 */\r
65 \r
66 /******************************************************************************\r
67  * NOTE 1:  This project provides two demo applications.  A simple blinky style\r
68  * project, and a more comprehensive test and demo application.  The\r
69  * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting in main.c is used to select\r
70  * between the two.  See the notes on using mainCREATE_SIMPLE_BLINKY_DEMO_ONLY\r
71  * in main.c.  This file implements the simply blinky style version.\r
72  *\r
73  * NOTE 2:  This file only contains the source code that is specific to the\r
74  * basic demo.  Generic functions, such FreeRTOS hook functions, and functions\r
75  * required to configure the hardware are defined in main.c.\r
76  ******************************************************************************\r
77  *\r
78  * main_blinky() creates one queue, and two tasks.  It then starts the\r
79  * scheduler.\r
80  *\r
81  * The Queue Send Task:\r
82  * The queue send task is implemented by the prvQueueSendTask() function in\r
83  * this file.  prvQueueSendTask() sits in a loop that causes it to repeatedly\r
84  * block for 200 milliseconds, before sending the value 100 to the queue that\r
85  * was created within main_blinky().  Once the value is sent, the task loops\r
86  * back around to block for another 200 milliseconds...and so on.\r
87  *\r
88  * The Queue Receive Task:\r
89  * The queue receive task is implemented by the prvQueueReceiveTask() function\r
90  * in this file.  prvQueueReceiveTask() sits in a loop where it repeatedly\r
91  * blocks on attempts to read data from the queue that was created within\r
92  * main_blinky().  When data is received, the task checks the value of the\r
93  * data, and if the value equals the expected 100, toggles an LED.  The 'block\r
94  * time' parameter passed to the queue receive function specifies that the\r
95  * task should be held in the Blocked state indefinitely to wait for data to\r
96  * be available on the queue.  The queue receive task will only leave the\r
97  * Blocked state when the queue send task writes to the queue.  As the queue\r
98  * send task writes to the queue every 200 milliseconds, the queue receive\r
99  * task leaves the Blocked state every 200 milliseconds, and therefore toggles\r
100  * the LED every 200 milliseconds.\r
101  */\r
102 \r
103 /* Kernel includes. */\r
104 #include "FreeRTOS.h"\r
105 #include "task.h"\r
106 #include "semphr.h"\r
107 \r
108 /* Standard demo includes. */\r
109 #include "partest.h"\r
110 \r
111 /* Priorities at which the tasks are created. */\r
112 #define mainQUEUE_RECEIVE_TASK_PRIORITY         ( tskIDLE_PRIORITY + 2 )\r
113 #define mainQUEUE_SEND_TASK_PRIORITY            ( tskIDLE_PRIORITY + 1 )\r
114 \r
115 /* The rate at which data is sent to the queue.  The 200ms value is converted\r
116 to ticks using the portTICK_PERIOD_MS constant. */\r
117 #define mainQUEUE_SEND_FREQUENCY_MS                     ( 200 / portTICK_PERIOD_MS )\r
118 \r
119 /* The number of items the queue can hold.  This is 1 as the receive task\r
120 will remove items as they are added, meaning the send task should always find\r
121 the queue empty. */\r
122 #define mainQUEUE_LENGTH                                        ( 1 )\r
123 \r
124 /* The LED toggled by the Rx task. */\r
125 #define mainTASK_LED                                            ( 0 )\r
126 \r
127 /*-----------------------------------------------------------*/\r
128 \r
129 /*\r
130  * The tasks as described in the comments at the top of this file.\r
131  */\r
132 static void prvQueueReceiveTask( void *pvParameters );\r
133 static void prvQueueSendTask( void *pvParameters );\r
134 \r
135 /*\r
136  * Called by main() to create the simply blinky style application if\r
137  * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1.\r
138  */\r
139 void main_blinky( void );\r
140 \r
141 /*-----------------------------------------------------------*/\r
142 \r
143 /* The queue used by both tasks. */\r
144 static QueueHandle_t xQueue = NULL;\r
145 \r
146 /*-----------------------------------------------------------*/\r
147 \r
148 void main_blinky( void )\r
149 {\r
150         /* Create the queue. */\r
151         xQueue = xQueueCreate( mainQUEUE_LENGTH, sizeof( uint32_t ) );\r
152 \r
153         if( xQueue != NULL )\r
154         {\r
155                 /* Start the two tasks as described in the comments at the top of this\r
156                 file. */\r
157                 xTaskCreate( prvQueueReceiveTask,                               /* The function that implements the task. */\r
158                                         "Rx",                                                           /* The text name assigned to the task - for debug only as it is not used by the kernel. */\r
159                                         configMINIMAL_STACK_SIZE,                       /* The size of the stack to allocate to the task. */\r
160                                         NULL,                                                           /* The parameter passed to the task - not used in this case. */\r
161                                         mainQUEUE_RECEIVE_TASK_PRIORITY,        /* The priority assigned to the task. */\r
162                                         NULL );                                                         /* The task handle is not required, so NULL is passed. */\r
163 \r
164                 xTaskCreate( prvQueueSendTask, "TX", configMINIMAL_STACK_SIZE, NULL, mainQUEUE_SEND_TASK_PRIORITY, NULL );\r
165 \r
166                 /* Start the tasks and timer running. */\r
167                 vTaskStartScheduler();\r
168         }\r
169 \r
170         /* If all is well, the scheduler will now be running, and the following\r
171         line will never be reached.  If the following line does execute, then\r
172         there was either insufficient FreeRTOS heap memory available for the idle\r
173         and/or timer tasks to be created, or vTaskStartScheduler() was called from\r
174         User mode.  See the memory management section on the FreeRTOS web site for\r
175         more details on the FreeRTOS heap http://www.freertos.org/a00111.html.  The\r
176         mode from which main() is called is set in the C start up code and must be\r
177         a privileged mode (not user mode). */\r
178         for( ;; );\r
179 }\r
180 /*-----------------------------------------------------------*/\r
181 \r
182 static void prvQueueSendTask( void *pvParameters )\r
183 {\r
184 TickType_t xNextWakeTime;\r
185 const uint32_t ulValueToSend = 100UL;\r
186 \r
187         /* Remove compiler warning about unused parameter. */\r
188         ( void ) pvParameters;\r
189 \r
190         /* Initialise xNextWakeTime - this only needs to be done once. */\r
191         xNextWakeTime = xTaskGetTickCount();\r
192 \r
193         for( ;; )\r
194         {\r
195                 /* Place this task in the blocked state until it is time to run again. */\r
196                 vTaskDelayUntil( &xNextWakeTime, mainQUEUE_SEND_FREQUENCY_MS );\r
197 \r
198                 /* Send to the queue - causing the queue receive task to unblock and\r
199                 toggle the LED.  0 is used as the block time so the sending operation\r
200                 will not block - it shouldn't need to block as the queue should always\r
201                 be empty at this point in the code. */\r
202                 xQueueSend( xQueue, &ulValueToSend, 0U );\r
203         }\r
204 }\r
205 /*-----------------------------------------------------------*/\r
206 \r
207 volatile uint32_t ulRxEvents = 0;\r
208 \r
209 static void prvQueueReceiveTask( void *pvParameters )\r
210 {\r
211 uint32_t ulReceivedValue;\r
212 const uint32_t ulExpectedValue = 100UL;\r
213 \r
214         /* Remove compiler warning about unused parameter. */\r
215         ( void ) pvParameters;\r
216 \r
217         for( ;; )\r
218         {\r
219                 /* Wait until something arrives in the queue - this task will block\r
220                 indefinitely provided INCLUDE_vTaskSuspend is set to 1 in\r
221                 FreeRTOSConfig.h. */\r
222                 xQueueReceive( xQueue, &ulReceivedValue, portMAX_DELAY );\r
223 \r
224                 /*  To get here something must have been received from the queue, but\r
225                 is it the expected value?  If it is, toggle the LED. */\r
226                 if( ulReceivedValue == ulExpectedValue )\r
227                 {\r
228                         vParTestToggleLED( mainTASK_LED );\r
229                         ulReceivedValue = 0U;\r
230                         ulRxEvents++;\r
231                 }\r
232         }\r
233 }\r
234 /*-----------------------------------------------------------*/\r
235 \r