test_tickless: replacing depreciated APIs with new one.

As part of Zephyr release 1.9 some APIs will be depreciated. This patch
replaces two of such APIs (task_sleep(ticks), sys_tick_get_32()) with
new ones (k_sleep(ms), k_uptime_get_32()).

Jira: ZEP-2008

Change-Id: Ic0e05906dadfb2ddaea9d0a8b738294dc81430f9
Signed-off-by: Youvedeep Singh <youvedeep.singh@intel.com>
This commit is contained in:
Youvedeep Singh 2017-04-17 10:49:09 +05:30
commit 576cfd9e74
5 changed files with 38 additions and 24 deletions

View file

@ -1,4 +1,3 @@
MDEF_FILE = prj.mdef
BOARD ?= qemu_x86
CONF_FILE ?= prj.conf

View file

@ -1,2 +1 @@
CONFIG_SYS_POWER_MANAGEMENT=y
CONFIG_LEGACY_KERNEL=y

View file

@ -1,5 +0,0 @@
% Application : TicklessTest
% TASK NAME PRIO ENTRY STACK GROUPS
% ==================================================
TASK timerApp 6 ticklessTestTask 4096 [EXE]

View file

@ -17,12 +17,18 @@ Unit test for tickless idle feature.
#include <arch/cpu.h>
#include <tc_util.h>
#define STACKSIZE 4096
#define PRIORITY 6
#define SLEEP_TICKS 10
#ifdef CONFIG_TICKLESS_IDLE
extern int32_t _sys_idle_threshold_ticks;
#endif
#define TICKS_TO_MS (MSEC_PER_SEC / CONFIG_SYS_CLOCK_TICKS_PER_SEC)
/* NOTE: Clock speed may change between platforms */
#define CAL_REPS 16 /* # of loops in timestamp calibration */
@ -64,10 +70,11 @@ extern void _TimestampClose(void);
#error "Unknown target"
#endif
void ticklessTestTask(void)
void ticklessTestThread(void)
{
int32_t start_ticks;
int32_t end_ticks;
int32_t start_time;
int32_t end_time;
int32_t diff_time;
int32_t diff_ticks;
_timer_res_t start_tsc;
_timer_res_t end_tsc;
@ -100,12 +107,15 @@ void ticklessTestTask(void)
* Do a single tick sleep to get us as close to a tick boundary
* as we can.
*/
task_sleep(1);
start_ticks = sys_tick_get_32();
k_sleep(TICKS_TO_MS);
start_time = k_uptime_get_32();
start_tsc = _TIMESTAMP_READ();
task_sleep(SLEEP_TICKS);
/* FIXME: one tick less to account for
* one extra tick for _TICK_ALIGN in k_sleep
*/
k_sleep((SLEEP_TICKS - 1) * TICKS_TO_MS);
end_tsc = _TIMESTAMP_READ();
end_ticks = sys_tick_get_32();
end_time = k_uptime_get_32();
cal_tsc += end_tsc - start_tsc;
}
cal_tsc /= CAL_REPS;
@ -130,21 +140,27 @@ void ticklessTestTask(void)
* Do a single tick sleep to get us as close to a tick boundary
* as we can.
*/
task_sleep(1);
start_ticks = sys_tick_get_32();
k_sleep(TICKS_TO_MS);
start_time = k_uptime_get_32();
start_tsc = _TIMESTAMP_READ();
task_sleep(SLEEP_TICKS);
/* FIXME: one tick less to account for
* one extra tick for _TICK_ALIGN in k_sleep
*/
k_sleep((SLEEP_TICKS - 1) * TICKS_TO_MS);
end_tsc = _TIMESTAMP_READ();
end_ticks = sys_tick_get_32();
end_time = k_uptime_get_32();
diff_tsc += end_tsc - start_tsc;
}
diff_tsc /= CAL_REPS;
diff_ticks = end_ticks - start_ticks;
diff_time = (end_time - start_time);
/* Convert ms to ticks*/
diff_ticks = (diff_time / TICKS_TO_MS);
printk("start ticks : %d\n", start_ticks);
printk("end ticks : %d\n", end_ticks);
printk("start time : %d\n", start_time);
printk("end time : %d\n", end_time);
printk("diff time : %d\n", diff_time);
printk("diff ticks : %d\n", diff_ticks);
#if defined(CONFIG_X86) || defined(CONFIG_ARC)
@ -181,3 +197,6 @@ void ticklessTestTask(void)
}
}
K_THREAD_DEFINE(TICKLESS_THREAD, STACKSIZE, ticklessTestThread, NULL, NULL,
NULL, PRIORITY, 0, K_NO_WAIT);

View file

@ -47,6 +47,8 @@
#define _TIMESTAMP_MAX ((uint32_t)0x7FFFFFFF)
#define _TIMESTAMP_EXT ((uint32_t)0x80000000)
#define TICKS_TO_MS (MSEC_PER_SEC / CONFIG_SYS_CLOCK_TICKS_PER_SEC)
/**
*
* @brief Timestamp initialization
@ -64,7 +66,7 @@ void _TimestampOpen(void)
_CLKGATECTRL |= _CLKGATECTRL_TIMESTAMP_EN;
/* minimum 3 clk delay is required before timer register access */
task_sleep(3);
k_sleep(3 * TICKS_TO_MS);
_TIMESTAMP_CTRL = 0x0; /* disable/reset timer */
_TIMESTAMP_CFG = 0x0; /* 32-bit timer */
@ -180,7 +182,7 @@ void _TimestampOpen(void)
_TIMESTAMP_IMASK = 0x0; /* mask all timer interrupts */
/* minimum 0.3 sec delay required for oscillator stabilization */
task_sleep(300000/sys_clock_us_per_tick);
k_sleep(0.3 * MSEC_PER_SEC);
_TIMESTAMP_VAL = 0x0; /* clear invalid time flag in status register */