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.

Are TivaWare Macros for hardware access wrong?

Other Parts Discussed in Thread: ENERGIA
//*****************************************************************************
//
// 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))

//*****************************************************************************

Well, these are the macros.

I only use HWREG personally but i would like to know how the last 3 works, the first 3 i understand fine although i don't understand the usefulness of the 16bit and 8bit access.

Are the last 3 correct? They seem to be the same or am i completely blind?

  • Hello Luis,,

    I have been using the HWREG, HWREGH and HWREGB for TM4C129 EPI external memory access when I specifically want to be reading a word, half-word or a byte. Turns out to be more useful.

    The other two are useful when setting a flag bit in SRAM and you do not want to waste a whole word for that. Look at the SMBus and SoftI2C examples/drivers.

    Regards

    Amit

  • Thank you Amit i will check it out

    So basically yea, i am completely blind. I just say the difference.

    I guess i don't much usefulness of the 16-8bits because i usually use the address macros from TivaWare which are all 32bits.

  • Hi Amit,

    Language police arrive...

    Amit Ashara said:
    when setting a flag bit in SRAM and you do not want to waste a whole word

    Might the issue not be so much the, "waste" of a whole word - but instead the potential to wreak havoc by, "painting with too broad a brush?"  By limiting/confining the "size/width" of such operation - the impact is made more surgical - may even free the user from "detailed knowledge" of that entire word's (potential & unwanted) command/control...

    In days past (when 8 bit/legged dinosaurs ruled) Petrei, Roberto, Robert & cb1 (then) really could not "waste" a "whole word!" (doubt that our enfeebled MCUs even possessed such)  Today - w/flash many multiples of our past - off chip memory space - "waste" matters not!  (most of the time) 

    Proposed then (rather than waste) is the potential for "unwanted/unanticipated damaging (side-effects)" - caused by a misplaced bit(s) - when executing a write or register load - "broader" than it really has to be.

    Your take - s'il vous plait...

  • i had to program some of the smaller MSP430, i used a abstraction IDE, Energia. Well that didn't go well eheh. Just a code with a pattern for 2 LEDs and a digital interrupt consumed all the flash. 

    So i had to re-learn in 2h direct register programming in the MSP430, there i usually used a whole 16bit word (it's 16bit the processor) but i used operations like |= and &=~.

    Most of the times i would just operate the needed number of bits, for bit 15 i would use a 16bit word, but i can see the way i done i could just use 8bits for everything and shift the data left before doing that |= or &=~ attribution to the registers

  • Hello cb1,

    Yes it could be. But the reference did come from devices with smaller SRAM and large programs still to be done by a customer.

    Regards

    Amit

  • Our readings may differ - poster originally asked only referencing TivaWare.  Then identified TMC129 - and only recently presented MSP - which is not "bounded" by TivaWare - thus disallowed.

    Hard to characterize TM4C129 as possesor of, "smaller SRAM" or "size limited" programs.

    The dangers of, "painting with too broad an MCU brush" are real - and that point has (now) been minimized - we think incorrectly...  "Waste" is secondary to the potential to cause issues - by (needliessly) exposing each/every bit to alteration - when only a proper few should be so targeted!