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.

Macros for hardware access

What does the following terms denote in TIVA C Series

HWREG , HWREGH , HWREGB , HWREGBITW , HWREGBITH , HWREGBITB ???

  • This is taken from hw_types.h:

    //*****************************************************************************
    //
    // Macros for hardware access, both direct and via the bit-band region.
    //
    //*****************************************************************************
    #define HWREG(x)                                                              \
            (*((volatile uint32_t *)(x)))
    #define HWREGH(x)                                                             \
            (*((volatile uint16_t *)(x)))
    #define HWREGB(x)                                                             \
            (*((volatile uint8_t *)(x)))
    #define HWREGBITW(x, b)                                                       \
            HWREG(((uint32_t)(x) & 0xF0000000) | 0x02000000 |                     \
                  (((uint32_t)(x) & 0x000FFFFF) << 5) | ((b) << 2))
    #define HWREGBITH(x, b)                                                       \
            HWREGH(((uint32_t)(x) & 0xF0000000) | 0x02000000 |                    \
                   (((uint32_t)(x) & 0x000FFFFF) << 5) | ((b) << 2))
    #define HWREGBITB(x, b)                                                       \
            HWREGB(((uint32_t)(x) & 0xF0000000) | 0x02000000 |                    \
                   (((uint32_t)(x) & 0x000FFFFF) << 5) | ((b) << 2))
    
    //*****************************************************************************

    I usually use the HWREG only, it lets me use direct access registers programming without including part.h. It accesses a full register if used correctly since it takes a 32bit value.

    HWREGH and HWREGB it's the same but for 16bit and 8bit values so you can use them just to access 16 or 8 bits at a time in a register if used correctly (with the right value and offset).

    The other 3 i don't really know, never used them but you can see what they do by their definition.

    Here is a example of the use of HWREG with the TivaWare equivalent next to it:

    HWREG(TIMER0_BASE + TIMER_O_TBMATCHR) = 36; // TimerMatchSet(TIMER0_BASE, TIMER_B, 36);

  • Hello All

    The last 3 are for bit banding in a 32-bit, 16-bit and 8-bit access

    Regards

    Amit

  • Thanks both to Luis & Amit - and we note that Luis provided an equivalent function under TivaWare.  C'est tres bien!

    Believe that it's always wise to employ TivaWare (or StellarisWare) over the direct register method as either driver library has been much more tested - and (often) hidden, non-obvious, register links have been anticipated - and fully & properly included w/in the driver library functions.  Absolutely NOT the case when using direct register!

    When execution speed is vital - or no driver library function exists to satisfy a programming requirement - only then should direct register be employed by the inexperienced.  (imho)

    If one (really) wants to "look under the hood" - review of the source code (freely provided) by the driver library - clearly lists the "when, where, & how" critical registers are impacted - by each/every driver lib. function call.  Using direct register - in harsh contrast - the user is responsible for all such obscure links/calling sequences/and "less than obvious" register manipulations.

    KISS - driver library first (especially when new/learning).  Plenty of time (later) to "play" w/direct register.  (keep fire extinguisher, "at the ready!")

  • @all Is there any timing difference when accessing 32bit HWreg versus the bit banding type access? Or both the instuctions are executed by the compiler in the same way under the hood?

  • Hello Settharaman

    The two are executed the same manner outside the hood as well. It is the address space that is being accessed that decides the intent of the access