diff --git a/kernel/kmod.c b/kernel/kmod.c index 882a9392a0ed832c425502f4f73ad23465757bf8..875c2dc1d8f393acaeea192ec5aef3bc166ea5f8 100644 --- a/kernel/kmod.c +++ b/kernel/kmod.c @@ -8,6 +8,7 @@ #include <linux/kthread.h> #include <linux/gpio.h> #include <linux/delay.h> +#include <linux/crc32.h> #include "../common/include/message.h" #define DEVICE_NAME "amogus" @@ -84,21 +85,28 @@ static void send_byte(uint8_t byte) { } } -static void send_data(void *data, size_t length) { - uint8_t *bytes = (uint8_t*)data; +static void send_data(const void *data, size_t length) { + const uint8_t *bytes = (const uint8_t*)data; for (size_t i = 0; i < length; i++) { send_byte(bytes[i]); } } +static uint32_t calculate_crc32(const void *data, size_t length){ + return crc32(0, data, length); +} + static int timed_thread_fn(void *args) { while (!kthread_should_stop()) { wait_event_interruptible(wq, atomic_read(&wake_counter) > 0); atomic_dec(&wake_counter); if (slot == 0) { + uint32_t crc = calculate_crc32(&message, sizeof(message)); + send_data(&message, sizeof(message)); + send_data(&crc, sizeof(uint32_t)); } slot = (slot + 1) % SLOTS;