mirror of
https://github.com/oopuuu/zTC1.git
synced 2025-12-19 08:23:22 +08:00
修改了Web后台的部分界面,增加了HAmqtt中的总电量传感器,后台新增mqtt上报频率设置
This commit is contained in:
16
mico-os/platform/MCU/MW3xx/peripherals/boot2/utils/crc.h
Normal file
16
mico-os/platform/MCU/MW3xx/peripherals/boot2/utils/crc.h
Normal file
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2013, Marvell International Ltd.
|
||||
* All Rights Reserved.
|
||||
*/
|
||||
|
||||
#ifndef __CRC_H__
|
||||
#define __CRC_H__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
uint32_t soft_crc32(const void *__data, int data_size, uint32_t crc);
|
||||
void soft_crc32_init();
|
||||
uint32_t soft_crc16(const void *__data, uint16_t len);
|
||||
void soft_crc16_init();
|
||||
|
||||
#endif
|
||||
34
mico-os/platform/MCU/MW3xx/peripherals/boot2/utils/crc32.c
Normal file
34
mico-os/platform/MCU/MW3xx/peripherals/boot2/utils/crc32.c
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (C) 2013, Marvell International Ltd.
|
||||
* All Rights Reserved.
|
||||
*/
|
||||
|
||||
#include <inttypes.h>
|
||||
#include "crc32.h"
|
||||
#include <lowlevel_drivers.h>
|
||||
|
||||
static int crc_init;
|
||||
|
||||
static void crc_set_mode()
|
||||
{
|
||||
CRC_SetMode(CRC_32_IEEE);
|
||||
}
|
||||
|
||||
uint32_t _crc32(void *__data, int data_size, uint32_t crc)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
if (!crc_init) {
|
||||
crc_set_mode();
|
||||
crc_init = 1;
|
||||
}
|
||||
|
||||
CRC_Disable();
|
||||
CRC_Enable();
|
||||
result = CRC_Calculate(__data, data_size);
|
||||
|
||||
if (crc && result == crc)
|
||||
result = 0;
|
||||
|
||||
return result;
|
||||
}
|
||||
13
mico-os/platform/MCU/MW3xx/peripherals/boot2/utils/crc32.h
Normal file
13
mico-os/platform/MCU/MW3xx/peripherals/boot2/utils/crc32.h
Normal file
@@ -0,0 +1,13 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2013, Marvell International Ltd.
|
||||
* All Rights Reserved.
|
||||
*/
|
||||
|
||||
#ifndef __CRC32_H
|
||||
#define __CRC32_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
uint32_t crc32(void *__data, int data_size, uint32_t crc);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,50 @@
|
||||
|
||||
#include "crc.h"
|
||||
|
||||
#define CRC_16_CCITT 0x8408 /*!< CRC mode: CRC-16-CCITT */
|
||||
#define TABLE_SIZE 16
|
||||
|
||||
static uint32_t crc_table[TABLE_SIZE];
|
||||
|
||||
void soft_crc16_init(void)
|
||||
{
|
||||
uint16_t crc = 0;
|
||||
uint8_t i;
|
||||
uint8_t j;
|
||||
|
||||
for (j = 0; j < TABLE_SIZE; j++) {
|
||||
crc = 0;
|
||||
for (i = 0x01; i != 0x10; i <<= 1) {
|
||||
if ((crc & 0x0001) != 0) {
|
||||
crc >>= 1;
|
||||
crc ^= CRC_16_CCITT;
|
||||
} else {
|
||||
crc >>= 1;
|
||||
}
|
||||
if ((j & i) != 0) {
|
||||
crc ^= CRC_16_CCITT;
|
||||
}
|
||||
}
|
||||
crc_table[j] = crc;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t soft_crc16(const void *__buf, uint16_t len)
|
||||
{
|
||||
const uint8_t *buf = __buf;
|
||||
uint16_t crc = 0;
|
||||
uint8_t crc_H8;
|
||||
|
||||
while (len--) {
|
||||
crc_H8 = (uint8_t)(crc & 0x000F);
|
||||
crc >>= 4;
|
||||
crc ^= crc_table[crc_H8 ^ (*buf & 0x0F)];
|
||||
crc_H8 = (uint8_t)(crc & 0x000F);
|
||||
crc >>= 4;
|
||||
crc ^= crc_table[crc_H8 ^ (*buf >> 4)];
|
||||
buf++;
|
||||
}
|
||||
|
||||
return (uint32_t)crc;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (C) 2013, Marvell International Ltd.
|
||||
* All Rights Reserved.
|
||||
*/
|
||||
|
||||
#include "crc.h"
|
||||
|
||||
#define TABLE_SIZE 256
|
||||
|
||||
static uint32_t crc_table[TABLE_SIZE];
|
||||
static const int rcrc32 = 0xEDB88320;
|
||||
|
||||
void soft_crc32_init(void)
|
||||
{
|
||||
unsigned int crc = 0;
|
||||
unsigned char i;
|
||||
unsigned int j;
|
||||
|
||||
for (j = 0; j < TABLE_SIZE; j++) {
|
||||
crc = 0;
|
||||
for (i = 0x01; i != 0x00; i <<= 1) {
|
||||
if ((crc & 0x00000001) != 0) {
|
||||
crc >>= 1;
|
||||
crc ^= rcrc32;
|
||||
} else {
|
||||
crc >>= 1;
|
||||
}
|
||||
if ((j & i) != 0)
|
||||
crc ^= rcrc32;
|
||||
}
|
||||
crc_table[j] = crc;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t soft_crc32(const void *__data, int data_size, uint32_t crc)
|
||||
{
|
||||
const uint8_t *data = __data;
|
||||
unsigned int result = crc;
|
||||
unsigned char crc_H8;
|
||||
|
||||
while (data_size--) {
|
||||
crc_H8 = (unsigned char)(result & 0x000000FF);
|
||||
result >>= 8;
|
||||
result ^= crc_table[crc_H8 ^ (*data)];
|
||||
data++;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
Reference in New Issue
Block a user