summaryrefslogtreecommitdiffstats
path: root/libs/bitfield-c/src/bitfield/bitarray.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/bitarray.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/bitarray.c')
-rw-r--r--libs/bitfield-c/src/bitfield/bitarray.c30
1 files changed, 15 insertions, 15 deletions
diff --git a/libs/bitfield-c/src/bitfield/bitarray.c b/libs/bitfield-c/src/bitfield/bitarray.c
index dcb9a08f..ec786a11 100644
--- a/libs/bitfield-c/src/bitfield/bitarray.c
+++ b/libs/bitfield-c/src/bitfield/bitarray.c
@@ -15,15 +15,15 @@
bit_count = 0; \
} } while (0)
-static const uint8_t reverse_mask[] =
+static const unsigned int reverse_mask[] =
{ 0x55, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff };
-static const uint8_t reverse_mask_xor[] =
+static const unsigned int reverse_mask_xor[] =
{ 0xff, 0x7f, 0x3f, 0x1f, 0x0f, 0x07, 0x03, 0x01, 0x00 };
-bool copy_bits(const uint8_t* source_origin, const uint16_t source_length,
- const uint16_t source_offset, uint16_t bit_count,
- uint8_t* destination_origin, const uint16_t destination_length,
- const uint16_t destination_offset) {
+bool copy_bits(const uint8_t* source_origin, const unsigned int source_length,
+ const unsigned int source_offset, unsigned int bit_count,
+ uint8_t* destination_origin, const unsigned int destination_length,
+ const unsigned int destination_offset) {
if(bit_count < 1) {
return false;
}
@@ -108,8 +108,8 @@ bool copy_bits(const uint8_t* source_origin, const uint16_t source_length,
return true;
}
-uint16_t bits_to_bytes(uint32_t bits) {
- uint8_t byte_count = bits / CHAR_BIT;
+unsigned int bits_to_bytes(uint32_t bits) {
+ unsigned int byte_count = bits / CHAR_BIT;
if(bits % CHAR_BIT != 0) {
++byte_count;
}
@@ -121,14 +121,14 @@ uint16_t bits_to_bytes(uint32_t bits) {
*
* Returns: a bit position from 0 to 7.
*/
-uint8_t find_end_bit(const uint16_t numBits) {
+unsigned int find_end_bit(const unsigned int numBits) {
int endBit = numBits % CHAR_BIT;
return endBit == 0 ? CHAR_BIT : endBit;
}
-bool copy_bits_right_aligned(const uint8_t source[], const uint16_t source_length,
- const uint16_t offset, const uint16_t bit_count,
- uint8_t* destination, const uint16_t destination_length) {
+bool copy_bits_right_aligned(const uint8_t source[], const unsigned int source_length,
+ const unsigned int offset, const unsigned int bit_count,
+ uint8_t* destination, const unsigned int destination_length) {
return copy_bits(source, source_length, offset, bit_count, destination,
destination_length,
// provide a proper destination offset so the result is right
@@ -137,9 +137,9 @@ bool copy_bits_right_aligned(const uint8_t source[], const uint16_t source_lengt
CHAR_BIT - find_end_bit(bit_count));
}
-bool copy_bytes_right_aligned(const uint8_t source[], const uint16_t source_length,
- const uint16_t offset, const uint16_t byte_count,
- uint8_t* destination, const uint16_t destination_length) {
+bool copy_bytes_right_aligned(const uint8_t source[], const unsigned int source_length,
+ const unsigned int offset, const unsigned int byte_count,
+ uint8_t* destination, const unsigned int destination_length) {
return copy_bits_right_aligned(source, source_length, offset * CHAR_BIT,
byte_count * CHAR_BIT, destination, destination_length);
}