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 FreeRTOS hook functions.
\r
43 * This demo does not contain a non-kernel interrupt service routine that
\r
44 * can be used as an example for application writers to use as a reference.
\r
45 * Therefore, the framework of a dummy (not installed) handler is provided
\r
46 * in this file. The dummy function is called Dummy_IRQHandler(). Please
\r
47 * ensure to read the comments in the function itself, but more importantly,
\r
48 * the notes on the function contained on the documentation page for this demo
\r
49 * that is found on the FreeRTOS.org web site.
\r
53 * The following #error directive is to remind users that a batch file must be
\r
54 * executed prior to this project being built. The batch file *cannot* be
\r
55 * executed from within the IDE! Once it has been executed, re-open or refresh
\r
56 * the Eclipse project and remove the #error line below.
\r
58 #error Ensure CreateProjectDirectoryStructure.bat has been executed before building. See comment immediately above.
\r
61 /* Standard includes. */
\r
64 /* Kernel includes. */
\r
65 #include "FreeRTOS.h"
\r
68 /* Standard demo includes. */
\r
69 #include "QueueSet.h"
\r
70 #include "QueueOverwrite.h"
\r
72 /* Set mainCREATE_SIMPLE_BLINKY_DEMO_ONLY to one to run the simple blinky demo,
\r
73 or 0 to run the more comprehensive test and demo application. */
\r
74 #define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY 1
\r
76 /*-----------------------------------------------------------*/
\r
79 * Set up the hardware ready to run this demo.
\r
81 static void prvSetupHardware( void );
\r
84 * main_blinky() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1.
\r
85 * main_full() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 0.
\r
87 extern void main_blinky( void );
\r
88 extern void main_full( void );
\r
90 /*-----------------------------------------------------------*/
\r
94 /* Prepare the hardware to run this demo. */
\r
97 /* The mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is described at the top
\r
99 #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1
\r
111 /*-----------------------------------------------------------*/
\r
113 static void prvSetupHardware( void )
\r
115 configCONFIGURE_LED();
\r
117 /* Ensure all priority bits are assigned as preemption priority bits. */
\r
118 NVIC_SetPriorityGrouping( 0 );
\r
120 /*-----------------------------------------------------------*/
\r
122 void vApplicationMallocFailedHook( void )
\r
124 /* vApplicationMallocFailedHook() will only be called if
\r
125 configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h. It is a hook
\r
126 function that will get called if a call to pvPortMalloc() fails.
\r
127 pvPortMalloc() is called internally by the kernel whenever a task, queue,
\r
128 timer or semaphore is created. It is also called by various parts of the
\r
129 demo application. If heap_1.c or heap_2.c are used, then the size of the
\r
130 heap available to pvPortMalloc() is defined by configTOTAL_HEAP_SIZE in
\r
131 FreeRTOSConfig.h, and the xPortGetFreeHeapSize() API function can be used
\r
132 to query the size of free heap space that remains (although it does not
\r
133 provide information on how the remaining heap might be fragmented). */
\r
134 taskDISABLE_INTERRUPTS();
\r
137 __asm volatile( "NOP" );
\r
140 /*-----------------------------------------------------------*/
\r
142 void vApplicationIdleHook( void )
\r
144 /* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set
\r
145 to 1 in FreeRTOSConfig.h. It will be called on each iteration of the idle
\r
146 task. It is essential that code added to this hook function never attempts
\r
147 to block in any way (for example, call xQueueReceive() with a block time
\r
148 specified, or call vTaskDelay()). If the application makes use of the
\r
149 vTaskDelete() API function (as this demo application does) then it is also
\r
150 important that vApplicationIdleHook() is permitted to return to its calling
\r
151 function, because it is the responsibility of the idle task to clean up
\r
152 memory allocated by the kernel to any task that has since been deleted. */
\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 __asm volatile( "NOP" );
\r
170 /*-----------------------------------------------------------*/
\r
172 void vApplicationTickHook( void )
\r
174 /* This function will be called by each tick interrupt if
\r
175 configUSE_TICK_HOOK is set to 1 in FreeRTOSConfig.h. User code can be
\r
176 added here, but the tick hook is called from an interrupt context, so
\r
177 code must not attempt to block, and only the interrupt safe FreeRTOS API
\r
178 functions can be used (those that end in FromISR()). */
\r
180 #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 0
\r
182 /* Write to a queue that is in use as part of the queue set demo to
\r
183 demonstrate using queue sets from an ISR. */
\r
184 vQueueSetAccessQueueSetFromISR();
\r
186 /* Test the ISR safe queue overwrite functions. */
\r
187 vQueueOverwritePeriodicISRDemo();
\r
189 #endif /* mainCREATE_SIMPLE_BLINKY_DEMO_ONLY */
\r
191 /*-----------------------------------------------------------*/
\r
193 #ifdef JUST_AN_EXAMPLE_ISR
\r
195 void Dummy_IRQHandler(void)
\r
197 long lHigherPriorityTaskWoken = pdFALSE;
\r
199 /* Clear the interrupt if necessary. */
\r
200 Dummy_ClearITPendingBit();
\r
202 /* This interrupt does nothing more than demonstrate how to synchronise a
\r
203 task with an interrupt. A semaphore is used for this purpose. Note
\r
204 lHigherPriorityTaskWoken is initialised to zero. */
\r
205 xSemaphoreGiveFromISR( xTestSemaphore, &lHigherPriorityTaskWoken );
\r
207 /* If there was a task that was blocked on the semaphore, and giving the
\r
208 semaphore caused the task to unblock, and the unblocked task has a priority
\r
209 higher than the current Running state task (the task that this interrupt
\r
210 interrupted), then lHigherPriorityTaskWoken will have been set to pdTRUE
\r
211 internally within xSemaphoreGiveFromISR(). Passing pdTRUE into the
\r
212 portEND_SWITCHING_ISR() macro will result in a context switch being pended to
\r
213 ensure this interrupt returns directly to the unblocked, higher priority,
\r
214 task. Passing pdFALSE into portEND_SWITCHING_ISR() has no effect. */
\r
215 portEND_SWITCHING_ISR( lHigherPriorityTaskWoken );
\r
218 #endif /* JUST_AN_EXAMPLE_ISR */
\r