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