2 * FreeRTOS Kernel V10.3.1
3 * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
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:
12 * The above copyright notice and this permission notice shall be included in all
13 * copies or substantial portions of the Software.
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.
22 * http://www.FreeRTOS.org
23 * http://aws.amazon.com/freertos
29 * This file contains the non-portable and therefore RX62N 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.
34 /* Scheduler includes. */
39 #include "IntQueueTimer.h"
42 /* Hardware specifics. */
45 #define tmrTIMER_0_1_FREQUENCY ( 2000UL )
46 #define tmrTIMER_2_3_FREQUENCY ( 2001UL )
48 /* Handlers for the two timers used. */
49 __interrupt void vT0_1InterruptHandler( void );
50 __interrupt void vT2_3InterruptHandler( void );
52 void vInitialiseTimerForIntQueueTest( void )
54 /* Ensure interrupts do not start until full configuration is complete. */
57 /* Cascade two 8bit timer channels to generate the interrupts.
58 8bit timer unit 1 (TMR0 and TMR1) and 8bit timer unit 2 (TMR2 and TMR3 are
59 utilised for this test. */
61 /* Enable the timers. */
62 SYSTEM.MSTPCRA.BIT.MSTPA5 = 0;
63 SYSTEM.MSTPCRA.BIT.MSTPA4 = 0;
65 /* Enable compare match A interrupt request. */
66 TMR0.TCR.BIT.CMIEA = 1;
67 TMR2.TCR.BIT.CMIEA = 1;
69 /* Clear the timer on compare match A. */
70 TMR0.TCR.BIT.CCLR = 1;
71 TMR2.TCR.BIT.CCLR = 1;
73 /* Set the compare match value. */
74 TMR01.TCORA = ( unsigned short ) ( ( ( configPERIPHERAL_CLOCK_HZ / tmrTIMER_0_1_FREQUENCY ) -1 ) / 8 );
75 TMR23.TCORA = ( unsigned short ) ( ( ( configPERIPHERAL_CLOCK_HZ / tmrTIMER_0_1_FREQUENCY ) -1 ) / 8 );
77 /* 16 bit operation ( count from timer 1,2 ). */
78 TMR0.TCCR.BIT.CSS = 3;
79 TMR2.TCCR.BIT.CSS = 3;
81 /* Use PCLK as the input. */
82 TMR1.TCCR.BIT.CSS = 1;
83 TMR3.TCCR.BIT.CSS = 1;
85 /* Divide PCLK by 8. */
86 TMR1.TCCR.BIT.CKS = 2;
87 TMR3.TCCR.BIT.CKS = 2;
89 /* Enable TMR 0, 2 interrupts. */
90 IEN( TMR0, CMIA0 ) = 1;
91 IEN( TMR2, CMIA2 ) = 1;
93 /* Set the timer interrupts to be above the kernel. The interrupts are
94 assigned different priorities so they nest with each other. */
95 IPR( TMR0, CMIA0 ) = configMAX_SYSCALL_INTERRUPT_PRIORITY - 1;
96 IPR( TMR2, CMIA2 ) = ( configMAX_SYSCALL_INTERRUPT_PRIORITY - 2 );
100 /* Ensure the interrupts are clear as they are edge detected. */
101 IR( TMR0, CMIA0 ) = 0;
102 IR( TMR2, CMIA2 ) = 0;
104 /*-----------------------------------------------------------*/
106 #pragma vector = VECT_TMR0_CMIA0
107 __interrupt void vT0_1InterruptHandler( void )
109 __enable_interrupt();
110 portYIELD_FROM_ISR( xFirstTimerHandler() );
112 /*-----------------------------------------------------------*/
114 #pragma vector = VECT_TMR2_CMIA2
115 __interrupt void vT2_3InterruptHandler( void )
117 __enable_interrupt();
118 portYIELD_FROM_ISR( xSecondTimerHandler() );