summaryrefslogtreecommitdiff
path: root/components/drivers/cputime
diff options
context:
space:
mode:
authorBernardXiong <[email protected]>2017-12-31 14:44:04 +0800
committerBernardXiong <[email protected]>2017-12-31 14:44:04 +0800
commit341f78fed7bc2ea53f454cfb0966e43b45cb1786 (patch)
tree435da9a1f97c8a07d1fa1d15457c208f974b5afa /components/drivers/cputime
parent872975b0ab7208c60c1a46be38e58642f146d9e6 (diff)
[DeviceDrivers] Add more API.
1. Use float type for clock_cpu_getres() return value; 2. Add clock_cpu_microsecond/millisecond APIs.
Diffstat (limited to 'components/drivers/cputime')
-rw-r--r--components/drivers/cputime/cputime.c36
-rw-r--r--components/drivers/cputime/cputime_cortexm.c7
2 files changed, 40 insertions, 3 deletions
diff --git a/components/drivers/cputime/cputime.c b/components/drivers/cputime/cputime.c
index a607aeefa1..20f41b6dac 100644
--- a/components/drivers/cputime/cputime.c
+++ b/components/drivers/cputime/cputime.c
@@ -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)
{
@@ -53,6 +57,36 @@ uint32_t clock_cpu_gettime(void)
}
/**
+ * 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.
*
* @return always return 0.
diff --git a/components/drivers/cputime/cputime_cortexm.c b/components/drivers/cputime/cputime_cortexm.c
index 7db27b4b98..f576df785f 100644
--- a/components/drivers/cputime/cputime_cortexm.c
+++ b/components/drivers/cputime/cputime_cortexm.c
@@ -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)