summaryrefslogtreecommitdiffstats
path: root/libs/bitfield-c/src/bitfield/bitfield.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/bitfield.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/bitfield.c')
-rw-r--r--libs/bitfield-c/src/bitfield/bitfield.c28
1 files changed, 14 insertions, 14 deletions
diff --git a/libs/bitfield-c/src/bitfield/bitfield.c b/libs/bitfield-c/src/bitfield/bitfield.c
index 795f0208..e9077e1c 100644
--- a/libs/bitfield-c/src/bitfield/bitfield.c
+++ b/libs/bitfield-c/src/bitfield/bitfield.c
@@ -4,14 +4,14 @@
#include <stddef.h>
#include <sys/param.h>
-uint64_t bitmask(const uint8_t bit_count) {
+uint64_t bitmask(const unsigned int bit_count) {
return (((uint64_t)0x1) << bit_count) - 1;
}
-uint8_t get_nibble(const uint8_t source[], const uint8_t source_length,
- const uint8_t nibble_index) {
- uint8_t byte_index = nibble_index / 2;
- uint8_t result = get_byte(source, source_length, byte_index);
+unsigned int get_nibble(const uint8_t source[], const unsigned int source_length,
+ const unsigned int nibble_index) {
+ unsigned int byte_index = nibble_index / 2;
+ unsigned int result = get_byte(source, source_length, byte_index);
if(nibble_index % 2 == 0) {
result >>= NIBBLE_SIZE;
}
@@ -19,16 +19,16 @@ uint8_t get_nibble(const uint8_t source[], const uint8_t source_length,
return result;
}
-uint8_t get_byte(const uint8_t source[], const uint8_t source_length,
- const uint8_t byte_index) {
+unsigned int get_byte(const uint8_t source[], const unsigned int source_length,
+ const unsigned int byte_index) {
if(byte_index < source_length) {
return source[byte_index];
}
return 0;
}
-uint64_t get_bitfield(const uint8_t source[], const uint8_t source_length,
- const uint16_t offset, const uint16_t bit_count) {
+uint64_t get_bitfield(const uint8_t source[], const unsigned int source_length,
+ const unsigned int offset, const unsigned int bit_count) {
if(bit_count > 64 || bit_count < 1) {
// TODO error reporting?
return 0;
@@ -47,15 +47,15 @@ uint64_t get_bitfield(const uint8_t source[], const uint8_t source_length,
return combined.whole;
}
-bool set_nibble(const uint16_t nibble_index, const uint8_t value,
- uint8_t* destination, const uint16_t destination_length) {
+bool set_nibble(const unsigned int nibble_index, const unsigned int value,
+ uint8_t* destination, const unsigned int destination_length) {
return copy_bits(&value, CHAR_BIT, NIBBLE_SIZE, NIBBLE_SIZE, destination,
destination_length, nibble_index * NIBBLE_SIZE);
}
-bool set_bitfield(const uint64_t value, const uint16_t offset,
- const uint16_t bit_count, uint8_t destination[],
- uint16_t destination_length) {
+bool set_bitfield(const uint64_t value, const unsigned int offset,
+ const unsigned int bit_count, uint8_t destination[],
+ unsigned int destination_length) {
if(value > bitmask(bit_count)) {
return false;
}