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.

Function of SFR_16BIT?

Other Parts Discussed in Thread: MSP430F5529

I am learning msp430f5529 using CCS V6, in the example codes,

WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer

And the WDTCTL is defined as:

SFR_16BIT(WDTCTL); 

#define SFR_16BIT(address)  extern volatile unsigned int address

I know the sentence means writing the value of WDTPW | WDTHOLD to the address 0000015C, but

Q1: What is the data type of WDTCTL? Is it extern volatile unsigned int or *(&(extern volatile unsigned int))? Which exact sentence defines the data type of WDTCTL? 

Q2: How is 0000015C assigned to WDTCTL? I have searched several previous posts and still don't quite understand. 

I am using MSPWare Version 2.21.00.39 which is different from this post

e2e.ti.com/.../231735

because I cannot find 

WDTCTL             = 0x015C;

in lnk_msp430f5529.cmd. Instead, in the generated .map file, I can find 

address name
------- ----

0000015c  WDTCTL 

Since .map is generated, How does the compiler assign the exact address to the WDTCTL and all the other registers?

Thanks

Eric 

  • SFR_16BIT() is just a macro-short-cut so you don't have to spell out:  extern volatile unsigned int "address" every time.
    Plus if something change you only need to edit it at one location.

    As it uses extern, it is declared implicitly globally and is often placed in common.h etc.
    as somewhere volatile unsigned int "address, without the extern is also placed.

    WDTCTL is defined in msp430f5529.h,
    Any decent complier when you select target you only have to use #include msp430.h and it will use mcu specific .h file automatically.

  • Tony,

    Thanks for the reply. but I still cannot find the definition of WDTCTL in my msp430f5529.h, allI can find is:

    SFR_16BIT(WDTCTL);                            /* Watchdog Timer Control */

    SFR_8BIT(WDTCTL_L);                           /* Watchdog Timer Control */

    SFR_8BIT(WDTCTL_H);                           /* Watchdog Timer Control */

    My msp430f5529.h is attached below

    Eric

    msp430f5529.h

  • It's in msp430f5529.cmd

    /************************************************************
    * WATCHDOG TIMER A
    ************************************************************/
    WDTCTL             = 0x015C;
    WDTCTL_L           = 0x015C;
    WDTCTL_H           = 0x015D;

  • Hi Christos,

    Thanks for the reply.

    I can find it under ccs_base/msp430/include now

    But I also notice that there is another cmd file called lnk_msp430f5529.cmd in the project

    What is the difference between these two cmd files?

    Eric

  • That's a completely different file mate.
    The lnk_msp430f5529.cmd contains information for the linker (where to put different code segments, memory ranges and stuff like that).
    Double click it to open it and see what it contains. Then you'll see the differences between the two files.
  • Hi Christos,

    If I write

    WDTCTL             = 0x015C;

    in a cmd file, and WDTCTL is an volatile unsigned int "address", it means WDTCTL represents the value stored in address 0x015C, by reading or writing WDTCTL, we basically operates the value in 0x015C.

    But if a write

    volatile unsigned int i;

    i = 0x015c;

    in a c file, it means i is stored in stack, we obviously cannot find i but we can find WDTCTL in the generated map file.

    So the difference is where to write WDTCTL, am I right?

    Thanks,

    Eric

     

  • I guess CCS is different, as in IAR they are just like any regular #define and don't use  equal char

    #define WDTCTL_             (0x0120u)          /* Watchdog Timer Control */
    DEFW(   WDTCTL            , WDTCTL_)


    So the hardware address is 0x0120 (on a G2553)
    It then uses the DEFW define as a wrapper

    #define DEFW(name, address) __no_init volatile unsigned short name @ address;

  • Let me try to clarify this a bit:

    The WDTCTL is a pointer to the hardware register (aka the 16 little wires of the peripheral inside the silicon end).
    TI could have given it any name they like. They chose WDTCTL (which makes sense :) ).

    Should you in your firmware want to assign a different name to the address 0x15C, you do so like this:
    extern volatile unsigned int *i = 0x15C;
    Notice the "*" in front of the i, denoting this is actually a pointer.

    Another way would be:
    unsigned int i = 0x15C;
    extern volatile unsigned int *WDTCTL_NAME_2;
    WDTCTL_NAME_2 = i;

    Now as to where the variables are stored, they follow the known rules (inside the function => stack,  globals => heap) and so on.

  • Hi Christos,

    Thanks, I can understand what you said clearly, but I still don't quite understand what the example codes from TI represent, which leads back to my original question 1: what is the data type of WDTCTL?

    (1)Unlike

    extern volatile unsigned int *i = 0x15C;

    nor

    unsigned int i = 0x15C;
    extern volatile unsigned int *WDTCTL_NAME_2;
    WDTCTL_NAME_2 = i;

    WDTCTL is not a pointer, because in the h file

    #define SFR_16BIT(address)  extern volatile unsigned int address

    (2) Now I think it's more like a

    volatile unsigned int

    type which is assigned to the address 0x015C by the way you mentioned in the

    msp430f5529.cmd

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

    * WATCHDOG TIMER A

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

    WDTCTL             = 0x015C;

    But I'm still confused by the difference between writing

    WDTCTL             = 0x015C;

    in a c file and in a cmd file.

    Eric

**Attention** This is a public forum