Fix swap macro (#2904)
* convert swap macroses to inline functions * clean-up workarounds
This commit is contained in:
parent
d69fc86f26
commit
fdfec5ea3c
|
@ -326,9 +326,7 @@ static void handleCrc32Check(TsChannelBase *tsChannel, ts_response_format_e mode
|
|||
|
||||
const char* start = getWorkingPageAddr() + offset;
|
||||
|
||||
uint32_t crc = crc32(start, count);
|
||||
// do not pass function as macro parameter that would cause same code to be invoked 4 times!
|
||||
crc = SWAP_UINT32(crc);
|
||||
uint32_t crc = SWAP_UINT32(crc32(start, count));
|
||||
tsChannel->sendResponse(mode, (const uint8_t *) &crc, 4);
|
||||
}
|
||||
|
||||
|
|
|
@ -155,9 +155,7 @@ void canMazdaRX8(CanCycle cycle) {
|
|||
|
||||
float kph = getVehicleSpeed();
|
||||
|
||||
int rpm = GET_RPM();
|
||||
// do not pass function as macro parameter that would cause same code to be invoked 2 times!
|
||||
msg.setShortValue(SWAP_UINT16(rpm * 4), 0);
|
||||
msg.setShortValue(SWAP_UINT16(GET_RPM() * 4), 0);
|
||||
msg.setShortValue(0xFFFF, 2);
|
||||
msg.setShortValue(SWAP_UINT16((int )(100 * kph + 10000)), 4);
|
||||
msg.setShortValue(0, 6);
|
||||
|
|
|
@ -13,9 +13,16 @@
|
|||
|
||||
// http://en.wikipedia.org/wiki/Endianness
|
||||
|
||||
#define SWAP_UINT16(x) (((x) << 8) | ((x) >> 8))
|
||||
static inline uint16_t SWAP_UINT16(uint16_t x)
|
||||
{
|
||||
return ((x << 8) | (x >> 8));
|
||||
}
|
||||
|
||||
#define SWAP_UINT32(x) ((((x) >> 24) & 0xff) | (((x) << 8) & 0xff0000) | (((x) >> 8) & 0xff00) | (((x) << 24) & 0xff000000))
|
||||
static inline uint32_t SWAP_UINT32(uint32_t x)
|
||||
{
|
||||
return (((x >> 24) & 0x000000ff) | ((x << 8) & 0x00ff0000) |
|
||||
((x >> 8) & 0x0000ff00) | ((x << 24) & 0xff000000));
|
||||
}
|
||||
|
||||
#define BIT(n) (UINT32_C(1) << (n))
|
||||
|
||||
|
|
Loading…
Reference in New Issue