/**************************************************************************//**
 * @file     bsp_ustimer.h
 * @brief    TIMER register definition header file
 *
 * SPDX-License-Identifier: Apache-2.0
 * @copyright (C) 2024-2034 HaiYang Technology Corp. All rights reserved.
 *****************************************************************************/
 #ifndef __BSP_US_TIMER_H__
 #define __BSP_US_TIMER_H__
 
 #include <linux/types.h>

 
 #define TIMER_BASE             		(0x03008000UL)
 #define TIMER_VH_OFFSET		32
 #define TIMER_VL_MASK		0xFFFFFFFF
 #define TIMER_VH_MASK		0xFFFFFF

 #define TIMER_IRQ_EN_REG	0x00
 #define TIMER_IRQ_EN(val)	(1 << val)
 #define TIMER_IRQ_ST_REG	0x04
 #define TIMER_IRQ_ST(val)	(1 << val)
 #define TIMER_CTL_REG(val)	(0x10 * val + 0x10)
 #define TIMER_CTL_ENABLE	(1 << 0)
 #define TIMER_CTL_AUTORELOAD	(1 << 1)
 #define TIMER_CTL_MODE_MASK	(1 << 7)
 #define TIMER_CTL_PERIODIC	(0 << 7)
 #define TIMER_CTL_ONESHOT	(1 << 7)
 #define TIMER_INTVAL_REG(val)	(0x10 * val + 0x14)
 #define TIMER_CNTVAL_REG(val)	(0x10 * val + 0x18)

 #define BSP_USTIMER_US		1
#define BSP_USTIMER_MS		(1000*BSP_USTIMER_US)
#define BSP_USTIMER_SEC		(1000*BSP_USTIMER_US)

 int bsp_ustimer_init(void);
 int bsp_ustimer_exit(void);
 unsigned long bsp_ustimer_get_origin(void);
 unsigned long bsp_ustimer_delay(unsigned long us);
 unsigned long bsp_ustimer_delay_origin(unsigned long origin,unsigned long us);
 unsigned long bsp_ustimer_get_duration(unsigned long origin);

 #endif