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
29 /* FreeRTOS includes. */
\r
30 #include "FreeRTOS.h"
\r
32 /* Standard demo includes. */
\r
33 #include "IntQueueTimer.h"
\r
34 #include "IntQueue.h"
\r
36 /* Microchip includes. */
\r
37 #include "MEC14xx/mec14xx_timers.h"
\r
38 #include "MEC14xx/mec14xx_jtvic.h"
\r
39 #include "MEC14xx/mec14xx.h"
\r
41 /* The frequency of the two timers is offset so the time between the timers
\r
42 expiring is not always the same. */
\r
43 #define timerINTERRUPT0_FREQUENCY ( 2000UL )
\r
44 #define timerINTERRUPT1_FREQUENCY ( 2221UL )
\r
46 /* MEC14xx JTVIC external interrupt controller is mapped to M14K closely-coupled
\r
47 peripheral space. */
\r
48 #define portMMCR_JTVIC_GIRQ23_PRIA *((volatile uint32_t *)(0xBFFFC3F0ul))
\r
50 /*-----------------------------------------------------------*/
\r
52 /* These are the C handlers called from the asm wrappers. */
\r
53 void vT0InterruptHandler( void );
\r
54 void vT1InterruptHandler( void );
\r
56 /*-----------------------------------------------------------*/
\r
58 void vInitialiseTimerForIntQueueTest( void )
\r
60 /* Timer RT is used for the tick interrupt, timer 3 is used for the high
\r
61 frequency interrupt test. This file therefore uses timers 0 and 1. */
\r
62 uint32_t ulPreload = ( unsigned short ) ( ( configPERIPHERAL_CLOCK_HZ / ( unsigned long ) timerINTERRUPT0_FREQUENCY ) );
\r
64 btmr_sleep_en( BTMR0_ID, 0 );
\r
65 btmr_init( BTMR0_ID, BTMR_COUNT_DOWN + BTMR_AUTO_RESTART + BTMR_INT_EN, 0, ulPreload, ulPreload );
\r
66 btmr_start( BTMR0_ID );
\r
68 jtvic_clr_source( MEC14xx_GIRQ23_ID, 0 );
\r
69 portMMCR_JTVIC_GIRQ23_PRIA &= ~( 0x0Ful << 0 );
\r
70 portMMCR_JTVIC_GIRQ23_PRIA |= ( ( portIPL_TO_CODE( configMAX_SYSCALL_INTERRUPT_PRIORITY ) ) << 0 );
\r
71 jtvic_en_source( MEC14xx_GIRQ23_ID, 0, pdTRUE );
\r
73 ulPreload = ( unsigned short ) ( ( configPERIPHERAL_CLOCK_HZ / ( unsigned long ) timerINTERRUPT1_FREQUENCY ) );
\r
74 btmr_sleep_en( BTMR1_ID, 0 );
\r
75 btmr_init( BTMR1_ID, BTMR_COUNT_DOWN + BTMR_AUTO_RESTART + BTMR_INT_EN, 0, ulPreload, ulPreload );
\r
76 btmr_start( BTMR1_ID );
\r
78 jtvic_clr_source( MEC14xx_GIRQ23_ID, 1 );
\r
79 portMMCR_JTVIC_GIRQ23_PRIA &= ~( 0x0Ful << 4 );
\r
80 portMMCR_JTVIC_GIRQ23_PRIA |= ( ( portIPL_TO_CODE( configMAX_SYSCALL_INTERRUPT_PRIORITY ) ) << 4 );
\r
81 jtvic_en_source( MEC14xx_GIRQ23_ID, 1, pdTRUE );
\r
83 /*-----------------------------------------------------------*/
\r
85 void vT0InterruptHandler( void )
\r
87 /* Disable all interrupts because the source bit is shared with a bit used
\r
88 by the other timer and the high frequency timer test. */
\r
89 __asm volatile( "di" );
\r
90 /* Clear the timer interrupt. */
\r
91 jtvic_clr_source( MEC14xx_GIRQ23_ID, 0 );
\r
92 __asm volatile( "ei" );
\r
94 portEND_SWITCHING_ISR( xFirstTimerHandler() );
\r
96 /*-----------------------------------------------------------*/
\r
98 void vT1InterruptHandler( void )
\r
100 /* Disable all interrupts because the source bit is shared with a bit used
\r
101 by the other timer and the high frequency timer test. */
\r
102 __asm volatile( "di" );
\r
103 /* Clear the timer interrupt. */
\r
104 jtvic_clr_source( MEC14xx_GIRQ23_ID, 1 );
\r
105 __asm volatile( "ei" );
\r
107 portEND_SWITCHING_ISR( xSecondTimerHandler() );
\r