2 * FreeRTOS Kernel V10.3.0
\r
3 * Copyright (C) 2020 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
29 * This file contains the non-portable and therefore RZ/T specific parts of
\r
30 * the IntQueue standard demo task - namely the configuration of the timers
\r
31 * that generate the interrupts and the interrupt entry points.
\r
34 /* Scheduler includes. */
\r
35 #include "FreeRTOS.h"
\r
38 /* Demo includes. */
\r
39 #include "IntQueueTimer.h"
\r
40 #include "IntQueue.h"
\r
42 /* Renesas includes. */
\r
43 #include "r_cg_macrodriver.h"
\r
44 #include "r_cg_cmt.h"
\r
45 #include "r_reset.h"
\r
47 #define tmrCMT_1_CHANNEL_0_HZ ( 4000UL )
\r
48 #define tmrCMT_1_CHANNEL_1_HZ ( 2011UL )
\r
51 * Handlers for the two timers used. See the documentation page
\r
52 * for this port on TBD for more information on writing
\r
53 * interrupt handlers.
\r
55 void vCMT_1_Channel_0_ISR( void );
\r
56 void vCMT_1_Channel_1_ISR( void );
\r
59 * Entry point for the handlers. These set the pxISRFunction variable to point
\r
60 * to the C handler for each timer, then branch to the FreeRTOS IRQ handler.
\r
63 static void vCMT_1_Channel_0_ISR_Entry( void ) __attribute__((naked));
\r
64 static void vCMT_1_Channel_1_ISR_Entry( void ) __attribute__((naked));
\r
65 #endif /* __GNUC__ */
\r
67 /* IAR requires the entry point to be in an assembly file. The functions
\r
68 are implemented in $PROJ_DIR$/System/IAR/Interrupt_Entry_Stubs.asm. */
\r
69 extern void vCMT_1_Channel_0_ISR_Entry( void );
\r
70 extern void vCMT_1_Channel_1_ISR_Entry( void );
\r
71 #endif /* __ICCARM__ */
\r
72 /*-----------------------------------------------------------*/
\r
74 void vInitialiseTimerForIntQueueTest( void )
\r
76 uint32_t ulCompareMatchValue;
\r
77 const uint32_t ulPeripheralClockDivider = 6UL, ulCMTClockDivider = 8UL;
\r
79 /* Disable CMI2 and CMI3 interrupts. */
\r
80 VIC.IEC0.LONG = ( 1UL << 23UL ) | ( 1UL << 24UL );
\r
82 /* Cancel CMT stop state in LPC. */
\r
83 r_rst_write_enable();
\r
85 r_rst_write_disable();
\r
87 /* Interrupt on compare match. */
\r
88 CMT2.CMCR.BIT.CMIE = 1;
\r
89 CMT3.CMCR.BIT.CMIE = 1;
\r
91 /* Calculate the compare match value. */
\r
92 ulCompareMatchValue = configCPU_CLOCK_HZ / ulPeripheralClockDivider;
\r
93 ulCompareMatchValue /= ulCMTClockDivider;
\r
94 ulCompareMatchValue /= tmrCMT_1_CHANNEL_0_HZ;
\r
95 ulCompareMatchValue -= 1UL;
\r
96 CMT2.CMCOR = ( unsigned short ) ulCompareMatchValue;
\r
98 ulCompareMatchValue = configCPU_CLOCK_HZ / ulPeripheralClockDivider;
\r
99 ulCompareMatchValue /= ulCMTClockDivider;
\r
100 ulCompareMatchValue /= tmrCMT_1_CHANNEL_1_HZ;
\r
101 ulCompareMatchValue -= 1UL;
\r
102 CMT3.CMCOR = ( unsigned short ) ulCompareMatchValue;
\r
104 /* Divide the PCLK by 8. */
\r
105 CMT2.CMCR.BIT.CKS = 0;
\r
106 CMT3.CMCR.BIT.CKS = 0;
\r
108 /* Clear count to 0. */
\r
112 /* Set CMI2 and CMI3 edge detection type. */
\r
113 VIC.PLS0.LONG |= ( 1UL << 23UL ) | ( 1UL << 24UL );
\r
115 /* Set CMI2 and CMI3 priority levels so they nest. */
\r
116 VIC.PRL23.LONG = _CMT_PRIORITY_LEVEL2;
\r
117 VIC.PRL24.LONG = _CMT_PRIORITY_LEVEL9;
\r
119 /* Set CMI2 and CMI3 interrupt address. */
\r
120 VIC.VAD23.LONG = ( uint32_t ) vCMT_1_Channel_0_ISR_Entry;
\r
121 VIC.VAD24.LONG = ( uint32_t ) vCMT_1_Channel_1_ISR_Entry;
\r
123 /* Enable CMI2 and CMI3 interrupts in ICU. */
\r
124 VIC.IEN0.LONG |= ( 1UL << 23UL ) | ( 1UL << 24UL );
\r
126 /* Start CMT1 channel 0 and 1 count. */
\r
127 CMT.CMSTR1.BIT.STR2 = 1U;
\r
128 CMT.CMSTR1.BIT.STR3 = 1U;
\r
130 /*-----------------------------------------------------------*/
\r
132 void vCMT_1_Channel_0_ISR( void )
\r
134 /* Clear the interrupt. */
\r
135 VIC.PIC0.LONG = ( 1UL << 23UL );
\r
137 /* Call the handler that is part of the common code - this is where the
\r
138 non-portable code ends and the actual test is performed. */
\r
139 portYIELD_FROM_ISR( xFirstTimerHandler() );
\r
141 /*-----------------------------------------------------------*/
\r
143 void vCMT_1_Channel_1_ISR( void )
\r
145 /* Clear the interrupt. */
\r
146 VIC.PIC0.LONG = ( 1UL << 24UL );
\r
148 /* Call the handler that is part of the common code - this is where the
\r
149 non-portable code ends and the actual test is performed. */
\r
150 portYIELD_FROM_ISR( xSecondTimerHandler() );
\r
152 /*-----------------------------------------------------------*/
\r
155 * The RZ/T vectors directly to a peripheral specific interrupt handler, rather
\r
156 * than using the Cortex-R IRQ vector. Therefore each interrupt handler
\r
157 * installed by the application must follow the examples below, which save a
\r
158 * pointer to a standard C function in the pxISRFunction variable, before
\r
159 * branching to the FreeRTOS IRQ handler. The FreeRTOS IRQ handler then manages
\r
160 * interrupt entry (including interrupt nesting), before calling the C function
\r
161 * saved in the pxISRFunction variable. NOTE: The entry points are naked
\r
162 * functions - do not add C code to these functions.
\r
164 * See http://www.freertos.org/Renesas_RZ-T_Cortex-R4F-RTOS.html
\r
167 /* The IAR equivalent is implemented in
\r
168 $PROJ_DIR$/System/IAR/Interrupt_Entry_Stubs.asm */
\r
169 static void vCMT_1_Channel_0_ISR_Entry( void )
\r
172 "PUSH {r0-r1} \t\n"
\r
173 "LDR r0, =pxISRFunction \t\n"
\r
174 "LDR r1, =vCMT_1_Channel_0_ISR \t\n"
\r
175 "STR r1, [r0] \t\n"
\r
177 "B FreeRTOS_IRQ_Handler "
\r
180 #endif /* __GNUC__ */
\r
181 /*-----------------------------------------------------------*/
\r
184 /* The IAR equivalent is implemented in
\r
185 $PROJ_DIR$/System/IAR/Interrupt_Entry_Stubs.asm */
\r
186 static void vCMT_1_Channel_1_ISR_Entry( void )
\r
189 "PUSH {r0-r1} \t\n"
\r
190 "LDR r0, =pxISRFunction \t\n"
\r
191 "LDR r1, =vCMT_1_Channel_1_ISR \t\n"
\r
192 "STR r1, [r0] \t\n"
\r
194 "B FreeRTOS_IRQ_Handler "
\r
197 #endif /* __GNUC__ */
\r