]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/Tensilica_Simulator_Xplorer_XCC/main.c
8a80cbaab971e8f6d7e6236277c79a5b30ff1075
[freertos] / FreeRTOS / Demo / Tensilica_Simulator_Xplorer_XCC / main.c
1 /*\r
2  * FreeRTOS Kernel V10.2.0\r
3  * Copyright (C) 2019 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:\r
30  * - A simple blinky style demo application.\r
31  * - A more comprehensive test and demo application.\r
32  * The mainCREATE_SIMPLE_BLINKY_DEMO_ONLY macro is used to select between the two.\r
33  *\r
34  * The simply blinky demo is implemented and described in the file main_blinky.c.\r
35  * The more comprehensive test and demo application is implemented and described\r
36  * in the file main_full.c.\r
37  *\r
38  * This file implements the code that is not demo specific, including the FreeRTOS\r
39  * hook functions.\r
40  *\r
41  *******************************************************************************\r
42  */\r
43 \r
44 /* Standard includes. */\r
45 #include <stdio.h>\r
46 #include <stdlib.h>\r
47 \r
48 /* FreeRTOS kernel includes. */\r
49 #include "FreeRTOS.h"\r
50 #include "task.h"\r
51 \r
52 /**\r
53  * This project provides two demo applications:\r
54  * - A simple blinky style demo application.\r
55  * - A more comprehensive test and demo application.\r
56  * The mainCREATE_SIMPLE_BLINKY_DEMO_ONLY macro is used to select between the two.\r
57  *\r
58  * If mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1 then the blinky demo will be\r
59  * built. The blinky demo is implemented and described in main_blinky.c.\r
60  *\r
61  * If mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 0 then the comprehensive test\r
62  * and demo application will be built. The comprehensive test and demo application\r
63  * is implemented and described in main_full.c.\r
64  */\r
65 #define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY      0\r
66 /*-----------------------------------------------------------*/\r
67 \r
68 /**\r
69  * The entry function for the blinky demo application.\r
70  *\r
71  * This is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1.\r
72  */\r
73 extern void main_blinky( void );\r
74 \r
75 /**\r
76  * The entry function for the comprehensive test and demo application.\r
77  *\r
78  * This is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 0.\r
79  */\r
80 extern void main_full( void );\r
81 \r
82 /**\r
83  * Prototypes for the standard FreeRTOS application hook (callback) functions\r
84  * implemented within this file.\r
85  *\r
86  * @see http://www.freertos.org/a00016.html\r
87  */\r
88 void vApplicationMallocFailedHook( void );\r
89 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );\r
90 void vApplicationTickHook( void );\r
91 \r
92 /**\r
93  * The function called from the tick hook.\r
94  *\r
95  * @note Only the comprehensive demo uses application hook (callback) functions.\r
96  *\r
97  * @see http://www.freertos.org/a00016.html\r
98  */\r
99 void vFullDemoTickHookFunction( void );\r
100 /*-----------------------------------------------------------*/\r
101 \r
102 int main( void )\r
103 {\r
104         /* The mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is described at the top\r
105          * of this file. */\r
106         #if ( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 )\r
107         {\r
108                 main_blinky();\r
109         }\r
110         #else\r
111         {\r
112                 main_full();\r
113         }\r
114         #endif\r
115 \r
116         return 0;\r
117 }\r
118 /*-----------------------------------------------------------*/\r
119 \r
120 void vApplicationMallocFailedHook( void )\r
121 {\r
122         /* vApplicationMallocFailedHook() will only be called if\r
123          * configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h. It is a hook\r
124          * function that will get called if a call to pvPortMalloc() fails.\r
125          * pvPortMalloc() is called internally by the kernel whenever a task, queue,\r
126          * timer or semaphore is created.  It is also called by various parts of the\r
127          * demo application.  If heap_1.c, heap_2.c or heap_4.c is being used, then\r
128          * the size of the      heap available to pvPortMalloc() is defined by\r
129          * configTOTAL_HEAP_SIZE in FreeRTOSConfig.h, and the xPortGetFreeHeapSize()\r
130          * API function can be used to query the size of free heap space that remains\r
131          * (although it does not provide information on how the remaining heap might be\r
132          * fragmented). See http://www.freertos.org/a00111.html for more information.\r
133          */\r
134         vAssertCalled( __LINE__, __FILE__ );\r
135 }\r
136 /*-----------------------------------------------------------*/\r
137 \r
138 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )\r
139 {\r
140         ( void ) pcTaskName;\r
141         ( void ) pxTask;\r
142 \r
143         /* Run time stack overflow checking is performed if\r
144          * configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2.  This hook\r
145          * function is called if a stack overflow is detected. */\r
146         vAssertCalled( __LINE__, __FILE__ );\r
147 }\r
148 /*-----------------------------------------------------------*/\r
149 \r
150 void vApplicationTickHook( void )\r
151 {\r
152         /* This function will be called by each tick interrupt if\r
153          * configUSE_TICK_HOOK is set to 1 in FreeRTOSConfig.h.  User code can be\r
154          * added here, but the tick hook is called from an interrupt context, so\r
155          * code must not attempt to block, and only the interrupt safe FreeRTOS API\r
156          * functions can be used (those that end in FromISR()). */\r
157         #if ( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY != 1 )\r
158         {\r
159                 vFullDemoTickHookFunction();\r
160         }\r
161         #endif /* mainCREATE_SIMPLE_BLINKY_DEMO_ONLY */\r
162 }\r
163 /*-----------------------------------------------------------*/\r
164 \r
165 void vAssertCalled( unsigned long ulLine, const char * const pcFileName )\r
166 {\r
167 static BaseType_t xPrinted = pdFALSE;\r
168 volatile uint32_t ulSetToNonZeroInDebuggerToContinue = 0;\r
169 \r
170         /* Called if an assertion passed to configASSERT() fails.  See\r
171          * http://www.freertos.org/a00110.html#configASSERT for more information. */\r
172 \r
173         /* Parameters are not used. */\r
174         ( void ) ulLine;\r
175         ( void ) pcFileName;\r
176 \r
177         taskENTER_CRITICAL();\r
178         {\r
179                 /* You can step out of this function to debug the assertion by using\r
180                  * the debugger to set ulSetToNonZeroInDebuggerToContinue to a non-zero\r
181                  * value. */\r
182                 while( ulSetToNonZeroInDebuggerToContinue == 0 )\r
183                 {\r
184                         __asm volatile( "NOP" );\r
185                         __asm volatile( "NOP" );\r
186                 }\r
187         }\r
188         taskEXIT_CRITICAL();\r
189 }\r
190 /*-----------------------------------------------------------*/\r