Skip to content

Commit 474253e

Browse files
cleanup
1 parent 1e72383 commit 474253e

1 file changed

Lines changed: 12 additions & 44 deletions

File tree

libcanard/canard.c

Lines changed: 12 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,7 @@ const uint_least8_t canard_len_to_dlc[65] = {
111111
static size_t smaller(const size_t a, const size_t b) { return (a < b) ? a : b; }
112112
static size_t larger(const size_t a, const size_t b) { return (a > b) ? a : b; }
113113
static int64_t min_i64(const int64_t a, const int64_t b) { return (a < b) ? a : b; }
114-
static int64_t max_i64(const int64_t a, const int64_t b) { return (a > b) ? a : b; }
115114
static canard_us_t earlier(const canard_us_t a, const canard_us_t b) { return min_i64(a, b); }
116-
static canard_us_t later(const canard_us_t a, const canard_us_t b) { return max_i64(a, b); }
117115

118116
/// Used if intrinsics are not available.
119117
/// http://en.wikipedia.org/wiki/Hamming_weight#Efficient_implementation
@@ -298,35 +296,6 @@ static void delist(canard_list_t* const list, canard_listed_t* const member)
298296
CANARD_ASSERT((list->head != NULL) == (list->tail != NULL));
299297
}
300298

301-
/// Insert addendum after anchor. If anchor is NULL, insert at the head.
302-
/// If the item is already in the list, it will be delisted first. Can be used for moving to the specified position.
303-
static void enlist_after(canard_list_t* const list, canard_listed_t* const anchor, canard_listed_t* const addendum)
304-
{
305-
delist(list, addendum);
306-
CANARD_ASSERT((addendum->next == NULL) && (addendum->prev == NULL));
307-
CANARD_ASSERT((list->head != NULL) == (list->tail != NULL));
308-
if (anchor == NULL) {
309-
addendum->next = list->head;
310-
if (list->head != NULL) {
311-
list->head->prev = addendum;
312-
}
313-
list->head = addendum;
314-
if (list->tail == NULL) {
315-
list->tail = addendum;
316-
}
317-
} else {
318-
addendum->prev = anchor;
319-
addendum->next = anchor->next;
320-
if (anchor->next != NULL) {
321-
anchor->next->prev = addendum;
322-
} else {
323-
list->tail = addendum;
324-
}
325-
anchor->next = addendum;
326-
}
327-
CANARD_ASSERT((list->head != NULL) && (list->tail != NULL));
328-
}
329-
330299
/// Insert addendum before anchor. If anchor is NULL, insert at the tail.
331300
/// If the item is already in the list, it will be delisted first. Can be used for moving to the specified position.
332301
static void enlist_before(canard_list_t* const list, canard_listed_t* const anchor, canard_listed_t* const addendum)
@@ -357,7 +326,6 @@ static void enlist_before(canard_list_t* const list, canard_listed_t* const anch
357326
}
358327

359328
/// If the item is already in the list, it will be delisted first. Can be used for moving to the front/back.
360-
static void enlist_head(canard_list_t* const list, canard_listed_t* const member) { enlist_after(list, NULL, member); }
361329
static void enlist_tail(canard_list_t* const list, canard_listed_t* const member) { enlist_before(list, NULL, member); }
362330

363331
#define LIST_TAIL(list, owner_type, owner_field) LIST_MEMBER((list).tail, owner_type, owner_field)
@@ -591,7 +559,7 @@ static canard_txfer_t* txfer_new(const canard_mem_t mem,
591559
return tr;
592560
}
593561

594-
static bool txfer_is_reliable(canard_t* const self, canard_txfer_t* const tr)
562+
static bool txfer_is_reliable(const canard_t* const self, const canard_txfer_t* const tr)
595563
{
596564
return cavl2_is_inserted(self->tx.reliable, &tr->index_reliable);
597565
}
@@ -818,7 +786,7 @@ static tx_frame_t* tx_spool(canard_t* const self,
818786
}
819787
// Insert the CRC.
820788
if ((frame_offset < frame_size) && (offset == size)) {
821-
tail->data[frame_offset] = (byte_t)((crc >> 8U) & BYTE_MAX);
789+
tail->data[frame_offset] = (byte_t)((crc >> 8U) & BYTE_MAX); // NOLINT(*-signed-bitwise)
822790
++frame_offset;
823791
++offset;
824792
}
@@ -855,16 +823,16 @@ static tx_frame_t* tx_spool_v0(canard_t* const self,
855823
}
856824
return item;
857825
}
858-
const uint16_t crc = crc_add_chain(crc_seed, payload);
859-
const byte_t crc_bytes[CRC_SIZE_BYTES] = { (byte_t)((crc >> 0U) & BYTE_MAX), // v0 little-endian CRC
860-
(byte_t)((crc >> 8U) & BYTE_MAX) };
861-
const size_t size_total = size + CRC_SIZE_BYTES;
862-
const canard_bytes_chain_t payload_total = { .bytes = { .size = CRC_SIZE_BYTES, .data = crc_bytes },
863-
.next = &payload };
864-
bytes_chain_reader_t reader = { .cursor = &payload_total, .position = 0U };
865-
tx_frame_t* head = NULL;
866-
tx_frame_t* tail = NULL;
867-
size_t offset = 0U;
826+
const uint16_t crc = crc_add_chain(crc_seed, payload);
827+
// NOLINTNEXTLINE(*-signed-bitwise) v0 CRC is little-endian, which is not the native ordering of CRC-16-CCITT.
828+
const byte_t crc_bytes[CRC_SIZE_BYTES] = { (byte_t)((crc >> 0U) & BYTE_MAX), (byte_t)((crc >> 8U) & BYTE_MAX) };
829+
const size_t size_total = size + CRC_SIZE_BYTES;
830+
const canard_bytes_chain_t payload_total = { .bytes = { .size = CRC_SIZE_BYTES, .data = crc_bytes },
831+
.next = &payload };
832+
bytes_chain_reader_t reader = { .cursor = &payload_total, .position = 0U };
833+
tx_frame_t* head = NULL;
834+
tx_frame_t* tail = NULL;
835+
size_t offset = 0U;
868836
while (offset < size_total) {
869837
tx_frame_t* const item = tx_frame_new(self, smaller((size_total - offset) + 1U, CANARD_MTU_CAN_CLASSIC));
870838
if (NULL == head) {

0 commit comments

Comments
 (0)