summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cesar/lib/test/utils/src/test_utils.c4
-rw-r--r--cesar/lib/utils.h16
2 files changed, 20 insertions, 0 deletions
diff --git a/cesar/lib/test/utils/src/test_utils.c b/cesar/lib/test/utils/src/test_utils.c
index 751a518b65..372a949539 100644
--- a/cesar/lib/test/utils/src/test_utils.c
+++ b/cesar/lib/test/utils/src/test_utils.c
@@ -173,6 +173,10 @@ bf_test_case (test_t t)
test_fail_unless (BF_SET (0x12345678u, TEST_BF__D, 0x2a)
== 0xaa345678);
} test_end;
+ test_begin (t, "masks")
+ {
+ test_fail_unless (BF_MASKS (TEST_BF, A, C) == 0x03ff000f);
+ } test_end;
test_begin (t, "fill")
{
test_fail_unless (BF_FILL (TEST_BF, (A, 0x8), (B, 0x567), (C, 0x234),
diff --git a/cesar/lib/utils.h b/cesar/lib/utils.h
index fc1e689a75..306030ffff 100644
--- a/cesar/lib/utils.h
+++ b/cesar/lib/utils.h
@@ -227,6 +227,22 @@ lesseq_mod2p16 (u16 a, u16 b)
#define BF_FILL_FIELD___(reg, f, v) \
| BF_SHIFT (reg ## f, v)
+/** Pack different bit masks together.
+ * \param reg register name (prefix)
+ * \param f list of fields
+ *
+ * Example:
+ * \code
+ * #define MYREG__A 7, 0
+ * #define MYREG__B 23, 12
+ * BF_MASKS (MYREG, A, B) => 0x00fff0ff
+ * \endcode
+ */
+#define BF_MASKS(reg, f...) \
+ (0 PREPROC_FOR_EACH_PARAM (BF_MASKS_FIELD_, reg ## __, f))
+#define BF_MASKS_FIELD_(reg, f) \
+ | BF_MASK (PASTE_EXPAND (reg, f))
+
/** Update several bit fields, without changing other bits.
* \param regv register value
* \param reg register name (prefix)