Zephyr porting assertion fail: 64-bit cycle counter

For the recent Zephyr versions, Edge impulse C++ model deployments for zephyr lead to assert in hardware that does not have 64-bit cycle counter. In my case for nRF9160DK.

ASSERTION FAIL [0] @ WEST_TOPDIR/zephyr/include/zephyr/kernel.h:1973
64-bit cycle counter not enabled on this platform. See CONFIG_TIMER_HAS_64BIT_CYCLE_COUNTER

This is because zephyr/ei_classifier_porting.cpp checks for kernel version, not for zephyr configuration:

uint64_t ei_read_timer_us() {
#if (KERNEL_VERSION_MAJOR > 3) || ((KERNEL_VERSION_MAJOR == 3) && (KERNEL_VERSION_MINOR >= 1))
uint64_t cycles = k_cycle_get_64();
uint64_t freq = sys_clock_hw_cycles_per_sec();
return(uint64_t)((cycles * 1000000ULL) / freq);
#else
return k_uptime_get() * 1000;
#endif
}

I think this is suitable fix, but you can investigate what is the best:

uint64_t ei_read_timer_us() {
#if defined(CONFIG_TIMER_HAS_64BIT_CYCLE_COUNTER)
uint64_t cycles = k_cycle_get_64();
uint64_t freq = sys_clock_hw_cycles_per_sec();
return(uint64_t)((cycles * 1000000ULL) / freq);
#else
return k_uptime_get() * 1000;
#endif
}

How to reproduce:
Run this code with latest Zephyr that has KERNEL_VERSION_MAJOR=4 (or versions >3.1):
edgeimpulse/firmware-nordic-nrf9160dk: Official Edge Impulse firmware for the nRF9160 DK

Hi @tuoman,

Thank you for reporting this!
I will look into solution you proposed and create a fix.

Cheers,
Vojislav