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.tar.gz rockbox-9e19c95d8efc78a22a32b4a77f9c4a0b4e64125c.zip |
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 c2246e1e70..313a9a8e4c 100644 --- a/firmware/export/system.h +++ b/firmware/export/system.h | |||
@@ -56,10 +56,26 @@ void cpu_idle_mode(bool on_off); | |||
56 | #endif | 56 | #endif |
57 | 57 | ||
58 | #ifdef ROCKBOX_LITTLE_ENDIAN | 58 | #ifdef ROCKBOX_LITTLE_ENDIAN |
59 | #define SWAB16(x) (x) | 59 | #define letoh16(x) (x) |
60 | #define SWAB32(x) (x) | 60 | #define letoh32(x) (x) |
61 | #define htole16(x) (x) | ||
62 | #define htole32(x) (x) | ||
63 | #define betoh16(x) swap16(x) | ||
64 | #define betoh32(x) swap32(x) | ||
65 | #define htobe16(x) swap16(x) | ||
66 | #define htobe32(x) swap32(x) | ||
67 | #else | ||
68 | #define letoh16(x) swap16(x) | ||
69 | #define letoh32(x) swap32(x) | ||
70 | #define htole16(x) swap16(x) | ||
71 | #define htole32(x) swap32(x) | ||
72 | #define betoh16(x) (x) | ||
73 | #define betoh32(x) (x) | ||
74 | #define htobe16(x) (x) | ||
75 | #define htobe32(x) (x) | ||
61 | #endif | 76 | #endif |
62 | 77 | ||
78 | |||
63 | #define nop \ | 79 | #define nop \ |
64 | asm volatile ("nop") | 80 | asm volatile ("nop") |
65 | 81 | ||
@@ -162,7 +178,7 @@ static inline int set_irq_level(int level) | |||
162 | return i; | 178 | return i; |
163 | } | 179 | } |
164 | 180 | ||
165 | static inline unsigned short SWAB16(unsigned short value) | 181 | static inline unsigned short swap16(unsigned short value) |
166 | /* | 182 | /* |
167 | result[15..8] = value[ 7..0]; | 183 | result[15..8] = value[ 7..0]; |
168 | result[ 7..0] = value[15..8]; | 184 | result[ 7..0] = value[15..8]; |
@@ -184,7 +200,7 @@ static inline unsigned long SWAW32(unsigned long value) | |||
184 | return result; | 200 | return result; |
185 | } | 201 | } |
186 | 202 | ||
187 | static inline unsigned long SWAB32(unsigned long value) | 203 | static inline unsigned long swap32(unsigned long value) |
188 | /* | 204 | /* |
189 | result[31..24] = value[ 7.. 0]; | 205 | result[31..24] = value[ 7.. 0]; |
190 | result[23..16] = value[15.. 8]; | 206 | result[23..16] = value[15.. 8]; |
@@ -212,7 +228,7 @@ static inline int set_irq_level(int level) | |||
212 | return oldlevel; | 228 | return oldlevel; |
213 | } | 229 | } |
214 | 230 | ||
215 | static inline unsigned short SWAB16(unsigned short value) | 231 | static inline unsigned short swap16(unsigned short value) |
216 | /* | 232 | /* |
217 | result[15..8] = value[ 7..0]; | 233 | result[15..8] = value[ 7..0]; |
218 | result[ 7..0] = value[15..8]; | 234 | result[ 7..0] = value[15..8]; |
@@ -231,7 +247,7 @@ static inline unsigned long SWAW32(unsigned long value) | |||
231 | return value; | 247 | return value; |
232 | } | 248 | } |
233 | 249 | ||
234 | static inline unsigned long SWAB32(unsigned long value) | 250 | static inline unsigned long swap32(unsigned long value) |
235 | /* | 251 | /* |
236 | result[31..24] = value[ 7.. 0]; | 252 | result[31..24] = value[ 7.. 0]; |
237 | result[23..16] = value[15.. 8]; | 253 | result[23..16] = value[15.. 8]; |
@@ -299,7 +315,7 @@ static inline int set_irq_level(int level) | |||
299 | return result; | 315 | return result; |
300 | } | 316 | } |
301 | 317 | ||
302 | static inline unsigned short SWAB16(unsigned short value) | 318 | static inline unsigned short swap16(unsigned short value) |
303 | /* | 319 | /* |
304 | result[15..8] = value[ 7..0]; | 320 | result[15..8] = value[ 7..0]; |
305 | result[ 7..0] = value[15..8]; | 321 | result[ 7..0] = value[15..8]; |
@@ -308,7 +324,7 @@ static inline unsigned short SWAB16(unsigned short value) | |||
308 | return (value >> 8) | (value << 8); | 324 | return (value >> 8) | (value << 8); |
309 | } | 325 | } |
310 | 326 | ||
311 | static inline unsigned long SWAB32(unsigned long value) | 327 | static inline unsigned long swap32(unsigned long value) |
312 | /* | 328 | /* |
313 | result[31..24] = value[ 7.. 0]; | 329 | result[31..24] = value[ 7.. 0]; |
314 | result[23..16] = value[15.. 8]; | 330 | result[23..16] = value[15.. 8]; |
@@ -316,8 +332,8 @@ static inline unsigned long SWAB32(unsigned long value) | |||
316 | result[ 7.. 0] = value[31..24]; | 332 | result[ 7.. 0] = value[31..24]; |
317 | */ | 333 | */ |
318 | { | 334 | { |
319 | unsigned long hi = SWAB16(value >> 16); | 335 | unsigned long hi = swap16(value >> 16); |
320 | unsigned long lo = SWAB16(value & 0xffff); | 336 | unsigned long lo = swap16(value & 0xffff); |
321 | return (lo << 16) | hi; | 337 | return (lo << 16) | hi; |
322 | } | 338 | } |
323 | 339 | ||
@@ -338,6 +354,29 @@ static inline unsigned long SWAB32(unsigned long value) | |||
338 | #endif | 354 | #endif |
339 | #else | 355 | #else |
340 | 356 | ||
357 | static inline unsigned short swap16(unsigned short value) | ||
358 | /* | ||
359 | result[15..8] = value[ 7..0]; | ||
360 | result[ 7..0] = value[15..8]; | ||
361 | */ | ||
362 | { | ||
363 | return (value >> 8) | (value << 8); | ||
364 | } | ||
365 | |||
366 | static inline unsigned long swap32(unsigned long value) | ||
367 | /* | ||
368 | result[31..24] = value[ 7.. 0]; | ||
369 | result[23..16] = value[15.. 8]; | ||
370 | result[15.. 8] = value[23..16]; | ||
371 | result[ 7.. 0] = value[31..24]; | ||
372 | */ | ||
373 | { | ||
374 | unsigned long hi = swap16(value >> 16); | ||
375 | unsigned long lo = swap16(value & 0xffff); | ||
376 | return (lo << 16) | hi; | ||
377 | } | ||
378 | |||
379 | |||
341 | #define invalidate_icache() | 380 | #define invalidate_icache() |
342 | 381 | ||
343 | #endif | 382 | #endif |