summaryrefslogtreecommitdiff
path: root/firmware/drivers
diff options
context:
space:
mode:
authorDave Chapman <dave@dchapman.com>2005-10-06 19:27:43 +0000
committerDave Chapman <dave@dchapman.com>2005-10-06 19:27:43 +0000
commit9e19c95d8efc78a22a32b4a77f9c4a0b4e64125c (patch)
tree1d0bc7970de2cd2f4fa365614f84f12517ad1b5f /firmware/drivers
parent1c3a83c44e6dd18990d813c2f12e83bab67f313a (diff)
downloadrockbox-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/drivers')
-rw-r--r--firmware/drivers/ata.c6
-rw-r--r--firmware/drivers/fat.c56
2 files changed, 31 insertions, 31 deletions
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 );