]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/Xilinx_FreeRTOS_BSP/repo/sw_apps/freertos_hello_world/src/freertos_hello_world.c
Add FreeRTOS BSP for Xilinx SDK.
[freertos] / FreeRTOS / Demo / Xilinx_FreeRTOS_BSP / repo / sw_apps / freertos_hello_world / src / freertos_hello_world.c
1 /*
2     FreeRTOS V8.2.1 - Copyright (C) 2015 Real Time Engineers Ltd.
3     All rights reserved
4
5     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
6
7     This file is part of the FreeRTOS distribution.
8
9     FreeRTOS is free software; you can redistribute it and/or modify it under
10     the terms of the GNU General Public License (version 2) as published by the
11     Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
12
13     ***************************************************************************
14     >>!   NOTE: The modification to the GPL is included to allow you to     !<<
15     >>!   distribute a combined work that includes FreeRTOS without being   !<<
16     >>!   obliged to provide the source code for proprietary components     !<<
17     >>!   outside of the FreeRTOS kernel.                                   !<<
18     ***************************************************************************
19
20     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
21     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
22     FOR A PARTICULAR PURPOSE.  Full license text is available on the following
23     link: http://www.freertos.org/a00114.html
24
25     ***************************************************************************
26      *                                                                       *
27      *    FreeRTOS provides completely free yet professionally developed,    *
28      *    robust, strictly quality controlled, supported, and cross          *
29      *    platform software that is more than just the market leader, it     *
30      *    is the industry's de facto standard.                               *
31      *                                                                       *
32      *    Help yourself get started quickly while simultaneously helping     *
33      *    to support the FreeRTOS project by purchasing a FreeRTOS           *
34      *    tutorial book, reference manual, or both:                          *
35      *    http://www.FreeRTOS.org/Documentation                              *
36      *                                                                       *
37     ***************************************************************************
38
39     http://www.FreeRTOS.org/FAQHelp.html - Having a problem?  Start by reading
40     the FAQ page "My application does not run, what could be wrong?".  Have you
41     defined configASSERT()?
42
43     http://www.FreeRTOS.org/support - In return for receiving this top quality
44     embedded software for free we request you assist our global community by
45     participating in the support forum.
46
47     http://www.FreeRTOS.org/training - Investing in training allows your team to
48     be as productive as possible as early as possible.  Now you can receive
49     FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
50     Ltd, and the world's leading authority on the world's leading RTOS.
51
52     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
53     including FreeRTOS+Trace - an indispensable productivity tool, a DOS
54     compatible FAT file system, and our tiny thread aware UDP/IP stack.
55
56     http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
57     Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
58
59     http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
60     Integrity Systems ltd. to sell under the OpenRTOS brand.  Low cost OpenRTOS
61     licenses offer ticketed support, indemnification and commercial middleware.
62
63     http://www.SafeRTOS.com - High Integrity Systems also provide a safety
64     engineered and independently SIL3 certified version for use in safety and
65     mission critical applications that require provable dependability.
66
67     1 tab == 4 spaces!
68 */
69
70 /*
71  * This is a very simply blinky style example that can be generated
72  * automatically by the Xilinx SDK.
73  *
74  * The example generates a Tx task, an Rx task, and a queue.  The Tx task
75  * simply uses the queue to send a value to the Rx task every 500ms.  The Rx
76  * prints out a message each time it receives the value.
77  *
78  * The demo does little in the way of hardware configuration.  Separate projects
79  * are provided that include comprehensive demos which demonstrate additional
80  * hardware configuration, and additional FreeRTOS features.  See the following
81  * link for more details: http://www.freertos.org/a00090.html#XILINX
82  */
83
84 /* FreeRTOS includes. */
85 #include "FreeRTOS.h"
86 #include "task.h"
87 #include "queue.h"
88
89 /* Xilinx includes. */
90 #include "xil_printf.h"
91 #include "xparameters.h"
92
93 /*-----------------------------------------------------------*/
94
95 /* The Tx and Rx tasks as described at the top of this file. */
96 static void prvTxTask( void *pvParameters );
97 static void prvRxTask( void *pvParameters );
98
99 /*-----------------------------------------------------------*/
100
101 /* The queue used by the Tx and Rx tasks, as described at the top of this
102 file. */
103 static QueueHandle_t xQueue = NULL;
104
105 int main( void )
106 {
107         xil_printf( "Hello from Freertos\r\n" );
108
109         /* Create the two tasks.  The Tx task is given a lower priority than the
110         Rx task, so the Rx task will leave the Blocked state and pre-empt the Tx
111         task as soon as the Tx task places an item in the queue. */
112         xTaskCreate(    prvTxTask,                                      /* The function that implements the task. */
113                                         ( const char * ) "Tx",          /* Text name for the task, provided to assist debugging only. */
114                                         configMINIMAL_STACK_SIZE,       /* The stack allocated to the task. */
115                                         NULL,                                           /* The task parameter is not used, so set to NULL. */
116                                         tskIDLE_PRIORITY,                       /* The task runs at the idle priority. */
117                                         NULL );
118
119         xTaskCreate( prvRxTask, ( const char * ) "GB",  configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1, NULL );
120
121         /* Create the queue used by the tasks.  The Rx task has a higher priority
122         than the Tx task, so will preempt the Tx task and remove values from the
123         queue as soon as the Tx task writes to the queue - therefore the queue can
124         never have more than one item in it. */
125         xQueue = xQueueCreate(  1,                                              /* There is only one space in the queue. */
126                                                         sizeof( uint32_t ) );   /* Each space in the queue is large enough to hold a uint32_t. */
127
128         /* Check the queue was created. */
129         configASSERT( xQueue );
130
131         /* Start the tasks and timer running. */
132         vTaskStartScheduler();
133
134         /* If all is well, the scheduler will now be running, and the following line
135         will never be reached.  If the following line does execute, then there was
136         insufficient FreeRTOS heap memory available for the idle and/or timer tasks
137         to be created.  See the memory management section on the FreeRTOS web site
138         for more details. */
139         for( ;; );
140 }
141
142
143 /*-----------------------------------------------------------*/
144 static void prvTxTask( void *pvParameters )
145 {
146 const TickType_t x500ms = pdMS_TO_TICKS( 500UL );
147 uint32_t ulValueToSend = 0;
148
149         for( ;; )
150         {
151                 /* Delay for 500ms. */
152                 vTaskDelay( x500ms );
153
154                 /* Send the next value on the queue.  The queue should always be
155                 empty at this point so a block time of 0 is used. */
156                 xQueueSend( xQueue,                     /* The queue being written to. */
157                                         &ulValueToSend, /* The address of the data being sent. */
158                                         0UL );                  /* The block time. */
159         }
160 }
161
162 /*-----------------------------------------------------------*/
163 static void prvRxTask( void *pvParameters )
164 {
165 uint32_t ulValueReceived;
166
167         for( ;; )
168         {
169                 /* Block to wait for data arriving on the queue. */
170                 xQueueReceive(  xQueue,                         /* The queue being read. */
171                                                 &ulValueReceived,       /* Data is read into this address. */
172                                                 portMAX_DELAY );        /* Wait without a timeout for data. */
173
174                 /* Print the received data. */
175                 xil_printf( "Rx task received %u\r\n", ( unsigned int ) ulValueReceived );
176         }
177 }
178
179