2 * FreeRTOS Kernel V10.2.1
\r
3 * Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
\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
12 * The above copyright notice and this permission notice shall be included in all
\r
13 * copies or substantial portions of the Software.
\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
22 * http://www.FreeRTOS.org
\r
23 * http://aws.amazon.com/freertos
\r
25 * 1 tab == 4 spaces!
\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
36 * This file implements the code that is not demo specific, including the
\r
37 * hardware setup and standard FreeRTOS hook functions.
\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
43 * http://www.freertos.org/RX113_RTOS_Renesas_GCC_IAR.html
\r
47 /* Scheduler include files. */
\r
48 #include "FreeRTOS.h"
\r
52 /* Renesas includes. */
\r
53 #include <rskrx113def.h>
\r
54 #include "r_cg_macrodriver.h"
\r
55 #include "r_cg_sci.h"
\r
57 /* Set mainCREATE_SIMPLE_BLINKY_DEMO_ONLY to one to run the simple blinky demo,
\r
58 or 0 to run the more comprehensive test and demo application. */
\r
59 #define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY 1
\r
61 /*-----------------------------------------------------------*/
\r
64 * Configure the hardware as necessary to run this demo.
\r
66 static void prvSetupHardware( void );
\r
69 * main_blinky() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1.
\r
70 * main_full() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 0.
\r
72 #if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 )
\r
73 extern void main_blinky( void );
\r
75 extern void main_full( void );
\r
76 #endif /* #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 */
\r
78 /* Prototypes for the standard FreeRTOS callback/hook functions implemented
\r
79 within this file. */
\r
80 void vApplicationMallocFailedHook( void );
\r
81 void vApplicationIdleHook( void );
\r
82 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );
\r
83 void vApplicationTickHook( void );
\r
85 /*-----------------------------------------------------------*/
\r
87 /* See http://www.freertos.org/RX113_RTOS_Renesas_GCC_IAR.html */
\r
90 /* Configure the hardware ready to run the demo. */
\r
93 /* The mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is described at the top
\r
95 #if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 )
\r
105 /* Should never get reached. */
\r
108 /*-----------------------------------------------------------*/
\r
110 static void prvSetupHardware( void )
\r
112 /* Some hardware setup is performed before main() is called. This routine
\r
113 just ensures the LEDs start off. */
\r
119 /*-----------------------------------------------------------*/
\r
121 void vApplicationMallocFailedHook( void )
\r
123 /* Called if a call to pvPortMalloc() fails because there is insufficient
\r
124 free memory available in the FreeRTOS heap. pvPortMalloc() is called
\r
125 internally by FreeRTOS API functions that create tasks, queues, software
\r
126 timers, and semaphores. The size of the FreeRTOS heap is set by the
\r
127 configTOTAL_HEAP_SIZE configuration constant in FreeRTOSConfig.h. */
\r
129 /* Force an assert. */
\r
130 configASSERT( ( volatile void * ) NULL );
\r
132 /*-----------------------------------------------------------*/
\r
134 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
\r
136 ( void ) pcTaskName;
\r
139 /* Run time stack overflow checking is performed if
\r
140 configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook
\r
141 function is called if a stack overflow is detected. */
\r
143 /* Force an assert. */
\r
144 configASSERT( ( volatile void * ) NULL );
\r
146 /*-----------------------------------------------------------*/
\r
148 void vApplicationIdleHook( void )
\r
150 volatile size_t xFreeHeapSpace;
\r
152 /* This is just a trivial example of an idle hook. It is called on each
\r
153 cycle of the idle task. It must *NOT* attempt to block. In this case the
\r
154 idle task just queries the amount of FreeRTOS heap that remains. See the
\r
155 memory management section on the http://www.FreeRTOS.org web site for memory
\r
156 management options. If there is a lot of heap memory free then the
\r
157 configTOTAL_HEAP_SIZE value in FreeRTOSConfig.h can be reduced to free up
\r
159 xFreeHeapSpace = xPortGetFreeHeapSize();
\r
161 /* Remove compiler warning about xFreeHeapSpace being set but never used. */
\r
162 ( void ) xFreeHeapSpace;
\r
164 /*-----------------------------------------------------------*/
\r
166 void vApplicationTickHook( void )
\r
168 /* The tick hook is not used by the blinky demo, but is by the full demo. */
\r
169 #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 0
\r
171 extern void vFullDemoTickHook( void );
\r
173 vFullDemoTickHook();
\r
177 /*-----------------------------------------------------------*/
\r
179 /* The RX port uses this callback function to configure its tick interrupt.
\r
180 This allows the application to choose the tick interrupt source.
\r
181 ***NOTE***: configTICK_VECTOR must be set in FreeRTOSConfig.h to be correct for
\r
182 whichever vector is used. */
\r
183 void vApplicationSetupTimerInterrupt( void )
\r
185 const uint32_t ulEnableRegisterWrite = 0xA50BUL, ulDisableRegisterWrite = 0xA500UL;
\r
187 /* Disable register write protection. */
\r
188 SYSTEM.PRCR.WORD = ulEnableRegisterWrite;
\r
190 /* Enable compare match timer 0. */
\r
193 /* Interrupt on compare match. */
\r
194 CMT0.CMCR.BIT.CMIE = 1;
\r
196 /* Set the compare match value. */
\r
197 CMT0.CMCOR = ( unsigned short ) ( ( ( configPERIPHERAL_CLOCK_HZ / configTICK_RATE_HZ ) -1 ) / 8 );
\r
199 /* Divide the PCLK by 8. */
\r
200 CMT0.CMCR.BIT.CKS = 0;
\r
202 /* Enable the interrupt... */
\r
203 _IEN( _CMT0_CMI0 ) = 1;
\r
205 /* ...and set its priority to the application defined kernel priority. */
\r
206 _IPR( _CMT0_CMI0 ) = configKERNEL_INTERRUPT_PRIORITY;
\r
208 /* Start the timer. */
\r
209 CMT.CMSTR0.BIT.STR0 = 1;
\r
211 /* Reneable register protection. */
\r
212 SYSTEM.PRCR.WORD = ulDisableRegisterWrite;
\r