]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_R4F_RZ_T_GCC_IAR_ARM/src/Full_Demo/IntQueueTimer.c
e6abe0eba782ad3b01c853c0467ede2b6cabf7f6
[freertos] / FreeRTOS / Demo / CORTEX_R4F_RZ_T_GCC_IAR_ARM / src / Full_Demo / IntQueueTimer.c
1 /*\r
2     FreeRTOS V8.2.2 - Copyright (C) 2015 Real Time Engineers Ltd.\r
3     All rights reserved\r
4 \r
5     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
6 \r
7     This file is part of the FreeRTOS distribution.\r
8 \r
9     FreeRTOS is free software; you can redistribute it and/or modify it under\r
10     the terms of the GNU General Public License (version 2) as published by the\r
11     Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.\r
12 \r
13     ***************************************************************************\r
14     >>!   NOTE: The modification to the GPL is included to allow you to     !<<\r
15     >>!   distribute a combined work that includes FreeRTOS without being   !<<\r
16     >>!   obliged to provide the source code for proprietary components     !<<\r
17     >>!   outside of the FreeRTOS kernel.                                   !<<\r
18     ***************************************************************************\r
19 \r
20     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
21     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
22     FOR A PARTICULAR PURPOSE.  Full license text is available on the following\r
23     link: http://www.freertos.org/a00114.html\r
24 \r
25     ***************************************************************************\r
26      *                                                                       *\r
27      *    FreeRTOS provides completely free yet professionally developed,    *\r
28      *    robust, strictly quality controlled, supported, and cross          *\r
29      *    platform software that is more than just the market leader, it     *\r
30      *    is the industry's de facto standard.                               *\r
31      *                                                                       *\r
32      *    Help yourself get started quickly while simultaneously helping     *\r
33      *    to support the FreeRTOS project by purchasing a FreeRTOS           *\r
34      *    tutorial book, reference manual, or both:                          *\r
35      *    http://www.FreeRTOS.org/Documentation                              *\r
36      *                                                                       *\r
37     ***************************************************************************\r
38 \r
39     http://www.FreeRTOS.org/FAQHelp.html - Having a problem?  Start by reading\r
40     the FAQ page "My application does not run, what could be wrong?".  Have you\r
41     defined configASSERT()?\r
42 \r
43     http://www.FreeRTOS.org/support - In return for receiving this top quality\r
44     embedded software for free we request you assist our global community by\r
45     participating in the support forum.\r
46 \r
47     http://www.FreeRTOS.org/training - Investing in training allows your team to\r
48     be as productive as possible as early as possible.  Now you can receive\r
49     FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers\r
50     Ltd, and the world's leading authority on the world's leading RTOS.\r
51 \r
52     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
53     including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
54     compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
55 \r
56     http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.\r
57     Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.\r
58 \r
59     http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High\r
60     Integrity Systems ltd. to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
61     licenses offer ticketed support, indemnification and commercial middleware.\r
62 \r
63     http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
64     engineered and independently SIL3 certified version for use in safety and\r
65     mission critical applications that require provable dependability.\r
66 \r
67     1 tab == 4 spaces!\r
68 */\r
69 \r
70 /*\r
71  * This file contains the non-portable and therefore RZ/T specific parts of\r
72  * the IntQueue standard demo task - namely the configuration of the timers\r
73  * that generate the interrupts and the interrupt entry points.\r
74  */\r
75 \r
76 /* Scheduler includes. */\r
77 #include "FreeRTOS.h"\r
78 #include "task.h"\r
79 \r
80 /* Demo includes. */\r
81 #include "IntQueueTimer.h"\r
82 #include "IntQueue.h"\r
83 \r
84 /* Renesas includes. */\r
85 #include "r_cg_macrodriver.h"\r
86 #include "r_cg_cmt.h"\r
87 #include "r_reset.h"\r
88 \r
89 #define tmrCMT_1_CHANNEL_0_HZ   ( 4000UL )\r
90 #define tmrCMT_1_CHANNEL_1_HZ   ( 2011UL )\r
91 \r
92 /*\r
93  * Handlers for the two timers used.  See the documentation page\r
94  * for this port on TBD for more information on writing\r
95  * interrupt handlers.\r
96  */\r
97 void vCMT_1_Channel_0_ISR( void );\r
98 void vCMT_1_Channel_1_ISR( void );\r
99 \r
100 /*\r
101  * Entry point for the handlers.  These set the pxISRFunction variable to point\r
102  * to the C handler for each timer, then branch to the FreeRTOS IRQ handler.\r
103  */\r
104 static void vCMT_1_Channel_0_ISR_Entry( void ) __attribute__((naked));\r
105 static void vCMT_1_Channel_1_ISR_Entry( void ) __attribute__((naked));\r
106 \r
107 /*-----------------------------------------------------------*/\r
108 \r
109 void vInitialiseTimerForIntQueueTest( void )\r
110 {\r
111 uint32_t ulCompareMatchValue;\r
112 const uint32_t ulPeripheralClockDivider = 6UL, ulCMTClockDivider = 8UL;\r
113 \r
114         /* Disable CMI2 and CMI3 interrupts. */\r
115         VIC.IEC0.LONG = ( 1UL << 23UL ) | ( 1UL << 24UL );\r
116 \r
117         /* Cancel CMT stop state in LPC. */\r
118         r_rst_write_enable();\r
119         MSTP( CMT1 ) = 0U;\r
120         r_rst_write_disable();\r
121 \r
122         /* Interrupt on compare match. */\r
123         CMT2.CMCR.BIT.CMIE = 1;\r
124         CMT3.CMCR.BIT.CMIE = 1;\r
125 \r
126         /* Calculate the compare match value. */\r
127         ulCompareMatchValue = configCPU_CLOCK_HZ / ulPeripheralClockDivider;\r
128         ulCompareMatchValue /= ulCMTClockDivider;\r
129         ulCompareMatchValue /= tmrCMT_1_CHANNEL_0_HZ;\r
130         ulCompareMatchValue -= 1UL;\r
131         CMT2.CMCOR = ( unsigned short ) ulCompareMatchValue;\r
132 \r
133         ulCompareMatchValue = configCPU_CLOCK_HZ / ulPeripheralClockDivider;\r
134         ulCompareMatchValue /= ulCMTClockDivider;\r
135         ulCompareMatchValue /= tmrCMT_1_CHANNEL_1_HZ;\r
136         ulCompareMatchValue -= 1UL;\r
137         CMT3.CMCOR = ( unsigned short ) ulCompareMatchValue;\r
138 \r
139         /* Divide the PCLK by 8. */\r
140         CMT2.CMCR.BIT.CKS = 0;\r
141         CMT3.CMCR.BIT.CKS = 0;\r
142 \r
143         /* Clear count to 0. */\r
144         CMT2.CMCNT = 0;\r
145         CMT3.CMCNT = 0;\r
146 \r
147         /* Set CMI2 and CMI3 edge detection type. */\r
148         VIC.PLS0.LONG |= ( 1UL << 23UL ) | ( 1UL << 24UL );\r
149 \r
150         /* Set CMI2 and CMI3 priority levels so they nest. */\r
151         VIC.PRL23.LONG = _CMT_PRIORITY_LEVEL2;\r
152         VIC.PRL24.LONG = _CMT_PRIORITY_LEVEL9;\r
153 \r
154         /* Set CMI2 and CMI3 interrupt address. */\r
155         VIC.VAD23.LONG = ( uint32_t ) vCMT_1_Channel_0_ISR_Entry;\r
156         VIC.VAD24.LONG = ( uint32_t ) vCMT_1_Channel_1_ISR_Entry;\r
157 \r
158     /* Enable CMI2 and CMI3 interrupts in ICU. */\r
159         VIC.IEN0.LONG |= ( 1UL << 23UL ) | ( 1UL << 24UL );\r
160 \r
161     /* Start CMT1 channel 0 and 1 count. */\r
162     CMT.CMSTR1.BIT.STR2 = 1U;\r
163         CMT.CMSTR1.BIT.STR3 = 1U;\r
164 }\r
165 /*-----------------------------------------------------------*/\r
166 \r
167 void vCMT_1_Channel_0_ISR( void )\r
168 {\r
169         /* Clear the interrupt. */\r
170         VIC.PIC0.LONG = ( 1UL << 23UL );\r
171 \r
172         /* Call the handler that is part of the common code - this is where the\r
173         non-portable code ends and the actual test is performed. */\r
174         portYIELD_FROM_ISR( xFirstTimerHandler() );\r
175 }\r
176 /*-----------------------------------------------------------*/\r
177 \r
178 void vCMT_1_Channel_1_ISR( void )\r
179 {\r
180         /* Clear the interrupt. */\r
181         VIC.PIC0.LONG = ( 1UL << 24UL );\r
182 \r
183         /* Call the handler that is part of the common code - this is where the\r
184         non-portable code ends and the actual test is performed. */\r
185         portYIELD_FROM_ISR( xSecondTimerHandler() );\r
186 }\r
187 /*-----------------------------------------------------------*/\r
188 \r
189 /*\r
190  * The RZ/T vectors directly to a peripheral specific interrupt handler, rather\r
191  * than using the Cortex-R IRQ vector.  Therefore each interrupt handler\r
192  * installed by the application must follow the examples below, which save a\r
193  * pointer to a standard C function in the pxISRFunction variable, before\r
194  * branching to the FreeRTOS IRQ handler.  The FreeRTOS IRQ handler then manages\r
195  * interrupt entry (including interrupt nesting), before calling the C function\r
196  * saved in the pxISRFunction variable.  NOTE:  The entry points are naked\r
197  * functions - do not add C code to these functions.\r
198  */\r
199 static void vCMT_1_Channel_0_ISR_Entry( void )\r
200 {\r
201         __asm volatile (                                                                                                                \\r
202                                                 "PUSH   {r0-r1}                                                         \t\n"   \\r
203                                                 "LDR    r0, =pxISRFunction                                      \t\n"   \\r
204                                                 "LDR    r1, =vCMT_1_Channel_0_ISR                       \t\n"   \\r
205                                                 "STR    r1, [r0]                                                        \t\n"   \\r
206                                                 "POP    {r0-r1}                                                         \t\n"   \\r
207                                                 "B              FreeRTOS_IRQ_Handler                                    "\r
208                                         );\r
209 }\r
210 /*-----------------------------------------------------------*/\r
211 \r
212 static void vCMT_1_Channel_1_ISR_Entry( void )\r
213 {\r
214         __asm volatile (                                                                                                                \\r
215                                                 "PUSH   {r0-r1}                                                         \t\n"   \\r
216                                                 "LDR    r0, =pxISRFunction                                      \t\n"   \\r
217                                                 "LDR    r1, =vCMT_1_Channel_1_ISR                       \t\n"   \\r
218                                                 "STR    r1, [r0]                                                        \t\n"   \\r
219                                                 "POP    {r0-r1}                                                         \t\n"   \\r
220                                                 "B              FreeRTOS_IRQ_Handler                                    "\r
221                                         );\r
222 }\r
223 \r
224 \r
225 \r
226 \r
227 \r