diff options
author | bondus <liquidpontus@yahoo.se> | 2020-08-10 03:07:59 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-09 21:07:59 -0400 |
commit | 35d28e880d1f4e0ae67fa7a7403849f10a052cba (patch) | |
tree | d209fe40d133c7cb6c61c904bb51a815ffce90e2 /src | |
parent | 04bd48ca9dfdadb43f42d62990cfcddd6b5e090c (diff) | |
download | kutter-35d28e880d1f4e0ae67fa7a7403849f10a052cba.tar.gz kutter-35d28e880d1f4e0ae67fa7a7403849f10a052cba.tar.xz kutter-35d28e880d1f4e0ae67fa7a7403849f10a052cba.zip |
stm32: Improvements to CAN bus ID generation. And added a small fast hash library (#3165)
Improved CAM bus ID generation, there were issues with ID collisions.
Added a small fast hash library.
Signed-off-by: Pontus Borg <liquidpontus@yahoo.se>
Diffstat (limited to 'src')
-rw-r--r-- | src/stm32/Makefile | 6 | ||||
-rw-r--r-- | src/stm32/can.c | 7 |
2 files changed, 7 insertions, 6 deletions
diff --git a/src/stm32/Makefile b/src/stm32/Makefile index 56f1581c..bd5017f2 100644 --- a/src/stm32/Makefile +++ b/src/stm32/Makefile @@ -17,7 +17,7 @@ CFLAGS-$(CONFIG_MACH_STM32F1) += -mcpu=cortex-m3 -Ilib/stm32f1/include CFLAGS-$(CONFIG_MACH_STM32F2) += -mcpu=cortex-m3 -Ilib/stm32f2/include CFLAGS-$(CONFIG_MACH_STM32F4) += -mcpu=cortex-m4 -Ilib/stm32f4/include CFLAGS-$(CONFIG_MACH_STM32F4) += -mfpu=fpv4-sp-d16 -mfloat-abi=hard -CFLAGS += $(CFLAGS-y) -D$(MCU_UPPER) -mthumb -Ilib/cmsis-core +CFLAGS += $(CFLAGS-y) -D$(MCU_UPPER) -mthumb -Ilib/cmsis-core -Ilib/fast-hash CFLAGS_klipper.elf += --specs=nano.specs --specs=nosys.specs CFLAGS_klipper.elf += -T $(OUT)src/generic/armcm_link.ld @@ -46,9 +46,11 @@ src-$(CONFIG_USBSERIAL) += $(usb-src-y) stm32/chipid.c generic/usb_cdc.c serial-src-y := stm32/serial.c serial-src-$(CONFIG_MACH_STM32F0) := stm32/stm32f0_serial.c src-$(CONFIG_SERIAL) += $(serial-src-y) generic/serial_irq.c -can-src-$(CONFIG_CANSERIAL) += stm32/can.c +can-src-$(CONFIG_CANSERIAL) += stm32/can.c ../lib/fast-hash/fasthash.c src-$(CONFIG_CANSERIAL) += $(can-src-y) generic/serial_irq.c +dirs-$(CONFIG_CANSERIAL) += lib/fast-hash + # Binary output file rules target-y += $(OUT)klipper.bin diff --git a/src/stm32/can.c b/src/stm32/can.c index 7e3d75f1..d0e84908 100644 --- a/src/stm32/can.c +++ b/src/stm32/can.c @@ -15,6 +15,7 @@ #include "sched.h" // DECL_INIT #include <string.h> #include "can.h" +#include <fasthash.h> #if (CONFIG_CAN_PINS_PA11_PA12) DECL_CONSTANT_STR("RESERVE_PINS_CAN", "PA11,PA12"); @@ -151,10 +152,8 @@ static void can_transmit(uint32_t id, uint32_t dlc, uint8_t *pkt) // Convert Unique 96-bit value into 48 bit representation static void pack_uuid(uint8_t* u) { - for(int i=0; i<SHORT_UUID_LEN; i++) { - u[i] = *((uint8_t*)(UID_BASE+i)) ^ - *((uint8_t*)(UID_BASE+i+SHORT_UUID_LEN)); - } + uint64_t hash = fasthash64((uint8_t*)UID_BASE, 12, 0xA16231A7); + memcpy(u, &hash, SHORT_UUID_LEN); } static void can_uuid_resp(void) |