]> begriffs open source - cmsis-freertos/blob - Demo/CORTEX_M4F_Infineon_XMC4000_Keil/main.c
Initial commit
[cmsis-freertos] / Demo / CORTEX_M4F_Infineon_XMC4000_Keil / main.c
1 /*
2     FreeRTOS V9.0.0 - Copyright (C) 2016 Real Time Engineers Ltd.
3     All rights reserved
4
5     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
6
7     This file is part of the FreeRTOS distribution.
8
9     FreeRTOS is free software; you can redistribute it and/or modify it under
10     the terms of the GNU General Public License (version 2) as published by the
11     Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.
12
13     ***************************************************************************
14     >>!   NOTE: The modification to the GPL is included to allow you to     !<<
15     >>!   distribute a combined work that includes FreeRTOS without being   !<<
16     >>!   obliged to provide the source code for proprietary components     !<<
17     >>!   outside of the FreeRTOS kernel.                                   !<<
18     ***************************************************************************
19
20     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
21     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
22     FOR A PARTICULAR PURPOSE.  Full license text is available on the following
23     link: http://www.freertos.org/a00114.html
24
25     ***************************************************************************
26      *                                                                       *
27      *    FreeRTOS provides completely free yet professionally developed,    *
28      *    robust, strictly quality controlled, supported, and cross          *
29      *    platform software that is more than just the market leader, it     *
30      *    is the industry's de facto standard.                               *
31      *                                                                       *
32      *    Help yourself get started quickly while simultaneously helping     *
33      *    to support the FreeRTOS project by purchasing a FreeRTOS           *
34      *    tutorial book, reference manual, or both:                          *
35      *    http://www.FreeRTOS.org/Documentation                              *
36      *                                                                       *
37     ***************************************************************************
38
39     http://www.FreeRTOS.org/FAQHelp.html - Having a problem?  Start by reading
40     the FAQ page "My application does not run, what could be wrong?".  Have you
41     defined configASSERT()?
42
43     http://www.FreeRTOS.org/support - In return for receiving this top quality
44     embedded software for free we request you assist our global community by
45     participating in the support forum.
46
47     http://www.FreeRTOS.org/training - Investing in training allows your team to
48     be as productive as possible as early as possible.  Now you can receive
49     FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
50     Ltd, and the world's leading authority on the world's leading RTOS.
51
52     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
53     including FreeRTOS+Trace - an indispensable productivity tool, a DOS
54     compatible FAT file system, and our tiny thread aware UDP/IP stack.
55
56     http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
57     Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
58
59     http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
60     Integrity Systems ltd. to sell under the OpenRTOS brand.  Low cost OpenRTOS
61     licenses offer ticketed support, indemnification and commercial middleware.
62
63     http://www.SafeRTOS.com - High Integrity Systems also provide a safety
64     engineered and independently SIL3 certified version for use in safety and
65     mission critical applications that require provable dependability.
66
67     1 tab == 4 spaces!
68 */
69
70 /******************************************************************************
71  * This project provides two demo applications.  A simple blinky style project,
72  * and a more comprehensive test and demo application.  The
73  * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting (defined in this file) is used to
74  * select between the two.  The simply blinky demo is implemented and described
75  * in main_blinky.c.  The more comprehensive test and demo application is
76  * implemented and described in main_full.c.
77  *
78  * This file implements the code that is not demo specific, including the
79  * hardware setup and FreeRTOS hook functions.
80  *
81  * 
82  * Additional code:
83  * 
84  * This demo does not contain a non-kernel interrupt service routine that
85  * can be used as an example for application writers to use as a reference.
86  * Therefore, the framework of a dummy (not installed) handler is provided
87  * in this file.  The dummy function is called Dummy_IRQHandler().  Please
88  * ensure to read the comments in the function itself, but more importantly,
89  * the notes on the function contained on the documentation page for this demo
90  * that is found on the FreeRTOS.org web site.
91  */
92
93 /* Standard includes. */
94 #include <stdio.h>
95
96 /* Kernel includes. */
97 #include "FreeRTOS.h"
98 #include "task.h"
99
100 /* Set mainCREATE_SIMPLE_BLINKY_DEMO_ONLY to one to run the simple blinky demo,
101 or 0 to run the more comprehensive test and demo application. */
102 #define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY      1
103
104 /*-----------------------------------------------------------*/
105
106 /*
107  * Set up the hardware ready to run this demo.
108  */
109 static void prvSetupHardware( void );
110
111 /* 
112  * main_blinky() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1.
113  * main_full() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 0. 
114  */
115 extern void main_blinky( void );
116 extern void main_full( void );
117
118 /*-----------------------------------------------------------*/
119
120 int main( void )
121 {
122         /* Prepare the hardware to run this demo. */
123         prvSetupHardware();
124
125         /* The mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is described at the top
126         of this file. */
127         #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1
128         {
129                 main_blinky();
130         }
131         #else
132         {
133                 main_full();
134         }
135         #endif
136
137         return 0;
138 }
139 /*-----------------------------------------------------------*/
140
141 static void prvSetupHardware( void )
142 {
143         configCONFIGURE_LED();
144         
145         /* Ensure all priority bits are assigned as preemption priority bits. */
146         NVIC_SetPriorityGrouping( 0 );
147 }
148 /*-----------------------------------------------------------*/
149
150 void vApplicationMallocFailedHook( void )
151 {
152         /* vApplicationMallocFailedHook() will only be called if
153         configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h.  It is a hook
154         function that will get called if a call to pvPortMalloc() fails.
155         pvPortMalloc() is called internally by the kernel whenever a task, queue,
156         timer or semaphore is created.  It is also called by various parts of the
157         demo application.  If heap_1.c or heap_2.c are used, then the size of the
158         heap available to pvPortMalloc() is defined by configTOTAL_HEAP_SIZE in
159         FreeRTOSConfig.h, and the xPortGetFreeHeapSize() API function can be used
160         to query the size of free heap space that remains (although it does not
161         provide information on how the remaining heap might be fragmented). */
162         taskDISABLE_INTERRUPTS();
163         for( ;; );
164 }
165 /*-----------------------------------------------------------*/
166
167 void vApplicationIdleHook( void )
168 {
169         /* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set
170         to 1 in FreeRTOSConfig.h.  It will be called on each iteration of the idle
171         task.  It is essential that code added to this hook function never attempts
172         to block in any way (for example, call xQueueReceive() with a block time
173         specified, or call vTaskDelay()).  If the application makes use of the
174         vTaskDelete() API function (as this demo application does) then it is also
175         important that vApplicationIdleHook() is permitted to return to its calling
176         function, because it is the responsibility of the idle task to clean up
177         memory allocated by the kernel to any task that has since been deleted. */
178 }
179 /*-----------------------------------------------------------*/
180
181 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
182 {
183         ( void ) pcTaskName;
184         ( void ) pxTask;
185
186         /* Run time stack overflow checking is performed if
187         configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2.  This hook
188         function is called if a stack overflow is detected. */
189         taskDISABLE_INTERRUPTS();
190         for( ;; );
191 }
192 /*-----------------------------------------------------------*/
193
194 void vApplicationTickHook( void )
195 {
196         /* This function will be called by each tick interrupt if 
197         configUSE_TICK_HOOK is set to 1 in FreeRTOSConfig.h.  User code can be
198         added here, but the tick hook is called from an interrupt context, so
199         code must not attempt to block, and only the interrupt safe FreeRTOS API
200         functions can be used (those that end in FromISR()). */
201 }
202 /*-----------------------------------------------------------*/
203
204 #ifdef JUST_AN_EXAMPLE_ISR
205
206 void Dummy_IRQHandler(void)
207 {
208 long lHigherPriorityTaskWoken = pdFALSE;
209
210         /* Clear the interrupt if necessary. */
211         Dummy_ClearITPendingBit();
212         
213         /* This interrupt does nothing more than demonstrate how to synchronise a
214         task with an interrupt.  A semaphore is used for this purpose.  Note
215         lHigherPriorityTaskWoken is initialised to zero. */
216         xSemaphoreGiveFromISR( xTestSemaphore, &lHigherPriorityTaskWoken );
217         
218         /* If there was a task that was blocked on the semaphore, and giving the
219         semaphore caused the task to unblock, and the unblocked task has a priority
220         higher than the current Running state task (the task that this interrupt
221         interrupted), then lHigherPriorityTaskWoken will have been set to pdTRUE
222         internally within xSemaphoreGiveFromISR().  Passing pdTRUE into the 
223         portEND_SWITCHING_ISR() macro will result in a context switch being pended to
224         ensure this interrupt returns directly to the unblocked, higher priority, 
225         task.  Passing pdFALSE into portEND_SWITCHING_ISR() has no effect. */
226         portEND_SWITCHING_ISR( lHigherPriorityTaskWoken );
227 }
228
229 #endif /* JUST_AN_EXAMPLE_ISR */