]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_A53_64-bit_UltraScale_MPSoC/RTOSDemo_A53_bsp/psu_cortexa53_0/libsrc/rtcpsu_v1_2/src/xrtcpsu_intr.c
Update BSP source files for UltraScale Cortex-A53 and Cortex-R5 and Microblaze to...
[freertos] / FreeRTOS / Demo / CORTEX_A53_64-bit_UltraScale_MPSoC / RTOSDemo_A53_bsp / psu_cortexa53_0 / libsrc / rtcpsu_v1_2 / src / xrtcpsu_intr.c
1 /******************************************************************************
2 *
3 * Copyright (C) 2015 Xilinx, Inc.  All rights reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * Use of the Software is limited solely to applications:
16 * (a) running on a Xilinx device, or
17 * (b) that interact with a Xilinx device through a bus or interconnect.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 * XILINX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
24 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * SOFTWARE.
26 *
27 * Except as contained in this notice, the name of the Xilinx shall not be used
28 * in advertising or otherwise to promote the sale, use or other dealings in
29 * this Software without prior written authorization from Xilinx.
30 *
31 ******************************************************************************/
32 /*****************************************************************************/
33 /**
34 *
35 * @file xrtcpsu_intr.c
36 * @addtogroup rtcpsu_v1_0
37 * @{
38 *
39 * This file contains functions related to RTC interrupt handling.
40 *
41 * <pre>
42 * MODIFICATION HISTORY:
43 *
44 * Ver   Who    Date     Changes
45 * ----- -----  -------- -----------------------------------------------
46 * 1.00  kvn    04/21/15 First release
47 * </pre>
48 *
49 ******************************************************************************/
50
51 /***************************** Include Files *********************************/
52
53 #include "xrtcpsu.h"
54
55 /************************** Constant Definitions *****************************/
56
57 /**************************** Type Definitions *******************************/
58
59 /***************** Macros (Inline Functions) Definitions *********************/
60
61 /************************** Variable Definitions *****************************/
62
63 /************************** Function Prototypes ******************************/
64
65 /************************** Variable Definitions ****************************/
66
67 /****************************************************************************/
68 /**
69 *
70 * This function sets the interrupt mask.
71 *
72 * @param        InstancePtr is a pointer to the XRtcPsu instance
73 * @param        Mask contains the interrupts to be enabled.
74 *               A '1' enables an interupt, and a '0' disables.
75 *
76 * @return       None.
77 *
78 * @note         None.
79 *
80 *****************************************************************************/
81 void XRtcPsu_SetInterruptMask(XRtcPsu *InstancePtr, u32 Mask)
82 {
83         /*
84          * Clear the Status register to be sure of no pending interrupts.
85          * Writing mask values to interrupt bits as it is a WTC register.
86          */
87         XRtcPsu_WriteReg(InstancePtr->RtcConfig.BaseAddr + XRTC_INT_STS_OFFSET,
88                         ((u32)XRTC_INT_STS_ALRM_MASK | (u32)XRTC_INT_STS_SECS_MASK));
89
90         /*
91          * XRTC_INT_MSK_RSTVAL contains the valid interrupts
92          * for the RTC device. The AND operation on Mask makes sure one
93          * of the valid bits are only set.
94          */
95
96         /* Write the mask to the IER Register */
97         XRtcPsu_WriteReg(InstancePtr->RtcConfig.BaseAddr+XRTC_INT_EN_OFFSET,
98                                         (Mask & (u32)XRTC_INT_MSK_RSTVAL));
99
100 }
101
102 /****************************************************************************/
103 /**
104 *
105 * This function clears the interrupt mask.
106 *
107 * @param        InstancePtr is a pointer to the XRtcPsu instance
108 * @param        Mask contains the interrupts to be disabled.
109 *               A '1' enables an interrupt, and a '0' disables.
110 *
111 * @return       None.
112 *
113 * @note         None.
114 *
115 *****************************************************************************/
116 void XRtcPsu_ClearInterruptMask(XRtcPsu *InstancePtr, u32 Mask)
117 {
118         /*
119          * XRTC_INT_MSK_RSTVAL contains the valid interrupts
120          * for the RTC device. The AND operation on mask makes sure one
121          * of the valid bits are only cleared.
122          */
123
124         /* Write the Mask to the IDR register */
125         XRtcPsu_WriteReg(InstancePtr->RtcConfig.BaseAddr+XRTC_INT_DIS_OFFSET,
126                                         (Mask & (u32)XRTC_INT_MSK_RSTVAL));
127 }
128
129 /****************************************************************************/
130 /**
131 *
132 * This function sets the handler that will be called when an event (interrupt)
133 * occurs that needs application's attention.
134 *
135 * @param        InstancePtr is a pointer to the XRtcPsu instance
136 * @param        FuncPtr is the pointer to the callback function.
137 * @param        CallBackRef is the upper layer callback reference passed back
138 *               when the callback function is invoked.
139 *
140 * @return       None.
141 *
142 * @note
143 *
144 * There is no assert on the CallBackRef since the driver doesn't know what it
145 * is (nor should it)
146 *
147 *****************************************************************************/
148 void XRtcPsu_SetHandler(XRtcPsu *InstancePtr, XRtcPsu_Handler FuncPtr,
149                  void *CallBackRef)
150 {
151         /*
152          * Asserts validate the input arguments
153          * CallBackRef not checked, no way to know what is valid
154          */
155         Xil_AssertVoid(InstancePtr != NULL);
156         Xil_AssertVoid(FuncPtr != NULL);
157         Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
158
159         InstancePtr->Handler = FuncPtr;
160         InstancePtr->CallBackRef = CallBackRef;
161 }
162
163 /****************************************************************************/
164 /**
165 *
166 * This function is the interrupt handler for the driver.
167 * It must be connected to an interrupt system by the application such that it
168 * can be called when an interrupt occurs.
169 *
170 * @param        InstancePtr contains a pointer to the driver instance
171 *
172 * @return       None.
173 *
174 * @note         None.
175 *
176 ******************************************************************************/
177 void XRtcPsu_InterruptHandler(XRtcPsu *InstancePtr)
178 {
179         u32 IsrStatus;
180
181         Xil_AssertVoid(InstancePtr != NULL);
182         Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
183
184         /*
185          * Read the interrupt ID register to determine which
186          * interrupt is active.
187          */
188         IsrStatus = ~(XRtcPsu_ReadReg(InstancePtr->RtcConfig.BaseAddr +
189                         XRTC_INT_MSK_OFFSET));
190
191         IsrStatus &= XRtcPsu_ReadReg(InstancePtr->RtcConfig.BaseAddr +
192                         XRTC_INT_STS_OFFSET);
193
194         /*
195          * Clear the interrupt status to allow future
196          * interrupts before this generated interrupt is serviced.
197          */
198         XRtcPsu_WriteReg(InstancePtr->RtcConfig.BaseAddr +
199                         XRTC_INT_STS_OFFSET, IsrStatus);
200
201         /* Handle the generated interrupts appropriately. */
202
203         /* Alarm interrupt */
204         if((IsrStatus & XRTC_INT_STS_ALRM_MASK) != (u32)0) {
205
206                 if(InstancePtr->IsPeriodicAlarm != 0U) {
207                         XRtcPsu_SetAlarm(InstancePtr,
208                                         (XRtcPsu_GetCurrentTime(InstancePtr)+InstancePtr->PeriodicAlarmTime),1U);
209                 }
210
211                 /*
212                  * Call the application handler to indicate that there is an
213                  * alarm interrupt. If the application cares about this alarm,
214                  * it will act accordingly through its own handler.
215                  */
216                 InstancePtr->Handler(InstancePtr->CallBackRef,
217                                         XRTCPSU_EVENT_ALARM_GEN);
218         }
219
220         /* Seconds interrupt */
221         if((IsrStatus & XRTC_INT_STS_SECS_MASK) != (u32)0) {
222                 /*
223                  * Call the application handler to indicate that there is an
224                  * seconds interrupt. If the application cares about this seconds
225                  * interrupt, it will act accordingly through its own handler.
226                  */
227                 InstancePtr->Handler(InstancePtr->CallBackRef,
228                                         XRTCPSU_EVENT_SECS_GEN);
229         }
230
231 }
232 /** @} */