X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=cfg%2Fmacros.h;h=5d363173d6327a2c570053338cda9ea980ffd28e;hb=3278853417ff353379e9c9b98a03bab687e16167;hp=85fb97af6f960dcbc5a781eafcd89e272379deda;hpb=6bf26ad78b32851d9dd56fbf68356bcbdded590e;p=bertos.git diff --git a/cfg/macros.h b/cfg/macros.h index 85fb97af..5d363173 100755 --- a/cfg/macros.h +++ b/cfg/macros.h @@ -2,7 +2,7 @@ * \file * * * \brief Common and handy function macros @@ -14,6 +14,18 @@ /*#* *#* $Log$ + *#* Revision 1.5 2005/11/04 16:20:01 bernie + *#* Fix reference to README.devlib in header. + *#* + *#* Revision 1.4 2005/07/03 15:19:09 bernie + *#* Doxygen fix. + *#* + *#* Revision 1.3 2005/06/27 21:23:32 bernie + *#* ROUND_DOWN, ROUND_UP, ROUND_NEAREST: New macros. + *#* + *#* Revision 1.2 2005/04/11 19:10:27 bernie + *#* Include top-level headers from cfg/ subdir. + *#* *#* Revision 1.1 2005/04/11 19:04:13 bernie *#* Move top-level headers to cfg/ subdir. *#* @@ -67,7 +79,7 @@ #ifndef MACROS_H #define MACROS_H -#include +#include /* avr-gcc does not seem to support libstdc++ */ #if defined(__cplusplus) && !CPU_AVR @@ -136,6 +148,18 @@ /*! Round up \a x to an even multiple of the 2's power \a pad */ #define ROUND2(x, pad) (((x) + ((pad) - 1)) & ~((pad) - 1)) +/*! + * \name Integer round macros. + * + * Round \a x to a multiple of \a base. + * \note If \a x is signed these macros generate a lot of code. + * \{ + */ +#define ROUND_DOWN(x, base) ( (x) - ((x) % (base)) ) +#define ROUND_UP(x, base) ( ((x) + (base) - 1) - (((x) + (base) - 1) % (base)) ) +#define ROUND_NEAREST(x, base) ( ((x) + (base) / 2) - (((x) + (base) / 2) % (base)) ) +/* \} */ + //! Check if \a x is an integer power of 2 #define IS_POW2(x) (!(bool)((x) & ((x)-1)))