Macro inflation [was: Re: change log for rtems (2010-09-08)]

Thomas Dörfler Thomas.Doerfler at embedded-brains.de
Fri Sep 10 16:44:35 UTC 2010


On 10.09.2010 17:33, Eric Norum wrote:
> I really don't see how
> 	someIOreg = BIT32(8);
> is any clearer than
> 	someIOreg = 1<<8;
> 
> But I think that
> #define	SOMEDEVICE_CSR_INTERRUPT_ENABLE	(1<<8)     
> .
> .
> .
> 	someIOreg = SOMEDEVICE_CSR_INTERRUPT_ENABLE;
> would be better.

Other example: In the mpc8xx, the smc1 BRG select is in simode register,
bits 17-19. (PPC notation).

the following existing code:

m8xx.simode = ( (m8xx.simode & 0xffff8fff) | (brg << 12) );

could be replaced with the following code:

m8xx.simode = BSETFIELD32(m8xx.simode,brg,17,19);

or in libcpu/powerpc/mpc8260/console-generic/console-generic.c:

   m8260.cmxscr &= ~(0xFF000000 >> (8*(minor-SCC1_MINOR)) );
    m8260.cmxscr |= ((brg<<(3+8*(3-(minor-SCC1_MINOR)))) &
                     (brg<<(8*(3-(minor-SCC1_MINOR)))));


could be replaced with:
  m8260.cmxscr = BSETFIELD32(m8260.cmxscr,brg,(8*minor)+2,
                                              (8*minor)+4);
  m8260.cmxscr = BSETFIELD32(m8260.cmxscr,brg,(8*minor)+5,
                                              (8*minor)+7);

By the way: do you see the error in the original code line?

If you have a look at the corresponding chip manuals, you will see that
the parameters
Surely these replacements rely on the proper implementation of the
BSETFIELD32() macro, but this is true for all code.

These macros can be a means to make register field accesses more
readable. Nobody is forced to use them, but IMHO they are useful in many
situations.

wkr,
Thomas.


> 
> 
> Or even better, use Till Straumann's I/O macros in case there are special instructions needed to synchronize or serialize I/O (i.e. the PowerPC EIEIO instruction)
> 
> On Sep 9, 2010, at 11:45 PM, Thomas Dörfler wrote:
> 
>> Eric, Ralf,
>>
>> obviously we have different opinions here. Once again: I agree that a
>> different namespace is required for these definitions, but I think the
>> macros _do_ improve readability.
>>
>> I would like to move the discussion back to the rtems-vc mailing list to
>> allow Sebastian to express his opinions.
>>
>> wkr,
>>
>> Thomas.
>>
>>
> 


-- 

--------------------------------------------
Embedded Brains GmbH
Thomas Doerfler        Obere Lagerstrasse 30
D-82178 Puchheim       Germany
email: Thomas.Doerfler at embedded-brains.de
Phone: +49-89-18908079-2
Fax:   +49-89-18908079-9



More information about the vc mailing list