1 /* 2 * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230) 3 * 4 * SPDX-License-Identifier: GPL-2.0-only 5 */ 6 7 #pragma once 8 9 #include <config.h> 10 #include <stdint.h> 11 12 #ifdef CONFIG_KERNEL_MCS 13 #include <util.h> 14 15 /* timer function definitions that work for all 32bit arm platforms that provide 16 * CLK_MAGIC and TIMER_CLOCK_MHZ -- these definitions might need to move 17 * if we come across an arm platform that does not suit this model */ 18 19 /* get the max value ticksToUs can be passed without overflowing */ getMaxTicksToUs(void)20static inline CONST ticks_t getMaxTicksToUs(void) 21 { 22 #if USE_KHZ 23 return UINT64_MAX / KHZ_IN_MHZ / CLK_MAGIC; 24 #else 25 return UINT64_MAX / CLK_MAGIC; 26 #endif 27 } 28 ticksToUs(ticks_t ticks)29static inline CONST time_t ticksToUs(ticks_t ticks) 30 { 31 /* simulate 64bit division using multiplication by reciprocal */ 32 #if USE_KHZ 33 return (ticks * KHZ_IN_MHZ) * CLK_MAGIC >> CLK_SHIFT; 34 #else 35 return (ticks * CLK_MAGIC) >> CLK_SHIFT; 36 #endif 37 } 38 #endif /* CONFIG_KERNEL_MCS */ 39 40