2 FreeRTOS V8.2.0 - Copyright (C) 2015 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 This file is part of the FreeRTOS distribution.
\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
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
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
25 ***************************************************************************
\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
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
37 ***************************************************************************
\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
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
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
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
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
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
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
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
78 * This file implements the code that is not demo specific, including the
\r
79 * hardware setup and FreeRTOS hook functions.
\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
87 /* Standard includes. */
\r
91 /* Scheduler include files. */
\r
92 #include "FreeRTOS.h"
\r
95 /* Demo app includes. */
\r
96 #include "partest.h"
\r
98 /* Xilinx includes. */
\r
99 #include "xtmrctr.h"
\r
100 #include "xil_cache.h"
\r
102 /* mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is used to select between the simply
\r
103 * blinky demo and the comprehensive test and demo application.
\r
105 * When mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1 the simple blinky example
\r
108 * When mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 0 the comprehensive test
\r
109 * and demo application will be run.
\r
111 #define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY 0
\r
113 /*-----------------------------------------------------------*/
\r
116 * Configure the hardware as necessary to run this demo.
\r
118 static void prvSetupHardware( void );
\r
121 * See the comments at the top of this file and above the
\r
122 * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY definition.
\r
124 #if ( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 )
\r
125 extern void main_blinky( void );
\r
127 extern void main_full( void );
\r
130 /* Prototypes for the standard FreeRTOS callback/hook functions implemented
\r
131 within this file. */
\r
132 void vApplicationMallocFailedHook( void );
\r
133 void vApplicationIdleHook( void );
\r
134 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );
\r
135 void vApplicationTickHook( void );
\r
137 /* The dual timer is used to generate the RTOS tick interrupt and as a time base
\r
138 for the run time stats. */
\r
139 static XTmrCtr xTickTimerInstance;
\r
141 /*-----------------------------------------------------------*/
\r
145 /* Configure the hardware ready to run the demo. */
\r
146 prvSetupHardware();
\r
148 /* The mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is described at the top
\r
150 #if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 )
\r
160 /* Don't expect to reach here. */
\r
163 /*-----------------------------------------------------------*/
\r
165 static void prvSetupHardware( void )
\r
167 microblaze_disable_interrupts();
\r
169 #if defined( XPAR_MICROBLAZE_USE_ICACHE ) && ( XPAR_MICROBLAZE_USE_ICACHE != 0 )
\r
171 Xil_ICacheInvalidate();
\r
172 Xil_ICacheEnable();
\r
176 #if defined( XPAR_MICROBLAZE_USE_DCACHE ) && ( XPAR_MICROBLAZE_USE_DCACHE != 0 )
\r
178 Xil_DCacheInvalidate();
\r
179 Xil_DCacheEnable();
\r
183 /* Initialise the LEDs. ParTest is a historic name which used to stand for
\r
184 PARallel port TEST. */
\r
185 vParTestInitialise();
\r
187 /*-----------------------------------------------------------*/
\r
189 void vApplicationMallocFailedHook( void )
\r
191 volatile uint32_t ulDummy = 0;
\r
193 /* Called if a call to pvPortMalloc() fails because there is insufficient
\r
194 free memory available in the FreeRTOS heap. pvPortMalloc() is called
\r
195 internally by FreeRTOS API functions that create tasks, queues, software
\r
196 timers, and semaphores. The size of the FreeRTOS heap is set by the
\r
197 configTOTAL_HEAP_SIZE configuration constant in FreeRTOSConfig.h. Force an
\r
198 assertion failure. */
\r
199 configASSERT( ulDummy != 0 );
\r
201 /*-----------------------------------------------------------*/
\r
203 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
\r
205 ( void ) pcTaskName;
\r
208 /* Run time stack overflow checking is performed if
\r
209 configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook
\r
210 function is called if a stack overflow is detected. Force an assertion
\r
212 configASSERT( ( char * ) pxTask == pcTaskName );
\r
214 /*-----------------------------------------------------------*/
\r
216 void vApplicationIdleHook( void )
\r
218 #if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 0 )
\r
220 extern void vFullDemoIdleHook( void );
\r
222 /* When the full demo is build the idle hook is used to create some
\r
223 timers to flash LEDs. */
\r
224 vFullDemoIdleHook();
\r
228 /*-----------------------------------------------------------*/
\r
230 void vAssertCalled( const char * pcFile, unsigned long ulLine )
\r
232 volatile unsigned long ul = 0;
\r
237 taskENTER_CRITICAL();
\r
239 /* Set ul to a non-zero value using the debugger to step out of this
\r
246 taskEXIT_CRITICAL();
\r
248 /*-----------------------------------------------------------*/
\r
250 void vApplicationTickHook( void )
\r
252 #if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 0 )
\r
254 extern void vFullDemoTickHook( void );
\r
256 /* When the full demo is build the tick hook is used to demonstrate
\r
257 functions being called from an interrupt and perform some tests. */
\r
258 vFullDemoTickHook();
\r
262 /*-----------------------------------------------------------*/
\r
264 /* This is an application defined callback function used to install the tick
\r
265 interrupt handler. It is provided as an application callback because the kernel
\r
266 will run on lots of different MicroBlaze and FPGA configurations - not all of
\r
267 which will have the same timer peripherals defined or available. This example
\r
268 uses the Dual Timer 0. If that is available on your hardware platform then this
\r
269 example callback implementation may not require modification. The name of the
\r
270 interrupt handler that must be installed is vPortTickISR(), which the function
\r
271 below declares as an extern. */
\r
272 void vApplicationSetupTimerInterrupt( void )
\r
274 portBASE_TYPE xStatus;
\r
275 const unsigned char ucTickTimerCounterNumber = ( unsigned char ) 0U;
\r
276 const unsigned char ucRunTimeStatsCounterNumber = ( unsigned char ) 1U;
\r
277 const unsigned long ulCounterValue = ( ( XPAR_TMRCTR_0_CLOCK_FREQ_HZ / configTICK_RATE_HZ ) - 1UL );
\r
278 extern void vPortTickISR( void *pvUnused );
\r
280 /* Initialise the timer/counter. */
\r
281 xStatus = XTmrCtr_Initialize( &xTickTimerInstance, XPAR_TMRCTR_0_DEVICE_ID );
\r
283 if( xStatus == XST_SUCCESS )
\r
285 /* Install the tick interrupt handler as the timer ISR.
\r
286 *NOTE* The xPortInstallInterruptHandler() API function must be used for
\r
288 xStatus = xPortInstallInterruptHandler( XPAR_INTC_0_TMRCTR_0_VEC_ID, vPortTickISR, NULL );
\r
291 if( xStatus == pdPASS )
\r
293 /* Enable the timer interrupt in the interrupt controller.
\r
294 *NOTE* The vPortEnableInterrupt() API function must be used for this
\r
296 vPortEnableInterrupt( XPAR_INTC_0_TMRCTR_0_VEC_ID );
\r
298 /* Configure the timer interrupt handler. */
\r
299 XTmrCtr_SetHandler( &xTickTimerInstance, ( void * ) vPortTickISR, NULL );
\r
301 /* Set the correct period for the timer. */
\r
302 XTmrCtr_SetResetValue( &xTickTimerInstance, ucTickTimerCounterNumber, ulCounterValue );
\r
304 /* Enable the interrupts. Auto-reload mode is used to generate a
\r
305 periodic tick. Note that interrupts are disabled when this function is
\r
306 called, so interrupts will not start to be processed until the first
\r
307 task has started to run. */
\r
308 XTmrCtr_SetOptions( &xTickTimerInstance, ucTickTimerCounterNumber, ( XTC_INT_MODE_OPTION | XTC_AUTO_RELOAD_OPTION | XTC_DOWN_COUNT_OPTION ) );
\r
310 /* Start the timer. */
\r
311 XTmrCtr_Start( &xTickTimerInstance, ucTickTimerCounterNumber );
\r
316 /* The second timer is used as the time base for the run time stats.
\r
317 Auto-reload mode is used to ensure the timer does not stop. */
\r
318 XTmrCtr_SetOptions( &xTickTimerInstance, ucRunTimeStatsCounterNumber, XTC_AUTO_RELOAD_OPTION );
\r
320 /* Start the timer. */
\r
321 XTmrCtr_Start( &xTickTimerInstance, ucRunTimeStatsCounterNumber );
\r
324 /* Sanity check that the function executed as expected. */
\r
325 configASSERT( ( xStatus == pdPASS ) );
\r
327 /*-----------------------------------------------------------*/
\r
329 /* This is an application defined callback function used to clear whichever
\r
330 interrupt was installed by the the vApplicationSetupTimerInterrupt() callback
\r
331 function. It is provided as an application callback because the kernel will run
\r
332 on lots of different MicroBlaze and FPGA configurations - not all of which will
\r
333 have the same timer peripherals defined or available. This example uses the
\r
334 dual timer 0. If that is available on your hardware platform then this example
\r
335 callback implementation will not require modification provided the example
\r
336 definition of vApplicationSetupTimerInterrupt() is also not modified. */
\r
337 void vApplicationClearTimerInterrupt( void )
\r
339 unsigned long ulCSR;
\r
341 /* Clear the timer interrupt */
\r
342 ulCSR = XTmrCtr_GetControlStatusReg( XPAR_TMRCTR_0_BASEADDR, 0 );
\r
343 XTmrCtr_SetControlStatusReg( XPAR_TMRCTR_0_BASEADDR, 0, ulCSR );
\r
345 /*-----------------------------------------------------------*/
\r
347 void *malloc( size_t x )
\r
349 /* Just to check it never gets called as there is no heap defined (other
\r
350 than the FreeRTOS heap). */
\r
353 /*-----------------------------------------------------------*/
\r
355 uint32_t ulMainGetRunTimeCounterValue( void )
\r
357 static uint32_t ulOverflows = 0, ulLastTime = 0;
\r
358 uint32_t ulTimeNow, ulReturn;
\r
359 const uint32_t ulPrescale = 10, ulTCR2Offset = 24UL;
\r
361 ulTimeNow = * ( ( uint32_t * ) ( XPAR_TMRCTR_0_BASEADDR + ulTCR2Offset ) );
\r
363 if( ulTimeNow < ulLastTime )
\r
365 ulOverflows += ( 1UL << ulPrescale );
\r
368 ulReturn = ( ulTimeNow >> ulPrescale ) + ulOverflows;
\r