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.

bitband technique



Hi there,

I have a query about the bit banding technique. Can anybody explain me what the following line of code doing

for(ui32Idx = 0; ui32Idx < 32; ui32Idx++)
{
//
// Set this bit.
//
HWREGBITW(&g_ui32Value, 31 - ui32Idx) = (0xdecafbad >> (31 - ui32Idx)) & 1;

UARTprintf("\r%08x", g_ui32Value);

}

I really don't understand how I am getting the "decafbad" after 32 iteration. Can anybody explain me about the HWREGBITW micro.

Regards,,

Mohsin

  • Hello Mohsin,

    You can refer to the following E2E thread

    http://e2e.ti.com/support/microcontrollers/tiva_arm/f/908/p/314176/1093601.aspx#1093601

    Regards

    Amit Ashara

  • Hi Amit,

    Thanks for your reply. I can understand the following statement

    HWREGBITW(&g_ui32Flags, 0) ^= 1;

    but i fail to understand how following line of code

    for(ui32Idx = 0; ui32Idx < 32; ui32Idx++)
    {

    HWREGBITW(&g_ui32Value, 31 - ui32Idx) = (0xdecafbad >> (31 - ui32Idx)) & 1;

     UARTprintf("\r%08x", g_ui32Value);

    }

    gives hex values

    00000000 80000000 c0000000 c0000000 d0000000 d8000000 dc000000 de000000 de000000 de800000 dec00000 dec00000 dec00000 dec80000 dec80000 deca0000 deca0000 deca8000 decac000 decae000 decaf000 decaf800 decaf800 decafa00 decafb00 decafb80 decafb80 decafba0 decafba0 decafba8 decafbac decafbac decafbad

    From my calculation first should be 0x80000000  instead of 00000000 as after right shifting 0xdecafbad by 31 we should get 0x00000001 & 1 = 1 on bit31 of ofg_ui32Value. Hence become 0x80000000  

    Similarly after right shifting 0xdecafbad by 30 we should get 0x00000003 & 1 = 1 for bit30 ofg_ui32Value. hence become 0xC0000000 and so on

    Kindly could you please explain me a more about this.

    Regards,

    Mohsin

  • Hello Mohsin,

    Please note that you are writing to a bit-banded region. So the shift operator is selecting the bit value to be written to the SRAM bit banded address in the HWREGBITW which is itslef computed by using the SRAM address for g_ui32Value and to the bit banded location specified by 31-ui32Idx

    Regards

    Amit