mirror of
https://github.com/andreili/katapult.git
synced 2025-08-23 19:34:06 +02:00
generic: add crc16 from klipper
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
849b81dce5
commit
011d3a8f45
22
src/generic/crc16_ccitt.c
Normal file
22
src/generic/crc16_ccitt.c
Normal file
@ -0,0 +1,22 @@
|
||||
// Code for crc16_ccitt
|
||||
//
|
||||
// Copyright (C) 2016 Kevin O'Connor <kevin@koconnor.net>
|
||||
//
|
||||
// This file may be distributed under the terms of the GNU GPLv3 license.
|
||||
|
||||
#include "misc.h" // crc16_ccitt
|
||||
|
||||
// Implement the standard crc "ccitt" algorithm on the given buffer
|
||||
uint16_t
|
||||
crc16_ccitt(uint8_t *buf, uint_fast8_t len)
|
||||
{
|
||||
uint16_t crc = 0xffff;
|
||||
while (len--) {
|
||||
uint8_t data = *buf++;
|
||||
data ^= crc & 0xff;
|
||||
data ^= data << 4;
|
||||
crc = ((((uint16_t)data << 8) | (crc >> 8)) ^ (uint8_t)(data >> 4)
|
||||
^ ((uint16_t)data << 3));
|
||||
}
|
||||
return crc;
|
||||
}
|
@ -18,4 +18,6 @@ uint8_t timer_is_before(uint32_t time1, uint32_t time2);
|
||||
uint32_t timer_read_time(void);
|
||||
void udelay(uint32_t usecs);
|
||||
|
||||
uint16_t crc16_ccitt(uint8_t *buf, uint_fast8_t len);
|
||||
|
||||
#endif // misc.h
|
||||
|
@ -25,7 +25,7 @@ $(OUT)canboot.elf: $(OUT)src/generic/armcm_link.ld
|
||||
|
||||
# Add source files
|
||||
src-y += stm32/gpio.c stm32/flash.c stm32/clockline.c
|
||||
src-y += generic/armcm_boot.c generic/armcm_irq.c
|
||||
src-y += generic/armcm_boot.c generic/armcm_irq.c generic/crc16_ccitt.c
|
||||
src-$(CONFIG_MACH_STM32F0) += ../lib/stm32f0/system_stm32f0xx.c
|
||||
src-$(CONFIG_MACH_STM32F0) += stm32/stm32f0.c stm32/stm32f0_timer.c
|
||||
src-$(CONFIG_MACH_STM32F0) += stm32/gpioperiph.c
|
||||
|
Loading…
x
Reference in New Issue
Block a user