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 /* High speed timer test as described in main.c. */
\r
32 /* Scheduler includes. */
\r
33 #include "FreeRTOS.h"
\r
35 /* The maximum value the 16bit timer can contain. */
\r
36 #define timerMAX_COUNT 0xffff
\r
38 /* The timer 2 interrupt handler. As this interrupt uses the FreeRTOS assembly
\r
39 entry point the IPL setting in the following function prototype has no effect.
\r
40 The interrupt priority is set by ConfigIntTimer2() in vSetupTimerTest(). */
\r
41 void __attribute__( (interrupt(IPL0AUTO), vector(_TIMER_2_VECTOR))) vT2InterruptWrapper( void );
\r
43 /*-----------------------------------------------------------*/
\r
45 /* Incremented every 20,000 interrupts, so should count in seconds. */
\r
46 unsigned long ulHighFrequencyTimerInterrupts = 0;
\r
48 /* The frequency at which the timer is interrupting. */
\r
49 static unsigned long ulFrequencyHz;
\r
51 /*-----------------------------------------------------------*/
\r
53 void vSetupTimerTest( unsigned short usFrequencyHz )
\r
55 /* Remember the frequency so it can be used from the ISR. */
\r
56 ulFrequencyHz = ( unsigned long ) usFrequencyHz;
\r
58 /* T2 is used to generate interrupts above the kernel and max syscall interrupt
\r
63 /* Timer 2 is going to interrupt at usFrequencyHz Hz. */
\r
64 PR2 = ( unsigned short ) ( ( configPERIPHERAL_CLOCK_HZ / ( unsigned long ) usFrequencyHz ) - 1 );
\r
66 /* Setup timer 2 interrupt priority to be above the kernel priority so
\r
67 the timer jitter is not effected by the kernel activity. */
\r
68 IPC2bits.T2IP = ( configMAX_SYSCALL_INTERRUPT_PRIORITY + 1 );
\r
70 /* Clear the interrupt as a starting condition. */
\r
73 /* Enable the interrupt. */
\r
76 /* Start the timer. */
\r
79 /*-----------------------------------------------------------*/
\r
81 void vT2InterruptHandler( void )
\r
83 static unsigned long ulCalls = 0;
\r
86 if( ulCalls >= ulFrequencyHz )
\r
88 /* Increment the count that will be shown on the LCD.
\r
89 The increment occurs once every 20,000 interrupts so
\r
90 ulHighFrequencyTimerInterrupts should count in seconds. */
\r
91 ulHighFrequencyTimerInterrupts++;
\r
95 /* Clear the timer interrupt. */
\r
96 IFS0CLR = _IFS0_T2IF_MASK;
\r