tests: x86/info: make it work with CONFIG_COUNTER_CMOS=n

There are boards without CMOS RTC, where blind accesses to
the RTC registers will freeze the system. So make the test
works with these boards if CONFIG_COUNTER_CMOS=n.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
This commit is contained in:
Daniel Leung 2022-02-14 13:36:16 -08:00 committed by Maureen Helm
commit 5a38451332

View file

@ -9,6 +9,7 @@
#define NR_SAMPLES 10 /* sample timer 10 times */ #define NR_SAMPLES 10 /* sample timer 10 times */
#if defined(CONFIG_COUNTER_CMOS)
static uint32_t sync(const struct device *cmos) static uint32_t sync(const struct device *cmos)
{ {
uint32_t this, last; uint32_t this, last;
@ -31,11 +32,10 @@ static uint32_t sync(const struct device *cmos)
return sys_clock_cycle_get_32(); return sys_clock_cycle_get_32();
} }
#endif
void timer(void) void timer(void)
{ {
const struct device *cmos;
#if defined(CONFIG_APIC_TIMER) #if defined(CONFIG_APIC_TIMER)
printk("TIMER: new local APIC"); printk("TIMER: new local APIC");
#elif defined(CONFIG_HPET_TIMER) #elif defined(CONFIG_HPET_TIMER)
@ -47,7 +47,8 @@ void timer(void)
printk(", configured frequency = %dHz\n", printk(", configured frequency = %dHz\n",
sys_clock_hw_cycles_per_sec()); sys_clock_hw_cycles_per_sec());
cmos = device_get_binding("CMOS"); #if defined(CONFIG_COUNTER_CMOS)
const struct device *cmos = device_get_binding("CMOS");
if (cmos == NULL) { if (cmos == NULL) {
printk("\tCan't get reference CMOS clock device.\n"); printk("\tCan't get reference CMOS clock device.\n");
} else { } else {
@ -68,6 +69,7 @@ void timer(void)
printk("\taverage = %uHz\n", (unsigned) (sum / NR_SAMPLES)); printk("\taverage = %uHz\n", (unsigned) (sum / NR_SAMPLES));
} }
#endif
printk("\n"); printk("\n");
} }