]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_A9_Zynq_ZC702/RTOSDemo/src/main.c
02873160de913d578db84958f77e5cbed47db59c
[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      1
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 /*
132  * The Xilinx projects use a BSP that do not allow the start up code to be
133  * altered easily.  Therefore the vector table used by FreeRTOS is defined in
134  * FreeRTOS_asm_vectors.S, which is part of this project.  Switch to use the
135  * FreeRTOS vector table.
136  */
137 extern void vPortInstallFreeRTOSVectorTable( void );
138
139 /* Prototypes for the standard FreeRTOS callback/hook functions implemented
140 within this file. */
141 void vApplicationMallocFailedHook( void );
142 void vApplicationIdleHook( void );
143 void vApplicationStackOverflowHook( xTaskHandle pxTask, char *pcTaskName );
144 void vApplicationTickHook( void );
145
146 /*-----------------------------------------------------------*/
147
148 /* The interrupt controller is initialised in this file, and made available to
149 other modules. */
150 XScuGic xInterruptController;
151
152 /*-----------------------------------------------------------*/
153
154 int main( void )
155 {
156         /* Configure the hardware ready to run the demo. */
157         prvSetupHardware();
158
159         /* The mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is described at the top
160         of this file. */
161         #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1
162         {
163                 main_blinky();
164         }
165         #else
166         {
167                 main_full();
168         }
169         #endif
170
171         /* Don't expect to reach here. */
172         return 0;
173 }
174 /*-----------------------------------------------------------*/
175
176 static void prvSetupHardware( void )
177 {
178 BaseType_t xStatus;
179 XScuGic_Config *pxGICConfig;
180
181         /* Ensure no interrupts execute while the scheduler is in an inconsistent
182         state.  Interrupts are automatically enabled when the scheduler is
183         started. */
184         portDISABLE_INTERRUPTS();
185
186         /* Obtain the configuration of the GIC. */
187         pxGICConfig = XScuGic_LookupConfig( XPAR_SCUGIC_SINGLE_DEVICE_ID );
188
189         /* Sanity check the FreeRTOSConfig.h settings are correct for the
190         hardware. */
191         configASSERT( pxGICConfig );
192         configASSERT( pxGICConfig->CpuBaseAddress == ( configINTERRUPT_CONTROLLER_BASE_ADDRESS + configINTERRUPT_CONTROLLER_CPU_INTERFACE_OFFSET ) );
193         configASSERT( pxGICConfig->DistBaseAddress == configINTERRUPT_CONTROLLER_BASE_ADDRESS );
194
195         /* Install a default handler for each GIC interrupt. */
196         xStatus = XScuGic_CfgInitialize( &xInterruptController, pxGICConfig, pxGICConfig->CpuBaseAddress );
197         configASSERT( xStatus == XST_SUCCESS );
198         ( void ) xStatus; /* Remove compiler warning if configASSERT() is not defined. */
199
200         /* Initialise the LED port. */
201         vParTestInitialise();
202
203         /* The Xilinx projects use a BSP that do not allow the start up code to be
204         altered easily.  Therefore the vector table used by FreeRTOS is defined in
205         FreeRTOS_asm_vectors.S, which is part of this project.  Switch to use the
206         FreeRTOS vector table. */
207         vPortInstallFreeRTOSVectorTable();
208 }
209 /*-----------------------------------------------------------*/
210
211 void vApplicationMallocFailedHook( void )
212 {
213         /* Called if a call to pvPortMalloc() fails because there is insufficient
214         free memory available in the FreeRTOS heap.  pvPortMalloc() is called
215         internally by FreeRTOS API functions that create tasks, queues, software
216         timers, and semaphores.  The size of the FreeRTOS heap is set by the
217         configTOTAL_HEAP_SIZE configuration constant in FreeRTOSConfig.h. */
218         taskDISABLE_INTERRUPTS();
219         for( ;; );
220 }
221 /*-----------------------------------------------------------*/
222
223 void vApplicationStackOverflowHook( xTaskHandle pxTask, char *pcTaskName )
224 {
225         ( void ) pcTaskName;
226         ( void ) pxTask;
227
228         /* Run time stack overflow checking is performed if
229         configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2.  This hook
230         function is called if a stack overflow is detected. */
231         taskDISABLE_INTERRUPTS();
232         for( ;; );
233 }
234 /*-----------------------------------------------------------*/
235
236 void vApplicationIdleHook( void )
237 {
238 volatile size_t xFreeHeapSpace;
239
240         /* This is just a trivial example of an idle hook.  It is called on each
241         cycle of the idle task.  It must *NOT* attempt to block.  In this case the
242         idle task just queries the amount of FreeRTOS heap that remains.  See the
243         memory management section on the http://www.FreeRTOS.org web site for memory
244         management options.  If there is a lot of heap memory free then the
245         configTOTAL_HEAP_SIZE value in FreeRTOSConfig.h can be reduced to free up
246         RAM. */
247         xFreeHeapSpace = xPortGetFreeHeapSize();
248
249         /* Remove compiler warning about xFreeHeapSpace being set but never used. */
250         ( void ) xFreeHeapSpace;
251 }
252 /*-----------------------------------------------------------*/
253
254 void vAssertCalled( const char * pcFile, unsigned long ulLine )
255 {
256 volatile unsigned long ul = 0;
257
258         ( void ) pcFile;
259         ( void ) ulLine;
260
261         taskENTER_CRITICAL();
262         {
263                 /* Set ul to a non-zero value using the debugger to step out of this
264                 function. */
265                 while( ul == 0 )
266                 {
267                         portNOP();
268                 }
269         }
270         taskEXIT_CRITICAL();
271 }
272 /*-----------------------------------------------------------*/
273
274 void vApplicationTickHook( void )
275 {
276         #if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 0 )
277         {
278                 /* The full demo includes a software timer demo/test that requires
279                 prodding periodically from the tick interrupt. */
280                 vTimerPeriodicISRTests();
281
282                 /* Call the periodic queue overwrite from ISR demo. */
283                 vQueueOverwritePeriodicISRDemo();
284         }
285         #endif
286 }