diff options
author | Roman Yeryomin <roman@advem.lv> | 2014-03-04 00:32:10 +0200 |
---|---|---|
committer | Roman Yeryomin <roman@advem.lv> | 2014-03-04 00:32:10 +0200 |
commit | 3e146f1cf64b48b4deee5793f67dac98ea077900 (patch) | |
tree | bc49f27fa825291c58c41159633543dcd09a1fa4 | |
parent | da597ef4a2dad742d70d2fbd4d559b8cbb7179d0 (diff) |
Fix endianess0.0.2
Signed-off-by: Roman Yeryomin <roman@advem.lv>
-rw-r--r-- | rtkmib.c | 21 |
1 files changed, 16 insertions, 5 deletions
@@ -62,17 +62,28 @@ static int flash_read( char *mtd, int offset, int len, char *buf ) return err; } +int is_big_endian( void ) +{ + union { + uint32_t i; + char c[4]; + } e = { 0x01000000 }; + + return e.c[0]; +} + inline uint16_t swap16( uint16_t x ) { - return ((x >> 8) & 0xff) | (x << 8); + return is_big_endian()? x : ((x >> 8) & 0xff) | (x << 8); } inline uint32_t swap32( uint32_t x ) { - return (x >> 24) | - ((x << 8) & 0x00ff0000) | - ((x >> 8) & 0x0000ff00) | - (x << 24); + return is_big_endian()? x : + (x >> 24) | + ((x << 8) & 0x00ff0000) | + ((x >> 8) & 0x0000ff00) | + (x << 24); } #define RING_SIZE 4096 /* size of ring buffer, must be power of 2 */ |