2 * FreeRTOS Kernel V10.0.0
\r
3 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
\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
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
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
23 * http://www.FreeRTOS.org
\r
24 * http://aws.amazon.com/freertos
\r
26 * 1 tab == 4 spaces!
\r
30 * This file contains the non-portable and therefore RX64M 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
35 /* Scheduler includes. */
\r
36 #include "FreeRTOS.h"
\r
39 /* Demo includes. */
\r
40 #include "IntQueueTimer.h"
\r
41 #include "IntQueue.h"
\r
43 /* Hardware specifics. */
\r
44 #include "iodefine.h"
\r
45 #include "rskrx64mdef.h"
\r
47 #define IPR_PERIB_INTB128 128
\r
48 #define IPR_PERIB_INTB129 129
\r
49 #define IER_PERIB_INTB128 0x10
\r
50 #define IER_PERIB_INTB129 0x10
\r
51 #define IEN_PERIB_INTB128 IEN0
\r
52 #define IEN_PERIB_INTB129 IEN1
\r
53 #define IR_PERIB_INTB128 128
\r
54 #define IR_PERIB_INTB129 129
\r
56 void vIntQTimerISR0( void ) __attribute__ ((interrupt));
\r
57 void vIntQTimerISR1( void ) __attribute__ ((interrupt));
\r
59 #define tmrTIMER_0_1_FREQUENCY ( 2000UL )
\r
60 #define tmrTIMER_2_3_FREQUENCY ( 2001UL )
\r
62 void vInitialiseTimerForIntQueueTest( void )
\r
64 /* Ensure interrupts do not start until full configuration is complete. */
\r
65 portENTER_CRITICAL();
\r
67 /* Give write access. */
\r
68 SYSTEM.PRCR.WORD = 0xa502;
\r
70 /* Cascade two 8bit timer channels to generate the interrupts.
\r
71 8bit timer unit 1 (TMR0 and TMR1) and 8bit timer unit 2 (TMR2 and TMR3 are
\r
72 utilised for this test. */
\r
74 /* Enable the timers. */
\r
75 SYSTEM.MSTPCRA.BIT.MSTPA5 = 0;
\r
76 SYSTEM.MSTPCRA.BIT.MSTPA4 = 0;
\r
78 /* Enable compare match A interrupt request. */
\r
79 TMR0.TCR.BIT.CMIEA = 1;
\r
80 TMR2.TCR.BIT.CMIEA = 1;
\r
82 /* Clear the timer on compare match A. */
\r
83 TMR0.TCR.BIT.CCLR = 1;
\r
84 TMR2.TCR.BIT.CCLR = 1;
\r
86 /* Set the compare match value. */
\r
87 TMR01.TCORA = ( unsigned short ) ( ( ( configPERIPHERAL_CLOCK_HZ / tmrTIMER_0_1_FREQUENCY ) -1 ) / 8 );
\r
88 TMR23.TCORA = ( unsigned short ) ( ( ( configPERIPHERAL_CLOCK_HZ / tmrTIMER_0_1_FREQUENCY ) -1 ) / 8 );
\r
90 /* 16 bit operation ( count from timer 1,2 ). */
\r
91 TMR0.TCCR.BIT.CSS = 3;
\r
92 TMR2.TCCR.BIT.CSS = 3;
\r
94 /* Use PCLK as the input. */
\r
95 TMR1.TCCR.BIT.CSS = 1;
\r
96 TMR3.TCCR.BIT.CSS = 1;
\r
98 /* Divide PCLK by 8. */
\r
99 TMR1.TCCR.BIT.CKS = 2;
\r
100 TMR3.TCCR.BIT.CKS = 2;
\r
102 /* Enable TMR 0, 2 interrupts. */
\r
103 TMR0.TCR.BIT.CMIEA = 1;
\r
104 TMR2.TCR.BIT.CMIEA = 1;
\r
106 /* Map TMR0 CMIA0 interrupt to vector slot B number 128 and set
\r
107 priority above the kernel's priority, but below the max syscall
\r
109 ICU.SLIBXR128.BYTE = 3; /* Three is TMR0 compare match A. */
\r
110 IPR( PERIB, INTB128 ) = configMAX_SYSCALL_INTERRUPT_PRIORITY - 1;
\r
111 IEN( PERIB, INTB128 ) = 1;
\r
113 /* Ensure that the flag is set to 0, otherwise the interrupt will not be
\r
115 IR( PERIB, INTB128 ) = 0;
\r
117 /* Do the same for TMR2, but to vector 129. */
\r
118 ICU.SLIBXR129.BYTE = 9; /* Nine is TMR2 compare match A. */
\r
119 IPR( PERIB, INTB129 ) = configMAX_SYSCALL_INTERRUPT_PRIORITY - 2;
\r
120 IEN( PERIB, INTB129 ) = 1;
\r
121 IR( PERIB, INTB129 ) = 0;
\r
123 portEXIT_CRITICAL();
\r
125 /*-----------------------------------------------------------*/
\r
127 /* On vector 128. */
\r
128 void vIntQTimerISR0( void )
\r
130 /* Enable interrupts to allow interrupt nesting. */
\r
131 __asm volatile( "setpsw i" );
\r
133 portYIELD_FROM_ISR( xFirstTimerHandler() );
\r
135 /*-----------------------------------------------------------*/
\r
137 /* On vector 129. */
\r
138 void vIntQTimerISR1( void )
\r
140 /* Enable interrupts to allow interrupt nesting. */
\r
141 __asm volatile( "setpsw i" );
\r
143 portYIELD_FROM_ISR( xSecondTimerHandler() );
\r