]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/Xilinx_FreeRTOS_BSP/repo/sw_apps/freertos_hello_world/src/freertos_hello_world.c
Final commit before tagging - cosmetic changes only.
[freertos] / FreeRTOS / Demo / Xilinx_FreeRTOS_BSP / repo / sw_apps / freertos_hello_world / src / freertos_hello_world.c
1 /*\r
2     FreeRTOS V8.2.2 - 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  * This is a very simply blinky style example that can be generated\r
72  * automatically by the Xilinx SDK.\r
73  *\r
74  * The example generates a Tx task, an Rx task, and a queue.  The Tx task\r
75  * simply uses the queue to send a value to the Rx task every 500ms.  The Rx\r
76  * prints out a message each time it receives the value.\r
77  *\r
78  * The demo does little in the way of hardware configuration.  Separate projects\r
79  * are provided that include comprehensive demos which demonstrate additional\r
80  * hardware configuration, and additional FreeRTOS features.  See the following\r
81  * link for more details: http://www.freertos.org/a00090.html#XILINX\r
82  */\r
83 \r
84 /* FreeRTOS includes. */\r
85 #include "FreeRTOS.h"\r
86 #include "task.h"\r
87 #include "queue.h"\r
88 \r
89 /* Xilinx includes. */\r
90 #include "xil_printf.h"\r
91 #include "xparameters.h"\r
92 \r
93 /*-----------------------------------------------------------*/\r
94 \r
95 /* The Tx and Rx tasks as described at the top of this file. */\r
96 static void prvTxTask( void *pvParameters );\r
97 static void prvRxTask( void *pvParameters );\r
98 \r
99 /*-----------------------------------------------------------*/\r
100 \r
101 /* The queue used by the Tx and Rx tasks, as described at the top of this\r
102 file. */\r
103 static QueueHandle_t xQueue = NULL;\r
104 \r
105 int main( void )\r
106 {\r
107         xil_printf( "Hello from Freertos\r\n" );\r
108 \r
109         /* Create the two tasks.  The Tx task is given a lower priority than the\r
110         Rx task, so the Rx task will leave the Blocked state and pre-empt the Tx\r
111         task as soon as the Tx task places an item in the queue. */\r
112         xTaskCreate(    prvTxTask,                                      /* The function that implements the task. */\r
113                                         ( const char * ) "Tx",          /* Text name for the task, provided to assist debugging only. */\r
114                                         configMINIMAL_STACK_SIZE,       /* The stack allocated to the task. */\r
115                                         NULL,                                           /* The task parameter is not used, so set to NULL. */\r
116                                         tskIDLE_PRIORITY,                       /* The task runs at the idle priority. */\r
117                                         NULL );\r
118 \r
119         xTaskCreate( prvRxTask, ( const char * ) "GB",  configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1, NULL );\r
120 \r
121         /* Create the queue used by the tasks.  The Rx task has a higher priority\r
122         than the Tx task, so will preempt the Tx task and remove values from the\r
123         queue as soon as the Tx task writes to the queue - therefore the queue can\r
124         never have more than one item in it. */\r
125         xQueue = xQueueCreate(  1,                                              /* There is only one space in the queue. */\r
126                                                         sizeof( uint32_t ) );   /* Each space in the queue is large enough to hold a uint32_t. */\r
127 \r
128         /* Check the queue was created. */\r
129         configASSERT( xQueue );\r
130 \r
131         /* Start the tasks and timer running. */\r
132         vTaskStartScheduler();\r
133 \r
134         /* If all is well, the scheduler will now be running, and the following line\r
135         will never be reached.  If the following line does execute, then there was\r
136         insufficient FreeRTOS heap memory available for the idle and/or timer tasks\r
137         to be created.  See the memory management section on the FreeRTOS web site\r
138         for more details. */\r
139         for( ;; );\r
140 }\r
141 /*-----------------------------------------------------------*/\r
142 \r
143 static void prvTxTask( void *pvParameters )\r
144 {\r
145 const TickType_t x500ms = pdMS_TO_TICKS( 500UL );\r
146 uint32_t ulValueToSend = 0;\r
147 \r
148         for( ;; )\r
149         {\r
150                 /* Delay for 500ms. */\r
151                 vTaskDelay( x500ms );\r
152 \r
153                 /* Send the next value on the queue.  The queue should always be\r
154                 empty at this point so a block time of 0 is used. */\r
155                 xQueueSend( xQueue,                     /* The queue being written to. */\r
156                                         &ulValueToSend, /* The address of the data being sent. */\r
157                                         0UL );                  /* The block time. */\r
158 \r
159                 ulValueToSend++;\r
160         }\r
161 }\r
162 /*-----------------------------------------------------------*/\r
163 \r
164 static void prvRxTask( void *pvParameters )\r
165 {\r
166 uint32_t ulValueReceived;\r
167 \r
168         for( ;; )\r
169         {\r
170                 /* Block to wait for data arriving on the queue. */\r
171                 xQueueReceive(  xQueue,                         /* The queue being read. */\r
172                                                 &ulValueReceived,       /* Data is read into this address. */\r
173                                                 portMAX_DELAY );        /* Wait without a timeout for data. */\r
174 \r
175                 /* Print the received data. */\r
176                 xil_printf( "Rx task received %d\r\n", ( int ) ulValueReceived );\r
177         }\r
178 }\r
179 \r
180 \r