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