]> begriffs open source - cmsis-freertos/blob - Demo/PIC32MZ_MPLAB/IntQueueTimer.c
osEventFlagsWait: Fix flag comparison
[cmsis-freertos] / Demo / PIC32MZ_MPLAB / IntQueueTimer.c
1 /*
2  * FreeRTOS Kernel V10.2.1
3  * Copyright (C) 2019 Amazon.com, Inc. or its affiliates.  All Rights Reserved.
4  *
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:
11  *
12  * The above copyright notice and this permission notice shall be included in all
13  * copies or substantial portions of the Software.
14  *
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.
21  *
22  * http://www.FreeRTOS.org
23  * http://aws.amazon.com/freertos
24  *
25  * 1 tab == 4 spaces!
26  */
27
28 #include "FreeRTOS.h"
29 #include "IntQueueTimer.h"
30 #include "IntQueue.h"
31
32 #define timerINTERRUPT3_FREQUENCY       ( 2000UL )
33 #define timerINTERRUPT4_FREQUENCY       ( 2001UL )
34
35 void vT3InterruptHandler( void );
36 void vT4InterruptHandler( void );
37
38 /* As these interrupts use the FreeRTOS interrupt entry point, the IPL settings
39 in the following prototypes have no effect.  The interrupt priorities are set
40 by the ConfigIntTimerX() library calls in vInitialiseTimerForIntQueueTest(). */
41 void __attribute__( (interrupt(IPL0AUTO), vector(_TIMER_3_VECTOR))) vT3InterruptWrapper( void );
42 void __attribute__( (interrupt(IPL0AUTO), vector(_TIMER_4_VECTOR))) vT4InterruptWrapper( void );
43
44 void vInitialiseTimerForIntQueueTest( void )
45 {
46         /* Timer 1 is used for the tick interrupt, timer 2 is used for the high
47         frequency interrupt test.  This file therefore uses timers 3 and 4. */
48
49         T3CON = 0;
50         TMR3 = 0;
51         PR3 = ( unsigned short ) ( configPERIPHERAL_CLOCK_HZ / timerINTERRUPT3_FREQUENCY );
52
53         /* Setup timer 3 interrupt priority to be above the kernel priority. */
54         IPC3bits.T3IP = ( configMAX_SYSCALL_INTERRUPT_PRIORITY - 1 );
55
56         /* Clear the interrupt as a starting condition. */
57         IFS0bits.T3IF = 0;
58
59         /* Enable the interrupt. */
60         IEC0bits.T3IE = 1;
61
62         /* Start the timer. */
63         T3CONbits.TON = 1;
64
65
66         /* Do the same for timer 4. */
67         T4CON = 0;
68         TMR4 = 0;
69         PR4 = ( unsigned short ) ( configPERIPHERAL_CLOCK_HZ / timerINTERRUPT4_FREQUENCY );
70
71         /* Setup timer 4 interrupt priority to be above the kernel priority. */
72         IPC4bits.T4IP = configMAX_SYSCALL_INTERRUPT_PRIORITY;
73
74         /* Clear the interrupt as a starting condition. */
75         IFS0bits.T4IF = 0;
76
77         /* Enable the interrupt. */
78         IEC0bits.T4IE = 1;
79
80         /* Start the timer. */
81         T4CONbits.TON = 1;
82 }
83 /*-----------------------------------------------------------*/
84
85 void vT3InterruptHandler( void )
86 {
87         IFS0CLR = _IFS0_T3IF_MASK;
88         portEND_SWITCHING_ISR( xFirstTimerHandler() );
89 }
90 /*-----------------------------------------------------------*/
91
92 void vT4InterruptHandler( void )
93 {
94         IFS0CLR = _IFS0_T4IF_MASK;
95         portEND_SWITCHING_ISR( xSecondTimerHandler() );
96 }
97
98