]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/RX600_RX64M_RSK_Renesas_e2studio/Source/main.c
12ac3b07f44a918d9d119446a4a7f9fafeb66db4
[freertos] / FreeRTOS / Demo / RX600_RX64M_RSK_Renesas_e2studio / Source / 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 and FreeRTOS hook functions.\r
38  *\r
39  * ENSURE TO READ THE DOCUMENTATION PAGE FOR THIS PORT AND DEMO APPLICATION ON\r
40  * THE http://www.FreeRTOS.org WEB SITE FOR FULL INFORMATION ON USING THIS DEMO\r
41  * APPLICATION, AND ITS ASSOCIATE FreeRTOS ARCHITECTURE PORT!\r
42  *\r
43  */\r
44 \r
45 /* Scheduler include files. */\r
46 #include "FreeRTOS.h"\r
47 #include "task.h"\r
48 #include "semphr.h"\r
49 \r
50 /* Standard demo includes. */\r
51 #include "partest.h"\r
52 #include "TimerDemo.h"\r
53 #include "QueueOverwrite.h"\r
54 #include "EventGroupsDemo.h"\r
55 \r
56 /* Renesas includes. */\r
57 #include "r_cg_macrodriver.h"\r
58 \r
59 /* Set option bytes */\r
60 #pragma address OFS0_location = 0xFFFFFF8CUL\r
61 #pragma address OFS1_location = 0xFFFFFF88UL\r
62 volatile const uint32_t OFS0_location = 0xFFFFFFFFUL;\r
63 volatile const uint32_t OFS1_location = 0xFFFFFFFFUL;\r
64 \r
65 \r
66 /* Set mainCREATE_SIMPLE_BLINKY_DEMO_ONLY to one to run the simple blinky demo,\r
67 or 0 to run the more comprehensive test and demo application. */\r
68 #define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY      1\r
69 \r
70 /*-----------------------------------------------------------*/\r
71 \r
72 /*\r
73  * Configure the hardware as necessary to run this demo.\r
74  */\r
75 static void prvSetupHardware( void );\r
76 \r
77 /*\r
78  * main_blinky() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1.\r
79  * main_full() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 0.\r
80  */\r
81 #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1\r
82         extern void main_blinky( void );\r
83 #else\r
84         extern void main_full( void );\r
85 #endif /* #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 */\r
86 \r
87 /*\r
88  * The Xilinx projects use a BSP that do not allow the start up code to be\r
89  * altered easily.  Therefore the vector table used by FreeRTOS is defined in\r
90  * FreeRTOS_asm_vectors.S, which is part of this project.  Switch to use the\r
91  * FreeRTOS vector table.\r
92  */\r
93 extern void vPortInstallFreeRTOSVectorTable( void );\r
94 \r
95 /* Prototypes for the standard FreeRTOS callback/hook functions implemented\r
96 within this file. */\r
97 void vApplicationMallocFailedHook( void );\r
98 void vApplicationIdleHook( void );\r
99 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );\r
100 void vApplicationTickHook( void );\r
101 \r
102 /*-----------------------------------------------------------*/\r
103 \r
104 int main( void )\r
105 {\r
106         /* Configure the hardware ready to run the demo. */\r
107         prvSetupHardware();\r
108 \r
109         /* The mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is described at the top\r
110         of this file. */\r
111         #if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 )\r
112         {\r
113                 main_blinky();\r
114         }\r
115         #else\r
116         {\r
117                 main_full();\r
118         }\r
119         #endif\r
120 \r
121         /* Don't expect to reach here. */\r
122         return 0;\r
123 }\r
124 /*-----------------------------------------------------------*/\r
125 \r
126 static void prvSetupHardware( void )\r
127 {\r
128         /* Set up the ports used by the LED outputs (the name ParTest is now\r
129         obsolete - it originally came from "parallel port test"). */\r
130         vParTestInitialise();\r
131 }\r
132 /*-----------------------------------------------------------*/\r
133 \r
134 void vApplicationMallocFailedHook( void )\r
135 {\r
136         /* Called if a call to pvPortMalloc() fails because there is insufficient\r
137         free memory available in the FreeRTOS heap.  pvPortMalloc() is called\r
138         internally by FreeRTOS API functions that create tasks, queues, software\r
139         timers, and semaphores.  The size of the FreeRTOS heap is set by the\r
140         configTOTAL_HEAP_SIZE configuration constant in FreeRTOSConfig.h. */\r
141         taskDISABLE_INTERRUPTS();\r
142         for( ;; );\r
143 }\r
144 /*-----------------------------------------------------------*/\r
145 \r
146 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )\r
147 {\r
148         ( void ) pcTaskName;\r
149         ( void ) pxTask;\r
150 \r
151         /* Run time stack overflow checking is performed if\r
152         configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2.  This hook\r
153         function is called if a stack overflow is detected. */\r
154         taskDISABLE_INTERRUPTS();\r
155         for( ;; );\r
156 }\r
157 /*-----------------------------------------------------------*/\r
158 \r
159 void vApplicationIdleHook( void )\r
160 {\r
161 volatile size_t xFreeHeapSpace;\r
162 \r
163         /* This is just a trivial example of an idle hook.  It is called on each\r
164         cycle of the idle task.  It must *NOT* attempt to block.  In this case the\r
165         idle task just queries the amount of FreeRTOS heap that remains.  See the\r
166         memory management section on the http://www.FreeRTOS.org web site for memory\r
167         management options.  If there is a lot of heap memory free then the\r
168         configTOTAL_HEAP_SIZE value in FreeRTOSConfig.h can be reduced to free up\r
169         RAM. */\r
170         xFreeHeapSpace = xPortGetFreeHeapSize();\r
171 \r
172         /* Remove compiler warning about xFreeHeapSpace being set but never used. */\r
173         ( void ) xFreeHeapSpace;\r
174 }\r
175 /*-----------------------------------------------------------*/\r
176 \r
177 void vApplicationTickHook( void )\r
178 {\r
179         #if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 0 )\r
180         {\r
181                 /* The full demo includes a software timer demo/test that requires\r
182                 prodding periodically from the tick interrupt. */\r
183                 vTimerPeriodicISRTests();\r
184 \r
185                 /* Call the periodic queue overwrite from ISR demo. */\r
186                 vQueueOverwritePeriodicISRDemo();\r
187 \r
188                 /* Call the periodic event group from ISR demo. */\r
189                 vPeriodicEventGroupsProcessing();\r
190         }\r
191         #endif\r
192 }\r
193 /*-----------------------------------------------------------*/\r
194 \r
195 void vAssertCalled( void )\r
196 {\r
197 volatile unsigned long ul = 0;\r
198 \r
199         taskENTER_CRITICAL();\r
200         {\r
201                 /* Use the debugger to set ul to a non-zero value in order to step out\r
202                 of this function to determine why it was called. */\r
203                 while( ul == 0 )\r
204                 {\r
205                         portNOP();\r
206                 }\r
207         }\r
208         taskEXIT_CRITICAL();\r
209 }\r
210 /*-----------------------------------------------------------*/\r
211 \r
212 /* The RX port uses this callback function to configure its tick interrupt.\r
213 This allows the application to choose the tick interrupt source. */\r
214 void vApplicationSetupTimerInterrupt( void )\r
215 {\r
216 const uint32_t ulEnableRegisterWrite = 0xA50BUL, ulDisableRegisterWrite = 0xA500UL;\r
217 \r
218     /* Disable register write protection. */\r
219     SYSTEM.PRCR.WORD = ulEnableRegisterWrite;\r
220 \r
221         /* Enable compare match timer 0. */\r
222         MSTP( CMT0 ) = 0;\r
223 \r
224         /* Interrupt on compare match. */\r
225         CMT0.CMCR.BIT.CMIE = 1;\r
226 \r
227         /* Set the compare match value. */\r
228         CMT0.CMCOR = ( unsigned short ) ( ( ( configPERIPHERAL_CLOCK_HZ / configTICK_RATE_HZ ) -1 ) / 8 );\r
229 \r
230         /* Divide the PCLK by 8. */\r
231         CMT0.CMCR.BIT.CKS = 0;\r
232 \r
233         /* Enable the interrupt... */\r
234         _IEN( _CMT0_CMI0 ) = 1;\r
235 \r
236         /* ...and set its priority to the application defined kernel priority. */\r
237         _IPR( _CMT0_CMI0 ) = configKERNEL_INTERRUPT_PRIORITY;\r
238 \r
239         /* Start the timer. */\r
240         CMT.CMSTR0.BIT.STR0 = 1;\r
241 \r
242     /* Reneable register protection. */\r
243     SYSTEM.PRCR.WORD = ulDisableRegisterWrite;\r
244 }\r
245 /*-----------------------------------------------------------*/\r