]> begriffs open source - cmsis-freertos/blob - Demo/RX100_RX113-RSK_Renesas_e2studio/src/main.c
Updated pack to FreeRTOS 10.4.6
[cmsis-freertos] / Demo / RX100_RX113-RSK_Renesas_e2studio / src / main.c
1 /*
2  * FreeRTOS V202111.00
3  * Copyright (C) 2020 Amazon.com, Inc. or its affiliates.  All Rights Reserved.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of
6  * this software and associated documentation files (the "Software"), to deal in
7  * the Software without restriction, including without limitation the rights to
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9  * the Software, and to permit persons to whom the Software is furnished to do so,
10  * subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in all
13  * copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  *
22  * http://www.FreeRTOS.org
23  * http://aws.amazon.com/freertos
24  *
25  * 1 tab == 4 spaces!
26  */
27
28 /******************************************************************************
29  * This project provides two demo applications.  A simple blinky style project,
30  * and a more comprehensive test and demo application.  The
31  * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting (defined in this file) is used to
32  * select between the two.  The simply blinky demo is implemented and described
33  * in main_blinky.c.  The more comprehensive test and demo application is
34  * implemented and described in main_full.c.
35  *
36  * This file implements the code that is not demo specific, including the
37  * hardware setup and standard FreeRTOS hook functions.
38  *
39  * ENSURE TO READ THE DOCUMENTATION PAGE FOR THIS PORT AND DEMO APPLICATION ON
40  * THE http://www.FreeRTOS.org WEB SITE FOR FULL INFORMATION ON USING THIS DEMO
41  * APPLICATION, AND ITS ASSOCIATE FreeRTOS ARCHITECTURE PORT!
42  *
43  * http://www.freertos.org/RX113_RTOS_Renesas_GCC_IAR.html
44  *
45  */
46
47 /* Scheduler include files. */
48 #include "FreeRTOS.h"
49 #include "task.h"
50 #include "semphr.h"
51
52 /* Renesas includes. */
53 #include <rskrx113def.h>
54 #include "r_cg_macrodriver.h"
55 #include "r_cg_sci.h"
56
57 /* Set mainCREATE_SIMPLE_BLINKY_DEMO_ONLY to one to run the simple blinky demo,
58 or 0 to run the more comprehensive test and demo application. */
59 #define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY      1
60
61 /*-----------------------------------------------------------*/
62
63 /*
64  * Configure the hardware as necessary to run this demo.
65  */
66 static void prvSetupHardware( void );
67
68 /*
69  * main_blinky() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1.
70  * main_full() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 0.
71  */
72 #if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 )
73         extern void main_blinky( void );
74 #else
75         extern void main_full( void );
76 #endif /* #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 */
77
78 /* Prototypes for the standard FreeRTOS callback/hook functions implemented
79 within this file. */
80 void vApplicationMallocFailedHook( void );
81 void vApplicationIdleHook( void );
82 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );
83 void vApplicationTickHook( void );
84
85 /*-----------------------------------------------------------*/
86
87 /* See http://www.freertos.org/RX113_RTOS_Renesas_GCC_IAR.html */
88 int main( void )
89 {
90         /* Configure the hardware ready to run the demo. */
91         prvSetupHardware();
92
93         /* The mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is described at the top
94         of this file. */
95         #if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 )
96         {
97                 main_blinky();
98         }
99         #else
100         {
101                 main_full();
102         }
103         #endif
104
105         /* Should never get reached. */
106         return 0;
107 }
108 /*-----------------------------------------------------------*/
109
110 static void prvSetupHardware( void )
111 {
112         /* Some hardware setup is performed before main() is called.  This routine
113         just ensures the LEDs start off. */
114     LED0 = LED_OFF;
115     LED1 = LED_OFF;
116     LED2 = LED_OFF;
117     LED3 = LED_OFF;
118 }
119 /*-----------------------------------------------------------*/
120
121 void vApplicationMallocFailedHook( void )
122 {
123         /* Called if a call to pvPortMalloc() fails because there is insufficient
124         free memory available in the FreeRTOS heap.  pvPortMalloc() is called
125         internally by FreeRTOS API functions that create tasks, queues, software
126         timers, and semaphores.  The size of the FreeRTOS heap is set by the
127         configTOTAL_HEAP_SIZE configuration constant in FreeRTOSConfig.h. */
128
129         /* Force an assert. */
130         configASSERT( ( volatile void * ) NULL );
131 }
132 /*-----------------------------------------------------------*/
133
134 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
135 {
136         ( void ) pcTaskName;
137         ( void ) pxTask;
138
139         /* Run time stack overflow checking is performed if
140         configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2.  This hook
141         function is called if a stack overflow is detected. */
142
143         /* Force an assert. */
144         configASSERT( ( volatile void * ) NULL );
145 }
146 /*-----------------------------------------------------------*/
147
148 void vApplicationIdleHook( void )
149 {
150 volatile size_t xFreeHeapSpace;
151
152         /* This is just a trivial example of an idle hook.  It is called on each
153         cycle of the idle task.  It must *NOT* attempt to block.  In this case the
154         idle task just queries the amount of FreeRTOS heap that remains.  See the
155         memory management section on the http://www.FreeRTOS.org web site for memory
156         management options.  If there is a lot of heap memory free then the
157         configTOTAL_HEAP_SIZE value in FreeRTOSConfig.h can be reduced to free up
158         RAM. */
159         xFreeHeapSpace = xPortGetFreeHeapSize();
160
161         /* Remove compiler warning about xFreeHeapSpace being set but never used. */
162         ( void ) xFreeHeapSpace;
163 }
164 /*-----------------------------------------------------------*/
165
166 void vApplicationTickHook( void )
167 {
168         /* The tick hook is not used by the blinky demo, but is by the full demo. */
169         #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 0
170         {
171                 extern void vFullDemoTickHook( void );
172
173                 vFullDemoTickHook();
174         }
175         #endif
176 }
177 /*-----------------------------------------------------------*/
178
179 /* The RX port uses this callback function to configure its tick interrupt.
180 This allows the application to choose the tick interrupt source.
181 ***NOTE***: configTICK_VECTOR must be set in FreeRTOSConfig.h to be correct for
182 whichever vector is used. */
183 void vApplicationSetupTimerInterrupt( void )
184 {
185 const uint32_t ulEnableRegisterWrite = 0xA50BUL, ulDisableRegisterWrite = 0xA500UL;
186
187     /* Disable register write protection. */
188     SYSTEM.PRCR.WORD = ulEnableRegisterWrite;
189
190         /* Enable compare match timer 0. */
191         MSTP( CMT0 ) = 0;
192
193         /* Interrupt on compare match. */
194         CMT0.CMCR.BIT.CMIE = 1;
195
196         /* Set the compare match value. */
197         CMT0.CMCOR = ( unsigned short ) ( ( ( configPERIPHERAL_CLOCK_HZ / configTICK_RATE_HZ ) -1 ) / 8 );
198
199         /* Divide the PCLK by 8. */
200         CMT0.CMCR.BIT.CKS = 0;
201
202         /* Enable the interrupt... */
203         _IEN( _CMT0_CMI0 ) = 1;
204
205         /* ...and set its priority to the application defined kernel priority. */
206         _IPR( _CMT0_CMI0 ) = configKERNEL_INTERRUPT_PRIORITY;
207
208         /* Start the timer. */
209         CMT.CMSTR0.BIT.STR0 = 1;
210
211     /* Reneable register protection. */
212     SYSTEM.PRCR.WORD = ulDisableRegisterWrite;
213 }
214
215
216