]> begriffs open source - cmsis-freertos/blob - Demo/RX600_RX64M_RSK_Renesas_e2studio/Source/IntQueueTimer.c
Updated pack to FreeRTOS 10.3.1
[cmsis-freertos] / Demo / RX600_RX64M_RSK_Renesas_e2studio / Source / IntQueueTimer.c
1 /*
2  * FreeRTOS Kernel V10.3.1
3  * Copyright (C) 2020 Amazon.com, Inc. or its affiliates.  All Rights Reserved.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of
6  * this software and associated documentation files (the "Software"), to deal in
7  * the Software without restriction, including without limitation the rights to
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9  * the Software, and to permit persons to whom the Software is furnished to do so,
10  * subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in all
13  * copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  *
22  * http://www.FreeRTOS.org
23  * http://aws.amazon.com/freertos
24  *
25  * 1 tab == 4 spaces!
26  */
27
28 /*
29  * This file contains the non-portable and therefore RX64M specific parts of
30  * the IntQueue standard demo task - namely the configuration of the timers
31  * that generate the interrupts and the interrupt entry points.
32  */
33
34 /* Scheduler includes. */
35 #include "FreeRTOS.h"
36 #include "task.h"
37
38 /* Demo includes. */
39 #include "IntQueueTimer.h"
40 #include "IntQueue.h"
41
42 /* Renesas includes. */
43 #include "r_cg_macrodriver.h"
44 #include "RegisterWriteProtect.h"
45
46 #define tmrTIMER_0_1_FREQUENCY  ( 2000UL )
47 #define tmrTIMER_2_3_FREQUENCY  ( 2001UL )
48
49 void vInitialiseTimerForIntQueueTest( void )
50 {
51         /* Ensure interrupts do not start until full configuration is complete. */
52         portENTER_CRITICAL();
53         {
54                 EnablePRCR( PRC1_BIT );
55
56                 /* Cascade two 8bit timer channels to generate the interrupts. 
57                 8bit timer unit 1 (TMR0 and TMR1) and 8bit timer unit 2 (TMR2 and TMR3 are
58                 utilised for this test. */
59
60                 /* Enable the timers. */
61                 SYSTEM.MSTPCRA.BIT.MSTPA5 = 0;
62                 SYSTEM.MSTPCRA.BIT.MSTPA4 = 0;
63
64                 /* Enable compare match A interrupt request. */
65                 TMR0.TCR.BIT.CMIEA = 1;
66                 TMR2.TCR.BIT.CMIEA = 1;
67
68                 /* Clear the timer on compare match A. */
69                 TMR0.TCR.BIT.CCLR = 1;
70                 TMR2.TCR.BIT.CCLR = 1;
71
72                 /* Set the compare match value. */
73                 TMR01.TCORA = ( unsigned short ) ( ( ( configPERIPHERAL_CLOCK_HZ / tmrTIMER_0_1_FREQUENCY ) -1 ) / 8 );
74                 TMR23.TCORA = ( unsigned short ) ( ( ( configPERIPHERAL_CLOCK_HZ / tmrTIMER_0_1_FREQUENCY ) -1 ) / 8 );
75
76                 /* 16 bit operation ( count from timer 1,2 ). */
77                 TMR0.TCCR.BIT.CSS = 3;
78                 TMR2.TCCR.BIT.CSS = 3;
79         
80                 /* Use PCLK as the input. */
81                 TMR1.TCCR.BIT.CSS = 1;
82                 TMR3.TCCR.BIT.CSS = 1;
83         
84                 /* Divide PCLK by 8. */
85                 TMR1.TCCR.BIT.CKS = 2;
86                 TMR3.TCCR.BIT.CKS = 2;
87
88                 /* Enable TMR 0, 2 interrupts. */
89                 TMR0.TCR.BIT.CMIEA = 1;
90                 TMR2.TCR.BIT.CMIEA = 1;
91
92                 /* Map TMR0 CMIA0 interrupt to vector slot B number 128 and set
93                 priority above the kernel's priority, but below the max syscall
94                 priority. */
95             ICU.SLIBXR128.BYTE = 3; /* Three is TMR0 compare match A. */
96             IPR( PERIB, INTB128 ) = configMAX_SYSCALL_INTERRUPT_PRIORITY - 1;
97                 IEN( PERIB, INTB128 ) = 1;
98
99                 /* Ensure that the flag is set to 0, otherwise the interrupt will not be
100                 accepted. */
101                 IR( PERIB, INTB128 ) = 0;
102
103                 /* Do the same for TMR2, but to vector 129. */
104             ICU.SLIBXR129.BYTE = 9; /* Nine is TMR2 compare match A. */
105             IPR( PERIB, INTB129 ) = configMAX_SYSCALL_INTERRUPT_PRIORITY - 2;
106                 IEN( PERIB, INTB129 ) = 1;
107                 IR( PERIB, INTB129 ) = 0;
108         }
109         portEXIT_CRITICAL();
110 }
111 /*-----------------------------------------------------------*/
112
113 #pragma interrupt ( Excep_PERIB_INTB128( vect = 128, enable ) )
114 void Excep_PERIB_INTB128( void )
115 {
116         portYIELD_FROM_ISR( xFirstTimerHandler() );
117 }
118 /*-----------------------------------------------------------*/
119
120 #pragma interrupt ( Excep_PERIB_INTB129( vect = 129, enable ) )
121 void Excep_PERIB_INTB129( void )
122 {
123         portYIELD_FROM_ISR( xSecondTimerHandler() );
124 }
125
126
127
128