]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_M0_Infineon_XMC1000_IAR_Keil_GCC/main.c
Update version number in readiness for V10.3.0 release. Sync SVN with reviewed releas...
[freertos] / FreeRTOS / Demo / CORTEX_M0_Infineon_XMC1000_IAR_Keil_GCC / 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.  It also contains a dummy\r
38  * interrupt service routine called Dummy_IRQHandler() that is provided as an\r
39  * example of how to use interrupt safe FreeRTOS API functions (those that end\r
40  * in "FromISR").\r
41  *\r
42  *****************************************************************************/\r
43 \r
44 \r
45 /* Standard includes. */\r
46 #include "string.h"\r
47 \r
48 /* FreeRTOS includes. */\r
49 #include "FreeRTOS.h"\r
50 #include "task.h"\r
51 #include "semphr.h"\r
52 \r
53 /* Demo application include. */\r
54 #include "ParTest.h"\r
55 #include "QueueSet.h"\r
56 \r
57 /* Set mainCREATE_SIMPLE_BLINKY_DEMO_ONLY to one to run the simple blinky demo,\r
58 or 0 to run the more comprehensive test and demo application. */\r
59 #define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY      1\r
60 \r
61 \r
62 /*-----------------------------------------------------------*/\r
63 \r
64 /*\r
65  * Perform any application specific hardware configuration.  The clocks,\r
66  * memory, etc. are configured before main() is called.\r
67  */\r
68 static void prvSetupHardware( void );\r
69 \r
70 /*\r
71  * main_blinky() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1.\r
72  * main_full() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 0.\r
73  */\r
74 extern void main_blinky( void );\r
75 extern void main_full( void );\r
76 \r
77 /*\r
78  * CMSIS clock configuration function.\r
79  */\r
80 extern void SystemCoreClockUpdate( void );\r
81 \r
82 /*-----------------------------------------------------------*/\r
83 \r
84 int main( void )\r
85 {\r
86         /* Prepare the hardware to run this demo. */\r
87         prvSetupHardware();\r
88 \r
89         /* The mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is described at the top\r
90         of this file. */\r
91         #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1\r
92         {\r
93                 main_blinky();\r
94         }\r
95         #else\r
96         {\r
97                 main_full();\r
98         }\r
99         #endif\r
100 \r
101         return 0;\r
102 }\r
103 /*-----------------------------------------------------------*/\r
104 \r
105 static void prvSetupHardware( void )\r
106 {\r
107         SystemCoreClockUpdate();\r
108         vParTestInitialise();\r
109 }\r
110 /*-----------------------------------------------------------*/\r
111 \r
112 void vApplicationMallocFailedHook( void )\r
113 {\r
114         /* vApplicationMallocFailedHook() will only be called if\r
115         configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h.  It is a hook\r
116         function that will get called if a call to pvPortMalloc() fails.\r
117         pvPortMalloc() is called internally by the kernel whenever a task, queue,\r
118         timer or semaphore is created.  It is also called by various parts of the\r
119         demo application.  If heap_1.c or heap_2.c are used, then the size of the\r
120         heap available to pvPortMalloc() is defined by configTOTAL_HEAP_SIZE in\r
121         FreeRTOSConfig.h, and the xPortGetFreeHeapSize() API function can be used\r
122         to query the size of free heap space that remains (although it does not\r
123         provide information on how the remaining heap might be fragmented). */\r
124         taskDISABLE_INTERRUPTS();\r
125         for( ;; );\r
126 }\r
127 /*-----------------------------------------------------------*/\r
128 \r
129 void vApplicationIdleHook( void )\r
130 {\r
131         /* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set\r
132         to 1 in FreeRTOSConfig.h.  It will be called on each iteration of the idle\r
133         task.  It is essential that code added to this hook function never attempts\r
134         to block in any way (for example, call xQueueReceive() with a block time\r
135         specified, or call vTaskDelay()).  If the application makes use of the\r
136         vTaskDelete() API function (as this demo application does) then it is also\r
137         important that vApplicationIdleHook() is permitted to return to its calling\r
138         function, because it is the responsibility of the idle task to clean up\r
139         memory allocated by the kernel to any task that has since been deleted. */\r
140 }\r
141 /*-----------------------------------------------------------*/\r
142 \r
143 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )\r
144 {\r
145         ( void ) pcTaskName;\r
146         ( void ) pxTask;\r
147 \r
148         /* Run time stack overflow checking is performed if\r
149         configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2.  This hook\r
150         function is called if a stack overflow is detected. */\r
151         taskDISABLE_INTERRUPTS();\r
152         for( ;; );\r
153 }\r
154 /*-----------------------------------------------------------*/\r
155 \r
156 void vApplicationTickHook( void )\r
157 {\r
158         /* This function will be called by each tick interrupt if\r
159         configUSE_TICK_HOOK is set to 1 in FreeRTOSConfig.h.  User code can be\r
160         added here, but the tick hook is called from an interrupt context, so\r
161         code must not attempt to block, and only the interrupt safe FreeRTOS API\r
162         functions can be used (those that end in FromISR()).  The code in this\r
163         tick hook implementation is for demonstration only - it has no real\r
164         purpose.  It just gives a semaphore every 50ms.  The semaphore unblocks a\r
165         task that then toggles an LED.  Additionally, the call to\r
166         vQueueSetAccessQueueSetFromISR() is part of the "standard demo tasks"\r
167         functionality. */\r
168 \r
169         /* The semaphore and associated task are not created when the simple blinky\r
170         demo is used. */\r
171         #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 0\r
172         {\r
173         static unsigned long ulLastGiveTime = 0UL;\r
174         const unsigned long ulRate = 50UL / portTICK_PERIOD_MS;\r
175         extern SemaphoreHandle_t xLEDSemaphore;\r
176 \r
177                 configASSERT( xLEDSemaphore );\r
178 \r
179                 if( ( xTaskGetTickCountFromISR() - ulLastGiveTime ) > ulRate )\r
180                 {\r
181                         /* The second parameter is normally used to determine if a context\r
182                         switch should be performed or not.  In this case the function is\r
183                         being performed from the tick hook, so the scheduler will make that\r
184                         assessment before returning to a task anyway - so the parameter is\r
185                         not needed and is just set to NULL. */\r
186                         xSemaphoreGiveFromISR( xLEDSemaphore, NULL );\r
187                         ulLastGiveTime += ulRate;\r
188                 }\r
189 \r
190                 /* Write to a queue that is in use as part of the queue set demo to\r
191                 demonstrate using queue sets from an ISR. */\r
192                 vQueueSetAccessQueueSetFromISR();\r
193         }\r
194         #endif /* mainCREATE_SIMPLE_BLINKY_DEMO_ONLY */\r
195 }\r
196 /*-----------------------------------------------------------*/\r
197 \r
198 #ifdef JUST_AN_EXAMPLE_ISR\r
199 \r
200 void Dummy_IRQHandler(void)\r
201 {\r
202 long lHigherPriorityTaskWoken = pdFALSE;\r
203 \r
204         /* Clear the interrupt if necessary. */\r
205         Dummy_ClearITPendingBit();\r
206 \r
207         /* This interrupt does nothing more than demonstrate how to synchronise a\r
208         task with an interrupt.  A semaphore is used for this purpose.  Note\r
209         lHigherPriorityTaskWoken is initialised to zero. Only FreeRTOS API functions\r
210         that end in "FromISR" can be called from an ISR. */\r
211         xSemaphoreGiveFromISR( xTestSemaphore, &lHigherPriorityTaskWoken );\r
212 \r
213         /* If there was a task that was blocked on the semaphore, and giving the\r
214         semaphore caused the task to unblock, and the unblocked task has a priority\r
215         higher than the current Running state task (the task that this interrupt\r
216         interrupted), then lHigherPriorityTaskWoken will have been set to pdTRUE\r
217         internally within xSemaphoreGiveFromISR().  Passing pdTRUE into the\r
218         portEND_SWITCHING_ISR() macro will result in a context switch being pended to\r
219         ensure this interrupt returns directly to the unblocked, higher priority,\r
220         task.  Passing pdFALSE into portEND_SWITCHING_ISR() has no effect. */\r
221         portEND_SWITCHING_ISR( lHigherPriorityTaskWoken );\r
222 }\r
223 \r
224 #endif /* JUST_AN_EXAMPLE_ISR */\r
225 \r
226 \r
227 \r
228 \r