]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/Tensilica_Simulator_Xplorer_XCC/main.c
5b5ca3b59be002f85c69d755689e36b19f47d444
[freertos] / FreeRTOS / Demo / Tensilica_Simulator_Xplorer_XCC / main.c
1 /*
2  * FreeRTOS Kernel V10.0.1
3  * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of
6  * this software and associated documentation files (the "Software"), to deal in
7  * the Software without restriction, including without limitation the rights to
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9  * the Software, and to permit persons to whom the Software is furnished to do so,
10  * subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in all
13  * copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  *
22  * http://www.FreeRTOS.org
23  * http://aws.amazon.com/freertos
24  *
25  * 1 tab == 4 spaces!
26  */
27
28 /******************************************************************************
29  * This project provides two demo applications.  A simple blinky style project,
30  * and a more comprehensive test and demo application.  The
31  * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is used to select between the two.
32  * The simply blinky demo is implemented and described in main_blinky.c.  The
33  * more comprehensive test and demo application is implemented and described in
34  * main_full.c.
35  *
36  * This file implements the code that is not demo specific, including the
37  * hardware setup and FreeRTOS hook functions.
38  *
39  *******************************************************************************
40  */
41
42 /* Standard includes. */
43 #include <stdio.h>
44 #include <stdlib.h>
45
46 /* FreeRTOS kernel includes. */
47 #include "FreeRTOS.h"
48 #include "task.h"
49
50 /* This project provides two demo applications.  A simple blinky style demo
51 application, and a more comprehensive test and demo application.  The
52 mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is used to select between the two.
53
54 If mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is 1 then the blinky demo will be built.
55 The blinky demo is implemented and described in main_blinky.c.
56
57 If mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is not 1 then the comprehensive test and
58 demo application will be built.  The comprehensive test and demo application is
59 implemented and described in main_full.c. */
60 #define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY      0
61
62 /*-----------------------------------------------------------*/
63
64 /*
65  * main_blinky() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1.
66  * main_full() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 0.
67  */
68 extern void main_blinky( void );
69 extern void main_full( void );
70
71 /*
72  * Prototypes for the standard FreeRTOS application hook (callback) functions
73  * implemented within this file.  See http://www.freertos.org/a00016.html .
74  */
75 void vApplicationMallocFailedHook( void );
76 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );
77 void vApplicationTickHook( void );
78
79 /*
80  * Only the comprehensive demo uses application hook (callback) functions.  See
81  * http://www.freertos.org/a00016.html for more information.
82  */
83 void vFullDemoTickHookFunction( void );
84
85
86 /*-----------------------------------------------------------*/
87
88 int main( void )
89 {
90         /* The mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is described at the top
91         of this file. */
92         #if ( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 )
93         {
94                 main_blinky();
95         }
96         #else
97         {
98                 main_full();
99         }
100         #endif
101
102         return 0;
103 }
104 /*-----------------------------------------------------------*/
105
106 void vApplicationMallocFailedHook( void )
107 {
108         /* vApplicationMallocFailedHook() will only be called if
109         configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h.  It is a hook
110         function that will get called if a call to pvPortMalloc() fails.
111         pvPortMalloc() is called internally by the kernel whenever a task, queue,
112         timer or semaphore is created.  It is also called by various parts of the
113         demo application.  If heap_1.c, heap_2.c or heap_4.c is being used, then the
114         size of the     heap available to pvPortMalloc() is defined by
115         configTOTAL_HEAP_SIZE in FreeRTOSConfig.h, and the xPortGetFreeHeapSize()
116         API function can be used to query the size of free heap space that remains
117         (although it does not provide information on how the remaining heap might be
118         fragmented).  See http://www.freertos.org/a00111.html for more
119         information. */
120         vAssertCalled( __LINE__, __FILE__ );
121 }
122 /*-----------------------------------------------------------*/
123
124 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
125 {
126         ( void ) pcTaskName;
127         ( void ) pxTask;
128
129         /* Run time stack overflow checking is performed if
130         configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2.  This hook
131         function is called if a stack overflow is detected.  This function is
132         provided as an example only as stack overflow checking does not function
133         when running the FreeRTOS Windows port. */
134         vAssertCalled( __LINE__, __FILE__ );
135 }
136 /*-----------------------------------------------------------*/
137
138 void vApplicationTickHook( void )
139 {
140         /* This function will be called by each tick interrupt if
141         configUSE_TICK_HOOK is set to 1 in FreeRTOSConfig.h.  User code can be
142         added here, but the tick hook is called from an interrupt context, so
143         code must not attempt to block, and only the interrupt safe FreeRTOS API
144         functions can be used (those that end in FromISR()). */
145
146         #if ( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY != 1 )
147         {
148                 vFullDemoTickHookFunction();
149         }
150         #endif /* mainCREATE_SIMPLE_BLINKY_DEMO_ONLY */
151 }
152 /*-----------------------------------------------------------*/
153
154 void vAssertCalled( unsigned long ulLine, const char * const pcFileName )
155 {
156 static BaseType_t xPrinted = pdFALSE;
157 volatile uint32_t ulSetToNonZeroInDebuggerToContinue = 0;
158
159         /* Called if an assertion passed to configASSERT() fails.  See
160         http://www.freertos.org/a00110.html#configASSERT for more information. */
161
162         /* Parameters are not used. */
163         ( void ) ulLine;
164         ( void ) pcFileName;
165
166         printf( "ASSERT! Line %ld, file %s\r\n", ulLine, pcFileName );
167
168         taskENTER_CRITICAL();
169         {
170                 /* You can step out of this function to debug the assertion by using
171                 the debugger to set ulSetToNonZeroInDebuggerToContinue to a non-zero
172                 value. */
173                 while( ulSetToNonZeroInDebuggerToContinue == 0 )
174                 {
175                         __asm volatile( "NOP" );
176                         __asm volatile( "NOP" );
177                 }
178         }
179         taskEXIT_CRITICAL();
180 }
181 /*-----------------------------------------------------------*/