]> git.donarmstrong.com Git - qmk_firmware.git/blob - tool/mbed/mbed-sdk/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_KPSDK_CODE/drivers/pit/src/fsl_pit_irq.c
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[qmk_firmware.git] / tool / mbed / mbed-sdk / libraries / mbed / targets / hal / TARGET_Freescale / TARGET_KPSDK_MCUS / TARGET_KPSDK_CODE / drivers / pit / src / fsl_pit_irq.c
1 /*
2  * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without modification,
6  * are permitted provided that the following conditions are met:
7  *
8  * o Redistributions of source code must retain the above copyright notice, this list
9  *   of conditions and the following disclaimer.
10  *
11  * o Redistributions in binary form must reproduce the above copyright notice, this
12  *   list of conditions and the following disclaimer in the documentation and/or
13  *   other materials provided with the distribution.
14  *
15  * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16  *   contributors may be used to endorse or promote products derived from this
17  *   software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30
31 #include <stdlib.h>
32 #include <assert.h>
33 #include "fsl_pit_common.h"
34 #include "fsl_pit_driver.h"
35
36 /*!
37  * @addtogroup pit_irq
38  * @{
39  */
40
41 /*******************************************************************************
42  * Variables
43  ******************************************************************************/
44
45 /*!
46  * @brief Function table to save PIT isr callback function pointers.
47  *
48  * Call PIT_DRV_InstallCallback to install isr callback functions.
49  */
50 static pit_isr_callback_t pitIsrCallbackTable[HW_PIT_INSTANCE_COUNT][FSL_FEATURE_PIT_TIMER_COUNT] = {{NULL}};
51
52 /*******************************************************************************
53  * Code
54  ******************************************************************************/
55 #if defined (KL25Z4_SERIES)
56 /*!
57  * @brief System default IRQ handler defined in startup code.
58  *
59  * Users can either edit this handler or define a callback function. Furthermore,
60  * interrupt manager could be used to re-map the IRQ handler to another function.
61  */
62 void PIT_IRQHandler(void)
63 {
64     uint32_t i;
65     for(i=0; i < FSL_FEATURE_PIT_TIMER_COUNT; i++)
66     {
67         /* Clear interrupt flag.*/
68         PIT_HAL_ClearIntFlag(g_pitBaseAddr[0], i);
69
70         /* Run callback function if it exists.*/
71         if (pitIsrCallbackTable[0][i])
72         {
73             (*pitIsrCallbackTable[0][i])();
74         }
75     }
76 }
77
78 #elif defined (K64F12_SERIES) || defined (K24F12_SERIES) || defined (K63F12_SERIES) || \
79       defined (K22F12810_SERIES) || defined (K22F25612_SERIES) || defined (K22F51212_SERIES) || \
80       defined (KV31F12810_SERIES) || defined (KV31F25612_SERIES) || defined (KV31F51212_SERIES) || \
81       defined (K70F12_SERIES) 
82 void PIT0_IRQHandler(void)
83 {
84     /* Clear interrupt flag.*/
85     PIT_HAL_ClearIntFlag(g_pitBaseAddr[0], 0U);
86
87     /* Run callback function if it exists.*/
88     if (pitIsrCallbackTable[0][0])
89     {
90         (*pitIsrCallbackTable[0][0])();
91     }
92 }
93
94 void PIT1_IRQHandler(void)
95 {
96     /* Clear interrupt flag.*/
97     PIT_HAL_ClearIntFlag(g_pitBaseAddr[0], 1U);
98
99     /* Run callback function if it exists.*/
100     if (pitIsrCallbackTable[0][1])
101     {
102         (*pitIsrCallbackTable[0][1])();
103     }
104 }
105
106 void PIT2_IRQHandler(void)
107 {
108     /* Clear interrupt flag.*/
109     PIT_HAL_ClearIntFlag(g_pitBaseAddr[0], 2U);
110
111     /* Run callback function if it exists.*/
112     if (pitIsrCallbackTable[0][2])
113     {
114         (*pitIsrCallbackTable[0][2])();
115     }
116 }
117
118 void PIT3_IRQHandler(void)
119 {
120     /* Clear interrupt flag.*/
121     PIT_HAL_ClearIntFlag(g_pitBaseAddr[0], 3U);
122
123     /* Run callback function if it exists.*/
124     if (pitIsrCallbackTable[0][3])
125     {
126         (*pitIsrCallbackTable[0][3])();
127     }
128 }
129 #endif
130
131 /*! @} */
132
133 /*FUNCTION**********************************************************************
134  *
135  * Function Name : PIT_DRV_InstallCallback
136  * Description   : Register pit isr callback function.
137  * System default ISR interfaces are already defined in fsl_pit_irq.c. Users
138  * can either edit these ISRs or use this function to register a callback
139  * function. The default ISR will run the callback function it there is one
140  * installed here.
141
142  *END**************************************************************************/
143 void PIT_DRV_InstallCallback(uint32_t instance, uint32_t channel, pit_isr_callback_t function)
144 {
145     assert(channel < FSL_FEATURE_PIT_TIMER_COUNT);
146     assert(function != NULL);
147
148     pitIsrCallbackTable[instance][channel] = function;
149 }
150
151 /*******************************************************************************
152  * EOF
153  ******************************************************************************/
154