X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=cpu.h;h=09240a0a68a7faeffe3bcd9f518847efa3fe2bee;hb=0512b7c964114137975fa9c9eaa9279997b05ce3;hp=626bd3e03b7dcf91dabe14d186672ce0b95c8694;hpb=b81657391042e045769c544cf749f2f382d6e9a5;p=bertos.git diff --git a/cpu.h b/cpu.h index 626bd3e0..09240a0a 100755 --- a/cpu.h +++ b/cpu.h @@ -3,7 +3,7 @@ * * * \brief CPU-specific definitions @@ -15,6 +15,15 @@ /* * $Log$ + * Revision 1.4 2004/07/20 16:06:04 bernie + * Add macros to handle endianess issues. + * + * Revision 1.3 2004/07/18 21:49:51 bernie + * Fixes for GCC 3.5. + * + * Revision 1.2 2004/06/03 11:27:09 bernie + * Add dual-license information. + * * Revision 1.1 2004/05/23 17:48:35 bernie * Add top-level files. * @@ -27,6 +36,11 @@ //! Initialization value for registers in stack frame #define CPU_REG_INIT_VALUE(reg) 0 +// Macros for determining CPU endianness +#define CPU_BIG_ENDIAN 0x1234 +#define CPU_LITTLE_ENDIAN 0x3412 + + #if defined(__IAR_SYSTEMS_ICC) || defined(__IAR_SYSTEMS_ICC__) /* 80C196 */ #define DISABLE_INTS disable_interrupt() @@ -40,6 +54,7 @@ #define CPU_REGS_CNT 16 #define CPU_STACK_GROWS_UPWARD 0 #define CPU_SP_ON_EMPTY_SLOT 0 + #define CPU_BYTE_ORDER CPU_LITTLE_ENDIAN #elif defined(__i386__) || defined(_MSC_VER) /* x86 */ @@ -54,6 +69,7 @@ #define CPU_REGS_CNT 7 #define CPU_STACK_GROWS_UPWARD 0 #define CPU_SP_ON_EMPTY_SLOT 0 + #define CPU_BYTE_ORDER CPU_LITTLE_ENDIAN #elif defined(__m56800E__) || defined(__m56800__) /* DSP56K */ @@ -74,6 +90,7 @@ #define CPU_SAVED_REGS_CNT 28 #define CPU_STACK_GROWS_UPWARD 1 #define CPU_SP_ON_EMPTY_SLOT 0 + #define CPU_BYTE_ORDER CPU_BIG_ENDIAN #undef CPU_REG_INIT_VALUE INLINE uint16_t CPU_REG_INIT_VALUE(int reg) @@ -91,9 +108,9 @@ #elif defined (__AVR__) - #define NOP asm volatile ("nop") - #define DISABLE_INTS cli() - #define ENABLE_INTS sei() + #define NOP asm volatile ("nop" ::) + #define DISABLE_INTS asm volatile ("cli" ::) + #define ENABLE_INTS asm volatile ("sei" ::) #define SCHEDULER_IDLE /* nothing */ #define DISABLE_IRQSAVE(x) \ @@ -119,7 +136,7 @@ #define CPU_SAVED_REGS_CNT 18 #define CPU_STACK_GROWS_UPWARD 0 #define CPU_SP_ON_EMPTY_SLOT 1 - + #define CPU_BYTE_ORDER CPU_LITTLE_ENDIAN #else #error Unknown CPU #endif @@ -196,4 +213,23 @@ CPU_PUSH_WORD((sp), (func)) #endif + +INLINE uint16_t htobe16(uint16_t n); +INLINE uint16_t htobe16(uint16_t n) +{ + if (CPU_BYTE_ORDER == CPU_LITTLE_ENDIAN) + n = n << 8 | n >> 8; + + return n; +} + +INLINE uint16_t htole16(uint16_t n); +INLINE uint16_t htole16(uint16_t n) +{ + if (CPU_BYTE_ORDER == CPU_BIG_ENDIAN) + n = n << 8 | n >> 8; + + return n; +} + #endif /* CPU_H */