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 | |
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
-rw-r--r-- | apps/codecs/libmusepack/internal.h | 9 | ||||
-rw-r--r-- | apps/codecs/wav.c | 2 | ||||
-rw-r--r-- | apps/metadata.c | 4 | ||||
-rw-r--r-- | apps/plugins/midi/guspat.c | 7 | ||||
-rw-r--r-- | firmware/drivers/ata.c | 6 | ||||
-rw-r--r-- | firmware/drivers/fat.c | 56 | ||||
-rw-r--r-- | firmware/export/system.h | 59 | ||||
-rw-r--r-- | firmware/pcm_record.c | 6 |
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 { | |||
42 | MPC_DECODER_SYNTH_DELAY = 481 | 42 | MPC_DECODER_SYNTH_DELAY = 481 |
43 | }; | 43 | }; |
44 | 44 | ||
45 | /// Big/little endian 32 bit byte swapping routine. | ||
46 | static inline | ||
47 | mpc_uint32_t swap32(mpc_uint32_t val) { | ||
48 | const unsigned char* src = (const unsigned char*)&val; | ||
49 | return | ||
50 | (mpc_uint32_t)src[0] | | ||
51 | ((mpc_uint32_t)src[1] << 8) | ((mpc_uint32_t)src[2] << 16) | ((mpc_uint32_t)src[3] << 24); | ||
52 | } | ||
53 | |||
54 | /// Searches for a ID3v2-tag and reads the length (in bytes) of it. | 45 | /// Searches for a ID3v2-tag and reads the length (in bytes) of it. |
55 | /// \param reader supplying raw stream data | 46 | /// \param reader supplying raw stream data |
56 | /// \return size of tag, in bytes | 47 | /// \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) | |||
482 | else if (bitspersample > 8) { | 482 | else if (bitspersample > 8) { |
483 | /* Byte-swap data. */ | 483 | /* Byte-swap data. */ |
484 | for (i=0;i<n/2;i++) { | 484 | for (i=0;i<n/2;i++) { |
485 | int16_samples[i]=(int16_t)SWAB16(wavbuf[i]); | 485 | int16_samples[i]=(int16_t)letoh16(wavbuf[i]); |
486 | } | 486 | } |
487 | wavbufsize = n; | 487 | wavbufsize = n; |
488 | } | 488 | } |
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) | |||
152 | { | 152 | { |
153 | long* d = (long*) data; | 153 | long* d = (long*) data; |
154 | 154 | ||
155 | *d = SWAB32(*d); | 155 | *d = letoh32(*d); |
156 | data = d + 1; | 156 | data = d + 1; |
157 | } | 157 | } |
158 | 158 | ||
@@ -162,7 +162,7 @@ static void convert_endian(void *data, const char *format) | |||
162 | { | 162 | { |
163 | short* d = (short*) data; | 163 | short* d = (short*) data; |
164 | 164 | ||
165 | *d = SWAB16(*d); | 165 | *d = letoh16(*d); |
166 | data = d + 1; | 166 | data = d + 1; |
167 | } | 167 | } |
168 | 168 | ||
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) | |||
97 | */ | 97 | */ |
98 | 98 | ||
99 | 99 | ||
100 | /* Iriver needs byteswapping.. big endian, go figure. Gus files are little endian */ | 100 | #ifdef ROCKBOX_BIG_ENDIAN |
101 | 101 | /* Byte-swap if necessary. Gus files are little endian */ | |
102 | #if !defined(SIMULATOR) | ||
103 | for(a=0; a<wav->numSamples; a++) | 102 | for(a=0; a<wav->numSamples; a++) |
104 | { | 103 | { |
105 | ((unsigned short *) wav->data)[a] = SWAB16(((unsigned short *) wav->data)[a]); | 104 | ((unsigned short *) wav->data)[a] = letoh16(((unsigned short *) wav->data)[a]); |
106 | } | 105 | } |
107 | #endif | 106 | #endif |
108 | 107 | ||
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) | |||
362 | { /* loop compiles to 7 assembler instructions */ | 362 | { /* loop compiles to 7 assembler instructions */ |
363 | /* takes 12 clock cycles (2 pipeline stalls, 1 wait) */ | 363 | /* takes 12 clock cycles (2 pipeline stalls, 1 wait) */ |
364 | #ifdef SWAP_WORDS | 364 | #ifdef SWAP_WORDS |
365 | *wbuf = SWAB16(ATA_DATA); | 365 | *wbuf = letoh16(ATA_DATA); |
366 | #else | 366 | #else |
367 | *wbuf = ATA_DATA; | 367 | *wbuf = ATA_DATA; |
368 | #endif | 368 | #endif |
@@ -677,7 +677,7 @@ static void copy_write_sectors(const unsigned char* buf, int wordcount) | |||
677 | #ifdef SWAP_WORDS | 677 | #ifdef SWAP_WORDS |
678 | /* loop compiles to 6 assembler instructions */ | 678 | /* loop compiles to 6 assembler instructions */ |
679 | /* takes 10 clock cycles (2 pipeline stalls) */ | 679 | /* takes 10 clock cycles (2 pipeline stalls) */ |
680 | SET_16BITREG(ATA_DATA, SWAB16(*wbuf)); | 680 | SET_16BITREG(ATA_DATA, htole16(*wbuf)); |
681 | #else | 681 | #else |
682 | SET_16BITREG(ATA_DATA, *wbuf); | 682 | SET_16BITREG(ATA_DATA, *wbuf); |
683 | #endif | 683 | #endif |
@@ -1270,7 +1270,7 @@ static int identify(void) | |||
1270 | #ifdef SWAP_WORDS | 1270 | #ifdef SWAP_WORDS |
1271 | identify_info[i] = ATA_DATA; | 1271 | identify_info[i] = ATA_DATA; |
1272 | #else | 1272 | #else |
1273 | identify_info[i] = SWAB16(ATA_DATA); | 1273 | identify_info[i] = letoh16(ATA_DATA); |
1274 | #endif | 1274 | #endif |
1275 | } | 1275 | } |
1276 | 1276 | ||
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)) | |||
534 | if ( c > fat_bpb->dataclusters+1 ) /* nr 0 is unused */ | 534 | if ( c > fat_bpb->dataclusters+1 ) /* nr 0 is unused */ |
535 | break; | 535 | break; |
536 | 536 | ||
537 | if (SWAB16(fat[j]) == 0x0000) { | 537 | if (letoh16(fat[j]) == 0x0000) { |
538 | free++; | 538 | free++; |
539 | if ( fat_bpb->fsinfo.nextfree == 0xffffffff ) | 539 | if ( fat_bpb->fsinfo.nextfree == 0xffffffff ) |
540 | fat_bpb->fsinfo.nextfree = c; | 540 | fat_bpb->fsinfo.nextfree = c; |
@@ -553,7 +553,7 @@ void fat_recalc_free(IF_MV_NONVOID(int volume)) | |||
553 | if ( c > fat_bpb->dataclusters+1 ) /* nr 0 is unused */ | 553 | if ( c > fat_bpb->dataclusters+1 ) /* nr 0 is unused */ |
554 | break; | 554 | break; |
555 | 555 | ||
556 | if (!(SWAB32(fat[j]) & 0x0fffffff)) { | 556 | if (!(letoh32(fat[j]) & 0x0fffffff)) { |
557 | free++; | 557 | free++; |
558 | if ( fat_bpb->fsinfo.nextfree == 0xffffffff ) | 558 | if ( fat_bpb->fsinfo.nextfree == 0xffffffff ) |
559 | fat_bpb->fsinfo.nextfree = c; | 559 | fat_bpb->fsinfo.nextfree = c; |
@@ -740,7 +740,7 @@ static unsigned long find_free_cluster(IF_MV2(struct bpb* fat_bpb,) unsigned lon | |||
740 | break; | 740 | break; |
741 | for (j = 0; j < CLUSTERS_PER_FAT16_SECTOR; j++) { | 741 | for (j = 0; j < CLUSTERS_PER_FAT16_SECTOR; j++) { |
742 | int k = (j + offset) % CLUSTERS_PER_FAT16_SECTOR; | 742 | int k = (j + offset) % CLUSTERS_PER_FAT16_SECTOR; |
743 | if (SWAB16(fat[k]) == 0x0000) { | 743 | if (letoh16(fat[k]) == 0x0000) { |
744 | unsigned int c = nr * CLUSTERS_PER_FAT16_SECTOR + k; | 744 | unsigned int c = nr * CLUSTERS_PER_FAT16_SECTOR + k; |
745 | /* Ignore the reserved clusters 0 & 1, and also | 745 | /* Ignore the reserved clusters 0 & 1, and also |
746 | cluster numbers out of bounds */ | 746 | cluster numbers out of bounds */ |
@@ -768,7 +768,7 @@ static unsigned long find_free_cluster(IF_MV2(struct bpb* fat_bpb,) unsigned lon | |||
768 | break; | 768 | break; |
769 | for (j = 0; j < CLUSTERS_PER_FAT_SECTOR; j++) { | 769 | for (j = 0; j < CLUSTERS_PER_FAT_SECTOR; j++) { |
770 | int k = (j + offset) % CLUSTERS_PER_FAT_SECTOR; | 770 | int k = (j + offset) % CLUSTERS_PER_FAT_SECTOR; |
771 | if (!(SWAB32(fat[k]) & 0x0fffffff)) { | 771 | if (!(letoh32(fat[k]) & 0x0fffffff)) { |
772 | unsigned long c = nr * CLUSTERS_PER_FAT_SECTOR + k; | 772 | unsigned long c = nr * CLUSTERS_PER_FAT_SECTOR + k; |
773 | /* Ignore the reserved clusters 0 & 1, and also | 773 | /* Ignore the reserved clusters 0 & 1, and also |
774 | cluster numbers out of bounds */ | 774 | cluster numbers out of bounds */ |
@@ -819,17 +819,17 @@ static int update_fat_entry(IF_MV2(struct bpb* fat_bpb,) | |||
819 | } | 819 | } |
820 | 820 | ||
821 | if ( val ) { | 821 | if ( val ) { |
822 | if (SWAB16(sec[offset]) == 0x0000 && fat_bpb->fsinfo.freecount > 0) | 822 | if (htole16(sec[offset]) == 0x0000 && fat_bpb->fsinfo.freecount > 0) |
823 | fat_bpb->fsinfo.freecount--; | 823 | fat_bpb->fsinfo.freecount--; |
824 | } | 824 | } |
825 | else { | 825 | else { |
826 | if (SWAB16(sec[offset])) | 826 | if (htole16(sec[offset])) |
827 | fat_bpb->fsinfo.freecount++; | 827 | fat_bpb->fsinfo.freecount++; |
828 | } | 828 | } |
829 | 829 | ||
830 | LDEBUGF("update_fat_entry: %d free clusters\n", fat_bpb->fsinfo.freecount); | 830 | LDEBUGF("update_fat_entry: %d free clusters\n", fat_bpb->fsinfo.freecount); |
831 | 831 | ||
832 | sec[offset] = SWAB16(val); | 832 | sec[offset] = htole16(val); |
833 | } | 833 | } |
834 | else | 834 | else |
835 | #endif /* #ifdef HAVE_FAT16SUPPORT */ | 835 | #endif /* #ifdef HAVE_FAT16SUPPORT */ |
@@ -854,20 +854,20 @@ static int update_fat_entry(IF_MV2(struct bpb* fat_bpb,) | |||
854 | } | 854 | } |
855 | 855 | ||
856 | if ( val ) { | 856 | if ( val ) { |
857 | if (!(SWAB32(sec[offset]) & 0x0fffffff) && | 857 | if (!(htole32(sec[offset]) & 0x0fffffff) && |
858 | fat_bpb->fsinfo.freecount > 0) | 858 | fat_bpb->fsinfo.freecount > 0) |
859 | fat_bpb->fsinfo.freecount--; | 859 | fat_bpb->fsinfo.freecount--; |
860 | } | 860 | } |
861 | else { | 861 | else { |
862 | if (SWAB32(sec[offset]) & 0x0fffffff) | 862 | if (htole32(sec[offset]) & 0x0fffffff) |
863 | fat_bpb->fsinfo.freecount++; | 863 | fat_bpb->fsinfo.freecount++; |
864 | } | 864 | } |
865 | 865 | ||
866 | LDEBUGF("update_fat_entry: %ld free clusters\n", fat_bpb->fsinfo.freecount); | 866 | LDEBUGF("update_fat_entry: %ld free clusters\n", fat_bpb->fsinfo.freecount); |
867 | 867 | ||
868 | /* don't change top 4 bits */ | 868 | /* don't change top 4 bits */ |
869 | sec[offset] &= SWAB32(0xf0000000); | 869 | sec[offset] &= htole32(0xf0000000); |
870 | sec[offset] |= SWAB32(val & 0x0fffffff); | 870 | sec[offset] |= htole32(val & 0x0fffffff); |
871 | } | 871 | } |
872 | 872 | ||
873 | return 0; | 873 | return 0; |
@@ -892,7 +892,7 @@ static long read_fat_entry(IF_MV2(struct bpb* fat_bpb,) unsigned long entry) | |||
892 | return -1; | 892 | return -1; |
893 | } | 893 | } |
894 | 894 | ||
895 | return SWAB16(sec[offset]); | 895 | return letoh16(sec[offset]); |
896 | } | 896 | } |
897 | else | 897 | else |
898 | #endif /* #ifdef HAVE_FAT16SUPPORT */ | 898 | #endif /* #ifdef HAVE_FAT16SUPPORT */ |
@@ -908,7 +908,7 @@ static long read_fat_entry(IF_MV2(struct bpb* fat_bpb,) unsigned long entry) | |||
908 | return -1; | 908 | return -1; |
909 | } | 909 | } |
910 | 910 | ||
911 | return SWAB32(sec[offset]) & 0x0fffffff; | 911 | return letoh32(sec[offset]) & 0x0fffffff; |
912 | } | 912 | } |
913 | } | 913 | } |
914 | 914 | ||
@@ -960,10 +960,10 @@ static int update_fsinfo(IF_MV_NONVOID(struct bpb* fat_bpb)) | |||
960 | return rc * 10 - 1; | 960 | return rc * 10 - 1; |
961 | } | 961 | } |
962 | intptr = (long*)&(fsinfo[FSINFO_FREECOUNT]); | 962 | intptr = (long*)&(fsinfo[FSINFO_FREECOUNT]); |
963 | *intptr = SWAB32(fat_bpb->fsinfo.freecount); | 963 | *intptr = htole32(fat_bpb->fsinfo.freecount); |
964 | 964 | ||
965 | intptr = (long*)&(fsinfo[FSINFO_NEXTFREE]); | 965 | intptr = (long*)&(fsinfo[FSINFO_NEXTFREE]); |
966 | *intptr = SWAB32(fat_bpb->fsinfo.nextfree); | 966 | *intptr = htole32(fat_bpb->fsinfo.nextfree); |
967 | 967 | ||
968 | rc = ata_write_sectors(IF_MV2(fat_bpb->drive,) | 968 | rc = ata_write_sectors(IF_MV2(fat_bpb->drive,) |
969 | fat_bpb->startsector + fat_bpb->bpb_fsinfo,1,fsinfo); | 969 | fat_bpb->startsector + fat_bpb->bpb_fsinfo,1,fsinfo); |
@@ -1212,11 +1212,11 @@ static int write_long_name(struct fat_file* file, | |||
1212 | 1212 | ||
1213 | fat_time(&date, &time, &tenth); | 1213 | fat_time(&date, &time, &tenth); |
1214 | entry[FATDIR_CRTTIMETENTH] = tenth; | 1214 | entry[FATDIR_CRTTIMETENTH] = tenth; |
1215 | *(unsigned short*)(entry + FATDIR_CRTTIME) = SWAB16(time); | 1215 | *(unsigned short*)(entry + FATDIR_CRTTIME) = htole16(time); |
1216 | *(unsigned short*)(entry + FATDIR_WRTTIME) = SWAB16(time); | 1216 | *(unsigned short*)(entry + FATDIR_WRTTIME) = htole16(time); |
1217 | *(unsigned short*)(entry + FATDIR_CRTDATE) = SWAB16(date); | 1217 | *(unsigned short*)(entry + FATDIR_CRTDATE) = htole16(date); |
1218 | *(unsigned short*)(entry + FATDIR_WRTDATE) = SWAB16(date); | 1218 | *(unsigned short*)(entry + FATDIR_WRTDATE) = htole16(date); |
1219 | *(unsigned short*)(entry + FATDIR_LSTACCDATE) = SWAB16(date); | 1219 | *(unsigned short*)(entry + FATDIR_LSTACCDATE) = htole16(date); |
1220 | } | 1220 | } |
1221 | idx++; | 1221 | idx++; |
1222 | nameidx -= NAME_BYTES_PER_ENTRY; | 1222 | nameidx -= NAME_BYTES_PER_ENTRY; |
@@ -1520,13 +1520,13 @@ static int update_short_entry( struct fat_file* file, long size, int attr ) | |||
1520 | entry[FATDIR_ATTR] = attr & 0xFF; | 1520 | entry[FATDIR_ATTR] = attr & 0xFF; |
1521 | 1521 | ||
1522 | clusptr = (short*)(entry + FATDIR_FSTCLUSHI); | 1522 | clusptr = (short*)(entry + FATDIR_FSTCLUSHI); |
1523 | *clusptr = SWAB16(file->firstcluster >> 16); | 1523 | *clusptr = htole16(file->firstcluster >> 16); |
1524 | 1524 | ||
1525 | clusptr = (short*)(entry + FATDIR_FSTCLUSLO); | 1525 | clusptr = (short*)(entry + FATDIR_FSTCLUSLO); |
1526 | *clusptr = SWAB16(file->firstcluster & 0xffff); | 1526 | *clusptr = htole16(file->firstcluster & 0xffff); |
1527 | 1527 | ||
1528 | sizeptr = (long*)(entry + FATDIR_FILESIZE); | 1528 | sizeptr = (long*)(entry + FATDIR_FILESIZE); |
1529 | *sizeptr = SWAB32(size); | 1529 | *sizeptr = htole32(size); |
1530 | 1530 | ||
1531 | { | 1531 | { |
1532 | #ifdef HAVE_RTC | 1532 | #ifdef HAVE_RTC |
@@ -1534,13 +1534,13 @@ static int update_short_entry( struct fat_file* file, long size, int attr ) | |||
1534 | unsigned short date = 0; | 1534 | unsigned short date = 0; |
1535 | #else | 1535 | #else |
1536 | /* get old time to increment from */ | 1536 | /* get old time to increment from */ |
1537 | unsigned short time = SWAB16(*(unsigned short*)(entry + FATDIR_WRTTIME)); | 1537 | unsigned short time = htole16(*(unsigned short*)(entry + FATDIR_WRTTIME)); |
1538 | unsigned short date = SWAB16(*(unsigned short*)(entry + FATDIR_WRTDATE)); | 1538 | unsigned short date = htole16(*(unsigned short*)(entry + FATDIR_WRTDATE)); |
1539 | #endif | 1539 | #endif |
1540 | fat_time(&date, &time, NULL); | 1540 | fat_time(&date, &time, NULL); |
1541 | *(unsigned short*)(entry + FATDIR_WRTTIME) = SWAB16(time); | 1541 | *(unsigned short*)(entry + FATDIR_WRTTIME) = htole16(time); |
1542 | *(unsigned short*)(entry + FATDIR_WRTDATE) = SWAB16(date); | 1542 | *(unsigned short*)(entry + FATDIR_WRTDATE) = htole16(date); |
1543 | *(unsigned short*)(entry + FATDIR_LSTACCDATE) = SWAB16(date); | 1543 | *(unsigned short*)(entry + FATDIR_LSTACCDATE) = htole16(date); |
1544 | } | 1544 | } |
1545 | 1545 | ||
1546 | rc = fat_seek( &dir, sector ); | 1546 | 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); | |||
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 |
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) | |||
354 | 354 | ||
355 | for (i=0; i<EACH_BUFFER_SIZE * num_ready / 4; i++) | 355 | for (i=0; i<EACH_BUFFER_SIZE * num_ready / 4; i++) |
356 | { | 356 | { |
357 | *ptr = SWAB32(*ptr); | 357 | *ptr = htole32(*ptr); |
358 | ptr++; | 358 | ptr++; |
359 | } | 359 | } |
360 | 360 | ||
@@ -476,11 +476,11 @@ static void close_wave(void) | |||
476 | { | 476 | { |
477 | long l; | 477 | long l; |
478 | 478 | ||
479 | l = SWAB32(num_rec_bytes + 36); | 479 | l = htole32(num_rec_bytes + 36); |
480 | lseek(wav_file, 4, SEEK_SET); | 480 | lseek(wav_file, 4, SEEK_SET); |
481 | write(wav_file, &l, 4); | 481 | write(wav_file, &l, 4); |
482 | 482 | ||
483 | l = SWAB32(num_rec_bytes); | 483 | l = htole32(num_rec_bytes); |
484 | lseek(wav_file, 40, SEEK_SET); | 484 | lseek(wav_file, 40, SEEK_SET); |
485 | write(wav_file, &l, 4); | 485 | write(wav_file, &l, 4); |
486 | 486 | ||