]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lib.git/blobdiff - rpp/include/binary.h
Uncrustify
[pes-rpp/rpp-lib.git] / rpp / include / binary.h
index c8a58b0682bfd8b247393a0e485433b2437deda9..a72a8f064ff1453e9f3ed0e9d9ce5688684cd9d6 100644 (file)
 
 
 /**
- * FIXME: Document.
+ * @brief Set value at position specified by mask.
+ *
+ * Macro for value setting into mask position.
+ * For example we want to get value 0x0040. We can use
+ * this macro with parameters: __val2mfld(0x00F0, 4)
  */
 #define __val2mfld(mask,val) (((mask)&~((mask)<<1))*(val)&(mask))
 
 
 /**
- * FIXME: Document.
+ * @brief Get value from position specified by mask.
+ *
+ * Macro for getting value from mask position.
+ * For example we have a value 0x1234 and we want get
+ * the second number value from the right. This macro
+ * can be used for this with parameters: __mfld2val(0x00F0, 0x1234)
+ * which will return 0x0030.
  */
 #define __mfld2val(mask,val) (((val)&(mask))/((mask)&~((mask)<<1)))
 
+/**
+ * @brief Clear bits in mask position
+ *
+ * This macro clears all bits specified by the mask.
+ * For example the call __clrvalmsk(0x00F0, 0x1234) will
+ * return 0x1204.
+ */
+#define __clrvalmsk(mask, val) ((val) & ~(mask))
+
+/**
+ * @brief Insert value into mask position
+ *
+ * This macro inserts value into position specified by mask.
+ * All others bits are preserved, only masked bits are changed.
+ * For example:
+ *      int value = 0X1234;
+ *      int mask = 0x00F0;
+ *      value = __insval2mfld(mask, value, 4);
+ *  will change value into 0x1244;
+ */
+#define __insval2mfld(mask, value, val) (__clrvalmsk(mask, value) | \
+                                                                                __val2mfld(mask,val))
 
 #endif /* __RPP_BINARY_H */