Removed unnecessary CRC function

I missed the existing one in include/blisp_util.h
This commit is contained in:
Pavel Zakopaylo 2023-12-01 14:52:07 +11:00
parent 14369675da
commit c48950e07b
No known key found for this signature in database
GPG Key ID: 9D4130BD5891F5CB
4 changed files with 5 additions and 80 deletions

View File

@ -9,7 +9,7 @@ option(BLISP_USE_SYSTEM_LIBRARIES "Use system-installed libraries" "${CMAKE_USE_
option(COMPILE_TESTS "Compile the tests" OFF) option(COMPILE_TESTS "Compile the tests" OFF)
add_library(libblisp_obj OBJECT add_library(libblisp_obj OBJECT
lib/blisp.c lib/blisp_easy.c lib/crc.c lib/blisp.c lib/blisp_easy.c
lib/chip/blisp_chip_bl60x.c lib/chip/blisp_chip_bl60x.c
lib/chip/blisp_chip_bl70x.c lib/chip/blisp_chip_bl70x.c
lib/chip/blisp_chip_bl808.c) lib/chip/blisp_chip_bl808.c)

View File

@ -1,6 +0,0 @@
#ifndef _BLISP_CRC_H
#define _BLISP_CRC_H
unsigned long crc(unsigned char *buf, int len);
#endif // _BLISP_CRC_H

View File

@ -5,7 +5,7 @@
#include "blisp.h" #include "blisp.h"
#include "blisp_struct.h" #include "blisp_struct.h"
#include "crc.h" #include "blisp_util.h"
#include <stddef.h> #include <stddef.h>
struct blisp_chip blisp_chip_bl808 = { struct blisp_chip blisp_chip_bl808 = {
@ -225,7 +225,7 @@ struct bl808_bootheader_t bl808_header = {
}; };
void fill_crcs(struct bl808_bootheader_t *bh) { void fill_crcs(struct bl808_bootheader_t *bh) {
bh->flash_cfg.crc32 = crc((unsigned char *) &bh->flash_cfg.cfg, sizeof(struct bl808_spi_flash_cfg_t)); bh->flash_cfg.crc32 = crc32_calculate((unsigned char *) &bh->flash_cfg.cfg, sizeof(struct bl808_spi_flash_cfg_t));
bh->clk_cfg.crc32 = crc((unsigned char *) &bh->clk_cfg.cfg, sizeof(struct bl808_sys_clk_cfg_t)); bh->clk_cfg.crc32 = crc32_calculate((unsigned char *) &bh->clk_cfg.cfg, sizeof(struct bl808_sys_clk_cfg_t));
bh->crc32 = crc((unsigned char *) bh, sizeof(struct bl808_bootheader_t) - 4); bh->crc32 = crc32_calculate((unsigned char *) bh, sizeof(struct bl808_bootheader_t) - 4);
} }

View File

@ -1,69 +0,0 @@
/*
* CRC code taken from https://www.rfc-editor.org/rfc/rfc1952#section-8
*
* Copyright (c) 1996 L. Peter Deutsch
*
* Permission is granted to copy and distribute this document for any
* purpose and without charge, including translations into other
* languages and incorporation into compilations, provided that the
* copyright notice and this notice are preserved, and that any
* substantive changes or deletions from the original are clearly
* marked.
*/
#include <stdlib.h>
#include <stdbool.h>
/* Table of CRCs of all 8-bit messages. */
unsigned long crc_table[256];
/* Flag: has the table been computed? Initially false. */
int crc_table_computed = 0;
/* Make the table for a fast CRC. */
void make_crc_table(void) {
unsigned long c;
int n, k;
for (n = 0; n < 256; n++) {
c = (unsigned long) n;
for (k = 0; k < 8; k++) {
if (c & 1) {
c = 0xedb88320L ^ (c >> 1);
} else {
c = c >> 1;
}
}
crc_table[n] = c;
}
crc_table_computed = 1;
}
/*
Update a running crc with the bytes buf[0..len-1] and return
the updated crc. The crc should be initialized to zero. Pre- and
post-conditioning (one's complement) is performed within this
function so it shouldn't be done by the caller. Usage example:
unsigned long crc = 0L;
while (read_buffer(buffer, length) != EOF) {
crc = update_crc(crc, buffer, length);
}
if (crc != original_crc) error();
*/
unsigned long update_crc(unsigned long crc, unsigned char *buf, int len) {
unsigned long c = crc ^ 0xffffffffL;
int n;
if (!crc_table_computed)
make_crc_table();
for (n = 0; n < len; n++) {
c = crc_table[(c ^ buf[n]) & 0xff] ^ (c >> 8);
}
return c ^ 0xffffffffL;
}
/* Return the CRC of the bytes buf[0..len-1]. */
unsigned long crc(unsigned char *buf, int len) {
return update_crc(0L, buf, len);
}