]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_M4F_MSP432_LaunchPad_IAR_CCS_Keil/Full_Demo/IntQueueTimer.c
0324777ad05cff5e5722ce8150bc6d2d03dda63e
[freertos] / FreeRTOS / Demo / CORTEX_M4F_MSP432_LaunchPad_IAR_CCS_Keil / Full_Demo / 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 /*\r
29  * This file initialises the two timers available in the Timer32 peripheral.\r
30  *\r
31  * Channels 0 and 1 provide the interrupts that are used with the IntQ\r
32  * standard demo tasks, which test interrupt nesting and using queues from\r
33  * interrupts.\r
34  */\r
35 \r
36 /* Scheduler includes. */\r
37 #include "FreeRTOS.h"\r
38 \r
39 /* Demo includes. */\r
40 #include "IntQueueTimer.h"\r
41 #include "IntQueue.h"\r
42 \r
43 /* The frequencies at which the two timers expire are slightly offset to ensure\r
44 they don't remain synchronised. */\r
45 #define tmrTIMER_0_FREQUENCY    ( 2000UL )\r
46 #define tmrTIMER_1_FREQUENCY    ( 2003UL )\r
47 \r
48 /* The interrupts use the FreeRTOS API so must be at or below the max syscall\r
49 interrupt priority.  Counter-intuitively, the higher the numeric number the\r
50 lower the logical priority. http://www.freertos.org/RTOS-Cortex-M3-M4.html */\r
51 #define tmrLOWER_PRIORITY               ( configMAX_SYSCALL_INTERRUPT_PRIORITY )\r
52 #define tmrHIGHER_PRIORITY              ( configMAX_SYSCALL_INTERRUPT_PRIORITY + 1 )\r
53 /*-----------------------------------------------------------*/\r
54 \r
55 /* Handlers for the two timer peripherals - two channels are used in the TC0\r
56 timer. */\r
57 void vT32_0_Handler( void );\r
58 void vT32_1_Handler( void );\r
59 \r
60 /*-----------------------------------------------------------*/\r
61 \r
62 void vInitialiseTimerForIntQueueTest( void )\r
63 {\r
64     /* Configure the timer channels. */\r
65         MAP_Timer32_initModule( (uint32_t)TIMER32_0_BASE, TIMER32_PRESCALER_1, TIMER32_32BIT, TIMER32_PERIODIC_MODE );\r
66         MAP_Timer32_setCount( (uint32_t)TIMER32_0_BASE, CS_getMCLK() / tmrTIMER_0_FREQUENCY );\r
67         MAP_Timer32_enableInterrupt( (uint32_t)TIMER32_0_BASE );\r
68         MAP_Timer32_startTimer( (uint32_t)TIMER32_0_BASE, false );\r
69         MAP_Interrupt_setPriority( INT_T32_INT1, tmrLOWER_PRIORITY );\r
70         MAP_Interrupt_enableInterrupt( INT_T32_INT1 );\r
71 \r
72         MAP_Timer32_initModule( (uint32_t)TIMER32_1_BASE, TIMER32_PRESCALER_1, TIMER32_32BIT, TIMER32_PERIODIC_MODE );\r
73         MAP_Timer32_setCount( (uint32_t)TIMER32_1_BASE, CS_getMCLK() / tmrTIMER_1_FREQUENCY );\r
74         MAP_Timer32_enableInterrupt( (uint32_t)TIMER32_1_BASE );\r
75         MAP_Timer32_startTimer( (uint32_t)TIMER32_1_BASE, false );\r
76         MAP_Interrupt_setPriority( INT_T32_INT2, tmrHIGHER_PRIORITY );\r
77         MAP_Interrupt_enableInterrupt( INT_T32_INT2 );\r
78 }\r
79 /*-----------------------------------------------------------*/\r
80 \r
81 void vT32_0_Handler( void )\r
82 {\r
83     MAP_Timer32_clearInterruptFlag( (uint32_t)TIMER32_0_BASE );\r
84         portYIELD_FROM_ISR( xFirstTimerHandler() );\r
85 }\r
86 /*-----------------------------------------------------------*/\r
87 \r
88 void vT32_1_Handler( void )\r
89 {\r
90     MAP_Timer32_clearInterruptFlag( (uint32_t)TIMER32_1_BASE );\r
91         portYIELD_FROM_ISR( xSecondTimerHandler() );\r
92 }\r
93 \r