[DeviceDrivers] Add more API.
1. Use float type for clock_cpu_getres() return value; 2. Add clock_cpu_microsecond/millisecond APIs.
This commit is contained in:
parent
872975b0ab
commit
341f78fed7
|
@ -7,7 +7,7 @@ config RT_USING_DEVICE_IPC
|
|||
config RT_USING_SERIAL
|
||||
bool "Using serial device drivers"
|
||||
select RT_USING_DEVICE_IPC
|
||||
select RT_USING_DEVICE
|
||||
select RT_USING_DEVICE
|
||||
default y
|
||||
|
||||
config RT_USING_CAN
|
||||
|
@ -24,13 +24,17 @@ config RT_USING_CPUTIME
|
|||
help
|
||||
When enable this option, the BSP should provide a rt_clock_cputime_ops
|
||||
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();
|
||||
/* The unit of clock_cpu_gettime() can be returned by */
|
||||
unit = clock_cpu_getres(); /* number for nanosecond */
|
||||
ts1 = clock_cpu_gettime();
|
||||
ts2 = clock_cpu_gettime();
|
||||
|
||||
/* 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
|
||||
config RT_USING_CPUTIME_CORTEXM
|
||||
|
|
|
@ -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
|
||||
* 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)
|
||||
return _cputime_ops->cputime_getres();
|
||||
|
@ -42,6 +44,8 @@ uint32_t clock_cpu_getres(void)
|
|||
|
||||
/**
|
||||
* The clock_cpu_gettime() function shall return the current value of cpu time tick.
|
||||
*
|
||||
* @return the cpu tick
|
||||
*/
|
||||
uint32_t clock_cpu_gettime(void)
|
||||
{
|
||||
|
@ -52,6 +56,36 @@ uint32_t clock_cpu_gettime(void)
|
|||
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.
|
||||
*
|
||||
|
|
|
@ -30,9 +30,12 @@
|
|||
|
||||
/* 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)
|
||||
|
|
|
@ -27,13 +27,16 @@
|
|||
|
||||
struct rt_clock_cputime_ops
|
||||
{
|
||||
uint32_t (*cputime_getres) (void);
|
||||
float (*cputime_getres) (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_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);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue