]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_SmartFusion2_M2S050_SoftConsole/RTOSDemo/Blinky-Demo/main_blinky.c
Move SmartFusion configuration options into FreeRTOSConfig.h.
[freertos] / FreeRTOS / Demo / CORTEX_SmartFusion2_M2S050_SoftConsole / RTOSDemo / 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  * configCREATE_SIMPLE_BLINKY_DEMO_ONLY setting in FreeRTOSConifg.h is used to\r
79  * select between the two.  See the notes on using\r
80  * configCREATE_SIMPLE_BLINKY_DEMO_ONLY in main.c.  This file implements the\r
81  * simply blinky style version.\r
82  *\r
83  * NOTE 2:  This file only contains the source code that is specific to the\r
84  * basic demo.  Generic functions, such FreeRTOS hook functions, and functions\r
85  * required to configure the hardware, are defined in main.c.\r
86  ******************************************************************************\r
87  *\r
88  * main_blinky() creates one queue, and two tasks.  It then starts the\r
89  * scheduler.\r
90  *\r
91  * The Queue Send Task:\r
92  * The queue send task is implemented by the prvQueueSendTask() function in\r
93  * this file.  prvQueueSendTask() sits in a loop that causes it to repeatedly\r
94  * block for 200 milliseconds, before sending the value 100 to the queue that\r
95  * was created within main_blinky().  Once the value is sent, the task loops\r
96  * back around to block for another 200 milliseconds.\r
97  *\r
98  * The Queue Receive Task:\r
99  * The queue receive task is implemented by the prvQueueReceiveTask() function\r
100  * in this file.  prvQueueReceiveTask() sits in a loop where it repeatedly\r
101  * blocks on attempts to read data from the queue that was created within\r
102  * main_blinky().  When data is received, the task checks the value of the\r
103  * data, and if the value equals the expected 100, toggles the LED.  The 'block\r
104  * time' parameter passed to the queue receive function specifies that the\r
105  * task should be held in the Blocked state indefinitely to wait for data to\r
106  * be available on the queue.  The queue receive task will only leave the\r
107  * Blocked state when the queue send task writes to the queue.  As the queue\r
108  * send task writes to the queue every 200 milliseconds, the queue receive\r
109  * task leaves the Blocked state every 200 milliseconds, and therefore toggles\r
110  * the LED every 200 milliseconds.\r
111  */\r
112 \r
113 /* Standard includes. */\r
114 #include <stdio.h>\r
115 \r
116 /* Kernel includes. */\r
117 #include "FreeRTOS.h"\r
118 #include "task.h"\r
119 #include "semphr.h"\r
120 \r
121 /* Common demo includes. */\r
122 #include "partest.h"\r
123 \r
124 /* Priorities at which the tasks are created. */\r
125 #define mainQUEUE_RECEIVE_TASK_PRIORITY         ( tskIDLE_PRIORITY + 2 )\r
126 #define mainQUEUE_SEND_TASK_PRIORITY            ( tskIDLE_PRIORITY + 1 )\r
127 \r
128 /* The rate at which data is sent to the queue.  The 200ms value is converted\r
129 to ticks using the portTICK_RATE_MS constant. */\r
130 #define mainQUEUE_SEND_FREQUENCY_MS                     ( 200 / portTICK_RATE_MS )\r
131 \r
132 /* The number of items the queue can hold.  This is 1 as the receive task\r
133 will remove items as they are added, meaning the send task should always find\r
134 the queue empty. */\r
135 #define mainQUEUE_LENGTH                                        ( 1 )\r
136 \r
137 /* Values passed to the two tasks just to check the task parameter\r
138 functionality. */\r
139 #define mainQUEUE_SEND_PARAMETER                        ( 0x1111UL )\r
140 #define mainQUEUE_RECEIVE_PARAMETER                     ( 0x22UL )\r
141 \r
142 /*-----------------------------------------------------------*/\r
143 \r
144 /*\r
145  * The tasks as described in the comments at the top of this file.\r
146  */\r
147 static void prvQueueReceiveTask( void *pvParameters );\r
148 static void prvQueueSendTask( void *pvParameters );\r
149 \r
150 /*\r
151  * Called by main() to create the simply blinky style application if\r
152  * configCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1.\r
153  */\r
154 void main_blinky( void );\r
155 \r
156 /*-----------------------------------------------------------*/\r
157 \r
158 /* The queue used by both tasks. */\r
159 static xQueueHandle xQueue = NULL;\r
160 \r
161 /*-----------------------------------------------------------*/\r
162 \r
163 void main_blinky( void )\r
164 {\r
165         /* Create the queue. */\r
166         xQueue = xQueueCreate( mainQUEUE_LENGTH, sizeof( unsigned long ) );\r
167 \r
168         if( xQueue != NULL )\r
169         {\r
170                 /* Start the two tasks as described in the comments at the top of this\r
171                 file. */\r
172                 xTaskCreate( prvQueueReceiveTask,                                       /* The function that implements the task. */\r
173                                         ( signed char * ) "Rx",                                 /* The text name assigned to the task - for debug only as it is not used by the kernel. */\r
174                                         configMINIMAL_STACK_SIZE,                               /* The size of the stack to allocate to the task. */\r
175                                         ( void * ) mainQUEUE_RECEIVE_PARAMETER, /* The parameter passed to the task - just to check the functionality. */\r
176                                         mainQUEUE_RECEIVE_TASK_PRIORITY,                /* The priority assigned to the task. */\r
177                                         NULL );                                                                 /* The task handle is not required, so NULL is passed. */\r
178 \r
179                 xTaskCreate( prvQueueSendTask, ( signed char * ) "TX", configMINIMAL_STACK_SIZE, ( void * ) mainQUEUE_SEND_PARAMETER, mainQUEUE_SEND_TASK_PRIORITY, NULL );\r
180 \r
181                 /* Start the tasks and timer running. */\r
182                 vTaskStartScheduler();\r
183         }\r
184 \r
185         /* If all is well, the scheduler will now be running, and the following\r
186         line will never be reached.  If the following line does execute, then\r
187         there was insufficient FreeRTOS heap memory available for the idle and/or\r
188         timer tasks     to be created.  See the memory management section on the\r
189         FreeRTOS web site for more details. */\r
190         for( ;; );\r
191 }\r
192 /*-----------------------------------------------------------*/\r
193 \r
194 static void prvQueueSendTask( void *pvParameters )\r
195 {\r
196 portTickType xNextWakeTime;\r
197 const unsigned long ulValueToSend = 100UL;\r
198 \r
199         /* Check the task parameter is as expected. */\r
200         configASSERT( ( ( unsigned long ) pvParameters ) == mainQUEUE_SEND_PARAMETER );\r
201 \r
202         /* Initialise xNextWakeTime - this only needs to be done once. */\r
203         xNextWakeTime = xTaskGetTickCount();\r
204 \r
205         for( ;; )\r
206         {\r
207                 /* Place this task in the blocked state until it is time to run again.\r
208                 The block time is specified in ticks, the constant used converts ticks\r
209                 to ms.  While in the Blocked state this task will not consume any CPU\r
210                 time. */\r
211                 vTaskDelayUntil( &xNextWakeTime, mainQUEUE_SEND_FREQUENCY_MS );\r
212 \r
213                 /* Send to the queue - causing the queue receive task to unblock and\r
214                 toggle the LED.  0 is used as the block time so the sending operation\r
215                 will not block - it shouldn't need to block as the queue should always\r
216                 be empty at this point in the code. */\r
217                 xQueueSend( xQueue, &ulValueToSend, 0U );\r
218         }\r
219 }\r
220 /*-----------------------------------------------------------*/\r
221 \r
222 static void prvQueueReceiveTask( void *pvParameters )\r
223 {\r
224 unsigned long ulReceivedValue;\r
225 \r
226         /* Check the task parameter is as expected. */\r
227         configASSERT( ( ( unsigned long ) pvParameters ) == mainQUEUE_RECEIVE_PARAMETER );\r
228 \r
229         for( ;; )\r
230         {\r
231                 /* Wait until something arrives in the queue - this task will block\r
232                 indefinitely provided INCLUDE_vTaskSuspend is set to 1 in\r
233                 FreeRTOSConfig.h. */\r
234                 xQueueReceive( xQueue, &ulReceivedValue, portMAX_DELAY );\r
235 \r
236                 /*  To get here something must have been received from the queue, but\r
237                 is it the expected value?  If it is, toggle the LED. */\r
238                 if( ulReceivedValue == 100UL )\r
239                 {\r
240                         vParTestToggleLED( 0 );\r
241                         ulReceivedValue = 0U;\r
242                 }\r
243         }\r
244 }\r
245 /*-----------------------------------------------------------*/\r
246 \r