]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_M4F_Infineon_XMC4000_Tasking/main.c
Update version number in readiness for V10.3.0 release. Sync SVN with reviewed releas...
[freertos] / FreeRTOS / Demo / CORTEX_M4F_Infineon_XMC4000_Tasking / main.c
1 /*\r
2  * FreeRTOS Kernel V10.3.0\r
3  * Copyright (C) 2020 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
4  *\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
11  *\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
14  *\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
21  *\r
22  * http://www.FreeRTOS.org\r
23  * http://aws.amazon.com/freertos\r
24  *\r
25  * 1 tab == 4 spaces!\r
26  */\r
27 \r
28 /******************************************************************************\r
29  * This project provides two demo applications.  A simple blinky style project,\r
30  * and a more comprehensive test and demo application.  The\r
31  * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting (defined in this file) is used to\r
32  * select between the two.  The simply blinky demo is implemented and described\r
33  * in main_blinky.c.  The more comprehensive test and demo application is\r
34  * implemented and described in main_full.c.\r
35  *\r
36  * This file implements the code that is not demo specific, including the\r
37  * hardware setup and FreeRTOS hook functions.\r
38  *\r
39  *\r
40  * Additional code:\r
41  *\r
42  * This demo does not contain a non-kernel interrupt service routine that\r
43  * can be used as an example for application writers to use as a reference.\r
44  * Therefore, the framework of a dummy (not installed) handler is provided\r
45  * in this file.  The dummy function is called Dummy_IRQHandler().  Please\r
46  * ensure to read the comments in the function itself, but more importantly,\r
47  * the notes on the function contained on the documentation page for this demo\r
48  * that is found on the FreeRTOS.org web site.\r
49  */\r
50 \r
51 /* \r
52  * The following #error directive is to remind users that a batch file must be\r
53  * executed prior to this project being built.  The batch file *cannot* be \r
54  * executed from within the IDE!  Once it has been executed, re-open or refresh \r
55  * the Eclipse project and remove the #error line below.\r
56  */\r
57 #error Ensure CreateProjectDirectoryStructure.bat has been executed before building.  See comment immediately above.\r
58 \r
59 \r
60 /* Standard includes. */\r
61 #include <stdio.h>\r
62 \r
63 /* Kernel includes. */\r
64 #include "FreeRTOS.h"\r
65 #include "task.h"\r
66 \r
67 /* Standard demo includes. */\r
68 #include "QueueSet.h"\r
69 #include "QueueOverwrite.h"\r
70 \r
71 /* Set mainCREATE_SIMPLE_BLINKY_DEMO_ONLY to one to run the simple blinky demo,\r
72 or 0 to run the more comprehensive test and demo application. */\r
73 #define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY      1\r
74 \r
75 /*-----------------------------------------------------------*/\r
76 \r
77 /*\r
78  * Set up the hardware ready to run this demo.\r
79  */\r
80 static void prvSetupHardware( void );\r
81 \r
82 /*\r
83  * main_blinky() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1.\r
84  * main_full() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 0.\r
85  */\r
86 extern void main_blinky( void );\r
87 extern void main_full( void );\r
88 \r
89 /*-----------------------------------------------------------*/\r
90 \r
91 int main( void )\r
92 {\r
93         /* Prepare the hardware to run this demo. */\r
94         prvSetupHardware();\r
95 \r
96         /* The mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is described at the top\r
97         of this file. */\r
98         #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1\r
99         {\r
100                 main_blinky();\r
101         }\r
102         #else\r
103         {\r
104                 main_full();\r
105         }\r
106         #endif\r
107 \r
108         return 0;\r
109 }\r
110 /*-----------------------------------------------------------*/\r
111 \r
112 static void prvSetupHardware( void )\r
113 {\r
114         configCONFIGURE_LED();\r
115 \r
116         /* Ensure all priority bits are assigned as preemption priority bits. */\r
117         NVIC_SetPriorityGrouping( 0 );\r
118 }\r
119 /*-----------------------------------------------------------*/\r
120 \r
121 void vApplicationMallocFailedHook( void )\r
122 {\r
123         /* vApplicationMallocFailedHook() will only be called if\r
124         configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h.  It is a hook\r
125         function that will get called if a call to pvPortMalloc() fails.\r
126         pvPortMalloc() is called internally by the kernel whenever a task, queue,\r
127         timer or semaphore is created.  It is also called by various parts of the\r
128         demo application.  If heap_1.c or heap_2.c are used, then the size of the\r
129         heap available to pvPortMalloc() is defined by configTOTAL_HEAP_SIZE in\r
130         FreeRTOSConfig.h, and the xPortGetFreeHeapSize() API function can be used\r
131         to query the size of free heap space that remains (although it does not\r
132         provide information on how the remaining heap might be fragmented). */\r
133         taskDISABLE_INTERRUPTS();\r
134         for( ;; )\r
135         {\r
136                 __asm volatile( "NOP" );\r
137         };\r
138 }\r
139 /*-----------------------------------------------------------*/\r
140 \r
141 void vApplicationIdleHook( void )\r
142 {\r
143         /* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set\r
144         to 1 in FreeRTOSConfig.h.  It will be called on each iteration of the idle\r
145         task.  It is essential that code added to this hook function never attempts\r
146         to block in any way (for example, call xQueueReceive() with a block time\r
147         specified, or call vTaskDelay()).  If the application makes use of the\r
148         vTaskDelete() API function (as this demo application does) then it is also\r
149         important that vApplicationIdleHook() is permitted to return to its calling\r
150         function, because it is the responsibility of the idle task to clean up\r
151         memory allocated by the kernel to any task that has since been deleted. */\r
152 }\r
153 /*-----------------------------------------------------------*/\r
154 \r
155 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )\r
156 {\r
157         ( void ) pcTaskName;\r
158         ( void ) pxTask;\r
159 \r
160         /* Run time stack overflow checking is performed if\r
161         configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2.  This hook\r
162         function is called if a stack overflow is detected. */\r
163         taskDISABLE_INTERRUPTS();\r
164         for( ;; )\r
165         {\r
166                 __asm volatile( "NOP" );\r
167         }\r
168 }\r
169 /*-----------------------------------------------------------*/\r
170 \r
171 void vApplicationTickHook( void )\r
172 {\r
173         /* This function will be called by each tick interrupt if\r
174         configUSE_TICK_HOOK is set to 1 in FreeRTOSConfig.h.  User code can be\r
175         added here, but the tick hook is called from an interrupt context, so\r
176         code must not attempt to block, and only the interrupt safe FreeRTOS API\r
177         functions can be used (those that end in FromISR()). */\r
178 \r
179         #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 0\r
180         {\r
181                 /* Write to a queue that is in use as part of the queue set demo to\r
182                 demonstrate using queue sets from an ISR. */\r
183                 vQueueSetAccessQueueSetFromISR();\r
184 \r
185                 /* Test the ISR safe queue overwrite functions. */\r
186                 vQueueOverwritePeriodicISRDemo();\r
187         }\r
188         #endif /* mainCREATE_SIMPLE_BLINKY_DEMO_ONLY */\r
189 }\r
190 /*-----------------------------------------------------------*/\r
191 \r
192 #ifdef JUST_AN_EXAMPLE_ISR\r
193 \r
194 void Dummy_IRQHandler(void)\r
195 {\r
196 long lHigherPriorityTaskWoken = pdFALSE;\r
197 \r
198         /* Clear the interrupt if necessary. */\r
199         Dummy_ClearITPendingBit();\r
200 \r
201         /* This interrupt does nothing more than demonstrate how to synchronise a\r
202         task with an interrupt.  A semaphore is used for this purpose.  Note\r
203         lHigherPriorityTaskWoken is initialised to zero. */\r
204         xSemaphoreGiveFromISR( xTestSemaphore, &lHigherPriorityTaskWoken );\r
205 \r
206         /* If there was a task that was blocked on the semaphore, and giving the\r
207         semaphore caused the task to unblock, and the unblocked task has a priority\r
208         higher than the current Running state task (the task that this interrupt\r
209         interrupted), then lHigherPriorityTaskWoken will have been set to pdTRUE\r
210         internally within xSemaphoreGiveFromISR().  Passing pdTRUE into the\r
211         portEND_SWITCHING_ISR() macro will result in a context switch being pended to\r
212         ensure this interrupt returns directly to the unblocked, higher priority,\r
213         task.  Passing pdFALSE into portEND_SWITCHING_ISR() has no effect. */\r
214         portEND_SWITCHING_ISR( lHigherPriorityTaskWoken );\r
215 }\r
216 \r
217 #endif /* JUST_AN_EXAMPLE_ISR */\r