[PATCH 2/3] Use <sys/endian.h>

Sebastian Huber sebastian.huber at embedded-brains.de
Mon Jan 23 07:14:14 UTC 2017


Update #2803.
---
 c/src/libchip/ide/ata_internal.h               | 16 +++++-----------
 cpukit/libblock/include/rtems/ide_part_table.h | 18 +++++-------------
 cpukit/libfs/src/dosfs/fat.h                   | 18 +++++-------------
 cpukit/libmisc/shell/main_pci.c                |  4 ++--
 4 files changed, 17 insertions(+), 39 deletions(-)

diff --git a/c/src/libchip/ide/ata_internal.h b/c/src/libchip/ide/ata_internal.h
index 887199d..985b6f5 100644
--- a/c/src/libchip/ide/ata_internal.h
+++ b/c/src/libchip/ide/ata_internal.h
@@ -16,6 +16,7 @@
 #define __ATA_INTERNAL_H__
 
 #include <sys/param.h>
+#include <sys/endian.h>
 #include <rtems.h>
 #include <sys/types.h>
 #include <rtems/libio.h>
@@ -34,17 +35,10 @@ extern "C" {
  * Naming: Ca_b_c, where a: F = from, T = to, b: LE = little-endian,
  * BE = big-endian, c: W = word (16 bits), L = longword (32 bits)
  */
-#if (CPU_BIG_ENDIAN == TRUE)
-#    define CF_LE_W(v) CPU_swap_u16(v)
-#    define CF_LE_L(v) CPU_swap_u32(v)
-#    define CT_LE_W(v) CPU_swap_u16(v)
-#    define CT_LE_L(v) CPU_swap_u32(v)
-#else
-#    define CF_LE_W(v) (v)
-#    define CF_LE_L(v) (v)
-#    define CT_LE_W(v) (v)
-#    define CT_LE_L(v) (v)
-#endif
+#define CF_LE_W(v) le16toh(v)
+#define CF_LE_L(v) le32toh(v)
+#define CT_LE_W(v) htole16(v)
+#define CT_LE_L(v) htole32(v)
 
 #define ATA_UNDEFINED_VALUE   (-1)
 
diff --git a/cpukit/libblock/include/rtems/ide_part_table.h b/cpukit/libblock/include/rtems/ide_part_table.h
index c638e28..316ff61 100644
--- a/cpukit/libblock/include/rtems/ide_part_table.h
+++ b/cpukit/libblock/include/rtems/ide_part_table.h
@@ -26,6 +26,7 @@
 #include <errno.h>
 #include <sys/ioctl.h>
 #include <sys/types.h>
+#include <sys/endian.h>
 #include <sys/stat.h>
 #include <unistd.h>
 #include <fcntl.h>
@@ -57,19 +58,10 @@
 /*
  * Conversion from and to little-endian byte order. (no-op on i386/i486)
  */
-
-#if (CPU_BIG_ENDIAN == TRUE)
-#   define LE_TO_CPU_U16(v) CPU_swap_u16(v)
-#   define LE_TO_CPU_U32(v) CPU_swap_u32(v)
-#   define CPU_TO_LE_U16(v) CPU_swap_u16(v)
-#   define CPU_TO_LE_U32(v) CPU_swap_u32(v)
-#else
-#   define LE_TO_CPU_U16(v) (v)
-#   define LE_TO_CPU_U32(v) (v)
-#   define CPU_TO_LE_U16(v) (v)
-#   define CPU_TO_LE_U32(v) (v)
-#endif
-
+#define CF_LE_W(v) le16toh(v)
+#define CF_LE_L(v) le32toh(v)
+#define CT_LE_W(v) htole16(v)
+#define CT_LE_L(v) htole32(v)
 
 /*
  * sector_data_t --
diff --git a/cpukit/libfs/src/dosfs/fat.h b/cpukit/libfs/src/dosfs/fat.h
index 6b86679..8fcd17f 100644
--- a/cpukit/libfs/src/dosfs/fat.h
+++ b/cpukit/libfs/src/dosfs/fat.h
@@ -23,11 +23,11 @@
 #define __DOSFS_FAT_H__
 
 #include <sys/param.h>
+#include <sys/endian.h>
 #include <string.h>
 
 #include <rtems/seterr.h>
 
-#include <rtems/score/cpu.h>
 #include <errno.h>
 #include <rtems/bdbuf.h>
 
@@ -56,18 +56,10 @@ extern "C" {
  * Naming: Ca_b_c, where a: F = from, T = to, b: LE = little-endian,
  * BE = big-endian, c: W = word (16 bits), L = longword (32 bits)
  */
-
-#if (CPU_BIG_ENDIAN == TRUE)
-#    define CF_LE_W(v) CPU_swap_u16((uint16_t)(v))
-#    define CF_LE_L(v) CPU_swap_u32((uint32_t)(v))
-#    define CT_LE_W(v) CPU_swap_u16((uint16_t)(v))
-#    define CT_LE_L(v) CPU_swap_u32((uint32_t)(v))
-#else
-#    define CF_LE_W(v) (v)
-#    define CF_LE_L(v) (v)
-#    define CT_LE_W(v) (v)
-#    define CT_LE_L(v) (v)
-#endif
+#define CF_LE_W(v) le16toh(v)
+#define CF_LE_L(v) le32toh(v)
+#define CT_LE_W(v) htole16(v)
+#define CT_LE_L(v) htole32(v)
 
 #define FAT_HASH_SIZE   2
 #define FAT_HASH_MODULE FAT_HASH_SIZE
diff --git a/cpukit/libmisc/shell/main_pci.c b/cpukit/libmisc/shell/main_pci.c
index c1d9535..a71b3fd 100644
--- a/cpukit/libmisc/shell/main_pci.c
+++ b/cpukit/libmisc/shell/main_pci.c
@@ -19,7 +19,7 @@
 #include <pci.h>
 #include <pci/cfg.h>
 #include <pci/access.h>
-#include <rtems/endian.h>
+#include <sys/endian.h>
 #include <bsp.h> /* For PCI endianness config */
 
 #include <rtems.h>
@@ -416,7 +416,7 @@ static int pci_summary(void)
 	printf(" CFG LIBRARY:       %s\n", cfglib_strs[pci_config_lib_type]);
 	printf(" NO. PCI BUSES:     %d buses\n", pci_bus_count());
 	printf(" PCI ENDIAN:        %s\n", pci_endian ? "Big" : "Little");
-#if (CPU_LITTLE_ENDIAN == TRUE)
+#if BYTE_ORDER == LITTLE_ENDIAN
 	puts(" MACHINE ENDIAN:    Little");
 #else
 	puts(" MACHINE ENDIAN:    Big");
-- 
1.8.4.5



More information about the devel mailing list