From 8e83584f1c43899bd6e3643aed7091f1de120999 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Mon, 2 Mar 2020 17:21:55 +0100 Subject: [PATCH] core/include: add macros for common units I got tired of counting zeros in frequency defines, so add a few helper macros to make defining frequency and sizes easier. --- core/include/macros/units.h | 56 +++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 core/include/macros/units.h diff --git a/core/include/macros/units.h b/core/include/macros/units.h new file mode 100644 index 0000000000..0defef090d --- /dev/null +++ b/core/include/macros/units.h @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2020 ML!PA Consulting GmbH + * + * 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. + */ + +/** + * @ingroup core_macros + * @{ + * + * @file + * @brief Unit helper macros + * + * @author Benjamin Valentin + */ + +#ifndef MACROS_UNITS_H +#define MACROS_UNITS_H + +#ifdef __cplusplus + extern "C" { +#endif + +/** + * @brief A macro to return the bytes in x KiB + */ +#define KiB(x) ((unsigned long long)(x) << 10) + +/** + * @brief A macro to return the bytes in x MiB + */ +#define MiB(x) (KiB(x) << 10) + +/** + * @brief A macro to return the bytes in x GiB + */ +#define GiB(x) (MiB(x) << 10) + +/** + * @brief A macro to return the Hz in x kHz + */ +#define KHZ(x) ((x) * 1000ULL) + +/** + * @brief A macro to return the Hz in x MHz + */ +#define MHZ(x) (KHZ(x) * 1000ULL) + +#ifdef __cplusplus +} +#endif + +#endif /* MACROS_UNITS_H */ +/** @} */