|
@@ -9,7 +9,7 @@
|
|
|
其它说明:
|
|
其它说明:
|
|
|
修改记录:
|
|
修改记录:
|
|
|
*/
|
|
*/
|
|
|
-#include "ustimer.h"
|
|
|
|
|
|
|
+#include "bsp_ustimer.h"
|
|
|
#include <stdlib.h>
|
|
#include <stdlib.h>
|
|
|
#include <fcntl.h>
|
|
#include <fcntl.h>
|
|
|
#include <sys/types.h>
|
|
#include <sys/types.h>
|
|
@@ -17,16 +17,18 @@
|
|
|
#include <stdio.h>
|
|
#include <stdio.h>
|
|
|
#include <sys/mman.h>
|
|
#include <sys/mman.h>
|
|
|
#include "bsp_ccu.h"
|
|
#include "bsp_ccu.h"
|
|
|
|
|
+#include "rt_types.h"
|
|
|
|
|
|
|
|
#define MAP_SIZE 4096UL
|
|
#define MAP_SIZE 4096UL
|
|
|
#define MAP_MASK (MAP_SIZE - 1)
|
|
#define MAP_MASK (MAP_SIZE - 1)
|
|
|
|
|
+#define BSP_USTIMER_DELAY_MAX_US (10UL*60*BSP_USTIMER_SEC) //10分钟
|
|
|
|
|
|
|
|
int g_ustimer_fd = -1;
|
|
int g_ustimer_fd = -1;
|
|
|
unsigned g_ustimer_mapped_size;
|
|
unsigned g_ustimer_mapped_size;
|
|
|
void *g_ustimer_map_base, *g_ustimer_virt_addr;
|
|
void *g_ustimer_map_base, *g_ustimer_virt_addr;
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
/******************************************************************************
|
|
|
-函数名称: ustimer_init
|
|
|
|
|
|
|
+函数名称: bsp_ustimer_init
|
|
|
函数版本: 01.01
|
|
函数版本: 01.01
|
|
|
创建作者: zhaoyang
|
|
创建作者: zhaoyang
|
|
|
创建日期: 2025-07-28
|
|
创建日期: 2025-07-28
|
|
@@ -35,7 +37,7 @@ void *g_ustimer_map_base, *g_ustimer_virt_addr;
|
|
|
返回值: 无
|
|
返回值: 无
|
|
|
修改记录:
|
|
修改记录:
|
|
|
*/
|
|
*/
|
|
|
-int ustimer_init(void)
|
|
|
|
|
|
|
+int bsp_ustimer_init(void)
|
|
|
{
|
|
{
|
|
|
void *temp_ccu_base, *temp_virt_l_base, *temp_virt_h_base, *temp_virt_ctl_base;
|
|
void *temp_ccu_base, *temp_virt_l_base, *temp_virt_h_base, *temp_virt_ctl_base;
|
|
|
unsigned long read_result;
|
|
unsigned long read_result;
|
|
@@ -102,7 +104,7 @@ int ustimer_init(void)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
/******************************************************************************
|
|
|
-函数名称: ustimer_exit
|
|
|
|
|
|
|
+函数名称: bsp_ustimer_exit
|
|
|
函数版本: 01.01
|
|
函数版本: 01.01
|
|
|
创建作者: zhaoyang
|
|
创建作者: zhaoyang
|
|
|
创建日期: 2025-07-28
|
|
创建日期: 2025-07-28
|
|
@@ -111,7 +113,7 @@ int ustimer_init(void)
|
|
|
返回值: 无
|
|
返回值: 无
|
|
|
修改记录:
|
|
修改记录:
|
|
|
*/
|
|
*/
|
|
|
-int ustimer_exit(void)
|
|
|
|
|
|
|
+int bsp_ustimer_exit(void)
|
|
|
{
|
|
{
|
|
|
if (g_ustimer_fd >= 0)
|
|
if (g_ustimer_fd >= 0)
|
|
|
{
|
|
{
|
|
@@ -128,7 +130,7 @@ int ustimer_exit(void)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
/******************************************************************************
|
|
|
-函数名称: ustimer_get_origin
|
|
|
|
|
|
|
+函数名称: bsp_ustimer_get_origin
|
|
|
函数版本: 01.01
|
|
函数版本: 01.01
|
|
|
创建作者: zhaoyang
|
|
创建作者: zhaoyang
|
|
|
创建日期: 2025-07-28
|
|
创建日期: 2025-07-28
|
|
@@ -138,7 +140,7 @@ int ustimer_exit(void)
|
|
|
返回值: 当前时刻定时器的值。
|
|
返回值: 当前时刻定时器的值。
|
|
|
修改记录:
|
|
修改记录:
|
|
|
*/
|
|
*/
|
|
|
-unsigned long ustimer_get_origin(void)
|
|
|
|
|
|
|
+unsigned long bsp_ustimer_get_origin(void)
|
|
|
{
|
|
{
|
|
|
void *temp_virt_l_base, *temp_virt_h_base;
|
|
void *temp_virt_l_base, *temp_virt_h_base;
|
|
|
u_int64_t val_low, val_high;
|
|
u_int64_t val_low, val_high;
|
|
@@ -154,3 +156,84 @@ unsigned long ustimer_get_origin(void)
|
|
|
|
|
|
|
|
return ((val_high << TIMER_VH_OFFSET) | val_low)/3;
|
|
return ((val_high << TIMER_VH_OFFSET) | val_low)/3;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+/******************************************************************************
|
|
|
|
|
+函数名称: bsp_ustimer_get_duration
|
|
|
|
|
+函数版本: 01.01
|
|
|
|
|
+创建作者: zhaoyang
|
|
|
|
|
+创建日期: 2025-07-28
|
|
|
|
|
+函数说明: 得到当前时刻相对于指定时间原点的时间间隔,以us为单位。
|
|
|
|
|
+参数说明: origin: 时间原点,以us为单位。
|
|
|
|
|
+返回值: 当前时刻相对于原点的的时间间隔。
|
|
|
|
|
+修改记录:
|
|
|
|
|
+*/
|
|
|
|
|
+unsigned long bsp_ustimer_get_duration(unsigned long origin)
|
|
|
|
|
+{
|
|
|
|
|
+ if(!g_ustimer_map_base)
|
|
|
|
|
+ return 0;
|
|
|
|
|
+ // 返回差值(根据C语言算法,会自动处理回绕问题)
|
|
|
|
|
+ return bsp_ustimer_get_origin() - origin;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/******************************************************************************
|
|
|
|
|
+函数名称: bsp_ustimer_delay_origin
|
|
|
|
|
+函数版本: 01.01
|
|
|
|
|
+创建作者: zhaoyang
|
|
|
|
|
+创建日期: 2025-07-28
|
|
|
|
|
+函数说明: 以us为单位的延时函数。最大延时值为1小时(3600000000us)和
|
|
|
|
|
+ ustimer_delay函数不同的是bsp_ustimer_delay_origin函数的延时计算的时间
|
|
|
|
|
+ 原点为origin,而不是函数被调用的时刻。当这个函数退出时,会确保延时
|
|
|
|
|
+ 大于等于设定值。如果需要高精度的延时,调用这个函数时应先屏蔽中断。
|
|
|
|
|
+参数说明:
|
|
|
|
|
+ origin: 延时计算的时间原点,以us为单位,通常通过ustimer_get_origin函数获得。
|
|
|
|
|
+ us: 延时us数。
|
|
|
|
|
+返回值:
|
|
|
|
|
+ 0: 成功
|
|
|
|
|
+ 其它: 失败
|
|
|
|
|
+修改记录:
|
|
|
|
|
+*/
|
|
|
|
|
+unsigned long bsp_ustimer_delay_origin(unsigned long origin,unsigned long us)
|
|
|
|
|
+{
|
|
|
|
|
+ if(!g_ustimer_map_base)
|
|
|
|
|
+ return 0;
|
|
|
|
|
+
|
|
|
|
|
+ //检查参数
|
|
|
|
|
+ if(us > BSP_USTIMER_DELAY_MAX_US)
|
|
|
|
|
+ return -1;
|
|
|
|
|
+
|
|
|
|
|
+ // 循环等待
|
|
|
|
|
+ while (us > (bsp_ustimer_get_origin() - origin))
|
|
|
|
|
+ ;
|
|
|
|
|
+ return 0;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/******************************************************************************
|
|
|
|
|
+函数名称: ustimer_delay
|
|
|
|
|
+函数版本: 01.01
|
|
|
|
|
+创建作者: zhaoyang
|
|
|
|
|
+创建日期: 2025-07-28
|
|
|
|
|
+函数说明: 以us为单位的延时函数。最大延时值为1小时(3600000000us)。
|
|
|
|
|
+ 当这个函数退出时,会确保延时大于等于设定值。如果需要高精度的延时,
|
|
|
|
|
+ 调用这个函数时应先屏蔽中断。
|
|
|
|
|
+参数说明:
|
|
|
|
|
+ us: 延时us数。
|
|
|
|
|
+返回值:
|
|
|
|
|
+ 0: 成功
|
|
|
|
|
+ 其它: 失败
|
|
|
|
|
+修改记录:
|
|
|
|
|
+*/
|
|
|
|
|
+unsigned long bsp_ustimer_delay(unsigned long us)
|
|
|
|
|
+{
|
|
|
|
|
+ u64 origin;
|
|
|
|
|
+
|
|
|
|
|
+ if(!g_ustimer_map_base)
|
|
|
|
|
+ return 0;
|
|
|
|
|
+
|
|
|
|
|
+ //检查参数
|
|
|
|
|
+ if(us > BSP_USTIMER_DELAY_MAX_US)
|
|
|
|
|
+ return -1;
|
|
|
|
|
+
|
|
|
|
|
+ origin = bsp_ustimer_get_origin();
|
|
|
|
|
+ bsp_ustimer_delay_origin(origin, us);
|
|
|
|
|
+ return 0;
|
|
|
|
|
+}
|