]> begriffs open source - cmsis-freertos/blob - Demo/RX200_RX231-RSK_GCC_e2studio_IAR/src/main.c
Updated pack to FreeRTOS 10.4.6
[cmsis-freertos] / Demo / RX200_RX231-RSK_GCC_e2studio_IAR / 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, standard FreeRTOS hook functions, and the ISR hander called
38  * by the RTOS after interrupt entry (including nesting) has been taken care of.
39  *
40  * ENSURE TO READ THE DOCUMENTATION PAGE FOR THIS PORT AND DEMO APPLICATION ON
41  * THE http://www.FreeRTOS.org WEB SITE FOR FULL INFORMATION ON USING THIS DEMO
42  * APPLICATION, AND ITS ASSOCIATE FreeRTOS ARCHITECTURE PORT!
43  *
44  * http://www.freertos.org/RX231_RTOS_Renesas_GCC_IAR.html
45  *
46  */
47
48 /* Scheduler include files. */
49 #include "FreeRTOS.h"
50 #include "task.h"
51 #include "semphr.h"
52
53 /* Set mainCREATE_SIMPLE_BLINKY_DEMO_ONLY to one to run the simple blinky demo,
54 or 0 to run the more comprehensive test and demo application. */
55 #define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY      0
56
57 /*-----------------------------------------------------------*/
58
59 /*
60  * Configure the hardware as necessary to run this demo.
61  */
62 static void prvSetupHardware( void );
63
64 /*
65  * main_blinky() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1.
66  * main_full() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 0.
67  */
68 #if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 )
69         extern void main_blinky( void );
70 #else
71         extern void main_full( void );
72 #endif /* #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 */
73
74 /* Prototypes for the standard FreeRTOS callback/hook functions implemented
75 within this file. */
76 void vApplicationMallocFailedHook( void );
77 void vApplicationIdleHook( void );
78 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );
79 void vApplicationTickHook( void );
80
81 /*-----------------------------------------------------------*/
82
83 /* See http://www.freertos.org/RX231_RTOS_Renesas_GCC_IAR.html */
84 int main( void )
85 {
86         /* Configure the hardware ready to run the demo. */
87         prvSetupHardware();
88
89         /* The mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is described at the top
90         of this file. */
91         #if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 )
92         {
93                 main_blinky();
94         }
95         #else
96         {
97                 main_full();
98         }
99         #endif
100
101         return 0;
102 }
103 /*-----------------------------------------------------------*/
104
105 static void prvSetupHardware( void )
106 {
107 /* Start user code. Do not edit comment generated here */
108 uint16_t usProtectDummy = ( uint16_t ) ( SYSTEM.PRCR.WORD & 0x000FU );
109
110         /* Disable protect bit */
111         SYSTEM.PRCR.WORD = 0xA50FU;
112
113         SYSTEM.VBATTCR.BYTE = 0x81U;
114
115         /* Restore the previous state of the protect register */
116         SYSTEM.PRCR.WORD = ( uint16_t )( 0xA500U | usProtectDummy );
117 }
118 /*-----------------------------------------------------------*/
119
120 void vApplicationMallocFailedHook( void )
121 {
122         /* Called if a call to pvPortMalloc() fails because there is insufficient
123         free memory available in the FreeRTOS heap.  pvPortMalloc() is called
124         internally by FreeRTOS API functions that create tasks, queues, software
125         timers, and semaphores.  The size of the FreeRTOS heap is set by the
126         configTOTAL_HEAP_SIZE configuration constant in FreeRTOSConfig.h. */
127
128         /* Force an assert. */
129         configASSERT( ( volatile void * ) NULL );
130 }
131 /*-----------------------------------------------------------*/
132
133 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
134 {
135         ( void ) pcTaskName;
136         ( void ) pxTask;
137
138         /* Run time stack overflow checking is performed if
139         configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2.  This hook
140         function is called if a stack overflow is detected. */
141
142         /* Force an assert. */
143         configASSERT( ( volatile void * ) NULL );
144 }
145 /*-----------------------------------------------------------*/
146
147 void vApplicationIdleHook( void )
148 {
149 volatile size_t xFreeHeapSpace;
150
151         /* This is just a trivial example of an idle hook.  It is called on each
152         cycle of the idle task.  It must *NOT* attempt to block.  In this case the
153         idle task just queries the amount of FreeRTOS heap that remains.  See the
154         memory management section on the http://www.FreeRTOS.org web site for memory
155         management options.  If there is a lot of heap memory free then the
156         configTOTAL_HEAP_SIZE value in FreeRTOSConfig.h can be reduced to free up
157         RAM. */
158         xFreeHeapSpace = xPortGetFreeHeapSize();
159
160         /* Remove compiler warning about xFreeHeapSpace being set but never used. */
161         ( void ) xFreeHeapSpace;
162 }
163 /*-----------------------------------------------------------*/
164
165 void vApplicationTickHook( void )
166 {
167         #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 0
168         {
169                 extern void vFullDemoTickHook( void );
170
171                 vFullDemoTickHook();
172         }
173         #endif
174 }
175 /*-----------------------------------------------------------*/
176
177 /* The RX port uses this callback function to configure its tick interrupt.
178 This allows the application to choose the tick interrupt source.
179 ***NOTE***: configTICK_VECTOR must be set in FreeRTOSConfig.h to be correct for
180 whichever vector is used. */
181 void vApplicationSetupTimerInterrupt( void )
182 {
183 const uint32_t ulEnableRegisterWrite = 0xA50BUL, ulDisableRegisterWrite = 0xA500UL;
184
185     /* Disable register write protection. */
186     SYSTEM.PRCR.WORD = ulEnableRegisterWrite;
187
188         /* Enable compare match timer 0. */
189         MSTP( CMT0 ) = 0;
190
191         /* Interrupt on compare match. */
192         CMT0.CMCR.BIT.CMIE = 1;
193
194         /* Set the compare match value. */
195         CMT0.CMCOR = ( unsigned short ) ( ( ( configPERIPHERAL_CLOCK_HZ / configTICK_RATE_HZ ) -1 ) / 8 );
196
197         /* Divide the PCLK by 8. */
198         CMT0.CMCR.BIT.CKS = 0;
199
200         /* Enable the interrupt... */
201         _IEN( _CMT0_CMI0 ) = 1;
202
203         /* ...and set its priority to the application defined kernel priority. */
204         _IPR( _CMT0_CMI0 ) = configKERNEL_INTERRUPT_PRIORITY;
205
206         /* Start the timer. */
207         CMT.CMSTR0.BIT.STR0 = 1;
208
209     /* Reneable register protection. */
210     SYSTEM.PRCR.WORD = ulDisableRegisterWrite;
211 }
212 /*-----------------------------------------------------------*/
213
214 #ifdef __ICCRX__
215
216         #include <intrinsics.h>
217
218         /* Called from the C start up code when compiled with IAR. */
219         #pragma diag_suppress = Pm011
220         int __low_level_init(void)
221         #pragma diag_default = Pm011
222         {
223         extern void R_Systeminit( void );
224
225                 __disable_interrupt();
226                 R_Systeminit();
227
228                 return (int)(1U);
229         }
230
231 #endif /* __ICCRX__ */
232
233
234