]> begriffs open source - freertos/blob - Demo/CORTEX_M4F_Infineon_XMC4500_IAR/main.c
Starting point for XMC4500 IAR demo application.
[freertos] / Demo / CORTEX_M4F_Infineon_XMC4500_IAR / main.c
1 /*\r
2     FreeRTOS V7.1.0 - Copyright (C) 2011 Real Time Engineers Ltd.\r
3 \r
4 \r
5     ***************************************************************************\r
6      *                                                                       *\r
7      *    FreeRTOS tutorial books are available in pdf and paperback.        *\r
8      *    Complete, revised, and edited pdf reference manuals are also       *\r
9      *    available.                                                         *\r
10      *                                                                       *\r
11      *    Purchasing FreeRTOS documentation will not only help you, by       *\r
12      *    ensuring you get running as quickly as possible and with an        *\r
13      *    in-depth knowledge of how to use FreeRTOS, it will also help       *\r
14      *    the FreeRTOS project to continue with its mission of providing     *\r
15      *    professional grade, cross platform, de facto standard solutions    *\r
16      *    for microcontrollers - completely free of charge!                  *\r
17      *                                                                       *\r
18      *    >>> See http://www.FreeRTOS.org/Documentation for details. <<<     *\r
19      *                                                                       *\r
20      *    Thank you for using FreeRTOS, and thank you for your support!      *\r
21      *                                                                       *\r
22     ***************************************************************************\r
23 \r
24 \r
25     This file is part of the FreeRTOS distribution.\r
26 \r
27     FreeRTOS is free software; you can redistribute it and/or modify it under\r
28     the terms of the GNU General Public License (version 2) as published by the\r
29     Free Software Foundation AND MODIFIED BY the FreeRTOS exception.\r
30     >>>NOTE<<< The modification to the GPL is included to allow you to\r
31     distribute a combined work that includes FreeRTOS without being obliged to\r
32     provide the source code for proprietary components outside of the FreeRTOS\r
33     kernel.  FreeRTOS is distributed in the hope that it will be useful, but\r
34     WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
35     or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for\r
36     more details. You should have received a copy of the GNU General Public\r
37     License and the FreeRTOS license exception along with FreeRTOS; if not it\r
38     can be viewed here: http://www.freertos.org/a00114.html and also obtained\r
39     by writing to Richard Barry, contact details for whom are available on the\r
40     FreeRTOS WEB site.\r
41 \r
42     1 tab == 4 spaces!\r
43 \r
44     http://www.FreeRTOS.org - Documentation, latest information, license and\r
45     contact details.\r
46 \r
47     http://www.SafeRTOS.com - A version that is certified for use in safety\r
48     critical systems.\r
49 \r
50     http://www.OpenRTOS.com - Commercial support, development, porting,\r
51     licensing and training services.\r
52 */\r
53 \r
54 /******************************************************************************\r
55  * This project provides two demo applications.  A simple blinky style project,\r
56  * and a more comprehensive test and demo application.  The\r
57  * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting (defined in this file) is used to\r
58  * select between the two.  The simply blinky demo is implemented and described\r
59  * in main_blinky.c.  The more comprehensive test and demo application is\r
60  * implemented and described in main_full.c.\r
61  *\r
62  * This file implements the code that is not demo specific, including the\r
63  * hardware setup and FreeRTOS hook functions.\r
64  *\r
65  *\r
66  * Additional code:\r
67  *\r
68  * This demo does not contain a non-kernel interrupt service routine that\r
69  * can be used as an example for application writers to use as a reference.\r
70  * Therefore, the framework of a dummy (not installed) handler is provided\r
71  * in this file.  The dummy function is called Dummy_IRQHandler().  Please\r
72  * ensure to read the comments in the function itself, but more importantly,\r
73  * the notes on the function contained on the documentation page for this demo\r
74  * that is found on the FreeRTOS.org web site.\r
75  */\r
76 \r
77 /* Standard includes. */\r
78 #include <stdio.h>\r
79 \r
80 /* Kernel includes. */\r
81 #include "FreeRTOS.h"\r
82 #include "task.h"\r
83 \r
84 /* Hardware includes. */\r
85 #include "XMC4500.h"\r
86 #include "System_XMC4500.h"\r
87 \r
88 /* Set mainCREATE_SIMPLE_BLINKY_DEMO_ONLY to one to run the simple blinky demo,\r
89 or 0 to run the more comprehensive test and demo application. */\r
90 #define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY      0\r
91 \r
92 /*-----------------------------------------------------------*/\r
93 \r
94 /*\r
95  * Set up the hardware ready to run this demo.\r
96  */\r
97 static void prvSetupHardware( void );\r
98 \r
99 /*\r
100  * main_blinky() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1.\r
101  * main_full() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 0.\r
102  */\r
103 extern void main_blinky( void );\r
104 extern void main_full( void );\r
105 \r
106 /*-----------------------------------------------------------*/\r
107 \r
108 int main( void )\r
109 {\r
110         /* Prepare the hardware to run this demo. */\r
111         prvSetupHardware();\r
112 \r
113         /* The mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is described at the top\r
114         of this file. */\r
115         #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1\r
116         {\r
117                 main_blinky();\r
118         }\r
119         #else\r
120         {\r
121                 main_full();\r
122         }\r
123         #endif\r
124 \r
125         return 0;\r
126 }\r
127 /*-----------------------------------------------------------*/\r
128 \r
129 static void prvSetupHardware( void )\r
130 {\r
131 extern void SystemCoreClockUpdate( void );\r
132 \r
133         /* Ensure SystemCoreClock variable is set. */\r
134         SystemCoreClockUpdate();\r
135 \r
136         /* Configure pin P3.9 for the LED. */\r
137         PORT3->IOCR8 = 0x00008000;\r
138 \r
139         /* Ensure all priority bits are assigned as preemption priority bits. */\r
140         NVIC_SetPriorityGrouping( 0 );\r
141 }\r
142 /*-----------------------------------------------------------*/\r
143 \r
144 void vApplicationMallocFailedHook( void )\r
145 {\r
146         /* vApplicationMallocFailedHook() will only be called if\r
147         configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h.  It is a hook\r
148         function that will get called if a call to pvPortMalloc() fails.\r
149         pvPortMalloc() is called internally by the kernel whenever a task, queue,\r
150         timer or semaphore is created.  It is also called by various parts of the\r
151         demo application.  If heap_1.c or heap_2.c are used, then the size of the\r
152         heap available to pvPortMalloc() is defined by configTOTAL_HEAP_SIZE in\r
153         FreeRTOSConfig.h, and the xPortGetFreeHeapSize() API function can be used\r
154         to query the size of free heap space that remains (although it does not\r
155         provide information on how the remaining heap might be fragmented). */\r
156         taskDISABLE_INTERRUPTS();\r
157         for( ;; );\r
158 }\r
159 /*-----------------------------------------------------------*/\r
160 \r
161 void vApplicationIdleHook( void )\r
162 {\r
163         /* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set\r
164         to 1 in FreeRTOSConfig.h.  It will be called on each iteration of the idle\r
165         task.  It is essential that code added to this hook function never attempts\r
166         to block in any way (for example, call xQueueReceive() with a block time\r
167         specified, or call vTaskDelay()).  If the application makes use of the\r
168         vTaskDelete() API function (as this demo application does) then it is also\r
169         important that vApplicationIdleHook() is permitted to return to its calling\r
170         function, because it is the responsibility of the idle task to clean up\r
171         memory allocated by the kernel to any task that has since been deleted. */\r
172 }\r
173 /*-----------------------------------------------------------*/\r
174 \r
175 void vApplicationStackOverflowHook( xTaskHandle pxTask, signed char *pcTaskName )\r
176 {\r
177         ( void ) pcTaskName;\r
178         ( void ) pxTask;\r
179 \r
180         /* Run time stack overflow checking is performed if\r
181         configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2.  This hook\r
182         function is called if a stack overflow is detected. */\r
183         taskDISABLE_INTERRUPTS();\r
184         for( ;; );\r
185 }\r
186 /*-----------------------------------------------------------*/\r
187 \r
188 void vApplicationTickHook( void )\r
189 {\r
190         /* This function will be called by each tick interrupt if\r
191         configUSE_TICK_HOOK is set to 1 in FreeRTOSConfig.h.  User code can be\r
192         added here, but the tick hook is called from an interrupt context, so\r
193         code must not attempt to block, and only the interrupt safe FreeRTOS API\r
194         functions can be used (those that end in FromISR()). */\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. */\r
210         xSemaphoreGiveFromISR( xTestSemaphore, &lHigherPriorityTaskWoken );\r
211         \r
212         /* If there was a task that was blocked on the semaphore, and giving the\r
213         semaphore caused the task to unblock, and the unblocked task has a priority\r
214         higher than the current Running state task (the task that this interrupt\r
215         interrupted), then lHigherPriorityTaskWoken will have been set to pdTRUE\r
216         internally within xSemaphoreGiveFromISR().  Passing pdTRUE into the\r
217         portEND_SWITCHING_ISR() macro will result in a context switch being pended to\r
218         ensure this interrupt returns directly to the unblocked, higher priority,\r
219         task.  Passing pdFALSE into portEND_SWITCHING_ISR() has no effect. */\r
220         portEND_SWITCHING_ISR( lHigherPriorityTaskWoken );\r
221 }\r
222 \r
223 #endif /* JUST_AN_EXAMPLE_ISR */\r