From 6769624eedee3430d0a2d2fc235afc36efca8992 Mon Sep 17 00:00:00 2001 From: Venkata Naga Sai Krishna Kolapalli Date: Thu, 4 Jun 2015 11:33:00 +0530 Subject: [PATCH] rtcpsu_v1_0 : Add new driver to RTC module. This patch adds new driver for RTC component. Signed-off-by: Venkata Naga Sai Krishna Kolapalli --- .../drivers/rtcpsu/data/rtcpsu.mdd | 42 ++ .../drivers/rtcpsu/data/rtcpsu.tcl | 51 +++ .../drivers/rtcpsu/examples/index.html | 23 + .../xrtcpsu_alarm_interrupt_example.c | 325 ++++++++++++++ .../examples/xrtcpsu_alarm_polled_example.c | 175 ++++++++ ...xrtcpsu_periodic_alarm_interrupt_example.c | 327 ++++++++++++++ .../xrtcpsu_seconds_interrupt_example.c | 311 +++++++++++++ .../examples/xrtcpsu_seconds_polled_example.c | 167 +++++++ .../xrtcpsu_set_calibration_example.c | 178 ++++++++ .../examples/xrtcpsu_set_time_example.c | 175 ++++++++ .../drivers/rtcpsu/src/Makefile | 40 ++ .../drivers/rtcpsu/src/xrtcpsu.c | 413 ++++++++++++++++++ .../drivers/rtcpsu/src/xrtcpsu.h | 381 ++++++++++++++++ .../drivers/rtcpsu/src/xrtcpsu_g.c | 78 ++++ .../drivers/rtcpsu/src/xrtcpsu_hw.h | 357 +++++++++++++++ .../drivers/rtcpsu/src/xrtcpsu_intr.c | 229 ++++++++++ .../drivers/rtcpsu/src/xrtcpsu_selftest.c | 109 +++++ .../drivers/rtcpsu/src/xrtcpsu_sinit.c | 99 +++++ 18 files changed, 3480 insertions(+) create mode 100755 XilinxProcessorIPLib/drivers/rtcpsu/data/rtcpsu.mdd create mode 100755 XilinxProcessorIPLib/drivers/rtcpsu/data/rtcpsu.tcl create mode 100644 XilinxProcessorIPLib/drivers/rtcpsu/examples/index.html create mode 100644 XilinxProcessorIPLib/drivers/rtcpsu/examples/xrtcpsu_alarm_interrupt_example.c create mode 100644 XilinxProcessorIPLib/drivers/rtcpsu/examples/xrtcpsu_alarm_polled_example.c create mode 100644 XilinxProcessorIPLib/drivers/rtcpsu/examples/xrtcpsu_periodic_alarm_interrupt_example.c create mode 100644 XilinxProcessorIPLib/drivers/rtcpsu/examples/xrtcpsu_seconds_interrupt_example.c create mode 100644 XilinxProcessorIPLib/drivers/rtcpsu/examples/xrtcpsu_seconds_polled_example.c create mode 100644 XilinxProcessorIPLib/drivers/rtcpsu/examples/xrtcpsu_set_calibration_example.c create mode 100644 XilinxProcessorIPLib/drivers/rtcpsu/examples/xrtcpsu_set_time_example.c create mode 100644 XilinxProcessorIPLib/drivers/rtcpsu/src/Makefile create mode 100644 XilinxProcessorIPLib/drivers/rtcpsu/src/xrtcpsu.c create mode 100644 XilinxProcessorIPLib/drivers/rtcpsu/src/xrtcpsu.h create mode 100644 XilinxProcessorIPLib/drivers/rtcpsu/src/xrtcpsu_g.c create mode 100644 XilinxProcessorIPLib/drivers/rtcpsu/src/xrtcpsu_hw.h create mode 100644 XilinxProcessorIPLib/drivers/rtcpsu/src/xrtcpsu_intr.c create mode 100644 XilinxProcessorIPLib/drivers/rtcpsu/src/xrtcpsu_selftest.c create mode 100644 XilinxProcessorIPLib/drivers/rtcpsu/src/xrtcpsu_sinit.c diff --git a/XilinxProcessorIPLib/drivers/rtcpsu/data/rtcpsu.mdd b/XilinxProcessorIPLib/drivers/rtcpsu/data/rtcpsu.mdd new file mode 100755 index 00000000..895c5b13 --- /dev/null +++ b/XilinxProcessorIPLib/drivers/rtcpsu/data/rtcpsu.mdd @@ -0,0 +1,42 @@ +############################################################################### +# +# Copyright (C) 2015 Xilinx, Inc. All rights reserved. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# Use of the Software is limited solely to applications: +# (a) running on a Xilinx device, or +# (b) that interact with a Xilinx device through a bus or interconnect. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# XILINX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF +# OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# +# Except as contained in this notice, the name of the Xilinx shall not be used +# in advertising or otherwise to promote the sale, use or other dealings in +# this Software without prior written authorization from Xilinx. +# +############################################################################### +OPTION psf_version = 2.1; + +BEGIN driver rtcpsu + + OPTION supported_peripherals = (psu_rtc); + OPTION driver_state = ACTIVE; + OPTION copyfiles = all; + OPTION VERSION = 1.0; + OPTION NAME = rtcpsu; + +END driver diff --git a/XilinxProcessorIPLib/drivers/rtcpsu/data/rtcpsu.tcl b/XilinxProcessorIPLib/drivers/rtcpsu/data/rtcpsu.tcl new file mode 100755 index 00000000..826ae126 --- /dev/null +++ b/XilinxProcessorIPLib/drivers/rtcpsu/data/rtcpsu.tcl @@ -0,0 +1,51 @@ +############################################################################### +# +# Copyright (C) 2015 Xilinx, Inc. All rights reserved. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# Use of the Software is limited solely to applications: +# (a) running on a Xilinx device, or +# (b) that interact with a Xilinx device through a bus or interconnect. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# XILINX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF +# OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# +# Except as contained in this notice, the name of the Xilinx shall not be used +# in advertising or otherwise to promote the sale, use or other dealings in +# this Software without prior written authorization from Xilinx. +# +############################################################################### +############################################################################## +# +# Modification History +# +# Ver Who Date Changes +# ----- ---- -------- ----------------------------------------------- +# 1.0 kvn 4/21/15 First release +# +############################################################################## + +#uses "xillib.tcl" + +proc generate {drv_handle} { + ::hsi::utils::define_zynq_include_file $drv_handle "xparameters.h" "XRtcPsu" "NUM_INSTANCES" "DEVICE_ID" "C_S_AXI_BASEADDR" "C_S_AXI_HIGHADDR" + + ::hsi::utils::define_zynq_config_file $drv_handle "xrtcpsu_g.c" "XRtcPsu" "DEVICE_ID" "C_S_AXI_BASEADDR" + + ::hsi::utils::define_zynq_canonical_xpars $drv_handle "xparameters.h" "XRtcPsu" "DEVICE_ID" "C_S_AXI_BASEADDR" "C_S_AXI_HIGHADDR" + +} diff --git a/XilinxProcessorIPLib/drivers/rtcpsu/examples/index.html b/XilinxProcessorIPLib/drivers/rtcpsu/examples/index.html new file mode 100644 index 00000000..c615e00c --- /dev/null +++ b/XilinxProcessorIPLib/drivers/rtcpsu/examples/index.html @@ -0,0 +1,23 @@ + + + + + +Driver example applications + + + +

Example Applications for the driver rtcpsu_v1_0

+
+ +

Copyright � 1995-2014 Xilinx, Inc. All rights reserved.

+ + diff --git a/XilinxProcessorIPLib/drivers/rtcpsu/examples/xrtcpsu_alarm_interrupt_example.c b/XilinxProcessorIPLib/drivers/rtcpsu/examples/xrtcpsu_alarm_interrupt_example.c new file mode 100644 index 00000000..1bdaf4fa --- /dev/null +++ b/XilinxProcessorIPLib/drivers/rtcpsu/examples/xrtcpsu_alarm_interrupt_example.c @@ -0,0 +1,325 @@ +/****************************************************************************** +* +* Copyright (C) 2015 Xilinx, Inc. All rights reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* Use of the Software is limited solely to applications: +* (a) running on a Xilinx device, or +* (b) that interact with a Xilinx device through a bus or interconnect. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* XILINX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF +* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +* +* Except as contained in this notice, the name of the Xilinx shall not be used +* in advertising or otherwise to promote the sale, use or other dealings in +* this Software without prior written authorization from Xilinx. +* +******************************************************************************/ +/****************************************************************************/ +/** +* +* @file xrtcpsu_alarm_intr_example.c +* +* This file contains an alarm example using the XRtcPsu driver in interrupt +* mode. It sets alarm for a specified time from the current time. +* +* +* @note +* The example contains an infinite loop such that if interrupts are not +* working it may hang. +* +* MODIFICATION HISTORY: +*
+* Ver   Who    Date     Changes
+* ----- ------ -------- ----------------------------------------------
+* 1.00  kvn 05/12/15 First Release
+*
+* 
+****************************************************************************/ + +/***************************** Include Files *******************************/ + +#include "xparameters.h" /* SDK generated parameters */ +#include "xrtcpsu.h" /* RTCPSU device driver */ +#include "xscugic.h" /* Interrupt controller device driver */ +#include "xil_exception.h" +#include "xil_printf.h" + +/************************** Constant Definitions **************************/ + +/* + * The following constants map to the XPAR parameters created in the + * xparameters.h file. They are defined here such that a user can easily + * change all the needed parameters in one place. + */ + +#define RTC_DEVICE_ID XPAR_XRTCPSU_0_DEVICE_ID +#define INTC_DEVICE_ID XPAR_SCUGIC_SINGLE_DEVICE_ID +#define RTC_ALARM_INT_IRQ_ID XPAR_XRTCPSU_ALARM_INTR + +/**************************** Type Definitions *******************************/ + +/***************** Macros (Inline Functions) Definitions *********************/ +#define ALARM_PERIOD 10U + +/************************** Function Prototypes *****************************/ + +int RtcPsuAlarmIntrExample(XScuGic *IntcInstPtr, XRtcPsu *RtcInstPtr, + u16 DeviceId, u16 RtcIntrId); + + +static int SetupInterruptSystem(XScuGic *IntcInstancePtr, + XRtcPsu *RtcInstancePtr, + u16 RtcIntrId); + +void Handler(void *CallBackRef, u32 Event); + + +/************************** Variable Definitions ***************************/ + +XRtcPsu RtcPsu; /* Instance of the RTC Device */ +XScuGic InterruptController; /* Instance of the Interrupt Controller */ +u32 IsAlarmGen; + + +/**************************************************************************/ +/** +* +* Main function to call the RTC Alarm interrupt example. +* +* @param None +* +* @return XST_SUCCESS if successful, XST_FAILURE if unsuccessful +* +* @note None +* +**************************************************************************/ +#ifndef TESTAPP_GEN +int main(void) +{ + int Status; + + /* Run the RtcPsu Interrupt example, specify the the Device ID */ + Status = RtcPsuAlarmIntrExample(&InterruptController, &RtcPsu, + RTC_DEVICE_ID, RTC_ALARM_INT_IRQ_ID); + if (Status != XST_SUCCESS) { + xil_printf("RTC Alarm Interrupt Example Test Failed\r\n"); + return XST_FAILURE; + } + + xil_printf("Successfully ran RTC Alarm Interrupt Example Test\r\n"); + return XST_SUCCESS; +} +#endif + +/**************************************************************************/ +/** +* +* This function does a minimal test on the Rtc device and driver as a +* design example. The purpose of this function is to illustrate +* how to use alarm feature in the XRtcPsu driver. +* +* This function sets alarm for a specified time from the current time. +* +* @param IntcInstPtr is a pointer to the instance of the ScuGic driver. +* @param RtcInstPtr is a pointer to the instance of the RTC driver +* which is going to be connected to the interrupt controller. +* @param DeviceId is the device Id of the RTC device and is typically +* XPAR__DEVICE_ID value from xparameters.h. +* @param RtcIntrId is the interrupt Id and is typically +* XPAR__INTR value from xparameters.h. +* +* @return XST_SUCCESS if successful, otherwise XST_FAILURE. +* +* @note +* +* This function contains an infinite loop such that if interrupts are not +* working it may never return. +* +**************************************************************************/ +int RtcPsuAlarmIntrExample(XScuGic *IntcInstPtr, XRtcPsu *RtcInstPtr, + u16 DeviceId, u16 RtcIntrId) +{ + int Status; + XRtcPsu_Config *Config; + u32 CurrentTime, Alarm; + XRtcPsu_DT dt0; + + /* + * Initialize the RTC driver so that it's ready to use + * Look up the configuration in the config table, then initialize it. + */ + Config = XRtcPsu_LookupConfig(DeviceId); + if (NULL == Config) { + return XST_FAILURE; + } + + Status = XRtcPsu_CfgInitialize(RtcInstPtr, Config, Config->BaseAddr); + if (Status != XST_SUCCESS) { + return XST_FAILURE; + } + + /* Check hardware build */ + Status = XRtcPsu_SelfTest(RtcInstPtr); + if (Status != XST_SUCCESS) { + return XST_FAILURE; + } + + xil_printf("\n\rDay Convention : 0-Fri, 1-Sat, 2-Sun, 3-Mon, 4-Tue, 5-Wed, 6-Thur\n\r"); + xil_printf("Current RTC time is..\n\r"); + CurrentTime = XRtcPsu_GetCurrentTime(RtcInstPtr); + XRtcPsu_SecToDateTime(CurrentTime,&dt0); + xil_printf("YEAR:MM:DD HR:MM:SS \t %04d:%02d:%02d %02d:%02d:%02d\t Day = %d\n\r", + dt0.Year,dt0.Month,dt0.Day,dt0.Hour,dt0.Min,dt0.Sec,dt0.WeekDay); + + /* + * Connect the RTC to the interrupt subsystem such that interrupts + * can occur. This function is application specific. + */ + Status = SetupInterruptSystem(IntcInstPtr, RtcInstPtr, RtcIntrId); + if (Status != XST_SUCCESS) { + return XST_FAILURE; + } + + /* + * Setup the handlers for the RTC that will be called from the + * interrupt context when alarm and seconds interrupts are raised, + * specify a pointer to the RTC driver instance as the callback reference + * so the handlers are able to access the instance data + */ + XRtcPsu_SetHandler(RtcInstPtr, (XRtcPsu_Handler)Handler, RtcInstPtr); + + /* + * Enable the interrupt of the RTC device so interrupts will occur. + */ + XRtcPsu_SetInterruptMask(RtcInstPtr, XRTC_INT_EN_ALRM_MASK ); + + CurrentTime = XRtcPsu_GetCurrentTime(RtcInstPtr); + Alarm = CurrentTime + ALARM_PERIOD; + XRtcPsu_SetAlarm(RtcInstPtr,Alarm,0); + + while( IsAlarmGen != 1); + + /* + * Disable the interrupt of the RTC device so interrupts will not occur. + */ + XRtcPsu_ClearInterruptMask(RtcInstPtr,XRTC_INT_DIS_ALRM_MASK); + + return XST_SUCCESS; +} + +/**************************************************************************/ +/** +* +* This function is the handler which performs processing to handle interrupt +* events from the device. It is called from an interrupt context. so the +* amount of processing should be minimal. +* +* This handler provides an example of how to handle interrupt data for the +* device and is application specific. +* +* @param CallBackRef contains a callback reference from the driver, +* in this case it is the instance pointer for the XRtcPsu driver. +* @param Event contains the specific kind of event that has occurred. +* +* @return None. +* +* @note None. +* +***************************************************************************/ +void Handler(void *CallBackRef, u32 Event) +{ + /* Alarm event */ + if (Event == XRTCPSU_EVENT_ALARM_GEN) { + IsAlarmGen = 1; + xil_printf("Alarm generated.\n\r"); + } +} + + +/*****************************************************************************/ +/** +* +* This function sets up the interrupt system so interrupts can occur for the +* RTC. This function is application-specific. The user should modify this +* function to fit the application. +* +* @param IntcInstancePtr is a pointer to the instance of the INTC. +* @param RtcInstancePtr contains a pointer to the instance of the RTC +* driver which is going to be connected to the interrupt +* controller. +* @param RtcIntrId is the interrupt Id and is typically +* XPAR__INTR value from xparameters_ps.h. +* +* @return XST_SUCCESS if successful, otherwise XST_FAILURE. +* +* @note None. +* +****************************************************************************/ +static int SetupInterruptSystem(XScuGic *IntcInstancePtr, + XRtcPsu *RtcInstancePtr, + u16 RtcIntrId) +{ + int Status; + +#ifndef TESTAPP_GEN + XScuGic_Config *IntcConfig; /* Config for interrupt controller */ + + /* Initialize the interrupt controller driver */ + IntcConfig = XScuGic_LookupConfig(INTC_DEVICE_ID); + if (NULL == IntcConfig) { + return XST_FAILURE; + } + + Status = XScuGic_CfgInitialize(IntcInstancePtr, IntcConfig, + IntcConfig->CpuBaseAddress); + if (Status != XST_SUCCESS) { + return XST_FAILURE; + } + + /* + * Connect the interrupt controller interrupt handler to the + * hardware interrupt handling logic in the processor. + */ + Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT, + (Xil_ExceptionHandler) XScuGic_InterruptHandler, + IntcInstancePtr); +#endif + + /* + * Connect a device driver handler that will be called when an + * interrupt for the device occurs, the device driver handler + * performs the specific interrupt processing for the device + */ + Status = XScuGic_Connect(IntcInstancePtr, RtcIntrId, + (Xil_ExceptionHandler) XRtcPsu_InterruptHandler, + (void *) RtcInstancePtr); + if (Status != XST_SUCCESS) { + return XST_FAILURE; + } + + /* Enable the interrupt for the device */ + XScuGic_Enable(IntcInstancePtr, RtcIntrId); + + +#ifndef TESTAPP_GEN + /* Enable interrupts */ + Xil_ExceptionEnable(); +#endif + + return XST_SUCCESS; +} diff --git a/XilinxProcessorIPLib/drivers/rtcpsu/examples/xrtcpsu_alarm_polled_example.c b/XilinxProcessorIPLib/drivers/rtcpsu/examples/xrtcpsu_alarm_polled_example.c new file mode 100644 index 00000000..952ce631 --- /dev/null +++ b/XilinxProcessorIPLib/drivers/rtcpsu/examples/xrtcpsu_alarm_polled_example.c @@ -0,0 +1,175 @@ +/****************************************************************************** +* +* Copyright (C) 2015 Xilinx, Inc. All rights reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* Use of the Software is limited solely to applications: +* (a) running on a Xilinx device, or +* (b) that interact with a Xilinx device through a bus or interconnect. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* XILINX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF +* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +* +* Except as contained in this notice, the name of the Xilinx shall not be used +* in advertising or otherwise to promote the sale, use or other dealings in +* this Software without prior written authorization from Xilinx. +* +******************************************************************************/ +/****************************************************************************/ +/** +* +* @file xrtcpsu_alarm_polled_example.c +* +* This file contains an example using the XRtcPsu driver in polled mode. +* +* This function sets alarm for a specified time from the current time. +* +* @note +* If the device does not work properly, the example may hang. +* +* MODIFICATION HISTORY: +*
+* Ver   Who    Date     Changes
+* ----- ------ -------- -----------------------------------------------
+* 1.00  kvn 05/12/15 First Release
+*
+* 
+******************************************************************************/ + +/***************************** Include Files *********************************/ + +#include "xparameters.h" /* SDK generated parameters */ +#include "xrtcpsu.h" /* RTCPSU device driver */ +#include "xil_printf.h" + +/************************** Constant Definitions *****************************/ + +/* + * The following constants map to the XPAR parameters created in the + * xparameters.h file. They are defined here such that a user can easily + * change all the needed parameters in one place. + */ +#define RTC_DEVICE_ID XPAR_XRTCPSU_0_DEVICE_ID + +/**************************** Type Definitions *******************************/ + +/***************** Macros (Inline Functions) Definitions *********************/ +#define ALARM_PERIOD 10U + +/************************** Function Prototypes ******************************/ + +int RtcPsuAlarmPolledExample(u16 DeviceId); + +/************************** Variable Definitions *****************************/ + +XRtcPsu Rtc_Psu; /* Instance of the RTC Device */ + +/*****************************************************************************/ +/** +* +* Main function to call the Rtc Alarm Polled mode example. +* +* @param None +* +* @return XST_SUCCESS if succesful, otherwise XST_FAILURE +* +* @note None +* +******************************************************************************/ +#ifndef TESTAPP_GEN +int main(void) +{ + int Status; + + /* + * Run the Rtc_Psu polled example , specify the the Device ID that is + * generated in xparameters.h + */ + Status = RtcPsuAlarmPolledExample(RTC_DEVICE_ID); + if (Status != XST_SUCCESS) { + xil_printf("RTC Alarm Polled Mode Example Test Failed\r\n"); + return XST_FAILURE; + } + + xil_printf("Successfully ran RTC Alarm Polled Mode Example Test\r\n"); + return XST_SUCCESS; +} +#endif + +/*****************************************************************************/ +/** +* +* This function does a minimal Alarm test on the XRtcPsu device in polled mode. +* +* This function sets one time alarm from the current time to a specified time. +* +* @param DeviceId is the unique device id from hardware build. +* +* @return XST_SUCCESS if successful, XST_FAILURE if unsuccessful +* +* @note +* This function polls the RTC, it may hang if the hardware is not +* working correctly. +* +****************************************************************************/ +int RtcPsuAlarmPolledExample(u16 DeviceId) +{ + int Status; + XRtcPsu_Config *Config; + u32 CurrentTime, AlarmTime; + XRtcPsu_DT dt0; + + /* + * Initialize the RTC driver so that it's ready to use. + * Look up the configuration in the config table, then initialize it. + */ + Config = XRtcPsu_LookupConfig(DeviceId); + if (NULL == Config) { + return XST_FAILURE; + } + + Status = XRtcPsu_CfgInitialize(&Rtc_Psu, Config, Config->BaseAddr); + if (Status != XST_SUCCESS) { + return XST_FAILURE; + } + + /* Check hardware build. */ + Status = XRtcPsu_SelfTest(&Rtc_Psu); + if (Status != XST_SUCCESS) { + return XST_FAILURE; + } + + xil_printf("\n\rDay Convention : 0-Fri, 1-Sat, 2-Sun, 3-Mon, 4-Tue, 5-Wed, 6-Thur\n\r"); + xil_printf("Current RTC time is..\n\r"); + CurrentTime = XRtcPsu_GetCurrentTime(&Rtc_Psu); + XRtcPsu_SecToDateTime(CurrentTime,&dt0); + xil_printf("YEAR:MM:DD HR:MM:SS \t %04d:%02d:%02d %02d:%02d:%02d\t Day = %d\n\r", + dt0.Year,dt0.Month,dt0.Day,dt0.Hour,dt0.Min,dt0.Sec,dt0.WeekDay); + + CurrentTime = XRtcPsu_GetCurrentTime(&Rtc_Psu); + AlarmTime = CurrentTime + ALARM_PERIOD; + XRtcPsu_SetAlarm(&Rtc_Psu,AlarmTime,0U); + + /* + * If Alarm was not generated, then the processor goes into an infinite + * loop. This represents a failure case of alarm example. + */ + while (!XRtcPsu_IsAlarmEventGenerated(&Rtc_Psu)); + xil_printf("Alarm generated.\n\r"); + + return XST_SUCCESS; +} diff --git a/XilinxProcessorIPLib/drivers/rtcpsu/examples/xrtcpsu_periodic_alarm_interrupt_example.c b/XilinxProcessorIPLib/drivers/rtcpsu/examples/xrtcpsu_periodic_alarm_interrupt_example.c new file mode 100644 index 00000000..894100bf --- /dev/null +++ b/XilinxProcessorIPLib/drivers/rtcpsu/examples/xrtcpsu_periodic_alarm_interrupt_example.c @@ -0,0 +1,327 @@ +/****************************************************************************** +* +* Copyright (C) 2015 Xilinx, Inc. All rights reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* Use of the Software is limited solely to applications: +* (a) running on a Xilinx device, or +* (b) that interact with a Xilinx device through a bus or interconnect. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* XILINX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF +* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +* +* Except as contained in this notice, the name of the Xilinx shall not be used +* in advertising or otherwise to promote the sale, use or other dealings in +* this Software without prior written authorization from Xilinx. +* +******************************************************************************/ +/****************************************************************************/ +/** +* +* @file xrtcpsu_periodic_alarm_intr_example.c +* +* This file contains an periodic alarm example using the XRtcPsu driver in interrupt +* mode. It sets periodical alarm for specified times from the current time. For +* demontration purpose, a periodic alarm for future 2Secs was implemented for 10 +* such events. +* +* +* @note +* In the example if interrupts are not working it may hang. +* +* MODIFICATION HISTORY: +*
+* Ver   Who    Date     Changes
+* ----- ------ -------- ----------------------------------------------
+* 1.00  kvn 05/12/15 First Release
+*
+* 
+****************************************************************************/ + +/***************************** Include Files *******************************/ + +#include "xparameters.h" /* SDK generated parameters */ +#include "xrtcpsu.h" /* RTCPSU device driver */ +#include "xscugic.h" /* Interrupt controller device driver */ +#include "xil_exception.h" +#include "xil_printf.h" + +/************************** Constant Definitions **************************/ + +/* + * The following constants map to the XPAR parameters created in the + * xparameters.h file. They are defined here such that a user can easily + * change all the needed parameters in one place. + */ + +#define RTC_DEVICE_ID XPAR_XRTCPSU_0_DEVICE_ID +#define INTC_DEVICE_ID XPAR_SCUGIC_SINGLE_DEVICE_ID +#define RTC_ALARM_INT_IRQ_ID XPAR_XRTCPSU_ALARM_INTR + +/**************************** Type Definitions *******************************/ + +/***************** Macros (Inline Functions) Definitions *********************/ +#define REPETATIONS 10 +#define PERIODIC_ALARM_PERIOD 2U + +/************************** Function Prototypes *****************************/ + +int RtcPsuPeriodicAlarmIntrExample(XScuGic *IntcInstPtr, XRtcPsu *RtcInstPtr, + u16 DeviceId, u16 RtcIntrId); + + +static int SetupInterruptSystem(XScuGic *IntcInstancePtr, + XRtcPsu *RtcInstancePtr, + u16 RtcIntrId); + +void Handler(void *CallBackRef, u32 Event); + + +/************************** Variable Definitions ***************************/ + +XRtcPsu RtcPsu; /* Instance of the RTC Device */ +XScuGic InterruptController; /* Instance of the Interrupt Controller */ +u32 PeriodicAlarms; + + +/**************************************************************************/ +/** +* +* Main function to call the RTC Alarm interrupt example. +* +* @param None +* +* @return XST_SUCCESS if successful, XST_FAILURE if unsuccessful +* +* @note None +* +**************************************************************************/ +#ifndef TESTAPP_GEN +int main(void) +{ + int Status; + + /* Run the RtcPsu Interrupt example, specify the the Device ID */ + Status = RtcPsuPeriodicAlarmIntrExample(&InterruptController, &RtcPsu, + RTC_DEVICE_ID, RTC_ALARM_INT_IRQ_ID); + if (Status != XST_SUCCESS) { + xil_printf("RTC Periodic Alarm Interrupt Example Test Failed\r\n"); + return XST_FAILURE; + } + + xil_printf("Successfully ran RTC Periodic Alarm Interrupt Example Test\r\n"); + return XST_SUCCESS; +} +#endif + +/**************************************************************************/ +/** +* +* This function does a minimal test on the Rtc device and driver as a +* design example. The purpose of this function is to illustrate +* how to use periodic alarm feature in the XRtcPsu driver. +* +* This function sets periodical alarm for specified times from the current. +* +* @param IntcInstPtr is a pointer to the instance of the ScuGic driver. +* @param RtcInstPtr is a pointer to the instance of the RTC driver +* which is going to be connected to the interrupt controller. +* @param DeviceId is the device Id of the RTC device and is typically +* XPAR__DEVICE_ID value from xparameters.h. +* @param RtcIntrId is the interrupt Id and is typically +* XPAR__INTR value from xparameters_ps.h. +* +* @return XST_SUCCESS if successful, otherwise XST_FAILURE. +* +* @note +* +* In this function if interrupts are not working it may never return. +* +**************************************************************************/ +int RtcPsuPeriodicAlarmIntrExample(XScuGic *IntcInstPtr, XRtcPsu *RtcInstPtr, + u16 DeviceId, u16 RtcIntrId) +{ + int Status; + XRtcPsu_Config *Config; + u32 CurrentTime, Alarm; + XRtcPsu_DT dt0; + + /* + * Initialize the RTC driver so that it's ready to use + * Look up the configuration in the config table, then initialize it. + */ + Config = XRtcPsu_LookupConfig(DeviceId); + if (NULL == Config) { + return XST_FAILURE; + } + + Status = XRtcPsu_CfgInitialize(RtcInstPtr, Config, Config->BaseAddr); + if (Status != XST_SUCCESS) { + return XST_FAILURE; + } + + /* Check hardware build */ + Status = XRtcPsu_SelfTest(RtcInstPtr); + if (Status != XST_SUCCESS) { + return XST_FAILURE; + } + + xil_printf("\n\rDay Convention : 0-Fri, 1-Sat, 2-Sun, 3-Mon, 4-Tue, 5-Wed, 6-Thur\n\r"); + xil_printf("Current RTC time is..\n\r"); + CurrentTime = XRtcPsu_GetCurrentTime(RtcInstPtr); + XRtcPsu_SecToDateTime(CurrentTime,&dt0); + xil_printf("YEAR:MM:DD HR:MM:SS \t %04d:%02d:%02d %02d:%02d:%02d\t Day = %d\n\r", + dt0.Year,dt0.Month,dt0.Day,dt0.Hour,dt0.Min,dt0.Sec,dt0.WeekDay); + + /* + * Connect the RTC to the interrupt subsystem such that interrupts + * can occur. This function is application specific. + */ + Status = SetupInterruptSystem(IntcInstPtr, RtcInstPtr, RtcIntrId); + if (Status != XST_SUCCESS) { + return XST_FAILURE; + } + + /* + * Setup the handlers for the RTC that will be called from the + * interrupt context when alarm and seconds interrupts are raised, + * specify a pointer to the RTC driver instance as the callback reference + * so the handlers are able to access the instance data + */ + XRtcPsu_SetHandler(RtcInstPtr, (XRtcPsu_Handler)Handler, RtcInstPtr); + + /* + * Enable the interrupt of the RTC device so interrupts will occur. + */ + XRtcPsu_SetInterruptMask(RtcInstPtr, XRTC_INT_EN_ALRM_MASK ); + + CurrentTime = XRtcPsu_GetCurrentTime(RtcInstPtr); + Alarm = CurrentTime + PERIODIC_ALARM_PERIOD; + XRtcPsu_SetAlarm(RtcInstPtr,Alarm,1U); + + while( PeriodicAlarms != REPETATIONS); + + /* + * Disable the interrupt of the RTC device so interrupts will not occur. + */ + XRtcPsu_ClearInterruptMask(RtcInstPtr,XRTC_INT_DIS_ALRM_MASK); + XRtcPsu_ResetAlarm(RtcInstPtr); + + return XST_SUCCESS; +} + +/**************************************************************************/ +/** +* +* This function is the handler which performs processing to handle interrupt +* events from the device. It is called from an interrupt context. so the +* amount of processing should be minimal. +* +* This handler provides an example of how to handle interrupt data for the +* device and is application specific. +* +* @param CallBackRef contains a callback reference from the driver, +* in this case it is the instance pointer for the XRtcPsu driver. +* @param Event contains the specific kind of event that has occurred. +* +* @return None. +* +* @note None. +* +***************************************************************************/ +void Handler(void *CallBackRef, u32 Event) +{ + /* Alarm event */ + if (Event == XRTCPSU_EVENT_ALARM_GEN) { + PeriodicAlarms++; + xil_printf("%dSec Periodic Alarm generated.\n\r",PERIODIC_ALARM_PERIOD); + } +} + + +/*****************************************************************************/ +/** +* +* This function sets up the interrupt system so interrupts can occur for the +* RTC. This function is application-specific. The user should modify this +* function to fit the application. +* +* @param IntcInstancePtr is a pointer to the instance of the INTC. +* @param RtcInstancePtr contains a pointer to the instance of the RTC +* driver which is going to be connected to the interrupt +* controller. +* @param RtcIntrId is the interrupt Id and is typically +* XPAR__INTR value from xparameters.h. +* +* @return XST_SUCCESS if successful, otherwise XST_FAILURE. +* +* @note None. +* +****************************************************************************/ +static int SetupInterruptSystem(XScuGic *IntcInstancePtr, + XRtcPsu *RtcInstancePtr, + u16 RtcIntrId) +{ + int Status; + +#ifndef TESTAPP_GEN + XScuGic_Config *IntcConfig; /* Config for interrupt controller */ + + /* Initialize the interrupt controller driver */ + IntcConfig = XScuGic_LookupConfig(INTC_DEVICE_ID); + if (NULL == IntcConfig) { + return XST_FAILURE; + } + + Status = XScuGic_CfgInitialize(IntcInstancePtr, IntcConfig, + IntcConfig->CpuBaseAddress); + if (Status != XST_SUCCESS) { + return XST_FAILURE; + } + + /* + * Connect the interrupt controller interrupt handler to the + * hardware interrupt handling logic in the processor. + */ + Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT, + (Xil_ExceptionHandler) XScuGic_InterruptHandler, + IntcInstancePtr); +#endif + + /* + * Connect a device driver handler that will be called when an + * interrupt for the device occurs, the device driver handler + * performs the specific interrupt processing for the device + */ + Status = XScuGic_Connect(IntcInstancePtr, RtcIntrId, + (Xil_ExceptionHandler) XRtcPsu_InterruptHandler, + (void *) RtcInstancePtr); + if (Status != XST_SUCCESS) { + return XST_FAILURE; + } + + /* Enable the interrupt for the device */ + XScuGic_Enable(IntcInstancePtr, RtcIntrId); + + +#ifndef TESTAPP_GEN + /* Enable interrupts */ + Xil_ExceptionEnable(); +#endif + + return XST_SUCCESS; +} diff --git a/XilinxProcessorIPLib/drivers/rtcpsu/examples/xrtcpsu_seconds_interrupt_example.c b/XilinxProcessorIPLib/drivers/rtcpsu/examples/xrtcpsu_seconds_interrupt_example.c new file mode 100644 index 00000000..2a67eb6f --- /dev/null +++ b/XilinxProcessorIPLib/drivers/rtcpsu/examples/xrtcpsu_seconds_interrupt_example.c @@ -0,0 +1,311 @@ +/****************************************************************************** +* +* Copyright (C) 2015 Xilinx, Inc. All rights reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* Use of the Software is limited solely to applications: +* (a) running on a Xilinx device, or +* (b) that interact with a Xilinx device through a bus or interconnect. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* XILINX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF +* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +* +* Except as contained in this notice, the name of the Xilinx shall not be used +* in advertising or otherwise to promote the sale, use or other dealings in +* this Software without prior written authorization from Xilinx. +* +******************************************************************************/ +/****************************************************************************/ +/** +* +* @file xrtcpsu_seconds_intr_example.c +* +* This file contains an seconds example using the XRtcPsu driver in interrupt +* mode. +* +* +* @note +* In the example,if interrupts are not working it may hang. +* +* MODIFICATION HISTORY: +*
+* Ver   Who    Date     Changes
+* ----- ------ -------- ----------------------------------------------
+* 1.00  kvn 05/12/15 First Release
+*
+* 
+****************************************************************************/ + +/***************************** Include Files *******************************/ + +#include "xparameters.h" /* SDK generated parameters */ +#include "xrtcpsu.h" /* RTCPSU device driver */ +#include "xscugic.h" /* Interrupt controller device driver */ +#include "xil_exception.h" +#include "xil_printf.h" + +/************************** Constant Definitions **************************/ + +/* + * The following constants map to the XPAR parameters created in the + * xparameters.h file. They are defined here such that a user can easily + * change all the needed parameters in one place. + */ + +#define RTC_DEVICE_ID XPAR_XRTCPSU_0_DEVICE_ID +#define INTC_DEVICE_ID XPAR_SCUGIC_SINGLE_DEVICE_ID +#define RTC_SEC_INT_IRQ_ID XPAR_XRTCPSU_SECONDS_INTR + + +/**************************** Type Definitions ******************************/ + +/***************** Macros (Inline Functions) Definitions *********************/ +#define REPETATIONS 10 + +/************************** Function Prototypes *****************************/ + +int RtcPsuSecondsIntrExample(XScuGic *IntcInstPtr, XRtcPsu *RtcInstPtr, + u16 DeviceId, u16 RtcIntrId); + + +static int SetupInterruptSystem(XScuGic *IntcInstancePtr, + XRtcPsu *RtcInstancePtr, + u16 RtcIntrId); + +void Handler(void *CallBackRef, u32 Event); + + +/************************** Variable Definitions ***************************/ + +XRtcPsu RtcPsu; /* Instance of the RTC Device */ +XScuGic InterruptController; /* Instance of the Interrupt Controller */ +u32 Seconds = 0; + + +/**************************************************************************/ +/** +* +* Main function to call the RTC Seconds interrupt example. +* +* @param None +* +* @return XST_SUCCESS if successful, XST_FAILURE if unsuccessful +* +* @note None +* +**************************************************************************/ +#ifndef TESTAPP_GEN +int main(void) +{ + int Status; + + /* Run the RtcPsu Interrupt example, specify the the Device ID */ + Status = RtcPsuSecondsIntrExample(&InterruptController, &RtcPsu, + RTC_DEVICE_ID, RTC_SEC_INT_IRQ_ID); + if (Status != XST_SUCCESS) { + xil_printf("RTC Seconds Interrupt Example Test Failed\r\n"); + return XST_FAILURE; + } + + xil_printf("Successfully ran RTC Seconds Interrupt Example Test\r\n"); + return XST_SUCCESS; +} +#endif + +/**************************************************************************/ +/** +* +* This function does a minimal test on the Rtc device and driver as a +* design example. The purpose of this function is to illustrate +* how to seconds feature is available in the XRtcPsu driver. +* +* This function shows the seconds interrupt feature.. +* +* @param IntcInstPtr is a pointer to the instance of the ScuGic driver. +* @param RtcInstPtr is a pointer to the instance of the RTC driver +* which is going to be connected to the interrupt controller. +* @param DeviceId is the device Id of the RTC device and is typically +* XPAR__DEVICE_ID value from xparameters.h. +* @param RtcIntrId is the interrupt Id and is typically +* XPAR__INTR value from xparameters.h. +* +* @return XST_SUCCESS if successful, otherwise XST_FAILURE. +* +* @note +* +* In this function ,if interrupts are not working it may never return. +* +**************************************************************************/ +int RtcPsuSecondsIntrExample(XScuGic *IntcInstPtr, XRtcPsu *RtcInstPtr, + u16 DeviceId, u16 RtcIntrId) +{ + int Status; + XRtcPsu_Config *Config; + + /* + * Initialize the RTC driver so that it's ready to use + * Look up the configuration in the config table, then initialize it. + */ + Config = XRtcPsu_LookupConfig(DeviceId); + if (NULL == Config) { + return XST_FAILURE; + } + + Status = XRtcPsu_CfgInitialize(RtcInstPtr, Config, Config->BaseAddr); + if (Status != XST_SUCCESS) { + return XST_FAILURE; + } + + /* Check hardware build */ + Status = XRtcPsu_SelfTest(RtcInstPtr); + if (Status != XST_SUCCESS) { + return XST_FAILURE; + } + + /* + * Connect the RTC to the interrupt subsystem such that interrupts + * can occur. This function is application specific. + */ + Status = SetupInterruptSystem(IntcInstPtr, RtcInstPtr, RtcIntrId); + if (Status != XST_SUCCESS) { + return XST_FAILURE; + } + + /* + * Setup the handlers for the RTC that will be called from the + * interrupt context when alarm and seconds interrupts are raised, + * specify a pointer to the RTC driver instance as the callback reference + * so the handlers are able to access the instance data + */ + XRtcPsu_SetHandler(RtcInstPtr, (XRtcPsu_Handler)Handler, RtcInstPtr); + + /* + * Enable the interrupt of the RTC device so interrupts will occur. + */ + XRtcPsu_SetInterruptMask(RtcInstPtr,XRTC_INT_EN_SECS_MASK); + + while( Seconds != REPETATIONS); + + /* + * Disable the interrupt of the RTC device so interrupts will not occur. + */ + XRtcPsu_ClearInterruptMask(RtcInstPtr,XRTC_INT_DIS_SECS_MASK); + + return XST_SUCCESS; +} + +/**************************************************************************/ +/** +* +* This function is the handler which performs processing to handle interrupt +* events from the device. It is called from an interrupt context. so the +* amount of processing should be minimal. +* +* This handler provides an example of how to handle interrupt data for the +* device and is application specific. +* +* @param CallBackRef contains a callback reference from the driver, +* in this case it is the instance pointer for the XRtcPsu driver. +* @param Event contains the specific kind of event that has occurred. +* +* @return None. +* +* @note None. +* +***************************************************************************/ +void Handler(void *CallBackRef, u32 Event) +{ + /* A new second event */ + if (Event == XRTCPSU_EVENT_SECS_GEN) { + Seconds++; + xil_printf("A new second is generated.\n\r"); + } +} + + +/*****************************************************************************/ +/** +* +* This function sets up the interrupt system so interrupts can occur for the +* RTC. This function is application-specific. The user should modify this +* function to fit the application. +* +* @param IntcInstancePtr is a pointer to the instance of the INTC. +* @param RtcInstancePtr contains a pointer to the instance of the RTC +* driver which is going to be connected to the interrupt +* controller. +* @param RtcIntrId is the interrupt Id and is typically +* XPAR__INTR value from xparameters.h. +* +* @return XST_SUCCESS if successful, otherwise XST_FAILURE. +* +* @note None. +* +****************************************************************************/ +static int SetupInterruptSystem(XScuGic *IntcInstancePtr, + XRtcPsu *RtcInstancePtr, + u16 RtcIntrId) +{ + int Status; + +#ifndef TESTAPP_GEN + XScuGic_Config *IntcConfig; /* Config for interrupt controller */ + + /* Initialize the interrupt controller driver */ + IntcConfig = XScuGic_LookupConfig(INTC_DEVICE_ID); + if (NULL == IntcConfig) { + return XST_FAILURE; + } + + Status = XScuGic_CfgInitialize(IntcInstancePtr, IntcConfig, + IntcConfig->CpuBaseAddress); + if (Status != XST_SUCCESS) { + return XST_FAILURE; + } + + /* + * Connect the interrupt controller interrupt handler to the + * hardware interrupt handling logic in the processor. + */ + Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT, + (Xil_ExceptionHandler) XScuGic_InterruptHandler, + IntcInstancePtr); +#endif + + /* + * Connect a device driver handler that will be called when an + * interrupt for the device occurs, the device driver handler + * performs the specific interrupt processing for the device + */ + Status = XScuGic_Connect(IntcInstancePtr, RtcIntrId, + (Xil_ExceptionHandler) XRtcPsu_InterruptHandler, + (void *) RtcInstancePtr); + if (Status != XST_SUCCESS) { + return XST_FAILURE; + } + + /* Enable the interrupt for the device */ + XScuGic_Enable(IntcInstancePtr, RtcIntrId); + + +#ifndef TESTAPP_GEN + /* Enable interrupts */ + Xil_ExceptionEnable(); +#endif + + return XST_SUCCESS; +} diff --git a/XilinxProcessorIPLib/drivers/rtcpsu/examples/xrtcpsu_seconds_polled_example.c b/XilinxProcessorIPLib/drivers/rtcpsu/examples/xrtcpsu_seconds_polled_example.c new file mode 100644 index 00000000..d9d34605 --- /dev/null +++ b/XilinxProcessorIPLib/drivers/rtcpsu/examples/xrtcpsu_seconds_polled_example.c @@ -0,0 +1,167 @@ +/****************************************************************************** +* +* Copyright (C) 2015 Xilinx, Inc. All rights reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* Use of the Software is limited solely to applications: +* (a) running on a Xilinx device, or +* (b) that interact with a Xilinx device through a bus or interconnect. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* XILINX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF +* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +* +* Except as contained in this notice, the name of the Xilinx shall not be used +* in advertising or otherwise to promote the sale, use or other dealings in +* this Software without prior written authorization from Xilinx. +* +******************************************************************************/ +/****************************************************************************/ +/** +* +* @file xrtcpsu_seconds_polled_example.c +* +* This file contains an example using the XRtcPsu driver in polled mode. +* +* This function checks the new second reporting feature of the RTC. +* +* @note +* If the device does not work properly, the example may hang. +* +* MODIFICATION HISTORY: +*
+* Ver   Who    Date     Changes
+* ----- ------ -------- -----------------------------------------------
+* 1.00  kvn 05/12/15 First Release
+*
+* 
+******************************************************************************/ + +/***************************** Include Files *********************************/ + +#include "xparameters.h" /* SDK generated parameters */ +#include "xrtcpsu.h" /* RTCPSU device driver */ +#include "xil_printf.h" + +/************************** Constant Definitions *****************************/ + +/* + * The following constants map to the XPAR parameters created in the + * xparameters.h file. They are defined here such that a user can easily + * change all the needed parameters in one place. + */ +#define RTC_DEVICE_ID XPAR_XRTCPSU_0_DEVICE_ID + +/**************************** Type Definitions *******************************/ + +/***************** Macros (Inline Functions) Definitions *********************/ +#define REPETATIONS 10 + +/************************** Function Prototypes ******************************/ + +int RtcPsuSecondsPolledExample(u16 DeviceId); + +/************************** Variable Definitions *****************************/ + +XRtcPsu Rtc_Psu; /* Instance of the RTC Device */ + +/*****************************************************************************/ +/** +* +* Main function to call the Rtc Seconds Polled mode example. +* +* @param None +* +* @return XST_SUCCESS if successful, otherwise XST_FAILURE. +* +* @note None +* +******************************************************************************/ +#ifndef TESTAPP_GEN +int main(void) +{ + int Status; + + /* + * Run the Rtc_Psu polled example , specify the the Device ID that is + * generated in xparameters.h + */ + Status = RtcPsuSecondsPolledExample(RTC_DEVICE_ID); + if (Status != XST_SUCCESS) { + xil_printf("RTC Seconds Polled Mode Example Test Failed\r\n"); + return XST_FAILURE; + } + + xil_printf("Successfully ran RTC Seconds Polled Mode Example Test\r\n"); + return XST_SUCCESS; +} +#endif + +/*****************************************************************************/ +/** +* +* This function does a minimal Seconds test on the XRtcPsu device in polled mode. +* +* This function checks the new second reporting feature of the RTC. +* +* @param DeviceId is the unique device id from hardware build. +* +* @return XST_SUCCESS if successful, XST_FAILURE if unsuccessful +* +* @note +* This function polls the RTC, it may hang if the hardware is not +* working correctly. +* +****************************************************************************/ +int RtcPsuSecondsPolledExample(u16 DeviceId) +{ + int Status; + XRtcPsu_Config *Config; + u32 Seconds; + + /* + * Initialize the RTC driver so that it's ready to use. + * Look up the configuration in the config table, then initialize it. + */ + Config = XRtcPsu_LookupConfig(DeviceId); + if (NULL == Config) { + return XST_FAILURE; + } + + Status = XRtcPsu_CfgInitialize(&Rtc_Psu, Config, Config->BaseAddr); + if (Status != XST_SUCCESS) { + return XST_FAILURE; + } + + /* Check hardware build. */ + Status = XRtcPsu_SelfTest(&Rtc_Psu); + if (Status != XST_SUCCESS) { + return XST_FAILURE; + } + + /* + * If seconds interrupt was not generated in ISR, then the processor goes + * into an infinite loop. This represents a failure case of seconds example. + */ + for (Seconds = 1;Seconds <= REPETATIONS; Seconds++) { + while (!XRtcPsu_IsSecondsEventGenerated(&Rtc_Psu)); + xil_printf("Seconds value is %02d.\n\r",Seconds); + } + + xil_printf("Seconds feature tested.\n\r"); + + return XST_SUCCESS; +} diff --git a/XilinxProcessorIPLib/drivers/rtcpsu/examples/xrtcpsu_set_calibration_example.c b/XilinxProcessorIPLib/drivers/rtcpsu/examples/xrtcpsu_set_calibration_example.c new file mode 100644 index 00000000..31229752 --- /dev/null +++ b/XilinxProcessorIPLib/drivers/rtcpsu/examples/xrtcpsu_set_calibration_example.c @@ -0,0 +1,178 @@ +/****************************************************************************** +* +* Copyright (C) 2015 Xilinx, Inc. All rights reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* Use of the Software is limited solely to applications: +* (a) running on a Xilinx device, or +* (b) that interact with a Xilinx device through a bus or interconnect. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* XILINX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF +* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +* +* Except as contained in this notice, the name of the Xilinx shall not be used +* in advertising or otherwise to promote the sale, use or other dealings in +* this Software without prior written authorization from Xilinx. +* +******************************************************************************/ +/****************************************************************************/ +/** +* +* @file xrtcpsu_set_calibration_example.c +* +* This file contains an example using the XRtcPsu driver. +* +* This function updates the calibration register value. +* +* @note +* If the device does not work properly, the example may hang. +* +* MODIFICATION HISTORY: +*
+* Ver   Who    Date     Changes
+* ----- ------ -------- -----------------------------------------------
+* 1.00  kvn 05/12/15 First Release
+*
+* 
+******************************************************************************/ + +/***************************** Include Files *********************************/ + +#include "xparameters.h" /* SDK generated parameters */ +#include "xrtcpsu.h" /* RTCPSU device driver */ +#include "xil_printf.h" +#include + +/************************** Constant Definitions *****************************/ + +/* + * The following constants map to the XPAR parameters created in the + * xparameters.h file. They are defined here such that a user can easily + * change all the needed parameters in one place. + */ +#define RTC_DEVICE_ID XPAR_XRTCPSU_0_DEVICE_ID + +/**************************** Type Definitions *******************************/ + +/***************** Macros (Inline Functions) Definitions *********************/ + +/************************** Function Prototypes ******************************/ + +int RtcPsuSetCalibrationExample(u16 DeviceId); + +/************************** Variable Definitions *****************************/ + +XRtcPsu Rtc_Psu; /* Instance of the RTC Device */ +XRtcPsu_Config *Config; + +/*****************************************************************************/ +/** +* +* Main function to call the Rtc set calibration example. +* +* @param None +* +* @return XST_SUCCESS if successful, otherwise XST_FAILURE. +* +* @note None +* +******************************************************************************/ +#ifndef TESTAPP_GEN +int main(void) +{ + int Status; + + /* + * Run the Rtc_Psu set calibration example , specify the the Device ID + * that is generated in xparameters.h + */ + Status = RtcPsuSetCalibrationExample(RTC_DEVICE_ID); + if (Status != XST_SUCCESS) { + xil_printf("RTC Set Calibration Example Test Failed\r\n"); + return XST_FAILURE; + } + + xil_printf("Successfully ran RTC Set Calibration Example Test\r\n"); + return XST_SUCCESS; +} +#endif + +/*****************************************************************************/ +/** +* +* This function does a minimal set Calibration test on the XRtcPsu device. +* +* This function updates the Calibration register value. +* +* @param DeviceId is the unique device id from hardware build. +* +* @return XST_SUCCESS if successful, XST_FAILURE if unsuccessful +* +* @note None. +* +****************************************************************************/ +int RtcPsuSetCalibrationExample(u16 DeviceId) +{ + int Status; + u32 NetworkTime; + XRtcPsu_DT dt1; + u32 OscillatorFreq; + + /* + * Initialize the RTC driver so that it's ready to use. + * Look up the configuration in the config table, then initialize it. + */ + Config = XRtcPsu_LookupConfig(DeviceId); + if (NULL == Config) { + return XST_FAILURE; + } + + Status = XRtcPsu_CfgInitialize(&Rtc_Psu, Config, Config->BaseAddr); + if (Status != XST_SUCCESS) { + return XST_FAILURE; + } + + /* Check hardware build. */ + Status = XRtcPsu_SelfTest(&Rtc_Psu); + if (Status != XST_SUCCESS) { + return XST_FAILURE; + } + + xil_printf("Enter Crystal oscillator frequency : "); + scanf("%d",&OscillatorFreq); + + xil_printf("\n\rEnter Internet / Network Time YEAR:MM:DD HR:MM:SS : "); + scanf("%d %d %d %d %d %d",&dt1.Year,&dt1.Month,&dt1.Day,&dt1.Hour,&dt1.Min,&dt1.Sec); + xil_printf("%d %d %d %d %d %d\n\r",dt1.Year,dt1.Month,dt1.Day,dt1.Hour,dt1.Min,dt1.Sec); + + NetworkTime = XRtcPsu_DateTimeToSec(&dt1); + + xil_printf("\n\rOld Calibration value : %08x\tCrystal Frequency : %08x\n\r", + Rtc_Psu.CalibrationValue,Rtc_Psu.OscillatorFreq); + + XRtcPsu_CalculateCalibration(&Rtc_Psu,NetworkTime,OscillatorFreq); + + Status = XRtcPsu_CfgInitialize(&Rtc_Psu, Config, Config->BaseAddr); + if (Status != XST_SUCCESS) { + return XST_FAILURE; + } + + xil_printf("New Calibration value : %08x\tCrystal Frequency : %08x\n\r", + Rtc_Psu.CalibrationValue,Rtc_Psu.OscillatorFreq); + + return XST_SUCCESS; +} diff --git a/XilinxProcessorIPLib/drivers/rtcpsu/examples/xrtcpsu_set_time_example.c b/XilinxProcessorIPLib/drivers/rtcpsu/examples/xrtcpsu_set_time_example.c new file mode 100644 index 00000000..fb910ab2 --- /dev/null +++ b/XilinxProcessorIPLib/drivers/rtcpsu/examples/xrtcpsu_set_time_example.c @@ -0,0 +1,175 @@ +/****************************************************************************** +* +* Copyright (C) 2015 Xilinx, Inc. All rights reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* Use of the Software is limited solely to applications: +* (a) running on a Xilinx device, or +* (b) that interact with a Xilinx device through a bus or interconnect. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* XILINX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF +* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +* +* Except as contained in this notice, the name of the Xilinx shall not be used +* in advertising or otherwise to promote the sale, use or other dealings in +* this Software without prior written authorization from Xilinx. +* +******************************************************************************/ +/****************************************************************************/ +/** +* +* @file xrtcpsu_set_time_example.c +* +* This file contains an example using the XRtcPsu driver. +* +* This function updates the current time. +* +* @note +* If the device does not work properly, the example may hang. +* +* MODIFICATION HISTORY: +*
+* Ver   Who    Date     Changes
+* ----- ------ -------- -----------------------------------------------
+* 1.00  kvn 05/12/15 First Release
+*
+* 
+******************************************************************************/ + +/***************************** Include Files *********************************/ + +#include "xparameters.h" /* SDK generated parameters */ +#include "xrtcpsu.h" /* RTCPSU device driver */ +#include "xil_printf.h" +#include + +/************************** Constant Definitions *****************************/ + +/* + * The following constants map to the XPAR parameters created in the + * xparameters.h file. They are defined here such that a user can easily + * change all the needed parameters in one place. + */ +#define RTC_DEVICE_ID XPAR_XRTCPSU_0_DEVICE_ID + +/**************************** Type Definitions *******************************/ + +/***************** Macros (Inline Functions) Definitions *********************/ + +/************************** Function Prototypes ******************************/ + +int RtcPsuSetTimeExample(u16 DeviceId); + +/************************** Variable Definitions *****************************/ + +XRtcPsu Rtc_Psu; /* Instance of the RTC Device */ +XRtcPsu_Config *Config; + +/*****************************************************************************/ +/** +* +* Main function to call the Rtc Set time example. +* +* @param None +* +* @return XST_SUCCESS if successful, otherwise XST_FAILURE. +* +* @note None +* +******************************************************************************/ +#ifndef TESTAPP_GEN +int main(void) +{ + int Status; + + /* + * Run the Rtc_Psu set time example , specify the the Device ID that is + * generated in xparameters.h + */ + Status = RtcPsuSetTimeExample(RTC_DEVICE_ID); + if (Status != XST_SUCCESS) { + xil_printf("RTC Set time Example Test Failed\r\n"); + return XST_FAILURE; + } + + xil_printf("Successfully ran RTC Set time Example Test\r\n"); + return XST_SUCCESS; +} +#endif + +/*****************************************************************************/ +/** +* +* This function does a minimal set time test on the XRtcPsu device. +* +* This function updates the current time to a specified time. +* +* @param DeviceId is the unique device id from hardware build. +* +* @return XST_SUCCESS if successful, XST_FAILURE if unsuccessful +* +* @note None. +* +****************************************************************************/ +int RtcPsuSetTimeExample(u16 DeviceId) +{ + int Status; + u32 CurrentTime, DesiredTime,LastSetTime; + XRtcPsu_DT dt1,dt2,dt3; + + /* + * Initialize the RTC driver so that it's ready to use. + * Look up the configuration in the config table, then initialize it. + */ + Config = XRtcPsu_LookupConfig(DeviceId); + if (NULL == Config) { + return XST_FAILURE; + } + + Status = XRtcPsu_CfgInitialize(&Rtc_Psu, Config, Config->BaseAddr); + if (Status != XST_SUCCESS) { + return XST_FAILURE; + } + + /* Check hardware build. */ + Status = XRtcPsu_SelfTest(&Rtc_Psu); + if (Status != XST_SUCCESS) { + return XST_FAILURE; + } + + xil_printf("Day Convention : 0-Fri, 1-Sat, 2-Sun, 3-Mon, 4-Tue, 5-Wed, 6-Thur\n\r"); + xil_printf("Last set time for RTC is..\n\r"); + LastSetTime = XRtcPsu_GetLastSetTime(&Rtc_Psu); + XRtcPsu_SecToDateTime(LastSetTime,&dt1); + xil_printf("YEAR:MM:DD HR:MM:SS \t %04d:%02d:%02d %02d:%02d:%02d\t Day = %d\n\r", + dt1.Year,dt1.Month,dt1.Day,dt1.Hour,dt1.Min,dt1.Sec,dt1.WeekDay); + + xil_printf("Current RTC time is..\n\r"); + CurrentTime = XRtcPsu_GetCurrentTime(&Rtc_Psu); + XRtcPsu_SecToDateTime(CurrentTime,&dt2); + xil_printf("YEAR:MM:DD HR:MM:SS \t %04d:%02d:%02d %02d:%02d:%02d\t Day = %d\n\r", + dt2.Year,dt2.Month,dt2.Day,dt2.Hour,dt2.Min,dt2.Sec,dt2.WeekDay); + + xil_printf("Enter Desired Current Time YEAR:MM:DD HR:MM:SS : "); + scanf("%d %d %d %d %d %d",&dt3.Year,&dt3.Month,&dt3.Day,&dt3.Hour,&dt3.Min,&dt3.Sec); + xil_printf("%d %d %d %d %d %d\n\r",dt3.Year,dt3.Month,dt3.Day,dt3.Hour,dt3.Min,dt3.Sec); + + DesiredTime = XRtcPsu_DateTimeToSec(&dt3); + XRtcPsu_SetTime(&Rtc_Psu,DesiredTime); + + return XST_SUCCESS; +} diff --git a/XilinxProcessorIPLib/drivers/rtcpsu/src/Makefile b/XilinxProcessorIPLib/drivers/rtcpsu/src/Makefile new file mode 100644 index 00000000..dc8cbdf6 --- /dev/null +++ b/XilinxProcessorIPLib/drivers/rtcpsu/src/Makefile @@ -0,0 +1,40 @@ +COMPILER= +ARCHIVER= +CP=cp +COMPILER_FLAGS= +EXTRA_COMPILER_FLAGS= +LIB=libxil.a + +CC_FLAGS = $(COMPILER_FLAGS) +ECC_FLAGS = $(EXTRA_COMPILER_FLAGS) + +RELEASEDIR=../../../lib +INCLUDEDIR=../../../include +INCLUDES=-I./. -I${INCLUDEDIR} + +OUTS = *.o + +LIBSOURCES:=*.c +INCLUDEFILES:=*.h + +OBJECTS = $(addsuffix .o, $(basename $(wildcard *.c))) + +libs: banner xrtcpsu_libs clean + +%.o: %.c + ${COMPILER} $(CC_FLAGS) $(ECC_FLAGS) $(INCLUDES) -o $@ $< + +banner: + echo "Compiling rtcpsu" + +xrtcpsu_libs: ${OBJECTS} + $(ARCHIVER) -r ${RELEASEDIR}/${LIB} ${OBJECTS} + +.PHONY: include +include: xrtcpsu_includes + +xrtcpsu_includes: + ${CP} ${INCLUDEFILES} ${INCLUDEDIR} + +clean: + rm -rf ${OBJECTS} diff --git a/XilinxProcessorIPLib/drivers/rtcpsu/src/xrtcpsu.c b/XilinxProcessorIPLib/drivers/rtcpsu/src/xrtcpsu.c new file mode 100644 index 00000000..b7439483 --- /dev/null +++ b/XilinxProcessorIPLib/drivers/rtcpsu/src/xrtcpsu.c @@ -0,0 +1,413 @@ +/****************************************************************************** +* +* Copyright (C) 2015 Xilinx, Inc. All rights reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* Use of the Software is limited solely to applications: +* (a) running on a Xilinx device, or +* (b) that interact with a Xilinx device through a bus or interconnect. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* XILINX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF +* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +* +* Except as contained in this notice, the name of the Xilinx shall not be used +* in advertising or otherwise to promote the sale, use or other dealings in +* this Software without prior written authorization from Xilinx. +* +******************************************************************************/ +/*****************************************************************************/ +/** +* +* @file xrtcpsu.c +* +* Functions in this file are the minimum required functions for the XRtcPsu +* driver. See xrtcpsu.h for a detailed description of the driver. +* +* @note None. +* +* +*
+* MODIFICATION HISTORY:
+*
+* Ver   Who    Date	Changes
+* ----- -----  -------- -----------------------------------------------
+* 1.00  kvn    04/21/15 First release
+* 
+* +******************************************************************************/ + +/***************************** Include Files *********************************/ + +#include "xrtcpsu.h" + +/************************** Constant Definitions *****************************/ + +/**************************** Type Definitions *******************************/ + +/***************** Macros (Inline Functions) Definitions *********************/ + +/************************** Variable Definitions *****************************/ + +static const u32 DaysInMonth[] = {31,28,31,30,31,30,31,31,30,31,30,31}; + +/************************** Function Prototypes ******************************/ + +static void XRtcPsu_StubHandler(void *CallBackRef, u32 Event); + +/*****************************************************************************/ +/* +* +* This function initializes a XRtcPsu instance/driver. +* +* The initialization entails: +* - Initialize all members of the XRtcPsu structure. +* +* @param InstancePtr is a pointer to the XRtcPsu instance. +* @param ConfigPtr points to the XRtcPsu device configuration structure. +* @param EffectiveAddr is the device base address in the virtual memory +* address space. If the address translation is not used then the +* physical address is passed. +* Unexpected errors may occur if the address mapping is changed +* after this function is invoked. +* +* @return XST_SUCCESS always. +* +* @note None. +* +******************************************************************************/ +s32 XRtcPsu_CfgInitialize(XRtcPsu *InstancePtr, XRtcPsu_Config *ConfigPtr, + u32 EffectiveAddr) +{ + s32 Status; + Xil_AssertNonvoid(InstancePtr != NULL); + Xil_AssertNonvoid(ConfigPtr != NULL); + + /* + * Set some default values for instance data, don't indicate the device + * is ready to use until everything has been initialized successfully. + */ + InstancePtr->IsReady = 0U; + InstancePtr->RtcConfig.BaseAddr = EffectiveAddr; + InstancePtr->RtcConfig.DeviceId = ConfigPtr->DeviceId; + + if(InstancePtr->OscillatorFreq == 0U) { + InstancePtr->CalibrationValue = XRTC_CALIBRATION_VALUE; + InstancePtr->OscillatorFreq = XRTC_TYPICAL_OSC_FREQ; + } + + /* Set all handlers to stub values, let user configure this data later. */ + InstancePtr->Handler = XRtcPsu_StubHandler; + + InstancePtr->IsPeriodicAlarm = 0U; + + /* Set the calibration value in calibration register. */ + XRtcPsu_WriteReg(InstancePtr->RtcConfig.BaseAddr + XRTC_CALIB_WR_OFFSET, + InstancePtr->CalibrationValue); + + /* Set the Oscillator crystal enable in control register. */ + XRtcPsu_WriteReg(InstancePtr->RtcConfig.BaseAddr + XRTC_CTL_OFFSET, + XRTCPSU_CRYSTAL_OSC_EN); + + /* Clear the Interrupt Status and Disable the interrupts. */ + XRtcPsu_WriteReg(InstancePtr->RtcConfig.BaseAddr + XRTC_INT_STS_OFFSET, + ((u32)XRTC_INT_STS_ALRM_MASK | (u32)XRTC_INT_STS_SECS_MASK)); + XRtcPsu_WriteReg(InstancePtr->RtcConfig.BaseAddr + XRTC_INT_DIS_OFFSET, + ((u32)XRTC_INT_DIS_ALRM_MASK | (u32)XRTC_INT_DIS_SECS_MASK)); + + /* Indicate the component is now ready to use. */ + InstancePtr->IsReady = XIL_COMPONENT_IS_READY; + + Status = XST_SUCCESS; + return Status; +} + +/****************************************************************************/ +/** +* +* This function is a stub handler that is the default handler such that if the +* application has not set the handler when interrupts are enabled, this +* function will be called. +* +* @param CallBackRef is unused by this function. +* @param Event is unused by this function. +* +* @return None. +* +* @note None. +* +*****************************************************************************/ +static void XRtcPsu_StubHandler(void *CallBackRef, u32 Event) +{ + (void *) CallBackRef; + (void) Event; + /* Assert occurs always since this is a stub and should never be called */ + Xil_AssertVoidAlways(); +} + +/****************************************************************************/ +/** +* +* This function sets the alarm value of RTC device. +* +* @param InstancePtr is a pointer to the XRtcPsu instance +* @param Alarm is the desired alarm time for RTC. +* @param Periodic says whether the alarm need to set at periodic +* Intervals or a one-time alarm. +* +* @return None. +* +* @note None. +* +*****************************************************************************/ +void XRtcPsu_SetAlarm(XRtcPsu *InstancePtr, u32 Alarm, u32 Periodic) +{ + Xil_AssertVoid(InstancePtr != NULL); + Xil_AssertVoid(Alarm != 0U); + Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY); + Xil_AssertVoid((Alarm - XRtcPsu_GetCurrentTime(InstancePtr)) > (u32)0); + + XRtcPsu_WriteReg(InstancePtr->RtcConfig.BaseAddr+XRTC_ALRM_OFFSET, Alarm); + if(Periodic != 0U) { + InstancePtr->IsPeriodicAlarm = 1U; + InstancePtr->PeriodicAlarmTime = + Alarm - XRtcPsu_GetCurrentTime(InstancePtr); + } +} + + +/****************************************************************************/ +/** +* +* This function translates time in seconds to a YEAR:MON:DAY HR:MIN:SEC +* format and saves it in the DT structure variable. It also reports the weekday. +* +* @param Seconds is the time value that has to be shown in DateTime +* format. +* @param dt is the DateTime format variable that stores the translated +* time. +* +* @return None. +* +* @note This API supports this century i.e., 2000 - 2099 years only. +* +*****************************************************************************/ +void XRtcPsu_SecToDateTime(u32 Seconds, XRtcPsu_DT *dt) +{ + u32 CurrentTime, TempDays, Leap, DaysPerMonth; + + CurrentTime = Seconds; + dt->Sec = CurrentTime % 60U; + CurrentTime /= 60U; + dt->Min = CurrentTime % 60U; + CurrentTime /= 60U; + dt->Hour = CurrentTime % 24U; + TempDays = CurrentTime / 24U; + + if (TempDays == 0U) { + TempDays = 1U; + } + dt->WeekDay = TempDays % 7U; + + for (dt->Year = 0U; dt->Year <= 99U; ++(dt->Year)) { + if ((dt->Year % 4U) == 0U ) { + Leap = 1U; + } + else { + Leap = 0U; + } + if (TempDays < (365U + Leap)) { + break; + } + TempDays -= (365U + Leap); + } + + for (dt->Month = 1U; dt->Month >= 1U; ++(dt->Month)) { + DaysPerMonth = DaysInMonth[dt->Month - 1]; + if ((Leap == 1U) && (dt->Month == 2U)) { + DaysPerMonth++; + } + if (TempDays < DaysPerMonth) { + break; + } + TempDays -= DaysPerMonth; + } + + dt->Day = TempDays; + dt->Year += 2000U; +} + +/****************************************************************************/ +/** +* +* This function translates time in YEAR:MON:DAY HR:MIN:SEC format to +* seconds. +* +* @param dt is a pointer to a DatetTime format structure variable +* of time that has to be shown in seconds. +* +* @return Seconds value of provided in dt time. +* +* @note None. +* +*****************************************************************************/ +u32 XRtcPsu_DateTimeToSec(XRtcPsu_DT *dt) +{ + u32 i, Days; + u32 Seconds; + Xil_AssertNonvoid(dt != NULL); + + if (dt->Year >= 2000U) { + dt->Year -= 2000U; + } + + for (i = 1U; i < dt->Month; i++) { + dt->Day += (u32)DaysInMonth[i-1]; + } + + if ((dt->Month > 2U) && ((dt->Year % 4U) == 0U)) { + dt->Day++; + } + Days = dt->Day + (365U * dt->Year) + ((dt->Year + 3U) / 4U); + Seconds = (((((Days * 24U) + dt->Hour) * 60U) + dt->Min) * 60U) + dt->Sec; + return Seconds; +} + +/****************************************************************************/ +/** +* +* This function calculates the calibration value depending on the actual +* realworld time and also helps in deriving new calibration value if +* the user wishes to change his oscillator frequency.TimeReal is generally the +* internet time with EPOCH time as reference i.e.,1/1/1970 1st second. +* But this RTC driver assumes start time from 1/1/2000 1st second. Hence,if +* the user maps the internet time InternetTimeInSecs, then he has to use +* XRtcPsu_SecToDateTime(InternetTimeInSecs,&InternetTime), +* TimeReal = XRtcPsu_DateTimeToSec(InternetTime) +* consecutively to arrive at TimeReal value. +* +* @param InstancePtr is a pointer to the XRtcPsu instance. +* @param TimeReal is the actual realworld time generally an +* network time / Internet time in seconds. +* +* @param CrystalOscFreq is the Oscillator new frequency. Say, If the user +* is going with the typical 32768Hz, then he inputs the same +* frequency value. +* +* @return None. +* +* @note After Calculating the calibration register, user / application has to +* call again CfgInitialize API to bring the new calibration into effect. +* +*****************************************************************************/ +void XRtcPsu_CalculateCalibration(XRtcPsu *InstancePtr,u32 TimeReal, + u32 CrystalOscFreq) +{ + u32 ReadTime, SetTime; + u32 Cprev,Fprev,Cnew,Fnew,Xf,Calibration; + Xil_AssertVoid(TimeReal != 0U); + Xil_AssertVoid(CrystalOscFreq != 0U); + + ReadTime = XRtcPsu_GetCurrentTime(InstancePtr); + SetTime = XRtcPsu_GetLastSetTime(InstancePtr); + Calibration = XRtcPsu_GetCalibration(InstancePtr); + /* + * When board gets reseted, Calibration value is zero + * and Last setTime will be marked as 1st second. This implies + * CurrentTime to be in few seconds say something in tens. TimeReal will + * be huge, say something in thousands. So to prevent such reset case, Cnew + * and Fnew will not be calculated. + */ + if((Calibration == 0U) || (CrystalOscFreq != InstancePtr->OscillatorFreq)) { + Cnew = CrystalOscFreq - (u32)1; + Fnew = 0U; + } else { + Cprev = Calibration & XRTC_CALIB_RD_FRACTN_DATA_MASK; + Fprev = Calibration & XRTC_CALIB_RD_MAX_TCK_MASK; + + Xf = ((ReadTime - SetTime) * ((Cprev+1U) + ((Fprev+1U)/16U))) / (TimeReal - SetTime); + Cnew = (u32)(Xf) - (u32)1; + Fnew = XRtcPsu_RoundOff((Xf - Cnew) * 16U) - (u32)1; + } + + Calibration = (Fnew << XRTC_CALIB_RD_FRACTN_DATA_SHIFT) + Cnew; + Calibration |= XRTC_CALIB_RD_FRACTN_EN_MASK; + + InstancePtr->CalibrationValue = Calibration; + InstancePtr->OscillatorFreq = CrystalOscFreq; +} + +/****************************************************************************/ +/** +* +* This function returns the seconds event status by reading +* interrupt status register. +* +* @param InstancePtr is a pointer to the XRtcPsu instance. +* +* @return Returns 1 if a new second event is generated.Else 0.. +* +* @note This API is used in polled mode operation of RTC. +* This also clears interrupt status seconds bit. +* +*****************************************************************************/ +u32 XRtcPsu_IsSecondsEventGenerated(XRtcPsu *InstancePtr) +{ + u32 Status; + + /* Loop the interrupt status register for Seconds Event */ + if ((XRtcPsu_ReadReg(InstancePtr->RtcConfig.BaseAddr + + XRTC_INT_STS_OFFSET) & (XRTC_INT_STS_SECS_MASK)) == 0U) { + Status = 0U; + } else { + /* Clear the interrupt status register */ + XRtcPsu_WriteReg((InstancePtr)->RtcConfig.BaseAddr + + XRTC_INT_STS_OFFSET, XRTC_INT_STS_SECS_MASK); + Status = 1U; + } + return Status; +} + +/****************************************************************************/ +/** +* +* This function returns the alarm event status by reading +* interrupt status register. +* +* @param InstancePtr is a pointer to the XRtcPsu instance. +* +* @return Returns 1 if the alarm event is generated.Else 0. +* +* @note This API is used in polled mode operation of RTC. +* This also clears interrupt status alarm bit. +* +*****************************************************************************/ +u32 XRtcPsu_IsAlarmEventGenerated(XRtcPsu *InstancePtr) +{ + u32 Status; + + /* Loop the interrupt status register for Alarm Event */ + if ((XRtcPsu_ReadReg(InstancePtr->RtcConfig.BaseAddr + + XRTC_INT_STS_OFFSET) & (XRTC_INT_STS_ALRM_MASK)) == 0U) { + Status = 0U; + } else { + /* Clear the interrupt status register */ + XRtcPsu_WriteReg((InstancePtr)->RtcConfig.BaseAddr + + XRTC_INT_STS_OFFSET, XRTC_INT_STS_ALRM_MASK); + Status = 1U; + } + return Status; +} diff --git a/XilinxProcessorIPLib/drivers/rtcpsu/src/xrtcpsu.h b/XilinxProcessorIPLib/drivers/rtcpsu/src/xrtcpsu.h new file mode 100644 index 00000000..46bf5870 --- /dev/null +++ b/XilinxProcessorIPLib/drivers/rtcpsu/src/xrtcpsu.h @@ -0,0 +1,381 @@ +/****************************************************************************** +* +* Copyright (C) 2015 Xilinx, Inc. All rights reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* Use of the Software is limited solely to applications: +* (a) running on a Xilinx device, or +* (b) that interact with a Xilinx device through a bus or interconnect. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* XILINX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF +* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +* +* Except as contained in this notice, the name of the Xilinx shall not be used +* in advertising or otherwise to promote the sale, use or other dealings in +* this Software without prior written authorization from Xilinx. +* +******************************************************************************/ +/*****************************************************************************/ +/** +* @file xrtcpsu.h +* +* The Xilinx RTC driver component. This component supports the Xilinx +* RTC Controller. RTC Core and RTC controller are the two main important sub- +* components for this RTC module. RTC core can run even in the battery powered +* domain when the power from auxiliary source is down. Because of this, RTC core +* latches the calibration,programmed time. This core interfaces with the crystal +* oscillator and maintains current time in seconds.Calibration circuitry +* calculates a second with maximum 1 PPM inaccuracy using a crystal oscillator +* with arbitrary static inaccuracy. Core also responsible to maintain control +* value used by the oscillator and power switching circuitry. +* +* RTC controller includes an APB interface responsible for register access with +* in controller and core. It contains alarm generation logic including the alarm +* register to hold alarm time in seconds.Interrupt management using Interrupt +* status, Interrupt mask, Interrupt enable, Interrupt disable registers are +* included to manage alarm and seconds interrupts. Address Slave error interrupts +* are not being handled by this driver component. +* +* This driver supports the following features: +* - Setting the RTC time. +* - Setting the Alarm value that can be one-time alarm or a periodic alarm. +* - Modifying the calibration value. +* +* Initialization & Configuration +* +* The XRtcPsu_Config structure is used by the driver to configure itself. +* Fields inside this structure are properties of XRtcPsu based on its hardware +* build. +* +* To support multiple runtime loading and initialization strategies employed +* by various operating systems, the driver instance can be initialized in the +* following way: +* +* - XRtcPsu_CfgInitialize(InstancePtr, CfgPtr, EffectiveAddr) - Uses a +* configuration structure provided by the caller. If running in a system +* with address translation, the parameter EffectiveAddr should be the +* virtual address. +* +* Interrupts +* +* The driver defaults to no interrupts at initialization such that interrupts +* must be enabled if desired. An interrupt is generated for one of the +* following conditions. +* +* - Alarm is generated. +* - A new second is generated. +* +* The application can control which interrupts are enabled using the +* XRtcPsu_SetInterruptMask() function. +* +* In order to use interrupts, it is necessary for the user to connect the +* driver interrupt handler, XRtcPsu_InterruptHandler(), to the interrupt +* system of the application. A separate handler should be provided by the +* application to communicate with the interrupt system, and conduct +* application specific interrupt handling. An application registers its own +* handler through the XRtcPsu_SetHandler() function. +* +*
+* MODIFICATION HISTORY:
+*
+* Ver   Who    Date	Changes
+* ----- -----  -------- -----------------------------------------------
+* 1.00  kvn    04/21/15 First release
+* 
+* +******************************************************************************/ + + +#ifndef XRTC_H_ /* prevent circular inclusions */ +#define XRTC_H_ /* by using protection macros */ + +#ifdef __cplusplus +extern "C" { +#endif + +/***************************** Include Files *********************************/ + +#include "xstatus.h" +#include "xil_assert.h" +#include "xil_io.h" +#include "xrtcpsu_hw.h" +#include "xil_types.h" + +/************************** Constant Definitions *****************************/ + +/** @name Callback events + * + * These constants specify the handler events that an application can handle + * using its specific handler function. Note that these constants are not bit + * mask, so only one event can be passed to an application at a time. + * + * @{ + */ +#define XRTCPSU_EVENT_ALARM_GEN 1U /**< Alarm generated event */ +#define XRTCPSU_EVENT_SECS_GEN 2U /**< A new second generated event */ +/*@}*/ + +#define XRTCPSU_CRYSTAL_OSC_EN (u32)1 << XRTC_CTL_OSC_SHIFT +/**< Separate Mask for Crystal oscillator bit Enable */ + +/**************************** Type Definitions *******************************/ + +/******************************************************************************/ +/** + * This data type defines a handler that an application defines to communicate + * with interrupt system to retrieve state information about an application. + * + * @param CallBackRef is a callback reference passed in by the upper layer + * when setting the handler, and is passed back to the upper layer + * when the handler is called. It is used to find the device driver + * instance. + * @param Event contains one of the event constants indicating events that + * have occurred. + * @param EventData contains the number of bytes sent or received at the + * time of the call for send and receive events and contains the + * modem status for modem events. + * + ******************************************************************************/ +typedef void (*XRtcPsu_Handler) (void *CallBackRef, u32 Event); + +/** + * This typedef contains configuration information for a device. + */ +typedef struct { + u16 DeviceId; /**< Unique ID of device */ + u32 BaseAddr; /**< Register base address */ +} XRtcPsu_Config; + +/** + * The XRtcPsu driver instance data. The user is required to allocate a + * variable of this type for the RTC device in the system. A pointer + * to a variable of this type is then passed to the driver API functions. + */ +typedef struct { + XRtcPsu_Config RtcConfig; /**< Device configuration */ + u32 IsReady; /**< Device is initialized and ready */ + u32 PeriodicAlarmTime; + u8 IsPeriodicAlarm; + u32 OscillatorFreq; + u32 CalibrationValue; + XRtcPsu_Handler Handler; + void *CallBackRef; /**< Callback reference for event handler */ +} XRtcPsu; + +/** + * This typedef contains DateTime format structure. + */ +typedef struct { + u32 Year; + u32 Month; + u32 Day; + u32 Hour; + u32 Min; + u32 Sec; + u32 WeekDay; +} XRtcPsu_DT; + + +/************************* Variable Definitions ******************************/ + + +/***************** Macros (Inline Functions) Definitions *********************/ + +#define XRTC_CALIBRATION_VALUE 0x00198231U +#define XRTC_TYPICAL_OSC_FREQ 33330U + +/****************************************************************************/ +/** +* +* This macro updates the current time of RTC device. +* +* @param InstancePtr is a pointer to the XRtcPsu instance. +* @param Time is the desired time for RTC in seconds. +* +* @return None. +* +* @note C-Style signature: +* void XRtcPsu_SetTime(XRtcPsu *InstancePtr, u32 Time) +* +*****************************************************************************/ +#define XRtcPsu_SetTime(InstancePtr,Time) \ + XRtcPsu_WriteReg(((InstancePtr)->RtcConfig.BaseAddr + \ + XRTC_SET_TIME_WR_OFFSET),(Time)) + +/****************************************************************************/ +/** +* +* This macro returns the last set time of RTC device. Whenever a reset +* happens, the last set time will be zeroth day first sec. +* +* @param InstancePtr is a pointer to the XRtcPsu instance. +* +* @return The last set time in seconds. +* +* @note C-Style signature: +* u32 XRtcPsu_GetLastSetTime(XRtcPsu *InstancePtr) +* +*****************************************************************************/ +#define XRtcPsu_GetLastSetTime(InstancePtr) \ + XRtcPsu_ReadReg((InstancePtr)->RtcConfig.BaseAddr + XRTC_SET_TIME_RD_OFFSET) + +/****************************************************************************/ +/** +* +* This macro returns the calibration value of RTC device. +* +* @param InstancePtr is a pointer to the XRtcPsu instance. +* +* @return Calibration value for RTC. +* +* @note C-Style signature: +* u32 XRtcPsu_GetCalibration(XRtcPsu *InstancePtr) +* +*****************************************************************************/ +#define XRtcPsu_GetCalibration(InstancePtr) \ + XRtcPsu_ReadReg((InstancePtr)->RtcConfig.BaseAddr+XRTC_CALIB_RD_OFFSET) + +/****************************************************************************/ +/** +* +* This macro returns the current time of RTC device. +* +* @param InstancePtr is a pointer to the XRtcPsu instance. +* +* @return Current Time. This current time will be in seconds. +* +* @note C-Style signature: +* u32 XRtcPsu_GetCurrentTime(XRtcPsu *InstancePtr) +* +*****************************************************************************/ +#define XRtcPsu_GetCurrentTime(InstancePtr) \ + XRtcPsu_ReadReg((InstancePtr)->RtcConfig.BaseAddr+XRTC_CUR_TIME_OFFSET) + +/****************************************************************************/ +/** +* +* This macro sets the control register value of RTC device. +* +* @param InstancePtr is a pointer to the XRtcPsu instance. +* @param Value is the desired control register value for RTC. +* +* @return None. +* +* @note C-Style signature: +* void XRtcPsu_SetControlRegister(XRtcPsu *InstancePtr, u32 Value) +* +*****************************************************************************/ +#define XRtcPsu_SetControlRegister(InstancePtr, Value) \ + XRtcPsu_WriteReg((InstancePtr)->RtcConfig.BaseAddr + \ + XRTC_CTL_OFFSET,(Value)) + +/****************************************************************************/ +/** +* +* This macro returns the safety check register value of RTC device. +* +* @param InstancePtr is a pointer to the XRtcPsu instance. +* +* @return Safety check register value. +* +* @note C-Style signature: +* u32 XRtcPsu_GetSafetyCheck(XRtcPsu *InstancePtr) +* +*****************************************************************************/ +#define XRtcPsu_GetSafetyCheck(InstancePtr) \ + XRtcPsu_ReadReg((InstancePtr)->RtcConfig.BaseAddr+XRTC_SFTY_CHK_OFFSET) + +/****************************************************************************/ +/** +* +* This macro sets the safety check register value of RTC device. +* +* @param InstancePtr is a pointer to the XRtcPsu instance. +* @param Value is a safety check value to be written in register. +* +* @return None. +* +* @note C-Style signature: +* void XRtcPsu_SetSafetyCheck(XRtcPsu *InstancePtr, u32 Value) +* +*****************************************************************************/ +#define XRtcPsu_SetSafetyCheck(InstancePtr, Value) \ + XRtcPsu_WriteReg((InstancePtr)->RtcConfig.BaseAddr + \ + XRTC_SFTY_CHK_OFFSET,(Value)) + +/****************************************************************************/ +/** +* +* This macro resets the alarm register +* +* @param InstancePtr is a pointer to the XRtcPsu instance. +* +* @return None. +* +* @note C-Style signature: +* u32 XRtcPsu_ResetAlarm(XRtcPsu *InstancePtr) +* +*****************************************************************************/ +#define XRtcPsu_ResetAlarm(InstancePtr) \ + XRtcPsu_WriteReg((InstancePtr)->RtcConfig.BaseAddr + \ + XRTC_ALRM_OFFSET,XRTC_ALRM_RSTVAL) + +/****************************************************************************/ +/** +* +* This macro rounds off the given number +* +* @param Number is the one that needs to be rounded off.. +* +* @return The rounded off value of the input number. +* +* @note C-Style signature: +* u32 XRtcPsu_RoundOff(float Number) +* +*****************************************************************************/ +#define XRtcPsu_RoundOff(Number) \ + (u32)(((Number) < (u32)0) ? ((Number) - (u32)0.5) : ((Number) + (u32)0.5)) + +/************************** Function Prototypes ******************************/ + +/* Functions in xrtcpsu.c */ +s32 XRtcPsu_CfgInitialize(XRtcPsu *InstancePtr, XRtcPsu_Config *ConfigPtr, + u32 EffectiveAddr); + +void XRtcPsu_SetAlarm(XRtcPsu *InstancePtr, u32 Alarm, u32 Periodic); +void XRtcPsu_SecToDateTime(u32 Seconds, XRtcPsu_DT *dt); +u32 XRtcPsu_DateTimeToSec(XRtcPsu_DT *dt); +void XRtcPsu_CalculateCalibration(XRtcPsu *InstancePtr,u32 TimeReal, + u32 CrystalOscFreq); +u32 XRtcPsu_IsSecondsEventGenerated(XRtcPsu *InstancePtr); +u32 XRtcPsu_IsAlarmEventGenerated(XRtcPsu *InstancePtr); + +/* interrupt functions in xrtcpsu_intr.c */ +void XRtcPsu_SetInterruptMask(XRtcPsu *InstancePtr, u32 Mask); +void XRtcPsu_ClearInterruptMask(XRtcPsu *InstancePtr, u32 Mask); +void XRtcPsu_InterruptHandler(XRtcPsu *InstancePtr); +void XRtcPsu_SetHandler(XRtcPsu *InstancePtr, XRtcPsu_Handler FuncPtr, + void *CallBackRef); + +/* Functions in xrtcpsu_selftest.c */ +s32 XRtcPsu_SelfTest(XRtcPsu *InstancePtr); + +/* Functions in xrtcpsu_sinit.c */ +XRtcPsu_Config *XRtcPsu_LookupConfig(u16 DeviceId); + + +#endif /* XRTC_H_ */ diff --git a/XilinxProcessorIPLib/drivers/rtcpsu/src/xrtcpsu_g.c b/XilinxProcessorIPLib/drivers/rtcpsu/src/xrtcpsu_g.c new file mode 100644 index 00000000..90849d61 --- /dev/null +++ b/XilinxProcessorIPLib/drivers/rtcpsu/src/xrtcpsu_g.c @@ -0,0 +1,78 @@ +/****************************************************************************** +* +* Copyright (C) 2015 Xilinx, Inc. All rights reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* Use of the Software is limited solely to applications: +* (a) running on a Xilinx device, or +* (b) that interact with a Xilinx device through a bus or interconnect. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* XILINX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF +* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +* +* Except as contained in this notice, the name of the Xilinx shall not be used +* in advertising or otherwise to promote the sale, use or other dealings in +* this Software without prior written authorization from Xilinx. +* +******************************************************************************/ +/*****************************************************************************/ +/** +* +* @file xrtcpsu_g.c +* +* This file contains a configuration table that specifies the configuration +* of CAN devices in the system. +* +*
+* MODIFICATION HISTORY:
+*
+* Ver   Who    Date	Changes
+* ----- -----  -------- -------------------------------------------------------
+* 1.00  kvn  04/21/15 First release.
+* 
+* +******************************************************************************/ + +/***************************** Include Files *********************************/ + +#include "xrtcpsu.h" +#include "xparameters.h" + +/************************** Constant Definitions *****************************/ + + +/**************************** Type Definitions *******************************/ + + +/***************** Macros (Inline Functions) Definitions *********************/ + + +/************************** Function Prototypes ******************************/ + + +/************************** Variable Prototypes ******************************/ + +/** + * This table contains configuration information for RTC device + * in the system. + */ +XRtcPsu_Config XRtcPsu_ConfigTable[XPAR_XRTCPSU_NUM_INSTANCES] = { + { + (u16)XPAR_XRTCPSU_0_DEVICE_ID, /* Unique ID of device */ + (u32)XPAR_XRTCPSU_0_BASEADDR /* Base address of device */ + } +}; diff --git a/XilinxProcessorIPLib/drivers/rtcpsu/src/xrtcpsu_hw.h b/XilinxProcessorIPLib/drivers/rtcpsu/src/xrtcpsu_hw.h new file mode 100644 index 00000000..6e6a054d --- /dev/null +++ b/XilinxProcessorIPLib/drivers/rtcpsu/src/xrtcpsu_hw.h @@ -0,0 +1,357 @@ +/****************************************************************************** +* +* Copyright (C) 2015 Xilinx, Inc. All rights reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* Use of the Software is limited solely to applications: +* (a) running on a Xilinx device, or +* (b) that interact with a Xilinx device through a bus or interconnect. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* XILINX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF +* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +* +* Except as contained in this notice, the name of the Xilinx shall not be used +* in advertising or otherwise to promote the sale, use or other dealings in +* this Software without prior written authorization from Xilinx. +* +******************************************************************************/ +/*****************************************************************************/ +/** +* +* @file xrtcpsu_hw.h +* +* This header file contains the identifiers and basic driver functions (or +* macros) that can be used to access the device. Other driver functions +* are defined in xrtcpsu.h. +* +*
+* MODIFICATION HISTORY:
+*
+* Ver   Who    Date	Changes
+* ----- -----  -------- -----------------------------------------------
+* 1.00a kvn	  04/21/15 First release
+*
+* 
+* +******************************************************************************/ + +#ifndef XRTC_HW_H_ /* prevent circular inclusions */ +#define XRTC_HW_H_ /* by using protection macros */ + +#ifdef __cplusplus +extern "C" { +#endif + +/***************************** Include Files *********************************/ + +#include "xil_types.h" +#include "xil_assert.h" +#include "xil_io.h" + +/************************** Constant Definitions *****************************/ + +/** + * Xrtc Base Address + */ +#define XRTC_BASEADDR 0xFFA60000U + +/** + * Register: XrtcSetTimeWr + */ +#define XRTC_SET_TIME_WR_OFFSET 0x00000000U +#define XRTC_SET_TIME_WR_RSTVAL 0x00000000U + +#define XRTC_SET_TIME_WR_VAL_SHIFT 0U +#define XRTC_SET_TIME_WR_VAL_WIDTH 32U +#define XRTC_SET_TIME_WR_VAL_MASK 0xffffffffU +#define XRTC_SET_TIME_WR_VAL_DEFVAL 0x0U + +/** + * Register: XrtcSetTimeRd + */ +#define XRTC_SET_TIME_RD_OFFSET 0x00000004U +#define XRTC_SET_TIME_RD_RSTVAL 0x00000000U + +#define XRTC_SET_TIME_RD_VAL_SHIFT 0U +#define XRTC_SET_TIME_RD_VAL_WIDTH 32U +#define XRTC_SET_TIME_RD_VAL_MASK 0xffffffffU +#define XRTC_SET_TIME_RD_VAL_DEFVAL 0x0U + +/** + * Register: XrtcCalibWr + */ +#define XRTC_CALIB_WR_OFFSET 0x00000008U +#define XRTC_CALIB_WR_RSTVAL 0x00000000U + +#define XRTC_CALIB_WR_FRACTN_EN_SHIFT 20U +#define XRTC_CALIB_WR_FRACTN_EN_WIDTH 1U +#define XRTC_CALIB_WR_FRACTN_EN_MASK 0x00100000U +#define XRTC_CALIB_WR_FRACTN_EN_DEFVAL 0x0U + +#define XRTC_CALIB_WR_FRACTN_DATA_SHIFT 16U +#define XRTC_CALIB_WR_FRACTN_DATA_WIDTH 4U +#define XRTC_CALIB_WR_FRACTN_DATA_MASK 0x000f0000U +#define XRTC_CALIB_WR_FRACTN_DATA_DEFVAL 0x0U + +#define XRTC_CALIB_WR_MAX_TCK_SHIFT 0U +#define XRTC_CALIB_WR_MAX_TCK_WIDTH 16U +#define XRTC_CALIB_WR_MAX_TCK_MASK 0x0000ffffU +#define XRTC_CALIB_WR_MAX_TCK_DEFVAL 0x0U + +/** + * Register: XrtcCalibRd + */ +#define XRTC_CALIB_RD_OFFSET 0x0000000CU +#define XRTC_CALIB_RD_RSTVAL 0x00000000U + +#define XRTC_CALIB_RD_FRACTN_EN_SHIFT 20U +#define XRTC_CALIB_RD_FRACTN_EN_WIDTH 1U +#define XRTC_CALIB_RD_FRACTN_EN_MASK 0x00100000U +#define XRTC_CALIB_RD_FRACTN_EN_DEFVAL 0x0U + +#define XRTC_CALIB_RD_FRACTN_DATA_SHIFT 16U +#define XRTC_CALIB_RD_FRACTN_DATA_WIDTH 4U +#define XRTC_CALIB_RD_FRACTN_DATA_MASK 0x000f0000U +#define XRTC_CALIB_RD_FRACTN_DATA_DEFVAL 0x0U + +#define XRTC_CALIB_RD_MAX_TCK_SHIFT 0U +#define XRTC_CALIB_RD_MAX_TCK_WIDTH 16U +#define XRTC_CALIB_RD_MAX_TCK_MASK 0x0000ffffU +#define XRTC_CALIB_RD_MAX_TCK_DEFVAL 0x0U + +/** + * Register: XrtcCurTime + */ +#define XRTC_CUR_TIME_OFFSET 0x00000010U +#define XRTC_CUR_TIME_RSTVAL 0x00000000U + +#define XRTC_CUR_TIME_VAL_SHIFT 0U +#define XRTC_CUR_TIME_VAL_WIDTH 32U +#define XRTC_CUR_TIME_VAL_MASK 0xffffffffU +#define XRTC_CUR_TIME_VAL_DEFVAL 0x0U + +/** + * Register: XrtcCurTck + */ +#define XRTC_CUR_TCK_OFFSET 0x00000014U +#define XRTC_CUR_TCK_RSTVAL 0x00000000U + +#define XRTC_CUR_TCK_VAL_SHIFT 0U +#define XRTC_CUR_TCK_VAL_WIDTH 16U +#define XRTC_CUR_TCK_VAL_MASK 0x0000ffffU +#define XRTC_CUR_TCK_VAL_DEFVAL 0x0U + +/** + * Register: XrtcAlrm + */ +#define XRTC_ALRM_OFFSET 0x00000018U +#define XRTC_ALRM_RSTVAL 0x00000000U + +#define XRTC_ALRM_VAL_SHIFT 0U +#define XRTC_ALRM_VAL_WIDTH 32U +#define XRTC_ALRM_VAL_MASK 0xffffffffU +#define XRTC_ALRM_VAL_DEFVAL 0x0U + +/** + * Register: XrtcIntSts + */ +#define XRTC_INT_STS_OFFSET 0x00000020U +#define XRTC_INT_STS_RSTVAL 0x00000000U + +#define XRTC_INT_STS_ALRM_SHIFT 1U +#define XRTC_INT_STS_ALRM_WIDTH 1U +#define XRTC_INT_STS_ALRM_MASK 0x00000002U +#define XRTC_INT_STS_ALRM_DEFVAL 0x0U + +#define XRTC_INT_STS_SECS_SHIFT 0U +#define XRTC_INT_STS_SECS_WIDTH 1U +#define XRTC_INT_STS_SECS_MASK 0x00000001U +#define XRTC_INT_STS_SECS_DEFVAL 0x0U + +/** + * Register: XrtcIntMsk + */ +#define XRTC_INT_MSK_OFFSET 0x00000024U +#define XRTC_INT_MSK_RSTVAL 0x00000003U + +#define XRTC_INT_MSK_ALRM_SHIFT 1U +#define XRTC_INT_MSK_ALRM_WIDTH 1U +#define XRTC_INT_MSK_ALRM_MASK 0x00000002U +#define XRTC_INT_MSK_ALRM_DEFVAL 0x1U + +#define XRTC_INT_MSK_SECS_SHIFT 0U +#define XRTC_INT_MSK_SECS_WIDTH 1U +#define XRTC_INT_MSK_SECS_MASK 0x00000001U +#define XRTC_INT_MSK_SECS_DEFVAL 0x1U + +/** + * Register: XrtcIntEn + */ +#define XRTC_INT_EN_OFFSET 0x00000028U +#define XRTC_INT_EN_RSTVAL 0x00000000U + +#define XRTC_INT_EN_ALRM_SHIFT 1U +#define XRTC_INT_EN_ALRM_WIDTH 1U +#define XRTC_INT_EN_ALRM_MASK 0x00000002U +#define XRTC_INT_EN_ALRM_DEFVAL 0x0U + +#define XRTC_INT_EN_SECS_SHIFT 0U +#define XRTC_INT_EN_SECS_WIDTH 1U +#define XRTC_INT_EN_SECS_MASK 0x00000001U +#define XRTC_INT_EN_SECS_DEFVAL 0x0U + +/** + * Register: XrtcIntDis + */ +#define XRTC_INT_DIS_OFFSET 0x0000002CU +#define XRTC_INT_DIS_RSTVAL 0x00000000U + +#define XRTC_INT_DIS_ALRM_SHIFT 1U +#define XRTC_INT_DIS_ALRM_WIDTH 1U +#define XRTC_INT_DIS_ALRM_MASK 0x00000002U +#define XRTC_INT_DIS_ALRM_DEFVAL 0x0U + +#define XRTC_INT_DIS_SECS_SHIFT 0U +#define XRTC_INT_DIS_SECS_WIDTH 1U +#define XRTC_INT_DIS_SECS_MASK 0x00000001U +#define XRTC_INT_DIS_SECS_DEFVAL 0x0U + +/** + * Register: XrtcAddErr + */ +#define XRTC_ADD_ERR_OFFSET 0x00000030U +#define XRTC_ADD_ERR_RSTVAL 0x00000000U + +#define XRTC_ADD_ERR_STS_SHIFT 0U +#define XRTC_ADD_ERR_STS_WIDTH 1U +#define XRTC_ADD_ERR_STS_MASK 0x00000001U +#define XRTC_ADD_ERR_STS_DEFVAL 0x0U + +/** + * Register: XrtcAddErrIntMsk + */ +#define XRTC_ADD_ERR_INT_MSK_OFFSET 0x00000034U +#define XRTC_ADD_ERR_INT_MSK_RSTVAL 0x00000001U + +#define XRTC_ADD_ERR_INT_MSK_SHIFT 0U +#define XRTC_ADD_ERR_INT_MSK_WIDTH 1U +#define XRTC_ADD_ERR_INT_MSK_MASK 0x00000001U +#define XRTC_ADD_ERR_INT_MSK_DEFVAL 0x1U + +/** + * Register: XrtcAddErrIntEn + */ +#define XRTC_ADD_ERR_INT_EN_OFFSET 0x00000038U +#define XRTC_ADD_ERR_INT_EN_RSTVAL 0x00000000U + +#define XRTC_ADD_ERR_INT_EN_MSK_SHIFT 0U +#define XRTC_ADD_ERR_INT_EN_MSK_WIDTH 1U +#define XRTC_ADD_ERR_INT_EN_MSK_MASK 0x00000001U +#define XRTC_ADD_ERR_INT_EN_MSK_DEFVAL 0x0U + +/** + * Register: XrtcAddErrIntDis + */ +#define XRTC_ADD_ERR_INT_DIS_OFFSET 0x0000003CU +#define XRTC_ADD_ERR_INT_DIS_RSTVAL 0x00000000U + +#define XRTC_ADD_ERR_INT_DIS_MSK_SHIFT 0U +#define XRTC_ADD_ERR_INT_DIS_MSK_WIDTH 1U +#define XRTC_ADD_ERR_INT_DIS_MSK_MASK 0x00000001U +#define XRTC_ADD_ERR_INT_DIS_MSK_DEFVAL 0x0U + +/** + * Register: XrtcCtl + */ +#define XRTC_CTL_OFFSET 0x00000040U +#define XRTC_CTL_RSTVAL 0x01000000U + +#define XRTC_CTL_BATTERY_DIS_SHIFT 31U +#define XRTC_CTL_BATTERY_DIS_WIDTH 1U +#define XRTC_CTL_BATTERY_DIS_MASK 0x80000000U +#define XRTC_CTL_BATTERY_DIS_DEFVAL 0x0U + +#define XRTC_CTL_OSC_SHIFT 24U +#define XRTC_CTL_OSC_WIDTH 4U +#define XRTC_CTL_OSC_MASK 0x0f000000U +#define XRTC_CTL_OSC_DEFVAL 0x1U + +#define XRTC_CTL_SLVERR_EN_SHIFT 0U +#define XRTC_CTL_SLVERR_EN_WIDTH 1U +#define XRTC_CTL_SLVERR_EN_MASK 0x00000001U +#define XRTC_CTL_SLVERR_EN_DEFVAL 0x0U + +/** + * Register: XrtcSftyChk + */ +#define XRTC_SFTY_CHK_OFFSET 0x00000050U +#define XRTC_SFTY_CHK_RSTVAL 0x00000000U + +#define XRTC_SFTY_CHK_REG_SHIFT 0U +#define XRTC_SFTY_CHK_REG_WIDTH 32U +#define XRTC_SFTY_CHK_REG_MASK 0xffffffffU +#define XRTC_SFTY_CHK_REG_DEFVAL 0x0U + +/** + * Register: XrtcEco + */ +#define XRTC_ECO_OFFSET 0x00000060U +#define XRTC_ECO_RSTVAL 0x00000000U + +#define XRTC_ECO_REG_SHIFT 0U +#define XRTC_ECO_REG_WIDTH 32U +#define XRTC_ECO_REG_MASK 0xffffffffU +#define XRTC_ECO_REG_DEFVAL 0x0U + +/***************** Macros (Inline Functions) Definitions *********************/ + +/****************************************************************************/ +/** +* +* This macro reads the given register. +* +* @param RegisterAddr is the register address in the address +* space of the RTC device. +* +* @return The 32-bit value of the register +* +* @note None. +* +*****************************************************************************/ +#define XRtcPsu_ReadReg(RegisterAddr) Xil_In32(RegisterAddr) + +/****************************************************************************/ +/** +* +* This macro writes the given register. +* +* @param RegisterAddr is the register address in the address +* space of the RTC device. +* @param Data is the 32-bit value to write to the register. +* +* @return None. +* +* @note None. +* +*****************************************************************************/ +#define XRtcPsu_WriteReg(RegisterAddr, Data) Xil_Out32(RegisterAddr, (u32)(Data)) + +#ifdef __cplusplus +} +#endif + +#endif /* XRTC_HW_H_ */ diff --git a/XilinxProcessorIPLib/drivers/rtcpsu/src/xrtcpsu_intr.c b/XilinxProcessorIPLib/drivers/rtcpsu/src/xrtcpsu_intr.c new file mode 100644 index 00000000..ffdd6184 --- /dev/null +++ b/XilinxProcessorIPLib/drivers/rtcpsu/src/xrtcpsu_intr.c @@ -0,0 +1,229 @@ +/****************************************************************************** +* +* Copyright (C) 2015 Xilinx, Inc. All rights reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* Use of the Software is limited solely to applications: +* (a) running on a Xilinx device, or +* (b) that interact with a Xilinx device through a bus or interconnect. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* XILINX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF +* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +* +* Except as contained in this notice, the name of the Xilinx shall not be used +* in advertising or otherwise to promote the sale, use or other dealings in +* this Software without prior written authorization from Xilinx. +* +******************************************************************************/ +/*****************************************************************************/ +/** +* +* @file xrtcpsu_intr.c +* +* This file contains functions related to RTC interrupt handling. +* +*
+* MODIFICATION HISTORY:
+*
+* Ver   Who    Date	Changes
+* ----- -----  -------- -----------------------------------------------
+* 1.00  kvn    04/21/15 First release
+* 
+* +******************************************************************************/ + +/***************************** Include Files *********************************/ + +#include "xrtcpsu.h" + +/************************** Constant Definitions *****************************/ + +/**************************** Type Definitions *******************************/ + +/***************** Macros (Inline Functions) Definitions *********************/ + +/************************** Variable Definitions *****************************/ + +/************************** Function Prototypes ******************************/ + +/************************** Variable Definitions ****************************/ + +/****************************************************************************/ +/** +* +* This function sets the interrupt mask. +* +* @param InstancePtr is a pointer to the XRtcPsu instance +* @param Mask contains the interrupts to be enabled. +* A '1' enables an interupt, and a '0' disables. +* +* @return None. +* +* @note None. +* +*****************************************************************************/ +void XRtcPsu_SetInterruptMask(XRtcPsu *InstancePtr, u32 Mask) +{ + /* + * Clear the Status register to be sure of no pending interrupts. + * Writing mask values to interrupt bits as it is a WTC register. + */ + XRtcPsu_WriteReg(InstancePtr->RtcConfig.BaseAddr + XRTC_INT_STS_OFFSET, + ((u32)XRTC_INT_STS_ALRM_MASK | (u32)XRTC_INT_STS_SECS_MASK)); + + /* + * XRTC_INT_MSK_RSTVAL contains the valid interrupts + * for the RTC device. The AND operation on Mask makes sure one + * of the valid bits are only set. + */ + + /* Write the mask to the IER Register */ + XRtcPsu_WriteReg(InstancePtr->RtcConfig.BaseAddr+XRTC_INT_EN_OFFSET, + (Mask & (u32)XRTC_INT_MSK_RSTVAL)); + +} + +/****************************************************************************/ +/** +* +* This function clears the interrupt mask. +* +* @param InstancePtr is a pointer to the XRtcPsu instance +* @param Mask contains the interrupts to be disabled. +* A '1' enables an interrupt, and a '0' disables. +* +* @return None. +* +* @note None. +* +*****************************************************************************/ +void XRtcPsu_ClearInterruptMask(XRtcPsu *InstancePtr, u32 Mask) +{ + /* + * XRTC_INT_MSK_RSTVAL contains the valid interrupts + * for the RTC device. The AND operation on mask makes sure one + * of the valid bits are only cleared. + */ + + /* Write the Mask to the IDR register */ + XRtcPsu_WriteReg(InstancePtr->RtcConfig.BaseAddr+XRTC_INT_DIS_OFFSET, + (Mask & (u32)XRTC_INT_MSK_RSTVAL)); +} + +/****************************************************************************/ +/** +* +* This function sets the handler that will be called when an event (interrupt) +* occurs that needs application's attention. +* +* @param InstancePtr is a pointer to the XRtcPsu instance +* @param FuncPtr is the pointer to the callback function. +* @param CallBackRef is the upper layer callback reference passed back +* when the callback function is invoked. +* +* @return None. +* +* @note +* +* There is no assert on the CallBackRef since the driver doesn't know what it +* is (nor should it) +* +*****************************************************************************/ +void XRtcPsu_SetHandler(XRtcPsu *InstancePtr, XRtcPsu_Handler FuncPtr, + void *CallBackRef) +{ + /* + * Asserts validate the input arguments + * CallBackRef not checked, no way to know what is valid + */ + Xil_AssertVoid(InstancePtr != NULL); + Xil_AssertVoid(FuncPtr != NULL); + Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY); + + InstancePtr->Handler = FuncPtr; + InstancePtr->CallBackRef = CallBackRef; +} + +/****************************************************************************/ +/** +* +* This function is the interrupt handler for the driver. +* It must be connected to an interrupt system by the application such that it +* can be called when an interrupt occurs. +* +* @param InstancePtr contains a pointer to the driver instance +* +* @return None. +* +* @note None. +* +******************************************************************************/ +void XRtcPsu_InterruptHandler(XRtcPsu *InstancePtr) +{ + u32 IsrStatus; + + Xil_AssertVoid(InstancePtr != NULL); + Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY); + + /* + * Read the interrupt ID register to determine which + * interrupt is active. + */ + IsrStatus = ~(XRtcPsu_ReadReg(InstancePtr->RtcConfig.BaseAddr + + XRTC_INT_MSK_OFFSET)); + + IsrStatus &= XRtcPsu_ReadReg(InstancePtr->RtcConfig.BaseAddr + + XRTC_INT_STS_OFFSET); + + /* + * Clear the interrupt status to allow future + * interrupts before this generated interrupt is serviced. + */ + XRtcPsu_WriteReg(InstancePtr->RtcConfig.BaseAddr + + XRTC_INT_STS_OFFSET, IsrStatus); + + /* Handle the generated interrupts appropriately. */ + + /* Alarm interrupt */ + if((IsrStatus & XRTC_INT_STS_ALRM_MASK) != (u32)0) { + + if(InstancePtr->IsPeriodicAlarm != 0U) { + XRtcPsu_SetAlarm(InstancePtr, + (XRtcPsu_GetCurrentTime(InstancePtr)+InstancePtr->PeriodicAlarmTime),1U); + } + + /* + * Call the application handler to indicate that there is an + * alarm interrupt. If the application cares about this alarm, + * it will act accordingly through its own handler. + */ + InstancePtr->Handler(InstancePtr->CallBackRef, + XRTCPSU_EVENT_ALARM_GEN); + } + + /* Seconds interrupt */ + if((IsrStatus & XRTC_INT_STS_SECS_MASK) != (u32)0) { + /* + * Call the application handler to indicate that there is an + * seconds interrupt. If the application cares about this seconds + * interrupt, it will act accordingly through its own handler. + */ + InstancePtr->Handler(InstancePtr->CallBackRef, + XRTCPSU_EVENT_SECS_GEN); + } + +} diff --git a/XilinxProcessorIPLib/drivers/rtcpsu/src/xrtcpsu_selftest.c b/XilinxProcessorIPLib/drivers/rtcpsu/src/xrtcpsu_selftest.c new file mode 100644 index 00000000..8248d8a8 --- /dev/null +++ b/XilinxProcessorIPLib/drivers/rtcpsu/src/xrtcpsu_selftest.c @@ -0,0 +1,109 @@ +/****************************************************************************** +* +* Copyright (C) 2015 Xilinx, Inc. All rights reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* Use of the Software is limited solely to applications: +* (a) running on a Xilinx device, or +* (b) that interact with a Xilinx device through a bus or interconnect. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* XILINX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF +* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +* +* Except as contained in this notice, the name of the Xilinx shall not be used +* in advertising or otherwise to promote the sale, use or other dealings in +* this Software without prior written authorization from Xilinx. +* +******************************************************************************/ +/****************************************************************************/ +/** +* +* @file xrtcpsu_selftest.c +* +* This file contains the self-test functions for the XRtcPsu driver. +* +*
+* MODIFICATION HISTORY:
+*
+* Ver   Who    Date	Changes
+* ----- ------ -------- -----------------------------------------------
+* 1.00  kvn    04/21/15 First release.
+* 
+* +******************************************************************************/ + +/***************************** Include Files *********************************/ + +#include "xstatus.h" +#include "xrtcpsu.h" + +/************************** Constant Definitions *****************************/ + + +/**************************** Type Definitions *******************************/ + + +/***************** Macros (Inline Functions) Definitions *********************/ + + +/************************** Variable Definitions *****************************/ + + +/************************** Function Prototypes ******************************/ + + +/****************************************************************************/ +/** +* +* This function runs a self-test on the driver and hardware device. This self +* test writes reset value into safety check register and read backs the same. +* If mismatch offers, returns the failure. +* +* @param InstancePtr is a pointer to the XRtcPsu instance +* +* @return +* - XST_SUCCESS if the test was successful +* +* @note +* +* This function can hang if the hardware is not functioning properly. +* +******************************************************************************/ +s32 XRtcPsu_SelfTest(XRtcPsu *InstancePtr) +{ + s32 Status = XST_SUCCESS; + u32 SafetyCheck; + + /* Assert validates the input arguments */ + Xil_AssertNonvoid(InstancePtr != NULL); + Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY); + + /* + * Write the reset value in safety check register and + * try reading back. If mismatch happens, return failure. + */ + XRtcPsu_WriteReg(InstancePtr->RtcConfig.BaseAddr + XRTC_SFTY_CHK_OFFSET, + XRTC_SFTY_CHK_RSTVAL); + SafetyCheck = XRtcPsu_ReadReg(InstancePtr->RtcConfig.BaseAddr + + XRTC_SFTY_CHK_OFFSET); + + if (SafetyCheck != XRTC_SFTY_CHK_RSTVAL) { + Status = XST_FAILURE; + } + + return Status; +} diff --git a/XilinxProcessorIPLib/drivers/rtcpsu/src/xrtcpsu_sinit.c b/XilinxProcessorIPLib/drivers/rtcpsu/src/xrtcpsu_sinit.c new file mode 100644 index 00000000..d987ca85 --- /dev/null +++ b/XilinxProcessorIPLib/drivers/rtcpsu/src/xrtcpsu_sinit.c @@ -0,0 +1,99 @@ +/****************************************************************************** +* +* Copyright (C) 2015 Xilinx, Inc. All rights reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* Use of the Software is limited solely to applications: +* (a) running on a Xilinx device, or +* (b) that interact with a Xilinx device through a bus or interconnect. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* XILINX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF +* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +* +* Except as contained in this notice, the name of the Xilinx shall not be used +* in advertising or otherwise to promote the sale, use or other dealings in +* this Software without prior written authorization from Xilinx. +* +******************************************************************************/ +/*****************************************************************************/ +/** +* +* @file xrtcpsu_sinit.c +* +* This file contains the implementation of the XRtcPsu driver's static +* initialization functionality. +* +* @note None. +* +*
+*
+* MODIFICATION HISTORY:
+*
+* Ver   Who    Date	Changes
+* ----- -----  -------- -----------------------------------------------
+* 1.00  kvn    04/21/15 First release.
+*
+* 
+* +******************************************************************************/ + +/***************************** Include Files *********************************/ + +#include "xrtcpsu.h" +#include "xparameters.h" + +/************************** Constant Definitions *****************************/ + +/**************************** Type Definitions *******************************/ + +/***************** Macros (Inline Functions) Definitions *********************/ + +/************************** Function Prototypes ******************************/ + +/************************** Variable Definitions *****************************/ + +extern XRtcPsu_Config XRtcPsu_ConfigTable[]; + +/*****************************************************************************/ +/** +* +* This function looks for the device configuration based on the unique device +* ID. The table XRtcPsu_ConfigTable[] contains the configuration information for +* each device in the system. +* +* @param DeviceId is the unique device ID of the device being looked up. +* +* @return A pointer to the configuration table entry corresponding to the +* given device ID, or NULL if no match is found. +* +* @note None. +* +******************************************************************************/ +XRtcPsu_Config *XRtcPsu_LookupConfig(u16 DeviceId) +{ + XRtcPsu_Config *CfgPtr = NULL; + u32 Index; + + for (Index = 0U; Index < (u32)XPAR_XRTCPSU_NUM_INSTANCES; Index++) { + if (XRtcPsu_ConfigTable[Index].DeviceId == DeviceId) { + CfgPtr = &XRtcPsu_ConfigTable[Index]; + break; + } + } + + return (XRtcPsu_Config *)CfgPtr; +}