]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_M4F_Infineon_XMC4000_IAR/main.c
Update to MIT licensed FreeRTOS V10.0.0 - see https://www.freertos.org/History.txt
[freertos] / FreeRTOS / Demo / CORTEX_M4F_Infineon_XMC4000_IAR / main.c
1 /*\r
2  * FreeRTOS Kernel V10.0.0\r
3  * Copyright (C) 2017 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. 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
15  *\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
22  *\r
23  * http://www.FreeRTOS.org\r
24  * http://aws.amazon.com/freertos\r
25  *\r
26  * 1 tab == 4 spaces!\r
27  */\r
28 \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
36  *\r
37  * This file implements the code that is not demo specific, including the\r
38  * hardware setup and FreeRTOS hook functions.\r
39  *\r
40  *\r
41  * Additional code:\r
42  *\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
50  */\r
51 \r
52 /* Standard includes. */\r
53 #include <stdio.h>\r
54 \r
55 /* Kernel includes. */\r
56 #include "FreeRTOS.h"\r
57 #include "task.h"\r
58 \r
59 /* Standard demo includes. */\r
60 #include "QueueSet.h"\r
61 #include "QueueOverwrite.h"\r
62 \r
63 /* Set mainCREATE_SIMPLE_BLINKY_DEMO_ONLY to one to run the simple blinky demo,\r
64 or 0 to run the more comprehensive test and demo application. */\r
65 #define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY      0\r
66 \r
67 /*-----------------------------------------------------------*/\r
68 \r
69 /*\r
70  * Set up the hardware ready to run this demo.\r
71  */\r
72 static void prvSetupHardware( void );\r
73 \r
74 /*\r
75  * main_blinky() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1.\r
76  * main_full() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 0.\r
77  */\r
78 extern void main_blinky( void );\r
79 extern void main_full( void );\r
80 \r
81 /*-----------------------------------------------------------*/\r
82 \r
83 int main( void )\r
84 {\r
85         /* Prepare the hardware to run this demo. */\r
86         prvSetupHardware();\r
87 \r
88         /* The mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is described at the top\r
89         of this file. */\r
90         #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1\r
91         {\r
92                 main_blinky();\r
93         }\r
94         #else\r
95         {\r
96                 main_full();\r
97         }\r
98         #endif\r
99 \r
100         return 0;\r
101 }\r
102 /*-----------------------------------------------------------*/\r
103 \r
104 static void prvSetupHardware( void )\r
105 {\r
106         configCONFIGURE_LED();\r
107 \r
108         /* Ensure all priority bits are assigned as preemption priority bits. */\r
109         NVIC_SetPriorityGrouping( 0 );\r
110 }\r
111 /*-----------------------------------------------------------*/\r
112 \r
113 void vApplicationMallocFailedHook( void )\r
114 {\r
115         /* vApplicationMallocFailedHook() will only be called if\r
116         configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h.  It is a hook\r
117         function that will get called if a call to pvPortMalloc() fails.\r
118         pvPortMalloc() is called internally by the kernel whenever a task, queue,\r
119         timer or semaphore is created.  It is also called by various parts of the\r
120         demo application.  If heap_1.c or heap_2.c are used, then the size of the\r
121         heap available to pvPortMalloc() is defined by configTOTAL_HEAP_SIZE in\r
122         FreeRTOSConfig.h, and the xPortGetFreeHeapSize() API function can be used\r
123         to query the size of free heap space that remains (although it does not\r
124         provide information on how the remaining heap might be fragmented). */\r
125         taskDISABLE_INTERRUPTS();\r
126         for( ;; );\r
127 }\r
128 /*-----------------------------------------------------------*/\r
129 \r
130 void vApplicationIdleHook( void )\r
131 {\r
132         /* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set\r
133         to 1 in FreeRTOSConfig.h.  It will be called on each iteration of the idle\r
134         task.  It is essential that code added to this hook function never attempts\r
135         to block in any way (for example, call xQueueReceive() with a block time\r
136         specified, or call vTaskDelay()).  If the application makes use of the\r
137         vTaskDelete() API function (as this demo application does) then it is also\r
138         important that vApplicationIdleHook() is permitted to return to its calling\r
139         function, because it is the responsibility of the idle task to clean up\r
140         memory allocated by the kernel to any task that has since been deleted. */\r
141 }\r
142 /*-----------------------------------------------------------*/\r
143 \r
144 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )\r
145 {\r
146         ( void ) pcTaskName;\r
147         ( void ) pxTask;\r
148 \r
149         /* Run time stack overflow checking is performed if\r
150         configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2.  This hook\r
151         function is called if a stack overflow is detected. */\r
152         taskDISABLE_INTERRUPTS();\r
153         for( ;; );\r
154 }\r
155 /*-----------------------------------------------------------*/\r
156 \r
157 void vApplicationTickHook( void )\r
158 {\r
159         /* This function will be called by each tick interrupt if\r
160         configUSE_TICK_HOOK is set to 1 in FreeRTOSConfig.h.  User code can be\r
161         added here, but the tick hook is called from an interrupt context, so\r
162         code must not attempt to block, and only the interrupt safe FreeRTOS API\r
163         functions can be used (those that end in FromISR()). */\r
164 \r
165         #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 0\r
166         {\r
167                 /* Write to a queue that is in use as part of the queue set demo to\r
168                 demonstrate using queue sets from an ISR. */\r
169                 vQueueSetAccessQueueSetFromISR();\r
170 \r
171                 /* Test the ISR safe queue overwrite functions. */\r
172                 vQueueOverwritePeriodicISRDemo();\r
173         }\r
174         #endif /* mainCREATE_SIMPLE_BLINKY_DEMO_ONLY */\r
175 }\r
176 /*-----------------------------------------------------------*/\r
177 \r
178 #ifdef JUST_AN_EXAMPLE_ISR\r
179 \r
180 void Dummy_IRQHandler(void)\r
181 {\r
182 long lHigherPriorityTaskWoken = pdFALSE;\r
183 \r
184         /* Clear the interrupt if necessary. */\r
185         Dummy_ClearITPendingBit();\r
186 \r
187         /* This interrupt does nothing more than demonstrate how to synchronise a\r
188         task with an interrupt.  A semaphore is used for this purpose.  Note\r
189         lHigherPriorityTaskWoken is initialised to zero. */\r
190         xSemaphoreGiveFromISR( xTestSemaphore, &lHigherPriorityTaskWoken );\r
191 \r
192         /* If there was a task that was blocked on the semaphore, and giving the\r
193         semaphore caused the task to unblock, and the unblocked task has a priority\r
194         higher than the current Running state task (the task that this interrupt\r
195         interrupted), then lHigherPriorityTaskWoken will have been set to pdTRUE\r
196         internally within xSemaphoreGiveFromISR().  Passing pdTRUE into the\r
197         portEND_SWITCHING_ISR() macro will result in a context switch being pended to\r
198         ensure this interrupt returns directly to the unblocked, higher priority,\r
199         task.  Passing pdFALSE into portEND_SWITCHING_ISR() has no effect. */\r
200         portEND_SWITCHING_ISR( lHigherPriorityTaskWoken );\r
201 }\r
202 \r
203 #endif /* JUST_AN_EXAMPLE_ISR */\r