Page 1 of 1

Documentation/coding style suggestion....

Posted: Sat Jan 02, 2016 12:14 pm
by rew
On http://chibios.org/dokuwiki/doku.php?id ... _dma_guide I see:

Code: Select all

#if defined(__GNUC__)
__attribute__((aligned (32)))
#endif
static uint8_t txbuf[SPI_BUFFERS_SIZE];

Might I suggest to write such things as:

Code: Select all

ALIGNED32 static uint8_t txbuf[SPI_BUFFERS_SIZE];

and have

Code: Select all

#if defined(__GNUC__)
#define ALIGNED32 __attribute__((aligned (32)))
#else
// Auch! Data that needs 32-byte alignment will not be aligned!
#warning "don't know how to align data to 32 bytes!"
#define ALIGNED32
#endif
somewhere else?

Why? First it deals with the compiler issue in one place. Adding a different compiler is easier when this is concentrated somewhere. Second it makes the code shorter and more readable. The code now clearly shows that the buffer needs 32-byte alignment, even if there is no way to indicate this to the compiler.

Re: Documentation/coding style suggestion....

Posted: Sat Jan 02, 2016 12:18 pm
by Giovanni
Probably the HAL should include a compiler-related abstraction module in order to implement that.

The problem are the dumb proprietary compilers that do not necessarily allow alignments, or implement them in a way that is not placeable in a macro like that.

Giovanni