2 * FreeRTOS Kernel V10.0.1
\r
3 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
\r
5 * Permission is hereby granted, free of charge, to any person obtaining a copy of
\r
6 * this software and associated documentation files (the "Software"), to deal in
\r
7 * the Software without restriction, including without limitation the rights to
\r
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
\r
9 * the Software, and to permit persons to whom the Software is furnished to do so,
\r
10 * subject to the following conditions:
\r
12 * The above copyright notice and this permission notice shall be included in all
\r
13 * copies or substantial portions of the Software.
\r
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
17 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
18 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
19 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
22 * http://www.FreeRTOS.org
\r
23 * http://aws.amazon.com/freertos
\r
25 * 1 tab == 4 spaces!
\r
28 /******************************************************************************
\r
29 * NOTE 1: This project provides two demo applications. A simple blinky
\r
30 * style project, and a more comprehensive test and demo application. The
\r
31 * mainSELECTED_APPLICATION setting in main.c is used to select between the two.
\r
32 * See the notes on using mainSELECTED_APPLICATION where it is defined below.
\r
34 * NOTE 2: This file only contains the source code that is not specific to
\r
35 * either the simply blinky or full demos - this includes initialisation code
\r
36 * and callback functions.
\r
39 /* Standard includes. */
\r
42 /* Scheduler include files. */
\r
43 #include "FreeRTOS.h"
\r
46 /* Xilinx includes. */
\r
47 #include "platform.h"
\r
49 #include "xscugic.h"
\r
51 /* mainSELECTED_APPLICATION is used to select between two demo applications,
\r
52 * as described at the top of this file.
\r
54 * When mainSELECTED_APPLICATION is set to 0 the simple blinky example will
\r
57 * When mainSELECTED_APPLICATION is set to 1 the comprehensive test and demo
\r
58 * application will be run.
\r
60 #define mainSELECTED_APPLICATION 1
\r
62 /*-----------------------------------------------------------*/
\r
65 * Configure the hardware as necessary to run this demo.
\r
67 static void prvSetupHardware( void );
\r
70 * See the comments at the top of this file and above the
\r
71 * mainSELECTED_APPLICATION definition.
\r
73 #if ( mainSELECTED_APPLICATION == 0 )
\r
74 extern void main_blinky( void );
\r
75 #elif ( mainSELECTED_APPLICATION == 1 )
\r
76 extern void main_full( void );
\r
78 #error Invalid mainSELECTED_APPLICATION setting. See the comments at the top of this file and above the mainSELECTED_APPLICATION definition.
\r
81 /* Prototypes for the standard FreeRTOS callback/hook functions implemented
\r
82 within this file. */
\r
83 void vApplicationMallocFailedHook( void );
\r
84 void vApplicationIdleHook( void );
\r
85 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );
\r
86 void vApplicationTickHook( void );
\r
88 /*-----------------------------------------------------------*/
\r
90 /* The interrupt controller is initialised in this file, and made available to
\r
92 XScuGic xInterruptController;
\r
94 /*-----------------------------------------------------------*/
\r
98 /* Configure the hardware ready to run the demo. */
\r
101 /* The mainSELECTED_APPLICATION setting is described at the top
\r
103 #if( mainSELECTED_APPLICATION == 0 )
\r
107 #elif( mainSELECTED_APPLICATION == 1 )
\r
113 /* Don't expect to reach here. */
\r
116 /*-----------------------------------------------------------*/
\r
118 static void prvSetupHardware( void )
\r
120 BaseType_t xStatus;
\r
121 XScuGic_Config *pxGICConfig;
\r
123 /* Ensure no interrupts execute while the scheduler is in an inconsistent
\r
124 state. Interrupts are automatically enabled when the scheduler is
\r
126 portDISABLE_INTERRUPTS();
\r
128 /* Obtain the configuration of the GIC. */
\r
129 pxGICConfig = XScuGic_LookupConfig( XPAR_SCUGIC_SINGLE_DEVICE_ID );
\r
131 /* Sanity check the FreeRTOSConfig.h settings are correct for the
\r
133 configASSERT( pxGICConfig );
\r
134 configASSERT( pxGICConfig->CpuBaseAddress == ( configINTERRUPT_CONTROLLER_BASE_ADDRESS + configINTERRUPT_CONTROLLER_CPU_INTERFACE_OFFSET ) );
\r
135 configASSERT( pxGICConfig->DistBaseAddress == configINTERRUPT_CONTROLLER_BASE_ADDRESS );
\r
137 /* Install a default handler for each GIC interrupt. */
\r
138 xStatus = XScuGic_CfgInitialize( &xInterruptController, pxGICConfig, pxGICConfig->CpuBaseAddress );
\r
139 configASSERT( xStatus == XST_SUCCESS );
\r
140 ( void ) xStatus; /* Remove compiler warning if configASSERT() is not defined. */
\r
142 /*-----------------------------------------------------------*/
\r
144 void vApplicationMallocFailedHook( void )
\r
146 /* Called if a call to pvPortMalloc() fails because there is insufficient
\r
147 free memory available in the FreeRTOS heap. pvPortMalloc() is called
\r
148 internally by FreeRTOS API functions that create tasks, queues, software
\r
149 timers, and semaphores. The size of the FreeRTOS heap is set by the
\r
150 configTOTAL_HEAP_SIZE configuration constant in FreeRTOSConfig.h. */
\r
151 taskDISABLE_INTERRUPTS();
\r
154 /*-----------------------------------------------------------*/
\r
156 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
\r
158 ( void ) pcTaskName;
\r
161 /* Run time stack overflow checking is performed if
\r
162 configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook
\r
163 function is called if a stack overflow is detected. */
\r
164 taskDISABLE_INTERRUPTS();
\r
167 /*-----------------------------------------------------------*/
\r
169 void vApplicationIdleHook( void )
\r
171 volatile size_t xFreeHeapSpace;
\r
173 /* This is just a trivial example of an idle hook. It is called on each
\r
174 cycle of the idle task. It must *NOT* attempt to block. In this case the
\r
175 idle task just queries the amount of FreeRTOS heap that remains. See the
\r
176 memory management section on the http://www.FreeRTOS.org web site for memory
\r
177 management options. If there is a lot of heap memory free then the
\r
178 configTOTAL_HEAP_SIZE value in FreeRTOSConfig.h can be reduced to free up
\r
180 xFreeHeapSpace = xPortGetFreeHeapSize();
\r
182 /* Remove compiler warning about xFreeHeapSpace being set but never used. */
\r
183 ( void ) xFreeHeapSpace;
\r
185 /*-----------------------------------------------------------*/
\r
187 void vApplicationTickHook( void )
\r
189 #if( mainSELECTED_APPLICATION == 1 )
\r
191 /* Only the comprehensive demo actually uses the tick hook. */
\r
192 extern void vFullDemoTickHook( void );
\r
193 vFullDemoTickHook();
\r
197 /*-----------------------------------------------------------*/
\r
199 /* configUSE_STATIC_ALLOCATION is set to 1, so the application must provide an
\r
200 implementation of vApplicationGetIdleTaskMemory() to provide the memory that is
\r
201 used by the Idle task. */
\r
202 void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize )
\r
204 /* If the buffers to be provided to the Idle task are declared inside this
\r
205 function then they must be declared static - otherwise they will be allocated on
\r
206 the stack and so not exists after this function exits. */
\r
207 static StaticTask_t xIdleTaskTCB;
\r
208 static StackType_t uxIdleTaskStack[ configMINIMAL_STACK_SIZE ];
\r
210 /* Pass out a pointer to the StaticTask_t structure in which the Idle task's
\r
211 state will be stored. */
\r
212 *ppxIdleTaskTCBBuffer = &xIdleTaskTCB;
\r
214 /* Pass out the array that will be used as the Idle task's stack. */
\r
215 *ppxIdleTaskStackBuffer = uxIdleTaskStack;
\r
217 /* Pass out the size of the array pointed to by *ppxIdleTaskStackBuffer.
\r
218 Note that, as the array is necessarily of type StackType_t,
\r
219 configMINIMAL_STACK_SIZE is specified in words, not bytes. */
\r
220 *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;
\r
222 /*-----------------------------------------------------------*/
\r
224 /* configUSE_STATIC_ALLOCATION and configUSE_TIMERS are both set to 1, so the
\r
225 application must provide an implementation of vApplicationGetTimerTaskMemory()
\r
226 to provide the memory that is used by the Timer service task. */
\r
227 void vApplicationGetTimerTaskMemory( StaticTask_t **ppxTimerTaskTCBBuffer, StackType_t **ppxTimerTaskStackBuffer, uint32_t *pulTimerTaskStackSize )
\r
229 /* If the buffers to be provided to the Timer task are declared inside this
\r
230 function then they must be declared static - otherwise they will be allocated on
\r
231 the stack and so not exists after this function exits. */
\r
232 static StaticTask_t xTimerTaskTCB;
\r
233 static StackType_t uxTimerTaskStack[ configTIMER_TASK_STACK_DEPTH ];
\r
235 /* Pass out a pointer to the StaticTask_t structure in which the Timer
\r
236 task's state will be stored. */
\r
237 *ppxTimerTaskTCBBuffer = &xTimerTaskTCB;
\r
239 /* Pass out the array that will be used as the Timer task's stack. */
\r
240 *ppxTimerTaskStackBuffer = uxTimerTaskStack;
\r
242 /* Pass out the size of the array pointed to by *ppxTimerTaskStackBuffer.
\r
243 Note that, as the array is necessarily of type StackType_t,
\r
244 configMINIMAL_STACK_SIZE is specified in words, not bytes. */
\r
245 *pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;
\r
247 /*-----------------------------------------------------------*/
\r
249 void vMainAssertCalled( const char *pcFileName, uint32_t ulLineNumber )
\r
251 xil_printf( "ASSERT! Line %lu of file %s\r\n", ulLineNumber, pcFileName );
\r
252 taskENTER_CRITICAL();
\r