Sergey A. Borshch escreveu:
Anthony L wrote:
  
Hi All,

Could someone please tell me what the purpose of the sfrw macro is?

For example;

#define TA0CTL_             0x0160
sfrw (TA0CTL,TA0CTL_);

What would be the difference to defining TA0CTL directly to 0x0160 ?
    
Because #define TA0CTL    0x0160 absolutely useless in C sources.
Expanding TA0CTL = 0; to 0x0160 = 0; is meanless.
sfrw() macro expanded differently when header file included into C or asm source 
files.

I can't say why sfrw (TA0CTL, 0x0160) notation not used. Possibly we can change 
headers to this notation to preserve global namespace from flooding with 
TA0CTL_-like useless names.


  
The C-compliant syntax, to turn the 0x0160 constant into an absolute address would be something like this:
    #define TA0CTL ((volatile uint16_t *)(0x0160))

Note that the "volatile" keyword is a MUST, since hardware may change register contents anytime.

The sfr notation comes from the Harward architecture, specially the 80x51, where the standard C notation can't cope with some processor specific features, like bit-addressing and other stuff. For modern microcontrollers such as ARM and MSP430 this is really an optional compiler extension.

Reply via email to