]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_A9_Zynq_ZC702/RTOSDemo/src/main.c
Continue Zynq demo - ParTest.c now working (with single LED), but still very much...
[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  * ENSURE TO READ THE DOCUMENTATION PAGE FOR THIS PORT AND DEMO APPLICATION ON
78  * THE http://www.FreeRTOS.org WEB SITE FOR FULL INFORMATION ON USING THIS DEMO
79  * APPLICATION, AND ITS ASSOCIATE FreeRTOS ARCHITECTURE PORT!
80  *
81  */
82
83 /* Standard includes. */
84 #include <stdio.h>
85
86 /* Scheduler include files. */
87 #include "FreeRTOS.h"
88 #include "task.h"
89 #include "semphr.h"
90
91 /* Standard demo includes. */
92 #include "partest.h"
93 #include "TimerDemo.h"
94 #include "QueueOverwrite.h"
95
96 /* Xilinx includes. */
97 #include "platform.h"
98 #include "xparameters.h"
99 #include "xscutimer.h"
100 #include "xscugic.h"
101 #include "xil_exception.h"
102
103 /* Set mainCREATE_SIMPLE_BLINKY_DEMO_ONLY to one to run the simple blinky demo,
104 or 0 to run the more comprehensive test and demo application. */
105 #define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY      1
106
107 /*-----------------------------------------------------------*/
108
109 /*
110  * Configure the hardware as necessary to run this demo.
111  */
112 static void prvSetupHardware( void );
113
114 /*
115  * main_blinky() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1.
116  * main_full() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 0.
117  */
118 #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1
119         extern void main_blinky( void );
120 #else
121         extern void main_full( void );
122 #endif /* #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 */
123
124 /* Prototypes for the standard FreeRTOS callback/hook functions implemented
125 within this file. */
126 void vApplicationMallocFailedHook( void );
127 void vApplicationIdleHook( void );
128 void vApplicationStackOverflowHook( xTaskHandle pxTask, char *pcTaskName );
129 void vApplicationTickHook( void );
130
131 /*-----------------------------------------------------------*/
132
133 int main( void )
134 {
135         /* Configure the hardware ready to run the demo. */
136         prvSetupHardware();
137
138         /* The mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is described at the top
139         of this file. */
140         #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1
141         {
142                 main_blinky();
143         }
144         #else
145         {
146                 main_full();
147         }
148         #endif
149
150         return 0;
151 }
152 /*-----------------------------------------------------------*/
153
154 static void prvSetupHardware( void )
155 {
156 BaseType_t xStatus;
157 XScuGic_Config *pxGICConfig;
158 XScuGic xInterruptController;
159
160         /* Ensure no interrupts execute while the scheduler is in an inconsistent
161         state.  Interrupts are automatically enabled when the scheduler is
162         started. */
163         portDISABLE_INTERRUPTS();
164
165         /* Obtain the configuration of the GIC. */
166         pxGICConfig = XScuGic_LookupConfig( XPAR_SCUGIC_SINGLE_DEVICE_ID );
167
168         /* Sanity check the FreeRTOSConfig.h settings are correct for the
169         hardware. */
170         configASSERT( pxGICConfig );
171         configASSERT( pxGICConfig->CpuBaseAddress == ( configINTERRUPT_CONTROLLER_BASE_ADDRESS + configINTERRUPT_CONTROLLER_CPU_INTERFACE_OFFSET ) );
172         configASSERT( pxGICConfig->DistBaseAddress == configINTERRUPT_CONTROLLER_BASE_ADDRESS );
173
174         /* Install a default handler for each GIC interrupt. */
175         xStatus = XScuGic_CfgInitialize( &xInterruptController, pxGICConfig, pxGICConfig->CpuBaseAddress );
176         configASSERT( xStatus == XST_SUCCESS );
177
178         /* Initialise the LED port. */
179         vParTestInitialise();
180 }
181 /*-----------------------------------------------------------*/
182
183 void vApplicationMallocFailedHook( void )
184 {
185         /* Called if a call to pvPortMalloc() fails because there is insufficient
186         free memory available in the FreeRTOS heap.  pvPortMalloc() is called
187         internally by FreeRTOS API functions that create tasks, queues, software
188         timers, and semaphores.  The size of the FreeRTOS heap is set by the
189         configTOTAL_HEAP_SIZE configuration constant in FreeRTOSConfig.h. */
190         taskDISABLE_INTERRUPTS();
191         for( ;; );
192 }
193 /*-----------------------------------------------------------*/
194
195 void vApplicationStackOverflowHook( xTaskHandle pxTask, char *pcTaskName )
196 {
197         ( void ) pcTaskName;
198         ( void ) pxTask;
199
200         /* Run time stack overflow checking is performed if
201         configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2.  This hook
202         function is called if a stack overflow is detected. */
203         taskDISABLE_INTERRUPTS();
204         for( ;; );
205 }
206 /*-----------------------------------------------------------*/
207
208 void vApplicationIdleHook( void )
209 {
210 volatile size_t xFreeHeapSpace;
211
212         /* This is just a trivial example of an idle hook.  It is called on each
213         cycle of the idle task.  It must *NOT* attempt to block.  In this case the
214         idle task just queries the amount of FreeRTOS heap that remains.  See the
215         memory management section on the http://www.FreeRTOS.org web site for memory
216         management options.  If there is a lot of heap memory free then the
217         configTOTAL_HEAP_SIZE value in FreeRTOSConfig.h can be reduced to free up
218         RAM. */
219         xFreeHeapSpace = xPortGetFreeHeapSize();
220
221         /* Remove compiler warning about xFreeHeapSpace being set but never used. */
222         ( void ) xFreeHeapSpace;
223
224         #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY != 1
225         {
226                 /* If the file system is only going to be accessed from one task then
227                 F_FS_THREAD_AWARE can be set to 0 and the set of example files is
228                 created before the RTOS scheduler is started.  If the file system is
229                 going to be     access from more than one task then F_FS_THREAD_AWARE must
230                 be set to 1 and the set of sample files are created from the idle task
231                 hook function. */
232                 #if F_FS_THREAD_AWARE == 1
233                 {
234                         static portBASE_TYPE xCreatedSampleFiles = pdFALSE;
235
236                         /* Initialise the drive and file system, then create a few example
237                         files.  The output from this function just goes to the stdout window,
238                         allowing the output to be viewed when the UDP command console is not
239                         connected. */
240                         if( xCreatedSampleFiles == pdFALSE )
241                         {
242                                 vCreateAndVerifySampleFiles();
243                                 xCreatedSampleFiles = pdTRUE;
244                         }
245                 }
246                 #endif
247         }
248         #endif
249 }
250 /*-----------------------------------------------------------*/
251
252 void vAssertCalled( const char * pcFile, unsigned long ulLine )
253 {
254 volatile unsigned long ul = 0;
255
256         ( void ) pcFile;
257         ( void ) ulLine;
258
259         taskENTER_CRITICAL();
260         {
261                 /* Set ul to a non-zero value using the debugger to step out of this
262                 function. */
263                 while( ul == 0 )
264                 {
265                         portNOP();
266                 }
267         }
268         taskEXIT_CRITICAL();
269 }
270 /*-----------------------------------------------------------*/
271
272 void vApplicationTickHook( void )
273 {
274         #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 0
275         {
276                 /* The full demo includes a software timer demo/test that requires
277                 prodding periodically from the tick interrupt. */
278                 vTimerPeriodicISRTests();
279
280                 /* Call the periodic queue overwrite from ISR demo. */
281                 vQueueOverwritePeriodicISRDemo();
282         }
283         #endif
284 }