what this function HWREG() do?

Hello @ all,

I know that the function  HWREG()   returns a unsigned long value, but I am not sure if this value the contain of the Register or what?

in which file can i find  HWREG()  function as the example below :

example:

unsigned long HWREG(unsigned long A)

{

 

return x

}

what is A and what is x in the above example

can you help me please

 

thank you

Bassel

 

  • Bassel Daou
    the function  HWREG()  

    What function? Where have you found it? Was there no documentation with it?

    "HWREG" is a pretty generic name that could be used by just about anyone to mean just about anything - you need to say specifically which particular "HWREG" function you are talking about!

  • Hi,

    fast all function on ther driverlib (C:\StellarisWare\driverlib) are build of the function HWREG(),

    I mean,  this function return the value that stored in the registor:

    unsigned long HWREG(Register base+ Register offset) will return the value which stored in the Register. 

    is this true ?

    please I need your help

    thank you

     

     

  • In reply to Andy Neil:

    Andy Neil
    "HWREG" is a pretty generic name that could be used by just about anyone to mean just about anything

    The Stellaris Firmware Development Package defines it as a Macro - not a function:

    Stellaris Firmware Development Package, hw_types.h

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

     

  • Bassel Daou
    in which file can i find  HWREG()  function

    Your software development tools should have the facility to tell you where a symbol is defined...

     

  • In reply to Andy Neil:

    Hi Andy, I am using IAR as software. I know that my software can this, but this function are not working. I don't know why!!!

    I have a question please 

     

    void
    I2CMasterInitExpClk(unsigned long ulBase, unsigned long ulI2CClk,
                        tBoolean bFast)
    {
        unsigned long ulSCLFreq;
        unsigned long ulTPR;

        //
        // Check the arguments.
        //
        ASSERT((ulBase == I2C0_MASTER_BASE) || (ulBase == I2C1_MASTER_BASE));

        //
        // Must enable the device before doing anything else.
        //
        I2CMasterEnable(ulBase);

        //
        // Get the desired SCL speed.
        //
        if(bFast == true)
        {
            ulSCLFreq = 400000;
        }
        else
        {
            ulSCLFreq = 100000;
        }

        //
        // Compute the clock divider that achieves the fastest speed less than or
        // equal to the desired speed.  The numerator is biased to favor a larger
        // clock divider so that the resulting clock is always less than or equal
        // to the desired clock, never greater.
        //
        ulTPR = ((ulI2CClk + (2 * 10 * ulSCLFreq) - 1) / (2 * 10 * ulSCLFreq)) - 1;
        HWREG(ulBase + I2C_O_MTPR) = ulTPR;
    }

    HWREG(ulBase + I2C_O_MTPR) = ulTPR   how this maen ?????????????

    thank you

    bassel

  • In reply to Bassel Daou:

    It "notify"  the compiler that you are about to do a 32bit instruction with an unsigned variable (volatile Unsigned long). you have them for other sizes as you've seen...

    Look at the* it means that it a pointer to some address in the "volatile" address range (which the compiler cant optimize according to the linker settings .icf file)

    it will translate for example:

    volatile unsigned long * 0x6000253 = ulTPR

    and that the 0x6000253 is a base address for 4 byte data.

    (which will translate to a 1/2/4 instructions depend on the device managing this address -> 16bit sdram means that for a 32 bit instruction data source or destination you'll ave to do tow 16 bit data fetch or set)

    ulBase is the base address, I2C_O_MTPE is the offset address....

     

    Oded

     

  • In reply to Oded Senecio:

    Normal 0 21 false false false MicrosoftInternetExplorer4

    Hi, thank you for your answer

    What I didn't understand this statement:

    0x6000253 = ulTPR;

    What I know that an assignment statement work in one direction.

    Example

    int a ;

    a = 5 ; Ok

    5 = a ; is not OK.

    that why I didn't understand the statement in this thread.

    I will be so please if you help me.

    thank you


  • In reply to Bassel Daou:

    Bassel Daou
    fast all function on ther driverlib (C:\StellarisWare\driverlib) are build of the function HWREG(),

    No!

    As previously noted, StellarisWare defines HWREG as a Macro - it is not a function!

    (in fact, it is general practice in 'C' that names in ALL CAPITALS are Macros)

    Bassel Daou
    this function return the value that stored in the registor

    No: it is not a function - so it does not return anything!

  • In reply to Bassel Daou:

    The macro statement

       HWREG(ulBase + I2C_O_MTPR) = ulTPR;

    expands to

      (*((volatile unsigned long *)(ulBase + I2C_O_MTPR))) = ulTPR;

    and when the defines for the base address and offset are resolved it would look something like

      (*((volatile unsigned long *)(0x400D0000 + 0x0024))) = ulTPR;

    So the actual address of the register is formed as a 32 bit hex number, then cast as a pointer to an unsigned long, then resolved from a pointer to the value which is set to the value in unsigned long variable ulTPR. So you can use the macro on either side of the equal sign as the macro expands into a value that is pointed to by the register address specified by the base address and offset.

     

  • In reply to Chris McDermott:

    Hi @ All,

    thank you for your answers. I've got it.

    @ Andy sorry I've overlooked that t you've witten : "this is  a macro not a function"

    thank you All

    Bassel