Skip to content
Snippets Groups Projects
Commit 4812f98d authored by Leon Bohnwagner's avatar Leon Bohnwagner :crab:
Browse files

feat: add crc32 calculation

parent 4f989950
Branches
Tags
No related merge requests found
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment