aboutsummaryrefslogtreecommitdiffstats
path: root/libs/bitfield-c/src/bitfield/8byte.c
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2019-11-23 13:39:52 +0100
committerRomain Forlot <romain.forlot@iot.bzh>2020-01-09 15:55:03 +0100
commit78e8a778786bf3f9050e55d99dd2b4338e8f4a8e (patch)
tree8dde7b0f50ea497f7a79ba60909570305328cb26 /libs/bitfield-c/src/bitfield/8byte.c
parentd76433ade0b75c8cc2b45fdae52a21d7fb28f526 (diff)
bitfield-c: use unsigned int instead of uint8_t
Use unsigned int instead of uint8_t upon destination and source array length. This is needed to handle gathered multi-frames message data which could be greater than 1 simple messages. Bug-AGL: SPEC-2988 Change-Id: I107bff383c2d0771dbc2a30770ec5c195b1c22ac Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'libs/bitfield-c/src/bitfield/8byte.c')
-rw-r--r--libs/bitfield-c/src/bitfield/8byte.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/libs/bitfield-c/src/bitfield/8byte.c b/libs/bitfield-c/src/bitfield/8byte.c
index 9325ed1b..be46e825 100644
--- a/libs/bitfield-c/src/bitfield/8byte.c
+++ b/libs/bitfield-c/src/bitfield/8byte.c
@@ -6,13 +6,13 @@
#define EIGHTBYTE_BIT (8 * sizeof(uint64_t))
-uint8_t eightbyte_get_nibble(const uint64_t source, const uint8_t nibble_index,
+unsigned int eightbyte_get_nibble(const uint64_t source, const unsigned int nibble_index,
const bool data_is_big_endian) {
- return (uint8_t) eightbyte_get_bitfield(source, NIBBLE_SIZE * nibble_index,
+ return (unsigned int) eightbyte_get_bitfield(source, NIBBLE_SIZE * nibble_index,
NIBBLE_SIZE, data_is_big_endian);
}
-uint8_t eightbyte_get_byte(uint64_t source, const uint8_t byte_index,
+unsigned int eightbyte_get_byte(uint64_t source, const unsigned int byte_index,
const bool data_is_big_endian) {
if(data_is_big_endian) {
source = __builtin_bswap64(source);
@@ -23,8 +23,8 @@ uint8_t eightbyte_get_byte(uint64_t source, const uint8_t byte_index,
// TODO is this funciton necessary anymore? is it any faster for uint64_t than
// get_bitfield(data[], ...)? is the performance better on a 32 bit platform
// like the PIC32?
-uint64_t eightbyte_get_bitfield(uint64_t source, const uint16_t offset,
- const uint16_t bit_count, const bool data_is_big_endian) {
+uint64_t eightbyte_get_bitfield(uint64_t source, const unsigned int offset,
+ const unsigned int bit_count, const bool data_is_big_endian) {
int startByte = offset / CHAR_BIT;
int endByte = (offset + bit_count - 1) / CHAR_BIT;
@@ -32,11 +32,11 @@ uint64_t eightbyte_get_bitfield(uint64_t source, const uint16_t offset,
source = __builtin_bswap64(source);
}
- uint8_t* bytes = (uint8_t*)&source;
+ unsigned int* bytes = (unsigned int*)&source;
uint64_t ret = bytes[startByte];
if(startByte != endByte) {
// The lowest byte address contains the most significant bit.
- uint8_t i;
+ unsigned int i;
for(i = startByte + 1; i <= endByte; i++) {
ret = ret << 8;
ret = ret | bytes[i];
@@ -47,8 +47,8 @@ uint64_t eightbyte_get_bitfield(uint64_t source, const uint16_t offset,
return ret & bitmask(bit_count);
}
-bool eightbyte_set_bitfield(uint64_t value, const uint16_t offset,
- const uint16_t bit_count, uint64_t* destination) {
+bool eightbyte_set_bitfield(uint64_t value, const unsigned int offset,
+ const unsigned int bit_count, uint64_t* destination) {
if(value > bitmask(bit_count)) {
return false;
}