diff options
| author | Dave Chapman <dave@dchapman.com> | 2005-10-06 19:27:43 +0000 |
|---|---|---|
| committer | Dave Chapman <dave@dchapman.com> | 2005-10-06 19:27:43 +0000 |
| commit | 9e19c95d8efc78a22a32b4a77f9c4a0b4e64125c (patch) | |
| tree | 1d0bc7970de2cd2f4fa365614f84f12517ad1b5f /firmware/export | |
| parent | 1c3a83c44e6dd18990d813c2f12e83bab67f313a (diff) | |
| download | rockbox-9e19c95d8efc78a22a32b4a77f9c4a0b4e64125c.zip rockbox-9e19c95d8efc78a22a32b4a77f9c4a0b4e64125c.tar.gz rockbox-9e19c95d8efc78a22a32b4a77f9c4a0b4e64125c.tar.bz2 rockbox-9e19c95d8efc78a22a32b4a77f9c4a0b4e64125c.tar.xz | |
Replace SWAB16 and SWAB32 with a comprehensive set of byte-swap macros - letoh16, letoh32, htole16, htole32, betoh16, betoh32, htobe16 and htobe32
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@7584 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/export')
| -rw-r--r-- | firmware/export/system.h | 59 |
1 files changed, 49 insertions, 10 deletions
diff --git a/firmware/export/system.h b/firmware/export/system.h index c2246e1..313a9a8 100644 --- a/firmware/export/system.h +++ b/firmware/export/system.h @@ -56,10 +56,26 @@ void cpu_idle_mode(bool on_off); #endif #ifdef ROCKBOX_LITTLE_ENDIAN -#define SWAB16(x) (x) -#define SWAB32(x) (x) +#define letoh16(x) (x) +#define letoh32(x) (x) +#define htole16(x) (x) +#define htole32(x) (x) +#define betoh16(x) swap16(x) +#define betoh32(x) swap32(x) +#define htobe16(x) swap16(x) +#define htobe32(x) swap32(x) +#else +#define letoh16(x) swap16(x) +#define letoh32(x) swap32(x) +#define htole16(x) swap16(x) +#define htole32(x) swap32(x) +#define betoh16(x) (x) +#define betoh32(x) (x) +#define htobe16(x) (x) +#define htobe32(x) (x) #endif + #define nop \ asm volatile ("nop") @@ -162,7 +178,7 @@ static inline int set_irq_level(int level) return i; } -static inline unsigned short SWAB16(unsigned short value) +static inline unsigned short swap16(unsigned short value) /* result[15..8] = value[ 7..0]; result[ 7..0] = value[15..8]; @@ -184,7 +200,7 @@ static inline unsigned long SWAW32(unsigned long value) return result; } -static inline unsigned long SWAB32(unsigned long value) +static inline unsigned long swap32(unsigned long value) /* result[31..24] = value[ 7.. 0]; result[23..16] = value[15.. 8]; @@ -212,7 +228,7 @@ static inline int set_irq_level(int level) return oldlevel; } -static inline unsigned short SWAB16(unsigned short value) +static inline unsigned short swap16(unsigned short value) /* result[15..8] = value[ 7..0]; result[ 7..0] = value[15..8]; @@ -231,7 +247,7 @@ static inline unsigned long SWAW32(unsigned long value) return value; } -static inline unsigned long SWAB32(unsigned long value) +static inline unsigned long swap32(unsigned long value) /* result[31..24] = value[ 7.. 0]; result[23..16] = value[15.. 8]; @@ -299,7 +315,7 @@ static inline int set_irq_level(int level) return result; } -static inline unsigned short SWAB16(unsigned short value) +static inline unsigned short swap16(unsigned short value) /* result[15..8] = value[ 7..0]; result[ 7..0] = value[15..8]; @@ -308,7 +324,7 @@ static inline unsigned short SWAB16(unsigned short value) return (value >> 8) | (value << 8); } -static inline unsigned long SWAB32(unsigned long value) +static inline unsigned long swap32(unsigned long value) /* result[31..24] = value[ 7.. 0]; result[23..16] = value[15.. 8]; @@ -316,8 +332,8 @@ static inline unsigned long SWAB32(unsigned long value) result[ 7.. 0] = value[31..24]; */ { - unsigned long hi = SWAB16(value >> 16); - unsigned long lo = SWAB16(value & 0xffff); + unsigned long hi = swap16(value >> 16); + unsigned long lo = swap16(value & 0xffff); return (lo << 16) | hi; } @@ -338,6 +354,29 @@ static inline unsigned long SWAB32(unsigned long value) #endif #else +static inline unsigned short swap16(unsigned short value) + /* + result[15..8] = value[ 7..0]; + result[ 7..0] = value[15..8]; + */ +{ + return (value >> 8) | (value << 8); +} + +static inline unsigned long swap32(unsigned long value) + /* + result[31..24] = value[ 7.. 0]; + result[23..16] = value[15.. 8]; + result[15.. 8] = value[23..16]; + result[ 7.. 0] = value[31..24]; + */ +{ + unsigned long hi = swap16(value >> 16); + unsigned long lo = swap16(value & 0xffff); + return (lo << 16) | hi; +} + + #define invalidate_icache() #endif |