Code Review
/
apps
/
agl-service-can-low-level.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
review
|
tree
raw
|
inline
| side by side
Enable warnings when compiling and fix a few.
[apps/agl-service-can-low-level.git]
/
src
/
bitfield
/
8byte.c
diff --git
a/src/bitfield/8byte.c
b/src/bitfield/8byte.c
index
845be8c
..
9325ed1
100644
(file)
--- a/
src/bitfield/8byte.c
+++ b/
src/bitfield/8byte.c
@@
-6,24
+6,29
@@
#define EIGHTBYTE_BIT (8 * sizeof(uint64_t))
#define EIGHTBYTE_BIT (8 * sizeof(uint64_t))
-uint64_t bitmask(const uint8_t bit_count) {
- return (((uint64_t)0x1) << bit_count) - 1;
+uint8_t eightbyte_get_nibble(const uint64_t source, const uint8_t nibble_index,
+ const bool data_is_big_endian) {
+ return (uint8_t) eightbyte_get_bitfield(source, NIBBLE_SIZE * nibble_index,
+ NIBBLE_SIZE, data_is_big_endian);
}
}
-static uint16_t bits_to_bytes(uint32_t bits) {
- uint8_t byte_count = bits / CHAR_BIT;
- if(
bits % CHAR_BIT != 0
) {
-
++byte_count
;
+uint8_t eightbyte_get_byte(uint64_t source, const uint8_t byte_index,
+ const bool data_is_big_endian) {
+ if(
data_is_big_endian
) {
+
source = __builtin_bswap64(source)
;
}
}
- return
byte_count
;
+ return
(source >> (EIGHTBYTE_BIT - ((byte_index + 1) * CHAR_BIT))) & 0xFF
;
}
}
-uint64_t get_bit_field(uint64_t source, const uint16_t offset,
- const uint16_t bit_count, bool big_endian) {
+// 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) {
int startByte = offset / CHAR_BIT;
int endByte = (offset + bit_count - 1) / CHAR_BIT;
int startByte = offset / CHAR_BIT;
int endByte = (offset + bit_count - 1) / CHAR_BIT;
- if(!big_endian) {
+ if(!
data_is_
big_endian) {
source = __builtin_bswap64(source);
}
source = __builtin_bswap64(source);
}
@@
-31,7
+36,7
@@
uint64_t get_bit_field(uint64_t source, const uint16_t offset,
uint64_t ret = bytes[startByte];
if(startByte != endByte) {
// The lowest byte address contains the most significant bit.
uint64_t ret = bytes[startByte];
if(startByte != endByte) {
// The lowest byte address contains the most significant bit.
-
in
t i;
+
uint8_
t i;
for(i = startByte + 1; i <= endByte; i++) {
ret = ret << 8;
ret = ret | bytes[i];
for(i = startByte + 1; i <= endByte; i++) {
ret = ret << 8;
ret = ret | bytes[i];
@@
-42,8
+47,8
@@
uint64_t get_bit_field(uint64_t source, const uint16_t offset,
return ret & bitmask(bit_count);
}
return ret & bitmask(bit_count);
}
-bool
set_bit_field(uint64_t* destination,
uint64_t value, const uint16_t offset,
- const uint16_t bit_count) {
+bool
eightbyte_set_bitfield(
uint64_t value, const uint16_t offset,
+ const uint16_t bit_count
, uint64_t* destination
) {
if(value > bitmask(bit_count)) {
return false;
}
if(value > bitmask(bit_count)) {
return false;
}
@@
-54,8
+59,3
@@
bool set_bit_field(uint64_t* destination, uint64_t value, const uint16_t offset,
*destination |= value;
return true;
}
*destination |= value;
return true;
}
-
-uint8_t nth_byte(const uint64_t source, const uint16_t byte_index) {
- return (source >> (EIGHTBYTE_BIT - ((byte_index + 1) * CHAR_BIT))) & 0xFF;
-}
-