avr-chat
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [avr-chat] Is this efficient?


From: Weddington, Eric
Subject: RE: [avr-chat] Is this efficient?
Date: Fri, 3 Oct 2008 11:57:11 -0600

 

> -----Original Message-----
> From: address@hidden 
> [mailto:address@hidden
>  On Behalf Of Ruud Vlaming
> Sent: Friday, October 03, 2008 10:28 AM
> To: address@hidden
> Subject: [avr-chat] Is this efficient?
> 
> To find out if a register is in the io space in .c files,
> i use the following, ugly, construct:
> 
> #undef  _SFR_IO8  
> #define _SFR_IO8(arg) (arg) 
>   #if (TIMSK < 0x40)
>     blah blah  
>   #else
>     bloh bloh
>   #endif
> #undef  _SFR_IO8  
> #define _SFR_IO8(arg) (*(volatile uint8_t *)((arg) + 0x20))
> 
> I cannot test it with _SFR_IO_REG_P, although that macro seems to be 
> meant for the purpose:
> 
>   #if _SFR_IO_REG_P(TIMSK) 
> 
> for that gives the error:
>   error: operator '*' has no left operand
> 
> Somewhere i am missing the point i guess. 
> Who knows the proper way to do such things?

The _SFR_IO_REG_P() macro is designed to be used in the C code itself, not in 
any preprocessor statements. Something like:

if _SFR_IO_REG_P(TIMSK)
{
    // TIMSK is an IO register.
}
else
{
    // TIMSK is not an IO register.
}

Thoroughly untested. And yes it creates more code, as it does not conditional 
compilation.

If you look at the implementation of the _SFR_IO_REG_P() macro, it is taking 
the address of the register and typecasting. IIRC, the preprocessor is not that 
smart. It is not enough C-aware to be able to handle this in preprocessor 
statements. But it should work in regular C code.

HTH
Eric




reply via email to

[Prev in Thread] Current Thread [Next in Thread]