# HG changeset patch # User Florian Pose # Date 1223558657 0 # Node ID c19d273a9e762b884cbba9311ec38d4cbd9ea81a # Parent 8a081444a89a0cf982e3ffba033f910b8be3050f Moved byteorder macros to ecrt.h. diff -r 8a081444a89a -r c19d273a9e76 include/ecrt.h --- a/include/ecrt.h Thu Oct 09 13:23:07 2008 +0000 +++ b/include/ecrt.h Thu Oct 09 13:24:17 2008 +0000 @@ -99,11 +99,11 @@ #ifndef __ECRT_H__ #define __ECRT_H__ +#ifdef __KERNEL__ #include - -#ifdef __KERNEL__ #include #else +#include // for size_t #include #endif @@ -1058,6 +1058,46 @@ } while (0) /****************************************************************************** + * Byte-swapping functions for user space + *****************************************************************************/ + +#ifndef __KERNEL__ + +#if __BYTE_ORDER == __LITTLE_ENDIAN + +#define le16_to_cpu(x) x +#define le32_to_cpu(x) x + +#define cpu_to_le16(x) x +#define cpu_to_le32(x) x + +#elif __BYTE_ORDER == __BIG_ENDIAN + +#define swap16(x) \ + ((uint16_t)( \ + (((uint16_t)(x) & 0x00ffU) << 8) | \ + (((uint16_t)(x) & 0xff00U) >> 8) )) +#define swap32(x) \ + ((uint32_t)( \ + (((uint32_t)(x) & 0x000000ffUL) << 24) | \ + (((uint32_t)(x) & 0x0000ff00UL) << 8) | \ + (((uint32_t)(x) & 0x00ff0000UL) >> 8) | \ + (((uint32_t)(x) & 0xff000000UL) >> 24) )) + +#define le16_to_cpu(x) swap16(x) +#define le32_to_cpu(x) swap32(x) + +#define cpu_to_le16(x) swap16(x) +#define cpu_to_le32(x) swap32(x) + +#endif + +#define le16_to_cpup(x) le16_to_cpu(*((uint16_t *)(x))) +#define le32_to_cpup(x) le32_to_cpu(*((uint32_t *)(x))) + +#endif /* ifndef __KERNEL__ */ + +/****************************************************************************** * Read macros *****************************************************************************/ diff -r 8a081444a89a -r c19d273a9e76 tool/CommandAlias.cpp --- a/tool/CommandAlias.cpp Thu Oct 09 13:23:07 2008 +0000 +++ b/tool/CommandAlias.cpp Thu Oct 09 13:24:17 2008 +0000 @@ -11,7 +11,6 @@ #include "CommandAlias.h" #include "sii_crc.h" -#include "byteorder.h" /*****************************************************************************/ @@ -130,7 +129,7 @@ } // write new alias address in word 4 - data.words[4] = cputole16(alias); + data.words[4] = cpu_to_le16(alias); // calculate checksum over words 0 to 6 crc = calcSiiCrc((const uint8_t *) data.words, 14); diff -r 8a081444a89a -r c19d273a9e76 tool/CommandConfig.cpp --- a/tool/CommandConfig.cpp Thu Oct 09 13:23:07 2008 +0000 +++ b/tool/CommandConfig.cpp Thu Oct 09 13:24:17 2008 +0000 @@ -11,7 +11,6 @@ using namespace std; #include "CommandConfig.h" -#include "byteorder.h" /*****************************************************************************/ @@ -174,11 +173,11 @@ break; case 2: cout << "0x" << setw(4) - << le16tocpu(*(uint16_t *) &sdo.data); + << le16_to_cpup(&sdo.data); break; case 4: cout << "0x" << setw(8) - << le32tocpu(*(uint32_t *) &sdo.data); + << le32_to_cpup(&sdo.data); break; default: cout << "???"; diff -r 8a081444a89a -r c19d273a9e76 tool/CommandDownload.cpp --- a/tool/CommandDownload.cpp Thu Oct 09 13:23:07 2008 +0000 +++ b/tool/CommandDownload.cpp Thu Oct 09 13:24:17 2008 +0000 @@ -9,7 +9,6 @@ using namespace std; #include "CommandDownload.h" -#include "byteorder.h" /*****************************************************************************/ @@ -150,14 +149,14 @@ { int16_t val; strValue >> val; - *(int16_t *) data.data = cputole16(val); + *(int16_t *) data.data = cpu_to_le16(val); break; } case 0x0004: // int32 { int32_t val; strValue >> val; - *(int32_t *) data.data = cputole32(val); + *(int32_t *) data.data = cpu_to_le32(val); break; } case 0x0005: // uint8 @@ -173,14 +172,14 @@ { uint16_t val; strValue >> val; - *(uint16_t *) data.data = cputole16(val); + *(uint16_t *) data.data = cpu_to_le16(val); break; } case 0x0007: // uint32 { uint32_t val; strValue >> val; - *(uint32_t *) data.data = cputole32(val); + *(uint32_t *) data.data = cpu_to_le32(val); break; } case 0x0009: // string diff -r 8a081444a89a -r c19d273a9e76 tool/CommandPhyWrite.cpp --- a/tool/CommandPhyWrite.cpp Thu Oct 09 13:23:07 2008 +0000 +++ b/tool/CommandPhyWrite.cpp Thu Oct 09 13:24:17 2008 +0000 @@ -11,7 +11,6 @@ #include "CommandPhyWrite.h" #include "sii_crc.h" -#include "byteorder.h" /*****************************************************************************/ diff -r 8a081444a89a -r c19d273a9e76 tool/CommandSiiRead.cpp --- a/tool/CommandSiiRead.cpp Thu Oct 09 13:23:07 2008 +0000 +++ b/tool/CommandSiiRead.cpp Thu Oct 09 13:24:17 2008 +0000 @@ -9,7 +9,6 @@ using namespace std; #include "CommandSiiRead.h" -#include "byteorder.h" /*****************************************************************************/ @@ -99,7 +98,7 @@ if (data.nwords > 0x0040U) { // cycle through categories categoryHeader = data.words + 0x0040U; - categoryType = le16tocpu(*categoryHeader); + categoryType = le16_to_cpup(categoryHeader); while (categoryType != 0xffff) { cout << "SII Category 0x" << hex << setw(4) << categoryType @@ -109,7 +108,7 @@ err << "SII data seem to be corrupted!"; throwCommandException(err); } - categorySize = le16tocpu(*(categoryHeader + 1)); + categorySize = le16_to_cpup(categoryHeader + 1); cout << ", " << dec << categorySize << " words" << flush; if (categoryHeader + 2 + categorySize @@ -136,7 +135,7 @@ throwCommandException(err); } categoryHeader += 2 + categorySize; - categoryType = le16tocpu(*categoryHeader); + categoryType = le16_to_cpup(categoryHeader); } } } else { diff -r 8a081444a89a -r c19d273a9e76 tool/CommandSiiWrite.cpp --- a/tool/CommandSiiWrite.cpp Thu Oct 09 13:23:07 2008 +0000 +++ b/tool/CommandSiiWrite.cpp Thu Oct 09 13:24:17 2008 +0000 @@ -11,7 +11,6 @@ #include "CommandSiiWrite.h" #include "sii_crc.h" -#include "byteorder.h" /*****************************************************************************/ @@ -173,14 +172,14 @@ // cycle through categories to detect corruption categoryHeader = data->words + 0x0040U; - categoryType = le16tocpu(*categoryHeader); + categoryType = le16_to_cpup(categoryHeader); while (categoryType != 0xffff) { if (categoryHeader + 1 > data->words + data->nwords) { err << "SII data seem to be corrupted! " << "Use --force to write anyway."; throwCommandException(err); } - categorySize = le16tocpu(*(categoryHeader + 1)); + categorySize = le16_to_cpup(categoryHeader + 1); if (categoryHeader + 2 + categorySize + 1 > data->words + data->nwords) { err << "SII data seem to be corrupted! " @@ -188,7 +187,7 @@ throwCommandException(err); } categoryHeader += 2 + categorySize; - categoryType = le16tocpu(*categoryHeader); + categoryType = le16_to_cpup(categoryHeader); } } diff -r 8a081444a89a -r c19d273a9e76 tool/CommandUpload.cpp --- a/tool/CommandUpload.cpp Thu Oct 09 13:23:07 2008 +0000 +++ b/tool/CommandUpload.cpp Thu Oct 09 13:24:17 2008 +0000 @@ -9,7 +9,6 @@ using namespace std; #include "CommandUpload.h" -#include "byteorder.h" /*****************************************************************************/ @@ -159,11 +158,11 @@ cout << sval << " 0x" << hex << setw(2) << sval << endl; break; case 0x0003: // int16 - sval = le16tocpu(*(int16_t *) data.target); + sval = le16_to_cpup(data.target); cout << sval << " 0x" << hex << setw(4) << sval << endl; break; case 0x0004: // int32 - sval = le32tocpu(*(int32_t *) data.target); + sval = le32_to_cpup(data.target); cout << sval << " 0x" << hex << setw(8) << sval << endl; break; case 0x0005: // uint8 @@ -171,11 +170,11 @@ cout << uval << " 0x" << hex << setw(2) << uval << endl; break; case 0x0006: // uint16 - uval = le16tocpu(*(uint16_t *) data.target); + uval = le16_to_cpup(data.target); cout << uval << " 0x" << hex << setw(4) << uval << endl; break; case 0x0007: // uint32 - uval = le32tocpu(*(uint32_t *) data.target); + uval = le32_to_cpup(data.target); cout << uval << " 0x" << hex << setw(8) << uval << endl; break; case 0x0009: // string diff -r 8a081444a89a -r c19d273a9e76 tool/Makefile.am --- a/tool/Makefile.am Thu Oct 09 13:23:07 2008 +0000 +++ b/tool/Makefile.am Thu Oct 09 13:24:17 2008 +0000 @@ -82,7 +82,6 @@ CommandXml.h \ MasterDevice.h \ SdoCommand.h \ - byteorder.h \ sii_crc.h REV = `if test -s $(srcdir)/../svnrevision; then \ diff -r 8a081444a89a -r c19d273a9e76 tool/byteorder.h --- a/tool/byteorder.h Thu Oct 09 13:23:07 2008 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,40 +0,0 @@ -/***************************************************************************** - * - * $Id$ - * - ****************************************************************************/ - -#include - -/*****************************************************************************/ - -#define swap16(x) \ - ((uint16_t)( \ - (((uint16_t)(x) & 0x00ffU) << 8) | \ - (((uint16_t)(x) & 0xff00U) >> 8) )) -#define swap32(x) \ - ((uint32_t)( \ - (((uint32_t)(x) & 0x000000ffUL) << 24) | \ - (((uint32_t)(x) & 0x0000ff00UL) << 8) | \ - (((uint32_t)(x) & 0x00ff0000UL) >> 8) | \ - (((uint32_t)(x) & 0xff000000UL) >> 24) )) - -#if __BYTE_ORDER == __LITTLE_ENDIAN - -#define le16tocpu(x) x -#define le32tocpu(x) x - -#define cputole16(x) x -#define cputole32(x) x - -#elif __BYTE_ORDER == __BIG_ENDIAN - -#define le16tocpu(x) swap16(x) -#define le32tocpu(x) swap32(x) - -#define cputole16(x) swap16(x) -#define cputole32(x) swap32(x) - -#endif - -/****************************************************************************/