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