From a298ad9ba29a71edd23ed0129c6fe0c0a3f02159 Mon Sep 17 00:00:00 2001 From: Pavel Kirienko Date: Wed, 16 Apr 2014 17:19:05 +0400 Subject: [PATCH] Transport CRC will not use table in UAVCAN_TINY builds --- libuavcan/include/uavcan/transport/crc.hpp | 21 +++++++++++++++++++++ libuavcan/src/transport/uc_crc.cpp | 5 ++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/libuavcan/include/uavcan/transport/crc.hpp b/libuavcan/include/uavcan/transport/crc.hpp index 91c6be0423..c025ec13f3 100644 --- a/libuavcan/include/uavcan/transport/crc.hpp +++ b/libuavcan/include/uavcan/transport/crc.hpp @@ -26,7 +26,10 @@ namespace uavcan */ class UAVCAN_EXPORT TransferCRC { +#if !UAVCAN_TINY static const uint16_t Table[256]; +#endif + uint16_t value_; public: @@ -36,10 +39,28 @@ public: : value_(0xFFFF) { } +#if UAVCAN_TINY + void add(uint8_t byte) + { + value_ ^= byte << 8; + for (uint8_t bit = 8; bit > 0; --bit) + { + if (value_ & 0x8000) + { + value_ = (value_ << 1) ^ 0x1021; + } + else + { + value_ = (value_ << 1); + } + } + } +#else void add(uint8_t byte) { value_ = ((value_ << 8) ^ Table[((value_ >> 8) ^ byte) & 0xFF]) & 0xFFFF; } +#endif void add(const uint8_t* bytes, unsigned len) { diff --git a/libuavcan/src/transport/uc_crc.cpp b/libuavcan/src/transport/uc_crc.cpp index 39856e116e..0ef8f7ef80 100644 --- a/libuavcan/src/transport/uc_crc.cpp +++ b/libuavcan/src/transport/uc_crc.cpp @@ -2,12 +2,13 @@ * Copyright (C) 2014 Pavel Kirienko */ -#include #include namespace uavcan { +#if !UAVCAN_TINY + // print ', '.join(map(lambda x: '%04x' % x, map(lambda x: int(x, 0), c.crc_ccitt_tab))) const uint16_t TransferCRC::Table[256] = { @@ -45,4 +46,6 @@ const uint16_t TransferCRC::Table[256] = 0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0 }; +#endif + }