]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_A9_Zynq_ZC702/RTOSDemo/src/main.c
6924f045c747083d047467d6547ddef5f5748a2f
[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  * Creates and verifies different files on the volume, demonstrating the use of
133  * various different API functions.
134  */
135 extern void vCreateAndVerifySampleFiles( void );
136
137 /*-----------------------------------------------------------*/
138
139 int main( void )
140 {
141         /* Configure the hardware ready to run the demo. */
142         prvSetupHardware();
143
144         /* The mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is described at the top
145         of this file. */
146         #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1
147         {
148                 main_blinky();
149         }
150         #else
151         {
152                 main_full();
153         }
154         #endif
155
156         return 0;
157 }
158 /*-----------------------------------------------------------*/
159
160 static void prvSetupHardware( void )
161 {
162 int Status;
163 static XScuGic InterruptController;     /* Interrupt controller instance */
164 extern void FreeRTOS_IRQ_Handler( void );
165 extern void FreeRTOS_SWI_Handler( void );
166
167         __asm volatile ( "cpsid i" );
168         Xil_ExceptionInit();
169
170         XScuGic_Config *IntcConfig; /* The configuration parameters of the
171                                                                         interrupt controller */
172         /*
173          * Initialize the interrupt controller driver
174          */
175         IntcConfig = XScuGic_LookupConfig(XPAR_SCUGIC_SINGLE_DEVICE_ID);
176         configASSERT( IntcConfig );
177         configASSERT( IntcConfig->CpuBaseAddress == ( configINTERRUPT_CONTROLLER_BASE_ADDRESS + configINTERRUPT_CONTROLLER_CPU_INTERFACE_OFFSET ) );
178         configASSERT( IntcConfig->DistBaseAddress == configINTERRUPT_CONTROLLER_BASE_ADDRESS );
179
180         Status = XScuGic_CfgInitialize(&InterruptController, IntcConfig, IntcConfig->CpuBaseAddress );
181         configASSERT( Status == XST_SUCCESS );
182
183         Xil_ExceptionRegisterHandler( XIL_EXCEPTION_ID_IRQ_INT, (Xil_ExceptionHandler)FreeRTOS_IRQ_Handler,     &InterruptController);
184         Xil_ExceptionRegisterHandler( XIL_EXCEPTION_ID_SWI_INT, (Xil_ExceptionHandler)FreeRTOS_SWI_Handler,     &InterruptController);
185
186 //      Xil_ExceptionEnableMask( XIL_EXCEPTION_ALL );
187 //      Xil_ExceptionEnable();
188
189         /*
190          * Connect the interrupt controller interrupt handler to the hardware
191          * interrupt handling logic in the ARM processor.
192          */
193 #if 0
194         Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_UNDEFINED_INT,
195                         (Xil_ExceptionHandler)FreeRTOS_ExHandler,
196                         (void *)4);
197
198         Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_PREFETCH_ABORT_INT,
199                         (Xil_ExceptionHandler)FreeRTOS_ExHandler,
200                         (void *)4);
201
202         Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_DATA_ABORT_INT,
203                         (Xil_ExceptionHandler)FreeRTOS_ExHandler,
204                         (void *)8);
205 #endif
206 }
207 /*-----------------------------------------------------------*/
208
209 void vApplicationMallocFailedHook( void )
210 {
211         /* Called if a call to pvPortMalloc() fails because there is insufficient
212         free memory available in the FreeRTOS heap.  pvPortMalloc() is called
213         internally by FreeRTOS API functions that create tasks, queues, software
214         timers, and semaphores.  The size of the FreeRTOS heap is set by the
215         configTOTAL_HEAP_SIZE configuration constant in FreeRTOSConfig.h. */
216         taskDISABLE_INTERRUPTS();
217         for( ;; );
218 }
219 /*-----------------------------------------------------------*/
220
221 void vApplicationStackOverflowHook( xTaskHandle pxTask, char *pcTaskName )
222 {
223         ( void ) pcTaskName;
224         ( void ) pxTask;
225
226         /* Run time stack overflow checking is performed if
227         configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2.  This hook
228         function is called if a stack overflow is detected. */
229         taskDISABLE_INTERRUPTS();
230         for( ;; );
231 }
232 /*-----------------------------------------------------------*/
233
234 void vApplicationIdleHook( void )
235 {
236 volatile size_t xFreeHeapSpace;
237
238         /* This is just a trivial example of an idle hook.  It is called on each
239         cycle of the idle task.  It must *NOT* attempt to block.  In this case the
240         idle task just queries the amount of FreeRTOS heap that remains.  See the
241         memory management section on the http://www.FreeRTOS.org web site for memory
242         management options.  If there is a lot of heap memory free then the
243         configTOTAL_HEAP_SIZE value in FreeRTOSConfig.h can be reduced to free up
244         RAM. */
245         xFreeHeapSpace = xPortGetFreeHeapSize();
246
247         /* Remove compiler warning about xFreeHeapSpace being set but never used. */
248         ( void ) xFreeHeapSpace;
249
250         #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY != 1
251         {
252                 /* If the file system is only going to be accessed from one task then
253                 F_FS_THREAD_AWARE can be set to 0 and the set of example files is
254                 created before the RTOS scheduler is started.  If the file system is
255                 going to be     access from more than one task then F_FS_THREAD_AWARE must
256                 be set to 1 and the set of sample files are created from the idle task
257                 hook function. */
258                 #if F_FS_THREAD_AWARE == 1
259                 {
260                         static portBASE_TYPE xCreatedSampleFiles = pdFALSE;
261
262                         /* Initialise the drive and file system, then create a few example
263                         files.  The output from this function just goes to the stdout window,
264                         allowing the output to be viewed when the UDP command console is not
265                         connected. */
266                         if( xCreatedSampleFiles == pdFALSE )
267                         {
268                                 vCreateAndVerifySampleFiles();
269                                 xCreatedSampleFiles = pdTRUE;
270                         }
271                 }
272                 #endif
273         }
274         #endif
275 }
276 /*-----------------------------------------------------------*/
277
278 void vAssertCalled( const char * pcFile, unsigned long ulLine )
279 {
280 volatile unsigned long ul = 0;
281
282         ( void ) pcFile;
283         ( void ) ulLine;
284
285         taskENTER_CRITICAL();
286         {
287                 /* Set ul to a non-zero value using the debugger to step out of this
288                 function. */
289                 while( ul == 0 )
290                 {
291                         portNOP();
292                 }
293         }
294         taskEXIT_CRITICAL();
295 }
296 /*-----------------------------------------------------------*/
297
298 void vApplicationTickHook( void )
299 {
300         #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 0
301         {
302                 /* The full demo includes a software timer demo/test that requires
303                 prodding periodically from the tick interrupt. */
304                 vTimerPeriodicISRTests();
305
306                 /* Call the periodic queue overwrite from ISR demo. */
307                 vQueueOverwritePeriodicISRDemo();
308         }
309         #endif
310 }
311 /*-----------------------------------------------------------*/
312
313 void vApplicationIRQHandler( uint32_t ulICCIAR )
314 {
315 uint32_t ulInterruptID;
316
317         /* Re-enable interrupts. */
318     __asm ( "cpsie i" );
319
320         /* The ID of the interrupt can be obtained by bitwise anding the ICCIAR value
321         with 0x3FF. */
322         ulInterruptID = ulICCIAR & 0x3FFUL;
323
324         /* Call the function installed in the array of installed handler functions. */
325 //      intc_func_table[ ulInterruptID ]( 0 );
326 }