From ec41c437515981b5b00d8453965d23dcf01cd000 Mon Sep 17 00:00:00 2001 From: Alexandre Abadie Date: Sun, 5 Dec 2021 11:53:44 +0100 Subject: [PATCH] sys: introduce coreclk utility function --- sys/include/clk.h | 49 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 sys/include/clk.h diff --git a/sys/include/clk.h b/sys/include/clk.h new file mode 100644 index 0000000000..577642bba9 --- /dev/null +++ b/sys/include/clk.h @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2021 Inria + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @defgroup sys_clk System core clock + * @ingroup sys + * @{ + * + * @file + * @brief System core clock utility functions + */ + +#ifndef CLK_H +#define CLK_H + +#include +#include +#include "periph_conf.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Get the current system core clock frequency in Hz. + * + * @returns current system core clock frequency in Hz + */ +static inline uint32_t coreclk(void) { +#if defined(CLOCK_CORECLOCK) + return CLOCK_CORECLOCK; +#else + extern uint32_t cpu_coreclk; + assert(cpu_coreclk != 0); + return cpu_coreclk; +#endif +} + +#ifdef __cplusplus +} +#endif + +#endif /* CLK_H */ +/** @} */