]> begriffs open source - cmsis-freertos/blob - Demo/RX600_RX64M_RSK_GCC_e2studio/src/IntQueueTimer.c
Merge pull request #18 from davidskeck/develop
[cmsis-freertos] / Demo / RX600_RX64M_RSK_GCC_e2studio / src / IntQueueTimer.c
1 /*
2  * FreeRTOS Kernel V10.1.1
3  * Copyright (C) 2018 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 /* Hardware specifics. */
43 #include "iodefine.h"
44 #include "rskrx64mdef.h"
45
46 #define IPR_PERIB_INTB128       128
47 #define IPR_PERIB_INTB129       129
48 #define IER_PERIB_INTB128       0x10
49 #define IER_PERIB_INTB129       0x10
50 #define IEN_PERIB_INTB128       IEN0
51 #define IEN_PERIB_INTB129       IEN1
52 #define IR_PERIB_INTB128        128
53 #define IR_PERIB_INTB129        129
54
55 void vIntQTimerISR0( void ) __attribute__ ((interrupt));
56 void vIntQTimerISR1( void ) __attribute__ ((interrupt));
57
58 #define tmrTIMER_0_1_FREQUENCY  ( 2000UL )
59 #define tmrTIMER_2_3_FREQUENCY  ( 2001UL )
60
61 void vInitialiseTimerForIntQueueTest( void )
62 {
63         /* Ensure interrupts do not start until full configuration is complete. */
64         portENTER_CRITICAL();
65         {
66                 /* Give write access. */
67                 SYSTEM.PRCR.WORD = 0xa502;
68
69                 /* Cascade two 8bit timer channels to generate the interrupts. 
70                 8bit timer unit 1 (TMR0 and TMR1) and 8bit timer unit 2 (TMR2 and TMR3 are
71                 utilised for this test. */
72
73                 /* Enable the timers. */
74                 SYSTEM.MSTPCRA.BIT.MSTPA5 = 0;
75                 SYSTEM.MSTPCRA.BIT.MSTPA4 = 0;
76
77                 /* Enable compare match A interrupt request. */
78                 TMR0.TCR.BIT.CMIEA = 1;
79                 TMR2.TCR.BIT.CMIEA = 1;
80
81                 /* Clear the timer on compare match A. */
82                 TMR0.TCR.BIT.CCLR = 1;
83                 TMR2.TCR.BIT.CCLR = 1;
84
85                 /* Set the compare match value. */
86                 TMR01.TCORA = ( unsigned short ) ( ( ( configPERIPHERAL_CLOCK_HZ / tmrTIMER_0_1_FREQUENCY ) -1 ) / 8 );
87                 TMR23.TCORA = ( unsigned short ) ( ( ( configPERIPHERAL_CLOCK_HZ / tmrTIMER_0_1_FREQUENCY ) -1 ) / 8 );
88
89                 /* 16 bit operation ( count from timer 1,2 ). */
90                 TMR0.TCCR.BIT.CSS = 3;
91                 TMR2.TCCR.BIT.CSS = 3;
92         
93                 /* Use PCLK as the input. */
94                 TMR1.TCCR.BIT.CSS = 1;
95                 TMR3.TCCR.BIT.CSS = 1;
96         
97                 /* Divide PCLK by 8. */
98                 TMR1.TCCR.BIT.CKS = 2;
99                 TMR3.TCCR.BIT.CKS = 2;
100
101                 /* Enable TMR 0, 2 interrupts. */
102                 TMR0.TCR.BIT.CMIEA = 1;
103                 TMR2.TCR.BIT.CMIEA = 1;
104
105                 /* Map TMR0 CMIA0 interrupt to vector slot B number 128 and set
106                 priority above the kernel's priority, but below the max syscall
107                 priority. */
108             ICU.SLIBXR128.BYTE = 3; /* Three is TMR0 compare match A. */
109             IPR( PERIB, INTB128 ) = configMAX_SYSCALL_INTERRUPT_PRIORITY - 1;
110                 IEN( PERIB, INTB128 ) = 1;
111
112                 /* Ensure that the flag is set to 0, otherwise the interrupt will not be
113                 accepted. */
114                 IR( PERIB, INTB128 ) = 0;
115
116                 /* Do the same for TMR2, but to vector 129. */
117             ICU.SLIBXR129.BYTE = 9; /* Nine is TMR2 compare match A. */
118             IPR( PERIB, INTB129 ) = configMAX_SYSCALL_INTERRUPT_PRIORITY - 2;
119                 IEN( PERIB, INTB129 ) = 1;
120                 IR( PERIB, INTB129 ) = 0;
121         }
122         portEXIT_CRITICAL();
123 }
124 /*-----------------------------------------------------------*/
125
126 /* On vector 128. */
127 void vIntQTimerISR0( void )
128 {
129         /* Enable interrupts to allow interrupt nesting. */
130         __asm volatile( "setpsw i" );
131
132         portYIELD_FROM_ISR( xFirstTimerHandler() );
133 }
134 /*-----------------------------------------------------------*/
135
136 /* On vector 129. */
137 void vIntQTimerISR1( void )
138 {
139         /* Enable interrupts to allow interrupt nesting. */
140         __asm volatile( "setpsw i" );
141
142         portYIELD_FROM_ISR( xSecondTimerHandler() );
143 }
144
145
146
147