Split cpu/cpu.h in 3 files: irq, types and attr.
[bertos.git] / cfg / macros.h
old mode 100755 (executable)
new mode 100644 (file)
index 17ee788..5e9e25e
@@ -1,8 +1,33 @@
 /**
  * \file
  * <!--
+ * This file is part of BeRTOS.
+ *
+ * Bertos is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ * As a special exception, you may use this file as part of a free software
+ * library without restriction.  Specifically, if other files instantiate
+ * templates or use macros or inline functions from this file, or you compile
+ * this file and link it with other files to produce an executable, this
+ * file does not by itself cause the resulting executable to be covered by
+ * the GNU General Public License.  This exception does not however
+ * invalidate any other reasons why the executable file might be covered by
+ * the GNU General Public License.
+ *
  * Copyright 2003, 2004 Develer S.r.l. (http://www.develer.com/)
- * This file is part of DevLib - See README.devlib for information.
+ *
  * -->
  *
  * \brief Common and handy function macros
 
 /*#*
  *#* $Log$
+ *#* Revision 1.11  2007/02/06 15:22:12  asterix
+ *#* Add ROTL and ROTR macros for bit rotating.
+ *#*
+ *#* Revision 1.10  2006/09/13 18:31:37  bernie
+ *#* BV8(), BV16(), BV32(): New macros for CPUs with small word size; SWAP_T(): New macro to support old compilers.
+ *#*
  *#* Revision 1.9  2006/07/19 12:56:25  bernie
  *#* Convert to new Doxygen style.
  *#*
 
 #endif /* COMPILER_TYPEOF */
 
+/**
+ * Macro to swap \a a with \a b, with explicit type \a T for dumb C89 compilers.
+ *
+ * \note Arguments are evaluated multiple times.
+ */
+#define SWAP_T(a, b, T) \
+       do { \
+               T tmp; \
+               ASSERT_TYPE_IS(a, T); \
+               ASSERT_TYPE_IS(b, T); \
+               tmp = (a); \
+               (a) = (b); \
+               (b) = tmp; \
+       } while (0)
+
+
 #ifndef BV
        /** Convert a bit value to a binary flag. */
        #define BV(x)  (1<<(x))
 #endif
 
+/** Same as BV() but with 32 bit result */
+#define BV32(x)  ((uint32_t)1<<(x))
+
+/** Same as BV() but with 16 bit result */
+#define BV16(x)  ((uint16_t)1<<(x))
+
+/** Same as BV() but with 8 bit result */
+#define BV8(x)  ((uint8_t)1<<(x))
+
+
+
 /** Round up \a x to an even multiple of the 2's power \a pad. */
 #define ROUND_UP2(x, pad) (((x) + ((pad) - 1)) & ~((pad) - 1))
 
 
 #endif /* COMPILER_VARIADIC_MACROS */
 
+/**
+ * Macro for rotating bit left or right.
+ * \{
+ */
+#define ROTR(var, rot) (((var) >> (rot)) | ((var) << ((sizeof(var) * 8) - (rot))))
+#define ROTL(var, rot) (((var) << (rot)) | ((var) >> ((sizeof(var) * 8) - (rot))))
+/*\}*/
+
 #endif /* MACROS_H */