]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/ColdFire_MCF52259_CodeWarrior/FreeRTOS_Tick_Setup.c
Update to MIT licensed FreeRTOS V10.0.0 - see https://www.freertos.org/History.txt
[freertos] / FreeRTOS / Demo / ColdFire_MCF52259_CodeWarrior / FreeRTOS_Tick_Setup.c
1 /*\r
2  * FreeRTOS Kernel V10.0.0\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. If you wish to use our Amazon\r
14  * FreeRTOS name, please do so in a fair use way that does not cause confusion.\r
15  *\r
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
18  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
19  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
20  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
21  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
22  *\r
23  * http://www.FreeRTOS.org\r
24  * http://aws.amazon.com/freertos\r
25  *\r
26  * 1 tab == 4 spaces!\r
27  */\r
28 \r
29 #include "FreeRTOS.h"\r
30 #include "task.h"\r
31 \r
32 __declspec(interrupt:0) void vPIT0InterruptHandler( void );\r
33 \r
34 /* Constants used to configure the interrupts. */\r
35 #define portPRESCALE_VALUE                      64\r
36 #define portPRESCALE_REG_SETTING        ( 5 << 8 )\r
37 #define portPIT_INTERRUPT_ENABLED       ( 0x08 )\r
38 #define configPIT0_INTERRUPT_VECTOR     ( 55 )\r
39 \r
40 /*\r
41  * FreeRTOS.org requires two interrupts - a tick interrupt generated from a\r
42  * timer source, and a spare interrupt vector used for context switching.\r
43  * The configuration below uses PIT0 for the former, and vector 16 for the\r
44  * latter.  **IF YOUR APPLICATION HAS BOTH OF THESE INTERRUPTS FREE THEN YOU DO\r
45  * NOT NEED TO CHANGE ANY OF THIS CODE** - otherwise instructions are provided\r
46  * here for using alternative interrupt sources.\r
47  *\r
48  * To change the tick interrupt source:\r
49  *\r
50  *      1) Modify vApplicationSetupInterrupts() below to be correct for whichever\r
51  *      peripheral is to be used to generate the tick interrupt.  The name of the\r
52  *  handler function (currently vPIT0InterruptHandler()) should also be updated\r
53  *  to indicate which peripheral is generating the interrupt.\r
54  *\r
55  *      2) Make sure the interrupt source is cleared within the interrupt handler function.\r
56  *  Currently vPIT0InterruptHandler() clears the PIT0 interrupt.\r
57  *\r
58  *  3) Update the vector table within mcf5225x_vectors.s to install the tick\r
59  *  interrupt handler in the correct vector position.\r
60  *\r
61  * To change the spare interrupt source:\r
62  *\r
63  *  1) Modify vApplicationSetupInterrupts() below to be correct for whichever\r
64  *  interrupt vector is to be used.  Make sure you use a spare interrupt on interrupt\r
65  *  controller 0, otherwise the register used to request context switches will also\r
66  *  require modification.\r
67  *\r
68  *  2) Change the definition of configYIELD_INTERRUPT_VECTOR within FreeRTOSConfig.h\r
69  *  to be correct for your chosen interrupt vector.\r
70  *\r
71  *  3) Update the vector table within mcf5225x_vectors.s to install the handler\r
72  *  _vPortYieldISR() in the correct vector position (by default vector number 16 is\r
73  *  used).\r
74  */\r
75 void vApplicationSetupInterrupts( void )\r
76 {\r
77 const unsigned short usCompareMatchValue = ( ( configCPU_CLOCK_HZ / portPRESCALE_VALUE ) / configTICK_RATE_HZ );\r
78 \r
79     /* Configure interrupt priority and level and unmask interrupt for PIT0. */\r
80     MCF_INTC0_ICR55 = ( 1 | ( configKERNEL_INTERRUPT_PRIORITY << 3 ) );\r
81     MCF_INTC0_IMRH &= ~( MCF_INTC_IMRH_INT_MASK55 );\r
82 \r
83     /* Do the same for vector 63 (interrupt controller 0.  I don't think the\r
84     write to MCF_INTC0_IMRH is actually required here but is included for\r
85     completeness. */\r
86     MCF_INTC0_ICR16 = ( 0 | configKERNEL_INTERRUPT_PRIORITY << 3 );\r
87     MCF_INTC0_IMRL &= ~( MCF_INTC_IMRL_INT_MASK16 | 0x01 );\r
88 \r
89     /* Configure PIT0 to generate the RTOS tick. */\r
90     MCF_PIT0_PCSR |= MCF_PIT_PCSR_PIF;\r
91     MCF_PIT0_PCSR = ( portPRESCALE_REG_SETTING | MCF_PIT_PCSR_PIE | MCF_PIT_PCSR_RLD | MCF_PIT_PCSR_EN );\r
92         MCF_PIT0_PMR = usCompareMatchValue;\r
93 }\r
94 /*-----------------------------------------------------------*/\r
95 \r
96 __declspec(interrupt:0) void vPIT0InterruptHandler( void )\r
97 {\r
98 unsigned long ulSavedInterruptMask;\r
99 \r
100         /* Clear the PIT0 interrupt. */\r
101         MCF_PIT0_PCSR |= MCF_PIT_PCSR_PIF;\r
102 \r
103         /* Increment the RTOS tick. */\r
104         ulSavedInterruptMask = portSET_INTERRUPT_MASK_FROM_ISR();\r
105                 if( xTaskIncrementTick() != pdFALSE )\r
106                 {\r
107                         taskYIELD();\r
108                 }\r
109         portCLEAR_INTERRUPT_MASK_FROM_ISR( ulSavedInterruptMask );\r
110 }\r