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
28 /* FreeRTOS includes. */
\r
29 #include "FreeRTOS.h"
\r
31 /* Renesas includes. */
\r
32 #include "r_cg_macrodriver.h"
\r
33 #include "r_cg_cmt.h"
\r
34 #include "r_reset.h"
\r
36 /*-----------------------------------------------------------*/
\r
39 * Entry point for the FreeRTOS tick interrupt. This sets the pxISRFunction
\r
40 * variable to point to the RTOS tick handler, then branches to the FreeRTOS
\r
44 static void FreeRTOS_Tick_Handler_Entry( void ) __attribute__((naked));
\r
45 #endif /* __GNUC__ */
\r
47 /* IAR requires the entry point to be in an assembly file. The function is
\r
48 implemented in $PROJ_DIR$/System/IAR/Interrupt_Entry_Stubs.asm. */
\r
49 extern void FreeRTOS_Tick_Handler_Entry( void );
\r
50 #endif /* __ICCARM__ */
\r
53 * The FreeRTOS IRQ handler, which is implemented in the RTOS port layer.
\r
55 extern void FreeRTOS_IRQ_Handler( void );
\r
58 * The function called by the FreeRTOS_IRQ_Handler() to call the actual
\r
59 * peripheral handler.
\r
61 void vApplicationIRQHandler( void );
\r
63 /*-----------------------------------------------------------*/
\r
66 * Variable used to hold the address of the interrupt handler the FreeRTOS IRQ
\r
67 * handler will branch to.
\r
69 ISRFunction_t pxISRFunction = NULL;
\r
71 /*-----------------------------------------------------------*/
\r
74 * The application must provide a function that configures a peripheral to
\r
75 * create the FreeRTOS tick interrupt, then define configSETUP_TICK_INTERRUPT()
\r
76 * in FreeRTOSConfig.h to call the function.
\r
78 void vConfigureTickInterrupt( void )
\r
80 uint32_t ulCompareMatchValue;
\r
81 const uint32_t ulPeripheralClockDivider = 6UL, ulCMTClockDivider = 8UL;
\r
83 /* Disable CMI5 interrupt. */
\r
84 VIC.IEC9.LONG = 0x00001000UL;
\r
86 /* Cancel CMT stop state in LPC. */
\r
87 r_rst_write_enable();
\r
89 r_rst_write_disable();
\r
91 /* Interrupt on compare match. */
\r
92 CMT5.CMCR.BIT.CMIE = 1;
\r
94 /* Calculate the compare match value. */
\r
95 ulCompareMatchValue = configCPU_CLOCK_HZ / ulPeripheralClockDivider;
\r
96 ulCompareMatchValue /= ulCMTClockDivider;
\r
97 ulCompareMatchValue /= configTICK_RATE_HZ;
\r
98 ulCompareMatchValue -= 1UL;
\r
100 /* Set the compare match value. */
\r
101 CMT5.CMCOR = ( unsigned short ) ulCompareMatchValue;
\r
103 /* Divide the PCLK by 8. */
\r
104 CMT5.CMCR.BIT.CKS = 0;
\r
108 /* Set CMI5 edge detection type. */
\r
109 VIC.PLS9.LONG |= 0x00001000UL;
\r
111 /* Set CMI5 priority level to the lowest possible. */
\r
112 VIC.PRL300.LONG = _CMT_PRIORITY_LEVEL31;
\r
114 /* Set CMI5 interrupt address */
\r
115 VIC.VAD300.LONG = ( uint32_t ) FreeRTOS_Tick_Handler_Entry;
\r
117 /* Enable CMI5 interrupt in ICU. */
\r
118 VIC.IEN9.LONG |= 0x00001000UL;
\r
120 /* Start CMT5 count. */
\r
121 CMT.CMSTR2.BIT.STR5 = 1U;
\r
123 /*-----------------------------------------------------------*/
\r
126 * The function called by the FreeRTOS IRQ handler, after it has managed
\r
127 * interrupt entry. This function creates a local copy of pxISRFunction before
\r
128 * re-enabling interrupts and actually calling the handler pointed to by
\r
131 void vApplicationIRQHandler( void )
\r
133 ISRFunction_t pxISRToCall = pxISRFunction;
\r
135 portENABLE_INTERRUPTS();
\r
137 /* Call the installed ISR. */
\r
140 /*-----------------------------------------------------------*/
\r
143 * The RZ/T vectors directly to a peripheral specific interrupt handler, rather
\r
144 * than using the Cortex-R IRQ vector. Therefore each interrupt handler
\r
145 * installed by the application must follow the example below, which saves a
\r
146 * pointer to a standard C function in the pxISRFunction variable, before
\r
147 * branching to the FreeRTOS IRQ handler. The FreeRTOS IRQ handler then manages
\r
148 * interrupt entry (including interrupt nesting), before calling the C function
\r
149 * saved in the pxISRFunction variable. NOTE: This entry point is a naked
\r
150 * function - do not add C code to this function.
\r
153 /* The IAR equivalent is implemented in
\r
154 $PROJ_DIR$/System/IAR/Interrupt_Entry_Stubs.asm */
\r
155 static void FreeRTOS_Tick_Handler_Entry( void )
\r
158 "PUSH {r0-r1} \t\n"
\r
159 "LDR r0, =pxISRFunction \t\n"
\r
160 "LDR R1, =FreeRTOS_Tick_Handler \t\n"
\r
161 "STR R1, [r0] \t\n"
\r
163 "B FreeRTOS_IRQ_Handler "
\r
166 #endif /* __GNUC__ */
\r
167 /*-----------------------------------------------------------*/
\r