From 1f6f283864c4889d415c44accd433938027337f1 Mon Sep 17 00:00:00 2001 From: Nathael Pajani Date: Tue, 27 Sep 2016 23:11:28 +0200 Subject: [PATCH] CRC engine support. NOT TESTED --- core/crc_engine.c | 68 ++++++++++++++++++++++++++++++++ include/core/crc_engine.h | 81 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 149 insertions(+) create mode 100644 core/crc_engine.c create mode 100644 include/core/crc_engine.h diff --git a/core/crc_engine.c b/core/crc_engine.c new file mode 100644 index 0000000..7cbf534 --- /dev/null +++ b/core/crc_engine.c @@ -0,0 +1,68 @@ +/**************************************************************************** + * core/crc_engine + * + * Copyright 2015 Nathael Pajani + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + *************************************************************************** */ + +/***************************************************************************** */ +/* CRC engine */ +/***************************************************************************** */ + +/* CRC engine configuration and utility functions + * Refer to the LPC122x documentation (UM10441.pdf) for more information + */ + + +#include "lib/stdint.h" +#include "core/crc_engine.h" + + +static uint32_t crc_seed = 0; + +/***************************************************************************** */ +/* Configure the CRC engine. */ +void crc_config(uint8_t poly, uint32_t seed, uint8_t data_mode, uint8_t sum_mode) +{ + struct lpc_crc_engine* crc_ctrl = LPC_CRC_ENGINE; + + crc_ctrl->mode = ((poly & 0x03) | (data_mode & 0x0C) | (sum_mode & 0x30)); + crc_ctrl->seed = seed; + crc_seed = seed; +} + + +void crc_reinit(void) +{ + struct lpc_crc_engine* crc_ctrl = LPC_CRC_ENGINE; + crc_ctrl->seed = crc_seed; +} + +uint32_t crc_get_sum(void) +{ + struct lpc_crc_engine* crc_ctrl = LPC_CRC_ENGINE; + return crc_ctrl->sum; +} + + +void crc_add(uint32_t value) +{ + struct lpc_crc_engine* crc_ctrl = LPC_CRC_ENGINE; + crc_ctrl->sum = value; +} + + + diff --git a/include/core/crc_engine.h b/include/core/crc_engine.h new file mode 100644 index 0000000..d201a3b --- /dev/null +++ b/include/core/crc_engine.h @@ -0,0 +1,81 @@ +/**************************************************************************** + * core/crc_engine.h + * + * Copyright 2015 Nathael Pajani + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + *************************************************************************** */ + + +#ifndef CORE_CRC_ENGINE_H +#define CORE_CRC_ENGINE_H + +/***************************************************************************** */ +/* CRC engine */ +/***************************************************************************** */ + +/* CRC engine configuration and utility functions + * Refer to the LPC122x documentation (UM10441.pdf) for more information + */ + + +#include "lib/stdint.h" +#include "core/lpc_regs.h" + + + +/***************************************************************************** */ +/* Configure the CRC engine. */ +void crc_config(uint8_t poly, uint32_t seed, uint8_t data_mode, uint8_t sum_mode); + + +void crc_reinit(void); + +uint32_t crc_get_sum(void); + +void crc_add(uint32_t value); + + + + +/***************************************************************************** */ +/* CRC engine */ +/***************************************************************************** */ +/* CRC engine */ +struct lpc_crc_engine +{ + volatile uint32_t mode; /* 0x000 CRC Mode (R/W) */ + volatile uint32_t seed; /* 0x004 CRC Seed (R/W) */ + union { + volatile uint32_t sum; /* 0x008 CRC CRC Checksum (R/-) */ + volatile uint32_t data; /* 0x008 CRC Data (-/W) */ + }; +}; +#define LPC_CRC_ENGINE ((struct lpc_crc_engine*)LPC_CRC_BASE) + +/* Mode register */ +#define LPC_CRC_POLY_CRC32 (0x02) +#define LPC_CRC_POLY_CRC16 (0x01) +#define LPC_CRC_POLY_CRCCITT (0x00) +#define LPC_CRC_REVERSE_DATA_BIT_ORDER (0x01 << 2) +#define LPC_CRC_DATA_COMPLEMENT (0x01 << 3) +#define LPC_CRC_REVERSE_SUM_BIT_ORDER (0x01 << 4) +#define LPC_CRC_SUM_COMPLEMENT (0x01 << 5) + + + +#endif /* CORE_CRC_ENGINE_H */ + + -- 2.43.0