2 FreeRTOS V7.0.2 - Copyright (C) 2011 Real Time Engineers Ltd.
\r
5 ***************************************************************************
\r
7 * FreeRTOS tutorial books are available in pdf and paperback. *
\r
8 * Complete, revised, and edited pdf reference manuals are also *
\r
11 * Purchasing FreeRTOS documentation will not only help you, by *
\r
12 * ensuring you get running as quickly as possible and with an *
\r
13 * in-depth knowledge of how to use FreeRTOS, it will also help *
\r
14 * the FreeRTOS project to continue with its mission of providing *
\r
15 * professional grade, cross platform, de facto standard solutions *
\r
16 * for microcontrollers - completely free of charge! *
\r
18 * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
\r
20 * Thank you for using FreeRTOS, and thank you for your support! *
\r
22 ***************************************************************************
\r
25 This file is part of the FreeRTOS distribution.
\r
27 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
28 the terms of the GNU General Public License (version 2) as published by the
\r
29 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
\r
30 >>>NOTE<<< The modification to the GPL is included to allow you to
\r
31 distribute a combined work that includes FreeRTOS without being obliged to
\r
32 provide the source code for proprietary components outside of the FreeRTOS
\r
33 kernel. FreeRTOS is distributed in the hope that it will be useful, but
\r
34 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
\r
35 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
36 more details. You should have received a copy of the GNU General Public
\r
37 License and the FreeRTOS license exception along with FreeRTOS; if not it
\r
38 can be viewed here: http://www.freertos.org/a00114.html and also obtained
\r
39 by writing to Richard Barry, contact details for whom are available on the
\r
44 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
47 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
50 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
51 licensing and training services.
\r
54 /* Standard includes. */
\r
58 /* Scheduler includes. */
\r
59 #include "FreeRTOS.h"
\r
63 /* Demo application includes. */
\r
64 #include "InterruptNestTest.h"
\r
66 /* TriCore specific includes. */
\r
68 #include <machine/intrinsics.h>
\r
69 #include <machine/cint.h>
\r
70 #include <machine/wdtcon.h>
\r
72 #warning DOCUMENT THIS
\r
73 /* This constant is specific to this test application. It allows the high
\r
74 frequency (interrupt nesting test) timer to know how often to trigger, and the
\r
75 check task to know how many iterations to expect at any given time. */
\r
76 #define tmrtestHIGH_FREQUENCY_TIMER_TEST_HZ ( 8931UL )
\r
78 static void prvPortHighFrequencyTimerHandler( int iArg ) __attribute__((longcall));
\r
79 static void prvHighFrequencyTimerTask( void *pvParameters );
\r
81 static const unsigned long ulCompareMatchValue = configPERIPHERAL_CLOCK_HZ / tmrtestHIGH_FREQUENCY_TIMER_TEST_HZ;
\r
82 static const unsigned long ulInterruptsPer10ms = tmrtestHIGH_FREQUENCY_TIMER_TEST_HZ / 100UL;
\r
83 static const unsigned long ulSemaphoreGiveRate_ms = 10UL;
\r
85 static xSemaphoreHandle xHighFrequencyTimerSemaphore = NULL;
\r
86 static unsigned long ulHighFrequencyCounterIterations = 0UL;
\r
88 /*-----------------------------------------------------------*/
\r
90 void vSetupInterruptNestingTest( void )
\r
92 unsigned long ulCompareMatchBits;
\r
94 /* Create the semaphore used to communicate between the high frequency
\r
95 interrupt and the task. */
\r
96 vSemaphoreCreateBinary( xHighFrequencyTimerSemaphore );
\r
97 configASSERT( xHighFrequencyTimerSemaphore );
\r
99 /* Create the task that pends on the semaphore that is given by the
\r
100 high frequency interrupt. */
\r
101 xTaskCreate( prvHighFrequencyTimerTask, ( signed char * ) "HFTmr", configMINIMAL_STACK_SIZE, NULL, configMAX_PRIORITIES - 1, NULL );
\r
103 /* Setup the interrupt itself. The STM module clock divider is setup when
\r
104 the tick interrupt is configured - which is when the scheduler is started -
\r
105 so there is no need to do it here.
\r
107 The tick interrupt uses compare match 0, so this test uses compare match
\r
108 1, which means shifting up the values by 16 before writing them to the
\r
110 ulCompareMatchBits = ( 0x1fUL - __CLZ( ulCompareMatchValue ) );
\r
111 ulCompareMatchBits <<= 16UL;
\r
113 /* Write the values to the relevant SMT registers, without changing other
\r
115 taskENTER_CRITICAL();
\r
117 STM_CMCON.reg &= ~( 0x1fUL << 16UL );
\r
118 STM_CMCON.reg |= ulCompareMatchBits;
\r
119 STM_CMP1.reg = ulCompareMatchValue;
\r
121 if( 0 != _install_int_handler( configHIGH_FREQUENCY_TIMER_PRIORITY, prvPortHighFrequencyTimerHandler, 0 ) )
\r
123 /* Set-up the interrupt. */
\r
124 STM_SRC1.reg = ( configHIGH_FREQUENCY_TIMER_PRIORITY | 0x00005000UL );
\r
126 /* Enable the Interrupt. */
\r
127 STM_ISRR.reg &= ~( 0x03UL << 2UL );
\r
128 STM_ISRR.reg |= ( 0x1UL << 2UL );
\r
129 STM_ICR.reg &= ~( 0x07UL << 4UL );
\r
130 STM_ICR.reg |= ( 0x5UL << 4UL );
\r
134 /* Failed to install the interrupt. */
\r
135 configASSERT( ( ( volatile void * ) NULL ) );
\r
138 taskEXIT_CRITICAL();
\r
140 /*-----------------------------------------------------------*/
\r
142 unsigned long ulInterruptNestingTestGetIterationCount( unsigned long *pulExpectedIncFrequency_ms )
\r
144 *pulExpectedIncFrequency_ms = ulSemaphoreGiveRate_ms;
\r
145 return ulHighFrequencyCounterIterations;
\r
147 /*-----------------------------------------------------------*/
\r
149 static void prvHighFrequencyTimerTask( void *pvParameters )
\r
151 /* Just to remove compiler warnings about the unused parameter. */
\r
152 ( void ) pvParameters;
\r
156 /* Wait for the next trigger from the high frequency timer interrupt. */
\r
157 xSemaphoreTake( xHighFrequencyTimerSemaphore, portMAX_DELAY );
\r
159 /* Just count how many times the task has been unblocked before
\r
160 returning to wait for the semaphore again. */
\r
161 ulHighFrequencyCounterIterations++;
\r
164 /*-----------------------------------------------------------*/
\r
166 static void prvPortHighFrequencyTimerHandler( int iArg )
\r
168 static volatile unsigned long ulExecutionCounter = 0UL;
\r
169 unsigned long ulHigherPriorityTaskWoken = pdFALSE;
\r
172 /* Just to avoid compiler warnings about unused parameters. */
\r
175 /* Clear the interrupt source. */
\r
176 STM_ISRR.reg = 1UL << 2UL;
\r
178 /* Reload the Compare Match register for X ticks into the future.*/
\r
179 STM_CMP1.reg += ulCompareMatchValue;
\r
181 ulExecutionCounter++;
\r
183 if( ulExecutionCounter >= ulInterruptsPer10ms )
\r
185 ulExecutionCounter = xSemaphoreGiveFromISR( xHighFrequencyTimerSemaphore, &ulHigherPriorityTaskWoken );
\r
187 /* If the semaphore was given ulExeuctionCounter will now be pdTRUE. */
\r
188 configASSERT( ulExecutionCounter == pdTRUE );
\r
190 /* Start counting again. */
\r
191 ulExecutionCounter = 0UL;
\r
194 portYIELD_FROM_ISR( ulHigherPriorityTaskWoken );
\r