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