2 * FreeRTOS Kernel V10.0.0
\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. If you wish to use our Amazon
\r
14 * FreeRTOS name, please do so in a fair use way that does not cause confusion.
\r
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
18 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
19 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
20 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
23 * http://www.FreeRTOS.org
\r
24 * http://aws.amazon.com/freertos
\r
26 * 1 tab == 4 spaces!
\r
29 /******************************************************************************
\r
30 * This project provides two demo applications. A simple blinky style project,
\r
31 * and a more comprehensive test and demo application. The
\r
32 * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting (defined in this file) is used to
\r
33 * select between the two. The simply blinky demo is implemented and described
\r
34 * in main_blinky.c. The more comprehensive test and demo application is
\r
35 * implemented and described in main_full.c.
\r
37 * This file implements the code that is not demo specific, including the
\r
38 * hardware setup and standard FreeRTOS hook functions.
\r
41 /* Scheduler include files. */
\r
42 #include "FreeRTOS.h"
\r
46 /* Standard demo includes - these are needed here as the tick hook function is
\r
47 defined in this file. */
\r
48 #include "TimerDemo.h"
\r
49 #include "QueueOverwrite.h"
\r
50 #include "EventGroupsDemo.h"
\r
51 #include "IntSemTest.h"
\r
52 #include "QueueSet.h"
\r
53 #include "TaskNotify.h"
\r
55 /* Set mainCREATE_SIMPLE_BLINKY_DEMO_ONLY to one to run the simple blinky demo,
\r
56 or 0 to run the more comprehensive test and demo application. */
\r
57 #define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY 0
\r
59 /*-----------------------------------------------------------*/
\r
62 * Configure the hardware as necessary to run this demo.
\r
64 static void prvSetupHardware( void );
\r
67 * Configure the system clock for maximum speed.
\r
69 static void prvSystemClockConfig( void );
\r
72 * main_blinky() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1.
\r
73 * main_full() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 0.
\r
75 #if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 )
\r
76 extern void main_blinky( void );
\r
78 extern void main_full( void );
\r
79 #endif /* #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 */
\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
92 /* Configure the hardware ready to run the demo. */
\r
95 /* The mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is described at the top
\r
97 #if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 )
\r
109 /*-----------------------------------------------------------*/
\r
111 static void prvSetupHardware( void )
\r
113 GPIO_InitTypeDef GPIO_InitStruct;
\r
115 /* Configure Flash prefetch and Instruction cache through ART accelerator. */
\r
116 #if( ART_ACCLERATOR_ENABLE != 0 )
\r
118 __HAL_FLASH_ART_ENABLE();
\r
120 #endif /* ART_ACCLERATOR_ENABLE */
\r
122 /* Set Interrupt Group Priority */
\r
123 HAL_NVIC_SetPriorityGrouping( NVIC_PRIORITYGROUP_4 );
\r
125 /* Init the low level hardware. */
\r
128 /* Configure the System clock to have a frequency of 200 MHz */
\r
129 prvSystemClockConfig();
\r
131 /* Enable GPIOB Clock (to be able to program the configuration
\r
132 registers) and configure for LED output. */
\r
133 __GPIOG_CLK_ENABLE();
\r
134 __HAL_RCC_GPIOF_CLK_ENABLE();
\r
136 GPIO_InitStruct.Pin = GPIO_PIN_10;
\r
137 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
\r
138 GPIO_InitStruct.Pull = GPIO_PULLUP;
\r
139 GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
\r
140 HAL_GPIO_Init( GPIOF, &GPIO_InitStruct );
\r
142 /* MCO2 : Pin PC9 */
\r
143 HAL_RCC_MCOConfig( RCC_MCO2, RCC_MCO2SOURCE_SYSCLK, RCC_MCODIV_1 );
\r
145 /*-----------------------------------------------------------*/
\r
147 static void prvSystemClockConfig( void )
\r
149 /* The system Clock is configured as follow :
\r
150 System Clock source = PLL (HSE)
\r
151 SYSCLK(Hz) = 200000000
\r
152 HCLK(Hz) = 200000000
\r
156 HSE Frequency(Hz) = 25000000
\r
162 Main regulator output voltage = Scale1 mode
\r
163 Flash Latency(WS) = 7 */
\r
164 RCC_ClkInitTypeDef RCC_ClkInitStruct;
\r
165 RCC_OscInitTypeDef RCC_OscInitStruct;
\r
167 /* Enable HSE Oscillator and activate PLL with HSE as source */
\r
168 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
\r
169 RCC_OscInitStruct.HSEState = RCC_HSE_ON;
\r
170 RCC_OscInitStruct.HSIState = RCC_HSI_OFF;
\r
171 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
\r
172 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
\r
173 RCC_OscInitStruct.PLL.PLLM = 25;
\r
174 RCC_OscInitStruct.PLL.PLLN = 400;
\r
175 RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
\r
176 RCC_OscInitStruct.PLL.PLLQ = 7;
\r
177 HAL_RCC_OscConfig(&RCC_OscInitStruct);
\r
179 /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
\r
181 RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
\r
182 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
\r
183 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
\r
184 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
\r
185 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
\r
186 configASSERT( HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_7) == HAL_OK );
\r
188 /*-----------------------------------------------------------*/
\r
190 void vApplicationMallocFailedHook( void )
\r
192 /* Called if a call to pvPortMalloc() fails because there is insufficient
\r
193 free memory available in the FreeRTOS heap. pvPortMalloc() is called
\r
194 internally by FreeRTOS API functions that create tasks, queues, software
\r
195 timers, and semaphores. The size of the FreeRTOS heap is set by the
\r
196 configTOTAL_HEAP_SIZE configuration constant in FreeRTOSConfig.h. */
\r
198 /* Force an assert. */
\r
199 configASSERT( ( volatile void * ) NULL );
\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. */
\r
212 /* Force an assert. */
\r
213 configASSERT( ( volatile void * ) NULL );
\r
215 /*-----------------------------------------------------------*/
\r
217 void vApplicationIdleHook( void )
\r
219 volatile size_t xFreeHeapSpace;
\r
221 /* This is just a trivial example of an idle hook. It is called on each
\r
222 cycle of the idle task. It must *NOT* attempt to block. In this case the
\r
223 idle task just queries the amount of FreeRTOS heap that remains. See the
\r
224 memory management section on the http://www.FreeRTOS.org web site for memory
\r
225 management options. If there is a lot of heap memory free then the
\r
226 configTOTAL_HEAP_SIZE value in FreeRTOSConfig.h can be reduced to free up
\r
228 xFreeHeapSpace = xPortGetFreeHeapSize();
\r
230 /* Remove compiler warning about xFreeHeapSpace being set but never used. */
\r
231 ( void ) xFreeHeapSpace;
\r
233 /*-----------------------------------------------------------*/
\r
235 void vAssertCalled( uint32_t ulLine, const char *pcFile )
\r
237 volatile unsigned long ul = 0;
\r
242 taskENTER_CRITICAL();
\r
244 /* Set ul to a non-zero value using the debugger to step out of this
\r
251 taskEXIT_CRITICAL();
\r
253 /*-----------------------------------------------------------*/
\r
255 void vApplicationTickHook( void )
\r
257 #if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 0 )
\r
259 /* The full demo includes a software timer demo/test that requires
\r
260 prodding periodically from the tick interrupt. */
\r
261 vTimerPeriodicISRTests();
\r
263 /* Call the periodic queue overwrite from ISR demo. */
\r
264 vQueueOverwritePeriodicISRDemo();
\r
266 /* Call the periodic event group from ISR demo. */
\r
267 vPeriodicEventGroupsProcessing();
\r
269 /* Call the code that uses a mutex from an ISR. */
\r
270 vInterruptSemaphorePeriodicTest();
\r
272 /* Use a queue set from an ISR. */
\r
273 vQueueSetAccessQueueSetFromISR();
\r
275 /* Use task notifications from an ISR. */
\r
276 xNotifyTaskFromISR();
\r
280 /*-----------------------------------------------------------*/
\r