2 * FreeRTOS Kernel V10.1.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.
\r
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
17 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
18 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
19 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
22 * http://www.FreeRTOS.org
\r
23 * http://aws.amazon.com/freertos
\r
25 * 1 tab == 4 spaces!
\r
28 /* FreeRTOS includes. */
\r
29 #include "FreeRTOS.h"
\r
31 /* Standard demo includes. */
\r
32 #include "IntQueueTimer.h"
\r
33 #include "IntQueue.h"
\r
35 /* Microchip includes. */
\r
36 #include "MEC14xx/mec14xx_timers.h"
\r
37 #include "MEC14xx/mec14xx_jtvic.h"
\r
38 #include "MEC14xx/mec14xx.h"
\r
40 /* The frequency of the two timers is offset so the time between the timers
\r
41 expiring is not always the same. */
\r
42 #define timerINTERRUPT0_FREQUENCY ( 2000UL )
\r
43 #define timerINTERRUPT1_FREQUENCY ( 2221UL )
\r
45 /* MEC14xx JTVIC external interrupt controller is mapped to M14K closely-coupled
\r
46 peripheral space. */
\r
47 #define portMMCR_JTVIC_GIRQ23_PRIA *((volatile uint32_t *)(0xBFFFC3F0ul))
\r
49 /*-----------------------------------------------------------*/
\r
51 /* These are the C handlers called from the asm wrappers. */
\r
52 void vT0InterruptHandler( void );
\r
53 void vT1InterruptHandler( void );
\r
55 /*-----------------------------------------------------------*/
\r
57 void vInitialiseTimerForIntQueueTest( void )
\r
59 /* Timer RT is used for the tick interrupt, timer 3 is used for the high
\r
60 frequency interrupt test. This file therefore uses timers 0 and 1. */
\r
61 uint32_t ulPreload = ( unsigned short ) ( ( configPERIPHERAL_CLOCK_HZ / ( unsigned long ) timerINTERRUPT0_FREQUENCY ) );
\r
63 btmr_sleep_en( BTMR0_ID, 0 );
\r
64 btmr_init( BTMR0_ID, BTMR_COUNT_DOWN + BTMR_AUTO_RESTART + BTMR_INT_EN, 0, ulPreload, ulPreload );
\r
65 btmr_start( BTMR0_ID );
\r
67 jtvic_clr_source( MEC14xx_GIRQ23_ID, 0 );
\r
68 portMMCR_JTVIC_GIRQ23_PRIA &= ~( 0x0Ful << 0 );
\r
69 portMMCR_JTVIC_GIRQ23_PRIA |= ( ( portIPL_TO_CODE( configMAX_SYSCALL_INTERRUPT_PRIORITY ) ) << 0 );
\r
70 jtvic_en_source( MEC14xx_GIRQ23_ID, 0, pdTRUE );
\r
72 ulPreload = ( unsigned short ) ( ( configPERIPHERAL_CLOCK_HZ / ( unsigned long ) timerINTERRUPT1_FREQUENCY ) );
\r
73 btmr_sleep_en( BTMR1_ID, 0 );
\r
74 btmr_init( BTMR1_ID, BTMR_COUNT_DOWN + BTMR_AUTO_RESTART + BTMR_INT_EN, 0, ulPreload, ulPreload );
\r
75 btmr_start( BTMR1_ID );
\r
77 jtvic_clr_source( MEC14xx_GIRQ23_ID, 1 );
\r
78 portMMCR_JTVIC_GIRQ23_PRIA &= ~( 0x0Ful << 4 );
\r
79 portMMCR_JTVIC_GIRQ23_PRIA |= ( ( portIPL_TO_CODE( configMAX_SYSCALL_INTERRUPT_PRIORITY ) ) << 4 );
\r
80 jtvic_en_source( MEC14xx_GIRQ23_ID, 1, pdTRUE );
\r
82 /*-----------------------------------------------------------*/
\r
84 void vT0InterruptHandler( void )
\r
86 /* Disable all interrupts because the source bit is shared with a bit used
\r
87 by the other timer and the high frequency timer test. */
\r
88 __asm volatile( "di" );
\r
89 /* Clear the timer interrupt. */
\r
90 jtvic_clr_source( MEC14xx_GIRQ23_ID, 0 );
\r
91 __asm volatile( "ei" );
\r
93 portEND_SWITCHING_ISR( xFirstTimerHandler() );
\r
95 /*-----------------------------------------------------------*/
\r
97 void vT1InterruptHandler( void )
\r
99 /* Disable all interrupts because the source bit is shared with a bit used
\r
100 by the other timer and the high frequency timer test. */
\r
101 __asm volatile( "di" );
\r
102 /* Clear the timer interrupt. */
\r
103 jtvic_clr_source( MEC14xx_GIRQ23_ID, 1 );
\r
104 __asm volatile( "ei" );
\r
106 portEND_SWITCHING_ISR( xSecondTimerHandler() );
\r