]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_R4F_RZ_T_GCC_IAR/src/main.c
Update to MIT licensed FreeRTOS V10.0.0 - see https://www.freertos.org/History.txt
[freertos] / FreeRTOS / Demo / CORTEX_R4F_RZ_T_GCC_IAR / src / 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, standard FreeRTOS hook functions, and the ISR hander called\r
39  * by the RTOS after interrupt entry (including nesting) has been taken care of.\r
40  *\r
41  * ENSURE TO READ THE DOCUMENTATION PAGE FOR THIS PORT AND DEMO APPLICATION ON\r
42  * THE http://www.FreeRTOS.org WEB SITE FOR FULL INFORMATION ON USING THIS DEMO\r
43  * APPLICATION, AND ITS ASSOCIATE FreeRTOS ARCHITECTURE PORT!\r
44  *\r
45  * http://www.freertos.org/Renesas_RZ-T_Cortex-R4F-RTOS.html\r
46  *\r
47  */\r
48 \r
49 /* Standard includes. */\r
50 #include "string.h"\r
51 \r
52 /* Scheduler include files. */\r
53 #include "FreeRTOS.h"\r
54 #include "task.h"\r
55 #include "semphr.h"\r
56 \r
57 /* Renesas includes. */\r
58 #include "r_cg_macrodriver.h"\r
59 #include "r_cg_icu.h"\r
60 #include "r_cg_rspi.h"\r
61 #include "r_system.h"\r
62 #include "r_reset.h"\r
63 #include "r_cg_userdefine.h"\r
64 \r
65 /* Set mainCREATE_SIMPLE_BLINKY_DEMO_ONLY to one to run the simple blinky demo,\r
66 or 0 to run the more comprehensive test and demo application. */\r
67 #define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY      0\r
68 \r
69 /*-----------------------------------------------------------*/\r
70 \r
71 /*\r
72  * The GCC start up code does not include a routine to clear the BSS segment to\r
73  * 0 (as would be normal before calling main()), so the BSS is cleared manually\r
74  * using the following function.\r
75  */\r
76 static void prvClearBSS( void );\r
77 \r
78 /*\r
79  * main_blinky() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1.\r
80  * main_full() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 0.\r
81  */\r
82 #if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 )\r
83         extern void main_blinky( void );\r
84 #else\r
85         extern void main_full( void );\r
86 #endif /* #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 */\r
87 \r
88 /* Prototypes for the standard FreeRTOS callback/hook functions implemented\r
89 within this file. */\r
90 void vApplicationMallocFailedHook( void );\r
91 void vApplicationIdleHook( void );\r
92 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );\r
93 void vApplicationTickHook( void );\r
94 \r
95 /* Library initialisation. */\r
96 extern void R_Systeminit( void );\r
97 \r
98 /*-----------------------------------------------------------*/\r
99 \r
100 /* See http://www.freertos.org/Renesas_RZ-T_Cortex-R4F-RTOS.html */\r
101 int main( void )\r
102 {\r
103         /* The start up code does not include a routine to clear the BSS segment to\r
104         0 (as would be normal before calling main()), so the BSS is cleared manually\r
105         using the following function. */\r
106         prvClearBSS();\r
107 \r
108         /* Configure the hardware ready to run the demo. */\r
109         R_Systeminit();\r
110 \r
111         /* The mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is described at the top\r
112         of this file. */\r
113         #if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 )\r
114         {\r
115                 main_blinky();\r
116         }\r
117         #else\r
118         {\r
119                 main_full();\r
120         }\r
121         #endif\r
122 \r
123         return 0;\r
124 }\r
125 /*-----------------------------------------------------------*/\r
126 \r
127 void vApplicationMallocFailedHook( void )\r
128 {\r
129         /* Called if a call to pvPortMalloc() fails because there is insufficient\r
130         free memory available in the FreeRTOS heap.  pvPortMalloc() is called\r
131         internally by FreeRTOS API functions that create tasks, queues, software\r
132         timers, and semaphores.  The size of the FreeRTOS heap is set by the\r
133         configTOTAL_HEAP_SIZE configuration constant in FreeRTOSConfig.h. */\r
134 \r
135         /* Force an assert. */\r
136         configASSERT( ( volatile void * ) NULL );\r
137 }\r
138 /*-----------------------------------------------------------*/\r
139 \r
140 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )\r
141 {\r
142         ( void ) pcTaskName;\r
143         ( void ) pxTask;\r
144 \r
145         /* Run time stack overflow checking is performed if\r
146         configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2.  This hook\r
147         function is called if a stack overflow is detected. */\r
148 \r
149         /* Force an assert. */\r
150         configASSERT( ( volatile void * ) NULL );\r
151 }\r
152 /*-----------------------------------------------------------*/\r
153 \r
154 void vApplicationIdleHook( void )\r
155 {\r
156 volatile size_t xFreeHeapSpace;\r
157 \r
158         /* This is just a trivial example of an idle hook.  It is called on each\r
159         cycle of the idle task.  It must *NOT* attempt to block.  In this case the\r
160         idle task just queries the amount of FreeRTOS heap that remains.  See the\r
161         memory management section on the http://www.FreeRTOS.org web site for memory\r
162         management options.  If there is a lot of heap memory free then the\r
163         configTOTAL_HEAP_SIZE value in FreeRTOSConfig.h can be reduced to free up\r
164         RAM. */\r
165         xFreeHeapSpace = xPortGetFreeHeapSize();\r
166 \r
167         /* Remove compiler warning about xFreeHeapSpace being set but never used. */\r
168         ( void ) xFreeHeapSpace;\r
169 }\r
170 /*-----------------------------------------------------------*/\r
171 \r
172 void vApplicationTickHook( void )\r
173 {\r
174         #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 0\r
175         {\r
176                 extern void vFullDemoTickHook( void );\r
177 \r
178                 vFullDemoTickHook();\r
179         }\r
180         #endif\r
181 }\r
182 /*-----------------------------------------------------------*/\r
183 \r
184 static void prvClearBSS( void )\r
185 {\r
186 #ifdef __GNUC__\r
187         /* The GCC start up files seem to be missing code to clear the BSS, so it\r
188         is done manually here. */\r
189         extern uint32_t __bss_start__[];\r
190         extern uint32_t __bss_end__[];\r
191         size_t xSize;\r
192 \r
193         /* Zero out bss. */\r
194         xSize = ( ( size_t ) __bss_end__ ) - ( ( size_t ) __bss_start__ );\r
195         memset( ( void * ) __bss_start__, 0x00, xSize );\r
196 #endif /* __GNUC__ */\r
197 }\r
198 \r
199 \r
200 \r