mirror of
https://github.com/espressif/ESP8266_RTOS_SDK.git
synced 2025-09-19 00:21:15 +08:00
feat(util): add esp_crc8 for efuse check
This commit is contained in:
@ -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);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
@ -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;
|
||||
}
|
Reference in New Issue
Block a user