[En-Nut-Discussion] Replacing compiler.h

Harald Kipp harald.kipp at egnite.de
Fri Oct 5 17:36:10 CEST 2012


Hi Nathan,

On 04.10.2012 19:11, Nathan Moore wrote:
>> What's your proposal to split this into different headers? Where to put
>> _NOP?
> 
> Ignoring (for now) all of your other points, then something along the lines of:
> 
> #if defined(__arm__)
> #include <arch/arm/intrinsics.h>
> #elif defined(__AVR__)
> #include <arch/avr/intrinsics.h>
> #elif defined(__AVR32__)
> #include <arch/avr32/intrinsics.h>
> ...
> #endif // arch intrinsics
> 
> Just a thought.

Unfortunately it is not that simple. _NOP depends on the target and the
toolchain. So in arch/avr/intrinsics.h we still have

#if define(__GNUC__)
#define _NOP ...
#elif defined(__IAR__)
#define _NOP ...
...

but when implementing more complicated features, we additionally get
library dependencies and more related #ifdefs.

Furthermore, intrinsics.h will be used by all toolchains and all runtime
libs and additional care is required not to spoil any of them.
This is often beyond the capabilities of a single developer, who is
familiar with one platform only.

Beside that, developers tend to blindly create copies of existing
implementations and add any required modification, but rarely remove
items, which are not required for their platform. That doesn't ease
maintenance. In the current trunk you'll find

#include <dev/mweeprom.h>

Although this had been implemented for the H8/300, it is included by
every new platform, including the latest Cortex-m. Most of these
function are not used or even not available.

This

 #ifndef _NOP
 #if defined(__arm__)
 #define _NOP() __asm__ __volatile__("mov r0, r0  @ _NOP")
 #elif defined(__AVR__) || defined(__AVR32__)
 #define _NOP() __asm__ __volatile__("nop")
 #endif
 #endif

may look ugly, but I assume, that it is easier to extend by someone, who
is familiar with GCC and a single target. May be I should insert

 #else
 error You must implement _NOP for your target.

Regards,

Harald




More information about the En-Nut-Discussion mailing list