1 /******************************************************************************
3 * Copyright (C) 2015 Xilinx, Inc. All rights reserved.
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:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
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.
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
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.
31 ******************************************************************************/
32 /*****************************************************************************/
35 * @file xrtcpsu_intr.c
36 * @addtogroup rtcpsu_v1_0
39 * This file contains functions related to RTC interrupt handling.
42 * MODIFICATION HISTORY:
44 * Ver Who Date Changes
45 * ----- ----- -------- -----------------------------------------------
46 * 1.00 kvn 04/21/15 First release
49 ******************************************************************************/
51 /***************************** Include Files *********************************/
55 /************************** Constant Definitions *****************************/
57 /**************************** Type Definitions *******************************/
59 /***************** Macros (Inline Functions) Definitions *********************/
61 /************************** Variable Definitions *****************************/
63 /************************** Function Prototypes ******************************/
65 /************************** Variable Definitions ****************************/
67 /****************************************************************************/
70 * This function sets the interrupt mask.
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.
80 *****************************************************************************/
81 void XRtcPsu_SetInterruptMask(XRtcPsu *InstancePtr, u32 Mask)
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.
87 XRtcPsu_WriteReg(InstancePtr->RtcConfig.BaseAddr + XRTC_INT_STS_OFFSET,
88 ((u32)XRTC_INT_STS_ALRM_MASK | (u32)XRTC_INT_STS_SECS_MASK));
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.
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));
102 /****************************************************************************/
105 * This function clears the interrupt mask.
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.
115 *****************************************************************************/
116 void XRtcPsu_ClearInterruptMask(XRtcPsu *InstancePtr, u32 Mask)
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.
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));
129 /****************************************************************************/
132 * This function sets the handler that will be called when an event (interrupt)
133 * occurs that needs application's attention.
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.
144 * There is no assert on the CallBackRef since the driver doesn't know what it
147 *****************************************************************************/
148 void XRtcPsu_SetHandler(XRtcPsu *InstancePtr, XRtcPsu_Handler FuncPtr,
152 * Asserts validate the input arguments
153 * CallBackRef not checked, no way to know what is valid
155 Xil_AssertVoid(InstancePtr != NULL);
156 Xil_AssertVoid(FuncPtr != NULL);
157 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
159 InstancePtr->Handler = FuncPtr;
160 InstancePtr->CallBackRef = CallBackRef;
163 /****************************************************************************/
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.
170 * @param InstancePtr contains a pointer to the driver instance
176 ******************************************************************************/
177 void XRtcPsu_InterruptHandler(XRtcPsu *InstancePtr)
181 Xil_AssertVoid(InstancePtr != NULL);
182 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
185 * Read the interrupt ID register to determine which
186 * interrupt is active.
188 IsrStatus = ~(XRtcPsu_ReadReg(InstancePtr->RtcConfig.BaseAddr +
189 XRTC_INT_MSK_OFFSET));
191 IsrStatus &= XRtcPsu_ReadReg(InstancePtr->RtcConfig.BaseAddr +
192 XRTC_INT_STS_OFFSET);
195 * Clear the interrupt status to allow future
196 * interrupts before this generated interrupt is serviced.
198 XRtcPsu_WriteReg(InstancePtr->RtcConfig.BaseAddr +
199 XRTC_INT_STS_OFFSET, IsrStatus);
201 /* Handle the generated interrupts appropriately. */
203 /* Alarm interrupt */
204 if((IsrStatus & XRTC_INT_STS_ALRM_MASK) != (u32)0) {
206 if(InstancePtr->IsPeriodicAlarm != 0U) {
207 XRtcPsu_SetAlarm(InstancePtr,
208 (XRtcPsu_GetCurrentTime(InstancePtr)+InstancePtr->PeriodicAlarmTime),1U);
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.
216 InstancePtr->Handler(InstancePtr->CallBackRef,
217 XRTCPSU_EVENT_ALARM_GEN);
220 /* Seconds interrupt */
221 if((IsrStatus & XRTC_INT_STS_SECS_MASK) != (u32)0) {
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.
227 InstancePtr->Handler(InstancePtr->CallBackRef,
228 XRTCPSU_EVENT_SECS_GEN);