mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-12-16 18:13:49 +01:00
Merge pull request #17703 from benpicco/pkg/nanors
pkg/nanors: add reed solomon codec implementation
This commit is contained in:
commit
d5f570c28b
12
pkg/nanors/Makefile
Normal file
12
pkg/nanors/Makefile
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
PKG_NAME=nanors
|
||||||
|
PKG_URL=https://github.com/sleepybishop/nanors.git
|
||||||
|
PKG_VERSION=389007b64a66f1c0c38c13bc510da1173cfe6097
|
||||||
|
PKG_LICENSE=MIT
|
||||||
|
|
||||||
|
include $(RIOTBASE)/pkg/pkg.mk
|
||||||
|
|
||||||
|
# disable large look-up tables
|
||||||
|
CFLAGS += -DOBLAS_TINY
|
||||||
|
|
||||||
|
all:
|
||||||
|
$(QQ)"$(MAKE)" -C $(PKG_SOURCE_DIR) -f $(RIOTBASE)/Makefile.base
|
||||||
2
pkg/nanors/Makefile.include
Normal file
2
pkg/nanors/Makefile.include
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
INCLUDES += -I$(PKGDIRBASE)/nanors
|
||||||
|
INCLUDES += -I$(PKGDIRBASE)/nanors/deps/obl
|
||||||
6
pkg/nanors/doc.txt
Normal file
6
pkg/nanors/doc.txt
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
/**
|
||||||
|
* @defgroup pkg_nanors small Reed-Solomon code implementation
|
||||||
|
* @ingroup pkg
|
||||||
|
* @brief Provides a tiny, performant implementation of reed solomon codes
|
||||||
|
* @see https://github.com/sleepybishop/nanors
|
||||||
|
*/
|
||||||
6
tests/pkg_nanors/Makefile
Normal file
6
tests/pkg_nanors/Makefile
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
include ../Makefile.tests_common
|
||||||
|
|
||||||
|
USEPKG += nanors
|
||||||
|
USEMODULE += random
|
||||||
|
|
||||||
|
include $(RIOTBASE)/Makefile.include
|
||||||
13
tests/pkg_nanors/Makefile.ci
Normal file
13
tests/pkg_nanors/Makefile.ci
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
BOARD_INSUFFICIENT_MEMORY := \
|
||||||
|
arduino-uno \
|
||||||
|
atmega328p-xplained-mini \
|
||||||
|
atmega328p \
|
||||||
|
nucleo-l011k4 \
|
||||||
|
arduino-nano \
|
||||||
|
arduino-leonardo \
|
||||||
|
samd10-xmini \
|
||||||
|
arduino-duemilanove \
|
||||||
|
nucleo-f031k6 \
|
||||||
|
stm32f030f4-demo \
|
||||||
|
stk3200 \
|
||||||
|
#
|
||||||
91
tests/pkg_nanors/main.c
Normal file
91
tests/pkg_nanors/main.c
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2022 ML!PA Consulting GmbH
|
||||||
|
*
|
||||||
|
* This file is subject to the terms and conditions of the GNU Lesser
|
||||||
|
* General Public License v2.1. See the file LICENSE in the top level
|
||||||
|
* directory for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ingroup tests
|
||||||
|
* @{
|
||||||
|
*
|
||||||
|
* @file
|
||||||
|
* @brief Test application for Reed-Solomon codec
|
||||||
|
*
|
||||||
|
* @author Benjamin Valentin <benjamin.valentin@ml-pa.com>
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "kernel_defines.h"
|
||||||
|
#include "random.h"
|
||||||
|
#include "rs.h"
|
||||||
|
|
||||||
|
#define DATA_SHARDS 20
|
||||||
|
#define RECOVERY_SHARDS 10
|
||||||
|
#define SHARD_SIZE 64
|
||||||
|
|
||||||
|
typedef reed_solomon rs_t;
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
/* data + recovery */
|
||||||
|
static uint8_t data[(DATA_SHARDS + RECOVERY_SHARDS) * SHARD_SIZE];
|
||||||
|
/* copy of data for comparison */
|
||||||
|
static uint8_t data_cmp[DATA_SHARDS * SHARD_SIZE];
|
||||||
|
/* pointer to shards */
|
||||||
|
static uint8_t *shards[DATA_SHARDS + RECOVERY_SHARDS];
|
||||||
|
/* map of missing shards */
|
||||||
|
static uint8_t marks[DATA_SHARDS + RECOVERY_SHARDS];
|
||||||
|
|
||||||
|
/* generate random data */
|
||||||
|
random_bytes(data, sizeof(data_cmp));
|
||||||
|
memcpy(data_cmp, data, sizeof(data_cmp));
|
||||||
|
|
||||||
|
/* set up shard pointers */
|
||||||
|
for (unsigned i = 0; i < ARRAY_SIZE(shards); ++i) {
|
||||||
|
shards[i] = &data[i * SHARD_SIZE];
|
||||||
|
}
|
||||||
|
|
||||||
|
puts("START");
|
||||||
|
reed_solomon_init();
|
||||||
|
rs_t *rs = reed_solomon_new(DATA_SHARDS, RECOVERY_SHARDS);
|
||||||
|
if (!rs) {
|
||||||
|
puts("failed to init codec");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("total: %u shards (%u bytes)\n",
|
||||||
|
(unsigned)ARRAY_SIZE(marks), (unsigned)sizeof(data));
|
||||||
|
|
||||||
|
/* generate parity shards */
|
||||||
|
reed_solomon_encode(rs, shards, ARRAY_SIZE(shards), SHARD_SIZE);
|
||||||
|
|
||||||
|
/* delete up to N shards */
|
||||||
|
for (unsigned i = 0; i < RECOVERY_SHARDS; i++) {
|
||||||
|
unsigned at = random_uint32_range(0, ARRAY_SIZE(shards));
|
||||||
|
printf("clear shard %u (%u byte)\n", at, SHARD_SIZE);
|
||||||
|
memset(shards[at], 0, SHARD_SIZE);
|
||||||
|
marks[at] = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
puts("reconstruct…");
|
||||||
|
if (reed_solomon_reconstruct(rs, shards, marks,
|
||||||
|
ARRAY_SIZE(shards), SHARD_SIZE)) {
|
||||||
|
puts("failed.");
|
||||||
|
} else {
|
||||||
|
puts("done.");
|
||||||
|
}
|
||||||
|
reed_solomon_release(rs);
|
||||||
|
|
||||||
|
if (memcmp(data, data_cmp, sizeof(data_cmp))) {
|
||||||
|
puts("FAILED");
|
||||||
|
} else {
|
||||||
|
puts("SUCCESS");
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
13
tests/pkg_nanors/tests/01-run.py
Executable file
13
tests/pkg_nanors/tests/01-run.py
Executable file
@ -0,0 +1,13 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import sys
|
||||||
|
from testrunner import run
|
||||||
|
|
||||||
|
|
||||||
|
def testfunc(child):
|
||||||
|
child.expect_exact('START')
|
||||||
|
child.expect_exact('SUCCESS')
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
sys.exit(run(testfunc))
|
||||||
Loading…
x
Reference in New Issue
Block a user