[riot-notifications] [RIOT-OS/RIOT] core/bitarithm: introduce bitarithm_get/set_masked(), convert pca9685 (#12238)

Kaspar Schleiser notifications at github.com
Mon Sep 16 21:37:43 CEST 2019


kaspar030 commented on this pull request.



> @@ -163,6 +163,47 @@ static inline unsigned bitarithm_lsb(unsigned v)
 }
 #endif
 
+/**
+ * @brief           Sets the masked bits in a word to the given value.
+ *
+ * @note            The mask should be compile-time constant so the compiler
+ *                  is able to optimize the entire loop away.
+ *
+ * @param       val The value to modify.
+ * @param[in]  mask The bitmask to apply.
+ * @param[in]  bits The new value of the masked bits.
+ *
+ */
+#define bitarithm_set_masked(val, mask, bits) do {                  \
+        const unsigned _mask = mask;                                \

IMO, if we're talking uint32_t and uint16_t, two implementations differing just in the type are preferable to a macro implementation. (That's also a coding convention - avoid macros if possible.)

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/RIOT-OS/RIOT/pull/12238#discussion_r324849970
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20190916/fece13c2/attachment.htm>


More information about the notifications mailing list