Moved byteorder macros to ecrt.h.
This commit is contained in:
parent
478448dd68
commit
0c998363fb
|
|
@ -99,11 +99,11 @@
|
|||
#ifndef __ECRT_H__
|
||||
#define __ECRT_H__
|
||||
|
||||
#include <asm/byteorder.h>
|
||||
|
||||
#ifdef __KERNEL__
|
||||
#include <asm/byteorder.h>
|
||||
#include <linux/types.h>
|
||||
#else
|
||||
#include <stdlib.h> // for size_t
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
|
|
@ -1057,6 +1057,46 @@ ec_request_state_t ecrt_voe_handler_execute(
|
|||
else *((uint8_t *) (DATA)) &= ~(1 << (POS)); \
|
||||
} 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
|
||||
*****************************************************************************/
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ using namespace std;
|
|||
|
||||
#include "CommandAlias.h"
|
||||
#include "sii_crc.h"
|
||||
#include "byteorder.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
|
|
@ -130,7 +129,7 @@ void CommandAlias::writeSlaveAlias(
|
|||
}
|
||||
|
||||
// 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);
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@
|
|||
using namespace std;
|
||||
|
||||
#include "CommandConfig.h"
|
||||
#include "byteorder.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
|
|
@ -174,11 +173,11 @@ void CommandConfig::showDetailedConfigs(
|
|||
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 << "???";
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@
|
|||
using namespace std;
|
||||
|
||||
#include "CommandDownload.h"
|
||||
#include "byteorder.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
|
|
@ -150,14 +149,14 @@ void CommandDownload::execute(MasterDevice &m, const StringVector &args)
|
|||
{
|
||||
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 @@ void CommandDownload::execute(MasterDevice &m, const StringVector &args)
|
|||
{
|
||||
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
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ using namespace std;
|
|||
|
||||
#include "CommandPhyWrite.h"
|
||||
#include "sii_crc.h"
|
||||
#include "byteorder.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@
|
|||
using namespace std;
|
||||
|
||||
#include "CommandSiiRead.h"
|
||||
#include "byteorder.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
|
|
@ -99,7 +98,7 @@ void CommandSiiRead::execute(MasterDevice &m, const StringVector &args)
|
|||
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 @@ void CommandSiiRead::execute(MasterDevice &m, const StringVector &args)
|
|||
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 @@ void CommandSiiRead::execute(MasterDevice &m, const StringVector &args)
|
|||
throwCommandException(err);
|
||||
}
|
||||
categoryHeader += 2 + categorySize;
|
||||
categoryType = le16tocpu(*categoryHeader);
|
||||
categoryType = le16_to_cpup(categoryHeader);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ using namespace std;
|
|||
|
||||
#include "CommandSiiWrite.h"
|
||||
#include "sii_crc.h"
|
||||
#include "byteorder.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
|
|
@ -173,14 +172,14 @@ void CommandSiiWrite::checkSiiData(
|
|||
|
||||
// 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 @@ void CommandSiiWrite::checkSiiData(
|
|||
throwCommandException(err);
|
||||
}
|
||||
categoryHeader += 2 + categorySize;
|
||||
categoryType = le16tocpu(*categoryHeader);
|
||||
categoryType = le16_to_cpup(categoryHeader);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@
|
|||
using namespace std;
|
||||
|
||||
#include "CommandUpload.h"
|
||||
#include "byteorder.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
|
|
@ -159,11 +158,11 @@ void CommandUpload::execute(MasterDevice &m, const StringVector &args)
|
|||
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 @@ void CommandUpload::execute(MasterDevice &m, const StringVector &args)
|
|||
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
|
||||
|
|
|
|||
|
|
@ -82,7 +82,6 @@ noinst_HEADERS = \
|
|||
CommandXml.h \
|
||||
MasterDevice.h \
|
||||
SdoCommand.h \
|
||||
byteorder.h \
|
||||
sii_crc.h
|
||||
|
||||
REV = `if test -s $(srcdir)/../svnrevision; then \
|
||||
|
|
|
|||
|
|
@ -1,40 +0,0 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
#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
|
||||
|
||||
/****************************************************************************/
|
||||
Loading…
Reference in New Issue