summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--apps/codecs/libmusepack/internal.h9
-rw-r--r--apps/codecs/wav.c2
-rw-r--r--apps/metadata.c4
-rw-r--r--apps/plugins/midi/guspat.c7
-rw-r--r--firmware/drivers/ata.c6
-rw-r--r--firmware/drivers/fat.c56
-rw-r--r--firmware/export/system.h59
-rw-r--r--firmware/pcm_record.c6
8 files changed, 89 insertions, 60 deletions
diff --git a/apps/codecs/libmusepack/internal.h b/apps/codecs/libmusepack/internal.h
index a912bfc0ab..27656d5a54 100644
--- a/apps/codecs/libmusepack/internal.h
+++ b/apps/codecs/libmusepack/internal.h
@@ -42,15 +42,6 @@ enum {
MPC_DECODER_SYNTH_DELAY = 481
};
-/// Big/little endian 32 bit byte swapping routine.
-static inline
-mpc_uint32_t swap32(mpc_uint32_t val) {
- const unsigned char* src = (const unsigned char*)&val;
- return
- (mpc_uint32_t)src[0] |
- ((mpc_uint32_t)src[1] << 8) | ((mpc_uint32_t)src[2] << 16) | ((mpc_uint32_t)src[3] << 24);
-}
-
/// Searches for a ID3v2-tag and reads the length (in bytes) of it.
/// \param reader supplying raw stream data
/// \return size of tag, in bytes
diff --git a/apps/codecs/wav.c b/apps/codecs/wav.c
index 36076caf25..2806409dd5 100644
--- a/apps/codecs/wav.c
+++ b/apps/codecs/wav.c
@@ -482,7 +482,7 @@ enum codec_status codec_start(struct codec_api* api)
else if (bitspersample > 8) {
/* Byte-swap data. */
for (i=0;i<n/2;i++) {
- int16_samples[i]=(int16_t)SWAB16(wavbuf[i]);
+ int16_samples[i]=(int16_t)letoh16(wavbuf[i]);
}
wavbufsize = n;
}
diff --git a/apps/metadata.c b/apps/metadata.c
index 0cf0890886..86e0887231 100644
--- a/apps/metadata.c
+++ b/apps/metadata.c
@@ -152,7 +152,7 @@ static void convert_endian(void *data, const char *format)
{
long* d = (long*) data;
- *d = SWAB32(*d);
+ *d = letoh32(*d);
data = d + 1;
}
@@ -162,7 +162,7 @@ static void convert_endian(void *data, const char *format)
{
short* d = (short*) data;
- *d = SWAB16(*d);
+ *d = letoh16(*d);
data = d + 1;
}
diff --git a/apps/plugins/midi/guspat.c b/apps/plugins/midi/guspat.c
index 23b6811542..6f1866cd58 100644
--- a/apps/plugins/midi/guspat.c
+++ b/apps/plugins/midi/guspat.c
@@ -97,12 +97,11 @@ struct GWaveform * loadWaveform(int file)
*/
- /* Iriver needs byteswapping.. big endian, go figure. Gus files are little endian */
-
-#if !defined(SIMULATOR)
+#ifdef ROCKBOX_BIG_ENDIAN
+ /* Byte-swap if necessary. Gus files are little endian */
for(a=0; a<wav->numSamples; a++)
{
- ((unsigned short *) wav->data)[a] = SWAB16(((unsigned short *) wav->data)[a]);
+ ((unsigned short *) wav->data)[a] = letoh16(((unsigned short *) wav->data)[a]);
}
#endif
diff --git a/firmware/drivers/ata.c b/firmware/drivers/ata.c
index 61365094bc..475b1257a6 100644
--- a/firmware/drivers/ata.c
+++ b/firmware/drivers/ata.c
@@ -362,7 +362,7 @@ static void copy_read_sectors(unsigned char* buf, int wordcount)
{ /* loop compiles to 7 assembler instructions */
/* takes 12 clock cycles (2 pipeline stalls, 1 wait) */
#ifdef SWAP_WORDS
- *wbuf = SWAB16(ATA_DATA);
+ *wbuf = letoh16(ATA_DATA);
#else
*wbuf = ATA_DATA;
#endif
@@ -677,7 +677,7 @@ static void copy_write_sectors(const unsigned char* buf, int wordcount)
#ifdef SWAP_WORDS
/* loop compiles to 6 assembler instructions */
/* takes 10 clock cycles (2 pipeline stalls) */
- SET_16BITREG(ATA_DATA, SWAB16(*wbuf));
+ SET_16BITREG(ATA_DATA, htole16(*wbuf));
#else
SET_16BITREG(ATA_DATA, *wbuf);
#endif
@@ -1270,7 +1270,7 @@ static int identify(void)
#ifdef SWAP_WORDS
identify_info[i] = ATA_DATA;
#else
- identify_info[i] = SWAB16(ATA_DATA);
+ identify_info[i] = letoh16(ATA_DATA);
#endif
}
diff --git a/firmware/drivers/fat.c b/firmware/drivers/fat.c
index e3e05f8523..5d430dd24e 100644
--- a/firmware/drivers/fat.c
+++ b/firmware/drivers/fat.c
@@ -534,7 +534,7 @@ void fat_recalc_free(IF_MV_NONVOID(int volume))
if ( c > fat_bpb->dataclusters+1 ) /* nr 0 is unused */
break;
- if (SWAB16(fat[j]) == 0x0000) {
+ if (letoh16(fat[j]) == 0x0000) {
free++;
if ( fat_bpb->fsinfo.nextfree == 0xffffffff )
fat_bpb->fsinfo.nextfree = c;
@@ -553,7 +553,7 @@ void fat_recalc_free(IF_MV_NONVOID(int volume))
if ( c > fat_bpb->dataclusters+1 ) /* nr 0 is unused */
break;
- if (!(SWAB32(fat[j]) & 0x0fffffff)) {
+ if (!(letoh32(fat[j]) & 0x0fffffff)) {
free++;
if ( fat_bpb->fsinfo.nextfree == 0xffffffff )
fat_bpb->fsinfo.nextfree = c;
@@ -740,7 +740,7 @@ static unsigned long find_free_cluster(IF_MV2(struct bpb* fat_bpb,) unsigned lon
break;
for (j = 0; j < CLUSTERS_PER_FAT16_SECTOR; j++) {
int k = (j + offset) % CLUSTERS_PER_FAT16_SECTOR;
- if (SWAB16(fat[k]) == 0x0000) {
+ if (letoh16(fat[k]) == 0x0000) {
unsigned int c = nr * CLUSTERS_PER_FAT16_SECTOR + k;
/* Ignore the reserved clusters 0 & 1, and also
cluster numbers out of bounds */
@@ -768,7 +768,7 @@ static unsigned long find_free_cluster(IF_MV2(struct bpb* fat_bpb,) unsigned lon
break;
for (j = 0; j < CLUSTERS_PER_FAT_SECTOR; j++) {
int k = (j + offset) % CLUSTERS_PER_FAT_SECTOR;
- if (!(SWAB32(fat[k]) & 0x0fffffff)) {
+ if (!(letoh32(fat[k]) & 0x0fffffff)) {
unsigned long c = nr * CLUSTERS_PER_FAT_SECTOR + k;
/* Ignore the reserved clusters 0 & 1, and also
cluster numbers out of bounds */
@@ -819,17 +819,17 @@ static int update_fat_entry(IF_MV2(struct bpb* fat_bpb,)
}
if ( val ) {
- if (SWAB16(sec[offset]) == 0x0000 && fat_bpb->fsinfo.freecount > 0)
+ if (htole16(sec[offset]) == 0x0000 && fat_bpb->fsinfo.freecount > 0)
fat_bpb->fsinfo.freecount--;
}
else {
- if (SWAB16(sec[offset]))
+ if (htole16(sec[offset]))
fat_bpb->fsinfo.freecount++;
}
LDEBUGF("update_fat_entry: %d free clusters\n", fat_bpb->fsinfo.freecount);
- sec[offset] = SWAB16(val);
+ sec[offset] = htole16(val);
}
else
#endif /* #ifdef HAVE_FAT16SUPPORT */
@@ -854,20 +854,20 @@ static int update_fat_entry(IF_MV2(struct bpb* fat_bpb,)
}
if ( val ) {
- if (!(SWAB32(sec[offset]) & 0x0fffffff) &&
+ if (!(htole32(sec[offset]) & 0x0fffffff) &&
fat_bpb->fsinfo.freecount > 0)
fat_bpb->fsinfo.freecount--;
}
else {
- if (SWAB32(sec[offset]) & 0x0fffffff)
+ if (htole32(sec[offset]) & 0x0fffffff)
fat_bpb->fsinfo.freecount++;
}
LDEBUGF("update_fat_entry: %ld free clusters\n", fat_bpb->fsinfo.freecount);
/* don't change top 4 bits */
- sec[offset] &= SWAB32(0xf0000000);
- sec[offset] |= SWAB32(val & 0x0fffffff);
+ sec[offset] &= htole32(0xf0000000);
+ sec[offset] |= htole32(val & 0x0fffffff);
}
return 0;
@@ -892,7 +892,7 @@ static long read_fat_entry(IF_MV2(struct bpb* fat_bpb,) unsigned long entry)
return -1;
}
- return SWAB16(sec[offset]);
+ return letoh16(sec[offset]);
}
else
#endif /* #ifdef HAVE_FAT16SUPPORT */
@@ -908,7 +908,7 @@ static long read_fat_entry(IF_MV2(struct bpb* fat_bpb,) unsigned long entry)
return -1;
}
- return SWAB32(sec[offset]) & 0x0fffffff;
+ return letoh32(sec[offset]) & 0x0fffffff;
}
}
@@ -960,10 +960,10 @@ static int update_fsinfo(IF_MV_NONVOID(struct bpb* fat_bpb))
return rc * 10 - 1;
}
intptr = (long*)&(fsinfo[FSINFO_FREECOUNT]);
- *intptr = SWAB32(fat_bpb->fsinfo.freecount);
+ *intptr = htole32(fat_bpb->fsinfo.freecount);
intptr = (long*)&(fsinfo[FSINFO_NEXTFREE]);
- *intptr = SWAB32(fat_bpb->fsinfo.nextfree);
+ *intptr = htole32(fat_bpb->fsinfo.nextfree);
rc = ata_write_sectors(IF_MV2(fat_bpb->drive,)
fat_bpb->startsector + fat_bpb->bpb_fsinfo,1,fsinfo);
@@ -1212,11 +1212,11 @@ static int write_long_name(struct fat_file* file,
fat_time(&date, &time, &tenth);
entry[FATDIR_CRTTIMETENTH] = tenth;
- *(unsigned short*)(entry + FATDIR_CRTTIME) = SWAB16(time);
- *(unsigned short*)(entry + FATDIR_WRTTIME) = SWAB16(time);
- *(unsigned short*)(entry + FATDIR_CRTDATE) = SWAB16(date);
- *(unsigned short*)(entry + FATDIR_WRTDATE) = SWAB16(date);
- *(unsigned short*)(entry + FATDIR_LSTACCDATE) = SWAB16(date);
+ *(unsigned short*)(entry + FATDIR_CRTTIME) = htole16(time);
+ *(unsigned short*)(entry + FATDIR_WRTTIME) = htole16(time);
+ *(unsigned short*)(entry + FATDIR_CRTDATE) = htole16(date);
+ *(unsigned short*)(entry + FATDIR_WRTDATE) = htole16(date);
+ *(unsigned short*)(entry + FATDIR_LSTACCDATE) = htole16(date);
}
idx++;
nameidx -= NAME_BYTES_PER_ENTRY;
@@ -1520,13 +1520,13 @@ static int update_short_entry( struct fat_file* file, long size, int attr )
entry[FATDIR_ATTR] = attr & 0xFF;
clusptr = (short*)(entry + FATDIR_FSTCLUSHI);
- *clusptr = SWAB16(file->firstcluster >> 16);
+ *clusptr = htole16(file->firstcluster >> 16);
clusptr = (short*)(entry + FATDIR_FSTCLUSLO);
- *clusptr = SWAB16(file->firstcluster & 0xffff);
+ *clusptr = htole16(file->firstcluster & 0xffff);
sizeptr = (long*)(entry + FATDIR_FILESIZE);
- *sizeptr = SWAB32(size);
+ *sizeptr = htole32(size);
{
#ifdef HAVE_RTC
@@ -1534,13 +1534,13 @@ static int update_short_entry( struct fat_file* file, long size, int attr )
unsigned short date = 0;
#else
/* get old time to increment from */
- unsigned short time = SWAB16(*(unsigned short*)(entry + FATDIR_WRTTIME));
- unsigned short date = SWAB16(*(unsigned short*)(entry + FATDIR_WRTDATE));
+ unsigned short time = htole16(*(unsigned short*)(entry + FATDIR_WRTTIME));
+ unsigned short date = htole16(*(unsigned short*)(entry + FATDIR_WRTDATE));
#endif
fat_time(&date, &time, NULL);
- *(unsigned short*)(entry + FATDIR_WRTTIME) = SWAB16(time);
- *(unsigned short*)(entry + FATDIR_WRTDATE) = SWAB16(date);
- *(unsigned short*)(entry + FATDIR_LSTACCDATE) = SWAB16(date);
+ *(unsigned short*)(entry + FATDIR_WRTTIME) = htole16(time);
+ *(unsigned short*)(entry + FATDIR_WRTDATE) = htole16(date);
+ *(unsigned short*)(entry + FATDIR_LSTACCDATE) = htole16(date);
}
rc = fat_seek( &dir, sector );
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);
#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
diff --git a/firmware/pcm_record.c b/firmware/pcm_record.c
index 6eb7bbcba8..cafbd71754 100644
--- a/firmware/pcm_record.c
+++ b/firmware/pcm_record.c
@@ -354,7 +354,7 @@ void pcmrec_callback(bool flush)
for (i=0; i<EACH_BUFFER_SIZE * num_ready / 4; i++)
{
- *ptr = SWAB32(*ptr);
+ *ptr = htole32(*ptr);
ptr++;
}
@@ -476,11 +476,11 @@ static void close_wave(void)
{
long l;
- l = SWAB32(num_rec_bytes + 36);
+ l = htole32(num_rec_bytes + 36);
lseek(wav_file, 4, SEEK_SET);
write(wav_file, &l, 4);
- l = SWAB32(num_rec_bytes);
+ l = htole32(num_rec_bytes);
lseek(wav_file, 40, SEEK_SET);
write(wav_file, &l, 4);