添加普冉 PY32F040 OTA 双工程代码生成模板

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-18 18:59:56 +08:00
co-authored by Cursor
commit 331864dc64
496 changed files with 329040 additions and 0 deletions
+47
View File
@@ -0,0 +1,47 @@
#include "crc32.h"
/* CRC-32/IEEE 802.3 查表实现(表在首次使用时生成,避免占用 Flash) */
static uint32_t crc32_table[256];
static uint8_t crc32_table_ready = 0;
static void crc32_build_table(void)
{
for (uint32_t i = 0; i < 256; i++)
{
uint32_t c = i;
for (uint32_t k = 0; k < 8; k++)
{
c = (c & 1U) ? (0xEDB88320UL ^ (c >> 1)) : (c >> 1);
}
crc32_table[i] = c;
}
crc32_table_ready = 1;
}
uint32_t crc32_init(void)
{
return 0xFFFFFFFFUL;
}
uint32_t crc32_update(uint32_t crc, const uint8_t *data, uint32_t len)
{
if (!crc32_table_ready)
{
crc32_build_table();
}
while (len--)
{
crc = crc32_table[(crc ^ *data++) & 0xFFU] ^ (crc >> 8);
}
return crc;
}
uint32_t crc32_final(uint32_t crc)
{
return crc ^ 0xFFFFFFFFUL;
}
uint32_t crc32_compute(const uint8_t *data, uint32_t len)
{
return crc32_final(crc32_update(crc32_init(), data, len));
}