support zynq7000-zc702
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
SRC_DIR:= arm/armv7-a/cortex-a9/imx6q-sabrelite
|
||||
SRC_DIR:= arm/armv7-a/cortex-a9/$(BOARD)
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
@@ -63,11 +63,17 @@ static void _clear_clock_intr()
|
||||
gpt_get_compare_event(kGPTOutputCompare1);
|
||||
}
|
||||
|
||||
static struct XiziClockDriver hardkernel_clock_driver = (struct XiziClockDriver) {
|
||||
static bool _is_timer_expired()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
static struct XiziClockDriver hardkernel_clock_driver = {
|
||||
.sys_clock_init = _sys_clock_init,
|
||||
.get_clock_int = _get_clock_int,
|
||||
.get_tick = _get_tick,
|
||||
.get_second = _get_second,
|
||||
.is_timer_expired = _is_timer_expired,
|
||||
.clear_clock_intr = _clear_clock_intr,
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
SRC_FILES := clock.c \
|
||||
xscutimer_g.c \
|
||||
xscutimer_sinit.c \
|
||||
xscutimer.c \
|
||||
xscutimer_selftest.c
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
/**
|
||||
* @file clock.c
|
||||
* @brief clock interfaces of hardkernel
|
||||
* @version 3.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2023.08.25
|
||||
*/
|
||||
/*************************************************
|
||||
File name: clock.c
|
||||
Description: clock interfaces of hardkernel
|
||||
Others:
|
||||
History:
|
||||
1. Date: 2023-08-28
|
||||
Author: AIIT XUOS Lab
|
||||
Modification:
|
||||
1. first version
|
||||
*************************************************/
|
||||
#include <stdint.h>
|
||||
|
||||
#include "xparameters.h"
|
||||
#include "xscutimer.h"
|
||||
|
||||
#include "clock_common_op.h"
|
||||
#include "log.h"
|
||||
|
||||
XScuTimer global_timer;
|
||||
#define TIMER_LOAD_VALUE 0x32CFD0 // 10ms
|
||||
|
||||
static void _sys_clock_init()
|
||||
{
|
||||
XScuTimer_Config* timer_cfg = XScuTimer_LookupConfig(XPAR_PS7_SCUTIMER_0_DEVICE_ID);
|
||||
if (XScuTimer_CfgInitialize(&global_timer, timer_cfg, timer_cfg->BaseAddr) != XST_SUCCESS || XScuTimer_SelfTest(&global_timer) != XST_SUCCESS) {
|
||||
ERROR("Error initializing timer\n");
|
||||
return;
|
||||
}
|
||||
XScuTimer_EnableInterrupt(&global_timer);
|
||||
XScuTimer_EnableAutoReload(&global_timer);
|
||||
XScuTimer_LoadTimer(&global_timer, TIMER_LOAD_VALUE);
|
||||
XScuTimer_Start(&global_timer);
|
||||
}
|
||||
|
||||
static uint32_t _get_clock_int()
|
||||
{
|
||||
return XPAR_PS7_SCUTIMER_0_INTR;
|
||||
}
|
||||
|
||||
static uint64_t _get_tick()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static uint64_t _get_second()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static bool _is_timer_expired()
|
||||
{
|
||||
return XScuTimer_IsExpired(&global_timer);
|
||||
}
|
||||
|
||||
static void _clear_clock_intr()
|
||||
{
|
||||
XScuTimer_ClearInterruptStatus(&global_timer);
|
||||
}
|
||||
|
||||
static struct XiziClockDriver hardkernel_clock_driver = {
|
||||
.sys_clock_init = _sys_clock_init,
|
||||
.get_clock_int = _get_clock_int,
|
||||
.get_tick = _get_tick,
|
||||
.get_second = _get_second,
|
||||
.is_timer_expired = _is_timer_expired,
|
||||
.clear_clock_intr = _clear_clock_intr,
|
||||
};
|
||||
|
||||
struct XiziClockDriver* hardkernel_clock_init(struct TraceTag* hardkernel_tag)
|
||||
{
|
||||
hardkernel_clock_driver.sys_clock_init();
|
||||
return &hardkernel_clock_driver;
|
||||
}
|
||||
@@ -0,0 +1,366 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright (C) 2010 - 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
|
||||
* XILINX 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 xscutimer.h
|
||||
* @addtogroup scutimer_v2_1
|
||||
* @{
|
||||
* @details
|
||||
*
|
||||
* The timer driver supports the Cortex A9 private timer.
|
||||
*
|
||||
* The timer driver supports the following features:
|
||||
* - Normal mode and Auto reload mode
|
||||
* - Interrupts (Interrupt handler is not provided in this driver. Application
|
||||
* has to register it's own handler)
|
||||
*
|
||||
* <b> Initialization and Configuration </b>
|
||||
*
|
||||
* The device driver enables higher layer software (e.g., an application) to
|
||||
* communicate with the Timer.
|
||||
*
|
||||
* XScuTimer_CfgInitialize() API is used to initialize the Timer. The
|
||||
* user needs to first call the XScuTimer_LookupConfig() API which returns
|
||||
* the Configuration structure pointer which is passed as a parameter to
|
||||
* the XScuTimer_CfgInitialize() API.
|
||||
*
|
||||
* <b> Interrupts </b>
|
||||
*
|
||||
* The Timer hardware supports interrupts.
|
||||
*
|
||||
* This driver does not provide a Interrupt Service Routine (ISR) for the device.
|
||||
* It is the responsibility of the application to provide one if needed. Refer to
|
||||
* the interrupt example provided with this driver for details on using the
|
||||
* Timer in interrupt mode.
|
||||
*
|
||||
* <b> Virtual Memory </b>
|
||||
*
|
||||
* This driver supports Virtual Memory. The RTOS is responsible for calculating
|
||||
* the correct device base address in Virtual Memory space.
|
||||
*
|
||||
* <b> Threads </b>
|
||||
*
|
||||
* This driver is not thread safe. Any needs for threads or thread mutual
|
||||
* exclusion must be satisfied by the layer above this driver.
|
||||
*
|
||||
* <b> Asserts </b>
|
||||
*
|
||||
* Asserts are used within all Xilinx drivers to enforce constraints on argument
|
||||
* values. Asserts can be turned off on a system-wide basis by defining, at
|
||||
* compile time, the NDEBUG identifier. By default, asserts are turned on and it
|
||||
* is recommended that users leave asserts on during development.
|
||||
*
|
||||
* <b> Building the driver </b>
|
||||
*
|
||||
* The XScuTimer driver is composed of several source files. This allows the user
|
||||
* to build and link only those parts of the driver that are necessary.
|
||||
*
|
||||
* <br><br>
|
||||
*
|
||||
* NOTE:
|
||||
* The timer is not a part of the snoop control unit as indicated by the
|
||||
* prefix "scu" in the name of the driver.
|
||||
* It is an independent module in APU.
|
||||
*
|
||||
* <pre>
|
||||
* MODIFICATION HISTORY:
|
||||
*
|
||||
* Ver Who Date Changes
|
||||
* ----- --- -------- ---------------------------------------------
|
||||
* 1.00a nm 03/10/10 First release
|
||||
* 1.02a sg 07/17/12 Included xil_assert.h for CR 667947. This is an issue
|
||||
* when the xstatus.h in the common driver overwrites
|
||||
* the xstatus.h of the standalone BSP during the
|
||||
* libgen.
|
||||
* 2.1 sk 02/26/15 Modified the code for MISRA-C:2012 compliance.
|
||||
* </pre>
|
||||
*
|
||||
******************************************************************************/
|
||||
#ifndef XSCUTIMER_H /* prevent circular inclusions */
|
||||
#define XSCUTIMER_H /* by using protection macros */
|
||||
|
||||
/***************************** Include Files *********************************/
|
||||
|
||||
#include "xstatus.h"
|
||||
#include "xscutimer_hw.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/************************** Constant Definitions *****************************/
|
||||
|
||||
/**************************** Type Definitions *******************************/
|
||||
|
||||
/**
|
||||
* This typedef contains configuration information for the device.
|
||||
*/
|
||||
typedef struct {
|
||||
u16 DeviceId; /**< Unique ID of device */
|
||||
u32 BaseAddr; /**< Base address of the device */
|
||||
} XScuTimer_Config;
|
||||
|
||||
/**
|
||||
* The XScuTimer driver instance data. The user is required to allocate a
|
||||
* variable of this type for every timer device in the system.
|
||||
* A pointer to a variable of this type is then passed to the driver API
|
||||
* functions.
|
||||
*/
|
||||
typedef struct {
|
||||
XScuTimer_Config Config; /**< Hardware Configuration */
|
||||
u32 IsReady; /**< Device is initialized and ready */
|
||||
u32 IsStarted; /**< Device timer is running */
|
||||
} XScuTimer;
|
||||
|
||||
/***************** Macros (Inline Functions) Definitions *********************/
|
||||
|
||||
/****************************************************************************/
|
||||
/**
|
||||
*
|
||||
* Check if the timer has expired.
|
||||
*
|
||||
* @param InstancePtr is a pointer to the XScuTimer instance.
|
||||
*
|
||||
* @return
|
||||
* - TRUE if the timer has expired.
|
||||
* - FALSE if the timer has not expired.
|
||||
*
|
||||
* @note C-style signature:
|
||||
* int XScuTimer_IsExpired(XScuTimer *InstancePtr)
|
||||
*
|
||||
******************************************************************************/
|
||||
#define XScuTimer_IsExpired(InstancePtr) \
|
||||
((XScuTimer_ReadReg((InstancePtr)->Config.BaseAddr, \
|
||||
XSCUTIMER_ISR_OFFSET) & \
|
||||
XSCUTIMER_ISR_EVENT_FLAG_MASK) == \
|
||||
XSCUTIMER_ISR_EVENT_FLAG_MASK)
|
||||
|
||||
/****************************************************************************/
|
||||
/**
|
||||
*
|
||||
* Re-start the timer. This macro will read the timer load register
|
||||
* and writes the same value to load register to update the counter register.
|
||||
*
|
||||
* @param InstancePtr is a pointer to the XScuTimer instance.
|
||||
*
|
||||
* @return None.
|
||||
*
|
||||
* @note C-style signature:
|
||||
* void XScuTimer_RestartTimer(XScuTimer *InstancePtr)
|
||||
*
|
||||
******************************************************************************/
|
||||
#define XScuTimer_RestartTimer(InstancePtr) \
|
||||
XScuTimer_LoadTimer((InstancePtr), \
|
||||
XScuTimer_ReadReg((InstancePtr)->Config.BaseAddr, \
|
||||
XSCUTIMER_LOAD_OFFSET))
|
||||
|
||||
/****************************************************************************/
|
||||
/**
|
||||
*
|
||||
* Write to the timer load register. This will also update the
|
||||
* timer counter register with the new value. This macro can be used to
|
||||
* change the time-out value.
|
||||
*
|
||||
* @param InstancePtr is a pointer to the XScuTimer instance.
|
||||
* @param Value is the count to be loaded in to the load register.
|
||||
*
|
||||
* @return None.
|
||||
*
|
||||
* @note C-style signature:
|
||||
* void XScuTimer_LoadTimer(XScuTimer *InstancePtr, u32 Value)
|
||||
*
|
||||
******************************************************************************/
|
||||
#define XScuTimer_LoadTimer(InstancePtr, Value) \
|
||||
XScuTimer_WriteReg((InstancePtr)->Config.BaseAddr, \
|
||||
XSCUTIMER_LOAD_OFFSET, (Value))
|
||||
|
||||
/****************************************************************************/
|
||||
/**
|
||||
*
|
||||
* Returns the current timer counter register value. It can be called at any
|
||||
* time.
|
||||
*
|
||||
* @param InstancePtr is a pointer to the XScuTimer instance.
|
||||
*
|
||||
* @return Contents of the timer counter register.
|
||||
*
|
||||
* @note C-style signature:
|
||||
u32 XScuTimer_GetCounterValue(XScuTimer *InstancePtr)
|
||||
*
|
||||
******************************************************************************/
|
||||
#define XScuTimer_GetCounterValue(InstancePtr) \
|
||||
XScuTimer_ReadReg((InstancePtr)->Config.BaseAddr, \
|
||||
XSCUTIMER_COUNTER_OFFSET)
|
||||
|
||||
/****************************************************************************/
|
||||
/**
|
||||
*
|
||||
* Enable auto-reload mode.
|
||||
*
|
||||
* @param InstancePtr is a pointer to the XScuTimer instance.
|
||||
*
|
||||
* @return None.
|
||||
*
|
||||
* @note C-style signature:
|
||||
* void XScuTimer_EnableAutoReload(XScuTimer *InstancePtr)
|
||||
*
|
||||
******************************************************************************/
|
||||
#define XScuTimer_EnableAutoReload(InstancePtr) \
|
||||
XScuTimer_WriteReg((InstancePtr)->Config.BaseAddr, \
|
||||
XSCUTIMER_CONTROL_OFFSET, \
|
||||
(XScuTimer_ReadReg((InstancePtr)->Config.BaseAddr, \
|
||||
XSCUTIMER_CONTROL_OFFSET) | \
|
||||
XSCUTIMER_CONTROL_AUTO_RELOAD_MASK))
|
||||
|
||||
/****************************************************************************/
|
||||
/**
|
||||
*
|
||||
* Disable auto-reload mode.
|
||||
*
|
||||
* @param InstancePtr is a pointer to the XScuTimer instance.
|
||||
*
|
||||
* @return None.
|
||||
*
|
||||
* @note C-style signature:
|
||||
* void XScuTimer_DisableAutoReload(XScuTimer *InstancePtr)
|
||||
*
|
||||
******************************************************************************/
|
||||
#define XScuTimer_DisableAutoReload(InstancePtr) \
|
||||
XScuTimer_WriteReg((InstancePtr)->Config.BaseAddr, \
|
||||
XSCUTIMER_CONTROL_OFFSET, \
|
||||
(XScuTimer_ReadReg((InstancePtr)->Config.BaseAddr, \
|
||||
XSCUTIMER_CONTROL_OFFSET) & \
|
||||
~(XSCUTIMER_CONTROL_AUTO_RELOAD_MASK)))
|
||||
|
||||
/****************************************************************************/
|
||||
/**
|
||||
*
|
||||
* Enable the Timer interrupt.
|
||||
*
|
||||
* @param InstancePtr is a pointer to the XScuTimer instance.
|
||||
*
|
||||
* @return None.
|
||||
*
|
||||
* @note C-style signature:
|
||||
* void XScuTimer_EnableInterrupt(XScuTimer *InstancePtr)
|
||||
*
|
||||
******************************************************************************/
|
||||
#define XScuTimer_EnableInterrupt(InstancePtr) \
|
||||
XScuTimer_WriteReg((InstancePtr)->Config.BaseAddr, \
|
||||
XSCUTIMER_CONTROL_OFFSET, \
|
||||
(XScuTimer_ReadReg((InstancePtr)->Config.BaseAddr, \
|
||||
XSCUTIMER_CONTROL_OFFSET) | \
|
||||
XSCUTIMER_CONTROL_IRQ_ENABLE_MASK))
|
||||
|
||||
/****************************************************************************/
|
||||
/**
|
||||
*
|
||||
* Disable the Timer interrupt.
|
||||
*
|
||||
* @param InstancePtr is a pointer to the XScuTimer instance.
|
||||
*
|
||||
* @return None.
|
||||
*
|
||||
* @note C-style signature:
|
||||
* void XScuTimer_DisableInterrupt(XScuTimer *InstancePtr)
|
||||
*
|
||||
******************************************************************************/
|
||||
#define XScuTimer_DisableInterrupt(InstancePtr) \
|
||||
XScuTimer_WriteReg((InstancePtr)->Config.BaseAddr, \
|
||||
XSCUTIMER_CONTROL_OFFSET, \
|
||||
(XScuTimer_ReadReg((InstancePtr)->Config.BaseAddr, \
|
||||
XSCUTIMER_CONTROL_OFFSET) & \
|
||||
~(XSCUTIMER_CONTROL_IRQ_ENABLE_MASK)))
|
||||
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
*
|
||||
* This function reads the interrupt status.
|
||||
*
|
||||
* @param InstancePtr is a pointer to the XScuTimer instance.
|
||||
*
|
||||
* @return None.
|
||||
*
|
||||
* @note C-style signature:
|
||||
* void XScuTimer_GetInterruptStatus(XScuTimer *InstancePtr)
|
||||
*
|
||||
******************************************************************************/
|
||||
#define XScuTimer_GetInterruptStatus(InstancePtr) \
|
||||
XScuTimer_ReadReg((InstancePtr)->Config.BaseAddr, \
|
||||
XSCUTIMER_ISR_OFFSET)
|
||||
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
*
|
||||
* This function clears the interrupt status.
|
||||
*
|
||||
* @param InstancePtr is a pointer to the XScuTimer instance.
|
||||
*
|
||||
* @return None.
|
||||
*
|
||||
* @note C-style signature:
|
||||
* void XScuTimer_ClearInterruptStatus(XScuTimer *InstancePtr)
|
||||
*
|
||||
******************************************************************************/
|
||||
#define XScuTimer_ClearInterruptStatus(InstancePtr) \
|
||||
XScuTimer_WriteReg((InstancePtr)->Config.BaseAddr, \
|
||||
XSCUTIMER_ISR_OFFSET, XSCUTIMER_ISR_EVENT_FLAG_MASK)
|
||||
|
||||
/************************** Function Prototypes ******************************/
|
||||
|
||||
/*
|
||||
* Lookup configuration in xscutimer_sinit.c
|
||||
*/
|
||||
XScuTimer_Config *XScuTimer_LookupConfig(u16 DeviceId);
|
||||
|
||||
/*
|
||||
* Selftest function in xscutimer_selftest.c
|
||||
*/
|
||||
s32 XScuTimer_SelfTest(XScuTimer *InstancePtr);
|
||||
|
||||
/*
|
||||
* Interface functions in xscutimer.c
|
||||
*/
|
||||
s32 XScuTimer_CfgInitialize(XScuTimer *InstancePtr,
|
||||
XScuTimer_Config *ConfigPtr, u32 EffectiveAddress);
|
||||
void XScuTimer_Start(XScuTimer *InstancePtr);
|
||||
void XScuTimer_Stop(XScuTimer *InstancePtr);
|
||||
void XScuTimer_SetPrescaler(XScuTimer *InstancePtr, u8 PrescalerValue);
|
||||
u8 XScuTimer_GetPrescaler(XScuTimer *InstancePtr);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* end of protection macro */
|
||||
/** @} */
|
||||
@@ -0,0 +1,287 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright (C) 2010 - 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
|
||||
* XILINX 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 xscutimer_hw.h
|
||||
* @addtogroup scutimer_v2_1
|
||||
* @{
|
||||
*
|
||||
* This file contains the hardware interface to the Timer.
|
||||
*
|
||||
* <pre>
|
||||
* MODIFICATION HISTORY:
|
||||
*
|
||||
* Ver Who Date Changes
|
||||
* ----- --- -------- ---------------------------------------------
|
||||
* 1.00a nm 03/10/10 First release
|
||||
* 1.01a sdm 02/02/12 Added low level macros to read/write load, counter, control
|
||||
* and interrupt registers
|
||||
* 1.02a sg 07/17/12 Included xil_assert.h for CR 667947. This is an issue
|
||||
* when the xstatus.h in the common driver overwrites
|
||||
* the xstatus.h of the standalone BSP during the
|
||||
* libgen.
|
||||
* 2.1 sk 02/26/15 Modified the code for MISRA-C:2012 compliance.
|
||||
* </pre>
|
||||
*
|
||||
******************************************************************************/
|
||||
#ifndef XSCUTIMER_HW_H /* prevent circular inclusions */
|
||||
#define XSCUTIMER_HW_H /* by using protection macros */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/***************************** Include Files *********************************/
|
||||
#include "xil_types.h"
|
||||
#include "xil_io.h"
|
||||
#include "xil_assert.h"
|
||||
/************************** Constant Definitions *****************************/
|
||||
|
||||
/** @name Register Map
|
||||
* Offsets of registers from the start of the device
|
||||
* @{
|
||||
*/
|
||||
|
||||
#define XSCUTIMER_LOAD_OFFSET 0x00U /**< Timer Load Register */
|
||||
#define XSCUTIMER_COUNTER_OFFSET 0x04U /**< Timer Counter Register */
|
||||
#define XSCUTIMER_CONTROL_OFFSET 0x08U /**< Timer Control Register */
|
||||
#define XSCUTIMER_ISR_OFFSET 0x0CU /**< Timer Interrupt
|
||||
Status Register */
|
||||
/* @} */
|
||||
|
||||
/** @name Timer Control register
|
||||
* This register bits control the prescaler, Intr enable,
|
||||
* auto-reload and timer enable.
|
||||
* @{
|
||||
*/
|
||||
|
||||
#define XSCUTIMER_CONTROL_PRESCALER_MASK 0x0000FF00U /**< Prescaler */
|
||||
#define XSCUTIMER_CONTROL_PRESCALER_SHIFT 8U
|
||||
#define XSCUTIMER_CONTROL_IRQ_ENABLE_MASK 0x00000004U /**< Intr enable */
|
||||
#define XSCUTIMER_CONTROL_AUTO_RELOAD_MASK 0x00000002U /**< Auto-reload */
|
||||
#define XSCUTIMER_CONTROL_ENABLE_MASK 0x00000001U /**< Timer enable */
|
||||
/* @} */
|
||||
|
||||
/** @name Interrupt Status register
|
||||
* This register indicates the Timer counter register has reached zero.
|
||||
* @{
|
||||
*/
|
||||
|
||||
#define XSCUTIMER_ISR_EVENT_FLAG_MASK 0x00000001U /**< Event flag */
|
||||
/*@}*/
|
||||
|
||||
/**************************** Type Definitions *******************************/
|
||||
|
||||
/***************** Macros (Inline Functions) Definitions *********************/
|
||||
|
||||
/****************************************************************************/
|
||||
/**
|
||||
*
|
||||
* Write to the timer load register. This will also update the
|
||||
* timer counter register with the new value. This macro can be used to
|
||||
* change the time-out value.
|
||||
*
|
||||
* @param BaseAddr is the base address of the scu timer.
|
||||
* @param Value is the count to be loaded in to the load register.
|
||||
*
|
||||
* @return None.
|
||||
*
|
||||
* @note C-style signature:
|
||||
* void XScuTimer_SetLoadReg(u32 BaseAddr, u32 Value)
|
||||
*
|
||||
******************************************************************************/
|
||||
#define XScuTimer_SetLoadReg(BaseAddr, Value) \
|
||||
XScuTimer_WriteReg(BaseAddr, XSCUTIMER_LOAD_OFFSET, (Value))
|
||||
|
||||
/****************************************************************************/
|
||||
/**
|
||||
*
|
||||
* Returns the current timer load register value.
|
||||
*
|
||||
* @param BaseAddr is the base address of the scu timer.
|
||||
*
|
||||
* @return Contents of the timer load register.
|
||||
*
|
||||
* @note C-style signature:
|
||||
* u32 XScuTimer_GetLoadReg(u32 BaseAddr)
|
||||
*
|
||||
******************************************************************************/
|
||||
#define XScuTimer_GetLoadReg(BaseAddr) \
|
||||
XScuTimer_ReadReg(BaseAddr, XSCUTIMER_LOAD_OFFSET)
|
||||
|
||||
/****************************************************************************/
|
||||
/**
|
||||
*
|
||||
* Write to the timer counter register.
|
||||
*
|
||||
* @param BaseAddr is the base address of the scu timer.
|
||||
* @param Value is the count to be loaded in to the counter register.
|
||||
*
|
||||
* @return None.
|
||||
*
|
||||
* @note C-style signature:
|
||||
* void XScuTimer_SetCounterReg(u32 BaseAddr, u32 Value)
|
||||
*
|
||||
******************************************************************************/
|
||||
#define XScuTimer_SetCounterReg(BaseAddr, Value) \
|
||||
XScuTimer_WriteReg(BaseAddr, XSCUTIMER_COUNTER_OFFSET, (Value))
|
||||
|
||||
/****************************************************************************/
|
||||
/**
|
||||
*
|
||||
* Returns the current timer counter register value.
|
||||
*
|
||||
* @param BaseAddr is the base address of the scu timer.
|
||||
*
|
||||
* @return Contents of the timer counter register.
|
||||
*
|
||||
* @note C-style signature:
|
||||
u32 XScuTimer_GetCounterReg(u32 BaseAddr)
|
||||
*
|
||||
******************************************************************************/
|
||||
#define XScuTimer_GetCounterReg(BaseAddr) \
|
||||
XScuTimer_ReadReg(BaseAddr, XSCUTIMER_COUNTER_OFFSET)
|
||||
|
||||
/****************************************************************************/
|
||||
/**
|
||||
*
|
||||
* Write to the timer load register. This will also update the
|
||||
* timer counter register with the new value. This macro can be used to
|
||||
* change the time-out value.
|
||||
*
|
||||
* @param BaseAddr is the base address of the scu timer.
|
||||
* @param Value is the count to be loaded in to the load register.
|
||||
*
|
||||
* @return None.
|
||||
*
|
||||
* @note C-style signature:
|
||||
* void XScuTimer_SetControlReg(u32 BaseAddr, u32 Value)
|
||||
*
|
||||
******************************************************************************/
|
||||
#define XScuTimer_SetControlReg(BaseAddr, Value) \
|
||||
XScuTimer_WriteReg(BaseAddr, XSCUTIMER_CONTROL_OFFSET, (Value))
|
||||
|
||||
/****************************************************************************/
|
||||
/**
|
||||
*
|
||||
* Returns the current timer load register value.
|
||||
*
|
||||
* @param BaseAddr is the base address of the scu timer.
|
||||
*
|
||||
* @return Contents of the timer load register.
|
||||
*
|
||||
* @note C-style signature:
|
||||
u32 XScuTimer_GetControlReg(u32 BaseAddr)
|
||||
*
|
||||
******************************************************************************/
|
||||
#define XScuTimer_GetControlReg(BaseAddr) \
|
||||
XScuTimer_ReadReg(BaseAddr, XSCUTIMER_CONTROL_OFFSET)
|
||||
|
||||
/****************************************************************************/
|
||||
/**
|
||||
*
|
||||
* Write to the timer counter register.
|
||||
*
|
||||
* @param BaseAddr is the base address of the scu timer.
|
||||
* @param Value is the count to be loaded in to the counter register.
|
||||
*
|
||||
* @return None.
|
||||
*
|
||||
* @note C-style signature:
|
||||
* void XScuTimer_SetIntrReg(u32 BaseAddr, u32 Value)
|
||||
*
|
||||
******************************************************************************/
|
||||
#define XScuTimer_SetIntrReg(BaseAddr, Value) \
|
||||
XScuTimer_WriteReg(BaseAddr, XSCUTIMER_ISR_OFFSET, (Value))
|
||||
|
||||
/****************************************************************************/
|
||||
/**
|
||||
*
|
||||
* Returns the current timer counter register value.
|
||||
*
|
||||
* @param BaseAddr is the base address of the scu timer.
|
||||
*
|
||||
* @return Contents of the timer counter register.
|
||||
*
|
||||
* @note C-style signature:
|
||||
u32 XScuTimer_GetIntrReg(u32 BaseAddr)
|
||||
*
|
||||
******************************************************************************/
|
||||
#define XScuTimer_GetIntrReg(BaseAddr) \
|
||||
XScuTimer_ReadReg(BaseAddr, XSCUTIMER_ISR_OFFSET)
|
||||
|
||||
/****************************************************************************/
|
||||
/**
|
||||
*
|
||||
* Read from the given Timer register.
|
||||
*
|
||||
* @param BaseAddr 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 XScuTimer_ReadReg(u32 BaseAddr, u32 RegOffset)
|
||||
*
|
||||
*****************************************************************************/
|
||||
#define XScuTimer_ReadReg(BaseAddr, RegOffset) \
|
||||
Xil_In32((BaseAddr) + (RegOffset))
|
||||
|
||||
/****************************************************************************/
|
||||
/**
|
||||
*
|
||||
* Write to the given Timer register.
|
||||
*
|
||||
* @param BaseAddr 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 XScuTimer_WriteReg(u32 BaseAddr, u32 RegOffset, u32 Data)
|
||||
*
|
||||
*****************************************************************************/
|
||||
#define XScuTimer_WriteReg(BaseAddr, RegOffset, Data) \
|
||||
Xil_Out32((BaseAddr) + (RegOffset), (Data))
|
||||
|
||||
/************************** Function Prototypes ******************************/
|
||||
|
||||
/************************** Variable Definitions *****************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* end of protection macro */
|
||||
/** @} */
|
||||
@@ -0,0 +1,89 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright (C) 2009 - 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
|
||||
* XILINX 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 xtime_l.h
|
||||
*
|
||||
* <pre>
|
||||
* MODIFICATION HISTORY:
|
||||
*
|
||||
* Ver Who Date Changes
|
||||
* ----- ------ -------- ---------------------------------------------------
|
||||
* 1.00a rp/sdm 11/03/09 Initial release.
|
||||
* 3.06a sgd 05/15/12 Upadted get/set time functions to make use Global Timer
|
||||
* 3.06a asa 06/17/12 Reverted back the changes to make use Global Timer.
|
||||
* 3.07a sgd 07/05/12 Upadted get/set time functions to make use Global Timer
|
||||
* </pre>
|
||||
*
|
||||
* @note None.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef XTIME_H /* prevent circular inclusions */
|
||||
#define XTIME_H /* by using protection macros */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/***************************** Include Files *********************************/
|
||||
|
||||
#include "xil_types.h"
|
||||
#include "xparameters.h"
|
||||
|
||||
/***************** Macros (Inline Functions) Definitions *********************/
|
||||
|
||||
/**************************** Type Definitions *******************************/
|
||||
|
||||
typedef u64 XTime;
|
||||
|
||||
/************************** Constant Definitions *****************************/
|
||||
#define GLOBAL_TMR_BASEADDR XPAR_GLOBAL_TMR_BASEADDR
|
||||
#define GTIMER_COUNTER_LOWER_OFFSET 0x00U
|
||||
#define GTIMER_COUNTER_UPPER_OFFSET 0x04U
|
||||
#define GTIMER_CONTROL_OFFSET 0x08U
|
||||
|
||||
|
||||
/* Global Timer is always clocked at half of the CPU frequency */
|
||||
#define COUNTS_PER_SECOND (XPAR_CPU_CORTEXA9_CORE_CLOCK_FREQ_HZ /2)
|
||||
/************************** Variable Definitions *****************************/
|
||||
|
||||
/************************** Function Prototypes ******************************/
|
||||
|
||||
void XTime_SetTime(XTime Xtime_Global);
|
||||
void XTime_GetTime(XTime *Xtime_Global);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* XTIME_H */
|
||||
@@ -0,0 +1,286 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright (C) 2010 - 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
|
||||
* XILINX 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 xscutimer.c
|
||||
* @addtogroup scutimer_v2_1
|
||||
* @{
|
||||
*
|
||||
* Contains the implementation of interface functions of the SCU Timer driver.
|
||||
* See xscutimer.h for a description of the driver.
|
||||
*
|
||||
* <pre>
|
||||
* MODIFICATION HISTORY:
|
||||
*
|
||||
* Ver Who Date Changes
|
||||
* ----- --- -------- ---------------------------------------------
|
||||
* 1.00a nm 03/10/10 First release
|
||||
* 2.1 sk 02/26/15 Modified the code for MISRA-C:2012 compliance.
|
||||
* </pre>
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/***************************** Include Files *********************************/
|
||||
|
||||
#include "xscutimer.h"
|
||||
|
||||
/************************** Constant Definitions *****************************/
|
||||
|
||||
/**************************** Type Definitions *******************************/
|
||||
|
||||
/***************** Macros (Inline Functions) Definitions *********************/
|
||||
|
||||
/************************** Function Prototypes ******************************/
|
||||
|
||||
/************************** Variable Definitions *****************************/
|
||||
|
||||
/****************************************************************************/
|
||||
/**
|
||||
*
|
||||
* Initialize a specific timer instance/driver. This function must be called
|
||||
* before other functions of the driver are called.
|
||||
*
|
||||
* @param InstancePtr is a pointer to the XScuTimer instance.
|
||||
* @param ConfigPtr points to the XScuTimer configuration 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.
|
||||
*
|
||||
******************************************************************************/
|
||||
s32 XScuTimer_CfgInitialize(XScuTimer *InstancePtr,
|
||||
XScuTimer_Config *ConfigPtr, u32 EffectiveAddress)
|
||||
{
|
||||
s32 Status;
|
||||
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) {
|
||||
/*
|
||||
* Copy configuration into the instance structure.
|
||||
*/
|
||||
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.BaseAddr = EffectiveAddress;
|
||||
|
||||
InstancePtr->IsStarted = (u32)0;
|
||||
|
||||
/*
|
||||
* Indicate the instance is ready to use, successfully initialized.
|
||||
*/
|
||||
InstancePtr->IsReady = XIL_COMPONENT_IS_READY;
|
||||
|
||||
Status =(s32)XST_SUCCESS;
|
||||
}
|
||||
else {
|
||||
Status = (s32)XST_DEVICE_IS_STARTED;
|
||||
}
|
||||
return Status;
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
/**
|
||||
*
|
||||
* Start the timer.
|
||||
*
|
||||
* @param InstancePtr is a pointer to the XScuTimer instance.
|
||||
*
|
||||
* @return None.
|
||||
*
|
||||
* @note None.
|
||||
*
|
||||
******************************************************************************/
|
||||
void XScuTimer_Start(XScuTimer *InstancePtr)
|
||||
{
|
||||
u32 Register;
|
||||
|
||||
Xil_AssertVoid(InstancePtr != NULL);
|
||||
Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
|
||||
|
||||
/*
|
||||
* Read the contents of the Control register.
|
||||
*/
|
||||
Register = XScuTimer_ReadReg(InstancePtr->Config.BaseAddr,
|
||||
XSCUTIMER_CONTROL_OFFSET);
|
||||
|
||||
/*
|
||||
* Set the 'timer enable' bit in the register.
|
||||
*/
|
||||
Register |= XSCUTIMER_CONTROL_ENABLE_MASK;
|
||||
|
||||
/*
|
||||
* Update the Control register with the new value.
|
||||
*/
|
||||
XScuTimer_WriteReg(InstancePtr->Config.BaseAddr,
|
||||
XSCUTIMER_CONTROL_OFFSET, Register);
|
||||
|
||||
/*
|
||||
* Indicate that the device is started.
|
||||
*/
|
||||
InstancePtr->IsStarted = XIL_COMPONENT_IS_STARTED;
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
/**
|
||||
*
|
||||
* Stop the timer.
|
||||
*
|
||||
* @param InstancePtr is a pointer to the XScuTimer instance.
|
||||
*
|
||||
* @return None.
|
||||
*
|
||||
* @note None.
|
||||
*
|
||||
******************************************************************************/
|
||||
void XScuTimer_Stop(XScuTimer *InstancePtr)
|
||||
{
|
||||
u32 Register;
|
||||
|
||||
Xil_AssertVoid(InstancePtr != NULL);
|
||||
Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
|
||||
|
||||
/*
|
||||
* Read the contents of the Control register.
|
||||
*/
|
||||
Register = XScuTimer_ReadReg(InstancePtr->Config.BaseAddr,
|
||||
XSCUTIMER_CONTROL_OFFSET);
|
||||
|
||||
/*
|
||||
* Clear the 'timer enable' bit in the register.
|
||||
*/
|
||||
Register &= (u32)(~XSCUTIMER_CONTROL_ENABLE_MASK);
|
||||
|
||||
/*
|
||||
* Update the Control register with the new value.
|
||||
*/
|
||||
XScuTimer_WriteReg(InstancePtr->Config.BaseAddr,
|
||||
XSCUTIMER_CONTROL_OFFSET, Register);
|
||||
|
||||
/*
|
||||
* Indicate that the device is stopped.
|
||||
*/
|
||||
InstancePtr->IsStarted = (u32)0;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
*
|
||||
* This function sets the prescaler bits in the timer control register.
|
||||
*
|
||||
* @param InstancePtr is a pointer to the XScuTimer instance.
|
||||
* @param PrescalerValue is a 8 bit value that sets the prescaler to use.
|
||||
*
|
||||
* @return None
|
||||
*
|
||||
* @note None
|
||||
*
|
||||
****************************************************************************/
|
||||
void XScuTimer_SetPrescaler(XScuTimer *InstancePtr, u8 PrescalerValue)
|
||||
{
|
||||
u32 ControlReg;
|
||||
|
||||
/*
|
||||
* Assert to validate input arguments.
|
||||
*/
|
||||
Xil_AssertVoid(InstancePtr != NULL);
|
||||
Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
|
||||
/*
|
||||
* Read the Timer control register.
|
||||
*/
|
||||
ControlReg = XScuTimer_ReadReg(InstancePtr->Config.BaseAddr,
|
||||
XSCUTIMER_CONTROL_OFFSET);
|
||||
|
||||
/*
|
||||
* Clear all of the prescaler control bits in the register.
|
||||
*/
|
||||
ControlReg &= (u32)(~XSCUTIMER_CONTROL_PRESCALER_MASK);
|
||||
|
||||
/*
|
||||
* Set the prescaler value.
|
||||
*/
|
||||
ControlReg |= (((u32)PrescalerValue) << XSCUTIMER_CONTROL_PRESCALER_SHIFT);
|
||||
|
||||
/*
|
||||
* Write the register with the new values.
|
||||
*/
|
||||
XScuTimer_WriteReg(InstancePtr->Config.BaseAddr,
|
||||
XSCUTIMER_CONTROL_OFFSET, ControlReg);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
*
|
||||
* This function returns the current prescaler value.
|
||||
*
|
||||
* @param InstancePtr is a pointer to the XScuTimer instance.
|
||||
*
|
||||
* @return The prescaler value.
|
||||
*
|
||||
* @note None.
|
||||
*
|
||||
****************************************************************************/
|
||||
u8 XScuTimer_GetPrescaler(XScuTimer *InstancePtr)
|
||||
{
|
||||
u32 ControlReg;
|
||||
|
||||
/*
|
||||
* Assert to validate input arguments.
|
||||
*/
|
||||
Xil_AssertNonvoid(InstancePtr != NULL);
|
||||
Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
|
||||
|
||||
/*
|
||||
* Read the Timer control register.
|
||||
*/
|
||||
ControlReg = XScuTimer_ReadReg(InstancePtr->Config.BaseAddr,
|
||||
XSCUTIMER_CONTROL_OFFSET);
|
||||
ControlReg &= XSCUTIMER_CONTROL_PRESCALER_MASK;
|
||||
|
||||
return (u8)(ControlReg >> XSCUTIMER_CONTROL_PRESCALER_SHIFT);
|
||||
}
|
||||
/** @} */
|
||||
@@ -0,0 +1,52 @@
|
||||
|
||||
/*******************************************************************
|
||||
*
|
||||
* CAUTION: This file is automatically generated by HSI.
|
||||
* Version:
|
||||
* DO NOT EDIT.
|
||||
*
|
||||
* Copyright (C) 2010-2024 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
|
||||
*XILINX 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.
|
||||
*
|
||||
|
||||
*
|
||||
* Description: Driver configuration
|
||||
*
|
||||
*******************************************************************/
|
||||
|
||||
#include "xparameters.h"
|
||||
#include "xscutimer.h"
|
||||
|
||||
#include "mmio_access.h"
|
||||
|
||||
/*
|
||||
* The configuration table for devices
|
||||
*/
|
||||
|
||||
XScuTimer_Config XScuTimer_ConfigTable[] = {
|
||||
{ XPAR_PS7_SCUTIMER_0_DEVICE_ID,
|
||||
MMIO_P2V_WO(XPAR_PS7_SCUTIMER_0_BASEADDR) }
|
||||
};
|
||||
@@ -0,0 +1,139 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright (C) 2010 - 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
|
||||
* XILINX 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 xscutimer_selftest.c
|
||||
* @addtogroup scutimer_v2_1
|
||||
* @{
|
||||
*
|
||||
* Contains diagnostic self-test functions for the XScuTimer driver.
|
||||
*
|
||||
* <pre>
|
||||
* MODIFICATION HISTORY:
|
||||
*
|
||||
* Ver Who Date Changes
|
||||
* ----- --- -------- ---------------------------------------------
|
||||
* 1.00a nm 03/10/10 First release
|
||||
* 2.1 sk 02/26/15 Modified the code for MISRA-C:2012 compliance.
|
||||
* </pre>
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/***************************** Include Files *********************************/
|
||||
|
||||
#include "xscutimer.h"
|
||||
|
||||
/************************** Constant Definitions *****************************/
|
||||
|
||||
#define XSCUTIMER_SELFTEST_VALUE 0xA55AF00FU
|
||||
|
||||
/**************************** Type Definitions *******************************/
|
||||
|
||||
/***************** Macros (Inline Functions) Definitions *********************/
|
||||
|
||||
/************************** Function Prototypes ******************************/
|
||||
|
||||
/************************** Variable Definitions *****************************/
|
||||
|
||||
/****************************************************************************/
|
||||
/**
|
||||
*
|
||||
* Run a self-test on the timer. This test clears the timer enable bit in
|
||||
* the control register, writes to the timer load register and verifies the
|
||||
* value read back matches the value written and restores the control register
|
||||
* and the timer load register.
|
||||
*
|
||||
* @param InstancePtr is a pointer to the XScuTimer instance.
|
||||
*
|
||||
* @return
|
||||
* - XST_SUCCESS if self-test was successful.
|
||||
* - XST_FAILURE if self test was not successful.
|
||||
*
|
||||
* @note None.
|
||||
*
|
||||
******************************************************************************/
|
||||
s32 XScuTimer_SelfTest(XScuTimer *InstancePtr)
|
||||
{
|
||||
u32 Register;
|
||||
u32 CtrlOrig;
|
||||
u32 LoadOrig;
|
||||
s32 Status;
|
||||
|
||||
/*
|
||||
* 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);
|
||||
|
||||
/*
|
||||
* Save the contents of the Control Register and stop the timer.
|
||||
*/
|
||||
CtrlOrig = XScuTimer_ReadReg(InstancePtr->Config.BaseAddr,
|
||||
XSCUTIMER_CONTROL_OFFSET);
|
||||
Register = CtrlOrig & (u32)(~XSCUTIMER_CONTROL_ENABLE_MASK);
|
||||
XScuTimer_WriteReg(InstancePtr->Config.BaseAddr,
|
||||
XSCUTIMER_CONTROL_OFFSET, Register);
|
||||
|
||||
/*
|
||||
* Save the contents of the Load Register.
|
||||
* Load a new test value in the Load Register, read it back and
|
||||
* compare it with the written value.
|
||||
*/
|
||||
LoadOrig = XScuTimer_ReadReg((InstancePtr)->Config.BaseAddr,
|
||||
XSCUTIMER_LOAD_OFFSET);
|
||||
XScuTimer_LoadTimer(InstancePtr, XSCUTIMER_SELFTEST_VALUE);
|
||||
Register = XScuTimer_ReadReg((InstancePtr)->Config.BaseAddr,
|
||||
XSCUTIMER_LOAD_OFFSET);
|
||||
|
||||
/*
|
||||
* Restore the contents of the Load Register and Control Register.
|
||||
*/
|
||||
XScuTimer_LoadTimer(InstancePtr, LoadOrig);
|
||||
XScuTimer_WriteReg(InstancePtr->Config.BaseAddr,
|
||||
XSCUTIMER_CONTROL_OFFSET, CtrlOrig);
|
||||
|
||||
/*
|
||||
* Return a Failure if the contents of the Load Register do not
|
||||
* match with the value written to it.
|
||||
*/
|
||||
if (Register != XSCUTIMER_SELFTEST_VALUE) {
|
||||
Status = (s32)XST_FAILURE;
|
||||
}
|
||||
else {
|
||||
Status = (s32)XST_SUCCESS;
|
||||
}
|
||||
|
||||
return Status;
|
||||
}
|
||||
/** @} */
|
||||
@@ -0,0 +1,96 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright (C) 2010 - 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
|
||||
* XILINX 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 xscutimer_sinit.c
|
||||
* @addtogroup scutimer_v2_1
|
||||
* @{
|
||||
*
|
||||
* This file contains method for static initialization (compile-time) of the
|
||||
* driver.
|
||||
*
|
||||
* <pre>
|
||||
* MODIFICATION HISTORY:
|
||||
*
|
||||
* Ver Who Date Changes
|
||||
* ----- --- -------- ---------------------------------------------
|
||||
* 1.00a nm 03/10/10 First release
|
||||
* 2.1 sk 02/26/15 Modified the code for MISRA-C:2012 compliance.
|
||||
* </pre>
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/***************************** Include Files *********************************/
|
||||
|
||||
#include "xscutimer.h"
|
||||
#include "xparameters.h"
|
||||
|
||||
/************************** Constant Definitions *****************************/
|
||||
|
||||
/**************************** Type Definitions *******************************/
|
||||
|
||||
/***************** Macros (Inline Functions) Definitions *********************/
|
||||
|
||||
/************************** Variable Definitions ****************************/
|
||||
extern XScuTimer_Config XScuTimer_ConfigTable[XPAR_XSCUTIMER_NUM_INSTANCES];
|
||||
|
||||
/************************** 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.
|
||||
*
|
||||
******************************************************************************/
|
||||
XScuTimer_Config *XScuTimer_LookupConfig(u16 DeviceId)
|
||||
{
|
||||
XScuTimer_Config *CfgPtr = NULL;
|
||||
u32 Index;
|
||||
|
||||
for (Index = 0U; Index < XPAR_XSCUTIMER_NUM_INSTANCES; Index++) {
|
||||
if (XScuTimer_ConfigTable[Index].DeviceId == DeviceId) {
|
||||
CfgPtr = &XScuTimer_ConfigTable[Index];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return (XScuTimer_Config *)CfgPtr;
|
||||
}
|
||||
/** @} */
|
||||
@@ -0,0 +1,117 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright (C) 2009 - 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
|
||||
* XILINX 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 xtime_l.c
|
||||
*
|
||||
* This file contains low level functions to get/set time from the Global Timer
|
||||
* register in the ARM Cortex A9 MP core.
|
||||
*
|
||||
* <pre>
|
||||
* MODIFICATION HISTORY:
|
||||
*
|
||||
* Ver Who Date Changes
|
||||
* ----- ------ -------- ---------------------------------------------------
|
||||
* 1.00a rp/sdm 11/03/09 Initial release.
|
||||
* 3.07a sgd 07/05/12 Upadted get/set time functions to make use Global Timer
|
||||
* </pre>
|
||||
*
|
||||
* @note None.
|
||||
*
|
||||
******************************************************************************/
|
||||
/***************************** Include Files *********************************/
|
||||
|
||||
#include "xtime_l.h"
|
||||
#include "xil_io.h"
|
||||
#include "xil_types.h"
|
||||
#include "xpseudo_asm.h"
|
||||
|
||||
/***************** Macros (Inline Functions) Definitions *********************/
|
||||
|
||||
/**************************** Type Definitions *******************************/
|
||||
|
||||
/************************** Constant Definitions *****************************/
|
||||
|
||||
/************************** Variable Definitions *****************************/
|
||||
|
||||
/************************** Function Prototypes ******************************/
|
||||
|
||||
/****************************************************************************
|
||||
*
|
||||
* Set the time in the Global Timer Counter Register.
|
||||
*
|
||||
* @param Value to be written to the Global Timer Counter Register.
|
||||
*
|
||||
* @return None.
|
||||
*
|
||||
* @note In multiprocessor environment reference time will reset/lost for
|
||||
* all processors, when this function called by any one processor.
|
||||
*
|
||||
****************************************************************************/
|
||||
void XTime_SetTime(XTime Xtime_Global)
|
||||
{
|
||||
/* Disable Global Timer */
|
||||
Xil_Out32((u32)GLOBAL_TMR_BASEADDR + (u32)GTIMER_CONTROL_OFFSET, (u32)0x0);
|
||||
|
||||
/* Updating Global Timer Counter Register */
|
||||
Xil_Out32((u32)GLOBAL_TMR_BASEADDR + (u32)GTIMER_COUNTER_LOWER_OFFSET, (u32)Xtime_Global);
|
||||
Xil_Out32((u32)GLOBAL_TMR_BASEADDR + (u32)GTIMER_COUNTER_UPPER_OFFSET,
|
||||
(u32)((u32)(Xtime_Global >> 32U)));
|
||||
|
||||
/* Enable Global Timer */
|
||||
Xil_Out32((u32)GLOBAL_TMR_BASEADDR + (u32)GTIMER_CONTROL_OFFSET, (u32)0x1);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
*
|
||||
* Get the time from the Global Timer Counter Register.
|
||||
*
|
||||
* @param Pointer to the location to be updated with the time.
|
||||
*
|
||||
* @return None.
|
||||
*
|
||||
* @note None.
|
||||
*
|
||||
****************************************************************************/
|
||||
void XTime_GetTime(XTime* Xtime_Global)
|
||||
{
|
||||
u32 low;
|
||||
u32 high;
|
||||
|
||||
/* Reading Global Timer Counter Register */
|
||||
do {
|
||||
high = Xil_In32(GLOBAL_TMR_BASEADDR + GTIMER_COUNTER_UPPER_OFFSET);
|
||||
low = Xil_In32(GLOBAL_TMR_BASEADDR + GTIMER_COUNTER_LOWER_OFFSET);
|
||||
} while (Xil_In32(GLOBAL_TMR_BASEADDR + GTIMER_COUNTER_UPPER_OFFSET) != high);
|
||||
|
||||
*Xtime_Global = (((XTime)high) << 32U) | (XTime)low;
|
||||
}
|
||||
@@ -35,6 +35,7 @@ Modification:
|
||||
struct XiziClockDriver {
|
||||
void (*sys_clock_init)();
|
||||
uint32_t (*get_clock_int)();
|
||||
bool (*is_timer_expired)();
|
||||
void (*clear_clock_intr)();
|
||||
|
||||
uint64_t (*get_tick)();
|
||||
|
||||
Reference in New Issue
Block a user