tte_byteorder.h

Go to the documentation of this file.
00001 /* -*- coding: iso-8859-1 -*-
00002  * Copyright (C) 2008 TTTech Computertechnik AG
00003  * ****************************************************************************
00004  * Name
00005  *    tte_environment.h
00006  *
00007  * Purpose
00008  *    Provide platform-independent data types, constants, helper functins, etc
00009  *
00010  * Revision Dates
00011  *    6-Mai-2008 Creation
00012  *   05-Nov-2008 (KSE) [29628] Include string, ose and target for __OSE
00013  *   01-Dec-2008 (KSE) [29628] Implement MISRA_2004 rules
00014  *   02-Dec-2008 (KSE) [29628] Changed include names
00015  *--
00016  */
00017 
00018 #ifndef TTE_BYTEORDER_H_
00019 #define TTE_BYTEORDER_H_
00020 
00021 #define BIG_ENDIAN
00022 
00023 //#pragma ghs startnomisra
00024 #ifdef OS_ARCH_LINUX
00025 
00026 #include <asm/byteorder.h>
00027 #        define tte_cpu_to_be16(x)  __cpu_to_be16(x)
00028 #        define tte_cpu_to_be32(x)  __cpu_to_be32(x)
00029 #        define tte_cpu_to_be64(x)  __cpu_to_be64(x)
00030 
00031 #        define tte_be16_to_cpu(x)  __be16_to_cpu(x)
00032 #        define tte_be32_to_cpu(x)  __be32_to_cpu(x)
00033 #        define tte_be64_to_cpu(x)  __be64_to_cpu(x)
00034 
00035 #        define tte_cpu_to_le16(x)  __cpu_to_le16(x)
00036 #        define tte_cpu_to_le32(x)  __cpu_to_le32(x)
00037 #        define tte_cpu_to_le64(x)  __cpu_to_le64(x)
00038 
00039 #        define tte_le16_to_cpu(x)  __le16_to_cpu(x)
00040 #        define tte_le32_to_cpu(x)  __le32_to_cpu(x)
00041 #        define tte_le64_to_cpu(x)  __le64_to_cpu(x)
00042 
00043 #else
00044 
00045 
00046 #if defined(LITTLE_ENDIAN) && defined(BIG_ENDIAN)
00047 #        error "You cannot have it both ways"
00048 #endif
00049 
00050 #if !defined(LITTLE_ENDIAN) && !defined(BIG_ENDIAN)
00051 #        error "You must define LITTLE_ENDIAN or BIG_ENDIAN"
00052 #endif
00053 
00054 
00055 
00056 
00057 #ifdef BIG_ENDIAN
00058 #        define tte_cpu_to_be16(x)  ((uint16_t)(x))
00059 #        define tte_cpu_to_be32(x)  ((uint32_t)(x))
00060 #        define tte_cpu_to_be64(x)  ((uint64_t)(x))
00061 
00062 #        define tte_be16_to_cpu(x)  ((uint16_t)(x))
00063 #        define tte_be32_to_cpu(x)  ((uint32_t)(x))
00064 #        define tte_be64_to_cpu(x)  ((uint64_t)(x))
00065 
00066 #        define tte_cpu_to_le16(x)  swab16(x)
00067 #        define tte_cpu_to_le32(x)  swab32(x)
00068 #        define tte_cpu_to_le64(x)  swab64(x)
00069 
00070 #        define tte_le16_to_cpu(x)  swab16(x)
00071 #        define tte_le32_to_cpu(x)  swab32(x)
00072 #        define tte_le64_to_cpu(x)  swab64(x)
00073 
00074 #endif
00075 
00076 #ifdef LITTLE_ENDIAN
00077 
00078 /*
00079 static uint16_t swab16(uint16_t x)
00080 {
00081     return (uint16_t)(x>>8) | (uint16_t)(x<<8);
00082 }
00083 
00084 static uint32_t swab32(uint32_t x)
00085 {
00086     return   ( (uint32_t)((uint32_t)x>>24u) & 0xFF)
00087            | ( (uint32_t)((uint32_t)x>>8u)  & 0XFF00 )
00088            | ( (uint32_t)((uint32_t)x<<8u)  & 0XFF0000 )
00089            | ( (uint32_t)((uint32_t)x<<24u) & 0XFF000000 );
00090 }
00091 
00092 static uint64_t swab64(uint64_t x)
00093 {
00094     return   ( (uint64_t)((uint64_t)x>>56u) & 0xFF)
00095            | ( (uint64_t)((uint64_t)x>>40u) & 0XFF00 )
00096            | ( (uint64_t)((uint64_t)x>>24u) & 0XFF0000 )
00097            | ( (uint64_t)((uint64_t)x>>8u)  & 0XFF000000 )
00098            | ( (uint64_t)((uint64_t)x<<8u)  & 0XFF00000000 )
00099            | ( (uint64_t)((uint64_t)x<<24u) & 0XFF0000000000 )
00100            | ( (uint64_t)((uint64_t)x<<40u) & 0XFF000000000000 )
00101            | ( (uint64_t)((uint64_t)x<<56u) & 0XFF00000000000000 );
00102 }*/
00103 
00104 static unsigned short swab16(unsigned short x)
00105 {
00106     return (unsigned short)(x>>8) | (unsigned short)(x<<8);
00107 }
00108 
00109 static unsigned long swab32(unsigned long x)
00110 {
00111     return   ( (unsigned long)((unsigned long)x>>24u) & 0xFF)
00112            | ( (unsigned long)((unsigned long)x>>8u)  & 0XFF00 )
00113            | ( (unsigned long)((unsigned long)x<<8u)  & 0XFF0000 )
00114            | ( (unsigned long)((unsigned long)x<<24u) & 0XFF000000 );
00115 }
00116 
00117 static unsigned long long swab64(unsigned long long x)
00118 {
00119     return   ( (unsigned long long)((unsigned long long)x>>56u) & 0xFF)
00120            | ( (unsigned long long)((unsigned long long)x>>40u) & 0XFF00 )
00121            | ( (unsigned long long)((unsigned long long)x>>24u) & 0XFF0000 )
00122            | ( (unsigned long long)((unsigned long long)x>>8u)  & 0XFF000000 )
00123            | ( (unsigned long long)((unsigned long long)x<<8u)  & 0XFF00000000 )
00124            | ( (unsigned long long)((unsigned long long)x<<24u) & 0XFF0000000000 )
00125            | ( (unsigned long long)((unsigned long long)x<<40u) & 0XFF000000000000 )
00126            | ( (unsigned long long)((unsigned long long)x<<56u) & 0XFF00000000000000 );
00127 }
00128 
00129 
00130 #        define tte_cpu_to_be16(x)  swab16(x)
00131 #        define tte_cpu_to_be32(x)  swab32(x)
00132 #        define tte_cpu_to_be64(x)  swab64(x)
00133 
00134 #        define tte_be16_to_cpu(x)  swab16(x)
00135 #        define tte_be32_to_cpu(x)  swab32(x)
00136 #        define tte_be64_to_cpu(x)  swab64(x)
00137 
00138 #        define tte_cpu_to_le16(x)  ((uint16_t)(x))
00139 #        define tte_cpu_to_le32(x)  ((uint32_t)(x))
00140 #        define tte_cpu_to_le64(x)  ((uint64_t)(x))
00141 
00142 #        define tte_le16_to_cpu(x)  ((uint16_t)(x))
00143 #        define tte_le32_to_cpu(x)  ((uint32_t)(x))
00144 #        define tte_le64_to_cpu(x)  ((uint64_t)(x))
00145 #endif
00146 
00147 #endif /* not a linux ARCH*/
00148 
00149 //#pragma ghs endnomisra
00150 #endif /* end of H file */
00151 
00152 
Generated on Tue Nov 29 14:09:18 2011 for TTEthernet Model for INET Framework by  doxygen 1.6.3