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