]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/ColdFire_MCF52233_Eclipse/RTOSDemo/FreeRTOS_Tick_Setup.c
Roll up the minor changes checked into svn since V10.0.0 into new V10.0.1 ready for...
[freertos] / FreeRTOS / Demo / ColdFire_MCF52233_Eclipse / RTOSDemo / FreeRTOS_Tick_Setup.c
1 /*\r
2  * FreeRTOS Kernel V10.0.1\r
3  * Copyright (C) 2017 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 #include "FreeRTOS.h"\r
29 #include "task.h"\r
30 \r
31 /* Constants used to configure the interrupts. */\r
32 #define portPRESCALE_VALUE                      64\r
33 #define portPRESCALE_REG_SETTING        ( 5 << 8 )\r
34 #define portPIT_INTERRUPT_ENABLED       ( 0x08 )\r
35 #define configPIT0_INTERRUPT_VECTOR     ( 55 )\r
36 \r
37 /*\r
38  * FreeRTOS.org requires two interrupts - a tick interrupt generated from a\r
39  * timer source, and a spare interrupt vector used for context switching.\r
40  * The configuration below uses PIT0 for the former, and vector 16 for the\r
41  * latter.  **IF YOUR APPLICATION HAS BOTH OF THESE INTERRUPTS FREE THEN YOU DO\r
42  * NOT NEED TO CHANGE ANY OF THIS CODE** - otherwise instructions are provided\r
43  * here for using alternative interrupt sources.\r
44  *\r
45  * To change the tick interrupt source:\r
46  *\r
47  *      1) Modify vApplicationSetupInterrupts() below to be correct for whichever\r
48  *      peripheral is to be used to generate the tick interrupt.\r
49  *\r
50  *      2) Change the name of the function __cs3_isr_interrupt_119() defined within\r
51  *      this file to be correct for the interrupt vector used by the timer peripheral.\r
52  *      The name of the function should contain the vector number, so by default vector\r
53  *      number 119 is being used.\r
54  *\r
55  *      3) Make sure the tick interrupt is cleared within the interrupt handler function.\r
56  *  Currently __cs3_isr_interrupt_119() clears the PIT0 interrupt.\r
57  *\r
58  * To change the spare interrupt source:\r
59  *\r
60  *  1) Modify vApplicationSetupInterrupts() below to be correct for whichever\r
61  *  interrupt vector is to be used.  Make sure you use a spare interrupt on interrupt\r
62  *  controller 0, otherwise the register used to request context switches will also\r
63  *  require modification.  By default vector 16 is used which is free on most MCF52xxx\r
64  *  devices.\r
65  *\r
66  *  2) Change the definition of configYIELD_INTERRUPT_VECTOR within FreeRTOSConfig.h\r
67  *  to be correct for your chosen interrupt vector.\r
68  *\r
69  *  3) Change the name of the function __cs3_isr_interrupt_80() within portasm.S\r
70  *  to be correct for whichever vector number is being used.  By default interrupt\r
71  *  controller 0 vector number 16 is used, which corresponds to vector number 80.\r
72  */\r
73 void vApplicationSetupInterrupts( void )\r
74 {\r
75 const unsigned short usCompareMatchValue = ( ( configCPU_CLOCK_HZ / portPRESCALE_VALUE ) / configTICK_RATE_HZ );\r
76 \r
77     /* Configure interrupt priority and level and unmask interrupt for PIT0. */\r
78     MCF_INTC0_ICR55 = ( 1 | ( configKERNEL_INTERRUPT_PRIORITY << 3 ) );\r
79     MCF_INTC0_IMRH &= ~( MCF_INTC_IMRH_INT_MASK55 );\r
80 \r
81     /* Do the same for vector 16 (interrupt controller 0).  I don't think the\r
82     write to MCF_INTC0_IMRH is actually required here but is included for\r
83     completeness. */\r
84     MCF_INTC0_ICR16 = ( 0 | ( configKERNEL_INTERRUPT_PRIORITY << 3 ) );\r
85     MCF_INTC0_IMRH &= ~( MCF_INTC_IPRL_INT16 );\r
86 \r
87     /* Configure PIT0 to generate the RTOS tick. */\r
88     MCF_PIT0_PCSR |= MCF_PIT_PCSR_PIF;\r
89     MCF_PIT0_PCSR = ( portPRESCALE_REG_SETTING | MCF_PIT_PCSR_PIE | MCF_PIT_PCSR_RLD | MCF_PIT_PCSR_EN );\r
90         MCF_PIT0_PMR = usCompareMatchValue;\r
91 }\r
92 /*-----------------------------------------------------------*/\r
93 \r
94 void __attribute__ ((interrupt)) __cs3_isr_interrupt_119( void )\r
95 {\r
96 unsigned long ulSavedInterruptMask;\r
97 \r
98         /* Clear the PIT0 interrupt. */\r
99         MCF_PIT0_PCSR |= MCF_PIT_PCSR_PIF;\r
100 \r
101         /* Increment the RTOS tick. */\r
102         ulSavedInterruptMask = portSET_INTERRUPT_MASK_FROM_ISR();\r
103                 if( xTaskIncrementTick() != pdFALSE )\r
104                 {\r
105                         taskYIELD();\r
106                 }\r
107         portCLEAR_INTERRUPT_MASK_FROM_ISR( ulSavedInterruptMask );\r
108 }\r