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