]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/MicroBlaze_Kintex7_EthernetLite/RTOSDemo/src/main.c
Add the beginnings of a Microblaze project for the KC705.
[freertos] / FreeRTOS / Demo / MicroBlaze_Kintex7_EthernetLite / RTOSDemo / src / main.c
1 /*\r
2     FreeRTOS V8.2.0 - Copyright (C) 2015 Real Time Engineers Ltd.\r
3     All rights reserved\r
4 \r
5     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
6 \r
7     This file is part of the FreeRTOS distribution.\r
8 \r
9     FreeRTOS is free software; you can redistribute it and/or modify it under\r
10     the terms of the GNU General Public License (version 2) as published by the\r
11     Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.\r
12 \r
13         ***************************************************************************\r
14     >>!   NOTE: The modification to the GPL is included to allow you to     !<<\r
15     >>!   distribute a combined work that includes FreeRTOS without being   !<<\r
16     >>!   obliged to provide the source code for proprietary components     !<<\r
17     >>!   outside of the FreeRTOS kernel.                                   !<<\r
18         ***************************************************************************\r
19 \r
20     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
21     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
22     FOR A PARTICULAR PURPOSE.  Full license text is available on the following\r
23     link: http://www.freertos.org/a00114.html\r
24 \r
25     ***************************************************************************\r
26      *                                                                       *\r
27      *    FreeRTOS provides completely free yet professionally developed,    *\r
28      *    robust, strictly quality controlled, supported, and cross          *\r
29      *    platform software that is more than just the market leader, it     *\r
30      *    is the industry's de facto standard.                               *\r
31      *                                                                       *\r
32      *    Help yourself get started quickly while simultaneously helping     *\r
33      *    to support the FreeRTOS project by purchasing a FreeRTOS           *\r
34      *    tutorial book, reference manual, or both:                          *\r
35      *    http://www.FreeRTOS.org/Documentation                              *\r
36      *                                                                       *\r
37     ***************************************************************************\r
38 \r
39     http://www.FreeRTOS.org/FAQHelp.html - Having a problem?  Start by reading\r
40         the FAQ page "My application does not run, what could be wrong?".  Have you\r
41         defined configASSERT()?\r
42 \r
43         http://www.FreeRTOS.org/support - In return for receiving this top quality\r
44         embedded software for free we request you assist our global community by\r
45         participating in the support forum.\r
46 \r
47         http://www.FreeRTOS.org/training - Investing in training allows your team to\r
48         be as productive as possible as early as possible.  Now you can receive\r
49         FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers\r
50         Ltd, and the world's leading authority on the world's leading RTOS.\r
51 \r
52     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
53     including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
54     compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
55 \r
56     http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.\r
57     Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.\r
58 \r
59     http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High\r
60     Integrity Systems ltd. to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
61     licenses offer ticketed support, indemnification and commercial middleware.\r
62 \r
63     http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
64     engineered and independently SIL3 certified version for use in safety and\r
65     mission critical applications that require provable dependability.\r
66 \r
67     1 tab == 4 spaces!\r
68 */\r
69 \r
70 /******************************************************************************\r
71  * This project provides two demo applications.  A simple blinky style project,\r
72  * and a more comprehensive test and demo application.  The\r
73  * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting (defined in this file) is used to\r
74  * select between the two.  The simply blinky demo is implemented and described\r
75  * in main_blinky.c.  The more comprehensive test and demo application is\r
76  * implemented and described in main_full.c.\r
77  *\r
78  * This file implements the code that is not demo specific, including the\r
79  * hardware setup and FreeRTOS hook functions.\r
80  *\r
81  * ENSURE TO READ THE DOCUMENTATION PAGE FOR THIS PORT AND DEMO APPLICATION ON\r
82  * THE http://www.FreeRTOS.org WEB SITE FOR FULL INFORMATION ON USING THIS DEMO\r
83  * APPLICATION, AND ITS ASSOCIATE FreeRTOS ARCHITECTURE PORT!\r
84  *\r
85  */\r
86 \r
87 #warning Try reducing minimal stack size.\r
88 \r
89 /* Standard includes. */\r
90 #include <stdio.h>\r
91 #include <limits.h>\r
92 \r
93 /* Scheduler include files. */\r
94 #include "FreeRTOS.h"\r
95 #include "task.h"\r
96 \r
97 /* Demo app includes. */\r
98 #include "partest.h"\r
99 \r
100 /* Xilinx includes. */\r
101 #include "xtmrctr.h"\r
102 #include "xil_cache.h"\r
103 \r
104 /* mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is used to select between the simply\r
105  * blinky demo and the comprehensive test and demo application.\r
106  *\r
107  * When mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1 the simple blinky example\r
108  * will be run.\r
109  *\r
110  * When mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 0 the comprehensive test\r
111  * and demo application will be run.\r
112  */\r
113 #define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY      0\r
114 \r
115 /*-----------------------------------------------------------*/\r
116 \r
117 /*\r
118  * Configure the hardware as necessary to run this demo.\r
119  */\r
120 static void prvSetupHardware( void );\r
121 \r
122 /*\r
123  * See the comments at the top of this file and above the\r
124  * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY definition.\r
125  */\r
126 #if ( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 )\r
127         extern void main_blinky( void );\r
128 #else\r
129         extern void main_full( void );\r
130 #endif\r
131 \r
132 /* Prototypes for the standard FreeRTOS callback/hook functions implemented\r
133 within this file. */\r
134 void vApplicationMallocFailedHook( void );\r
135 void vApplicationIdleHook( void );\r
136 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );\r
137 void vApplicationTickHook( void );\r
138 \r
139 /* The dual timer is used to generate the RTOS tick interrupt. */\r
140 static XTmrCtr xDualTimerInstance;\r
141 \r
142 /*-----------------------------------------------------------*/\r
143 \r
144 int main( void )\r
145 {\r
146         /* Configure the hardware ready to run the demo. */\r
147         prvSetupHardware();\r
148 \r
149         /* The mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is described at the top\r
150         of this file. */\r
151         #if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 )\r
152         {\r
153                 main_blinky();\r
154         }\r
155         #else\r
156         {\r
157                 main_full();\r
158         }\r
159         #endif\r
160 \r
161         /* Don't expect to reach here. */\r
162         return 0;\r
163 }\r
164 /*-----------------------------------------------------------*/\r
165 \r
166 static void prvSetupHardware( void )\r
167 {\r
168 #warning Stacks are in BRAM.\r
169 #warning Caches are disabled.\r
170 //      init_platform();\r
171 \r
172         microblaze_disable_interrupts();\r
173 \r
174         #if defined( XPAR_MICROBLAZE_USE_ICACHE ) && ( XPAR_MICROBLAZE_USE_ICACHE != 0 )\r
175         {\r
176                 Xil_ICacheEnable();\r
177         }\r
178         #endif\r
179 \r
180         #if defined( XPAR_MICROBLAZE_USE_DCACHE ) && ( XPAR_MICROBLAZE_USE_DCACHE != 0 )\r
181         {\r
182                 Xil_DCacheEnable();\r
183         }\r
184         #endif\r
185 \r
186         /* Initialise the LEDs.  ParTest is a historic name which used to stand for\r
187         PARallel port TEST. */\r
188         vParTestInitialise();\r
189 }\r
190 /*-----------------------------------------------------------*/\r
191 \r
192 void vApplicationMallocFailedHook( void )\r
193 {\r
194 volatile uint32_t ulDummy = 0;\r
195 \r
196         /* Called if a call to pvPortMalloc() fails because there is insufficient\r
197         free memory available in the FreeRTOS heap.  pvPortMalloc() is called\r
198         internally by FreeRTOS API functions that create tasks, queues, software\r
199         timers, and semaphores.  The size of the FreeRTOS heap is set by the\r
200         configTOTAL_HEAP_SIZE configuration constant in FreeRTOSConfig.h.  Force an\r
201         assertion failure. */\r
202         configASSERT( ulDummy != 0 );\r
203 }\r
204 /*-----------------------------------------------------------*/\r
205 \r
206 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )\r
207 {\r
208         ( void ) pcTaskName;\r
209         ( void ) pxTask;\r
210 \r
211         /* Run time stack overflow checking is performed if\r
212         configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2.  This hook\r
213         function is called if a stack overflow is detected.  Force an assertion\r
214         failuse. */\r
215         configASSERT( ( char * ) pxTask == pcTaskName );\r
216 }\r
217 /*-----------------------------------------------------------*/\r
218 \r
219 void vApplicationIdleHook( void )\r
220 {\r
221         #if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 0 )\r
222         {\r
223                 extern void vFullDemoIdleHook( void );\r
224 \r
225                 /* When the full demo is build the idle hook is used to create some\r
226                 timers to flash LEDs. */\r
227                 vFullDemoIdleHook();\r
228         }\r
229         #endif\r
230 }\r
231 /*-----------------------------------------------------------*/\r
232 \r
233 void vAssertCalled( const char * pcFile, unsigned long ulLine )\r
234 {\r
235 volatile unsigned long ul = 0;\r
236 \r
237         ( void ) pcFile;\r
238         ( void ) ulLine;\r
239 \r
240         taskENTER_CRITICAL();\r
241         {\r
242                 /* Set ul to a non-zero value using the debugger to step out of this\r
243                 function. */\r
244                 while( ul == 0 )\r
245                 {\r
246                         portNOP();\r
247                 }\r
248         }\r
249         taskEXIT_CRITICAL();\r
250 }\r
251 /*-----------------------------------------------------------*/\r
252 \r
253 void vApplicationTickHook( void )\r
254 {\r
255         #if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 0 )\r
256         {\r
257                 extern void vFullDemoTickHook( void );\r
258 \r
259                 /* When the full demo is build the tick hook is used to demonstrate\r
260                 functions being called from an interrupt and perform some tests. */\r
261                 vFullDemoTickHook();\r
262         }\r
263         #endif\r
264 }\r
265 /*-----------------------------------------------------------*/\r
266 \r
267 /* This is an application defined callback function used to install the tick\r
268 interrupt handler.  It is provided as an application callback because the kernel\r
269 will run on lots of different MicroBlaze and FPGA configurations - not all of\r
270 which will have the same timer peripherals defined or available.  This example\r
271 uses the Dual Timer 0.  If that is available on your hardware platform then this\r
272 example callback implementation may not require modification.   The name of the\r
273 interrupt handler that must be installed is vPortTickISR(), which the function\r
274 below declares as an extern. */\r
275 void vApplicationSetupTimerInterrupt( void )\r
276 {\r
277 portBASE_TYPE xStatus;\r
278 const unsigned char ucTimerCounterNumber = ( unsigned char ) 0U;\r
279 const unsigned long ulCounterValue = ( ( XPAR_TMRCTR_0_CLOCK_FREQ_HZ / configTICK_RATE_HZ ) - 1UL );\r
280 extern void vPortTickISR( void *pvUnused );\r
281 \r
282         /* Initialise the timer/counter. */\r
283         xStatus = XTmrCtr_Initialize( &xDualTimerInstance, XPAR_TMRCTR_0_DEVICE_ID );\r
284 \r
285         if( xStatus == XST_SUCCESS )\r
286         {\r
287                 /* Install the tick interrupt handler as the timer ISR.\r
288                 *NOTE* The xPortInstallInterruptHandler() API function must be used for\r
289                 this purpose. */\r
290                 xStatus = xPortInstallInterruptHandler( XPAR_INTC_0_TMRCTR_0_VEC_ID, vPortTickISR, NULL );\r
291         }\r
292 \r
293         if( xStatus == pdPASS )\r
294         {\r
295                 /* Enable the timer interrupt in the interrupt controller.\r
296                 *NOTE* The vPortEnableInterrupt() API function must be used for this\r
297                 purpose. */\r
298                 vPortEnableInterrupt( XPAR_INTC_0_TMRCTR_0_VEC_ID );\r
299 \r
300                 /* Configure the timer interrupt handler. */\r
301                 XTmrCtr_SetHandler( &xDualTimerInstance, ( void * ) vPortTickISR, NULL );\r
302 \r
303                 /* Set the correct period for the timer. */\r
304                 XTmrCtr_SetResetValue( &xDualTimerInstance, ucTimerCounterNumber, ulCounterValue );\r
305 \r
306                 /* Enable the interrupts.  Auto-reload mode is used to generate a\r
307                 periodic tick.  Note that interrupts are disabled when this function is\r
308                 called, so interrupts will not start to be processed until the first\r
309                 task has started to run. */\r
310                 XTmrCtr_SetOptions( &xDualTimerInstance, ucTimerCounterNumber, ( XTC_INT_MODE_OPTION | XTC_AUTO_RELOAD_OPTION | XTC_DOWN_COUNT_OPTION ) );\r
311 \r
312                 /* Start the timer. */\r
313                 XTmrCtr_Start( &xDualTimerInstance, ucTimerCounterNumber );\r
314         }\r
315 \r
316         /* Sanity check that the function executed as expected. */\r
317         configASSERT( ( xStatus == pdPASS ) );\r
318 }\r
319 /*-----------------------------------------------------------*/\r
320 \r
321 /* This is an application defined callback function used to clear whichever\r
322 interrupt was installed by the the vApplicationSetupTimerInterrupt() callback\r
323 function.  It is provided as an application callback because the kernel will run\r
324 on lots of different MicroBlaze and FPGA configurations - not all of which will\r
325 have the same timer peripherals defined or available.  This example uses the\r
326 dual timer 0.  If that is available on your hardware platform then this example\r
327 callback implementation will not require modification provided the example\r
328 definition of vApplicationSetupTimerInterrupt() is also not modified. */\r
329 void vApplicationClearTimerInterrupt( void )\r
330 {\r
331 unsigned long ulCSR;\r
332 \r
333         /* Clear the timer interrupt */\r
334         ulCSR = XTmrCtr_GetControlStatusReg( XPAR_TMRCTR_0_BASEADDR, 0 );\r
335         XTmrCtr_SetControlStatusReg( XPAR_TMRCTR_0_BASEADDR, 0, ulCSR );\r
336 }\r
337 /*-----------------------------------------------------------*/\r
338 \r
339 void *malloc( size_t x )\r
340 {\r
341         /* Just to check it never gets called as there is no heap defined (other\r
342         than the FreeRTOS heap). */\r
343         for( ;; );\r
344 }\r
345 /*-----------------------------------------------------------*/\r
346 \r
347 void vMainConfigTimerForRunTimeStats( void )\r
348 {\r
349 }\r
350 /*-----------------------------------------------------------*/\r
351 \r
352 uint32_t ulMainGetRunTimeCounterValue( void )\r
353 {\r
354         return 0;\r
355 }\r