]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/ColdFire_MCF5282_Eclipse/RTOSDemo/FreeRTOS_Tick_Setup.c
Prepare for V7.2.0 release.
[freertos] / FreeRTOS / Demo / ColdFire_MCF5282_Eclipse / RTOSDemo / FreeRTOS_Tick_Setup.c
1 /*\r
2     FreeRTOS V7.2.0 - Copyright (C) 2012 Real Time Engineers Ltd.\r
3         \r
4 \r
5     ***************************************************************************\r
6      *                                                                       *\r
7      *    FreeRTOS tutorial books are available in pdf and paperback.        *\r
8      *    Complete, revised, and edited pdf reference manuals are also       *\r
9      *    available.                                                         *\r
10      *                                                                       *\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
17      *                                                                       *\r
18      *    >>> See http://www.FreeRTOS.org/Documentation for details. <<<     *\r
19      *                                                                       *\r
20      *    Thank you for using FreeRTOS, and thank you for your support!      *\r
21      *                                                                       *\r
22     ***************************************************************************\r
23 \r
24 \r
25     This file is part of the FreeRTOS distribution.\r
26 \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
40     FreeRTOS WEB site.\r
41 \r
42     1 tab == 4 spaces!\r
43     \r
44     ***************************************************************************\r
45      *                                                                       *\r
46      *    Having a problem?  Start by reading the FAQ "My application does   *\r
47      *    not run, what could be wrong?                                      *\r
48      *                                                                       *\r
49      *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
50      *                                                                       *\r
51     ***************************************************************************\r
52 \r
53     \r
54     http://www.FreeRTOS.org - Documentation, training, latest information, \r
55     license and contact details.\r
56     \r
57     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
58     including FreeRTOS+Trace - an indispensable productivity tool.\r
59 \r
60     Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell \r
61     the code with commercial support, indemnification, and middleware, under \r
62     the OpenRTOS brand: http://www.OpenRTOS.com.  High Integrity Systems also\r
63     provide a safety engineered and independently SIL3 certified version under \r
64     the SafeRTOS brand: http://www.SafeRTOS.com.\r
65 */\r
66 \r
67 #include "FreeRTOS.h"\r
68 #include "task.h"\r
69 \r
70 /* Constants used to configure the interrupts. */\r
71 #define portPRESCALE_VALUE                      64\r
72 #define portPRESCALE_REG_SETTING        ( 5 << 8 )\r
73 #define portPIT_INTERRUPT_ENABLED       ( 0x08 )\r
74 #define configPIT0_INTERRUPT_VECTOR     ( 55 )\r
75 \r
76 /*\r
77  * FreeRTOS.org requires two interrupts - a tick interrupt generated from a\r
78  * timer source, and a spare interrupt vector used for context switching.\r
79  * The configuration below uses PIT0 for the former, and vector 16 for the\r
80  * latter.  **IF YOUR APPLICATION HAS BOTH OF THESE INTERRUPTS FREE THEN YOU DO\r
81  * NOT NEED TO CHANGE ANY OF THIS CODE** - otherwise instructions are provided\r
82  * here for using alternative interrupt sources.\r
83  *\r
84  * To change the tick interrupt source:\r
85  *\r
86  *      1) Modify vApplicationSetupInterrupts() below to be correct for whichever\r
87  *      peripheral is to be used to generate the tick interrupt.\r
88  *\r
89  *      2) Change the name of the function __cs3_isr_interrupt_119() defined within\r
90  *      this file to be correct for the interrupt vector used by the timer peripheral.\r
91  *      The name of the function should contain the vector number, so by default vector\r
92  *      number 119 is being used.\r
93  *\r
94  *      3) Make sure the tick interrupt is cleared within the interrupt handler function.\r
95  *  Currently __cs3_isr_interrupt_119() clears the PIT0 interrupt.\r
96  *\r
97  * To change the spare interrupt source:\r
98  *\r
99  *  1) Modify vApplicationSetupInterrupts() below to be correct for whichever\r
100  *  interrupt vector is to be used.  Make sure you use a spare interrupt on interrupt\r
101  *  controller 0, otherwise the register used to request context switches will also\r
102  *  require modification.  By default vector 16 is used which is free on most MCF52xxx\r
103  *  devices.\r
104  *\r
105  *  2) Change the definition of configYIELD_INTERRUPT_VECTOR within FreeRTOSConfig.h\r
106  *  to be correct for your chosen interrupt vector.\r
107  *\r
108  *  3) Change the name of the function __cs3_isr_interrupt_80() within portasm.S\r
109  *  to be correct for whichever vector number is being used.  By default interrupt\r
110  *  controller 0 vector number 16 is used, which corresponds to vector number 80.\r
111  */\r
112 void vApplicationSetupInterrupts( void )\r
113 {\r
114 const unsigned portSHORT usCompareMatchValue = ( ( configCPU_CLOCK_HZ / portPRESCALE_VALUE ) / configTICK_RATE_HZ );\r
115 \r
116     /* Configure interrupt priority and level and unmask interrupt for PIT0. */\r
117     MCF_INTC0_ICR55 = ( 1 | ( configKERNEL_INTERRUPT_PRIORITY << 3 ) );\r
118     MCF_INTC0_IMRH &= ~( MCF_INTC_IMRH_INT_MASK55 );\r
119 \r
120     /* Do the same for vector 16 (interrupt controller 0).  I don't think the\r
121     write to MCF_INTC0_IMRH is actually required here but is included for\r
122     completeness. */\r
123     MCF_INTC0_ICR16 = ( 0 | ( configKERNEL_INTERRUPT_PRIORITY << 3 ) );\r
124     MCF_INTC0_IMRH &= ~( MCF_INTC_IPRL_INT16 );\r
125 \r
126     /* Configure PIT0 to generate the RTOS tick. */\r
127     MCF_PIT0_PCSR |= MCF_PIT_PCSR_PIF;\r
128     MCF_PIT0_PCSR = ( portPRESCALE_REG_SETTING | MCF_PIT_PCSR_PIE | MCF_PIT_PCSR_RLD | MCF_PIT_PCSR_EN );\r
129         MCF_PIT0_PMR = usCompareMatchValue;\r
130 }\r
131 /*-----------------------------------------------------------*/\r
132 \r
133 void __attribute__ ((interrupt)) __cs3_isr_interrupt_119( void )\r
134 {\r
135 unsigned portLONG ulSavedInterruptMask;\r
136 \r
137         /* Clear the PIT0 interrupt. */\r
138         MCF_PIT0_PCSR |= MCF_PIT_PCSR_PIF;\r
139 \r
140         /* Increment the RTOS tick. */\r
141         ulSavedInterruptMask = portSET_INTERRUPT_MASK_FROM_ISR();\r
142                 vTaskIncrementTick();\r
143         portCLEAR_INTERRUPT_MASK_FROM_ISR( ulSavedInterruptMask );\r
144 \r
145         /* If we are using the pre-emptive scheduler then also request a\r
146         context switch as incrementing the tick could have unblocked a task. */\r
147         #if configUSE_PREEMPTION == 1\r
148         {\r
149                 taskYIELD();\r
150         }\r
151         #endif\r
152 }\r