]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_A9_Zynq_ZC702/RTOSDemo/src/main.c
Finish the Zynq demo.
[freertos] / FreeRTOS / Demo / CORTEX_A9_Zynq_ZC702 / RTOSDemo / src / main.c
1 /*
2     FreeRTOS V8.0.0:rc2 - Copyright (C) 2014 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     ***************************************************************************
8      *                                                                       *
9      *    FreeRTOS provides completely free yet professionally developed,    *
10      *    robust, strictly quality controlled, supported, and cross          *
11      *    platform software that has become a de facto standard.             *
12      *                                                                       *
13      *    Help yourself get started quickly and support the FreeRTOS         *
14      *    project by purchasing a FreeRTOS tutorial book, reference          *
15      *    manual, or both from: http://www.FreeRTOS.org/Documentation        *
16      *                                                                       *
17      *    Thank you!                                                         *
18      *                                                                       *
19     ***************************************************************************
20
21     This file is part of the FreeRTOS distribution.
22
23     FreeRTOS is free software; you can redistribute it and/or modify it under
24     the terms of the GNU General Public License (version 2) as published by the
25     Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
26
27     >>! NOTE: The modification to the GPL is included to allow you to distribute
28     >>! a combined work that includes FreeRTOS without being obliged to provide
29     >>! the source code for proprietary components outside of the FreeRTOS
30     >>! kernel.
31
32     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
33     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
34     FOR A PARTICULAR PURPOSE.  Full license text is available from the following
35     link: http://www.freertos.org/a00114.html
36
37     1 tab == 4 spaces!
38
39     ***************************************************************************
40      *                                                                       *
41      *    Having a problem?  Start by reading the FAQ "My application does   *
42      *    not run, what could be wrong?"                                     *
43      *                                                                       *
44      *    http://www.FreeRTOS.org/FAQHelp.html                               *
45      *                                                                       *
46     ***************************************************************************
47
48     http://www.FreeRTOS.org - Documentation, books, training, latest versions,
49     license and Real Time Engineers Ltd. contact details.
50
51     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
52     including FreeRTOS+Trace - an indispensable productivity tool, a DOS
53     compatible FAT file system, and our tiny thread aware UDP/IP stack.
54
55     http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
56     Integrity Systems to sell under the OpenRTOS brand.  Low cost OpenRTOS
57     licenses offer ticketed support, indemnification and middleware.
58
59     http://www.SafeRTOS.com - High Integrity Systems also provide a safety
60     engineered and independently SIL3 certified version for use in safety and
61     mission critical applications that require provable dependability.
62
63     1 tab == 4 spaces!
64 */
65
66 /******************************************************************************
67  * This project provides two demo applications.  A simple blinky style project,
68  * and a more comprehensive test and demo application.  The
69  * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting (defined in this file) is used to
70  * select between the two.  The simply blinky demo is implemented and described
71  * in main_blinky.c.  The more comprehensive test and demo application is
72  * implemented and described in main_full.c.
73  *
74  * This file implements the code that is not demo specific, including the
75  * hardware setup and FreeRTOS hook functions.
76  *
77  * NOTE:  The full demo includes a test that checks the floating point context
78  * is maintained correctly across task switches.  The standard GCC libraries can
79  * use floating point registers and made this test fail (unless the tasks that
80  * use the library are given a floating point context as described on the
81  * documentation page for this demo).  printf-stdarg.c is included in this
82  * project to prevent the standard GCC libraries being linked into the project.
83  *
84  * ENSURE TO READ THE DOCUMENTATION PAGE FOR THIS PORT AND DEMO APPLICATION ON
85  * THE http://www.FreeRTOS.org WEB SITE FOR FULL INFORMATION ON USING THIS DEMO
86  * APPLICATION, AND ITS ASSOCIATE FreeRTOS ARCHITECTURE PORT!
87  *
88  */
89
90 /* Standard includes. */
91 #include <stdio.h>
92
93 /* Scheduler include files. */
94 #include "FreeRTOS.h"
95 #include "task.h"
96 #include "semphr.h"
97
98 /* Standard demo includes. */
99 #include "partest.h"
100 #include "TimerDemo.h"
101 #include "QueueOverwrite.h"
102
103 /* Xilinx includes. */
104 #include "platform.h"
105 #include "xparameters.h"
106 #include "xscutimer.h"
107 #include "xscugic.h"
108 #include "xil_exception.h"
109
110 /* Set mainCREATE_SIMPLE_BLINKY_DEMO_ONLY to one to run the simple blinky demo,
111 or 0 to run the more comprehensive test and demo application. */
112 #define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY      0
113
114 /*-----------------------------------------------------------*/
115
116 /*
117  * Configure the hardware as necessary to run this demo.
118  */
119 static void prvSetupHardware( void );
120
121 /*
122  * main_blinky() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1.
123  * main_full() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 0.
124  */
125 #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1
126         extern void main_blinky( void );
127 #else
128         extern void main_full( void );
129 #endif /* #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 */
130
131 /* Prototypes for the standard FreeRTOS callback/hook functions implemented
132 within this file. */
133 void vApplicationMallocFailedHook( void );
134 void vApplicationIdleHook( void );
135 void vApplicationStackOverflowHook( xTaskHandle pxTask, char *pcTaskName );
136 void vApplicationTickHook( void );
137
138 /*-----------------------------------------------------------*/
139
140 /* The interrupt controller is initialised in this file, and made available to
141 other modules. */
142 XScuGic xInterruptController;
143
144 /*-----------------------------------------------------------*/
145
146 int main( void )
147 {
148         /* Configure the hardware ready to run the demo. */
149         prvSetupHardware();
150
151         /* The mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is described at the top
152         of this file. */
153         #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1
154         {
155                 main_blinky();
156         }
157         #else
158         {
159                 main_full();
160         }
161         #endif
162
163         /* Don't expect to reach here. */
164         return 0;
165 }
166 /*-----------------------------------------------------------*/
167
168 static void prvSetupHardware( void )
169 {
170 BaseType_t xStatus;
171 XScuGic_Config *pxGICConfig;
172
173         /* Ensure no interrupts execute while the scheduler is in an inconsistent
174         state.  Interrupts are automatically enabled when the scheduler is
175         started. */
176         portDISABLE_INTERRUPTS();
177
178         /* Obtain the configuration of the GIC. */
179         pxGICConfig = XScuGic_LookupConfig( XPAR_SCUGIC_SINGLE_DEVICE_ID );
180
181         /* Sanity check the FreeRTOSConfig.h settings are correct for the
182         hardware. */
183         configASSERT( pxGICConfig );
184         configASSERT( pxGICConfig->CpuBaseAddress == ( configINTERRUPT_CONTROLLER_BASE_ADDRESS + configINTERRUPT_CONTROLLER_CPU_INTERFACE_OFFSET ) );
185         configASSERT( pxGICConfig->DistBaseAddress == configINTERRUPT_CONTROLLER_BASE_ADDRESS );
186
187         /* Install a default handler for each GIC interrupt. */
188         xStatus = XScuGic_CfgInitialize( &xInterruptController, pxGICConfig, pxGICConfig->CpuBaseAddress );
189         configASSERT( xStatus == XST_SUCCESS );
190
191         /* Initialise the LED port. */
192         vParTestInitialise();
193 }
194 /*-----------------------------------------------------------*/
195
196 void vApplicationMallocFailedHook( void )
197 {
198         /* Called if a call to pvPortMalloc() fails because there is insufficient
199         free memory available in the FreeRTOS heap.  pvPortMalloc() is called
200         internally by FreeRTOS API functions that create tasks, queues, software
201         timers, and semaphores.  The size of the FreeRTOS heap is set by the
202         configTOTAL_HEAP_SIZE configuration constant in FreeRTOSConfig.h. */
203         taskDISABLE_INTERRUPTS();
204         for( ;; );
205 }
206 /*-----------------------------------------------------------*/
207
208 void vApplicationStackOverflowHook( xTaskHandle pxTask, char *pcTaskName )
209 {
210         ( void ) pcTaskName;
211         ( void ) pxTask;
212
213         /* Run time stack overflow checking is performed if
214         configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2.  This hook
215         function is called if a stack overflow is detected. */
216         taskDISABLE_INTERRUPTS();
217         for( ;; );
218 }
219 /*-----------------------------------------------------------*/
220
221 void vApplicationIdleHook( void )
222 {
223 volatile size_t xFreeHeapSpace;
224
225         /* This is just a trivial example of an idle hook.  It is called on each
226         cycle of the idle task.  It must *NOT* attempt to block.  In this case the
227         idle task just queries the amount of FreeRTOS heap that remains.  See the
228         memory management section on the http://www.FreeRTOS.org web site for memory
229         management options.  If there is a lot of heap memory free then the
230         configTOTAL_HEAP_SIZE value in FreeRTOSConfig.h can be reduced to free up
231         RAM. */
232         xFreeHeapSpace = xPortGetFreeHeapSize();
233
234         /* Remove compiler warning about xFreeHeapSpace being set but never used. */
235         ( void ) xFreeHeapSpace;
236 }
237 /*-----------------------------------------------------------*/
238
239 void vAssertCalled( const char * pcFile, unsigned long ulLine )
240 {
241 volatile unsigned long ul = 0;
242
243         ( void ) pcFile;
244         ( void ) ulLine;
245
246         taskENTER_CRITICAL();
247         {
248                 /* Set ul to a non-zero value using the debugger to step out of this
249                 function. */
250                 while( ul == 0 )
251                 {
252                         portNOP();
253                 }
254         }
255         taskEXIT_CRITICAL();
256 }
257 /*-----------------------------------------------------------*/
258
259 void vApplicationTickHook( void )
260 {
261         #if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 0 )
262         {
263                 /* The full demo includes a software timer demo/test that requires
264                 prodding periodically from the tick interrupt. */
265                 vTimerPeriodicISRTests();
266
267                 /* Call the periodic queue overwrite from ISR demo. */
268                 vQueueOverwritePeriodicISRDemo();
269         }
270         #endif
271 }