]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/RX700_RX71M_RSK_GCC_e2studio_IAR/src/main.c
Update version number in readiness for V10.3.0 release. Sync SVN with reviewed releas...
[freertos] / FreeRTOS / Demo / RX700_RX71M_RSK_GCC_e2studio_IAR / src / main.c
1 /*\r
2  * FreeRTOS Kernel V10.3.0\r
3  * Copyright (C) 2020 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.  A simple blinky style project,\r
30  * and a more comprehensive test and demo application.  The\r
31  * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting (defined in this file) is used to\r
32  * select between the two.  The simply blinky demo is implemented and described\r
33  * in main_blinky.c.  The more comprehensive test and demo application is\r
34  * implemented and described in main_full.c.\r
35  *\r
36  * This file implements the code that is not demo specific, including the\r
37  * hardware setup, standard FreeRTOS hook functions, and the ISR hander called\r
38  * by the RTOS after interrupt entry (including nesting) has been taken care of.\r
39  *\r
40  * ENSURE TO READ THE DOCUMENTATION PAGE FOR THIS PORT AND DEMO APPLICATION ON\r
41  * THE http://www.FreeRTOS.org WEB SITE FOR FULL INFORMATION ON USING THIS DEMO\r
42  * APPLICATION, AND ITS ASSOCIATE FreeRTOS ARCHITECTURE PORT!\r
43  *\r
44  */\r
45 \r
46 /* Standard includes. */\r
47 #include "string.h"\r
48 \r
49 /* Scheduler include files. */\r
50 #include "FreeRTOS.h"\r
51 #include "task.h"\r
52 #include "semphr.h"\r
53 \r
54 /* Renesas code generator includes. */\r
55 #include "r_cg_macrodriver.h"\r
56 #include "r_cg_sci.h"\r
57 \r
58 /* Set mainCREATE_SIMPLE_BLINKY_DEMO_ONLY to one to run the simple blinky demo,\r
59 or 0 to run the more comprehensive test and demo application. */\r
60 #define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY      0\r
61 \r
62 /*-----------------------------------------------------------*/\r
63 \r
64 /*\r
65  * Configure the hardware as necessary to run this demo.\r
66  */\r
67 static void prvSetupHardware( void );\r
68 \r
69 /*\r
70  * main_blinky() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1.\r
71  * main_full() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 0.\r
72  */\r
73 #if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 )\r
74         extern void main_blinky( void );\r
75 #else\r
76         extern void main_full( void );\r
77 #endif /* #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 */\r
78 \r
79 /* Prototypes for the standard FreeRTOS callback/hook functions implemented\r
80 within this file. */\r
81 void vApplicationMallocFailedHook( void );\r
82 void vApplicationIdleHook( void );\r
83 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );\r
84 void vApplicationTickHook( void );\r
85 \r
86 /*-----------------------------------------------------------*/\r
87 \r
88 int main( void )\r
89 {\r
90         /* Configure the hardware ready to run the demo. */\r
91         prvSetupHardware();\r
92 \r
93         /* The mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is described at the top\r
94         of this file. */\r
95         #if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 )\r
96         {\r
97                 main_blinky();\r
98         }\r
99         #else\r
100         {\r
101                 main_full();\r
102         }\r
103         #endif\r
104 \r
105         /* Should never get reached. */\r
106         return 0;\r
107 }\r
108 /*-----------------------------------------------------------*/\r
109 \r
110 static void prvSetupHardware( void )\r
111 {\r
112     /* Set up SCI7 receive buffer and callback function. */\r
113     R_SCI7_Serial_Receive((uint8_t *)&g_rx_char, 1);\r
114 \r
115     /* Enable SCI7 operations. */\r
116     R_SCI7_Start();\r
117 }\r
118 /*-----------------------------------------------------------*/\r
119 \r
120 void vApplicationMallocFailedHook( void )\r
121 {\r
122         /* Called if a call to pvPortMalloc() fails because there is insufficient\r
123         free memory available in the FreeRTOS heap.  pvPortMalloc() is called\r
124         internally by FreeRTOS API functions that create tasks, queues, software\r
125         timers, and semaphores.  The size of the FreeRTOS heap is set by the\r
126         configTOTAL_HEAP_SIZE configuration constant in FreeRTOSConfig.h. */\r
127 \r
128         /* Force an assert. */\r
129         configASSERT( ( volatile void * ) NULL );\r
130 }\r
131 /*-----------------------------------------------------------*/\r
132 \r
133 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )\r
134 {\r
135         ( void ) pcTaskName;\r
136         ( void ) pxTask;\r
137 \r
138         /* Run time stack overflow checking is performed if\r
139         configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2.  This hook\r
140         function is called if a stack overflow is detected. */\r
141 \r
142         /* Force an assert. */\r
143         configASSERT( ( volatile void * ) NULL );\r
144 }\r
145 /*-----------------------------------------------------------*/\r
146 \r
147 void vApplicationIdleHook( void )\r
148 {\r
149 volatile size_t xFreeHeapSpace;\r
150 \r
151         /* This is just a trivial example of an idle hook.  It is called on each\r
152         cycle of the idle task.  It must *NOT* attempt to block.  In this case the\r
153         idle task just queries the amount of FreeRTOS heap that remains.  See the\r
154         memory management section on the http://www.FreeRTOS.org web site for memory\r
155         management options.  If there is a lot of heap memory free then the\r
156         configTOTAL_HEAP_SIZE value in FreeRTOSConfig.h can be reduced to free up\r
157         RAM. */\r
158         xFreeHeapSpace = xPortGetFreeHeapSize();\r
159 \r
160         /* Remove compiler warning about xFreeHeapSpace being set but never used. */\r
161         ( void ) xFreeHeapSpace;\r
162 }\r
163 /*-----------------------------------------------------------*/\r
164 \r
165 void vApplicationTickHook( void )\r
166 {\r
167         /* The tick hook is not used by the blinky demo, but is by the full demo. */\r
168         #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 0\r
169         {\r
170                 extern void vFullDemoTickHook( void );\r
171 \r
172                 vFullDemoTickHook();\r
173         }\r
174         #endif\r
175 }\r
176 /*-----------------------------------------------------------*/\r
177 \r
178 /* The RX port uses this callback function to configure its tick interrupt.\r
179 This allows the application to choose the tick interrupt source.\r
180 ***NOTE***: configTICK_VECTOR must be set in FreeRTOSConfig.h to be correct for\r
181 whichever vector is used. */\r
182 void vApplicationSetupTimerInterrupt( void )\r
183 {\r
184 const uint32_t ulEnableRegisterWrite = 0xA50BUL, ulDisableRegisterWrite = 0xA500UL;\r
185 \r
186     /* Disable register write protection. */\r
187     SYSTEM.PRCR.WORD = ulEnableRegisterWrite;\r
188 \r
189         /* Enable compare match timer 0. */\r
190         MSTP( CMT0 ) = 0;\r
191 \r
192         /* Interrupt on compare match. */\r
193         CMT0.CMCR.BIT.CMIE = 1;\r
194 \r
195         /* Set the compare match value. */\r
196         CMT0.CMCOR = ( unsigned short ) ( ( ( configPERIPHERAL_CLOCK_HZ / configTICK_RATE_HZ ) -1 ) / 8 );\r
197 \r
198         /* Divide the PCLK by 8. */\r
199         CMT0.CMCR.BIT.CKS = 0;\r
200 \r
201         /* Enable the interrupt... */\r
202         _IEN( _CMT0_CMI0 ) = 1;\r
203 \r
204         /* ...and set its priority to the application defined kernel priority. */\r
205         _IPR( _CMT0_CMI0 ) = configKERNEL_INTERRUPT_PRIORITY;\r
206 \r
207         /* Start the timer. */\r
208         CMT.CMSTR0.BIT.STR0 = 1;\r
209 \r
210     /* Reneable register protection. */\r
211     SYSTEM.PRCR.WORD = ulDisableRegisterWrite;\r
212 }\r
213 /*-----------------------------------------------------------*/\r
214 \r
215 #ifdef __ICCRX__\r
216 \r
217         #include <intrinsics.h>\r
218 \r
219         /* Called from the C start up code when compiled with IAR. */\r
220         #pragma diag_suppress = Pm011\r
221         int __low_level_init(void)\r
222         #pragma diag_default = Pm011\r
223         {\r
224         extern void R_Systeminit( void );\r
225 \r
226                 __disable_interrupt();\r
227                 R_Systeminit();\r
228 \r
229                 return (int)(1U);\r
230         }\r
231 \r
232 #endif /* __ICCRX__ */\r