]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/pdk.git/blobdiff - packages/ti/drv/sciclient/soc/sysfw/include/tisci/tisci_bitops.h
Migrating to SYSFW version v2020.05 and AM64 presilicon
[processor-sdk/pdk.git] / packages / ti / drv / sciclient / soc / sysfw / include / tisci / tisci_bitops.h
index 64d2679dc2a63fa180fd9cbfb46ad86f80778c78..5f7226fd40faf981f3ff7780fe2f2b3eacc91318 100644 (file)
  *          WARNING!!: Autogenerated file from SYSFW. DO NOT MODIFY!!
  * System Firmware
  *
- * Cortex-M3 (CM3) firmware for power management
+ * Functions for bit and bitfield operations
  *
  */
 
 #ifndef BITOPS_H
 #define BITOPS_H
 
+
+/** TISCI_BIT macro for easily calculating a bit at offset (n) */
 #define TISCI_BIT(n)  (1UL << (n))
 
 
+static inline uint32_t get_field(uint32_t val, uint32_t end, uint32_t start);
+static inline uint32_t set_field(uint32_t tgt, uint32_t end, uint32_t start, uint32_t val);
+static inline uint32_t get_mask(uint32_t end, uint32_t start);
+
+/**
+ * \brief Generate a mask for the give bit field [end:start]
+ *
+ * All the bits between the two specified bit indices including
+ * the specified indices are set to 1. Rest of the bits are set
+ * to zero.
+ *
+ * \param end upper bit index of the mask
+ * \param start lower bit index of the mask
+ *
+ * \return generated mask
+ */
+static inline uint32_t get_mask(uint32_t end, uint32_t start)
+{
+    return ((1U << (end - start + 1)) - 1U) << start;
+}
+
+/**
+ * \brief extract the specified bit field from a 32 bit unsigned integer.
+ *
+ * \param val input from which the bitfield is extracted
+ * \param end upper bit index of the bitfield
+ * \param start lower bit index of the bitfield
+ *
+ * \return extracted bit field, right shifted by start bits.
+ */
+static inline uint32_t get_field(uint32_t val, uint32_t end, uint32_t start)
+{
+    uint32_t mask = get_mask(end, start);
+
+    return (val & mask) >> start;
+}
+
+/**
+ * \brief set the specified bit field from a 32 bit unsigned integer
+ * to provided value
+ *
+ * \param tgt input in which the bitfield is to be set
+ * \param end upper bit index of the bitfield
+ * \param start lower bit index of the bitfield
+ * \param val  value to which the bit field is to be set.
+ *
+ * \return input value with bitfield updated as specified.
+ */
+static inline uint32_t set_field(uint32_t tgt, uint32_t end, uint32_t start, uint32_t val)
+{
+    uint32_t ret = 0U;
+    uint32_t mask = get_mask(end, start);
+
+    ret = (tgt & (~mask));
+
+    ret = (ret | ((val << start) & mask));
+
+    return ret;
+}
+
 #endif
 
 /* @} */