From 6f8f3541cdc5613251e81e6d9249decc8ae955db Mon Sep 17 00:00:00 2001 From: "Ake Hedman, Paradise of the Frog" Date: Wed, 25 Nov 2015 15:47:32 +0100 Subject: [PATCH] Added macros to construct signed integers from EEPROM content in a safe c standard way. --- common/vscp_firmware.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/common/vscp_firmware.h b/common/vscp_firmware.h index 0c72172b..62d559f5 100644 --- a/common/vscp_firmware.h +++ b/common/vscp_firmware.h @@ -65,6 +65,17 @@ low end hardware device. #include // This file should be in your project folder #include +// Macros + +// This macro construct a signed integer from two unsigned chars in a safe way +#define construct_signed16( msb, lsb ) ((int16_t)( (((uint16_t)msb)<<8) + \ + (uint16_t)lsb) ) + +// This macro construct a signed long from four unsigned chars in a safe way +#define construct_signed32( b0, b1, b2, b3 ) ((int32_t)( (((uint32_t)b0)<<24) + \ + (((uint32_t)b0)<<16) + \ + (((uint32_t)b0)<<8) + \ + ((uint32_t)b0); // ****************************************************************************** // VSCP Constants