Berry add crc.sum()

This commit is contained in:
Stephan Hadinger 2022-05-24 22:06:50 +02:00
parent bc5bedcb3c
commit 2a38c1c0f6
4 changed files with 20 additions and 7 deletions

View File

@ -919,6 +919,7 @@ extern const bcstring be_const_str_subscribe;
extern const bcstring be_const_str_subtype;
extern const bcstring be_const_str_subtype_to_string;
extern const bcstring be_const_str_success;
extern const bcstring be_const_str_sum;
extern const bcstring be_const_str_super;
extern const bcstring be_const_str_switch_factory;
extern const bcstring be_const_str_sys;

View File

@ -889,7 +889,7 @@ be_define_const_str(skip, "skip", 1097563074u, 0, 4, NULL);
be_define_const_str(slots, "slots", 1023330342u, 0, 5, NULL);
be_define_const_str(solidified, "solidified", 3257553487u, 0, 10, NULL);
be_define_const_str(spiffs, "spiffs", 994943858u, 0, 6, &be_const_str_str);
be_define_const_str(splash, "splash", 2531464038u, 0, 6, &be_const_str_wifi_arcs);
be_define_const_str(splash, "splash", 2531464038u, 0, 6, &be_const_str_sum);
be_define_const_str(splash_init, "splash_init", 1522992293u, 0, 11, &be_const_str_split);
be_define_const_str(splash_remove, "splash_remove", 3132020807u, 0, 13, NULL);
be_define_const_str(split, "split", 2276994531u, 0, 5, NULL);
@ -911,6 +911,7 @@ be_define_const_str(subscribe, "subscribe", 2946386435u, 0, 9, NULL);
be_define_const_str(subtype, "subtype", 2023873341u, 0, 7, &be_const_str_toint);
be_define_const_str(subtype_to_string, "subtype_to_string", 2996733901u, 0, 17, &be_const_str_type_to_string);
be_define_const_str(success, "success", 979353360u, 0, 7, &be_const_str_widget_struct_by_class);
be_define_const_str(sum, "sum", 3712891560u, 0, 3, &be_const_str_wifi_arcs);
be_define_const_str(super, "super", 4152230356u, 0, 5, NULL);
be_define_const_str(switch_factory, "switch_factory", 4206217516u, 0, 14, NULL);
be_define_const_str(sys, "sys", 3277365014u, 0, 3, NULL);
@ -1545,6 +1546,6 @@ static const bstring* const m_string_table[] = {
static const struct bconststrtab m_const_string_table = {
.size = 506,
.count = 1035,
.count = 1036,
.table = m_string_table
};

View File

@ -2,13 +2,14 @@
static be_define_const_map_slots(m_libcrc_map) {
{ be_const_key(crc32, 1), be_const_ctype_func(c_crc32) },
{ be_const_key(crc8, 2), be_const_ctype_func(c_crc8) },
{ be_const_key(sum, -1), be_const_ctype_func(c_sum) },
{ be_const_key(crc16, -1), be_const_ctype_func(c_crc16) },
{ be_const_key(crc8, -1), be_const_ctype_func(c_crc8) },
};
static be_define_const_map(
m_libcrc_map,
3
4
);
static be_define_const_module(

View File

@ -10,21 +10,30 @@
#include "rom/crc.h"
uint32_t c_crc32(uint32_t crc, const uint8_t* buf, size_t size) {
static uint32_t c_crc32(uint32_t crc, const uint8_t* buf, size_t size) {
return crc32_le(crc, buf, size);
}
BE_FUNC_CTYPE_DECLARE(c_crc32, "i", "i(bytes)~")
uint32_t c_crc16(uint32_t crc, const uint8_t* buf, size_t size) {
static uint32_t c_crc16(uint32_t crc, const uint8_t* buf, size_t size) {
return crc16_le(crc, buf, size);
}
BE_FUNC_CTYPE_DECLARE(c_crc16, "i", "i(bytes)~")
uint32_t c_crc8(uint32_t crc, const uint8_t* buf, size_t size) {
static uint32_t c_crc8(uint32_t crc, const uint8_t* buf, size_t size) {
return crc8_le(crc, buf, size);
}
BE_FUNC_CTYPE_DECLARE(c_crc8, "i", "i(bytes)~")
static uint32_t c_sum(const uint8_t* buf, size_t size) {
uint32_t sum = 0;
for (uint32_t i = 0; i < size; i++) {
sum = (sum + buf[i]) & 0xFF;
}
return sum;
}
BE_FUNC_CTYPE_DECLARE(c_sum, "i", "(bytes)~")
// const uint32_t crc32_tab[] = {
// 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
// 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
@ -83,6 +92,7 @@ module crc (scope: global) {
crc32, ctype_func(c_crc32)
crc16, ctype_func(c_crc16)
crc8, ctype_func(c_crc8)
sum, ctype_func(c_sum)
}
@const_object_info_end */
#include "be_fixed_crc.h"