2 * FreeRTOS Kernel V10.3.0
\r
3 * Copyright (C) 2020 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 /* Scheduler includes. */
\r
29 #include "FreeRTOS.h"
\r
32 /* Demo includes. */
\r
33 #include "IntQueueTimer.h"
\r
34 #include "IntQueue.h"
\r
37 #include "fsl_ctimer.h"
\r
39 /* The priorities for the two timers. Note that a priority of 0 is the highest
\r
40 possible on Cortex-M devices. */
\r
41 #define tmrMAX_PRIORITY ( 0UL )
\r
42 #define trmSECOND_HIGHEST_PRIORITY ( tmrMAX_PRIORITY + 1 )
\r
44 void vInitialiseTimerForIntQueueTest( void )
\r
46 ctimer_config_t xConfigTimer0, xConfigTimer1;
\r
47 ctimer_match_config_t xConfigInterrupt = { 0 };
\r
49 memset( &xConfigTimer0, 0x00, sizeof( xConfigTimer0 ) );
\r
50 memset( &xConfigTimer1, 0x00, sizeof( xConfigTimer1 ) );
\r
52 /* Enable peripheral bus clock for CTIMER0 and CTIMER1. */
\r
53 CLOCK_EnableClock( kCLOCK_Ctimer0 );
\r
54 CLOCK_EnableClock( kCLOCK_Ctimer1 );
\r
56 /* Interrupt settings for timers --
\r
57 A timer will generates an interrupt when the count matches the value specified.
\r
58 Timer will reset itself and restart the count. The interrupt frequency is fairly
\r
59 arbitrary, in a sense that all we need to make sure is IRQs are triggered so that
\r
60 queues have items for tasks to process. */
\r
61 xConfigInterrupt.enableCounterReset = true;
\r
62 xConfigInterrupt.enableCounterStop = false;
\r
63 xConfigInterrupt.enableInterrupt = true;
\r
64 xConfigInterrupt.matchValue = 0xFFFFF;
\r
65 xConfigInterrupt.outControl = kCTIMER_Output_NoAction;
\r
66 xConfigInterrupt.outPinInitState = true;
\r
68 /* Configuration settings for timers. */
\r
69 CTIMER_GetDefaultConfig( &xConfigTimer0 );
\r
70 xConfigTimer0.prescale = 1;
\r
72 CTIMER_GetDefaultConfig( &xConfigTimer1 );
\r
73 xConfigTimer1.prescale = 2;
\r
75 /* Initialize timers. */
\r
76 CTIMER_Init( CTIMER0, &xConfigTimer0 );
\r
77 CTIMER_SetupMatch( CTIMER0, kCTIMER_Match_0, &xConfigInterrupt );
\r
79 CTIMER_Init( CTIMER1, &xConfigTimer1 );
\r
80 CTIMER_SetupMatch( CTIMER1, kCTIMER_Match_0, &xConfigInterrupt );
\r
82 /* Don't generate interrupts until the scheduler has been started.
\r
83 Interrupts will be automatically enabled when the first task starts
\r
85 taskDISABLE_INTERRUPTS();
\r
87 /* Set the timer interrupts to be above the kernel. The interrupts are
\r
88 assigned different priorities so they nest with each other. */
\r
89 NVIC_SetPriority( CTIMER0_IRQn, trmSECOND_HIGHEST_PRIORITY );
\r
90 NVIC_SetPriority( CTIMER1_IRQn, tmrMAX_PRIORITY );
\r
92 /* Enable the timer interrupts. */
\r
93 NVIC_EnableIRQ( CTIMER0_IRQn );
\r
94 NVIC_EnableIRQ( CTIMER1_IRQn );
\r
97 CTIMER_StartTimer( CTIMER0 );
\r
98 CTIMER_StartTimer( CTIMER1 );
\r
100 /*-----------------------------------------------------------*/
\r
102 void CTIMER0_IRQHandler( void )
\r
104 uint32_t ulInterruptStatus;
\r
106 /* Get Interrupt status flags */
\r
107 ulInterruptStatus = CTIMER_GetStatusFlags( CTIMER0 );
\r
109 /* Clear the status flags that were set */
\r
110 CTIMER_ClearStatusFlags( CTIMER0, ulInterruptStatus );
\r
112 portEND_SWITCHING_ISR( xFirstTimerHandler() );
\r
114 /*-----------------------------------------------------------*/
\r
116 void CTIMER1_IRQHandler(void)
\r
118 uint32_t ulInterruptStatus;
\r
120 /* Get Interrupt status flags */
\r
121 ulInterruptStatus = CTIMER_GetStatusFlags( CTIMER1 );
\r
123 /* Clear the status flags that were set */
\r
124 CTIMER_ClearStatusFlags( CTIMER1, ulInterruptStatus );
\r
126 portEND_SWITCHING_ISR( xSecondTimerHandler() );
\r
128 /*-----------------------------------------------------------*/
\r