This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Absolute beginner question on Bit-Banding and HWREGBITW

Hi everyone,

I am a beginner to ARM programming and I'm having the hardest time understanding bit-banding! I have read the ARM document here: http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0337e/Behcjiic.html, but I still don't understand what is going on. Can someone please explain what bit-banding is in simple terms?

In addition, I do not understand what the HWREGBITW function from inc/hw_types.h does. Is it used to set a bit in the bit band region? If so, how does it work?

I apologize for such simple questions but I feel like I am making no progress in trying to understand this myself. Thanks in advance!

  • Hi Nipun,

    Simple: Bit banding is a method where a bit is mapped to a complete word access.

    As an example if the there is a 32-bit word for which you want to set a particular bit, then the normal operation would be to read the whole 32-bit word, set the correct bit and write it back.

    Bit banding will allow you to do the same by setting (or writting 1) to a particular location, which will cause the bit in question to be set. Clearly the advantage is that you save the a lot of processor time if there are bits of interest are bit-banded.

    HWREGBITW is a macro for bit banding access. I would suggest you to find a TIVAWare API which uses it and then reconstruct it. Any doubts on it can be supported.

    Amit

  • Hi Amit,

    Thank you very much for your help, the concept of bit-banding makes much more sense now! Can you please let me know if I'm correctly interpreting the following command using HWREGBITW?

    HWREGBITW(&g_ui32Flags, 0) ^= 1;

    Is the above code saying that the Zeroth bit of the word occupied by g_ui32Flags should be toggled using an XOR? This code comes from the TivaWare timers example where they are using g_ui32Flags as a status variable. For applications like these, does it make more sense to use bit-banding as opposed to a regular boolean variable?

    Thanks again for your help,

    Nipun

  • Hi Nipun,

    Bitbanding allows to set or clear a bit directly by addressing the bit in a 32-bit address space. When doing an operation like what you have shown, it will effectively convert it to a read modified write since to toggle a bit it has to read it first.

    Amit

  • Amit,

    Thank you very much for your help, it all makes sense now.

    -Nipun 

  • I'm confused by this response. I found the following in the ARM documentation:

    "It also allows individual bits to be toggled from C without performing a read-modify-write sequence of instructions."

  • Hello Mike,,

    I believe in the ARM document they meant set or clear. The reason why I say so is because, for SRAM without reading the bit you cannot toggle it.

    Regards

    Amit