Skip to content

Commit ddd45db

Browse files
author
Jarkko Paso
authored
Merge pull request #65 from ARMmbed/IOTTHD-2055
Common write 24-bit inverse implemented
2 parents 09056ed + 4720a2e commit ddd45db

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

mbed-client-libservice/common_functions.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,29 @@ NS_INLINE uint8_t *common_write_24_bit(uint_fast24_t value, uint8_t ptr[__static
114114
*/
115115
NS_INLINE uint_fast24_t common_read_24_bit(const uint8_t data_buf[__static 3]);
116116

117+
/*
118+
* Common write 24-bit variable to 8-bit pointer.
119+
*
120+
* Write 24 bits in little-endian byte order.
121+
*
122+
* \param value 24-bit variable
123+
* \param ptr pointer where data to be written
124+
*
125+
* \return updated pointer
126+
*/
127+
NS_INLINE uint8_t *common_write_24_bit_inverse(uint_fast24_t value, uint8_t ptr[__static 3]);
128+
129+
/*
130+
* Common read 24-bit variable from 8-bit pointer.
131+
*
132+
* Read 24 bits in little-endian byte order.
133+
*
134+
* \param data_buf pointer where data to be read
135+
*
136+
* \return 24-bit variable
137+
*/
138+
NS_INLINE uint_fast24_t common_read_24_bit_inverse(const uint8_t data_buf[__static 3]);
139+
117140
/*
118141
* Common write 16-bit variable to 8-bit pointer.
119142
*
@@ -420,6 +443,23 @@ COMMON_FUNCTIONS_FN uint_fast24_t common_read_24_bit(const uint8_t data_buf[__st
420443
return temp_24;
421444
}
422445

446+
COMMON_FUNCTIONS_FN uint8_t *common_write_24_bit_inverse(uint_fast24_t value, uint8_t ptr[__static 3])
447+
{
448+
*ptr++ = value;
449+
*ptr++ = value >> 8;
450+
*ptr++ = value >> 16;
451+
return ptr;
452+
}
453+
454+
COMMON_FUNCTIONS_FN uint_fast24_t common_read_24_bit_inverse(const uint8_t data_buf[__static 3])
455+
{
456+
uint_fast24_t temp_24;
457+
temp_24 = *data_buf++;
458+
temp_24 += (uint_fast24_t)(*data_buf++) << 8;
459+
temp_24 += (uint_fast24_t)(*data_buf++) << 16;
460+
return temp_24;
461+
}
462+
423463
COMMON_FUNCTIONS_FN uint8_t *common_write_16_bit(uint16_t value, uint8_t ptr[__static 2])
424464
{
425465
*ptr++ = value >> 8;

0 commit comments

Comments
 (0)