]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/RX700_RX71M_RSK_Renesas_e2studio/src/main.c
Update to MIT licensed FreeRTOS V10.0.0 - see https://www.freertos.org/History.txt
[freertos] / FreeRTOS / Demo / RX700_RX71M_RSK_Renesas_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, 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  */\r
46 \r
47 /* Scheduler include files. */\r
48 #include "FreeRTOS.h"\r
49 #include "task.h"\r
50 #include "semphr.h"\r
51 \r
52 /* Renesas code generator includes. */\r
53 #include "r_cg_macrodriver.h"\r
54 #include "r_cg_sci.h"\r
55 \r
56 /* Set mainCREATE_SIMPLE_BLINKY_DEMO_ONLY to one to run the simple blinky demo,\r
57 or 0 to run the more comprehensive test and demo application. */\r
58 #define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY      1\r
59 \r
60 /*-----------------------------------------------------------*/\r
61 \r
62 /*\r
63  * Configure the hardware as necessary to run this demo.\r
64  */\r
65 static void prvSetupHardware( void );\r
66 \r
67 /*\r
68  * main_blinky() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1.\r
69  * main_full() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 0.\r
70  */\r
71 #if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 )\r
72         extern void main_blinky( void );\r
73 #else\r
74         extern void main_full( void );\r
75 #endif /* #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 */\r
76 \r
77 /* Prototypes for the standard FreeRTOS callback/hook functions implemented\r
78 within this file. */\r
79 void vApplicationMallocFailedHook( void );\r
80 void vApplicationIdleHook( void );\r
81 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );\r
82 void vApplicationTickHook( void );\r
83 \r
84 /*-----------------------------------------------------------*/\r
85 \r
86 int main( void )\r
87 {\r
88         /* Configure the hardware ready to run the demo. */\r
89         prvSetupHardware();\r
90 \r
91         /* The mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is described at the top\r
92         of this file. */\r
93         #if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 )\r
94         {\r
95                 main_blinky();\r
96         }\r
97         #else\r
98         {\r
99                 main_full();\r
100         }\r
101         #endif\r
102 \r
103         /* Should never get reached. */\r
104         return 0;\r
105 }\r
106 /*-----------------------------------------------------------*/\r
107 \r
108 static void prvSetupHardware( void )\r
109 {\r
110     /* Set up SCI7 receive buffer and callback function. */\r
111     R_SCI7_Serial_Receive((uint8_t *)&g_rx_char, 1);\r
112 \r
113     /* Enable SCI7 operations. */\r
114     R_SCI7_Start();\r
115 }\r
116 /*-----------------------------------------------------------*/\r
117 \r
118 void vApplicationMallocFailedHook( void )\r
119 {\r
120         /* Called if a call to pvPortMalloc() fails because there is insufficient\r
121         free memory available in the FreeRTOS heap.  pvPortMalloc() is called\r
122         internally by FreeRTOS API functions that create tasks, queues, software\r
123         timers, and semaphores.  The size of the FreeRTOS heap is set by the\r
124         configTOTAL_HEAP_SIZE configuration constant in FreeRTOSConfig.h. */\r
125 \r
126         /* Force an assert. */\r
127         configASSERT( ( volatile void * ) NULL );\r
128 }\r
129 /*-----------------------------------------------------------*/\r
130 \r
131 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )\r
132 {\r
133         ( void ) pcTaskName;\r
134         ( void ) pxTask;\r
135 \r
136         /* Run time stack overflow checking is performed if\r
137         configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2.  This hook\r
138         function is called if a stack overflow is detected. */\r
139 \r
140         /* Force an assert. */\r
141         configASSERT( ( volatile void * ) NULL );\r
142 }\r
143 /*-----------------------------------------------------------*/\r
144 \r
145 void vApplicationIdleHook( void )\r
146 {\r
147 volatile size_t xFreeHeapSpace;\r
148 \r
149         /* This is just a trivial example of an idle hook.  It is called on each\r
150         cycle of the idle task.  It must *NOT* attempt to block.  In this case the\r
151         idle task just queries the amount of FreeRTOS heap that remains.  See the\r
152         memory management section on the http://www.FreeRTOS.org web site for memory\r
153         management options.  If there is a lot of heap memory free then the\r
154         configTOTAL_HEAP_SIZE value in FreeRTOSConfig.h can be reduced to free up\r
155         RAM. */\r
156         xFreeHeapSpace = xPortGetFreeHeapSize();\r
157 \r
158         /* Remove compiler warning about xFreeHeapSpace being set but never used. */\r
159         ( void ) xFreeHeapSpace;\r
160 }\r
161 /*-----------------------------------------------------------*/\r
162 \r
163 void vApplicationTickHook( void )\r
164 {\r
165         /* The tick hook is not used by the blinky demo, but is by the full demo. */\r
166         #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 0\r
167         {\r
168                 extern void vFullDemoTickHook( void );\r
169 \r
170                 vFullDemoTickHook();\r
171         }\r
172         #endif\r
173 }\r
174 /*-----------------------------------------------------------*/\r
175 \r
176 /* The RX port uses this callback function to configure its tick interrupt.\r
177 This allows the application to choose the tick interrupt source.\r
178 ***NOTE***: configTICK_VECTOR must be set in FreeRTOSConfig.h to be correct for\r
179 whichever vector is used. */\r
180 void vApplicationSetupTimerInterrupt( void )\r
181 {\r
182 const uint32_t ulEnableRegisterWrite = 0xA50BUL, ulDisableRegisterWrite = 0xA500UL;\r
183 \r
184     /* Disable register write protection. */\r
185     SYSTEM.PRCR.WORD = ulEnableRegisterWrite;\r
186 \r
187         /* Enable compare match timer 0. */\r
188         MSTP( CMT0 ) = 0;\r
189 \r
190         /* Interrupt on compare match. */\r
191         CMT0.CMCR.BIT.CMIE = 1;\r
192 \r
193         /* Set the compare match value. */\r
194         CMT0.CMCOR = ( unsigned short ) ( ( ( configPERIPHERAL_CLOCK_HZ / configTICK_RATE_HZ ) -1 ) / 8 );\r
195 \r
196         /* Divide the PCLK by 8. */\r
197         CMT0.CMCR.BIT.CKS = 0;\r
198 \r
199         /* Enable the interrupt... */\r
200         _IEN( _CMT0_CMI0 ) = 1;\r
201 \r
202         /* ...and set its priority to the application defined kernel priority. */\r
203         _IPR( _CMT0_CMI0 ) = configKERNEL_INTERRUPT_PRIORITY;\r
204 \r
205         /* Start the timer. */\r
206         CMT.CMSTR0.BIT.STR0 = 1;\r
207 \r
208     /* Reneable register protection. */\r
209     SYSTEM.PRCR.WORD = ulDisableRegisterWrite;\r
210 }\r
211 \r
212 \r
213 \r