3 * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
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:
12 * The above copyright notice and this permission notice shall be included in all
13 * copies or substantial portions of the Software.
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.
22 * http://www.FreeRTOS.org
23 * http://aws.amazon.com/freertos
31 __declspec(interrupt:0) void vPIT0InterruptHandler( void );
33 /* Constants used to configure the interrupts. */
34 #define portPRESCALE_VALUE 64
35 #define portPRESCALE_REG_SETTING ( 5 << 8 )
36 #define portPIT_INTERRUPT_ENABLED ( 0x08 )
37 #define configPIT0_INTERRUPT_VECTOR ( 55 )
40 * FreeRTOS.org requires two interrupts - a tick interrupt generated from a
41 * timer source, and a spare interrupt vector used for context switching.
42 * The configuration below uses PIT0 for the former, and vector 16 for the
43 * latter. **IF YOUR APPLICATION HAS BOTH OF THESE INTERRUPTS FREE THEN YOU DO
44 * NOT NEED TO CHANGE ANY OF THIS CODE** - otherwise instructions are provided
45 * here for using alternative interrupt sources.
47 * To change the tick interrupt source:
49 * 1) Modify vApplicationSetupInterrupts() below to be correct for whichever
50 * peripheral is to be used to generate the tick interrupt.
52 * 2) Change the name of the function __cs3_isr_interrupt_119() defined within
53 * this file to be correct for the interrupt vector used by the timer peripheral.
54 * The name of the function should contain the vector number, so by default vector
55 * number 119 is being used.
57 * 3) Make sure the tick interrupt is cleared within the interrupt handler function.
58 * Currently __cs3_isr_interrupt_119() clears the PIT0 interrupt.
60 * To change the spare interrupt source:
62 * 1) Modify vApplicationSetupInterrupts() below to be correct for whichever
63 * interrupt vector is to be used. Make sure you use a spare interrupt on interrupt
64 * controller 0, otherwise the register used to request context switches will also
65 * require modification.
67 * 2) Change the definition of configYIELD_INTERRUPT_VECTOR within FreeRTOSConfig.h
68 * to be correct for your chosen interrupt vector.
70 * 3) Change the name of the function __cs3_isr_interrupt_127() within portasm.S
71 * to be correct for whichever vector number is being used. By default interrupt
72 * controller 0 number 16 is used, which corresponds to vector number 127.
74 void vApplicationSetupInterrupts( void )
76 const unsigned short usCompareMatchValue = ( ( configCPU_CLOCK_HZ / portPRESCALE_VALUE ) / configTICK_RATE_HZ );
78 /* Configure interrupt priority and level and unmask interrupt for PIT0. */
79 MCF_INTC0_ICR55 = ( 1 | ( configKERNEL_INTERRUPT_PRIORITY << 3 ) );
80 MCF_INTC0_IMRH &= ~( MCF_INTC_IMRH_INT_MASK55 );
82 /* Do the same for vector 63 (interrupt controller 0. I don't think the
83 write to MCF_INTC0_IMRH is actually required here but is included for
85 MCF_INTC0_ICR16 = ( 0 | configKERNEL_INTERRUPT_PRIORITY << 3 );
86 MCF_INTC0_IMRL &= ~( MCF_INTC_IMRL_INT_MASK16 | 0x01 );
88 /* Configure PIT0 to generate the RTOS tick. */
89 MCF_PIT0_PCSR |= MCF_PIT_PCSR_PIF;
90 MCF_PIT0_PCSR = ( portPRESCALE_REG_SETTING | MCF_PIT_PCSR_PIE | MCF_PIT_PCSR_RLD | MCF_PIT_PCSR_EN );
91 MCF_PIT0_PMR = usCompareMatchValue;
93 /*-----------------------------------------------------------*/
95 __declspec(interrupt:0) void vPIT0InterruptHandler( void )
97 unsigned long ulSavedInterruptMask;
99 /* Clear the PIT0 interrupt. */
100 MCF_PIT0_PCSR |= MCF_PIT_PCSR_PIF;
102 /* Increment the RTOS tick. */
103 ulSavedInterruptMask = portSET_INTERRUPT_MASK_FROM_ISR();
104 if( xTaskIncrementTick() != pdFALSE )
108 portCLEAR_INTERRUPT_MASK_FROM_ISR( ulSavedInterruptMask );