提交 341f78fe 编写于 作者: B BernardXiong

[DeviceDrivers] Add more API.

1. Use float type for clock_cpu_getres() return value;
2. Add clock_cpu_microsecond/millisecond APIs.
上级 872975b0
...@@ -7,7 +7,7 @@ config RT_USING_DEVICE_IPC ...@@ -7,7 +7,7 @@ config RT_USING_DEVICE_IPC
config RT_USING_SERIAL config RT_USING_SERIAL
bool "Using serial device drivers" bool "Using serial device drivers"
select RT_USING_DEVICE_IPC select RT_USING_DEVICE_IPC
select RT_USING_DEVICE select RT_USING_DEVICE
default y default y
config RT_USING_CAN config RT_USING_CAN
...@@ -24,13 +24,17 @@ config RT_USING_CPUTIME ...@@ -24,13 +24,17 @@ config RT_USING_CPUTIME
help help
When enable this option, the BSP should provide a rt_clock_cputime_ops When enable this option, the BSP should provide a rt_clock_cputime_ops
for CPU time by: for CPU time by:
clock_cpu_setops(const struct rt_clock_cputime_ops *ops); const static struct rt_clock_cputime_ops _ops = {...};
clock_cpu_setops(&_ops);
Then developer can use high resolution clock counter with: Then user can use high resolution clock counter with:
ts = clock_cpu_gettime(); ts1 = clock_cpu_gettime();
/* The unit of clock_cpu_gettime() can be returned by */ ts2 = clock_cpu_gettime();
unit = clock_cpu_getres(); /* number for nanosecond */
/* and get the ms of delta tick with API: */
ms_tick = clock_cpu_millisecond(t2 - t1);
us_tick = clock_cpu_microsecond(t2 - t1);
if RT_USING_CPUTIME if RT_USING_CPUTIME
config RT_USING_CPUTIME_CORTEXM config RT_USING_CPUTIME_CORTEXM
......
...@@ -30,8 +30,10 @@ static const struct rt_clock_cputime_ops *_cputime_ops = RT_NULL; ...@@ -30,8 +30,10 @@ static const struct rt_clock_cputime_ops *_cputime_ops = RT_NULL;
/** /**
* The clock_cpu_getres() function shall return the resolution of CPU time, the * The clock_cpu_getres() function shall return the resolution of CPU time, the
* number of nanosecond per tick. * number of nanosecond per tick.
*
* @return the number of nanosecond per tick
*/ */
uint32_t clock_cpu_getres(void) float clock_cpu_getres(void)
{ {
if (_cputime_ops) if (_cputime_ops)
return _cputime_ops->cputime_getres(); return _cputime_ops->cputime_getres();
...@@ -42,6 +44,8 @@ uint32_t clock_cpu_getres(void) ...@@ -42,6 +44,8 @@ uint32_t clock_cpu_getres(void)
/** /**
* The clock_cpu_gettime() function shall return the current value of cpu time tick. * The clock_cpu_gettime() function shall return the current value of cpu time tick.
*
* @return the cpu tick
*/ */
uint32_t clock_cpu_gettime(void) uint32_t clock_cpu_gettime(void)
{ {
...@@ -52,6 +56,36 @@ uint32_t clock_cpu_gettime(void) ...@@ -52,6 +56,36 @@ uint32_t clock_cpu_gettime(void)
return 0; return 0;
} }
/**
* The clock_cpu_microsecond() fucntion shall return the microsecond according to
* cpu_tick parameter.
*
* @param cpu_tick the cpu tick
*
* @return the microsecond
*/
uint32_t clock_cpu_microsecond(uint32_t cpu_tick)
{
float unit = clock_cpu_getres();
return (cpu_tick * unit) / 1000;
}
/**
* The clock_cpu_microsecond() fucntion shall return the millisecond according to
* cpu_tick parameter.
*
* @param cpu_tick the cpu tick
*
* @return the millisecond
*/
uint32_t clock_cpu_millisecond(uint32_t cpu_tick)
{
float unit = clock_cpu_getres();
return (cpu_tick * unit) / (1000 * 1000);
}
/** /**
* The clock_cpu_seops() function shall set the ops of cpu time. * The clock_cpu_seops() function shall set the ops of cpu time.
* *
......
...@@ -30,9 +30,12 @@ ...@@ -30,9 +30,12 @@
/* Use Cycle counter of Data Watchpoint and Trace Register for CPU time */ /* Use Cycle counter of Data Watchpoint and Trace Register for CPU time */
static uint32_t cortexm_cputime_getres(void) static float cortexm_cputime_getres(void)
{ {
return (1000 * 1000 * 1000)/SystemCoreClock; float ret = 1000 * 1000 * 1000;
ret = ret / SystemCoreClock;
return ret;
} }
static uint32_t cortexm_cputime_gettime(void) static uint32_t cortexm_cputime_gettime(void)
......
...@@ -27,13 +27,16 @@ ...@@ -27,13 +27,16 @@
struct rt_clock_cputime_ops struct rt_clock_cputime_ops
{ {
uint32_t (*cputime_getres) (void); float (*cputime_getres) (void);
uint32_t (*cputime_gettime)(void); uint32_t (*cputime_gettime)(void);
}; };
uint32_t clock_cpu_getres(void); float clock_cpu_getres(void);
uint32_t clock_cpu_gettime(void); uint32_t clock_cpu_gettime(void);
uint32_t clock_cpu_microsecond(uint32_t cpu_tick);
uint32_t clock_cpu_millisecond(uint32_t cpu_tick);
int clock_cpu_setops(const struct rt_clock_cputime_ops *ops); int clock_cpu_setops(const struct rt_clock_cputime_ops *ops);
#endif #endif
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册