]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/RX100_RX113-RSK_GCC_e2studio_IAR/src/Full_Demo/IntQueueTimer.c
Update to MIT licensed FreeRTOS V10.0.0 - see https://www.freertos.org/History.txt
[freertos] / FreeRTOS / Demo / RX100_RX113-RSK_GCC_e2studio_IAR / src / Full_Demo / IntQueueTimer.c
1 /*\r
2  * FreeRTOS Kernel V10.0.0\r
3  * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
4  *\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
11  *\r
12  * The above copyright notice and this permission notice shall be included in all\r
13  * copies or substantial portions of the Software. If you wish to use our Amazon\r
14  * FreeRTOS name, please do so in a fair use way that does not cause confusion.\r
15  *\r
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
18  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
19  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
20  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
21  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
22  *\r
23  * http://www.FreeRTOS.org\r
24  * http://aws.amazon.com/freertos\r
25  *\r
26  * 1 tab == 4 spaces!\r
27  */\r
28 \r
29 /*\r
30  * This file contains the non-portable and therefore RX62N specific parts of\r
31  * the IntQueue standard demo task - namely the configuration of the timers\r
32  * that generate the interrupts and the interrupt entry points.\r
33  *\r
34  * ***NOTE***: When using GCC it is best to compile this file with maximum speed\r
35  * optimisation - otherwise standard demo tasks that monitor their own\r
36  * performance might fail assertion tests.\r
37  */\r
38 \r
39 /* Scheduler includes. */\r
40 #include "FreeRTOS.h"\r
41 #include "task.h"\r
42 \r
43 /* Demo includes. */\r
44 #include "IntQueueTimer.h"\r
45 #include "IntQueue.h"\r
46 \r
47 #define tmrTIMER_0_1_FREQUENCY  ( 2000UL )\r
48 #define tmrTIMER_2_3_FREQUENCY  ( 2007UL )\r
49 \r
50 void vInitialiseTimerForIntQueueTest( void )\r
51 {\r
52         /* Ensure interrupts do not start until full configuration is complete. */\r
53         portENTER_CRITICAL();\r
54         {\r
55                 /* Give write access. */\r
56                 SYSTEM.PRCR.WORD = 0xa502;\r
57 \r
58                 /* Cascade two 8bit timer channels to generate the interrupts.\r
59                 8bit timer unit 1 (TMR0 and TMR1) and 8bit timer unit 2 (TMR2 and TMR3 are\r
60                 utilised for this test. */\r
61 \r
62                 /* Enable the timers. */\r
63                 SYSTEM.MSTPCRA.BIT.MSTPA5 = 0;\r
64                 SYSTEM.MSTPCRA.BIT.MSTPA4 = 0;\r
65 \r
66                 /* Enable compare match A interrupt request. */\r
67                 TMR0.TCR.BIT.CMIEA = 1;\r
68                 TMR2.TCR.BIT.CMIEA = 1;\r
69 \r
70                 /* Clear the timer on compare match A. */\r
71                 TMR0.TCR.BIT.CCLR = 1;\r
72                 TMR2.TCR.BIT.CCLR = 1;\r
73 \r
74                 /* Set the compare match value. */\r
75                 TMR01.TCORA = ( unsigned short ) ( ( ( configPERIPHERAL_CLOCK_HZ / tmrTIMER_0_1_FREQUENCY ) -1 ) / 8 );\r
76                 TMR23.TCORA = ( unsigned short ) ( ( ( configPERIPHERAL_CLOCK_HZ / tmrTIMER_0_1_FREQUENCY ) -1 ) / 8 );\r
77 \r
78                 /* 16 bit operation ( count from timer 1,2 ). */\r
79                 TMR0.TCCR.BIT.CSS = 3;\r
80                 TMR2.TCCR.BIT.CSS = 3;\r
81 \r
82                 /* Use PCLK as the input. */\r
83                 TMR1.TCCR.BIT.CSS = 1;\r
84                 TMR3.TCCR.BIT.CSS = 1;\r
85 \r
86                 /* Divide PCLK by 8. */\r
87                 TMR1.TCCR.BIT.CKS = 2;\r
88                 TMR3.TCCR.BIT.CKS = 2;\r
89 \r
90                 /* Enable TMR 0, 2 interrupts. */\r
91                 TMR0.TCR.BIT.CMIEA = 1;\r
92                 TMR2.TCR.BIT.CMIEA = 1;\r
93 \r
94                 /* Set interrupt priority and enable. */\r
95                 IPR( TMR0, CMIA0 ) = configMAX_SYSCALL_INTERRUPT_PRIORITY - 1;\r
96                 IR( TMR0, CMIA0 ) = 0U;\r
97                 IEN( TMR0, CMIA0 ) = 1U;\r
98 \r
99                 /* Do the same for TMR2, but to vector 129. */\r
100                 IPR( TMR2, CMIA2 ) = configMAX_SYSCALL_INTERRUPT_PRIORITY - 2;\r
101                 IR( TMR2, CMIA2 ) = 0U;\r
102                 IEN( TMR2, CMIA2 ) = 1U;\r
103         }\r
104         portEXIT_CRITICAL();\r
105 }\r
106 /*-----------------------------------------------------------*/\r
107 \r
108 #ifdef __GNUC__\r
109 \r
110         void vIntQTimerISR0( void ) __attribute__ ((interrupt));\r
111         void vIntQTimerISR1( void ) __attribute__ ((interrupt));\r
112 \r
113         void vIntQTimerISR0( void )\r
114         {\r
115                 /* Enable interrupts to allow interrupt nesting. */\r
116                 __asm volatile( "setpsw i" );\r
117 \r
118                 portYIELD_FROM_ISR( xFirstTimerHandler() );\r
119         }\r
120         /*-----------------------------------------------------------*/\r
121 \r
122         void vIntQTimerISR1( void )\r
123         {\r
124                 /* Enable interrupts to allow interrupt nesting. */\r
125                 __asm volatile( "setpsw i" );\r
126 \r
127                 portYIELD_FROM_ISR( xSecondTimerHandler() );\r
128         }\r
129 \r
130 #endif /* __GNUC__ */\r
131 \r
132 #ifdef __ICCRX__\r
133 \r
134 #pragma vector = VECT_TMR0_CMIA0\r
135 __interrupt void vT0_1InterruptHandler( void )\r
136 {\r
137         __enable_interrupt();\r
138         portYIELD_FROM_ISR( xFirstTimerHandler() );\r
139 }\r
140 /*-----------------------------------------------------------*/\r
141 \r
142 #pragma vector = VECT_TMR2_CMIA2\r
143 __interrupt void vT2_3InterruptHandler( void )\r
144 {\r
145         __enable_interrupt();\r
146         portYIELD_FROM_ISR( xSecondTimerHandler() );\r
147 }\r
148 \r
149 #endif /* __ICCRX__ */\r
150 \r