2 FreeRTOS V8.2.1 - 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 standard FreeRTOS hook functions.
\r
82 /* Scheduler include files. */
\r
83 #include "FreeRTOS.h"
\r
87 /* Standard demo includes - these are needed here as the tick hook function is
\r
88 defined in this file. */
\r
89 #include "TimerDemo.h"
\r
90 #include "QueueOverwrite.h"
\r
91 #include "EventGroupsDemo.h"
\r
92 #include "IntSemTest.h"
\r
93 #include "QueueSet.h"
\r
94 #include "TaskNotify.h"
\r
96 /* Set mainCREATE_SIMPLE_BLINKY_DEMO_ONLY to one to run the simple blinky demo,
\r
97 or 0 to run the more comprehensive test and demo application. */
\r
98 #define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY 0
\r
100 /*-----------------------------------------------------------*/
\r
103 * Configure the hardware as necessary to run this demo.
\r
105 static void prvSetupHardware( void );
\r
108 * Configure the system clock for maximum speed.
\r
110 static void prvSystemClockConfig( void );
\r
113 * main_blinky() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1.
\r
114 * main_full() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 0.
\r
116 #if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 )
\r
117 extern void main_blinky( void );
\r
119 extern void main_full( void );
\r
120 #endif /* #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 */
\r
122 /* Prototypes for the standard FreeRTOS callback/hook functions implemented
\r
123 within this file. */
\r
124 void vApplicationMallocFailedHook( void );
\r
125 void vApplicationIdleHook( void );
\r
126 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );
\r
127 void vApplicationTickHook( void );
\r
129 /*-----------------------------------------------------------*/
\r
133 /* Configure the hardware ready to run the demo. */
\r
134 prvSetupHardware();
\r
136 /* The mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is described at the top
\r
138 #if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 )
\r
150 /*-----------------------------------------------------------*/
\r
152 static void prvSetupHardware( void )
\r
154 GPIO_InitTypeDef GPIO_InitStruct;
\r
156 /* Configure Flash prefetch and Instruction cache through ART accelerator. */
\r
157 #if( ART_ACCLERATOR_ENABLE != 0 )
\r
159 __HAL_FLASH_ART_ENABLE();
\r
161 #endif /* ART_ACCLERATOR_ENABLE */
\r
163 /* Set Interrupt Group Priority */
\r
164 HAL_NVIC_SetPriorityGrouping( NVIC_PRIORITYGROUP_4 );
\r
166 /* Init the low level hardware. */
\r
169 /* Configure the System clock to have a frequency of 200 MHz */
\r
170 prvSystemClockConfig();
\r
172 /* Enable GPIOB Clock (to be able to program the configuration
\r
173 registers) and configure for LED output. */
\r
174 __GPIOG_CLK_ENABLE();
\r
176 GPIO_InitStruct.Pin = GPIO_PIN_6;
\r
177 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
\r
178 GPIO_InitStruct.Pull = GPIO_PULLUP;
\r
179 GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
\r
180 HAL_GPIO_Init( GPIOG, &GPIO_InitStruct );
\r
182 /* MCO2 : Pin PC9 */
\r
183 HAL_RCC_MCOConfig( RCC_MCO2, RCC_MCO2SOURCE_SYSCLK, RCC_MCODIV_1 );
\r
185 /*-----------------------------------------------------------*/
\r
187 static void prvSystemClockConfig( void )
\r
189 /* The system Clock is configured as follow :
\r
190 System Clock source = PLL (HSE)
\r
191 SYSCLK(Hz) = 200000000
\r
192 HCLK(Hz) = 200000000
\r
196 HSE Frequency(Hz) = 25000000
\r
202 Main regulator output voltage = Scale1 mode
\r
203 Flash Latency(WS) = 7 */
\r
204 RCC_ClkInitTypeDef RCC_ClkInitStruct;
\r
205 RCC_OscInitTypeDef RCC_OscInitStruct;
\r
207 /* Enable HSE Oscillator and activate PLL with HSE as source */
\r
208 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
\r
209 RCC_OscInitStruct.HSEState = RCC_HSE_ON;
\r
210 RCC_OscInitStruct.HSIState = RCC_HSI_OFF;
\r
211 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
\r
212 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
\r
213 RCC_OscInitStruct.PLL.PLLM = 25;
\r
214 RCC_OscInitStruct.PLL.PLLN = 400;
\r
215 RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
\r
216 RCC_OscInitStruct.PLL.PLLQ = 7;
\r
217 HAL_RCC_OscConfig(&RCC_OscInitStruct);
\r
219 /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
\r
221 RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
\r
222 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
\r
223 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
\r
224 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
\r
225 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
\r
226 configASSERT( HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_7) == HAL_OK );
\r
228 /*-----------------------------------------------------------*/
\r
230 void vApplicationMallocFailedHook( void )
\r
232 /* Called if a call to pvPortMalloc() fails because there is insufficient
\r
233 free memory available in the FreeRTOS heap. pvPortMalloc() is called
\r
234 internally by FreeRTOS API functions that create tasks, queues, software
\r
235 timers, and semaphores. The size of the FreeRTOS heap is set by the
\r
236 configTOTAL_HEAP_SIZE configuration constant in FreeRTOSConfig.h. */
\r
238 /* Force an assert. */
\r
239 configASSERT( ( volatile void * ) NULL );
\r
241 /*-----------------------------------------------------------*/
\r
243 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
\r
245 ( void ) pcTaskName;
\r
248 /* Run time stack overflow checking is performed if
\r
249 configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook
\r
250 function is called if a stack overflow is detected. */
\r
252 /* Force an assert. */
\r
253 configASSERT( ( volatile void * ) NULL );
\r
255 /*-----------------------------------------------------------*/
\r
257 void vApplicationIdleHook( void )
\r
259 volatile size_t xFreeHeapSpace;
\r
261 /* This is just a trivial example of an idle hook. It is called on each
\r
262 cycle of the idle task. It must *NOT* attempt to block. In this case the
\r
263 idle task just queries the amount of FreeRTOS heap that remains. See the
\r
264 memory management section on the http://www.FreeRTOS.org web site for memory
\r
265 management options. If there is a lot of heap memory free then the
\r
266 configTOTAL_HEAP_SIZE value in FreeRTOSConfig.h can be reduced to free up
\r
268 xFreeHeapSpace = xPortGetFreeHeapSize();
\r
270 /* Remove compiler warning about xFreeHeapSpace being set but never used. */
\r
271 ( void ) xFreeHeapSpace;
\r
273 /*-----------------------------------------------------------*/
\r
275 void vAssertCalled( uint32_t ulLine, const char *pcFile )
\r
277 volatile unsigned long ul = 0;
\r
282 taskENTER_CRITICAL();
\r
284 /* Set ul to a non-zero value using the debugger to step out of this
\r
291 taskEXIT_CRITICAL();
\r
293 /*-----------------------------------------------------------*/
\r
295 void vApplicationTickHook( void )
\r
297 #if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 0 )
\r
299 /* The full demo includes a software timer demo/test that requires
\r
300 prodding periodically from the tick interrupt. */
\r
301 vTimerPeriodicISRTests();
\r
303 /* Call the periodic queue overwrite from ISR demo. */
\r
304 vQueueOverwritePeriodicISRDemo();
\r
306 /* Call the periodic event group from ISR demo. */
\r
307 vPeriodicEventGroupsProcessing();
\r
309 /* Call the code that uses a mutex from an ISR. */
\r
310 vInterruptSemaphorePeriodicTest();
\r
312 /* Use a queue set from an ISR. */
\r
313 vQueueSetAccessQueueSetFromISR();
\r
315 /* Use task notifications from an ISR. */
\r
316 xNotifyTaskFromISR();
\r
320 /*-----------------------------------------------------------*/
\r