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.

What actually does SFR_8BIT(address) declare?

Other Parts Discussed in Thread: MSP430G2553

I  am developing standard API's for MSP430G2553 Launchpad.  I have 2 different ways of setting clock source of Timer0. In both cases, i am trying to access the TA0CTL register to set the bits for selecting clock source. But the way I am trying to access is different. Below are the two ways and I get warnings in both cases:

First Method:

void set_clk_src_Timer0(unsigned short int clk_src)
{
void *ptr;
ptr=TACTL;
struct timer_control_register *TACTL_0;
TACTL_0 = (struct timer_control_register*)ptr;
TACTL_0->TSSEL = clk_src;
}

Warning : TACTL is of unsigned int type and cannot be assigned to type void*

Hence I assigned the address of TACTL in below method.

Second Method:

void set_clk_src_Timer0(unsigned short int clk_src)
{
void *ptr;
ptr=&TACTL;
struct timer_control_register *TACTL_0;
TACTL_0 = (struct timer_control_register*)ptr;
TACTL_0->TSSEL = clk_src;
}

Warning: TACTL is of type volatile unsigned int * and cannot be assigned to type void *

I see below declarations  in the MSP430G2553 header file

#define SFR_16BIT(address) extern volatile unsigned int address

#define TACTL TA0CTL

SFR_16BIT(TA0CTL)

Please explain me following doubts:

1. What actually SFR_16BIT(address) declares?

2. How the register name actually gives register address?

  • Hi Shivakumar,

     SFR_16BIT is defined as:

    #define SFR_16BIT(address)  extern volatile unsigned int address

    As you can see, the .h only declares the register as "extern" but the address of the register is defined in the .cmd file. In this case:

    ccs_base\msp430\include\msp430g2553.cmd

    Note that this file is automatically included at the bottom of the linker file lnk_msp430g2553.cmd:

    -l msp430g2553.cmd

     More details here: http://e2e.ti.com/support/microcontrollers/msp430/f/166/t/231735

    Regards,

    Luis R

  • I guess, the use of 'address' as parameter name is a leftover form the original method, where 'address' was a precompiler token (by #define) that was used literally for the register name and substituted for its address in teh SFR macro. Originally both, name and address, were specified in teh resulting register definition, so the compiler did generate direct access instructions (which did perhaps lead to shorter code but was problematic for precompiled libraries).
    Now the parameter 'address' is only a symbol name (with no value anymore). And needs to be known to the linker.
    As a result, it will appear in the linker map file (if one is generated). Also, the header files can be more generic. And libraries compiled this way will get their register access adjusted to the target MSP at link time, allowing libraries used for multiple targets with same hardware module but on different memory locations.

**Attention** This is a public forum