]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_R4F_RZ_T_GCC_IAR_ARM/src/Full_Demo/IntQueueTimer.c
Common source code:
[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   ( 2000UL )\r
90 #define tmrCMT_1_CHANNEL_1_HZ   ( 2011UL )\r
91 \r
92 /* Handlers for the two timers used.  See the documentation page\r
93 for this port on http://www.FreeRTOS.org for more information on writing\r
94 interrupt handlers. */\r
95 void vCMT_1_Channel_0_ISR( void );\r
96 void vCMT_1_Channel_1_ISR( void );\r
97 \r
98 /*-----------------------------------------------------------*/\r
99 \r
100 void vInitialiseTimerForIntQueueTest( void )\r
101 {\r
102 uint32_t ulCompareMatchValue;\r
103 const uint32_t ulPeripheralClockDivider = 6UL, ulCMTClockDivider = 8UL;\r
104 extern void FreeRTOS_IRQ_Handler( void );\r
105 \r
106         /* Disable CMI2 and CMI3 interrupts. */\r
107         VIC.IEC0.LONG = ( 1UL << 23UL ) | ( 1UL << 24UL );\r
108 \r
109         /* Cancel CMT stop state in LPC. */\r
110         r_rst_write_enable();\r
111         MSTP( CMT1 ) = 0U;\r
112         r_rst_write_disable();\r
113 \r
114         /* Interrupt on compare match. */\r
115         CMT2.CMCR.BIT.CMIE = 1;\r
116         CMT3.CMCR.BIT.CMIE = 1;\r
117 \r
118         /* Calculate the compare match value. */\r
119         ulCompareMatchValue = configCPU_CLOCK_HZ / ulPeripheralClockDivider;\r
120         ulCompareMatchValue /= ulCMTClockDivider;\r
121         ulCompareMatchValue /= tmrCMT_1_CHANNEL_0_HZ;\r
122         ulCompareMatchValue -= 1UL;\r
123         CMT2.CMCOR = ( unsigned short ) ulCompareMatchValue;\r
124 \r
125         ulCompareMatchValue = configCPU_CLOCK_HZ / ulPeripheralClockDivider;\r
126         ulCompareMatchValue /= ulCMTClockDivider;\r
127         ulCompareMatchValue /= tmrCMT_1_CHANNEL_1_HZ;\r
128         ulCompareMatchValue -= 1UL;\r
129         CMT3.CMCOR = ( unsigned short ) ulCompareMatchValue;\r
130 \r
131         /* Divide the PCLK by 8. */\r
132         CMT2.CMCR.BIT.CKS = 0;\r
133         CMT3.CMCR.BIT.CKS = 0;\r
134 \r
135         /* Clear count to 0. */\r
136         CMT2.CMCNT = 0;\r
137         CMT3.CMCNT = 0;\r
138 \r
139         /* Set CMI2 and CMI3 edge detection type. */\r
140         VIC.PLS0.LONG |= ( 1UL << 23UL ) | ( 1UL << 24UL );\r
141 \r
142         /* Set CMI2 and CMI3 priority levels so they nest. */\r
143         VIC.PRL23.LONG = _CMT_PRIORITY_LEVEL10;\r
144         VIC.PRL24.LONG = _CMT_PRIORITY_LEVEL9;\r
145 \r
146         /* Set CMI2 and CMI3 interrupt address. */\r
147 #warning Int 1 timer handler addresses not set.\r
148         VIC.VAD23.LONG = ( uint32_t ) NULL;\r
149         VIC.VAD24.LONG = ( uint32_t ) NULL;\r
150 \r
151     /* Enable CMI2 and CMI3 interrupts in ICU. */\r
152     VIC.IEN0.LONG |= ( 1UL << 23UL ) | ( 1UL << 24UL );\r
153 \r
154     /* Start CMT1 channel 0 and 1 count. */\r
155     CMT.CMSTR1.BIT.STR2 = 1U;\r
156         CMT.CMSTR1.BIT.STR3 = 1U;\r
157 }\r
158 /*-----------------------------------------------------------*/\r
159 \r
160 void vCMT_1_Channel_0_ISR( void )\r
161 {\r
162         /* Re-enabled interrupts. */\r
163         taskENABLE_INTERRUPTS();\r
164 \r
165         /* Call the handler that is part of the common code - this is where the\r
166         non-portable code ends and the actual test is performed. */\r
167         portYIELD_FROM_ISR( xFirstTimerHandler() );\r
168 }\r
169 /*-----------------------------------------------------------*/\r
170 \r
171 void vCMT_1_Channel_1_ISR( void )\r
172 {\r
173         /* Re-enabled interrupts. */\r
174         portENABLE_INTERRUPTS();\r
175 \r
176         /* Call the handler that is part of the common code - this is where the\r
177         non-portable code ends and the actual test is performed. */\r
178         portYIELD_FROM_ISR( xSecondTimerHandler() );\r
179 }\r
180 /*-----------------------------------------------------------*/\r
181 \r
182 \r
183 \r
184 \r
185 \r
186 \r