feat(util): add esp_crc8 for efuse check

This commit is contained in:
Wu Jian Gang
2018-06-28 19:32:06 +08:00
parent 8a90670956
commit 1f2f10c7d4
2 changed files with 52 additions and 6 deletions

View File

@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef ROM_CRC_H
#define ROM_CRC_H
#ifndef __CRC_H_
#define __CRC_H_
#include <stdint.h>
@ -115,6 +115,17 @@ uint8_t crc8_le(uint8_t crc, uint8_t const *buf, uint32_t len);
*/
uint8_t crc8_be(uint8_t crc, uint8_t const *buf, uint32_t len);
/**
* @brief A crc8 algorithm used in efuse check.
*
* @param uint8_t const *p : Pointer to original data.
*
* @param uint32_t len : Data length in byte.
*
* @return uint8_t: Crc value.
*/
uint8_t esp_crc8(uint8_t const *p, uint32_t len);
/**
* @}
*/

View File

@ -1,5 +1,20 @@
// Copyright 2018 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <stdint.h>
#include <stdbool.h>
#include "crc.h"
static const uint32_t crc32_le_table[256] = {
0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L, 0x706af48fL, 0xe963a535L, 0x9e6495a3L,
@ -49,3 +64,23 @@ uint32_t crc32_le(uint32_t crc, const uint8_t *buf, uint32_t len)
return ~crc;
}
uint8_t esp_crc8(uint8_t const *p, uint32_t len)
{
uint8_t i;
uint8_t crc = 0;
while (len--) {
crc = crc ^ (*p++);
for (i = 0; i < 8; i++) {
if (crc & 0x01) {
crc = (crc >> 1) ^ 0x8c;
} else {
crc = crc >> 1;
}
}
}
return crc;
}