diff --git a/XilinxProcessorIPLib/drivers/wdtps/data/wdtps.mdd b/XilinxProcessorIPLib/drivers/wdtps/data/wdtps.mdd new file mode 100755 index 00000000..55f085a3 --- /dev/null +++ b/XilinxProcessorIPLib/drivers/wdtps/data/wdtps.mdd @@ -0,0 +1,42 @@ +############################################################################### +# +# Copyright (C) 2011 - 2014 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 wdtps + + OPTION supported_peripherals = (ps7_wdt, ps8_wdt, pss_wdt); + OPTION driver_state = ACTIVE; + OPTION copyfiles = all; + OPTION VERSION = 3.0; + OPTION NAME = wdtps; + +END driver diff --git a/XilinxProcessorIPLib/drivers/wdtps/data/wdtps.tcl b/XilinxProcessorIPLib/drivers/wdtps/data/wdtps.tcl new file mode 100755 index 00000000..6afd4547 --- /dev/null +++ b/XilinxProcessorIPLib/drivers/wdtps/data/wdtps.tcl @@ -0,0 +1,51 @@ +############################################################################### +# +# Copyright (C) 2011 - 2014 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.00a sdm 11/22/11 Created +# +############################################################################## + +#uses "xillib.tcl" + +proc generate {drv_handle} { + xdefine_zynq_include_file $drv_handle "xparameters.h" "XWdtPs" "NUM_INSTANCES" "DEVICE_ID" "C_S_AXI_BASEADDR" "C_S_AXI_HIGHADDR" "C_WDT_CLK_FREQ_HZ" + + xdefine_zynq_config_file $drv_handle "xwdtps_g.c" "XWdtPs" "DEVICE_ID" "C_S_AXI_BASEADDR" + + xdefine_zynq_canonical_xpars $drv_handle "xparameters.h" "XWdtPs" "DEVICE_ID" "C_S_AXI_BASEADDR" "C_S_AXI_HIGHADDR" "C_WDT_CLK_FREQ_HZ" + +} diff --git a/XilinxProcessorIPLib/drivers/wdtps/data/wdtps_header.h b/XilinxProcessorIPLib/drivers/wdtps/data/wdtps_header.h new file mode 100755 index 00000000..3a015da6 --- /dev/null +++ b/XilinxProcessorIPLib/drivers/wdtps/data/wdtps_header.h @@ -0,0 +1,41 @@ +/* $Id: tmrctr_header.h,v 1.1.2.1 2010/12/01 07:53:56 svemula Exp $ */ +/****************************************************************************** +* +* Copyright (C) 2011 - 2014 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. +* +******************************************************************************/ +#ifndef WDTPS_HEADER_H /* prevent circular inclusions */ +#define WDTPS_HEADER_H /* by using protection macros */ + +#include "xil_types.h" +#include "xil_assert.h" +#include "xstatus.h" + +int WdtPsSelfTestExample(u16 DeviceId); +#endif diff --git a/XilinxProcessorIPLib/drivers/wdtps/data/wdtps_tapp.tcl b/XilinxProcessorIPLib/drivers/wdtps/data/wdtps_tapp.tcl new file mode 100755 index 00000000..f6ba487f --- /dev/null +++ b/XilinxProcessorIPLib/drivers/wdtps/data/wdtps_tapp.tcl @@ -0,0 +1,137 @@ +############################################################################### +# +# Copyright (C) 2010 - 2014 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 +# -------- ------ -------- ------------------------------------ +# 2.0 adk 12/10/13 Updated as per the New Tcl API's +############################################################################## + +# Uses $XILINX_EDK/bin/lib/xillib_sw.tcl +# ----------------------------------------------------------------- +# Software Project Types (swproj): +# 0 : MemoryTest - Calls basic memorytest routines from common driver dir +# 1 : PeripheralTest - Calls any existing polled_example and/or selftest +# ----------------------------------------------------------------- + +# ----------------------------------------------------------------- +# TCL Procedures: +# ----------------------------------------------------------------- + +proc gen_include_files {swproj mhsinst} { + if {$swproj == 0} { + return "" + } + if {$swproj == 1} { + set inc_file_lines {xwdtps.h wdtps_header.h} + } + return $inc_file_lines +} + +proc gen_src_files {swproj mhsinst} { + if {$swproj == 0} { + return "" + } + if {$swproj == 1} { + + set inc_file_lines {examples/xwdtps_selftest_example.c data/wdtps_header.h} + + return $inc_file_lines + } +} + +proc gen_testfunc_def {swproj mhsinst} { + return "" +} + +proc gen_init_code {swproj mhsinst} { + + if {$swproj == 0} { + return "" + } + if {$swproj == 1} { + return "" + } + +} + +proc gen_testfunc_call {swproj mhsinst} { + + if {$swproj == 0} { + return "" + } + + set ipname [get_property NAME $mhsinst] + set deviceid [hsm::utils::get_ip_param_name $mhsinst "DEVICE_ID"] + set stdout [get_property CONFIG.STDOUT [get_os]] + if { $stdout == "" || $stdout == "none" } { + set hasStdout 0 + } else { + set hasStdout 1 + } + + set testfunc_call "" + + if {${hasStdout} == 0} { + + append testfunc_call " + + { + int Status; + + Status = WdtPsSelfTestExample(${deviceid}); + + }" + + + } else { + + append testfunc_call " + + { + int Status; + + print(\"\\r\\n Running WdtPsSelfTestExample() for ${ipname}...\\r\\n\"); + + Status = WdtPsSelfTestExample(${deviceid}); + + if (Status == 0) { + print(\"WdtPsSelfTestExample PASSED\\r\\n\"); + } + else { + print(\"WdtPsSelfTestExample FAILED\\r\\n\"); + } + }" + + } + + return $testfunc_call +} diff --git a/XilinxProcessorIPLib/drivers/wdtps/examples/index.html b/XilinxProcessorIPLib/drivers/wdtps/examples/index.html new file mode 100755 index 00000000..76cfe30b --- /dev/null +++ b/XilinxProcessorIPLib/drivers/wdtps/examples/index.html @@ -0,0 +1,19 @@ + + +
+ + +Copyright � 1995-2014 Xilinx, Inc. All rights reserved.
+ + \ No newline at end of file diff --git a/XilinxProcessorIPLib/drivers/wdtps/examples/xwdtps_intr_example.c b/XilinxProcessorIPLib/drivers/wdtps/examples/xwdtps_intr_example.c new file mode 100755 index 00000000..a5688629 --- /dev/null +++ b/XilinxProcessorIPLib/drivers/wdtps/examples/xwdtps_intr_example.c @@ -0,0 +1,479 @@ +/****************************************************************************** +* +* Copyright (C) 2010 - 2014 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 xwdtps_intr_example.c +* +* This file contains a design example using the System Watchdog Timer Device +* (WdtPs) driver and hardware device using interrupt mode. This test +* assumes that the RESET OUTPUT OF WDT IS NOT CONNECTED to the processor and +* the IRQ output is connected to an interrupt controller attached to the +* processor +* +* +* @note +* +*+* +* MODIFICATION HISTORY: +* +* Ver Who Date Changes +* ----- ------ -------- --------------------------------------------- +* 1.00a ecm/jz 01/15/10 First release +*+* +******************************************************************************/ + +/***************************** Include Files *********************************/ + +#include "xparameters.h" +#include "xwdtps.h" +#include "xscugic.h" +#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 only defined here such that a user can easily + * change all the needed parameters in one place. + */ +#define WDT_DEVICE_ID XPAR_XWDTPS_0_DEVICE_ID +#define INTC_DEVICE_ID XPAR_SCUGIC_SINGLE_DEVICE_ID +#define WDT_IRPT_INTR XPAR_XWDTPS_0_INTR + +/**************************** Type Definitions *******************************/ +#define HANDLER_CALLED 0xFFFFFFFF + +/***************** Macros (Inline Functions) Definitions *********************/ + +/************************** Function Prototypes ******************************/ + +int WdtPsIntrExample(XScuGic *IntcInstancePtr, XWdtPs * WdtInstancePtr, + u16 WdtDeviceId, u16 WdtIntrId); + +static void WdtIntrHandler(void *CallBackRef); + +static int WdtSetupIntrSystem(XScuGic *IntcInstancePtr, + XWdtPs * WdtInstancePtr, u16 WdtIntrId); + +static void WdtDisableIntrSystem(XScuGic *IntcInstancePtr, u16 WdtIntrId); + +/************************** Variable Definitions *****************************/ + +XWdtPs WdtInstance; /* Instance of WatchDog Timer */ +XScuGic IntcInstance; /* Instance of the Interrupt Controller */ + +volatile u32 HandlerCalled; /* flag is set when timeout interrupt occurs */ + +/*****************************************************************************/ +/** +* Main function to call the Wdt interrupt example. +* +* @param None. +* +* @return XST_SUCCESS if successful, otherwise XST_FAILURE. +* +* @note None. +* +******************************************************************************/ +int main(void) +{ + int Status; + + xil_printf("WDT Interrupt Example Test\r\n"); + + /* + * Call the interrupt example, specify the parameters generated in + * xparameters.h + */ + Status = WdtPsIntrExample(&IntcInstance, + &WdtInstance, WDT_DEVICE_ID, WDT_IRPT_INTR); + if (Status != XST_SUCCESS) { + xil_printf("WDT Interrupt Example Test Failed\r\n"); + return XST_FAILURE; + } + + xil_printf("Successfully ran WDT Interrupt Example Test\r\n"); + return XST_SUCCESS; +} + +/*****************************************************************************/ +/** +* +* This function tests the functioning of the System WatchDog Timer driver in the +* Interrupt mode. +* +* After one expiration of the timeout interval, an interrupt is generated and +* the WDT state bit is set to one in the status register. +* +* This function assumes that the reset output of the Wdt device is not +* connected to the reset of the processor, otherwise, the timer will cause the +* processor to reset when it expires. +* +* @param IntcInstancePtr is a pointer to the instance of the XScuGic +* driver. +* @param WdtInstancePtr is a pointer to the instance of XWdtPs driver. +* @param WdtDeviceId is the Device ID of the XWdtPs device. +* @param WdtIntrId is the Interrupt Id of the XWdtPs device. +* +* @return XST_SUCCESS if successful, otherwise XST_FAILURE. +* +* @note None. +* +******************************************************************************/ +int WdtPsIntrExample(XScuGic *IntcInstancePtr, + XWdtPs * WdtInstancePtr, u16 WdtDeviceId, u16 WdtIntrId) +{ + int Status; + u32 Timebase = 0; + u32 ExpiredTimeDelta = 0; + u32 EffectiveAddress; /* This can be the virtual address */ + XWdtPs_Config *ConfigPtr; + + + /* + * Initialize the Wdt driver. + */ + ConfigPtr = XWdtPs_LookupConfig(WdtDeviceId); + + /* + * This is where the virtual address would be used, this example + * uses physical address. + */ + EffectiveAddress = ConfigPtr->BaseAddress; + + Status = XWdtPs_CfgInitialize(WdtInstancePtr, ConfigPtr, + EffectiveAddress); + if (Status != XST_SUCCESS) { + return XST_FAILURE; + } + + /* + * Perform a self-test to ensure that the hardware was built correctly. + */ + Status = XWdtPs_SelfTest(WdtInstancePtr); + if (Status != XST_SUCCESS) { + return XST_FAILURE; + } + + /* + * Set the initial counter restart to the smallest value (0). + */ + XWdtPs_SetControlValue(WdtInstancePtr, + (u8) XWDTPS_COUNTER_RESET, (u8) 0); + + /* + * Set the initial Divider ratio at the smallest value. + */ + XWdtPs_SetControlValue(WdtInstancePtr, + (u8) XWDTPS_CLK_PRESCALE, + (u8) XWDTPS_CCR_PSCALE_0008); + + /* + * Disable the RESET output. + */ + XWdtPs_DisableOutput(WdtInstancePtr, XWDTPS_RESET_SIGNAL); + + /* + * Start the Wdt device. + */ + XWdtPs_Start(WdtInstancePtr); + + /* + * Restart the timer. + */ + XWdtPs_RestartWdt(WdtInstancePtr); + + /* + * Determine how long it takes for the Watchdog Timer to expire + * for later processing. + * If the reset output of the device is connected to the processor, + * the following code will cause a reset. + */ + while (1) { + if (!(XWdtPs_IsWdtExpired(WdtInstancePtr))) { + ExpiredTimeDelta++; + } else { + break; + } + } + + /* + * Stop the timer to set up the device in interrupt mode. + */ + XWdtPs_Stop(WdtInstancePtr); + + /* + * Connect to the interrupt subsystem so that interrupts can occur. + */ + Status = WdtSetupIntrSystem(IntcInstancePtr, WdtInstancePtr, WdtIntrId); + if (Status != XST_SUCCESS) { + return XST_FAILURE; + } + + /* + * Enable the IRQ output. + */ + XWdtPs_EnableOutput(WdtInstancePtr, (u8) XWDTPS_IRQ_SIGNAL); + + /* + * Start the Wdt device. + */ + HandlerCalled = 0; + + XWdtPs_Start(WdtInstancePtr); + + XWdtPs_RestartWdt(WdtInstancePtr); + + /* + * Verify that the Watchdog Timer does timeout when not restarted + * all the time, wait more than the amount of time it took for it + * to expire in the previous test. + */ + while (1) { + /* + * If the handler is called, the test passed + */ + if ((HandlerCalled != 0)) { + break; + } + + /* + * If more time has gone past than it took for it to expire + * when not restarted in the previous test, then stop since the + * handler was never called failing the test. + */ + + Timebase++; + if (Timebase > ExpiredTimeDelta + ExpiredTimeDelta) { + /* + * Disable and disconnect the interrupt system. + */ + + WdtDisableIntrSystem(IntcInstancePtr, WdtIntrId); + return XST_FAILURE; + } + + /* + * If the Watchdog Timer expired and handler was not called, + * then the test failed. + */ + if ((XWdtPs_IsWdtExpired(WdtInstancePtr)) && + (HandlerCalled == 0)) { + /* + * Disable and disconnect the interrupt system. + */ + WdtDisableIntrSystem(IntcInstancePtr, + WdtIntrId); + return XST_FAILURE; + } + } + + /* + * Restart the device to allow the next test to run normally. + */ + XWdtPs_RestartWdt(WdtInstancePtr); + + HandlerCalled = 0; + + /* + * Verify that the Watchdog Timer does not timeout when restarted + * all the time, wait more than the amount of time it took for it + * to expire in the previous test. + */ + while (1) { + /* + * Reset the WDT each pass through the loop + */ + XWdtPs_RestartWdt(WdtInstancePtr); + + /* + * If more time has gone past than it took for it to expire + * when not restarted in the previous test, then stop as the + * restarting worked. + */ + Timebase++; + if (Timebase > ExpiredTimeDelta + ExpiredTimeDelta) { + break; + } + + /* + * If the Watchdog Timer expired and/or handler called, then the + * test failed. + */ + if ((XWdtPs_IsWdtExpired(WdtInstancePtr)) || + (HandlerCalled != 0)) { + /* + * Disable and disconnect the interrupt system. + */ + WdtDisableIntrSystem(IntcInstancePtr, WdtIntrId); + return XST_FAILURE; + } + } + + /* + * Disable and disconnect the interrupt system. + */ + WdtDisableIntrSystem(IntcInstancePtr, WdtIntrId); + + return XST_SUCCESS; +} + +/*****************************************************************************/ +/** +* +* This function sets up the interrupt system such that interrupts can occur +* for the device. This function is application specific since the actual +* system may or may not have an interrupt controller. The device could be +* directly connected to a processor without an interrupt controller. The +* user should modify this function to fit the application. +* +* @param IntcInstancePtr is a pointer to the instance of ScuGic driver. +* @param WdtInstancePtr is a pointer to the instance of XWdtPs driver. +* @param WdtIntrId is the Interrupt Id of the XWdtPs device. +* +* @return XST_SUCCESS if successful, otherwise XST_FAILURE. +* +* @note None. +* +******************************************************************************/ +static int WdtSetupIntrSystem(XScuGic *IntcInstancePtr, + XWdtPs *WdtInstancePtr, u16 WdtIntrId) +{ + int Status; + XScuGic_Config *IntcConfig; + u8 Priority, Trigger; + + Xil_ExceptionInit(); + + /* + * Initialize the interrupt controller driver so that it is ready to + * use. + */ + 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; + } + + XScuGic_GetPriorityTriggerType(IntcInstancePtr, WdtIntrId, + &Priority, &Trigger); + Trigger = 3; + XScuGic_SetPriorityTriggerType(IntcInstancePtr, WdtIntrId, + Priority, Trigger); + + /* + * 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); + + /* + * Connect the device driver handler that will be called when an + * interrupt for the device occurs, the handler defined above performs + * the specific interrupt processing for the device. + */ + Status = XScuGic_Connect(IntcInstancePtr, WdtIntrId, + (Xil_ExceptionHandler)WdtIntrHandler, + (void *)WdtInstancePtr); + if (Status != XST_SUCCESS) { + return Status; + } + + /* + * Enable the interrupt for the device. + */ + XScuGic_Enable(IntcInstancePtr, WdtIntrId); + + /* + * Enable interrupts in the Processor. + */ + Xil_ExceptionEnable(); + + return XST_SUCCESS; +} + +/*****************************************************************************/ +/** +* +* This function is the Interrupt handler for the WDT Interrupt of the +* Wdt device. It is called on the expiration of the timer counter in +* interrupt context. +* +* @param CallBackRef is a pointer to the callback function. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +static void WdtIntrHandler(void *CallBackRef) +{ + /* + * WDT timed out and interrupt occurred, let main test loop know. + */ + HandlerCalled = HANDLER_CALLED; +} + +/*****************************************************************************/ +/** +* +* This function disables the interrupts that occur for the device. +* +* @param IntcInstancePtr is the pointer to the instance of XScuGic +* driver. +* @param WdtIntrId is the Interrupt Id for the device. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +static void WdtDisableIntrSystem(XScuGic *IntcInstancePtr, u16 WdtIntrId) +{ + + /* + * Disconnect and disable the interrupt for the Wdt. + */ + XScuGic_Disconnect(IntcInstancePtr, WdtIntrId); + +} diff --git a/XilinxProcessorIPLib/drivers/wdtps/examples/xwdtps_polled_example.c b/XilinxProcessorIPLib/drivers/wdtps/examples/xwdtps_polled_example.c new file mode 100755 index 00000000..b7a06419 --- /dev/null +++ b/XilinxProcessorIPLib/drivers/wdtps/examples/xwdtps_polled_example.c @@ -0,0 +1,261 @@ +/****************************************************************************** +* +* Copyright (C) 2010 - 2014 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 xwdtps_polled_example.c +* +* This file contains a design example using the System Watchdog Timer driver +* (XWdtPs) and hardware device. This function assumes that the reset output +* of the Watchdog timer device is not connected to the reset of the processor. +* +* @note +* +* None. +* +* MODIFICATION HISTORY: +* +*
+* Ver Who Date Changes +* ----- ------ -------- --------------------------------------------- +* 1.00a ecm/jz 01/15/10 First release +*+******************************************************************************/ + +/***************************** Include Files *********************************/ + +#include "xparameters.h" +#include "xwdtps.h" +#include "xil_printf.h" + +/************************** Constant Definitions *****************************/ + +/* + * The following constants map to the XPAR parameters created in the + * xparameters.h file. They are only defined here such that a user can easily + * change all the needed parameters in one place. + */ +#define WDT_DEVICE_ID XPAR_XWDTPS_0_DEVICE_ID + +/**************************** Type Definitions *******************************/ + + +/***************** Macros (Inline Functions) Definitions *********************/ + + +/************************** Function Prototypes ******************************/ + +int WdtPsPolledExample(u16 DeviceId); + +/************************** Variable Definitions *****************************/ + +XWdtPs Watchdog; /* Instance of WatchDog Timer */ + +/*****************************************************************************/ +/** +* +* Main function to call the Wdt polled mode example. +* +* @param None +* +* @return XST_SUCCESS if successful, XST_FAILURE if unsuccessful +* +* @note None +* +******************************************************************************/ +int main(void) +{ + int Status; + + xil_printf("WDT Polled Mode Example Test\r\n"); + + /* + * Call the example , specify the device ID that is generated in + * xparameters.h. + */ + Status = WdtPsPolledExample(WDT_DEVICE_ID); + if (Status != XST_SUCCESS) { + xil_printf("WDT Polled Mode Example Test Failed\r\n"); + return XST_FAILURE; + } + + xil_printf("Successfully ran WDT Polled Mode Example Test\r\n"); + return XST_SUCCESS; +} + +/*****************************************************************************/ +/** +* This function does a minimal test on the System Watchdog Timer device and +* driver as a design example. The purpose of this function is to illustrate +* how to use the XWdtPs driver. +* +* This function assumes that the reset output of the Watchdog timer +* device is not connected to the reset of the processor. The function +* allows the Watchdog Timer to timeout such that a reset will occur if it is +* connected. If the interrupt output is connected to an interrupt input, the +* user must handle the interrupts appropriately if the output is enabled. +* +* This function may require some time (seconds or even minutes) to execute +* because it waits for the Watchdog Timer to expire. +* +* @param DeviceId is the unique device id of the device. +* +* @return XST_SUCCESS if successful, otherwise XST_FAILURE. +* +* @note None. +* +****************************************************************************/ +int WdtPsPolledExample(u16 DeviceId) +{ + int Status; + u32 ExpiredTimeDelta1 = 0; + u32 ExpiredTimeDelta2 = 0; + XWdtPs_Config *ConfigPtr; + u32 EffectiveAddress; /* This can be the virtual address */ + + /* + * Initialize the Watchdog Timer so that it is ready to use + */ + ConfigPtr = XWdtPs_LookupConfig(DeviceId); + + /* + * This is where the virtual address would be used, this example + * uses physical address. + */ + EffectiveAddress = ConfigPtr->BaseAddress; + Status = XWdtPs_CfgInitialize(&Watchdog, ConfigPtr, + EffectiveAddress); + if (Status != XST_SUCCESS) { + return XST_FAILURE; + } + + /* + * Set the initial counter restart to the smallest value (0). + */ + XWdtPs_SetControlValue(&Watchdog, + (u8) XWDTPS_COUNTER_RESET, (u8) 0); + + + /* + * Set the initial Divider ratio at the smallest value. + */ + XWdtPs_SetControlValue(&Watchdog, + (u8) XWDTPS_CLK_PRESCALE, + (u8) XWDTPS_CCR_PSCALE_0008); + + /* + * Disable the RESET output. + */ + XWdtPs_DisableOutput(&Watchdog, XWDTPS_RESET_SIGNAL); + + /* + * Start the Watchdog Timer. + */ + XWdtPs_Start(&Watchdog); + + /* + * Restart the Watchdog Timer. + */ + XWdtPs_RestartWdt(&Watchdog); + + /* + * Determine how long it takes for the Watchdog Timer to expire + * for later processing. + */ + while (1) { + if (!(XWdtPs_IsWdtExpired(&Watchdog))) { + ExpiredTimeDelta1++; + } else { + break; + } + } + + /* + * Change the initial restart count value and make sure the WDT takes longer. + */ + XWdtPs_SetControlValue(&Watchdog, + (u8) XWDTPS_COUNTER_RESET, (u8) 1); + + + XWdtPs_RestartWdt(&Watchdog); + + /* + * Wait for the WDT to timeout again, should take longer this time. + */ + while (1) { + if (!(XWdtPs_IsWdtExpired(&Watchdog))) { + ExpiredTimeDelta2++; + } else { + break; + } + } + + + /* + * Verify that the Watchdog Timer took longer. + */ + if (ExpiredTimeDelta2 <= ExpiredTimeDelta1) { + return XST_FAILURE; + } + + /* + * Verify that the Watchdog Timer does not timeout when restarted + * all the time, wait more than twice the amount of time it took for it + * to expire in the previous test. + */ + ExpiredTimeDelta1 = 0; + + while (1) { + /* + * Restart the Watchdog Timer as a normal application would. + */ + XWdtPs_RestartWdt(&Watchdog); + + ExpiredTimeDelta1++; + /* + * If more time has gone past than it took for it to expire + * when not restarted in the previous test, then stop as the + * restarting worked. + */ + if (ExpiredTimeDelta1 > (ExpiredTimeDelta2 * 2)) { + break; + } + + /* + * If the Watchdog Timer expired, then the test failed. + */ + if (XWdtPs_IsWdtExpired(&Watchdog)) { + return XST_FAILURE; + } + } + + return XST_SUCCESS; +} diff --git a/XilinxProcessorIPLib/drivers/wdtps/examples/xwdtps_selftest_example.c b/XilinxProcessorIPLib/drivers/wdtps/examples/xwdtps_selftest_example.c new file mode 100755 index 00000000..992c9374 --- /dev/null +++ b/XilinxProcessorIPLib/drivers/wdtps/examples/xwdtps_selftest_example.c @@ -0,0 +1,161 @@ +/****************************************************************************** +* +* Copyright (C) 2011 - 2014 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 xwdtps_selftest_example.c +* +* This file contains a design example using the System Watchdog Timer driver +* (XWdtPs) and hardware device. +* +* @note +* +* None. +* +* MODIFICATION HISTORY: +* +*
+* Ver Who Date Changes +* ----- ------ -------- --------------------------------------------- +* 1.00a sdm 05/27/11 First release +*+******************************************************************************/ + +/***************************** Include Files *********************************/ + +#include "xparameters.h" +#include "xwdtps.h" +#include "xil_printf.h" + +/************************** Constant Definitions *****************************/ + +/* + * The following constants map to the XPAR parameters created in the + * xparameters.h file. They are only defined here such that a user can easily + * change all the needed parameters in one place. + */ +#define WDT_DEVICE_ID XPAR_XWDTPS_0_DEVICE_ID + +/**************************** Type Definitions *******************************/ + + +/***************** Macros (Inline Functions) Definitions *********************/ + + +/************************** Function Prototypes ******************************/ + +int WdtPsSelfTestExample(u16 DeviceId); + +/************************** Variable Definitions *****************************/ + +XWdtPs Watchdog; /* Instance of WatchDog Timer */ + +/*****************************************************************************/ +/** +* Main function to call the self test example. +* +* @param None +* +* @return XST_SUCCESS if successful, XST_FAILURE if unsuccessful +* +* @note None +* +******************************************************************************/ +#ifndef TESTAPP_GEN +int main(void) +{ + int Status; + + xil_printf("WDT SelfTest Example Test\r\n"); + + /* + * Call the example , specify the device ID that is generated in + * xparameters.h. + */ + Status = WdtPsSelfTestExample(WDT_DEVICE_ID); + if (Status != XST_SUCCESS) { + xil_printf("WDT SelfTest Example Test Failed\r\n"); + return XST_FAILURE; + } + + xil_printf("Successfully ran WDT SelfTest Example Test\r\n"); + return XST_SUCCESS; +} +#endif + +/*****************************************************************************/ +/** +* This function does a minimal test on the watchdog timer device and driver +* as a design example. The purpose of this function is to illustrate how to use +* the XWdtPs driver. +* +* This function may require some time (seconds or even minutes) to execute +* because it waits for the watchdog timer to expire. +* +* @param DeviceId is the unique device id of the device. +* +* @return XST_SUCCESS if successful, otherwise XST_FAILURE. +* +* @note None. +* +****************************************************************************/ +int WdtPsSelfTestExample(u16 DeviceId) +{ + int Status; + XWdtPs_Config *ConfigPtr; + + /* + * Initialize the watchdog timer so that it is ready to use + */ + ConfigPtr = XWdtPs_LookupConfig(DeviceId); + if (NULL == ConfigPtr) { + return XST_FAILURE; + } + /* + * This is where the virtual address would be used, this example + * uses physical address. + */ + Status = XWdtPs_CfgInitialize(&Watchdog, ConfigPtr, + ConfigPtr->BaseAddress); + if (Status != XST_SUCCESS) { + return XST_FAILURE; + } + + /* + * Run the SelfTest + */ + Status = XWdtPs_SelfTest(&Watchdog); + if (Status != XST_SUCCESS) { + return XST_FAILURE; + } + + return XST_SUCCESS; +} diff --git a/XilinxProcessorIPLib/drivers/wdtps/src/Makefile b/XilinxProcessorIPLib/drivers/wdtps/src/Makefile new file mode 100755 index 00000000..8efa5728 --- /dev/null +++ b/XilinxProcessorIPLib/drivers/wdtps/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 wdtps_libs clean + +%.o: %.c + ${COMPILER} $(CC_FLAGS) $(ECC_FLAGS) $(INCLUDES) -o $@ $< + +banner: + echo "Compiling wdtps" + +wdtps_libs: ${OBJECTS} + $(ARCHIVER) -r ${RELEASEDIR}/${LIB} ${OBJECTS} + +.PHONY: include +include: wdtps_includes + +wdtps_includes: + ${CP} ${INCLUDEFILES} ${INCLUDEDIR} + +clean: + rm -rf ${OBJECTS} diff --git a/XilinxProcessorIPLib/drivers/wdtps/src/xwdtps.c b/XilinxProcessorIPLib/drivers/wdtps/src/xwdtps.c new file mode 100755 index 00000000..c76af5c0 --- /dev/null +++ b/XilinxProcessorIPLib/drivers/wdtps/src/xwdtps.c @@ -0,0 +1,466 @@ +/****************************************************************************** +* +* Copyright (C) 2010 - 2014 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 xwdtps.c +* +* Contains the implementation of interface functions of the XWdtPs driver. +* See xwdtps.h for a description of the driver. +* +*
+* MODIFICATION HISTORY: +* +* Ver Who Date Changes +* ----- ------ -------- --------------------------------------------- +* 1.00a ecm/jz 01/15/10 First release +* 1.02a sg 07/15/12 Removed code/APIs related to External Signal +* Length functionality for CR 658287 +* Removed APIs XWdtPs_SetExternalSignalLength, +* XWdtPs_GetExternalSignalLength +*+* +******************************************************************************/ + +/***************************** Include Files *********************************/ + +#include "xwdtps.h" + +/************************** Constant Definitions *****************************/ + + +/**************************** Type Definitions *******************************/ + + +/***************** Macros (Inline Functions) Definitions *********************/ + + +/************************** Function Prototypes ******************************/ + + +/************************** Variable Definitions *****************************/ + + +/****************************************************************************/ +/** +* +* Initialize a specific watchdog timer instance/driver. This function +* must be called before other functions of the driver are called. +* +* @param InstancePtr is a pointer to the XWdtPs instance. +* @param ConfigPtr is the config structure. +* @param EffectiveAddress is the base address for the device. It could be +* a virtual address if address translation is supported in the +* system, otherwise it is the physical address. +* +* @return +* - XST_SUCCESS if initialization was successful. +* - XST_DEVICE_IS_STARTED if the device has already been started. +* +* @note None. +* +******************************************************************************/ +int XWdtPs_CfgInitialize(XWdtPs *InstancePtr, + XWdtPs_Config *ConfigPtr, u32 EffectiveAddress) +{ + Xil_AssertNonvoid(InstancePtr != NULL); + Xil_AssertNonvoid(ConfigPtr != NULL); + + /* + * If the device is started, disallow the initialize and return a + * status indicating it is started. This allows the user to stop the + * device and reinitialize, but prevents a user from inadvertently + * initializing. + */ + if (InstancePtr->IsStarted == XIL_COMPONENT_IS_STARTED) { + return XST_DEVICE_IS_STARTED; + } + + /* + * Copy configuration into instance. + */ + InstancePtr->Config.DeviceId = ConfigPtr->DeviceId; + + /* + * Save the base address pointer such that the registers of the block + * can be accessed and indicate it has not been started yet. + */ + InstancePtr->Config.BaseAddress = EffectiveAddress; + InstancePtr->IsStarted = 0; + + /* + * Indicate the instance is ready to use, successfully initialized. + */ + InstancePtr->IsReady = XIL_COMPONENT_IS_READY; + + return XST_SUCCESS; +} + +/****************************************************************************/ +/** +* +* Start the watchdog timer of the device. +* +* @param InstancePtr is a pointer to the XWdtPs instance. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +void XWdtPs_Start(XWdtPs *InstancePtr) +{ + u32 Register; + + Xil_AssertVoid(InstancePtr != NULL); + Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY); + + /* + * Read the contents of the ZMR register. + */ + Register = XWdtPs_ReadReg(InstancePtr->Config.BaseAddress, + XWDTPS_ZMR_OFFSET); + + /* + * Enable the Timer field in the register and Set the access key so the + * write takes place. + */ + Register |= XWDTPS_ZMR_WDEN_MASK; + Register |= XWDTPS_ZMR_ZKEY_VAL; + + /* + * Update the ZMR with the new value. + */ + XWdtPs_WriteReg(InstancePtr->Config.BaseAddress, XWDTPS_ZMR_OFFSET, + Register); + + /* + * Indicate that the device is started. + */ + InstancePtr->IsStarted = XIL_COMPONENT_IS_STARTED; + +} + +/****************************************************************************/ +/** +* +* Disable the watchdog timer. +* +* It is the caller's responsibility to disconnect the interrupt handler +* of the watchdog timer from the interrupt source, typically an interrupt +* controller, and disable the interrupt in the interrupt controller. +* +* @param InstancePtr is a pointer to the XWdtPs instance. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +void XWdtPs_Stop(XWdtPs *InstancePtr) +{ + u32 Register; + + Xil_AssertVoid(InstancePtr != NULL); + Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY); + + /* + * Read the contents of the ZMR register. + */ + Register = XWdtPs_ReadReg(InstancePtr->Config.BaseAddress, + XWDTPS_ZMR_OFFSET); + + /* + * Disable the Timer field in the register and + * Set the access key for the write to be done the register. + */ + Register &= ~XWDTPS_ZMR_WDEN_MASK; + Register |= XWDTPS_ZMR_ZKEY_VAL; + + /* + * Update the ZMR with the new value. + */ + XWdtPs_WriteReg(InstancePtr->Config.BaseAddress, XWDTPS_ZMR_OFFSET, + Register); + + InstancePtr->IsStarted = 0; +} + + +/****************************************************************************/ +/** +* +* Enables the indicated signal/output. +* Performs a read/modify/write cycle to update the value correctly. +* +* @param InstancePtr is a pointer to the XWdtPs instance. +* @param Signal is the desired signal/output. +* Valid Signal Values are XWDTPS_RESET_SIGNAL and +* XWDTPS_IRQ_SIGNAL. +* Only one of them can be specified at a time. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +void XWdtPs_EnableOutput(XWdtPs *InstancePtr, u8 Signal) +{ + u32 Register = 0; + + Xil_AssertVoid(InstancePtr != NULL); + Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY); + Xil_AssertVoid((Signal == XWDTPS_RESET_SIGNAL) || + (Signal == XWDTPS_IRQ_SIGNAL)); + + /* + * Read the contents of the ZMR register. + */ + Register = XWdtPs_ReadReg(InstancePtr->Config.BaseAddress, + XWDTPS_ZMR_OFFSET); + + if (Signal == XWDTPS_RESET_SIGNAL) { + /* + * Enable the field in the register. + */ + Register |= XWDTPS_ZMR_RSTEN_MASK; + + } else if (Signal == XWDTPS_IRQ_SIGNAL) { + /* + * Enable the field in the register. + */ + Register |= XWDTPS_ZMR_IRQEN_MASK; + + } + + /* + * Set the access key so the write takes. + */ + Register |= XWDTPS_ZMR_ZKEY_VAL; + + /* + * Update the ZMR with the new value. + */ + XWdtPs_WriteReg(InstancePtr->Config.BaseAddress, XWDTPS_ZMR_OFFSET, + Register); +} + +/****************************************************************************/ +/** +* +* Disables the indicated signal/output. +* Performs a read/modify/write cycle to update the value correctly. +* +* @param InstancePtr is a pointer to the XWdtPs instance. +* @param Signal is the desired signal/output. +* Valid Signal Values are XWDTPS_RESET_SIGNAL and +* XWDTPS_IRQ_SIGNAL +* Only one of them can be specified at a time. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +void XWdtPs_DisableOutput(XWdtPs *InstancePtr, u8 Signal) +{ + u32 Register = 0; + + Xil_AssertVoid(InstancePtr != NULL); + Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY); + Xil_AssertVoid((Signal == XWDTPS_RESET_SIGNAL) || + (Signal == XWDTPS_IRQ_SIGNAL)); + + /* + * Read the contents of the ZMR register. + */ + Register = XWdtPs_ReadReg(InstancePtr->Config.BaseAddress, + XWDTPS_ZMR_OFFSET); + + if (Signal == XWDTPS_RESET_SIGNAL) { + /* + * Disable the field in the register. + */ + Register &= ~XWDTPS_ZMR_RSTEN_MASK; + + } else if (Signal == XWDTPS_IRQ_SIGNAL) { + /* + * Disable the field in the register. + */ + Register &= ~XWDTPS_ZMR_IRQEN_MASK; + + } + + /* + * Set the access key so the write takes place. + */ + Register |= XWDTPS_ZMR_ZKEY_VAL; + + /* + * Update the ZMR with the new value. + */ + XWdtPs_WriteReg(InstancePtr->Config.BaseAddress, XWDTPS_ZMR_OFFSET, + Register); +} + +/****************************************************************************/ +/** +* +* Returns the current control setting for the indicated signal/output. +* The register referenced is the Counter Control Register (XWDTPS_CCR_OFFSET) +* +* @param InstancePtr is a pointer to the XWdtPs instance. +* @param Control is the desired signal/output. +* Valid Control Values are XWDTPS_CLK_PRESCALE and +* XWDTPS_COUNTER_RESET. Only one of them can be specified at a +* time. +* +* @return The contents of the requested control field in the Counter +* Control Register (XWDTPS_CCR_OFFSET). +* If the Control is XWDTPS_CLK_PRESCALE then use the +* defintions XWDTEPB_CCR_PSCALE_XXXX. +* If the Control is XWDTPS_COUNTER_RESET then the values are +* 0x0 to 0xFFF. This is the Counter Restart value in the CCR +* register. +* +* @note None. +* +******************************************************************************/ +u32 XWdtPs_GetControlValue(XWdtPs *InstancePtr, u8 Control) +{ + u32 Register; + u32 ReturnValue = 0; + + Xil_AssertNonvoid(InstancePtr != NULL); + Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY); + Xil_AssertNonvoid((Control == XWDTPS_CLK_PRESCALE) || + (Control == XWDTPS_COUNTER_RESET)); + + /* + * Read the contents of the CCR register. + */ + Register = XWdtPs_ReadReg(InstancePtr->Config.BaseAddress, + XWDTPS_CCR_OFFSET); + + if (Control == XWDTPS_CLK_PRESCALE) { + /* + * Mask off the field in the register. + */ + ReturnValue = Register & XWDTPS_CCR_CLKSEL_MASK; + + } else if (Control == XWDTPS_COUNTER_RESET) { + /* + * Mask off the field in the register. + */ + Register &= XWDTPS_CCR_CRV_MASK; + + /* + * Shift over to the right most positions. + */ + ReturnValue = Register >> XWDTPS_CCR_CRV_SHIFT; + } + + return ReturnValue; +} + +/****************************************************************************/ +/** +* +* Updates the current control setting for the indicated signal/output with +* the provided value. +* +* Performs a read/modify/write cycle to update the value correctly. +* The register referenced is the Counter Control Register (XWDTPS_CCR_OFFSET) +* +* @param InstancePtr is a pointer to the XWdtPs instance. +* @param Control is the desired signal/output. +* Valid Control Values are XWDTPS_CLK_PRESCALE and +* XWDTPS_COUNTER_RESET. Only one of them can be specified at a +* time. +* @param Value is the desired control value. +* If the Control is XWDTPS_CLK_PRESCALE then use the +* defintions XWDTEPB_CCR_PSCALE_XXXX. +* If the Control is XWDTPS_COUNTER_RESET then the valid values +* are 0x0 to 0xFFF, this sets the counter restart value of the CCR +* register. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +void XWdtPs_SetControlValue(XWdtPs *InstancePtr, u8 Control, u32 Value) +{ + u32 Register = 0; + + Xil_AssertVoid(InstancePtr != NULL); + Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY); + Xil_AssertVoid((Control == XWDTPS_CLK_PRESCALE) || + (Control == XWDTPS_COUNTER_RESET)); + + /* + * Read the contents of the CCR register. + */ + Register = XWdtPs_ReadReg(InstancePtr->Config.BaseAddress, + XWDTPS_CCR_OFFSET); + + if (Control == XWDTPS_CLK_PRESCALE) { + /* + * Zero the field in the register. + */ + Register &= ~XWDTPS_CCR_CLKSEL_MASK; + + } else if (Control == XWDTPS_COUNTER_RESET) { + /* + * Zero the field in the register. + */ + Register &= ~XWDTPS_CCR_CRV_MASK; + + /* + * Shift Value over to the proper positions. + */ + Value = Value << XWDTPS_CCR_CRV_SHIFT; + } + + Register |= Value; + + /* + * Set the access key so the write takes. + */ + Register |= XWDTPS_CCR_CKEY_VAL; + + /* + * Update the CCR with the new value. + */ + XWdtPs_WriteReg(InstancePtr->Config.BaseAddress, XWDTPS_CCR_OFFSET, + Register); +} diff --git a/XilinxProcessorIPLib/drivers/wdtps/src/xwdtps.h b/XilinxProcessorIPLib/drivers/wdtps/src/xwdtps.h new file mode 100755 index 00000000..a6eabef8 --- /dev/null +++ b/XilinxProcessorIPLib/drivers/wdtps/src/xwdtps.h @@ -0,0 +1,218 @@ +/****************************************************************************** +* +* Copyright (C) 2010 - 2014 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 xwdtps.h +* +* The Xilinx watchdog timer driver supports the Xilinx watchdog timer hardware. +* +* The Xilinx watchdog timer (WDT) driver supports the following features: +* - Both Interrupt driven and Polled mode +* - enabling and disabling the watchdog timer +* - restarting the watchdog. +* - initializing the most significant digit of the counter restart value. +* - multiple individually enabling/disabling outputs +* +* It is the responsibility of the application to provide an interrupt handler +* for the watchdog timer and connect it to the interrupt system if interrupt +* driven mode is desired. +* +* If interrupt is enabled, the watchdog timer device generates an interrupt +* when the counter reaches zero. +* +* If the hardware interrupt signal is not connected/enabled, polled mode is the +* only option (using IsWdtExpired) for the watchdog. +* +* The outputs from the WDT are individually enabled/disabled using +* _EnableOutput()/_DisableOutput(). The clock divisor ratio and initial restart +* value of the count is configurable using _SetControlValues(). +* +* The reset condition of the hardware has the maximum initial count in the +* Counter Reset Value (CRV) and the WDT is disabled with the reset enable +* enabled and the reset length set to 32 clocks. i.e. +*
+* register ZMR = 0x1C2 +* register CCR = 0x3FC +*+* +* This driver is intended to be RTOS and processor independent. It works with +* physical addresses only. Any needs for dynamic memory management, threads +* or thread mutual exclusion, virtual memory, or cache control must be +* satisfied by the layer above this driver. +* +*
+* MODIFICATION HISTORY: +* +* Ver Who Date Changes +* ----- ------ -------- ----------------------------------------------- +* 1.00a ecm/jz 01/15/10 First release +* 1.01a asa 02/15/12 Added tcl file to generate xparameters +* 1.02a sg 07/15/12 Removed code/APIs related to External Signal +* Length functionality for CR 658287 +* Removed APIs XWdtPs_SetExternalSignalLength, +* XWdtPs_GetExternalSignalLength +* Modified the Self Test to use the Reset Length mask +* for CR 658287 +* 3.0 pkp 12/09/14 Added support for Zynq Ultrascale Mp +*+* +******************************************************************************/ +#ifndef XWDTPS_H /* prevent circular inclusions */ +#define XWDTPS_H /* by using protection macros */ + +/***************************** Include Files *********************************/ +#include "xil_types.h" +#include "xil_assert.h" +#include "xstatus.h" +#include "xwdtps_hw.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/************************** Constant Definitions *****************************/ + +/* + * Choices for output selections for the device, used in + * XWdtPs_EnableOutput()/XWdtPs_DisableOutput() functions + */ +#define XWDTPS_RESET_SIGNAL 1 /**< Reset signal request */ +#define XWDTPS_IRQ_SIGNAL 2 /**< IRQ signal request */ + +/* + * Control value setting flags, used in + * XWdtPs_SetControlValues()/XWdtPs_GetControlValues() functions + */ +#define XWDTPS_CLK_PRESCALE 1 /**< Clock Prescale request */ +#define XWDTPS_COUNTER_RESET 2 /**< Counter Reset request */ + +/**************************** Type Definitions *******************************/ + +/** + * This typedef contains configuration information for the device. + */ +typedef struct { + u16 DeviceId; /**< Unique ID of device */ + u32 BaseAddress; /**< Base address of the device */ +} XWdtPs_Config; + + +/** + * The XWdtPs driver instance data. The user is required to allocate a + * variable of this type for every watchdog/timer device in the system. + * A pointer to a variable of this type is then passed to the driver API + * functions. + */ +typedef struct { + XWdtPs_Config Config; /**< Hardware Configuration */ + u32 IsReady; /**< Device is initialized and ready */ + u32 IsStarted; /**< Device watchdog timer is running */ +} XWdtPs; + +/***************** Macros (Inline Functions) Definitions *********************/ +/****************************************************************************/ +/** +* +* Check if the watchdog timer has expired. This function is used for polled +* mode and it is also used to check if the last reset was caused by the +* watchdog timer. +* +* @param InstancePtr is a pointer to the XWdtPs instance. +* +* @return +* - TRUE if the watchdog has expired. +* - FALSE if the watchdog has not expired. +* +* @note C-style signature: +* int XWdtPs_IsWdtExpired(XWdtPs *InstancePtr) +* +******************************************************************************/ +#define XWdtPs_IsWdtExpired(InstancePtr) \ +((XWdtPs_ReadReg((InstancePtr)->Config.BaseAddress, XWDTPS_SR_OFFSET) & \ + XWDTPS_SR_WDZ_MASK) == XWDTPS_SR_WDZ_MASK) + + +/****************************************************************************/ +/** +* +* Restart the watchdog timer. An application needs to call this function +* periodically to keep the timer from asserting the enabled output. +* +* @param InstancePtr is a pointer to the XWdtPs instance. +* +* @return None. +* +* @note C-style signature: +* void XWdtPs_RestartWdt(XWdtPs *InstancePtr) +* +******************************************************************************/ +#define XWdtPs_RestartWdt(InstancePtr) \ + XWdtPs_WriteReg((InstancePtr)->Config.BaseAddress, \ + XWDTPS_RESTART_OFFSET, XWDTPS_RESTART_KEY_VAL) + +/************************** Function Prototypes ******************************/ + +/* + * Lookup configuration in xwdtps_sinit.c. + */ +XWdtPs_Config *XWdtPs_LookupConfig(u16 DeviceId); + +/* + * Interface functions in xwdtps.c + */ +int XWdtPs_CfgInitialize(XWdtPs *InstancePtr, + XWdtPs_Config *ConfigPtr, u32 EffectiveAddress); + +void XWdtPs_Start(XWdtPs *InstancePtr); + +void XWdtPs_Stop(XWdtPs *InstancePtr); + +void XWdtPs_EnableOutput(XWdtPs *InstancePtr, u8 Signal); + +void XWdtPs_DisableOutput(XWdtPs *InstancePtr, u8 Signal); + +u32 XWdtPs_GetControlValue(XWdtPs *InstancePtr, u8 Control); + +void XWdtPs_SetControlValue(XWdtPs *InstancePtr, u8 Control, u32 Value); + +/* + * Self-test function in xwdttb_selftest.c. + */ +int XWdtPs_SelfTest(XWdtPs *InstancePtr); + + +#ifdef __cplusplus +} +#endif + +#endif /* end of protection macro */ diff --git a/XilinxProcessorIPLib/drivers/wdtps/src/xwdtps_g.c b/XilinxProcessorIPLib/drivers/wdtps/src/xwdtps_g.c new file mode 100755 index 00000000..f2ab3579 --- /dev/null +++ b/XilinxProcessorIPLib/drivers/wdtps/src/xwdtps_g.c @@ -0,0 +1,78 @@ +/****************************************************************************** +* +* Copyright (C) 2010 - 2014 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 xwdtps_g.c +* +* This file contains a table that specifies the configuration of the watchdog +* timer devices in the system. Each device should have an entry in the table. +* +*
+* MODIFICATION HISTORY: +* +* Ver Who Date Changes +* ----- ------ -------- --------------------------------------------- +* 1.00a ecm/jz 01/15/10 First release +*+* +******************************************************************************/ + +/***************************** Include Files *********************************/ + +#include "xparameters.h" +#include "xwdtps.h" + +/************************** Constant Definitions *****************************/ + + +/**************************** Type Definitions *******************************/ + + +/***************** Macros (Inline Functions) Definitions *********************/ + + +/************************** Function Prototypes ******************************/ + + +/************************** Variable Prototypes ******************************/ + +/** + * This table contains configuration information for each watchdog timer + * device in the system. + */ +XWdtPs_Config XWdtPs_ConfigTable[XPAR_XWDTPS_NUM_INSTANCES] = { + { + XPAR_XWDTPS_0_DEVICE_ID, + XPAR_XWDTPS_0_BASEADDR + } +}; diff --git a/XilinxProcessorIPLib/drivers/wdtps/src/xwdtps_hw.h b/XilinxProcessorIPLib/drivers/wdtps/src/xwdtps_hw.h new file mode 100755 index 00000000..2c18a7de --- /dev/null +++ b/XilinxProcessorIPLib/drivers/wdtps/src/xwdtps_hw.h @@ -0,0 +1,189 @@ +/****************************************************************************** +* +* Copyright (C) 2010 - 2014 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 xwdtps_hw.h +* +* This file contains the hardware interface to the System Watch Dog Timer (WDT). +* +*
+* MODIFICATION HISTORY: +* +* Ver Who Date Changes +* ----- ------ -------- --------------------------------------------- +* 1.00a ecm/jz 01/15/10 First release +* 1.02a sg 07/15/12 Removed defines related to External Signal +* Length functionality for CR 658287 +*+* +******************************************************************************/ +#ifndef XWDTPS_HW_H /* prevent circular inclusions */ +#define XWDTPS_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 *****************************/ + +/** @name Register Map + * Offsets of registers from the start of the device + * @{ + */ + +#define XWDTPS_ZMR_OFFSET 0x0 /**< Zero Mode Register */ +#define XWDTPS_CCR_OFFSET 0x4 /**< Counter Control Register */ +#define XWDTPS_RESTART_OFFSET 0x8 /**< Restart Register */ +#define XWDTPS_SR_OFFSET 0xC /**< Status Register */ +/* @} */ + + +/** @name Zero Mode Register + * This register controls how the time out is indicated and also contains + * the access code (0xABC) to allow writes to the register + * @{ + */ +#define XWDTPS_ZMR_WDEN_MASK 0x00000001 /**< enable the WDT */ +#define XWDTPS_ZMR_RSTEN_MASK 0x00000002 /**< enable the reset output */ +#define XWDTPS_ZMR_IRQEN_MASK 0x00000004 /**< enable the IRQ output */ + +#define XWDTPS_ZMR_RSTLN_MASK 0x00000070 /**< set length of reset pulse */ +#define XWDTPS_ZMR_RSTLN_SHIFT 4 /**< shift for reset pulse */ + +#define XWDTPS_ZMR_IRQLN_MASK 0x00000180 /**< set length of interrupt pulse */ +#define XWDTPS_ZMR_IRQLN_SHIFT 7 /**< shift for interrupt pulse */ + +#define XWDTPS_ZMR_ZKEY_MASK 0x00FFF000 /**< mask for writing access key */ +#define XWDTPS_ZMR_ZKEY_VAL 0x00ABC000 /**< access key, 0xABC << 12 */ + +/* @} */ + +/** @name Counter Control register + * This register controls how fast the timer runs and the reset value + * and also contains the access code (0x248) to allow writes to the + * register + * @{ + */ + +#define XWDTPS_CCR_CLKSEL_MASK 0x00000003 /**< counter clock prescale */ + +#define XWDTPS_CCR_CRV_MASK 0x00003FFC /**< counter reset value */ +#define XWDTPS_CCR_CRV_SHIFT 2 /**< shift for writing value */ + +#define XWDTPS_CCR_CKEY_MASK 0x03FFC000 /**< mask for writing access key */ +#define XWDTPS_CCR_CKEY_VAL 0x00920000 /**< access key, 0x248 << 14 */ + +/* Bit patterns for Clock prescale divider values */ + +#define XWDTPS_CCR_PSCALE_0008 0x00000000 /**< divide clock by 8 */ +#define XWDTPS_CCR_PSCALE_0064 0x00000001 /**< divide clock by 64 */ +#define XWDTPS_CCR_PSCALE_0512 0x00000002 /**< divide clock by 512 */ +#define XWDTPS_CCR_PSCALE_4096 0x00000003 /**< divide clock by 4096 */ + +/* @} */ + +/** @name Restart register + * This register resets the timer preventing a timeout. Value is specific + * 0x1999 + * @{ + */ + +#define XWDTPS_RESTART_KEY_VAL 0x00001999 /**< valid key */ + +/*@}*/ + +/** @name Status register + * This register indicates timer reached zero count. + * @{ + */ +#define XWDTPS_SR_WDZ_MASK 0x00000001 /**< time out occurred */ + +/*@}*/ + +/**************************** Type Definitions *******************************/ + + +/***************** Macros (Inline Functions) Definitions *********************/ + +/****************************************************************************/ +/** +* +* Read the given register. +* +* @param BaseAddress is the base address of the device +* @param RegOffset is the register offset to be read +* +* @return The 32-bit value of the register +* +* @note C-style signature: +* u32 XWdtPs_ReadReg(u32 BaseAddress, u32 RegOffset) +* +*****************************************************************************/ +#define XWdtPs_ReadReg(BaseAddress, RegOffset) \ + Xil_In32((BaseAddress) + (RegOffset)) + +/****************************************************************************/ +/** +* +* Write the given register. +* +* @param BaseAddress is the base address of the device +* @param RegOffset is the register offset to be written +* @param Data is the 32-bit value to write to the register +* +* @return None. +* +* @note C-style signature: +* void XWdtPs_WriteReg(u32 BaseAddress, u32 RegOffset, u32 Data) +* +*****************************************************************************/ +#define XWdtPs_WriteReg(BaseAddress, RegOffset, Data) \ + Xil_Out32((BaseAddress) + (RegOffset), (Data)) + + +/************************** Function Prototypes ******************************/ + + +/************************** Variable Definitions *****************************/ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/XilinxProcessorIPLib/drivers/wdtps/src/xwdtps_selftest.c b/XilinxProcessorIPLib/drivers/wdtps/src/xwdtps_selftest.c new file mode 100755 index 00000000..48d51266 --- /dev/null +++ b/XilinxProcessorIPLib/drivers/wdtps/src/xwdtps_selftest.c @@ -0,0 +1,165 @@ +/****************************************************************************** +* +* Copyright (C) 2010 - 2014 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 xwdtps_selftest.c +* +* Contains diagnostic self-test functions for the XWdtPs driver. +* +*
+* MODIFICATION HISTORY: +* +* Ver Who Date Changes +* ----- ------ -------- -------------------------------------------- +* 1.00a ecm/jz 01/15/10 First release +* 1.02a sg 08/01/12 Modified it use the Reset Length mask for the self +* test for CR 658287 +*+* +******************************************************************************/ + +/***************************** Include Files *********************************/ + +#include "xil_types.h" +#include "xil_assert.h" +#include "xwdtps.h" + +/************************** Constant Definitions *****************************/ + + +/**************************** Type Definitions *******************************/ + + +/***************** Macros (Inline Functions) Definitions *********************/ + + +/************************** Function Prototypes ******************************/ + + +/************************** Variable Definitions *****************************/ + + +/****************************************************************************/ +/** +* +* Run a self-test on the timebase. This test verifies that the register access +* locking functions. This is tested by trying to alter a register without +* setting the key value and verifying that the register contents did not +* change. +* +* @param InstancePtr is a pointer to the XWdtPs instance. +* +* @return +* - XST_SUCCESS if self-test was successful. +* - XST_FAILURE if self-test was not successful. +* +* @note None. +* +******************************************************************************/ +int XWdtPs_SelfTest(XWdtPs *InstancePtr) +{ + u32 ZmrOrig; + u32 ZmrValue1; + u32 ZmrValue2; + + /* + * Assert to ensure the inputs are valid and the instance has been + * initialized. + */ + Xil_AssertNonvoid(InstancePtr != NULL); + Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY); + + /* + * Read the ZMR register at start the test. + */ + ZmrOrig = XWdtPs_ReadReg(InstancePtr->Config.BaseAddress, + XWDTPS_ZMR_OFFSET); + + /* + * EX-OR in the length of the interrupt pulse, + * do not set the key value. + */ + ZmrValue1 = ZmrOrig ^ XWDTPS_ZMR_RSTLN_MASK; + + + /* + * Try to write to register w/o key value then read back. + */ + XWdtPs_WriteReg(InstancePtr->Config.BaseAddress, XWDTPS_ZMR_OFFSET, + ZmrValue1); + + ZmrValue2 = XWdtPs_ReadReg(InstancePtr->Config.BaseAddress, + XWDTPS_ZMR_OFFSET); + + if (ZmrValue1 == ZmrValue2) { + /* + * If the values match, the hw failed the test, + * return orig register value. + */ + XWdtPs_WriteReg(InstancePtr->Config.BaseAddress, + XWDTPS_ZMR_OFFSET, + (ZmrOrig | XWDTPS_ZMR_ZKEY_VAL)); + return XST_FAILURE; + } + + + /* + * Try to write to register with key value then read back. + */ + XWdtPs_WriteReg(InstancePtr->Config.BaseAddress, XWDTPS_ZMR_OFFSET, + (ZmrValue1 | XWDTPS_ZMR_ZKEY_VAL)); + + ZmrValue2 = XWdtPs_ReadReg(InstancePtr->Config.BaseAddress, + XWDTPS_ZMR_OFFSET); + + if (ZmrValue1 != ZmrValue2) { + /* + * If the values do not match, the hw failed the test, + * return orig register value. + */ + XWdtPs_WriteReg(InstancePtr->Config.BaseAddress, + XWDTPS_ZMR_OFFSET, + ZmrOrig | XWDTPS_ZMR_ZKEY_VAL); + return XST_FAILURE; + + } + + /* + * The hardware locking feature is functional, return the original value + * and return success. + */ + XWdtPs_WriteReg(InstancePtr->Config.BaseAddress, XWDTPS_ZMR_OFFSET, + ZmrOrig | XWDTPS_ZMR_ZKEY_VAL); + + return XST_SUCCESS; +} diff --git a/XilinxProcessorIPLib/drivers/wdtps/src/xwdtps_sinit.c b/XilinxProcessorIPLib/drivers/wdtps/src/xwdtps_sinit.c new file mode 100755 index 00000000..f92bb662 --- /dev/null +++ b/XilinxProcessorIPLib/drivers/wdtps/src/xwdtps_sinit.c @@ -0,0 +1,92 @@ +/****************************************************************************** +* +* Copyright (C) 2010 - 2014 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 xwdtps_sinit.c +* +* This file contains method for static initialization (compile-time) of the +* driver. +* +*
+* MODIFICATION HISTORY: +* +* Ver Who Date Changes +* ----- ------ -------- ---------------------------------------------- +* 1.00a ecm/jz 01/15/10 First release +*+* +******************************************************************************/ + +/***************************** Include Files *********************************/ + +#include "xparameters.h" +#include "xwdtps.h" + +/************************** Constant Definitions *****************************/ + +/**************************** Type Definitions *******************************/ + + +/***************** Macros (Inline Functions) Definitions *********************/ + + +/************************** Function Prototypes ******************************/ + +/*****************************************************************************/ +/** +* Lookup the device configuration based on the unique device ID. The table +* contains the configuration info 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. +* +******************************************************************************/ +XWdtPs_Config *XWdtPs_LookupConfig(u16 DeviceId) +{ + extern XWdtPs_Config XWdtPs_ConfigTable[]; + XWdtPs_Config *CfgPtr = NULL; + int Index; + + for (Index = 0; Index < XPAR_XWDTPS_NUM_INSTANCES; Index++) { + if (XWdtPs_ConfigTable[Index].DeviceId == DeviceId) { + CfgPtr = &XWdtPs_ConfigTable[Index]; + break; + } + } + + return (CfgPtr); +}