From 8de8558841cc21857f603da945ec9d92ca929695 Mon Sep 17 00:00:00 2001 From: morris Date: Thu, 9 Jan 2025 18:44:50 +0800 Subject: [PATCH] fix(bitscrambler): example timeout in the bsasm also added example pytest --- .../peripherals/bitscrambler.rst | 4 ++++ .../peripherals/bitscrambler/CMakeLists.txt | 4 ++++ examples/peripherals/bitscrambler/README.md | 9 ++++++++ .../bitscrambler/main/CMakeLists.txt | 5 ++--- .../main/bitscrambler_example_main.c | 13 ++++-------- .../bitscrambler/main/example.bsasm | 5 ++++- .../pytest_bitscrambler_loopback_example.py | 21 +++++++++++++++++++ 7 files changed, 48 insertions(+), 13 deletions(-) create mode 100644 examples/peripherals/bitscrambler/pytest_bitscrambler_loopback_example.py diff --git a/docs/en/api-reference/peripherals/bitscrambler.rst b/docs/en/api-reference/peripherals/bitscrambler.rst index ab38a37981..eb3d0a536e 100644 --- a/docs/en/api-reference/peripherals/bitscrambler.rst +++ b/docs/en/api-reference/peripherals/bitscrambler.rst @@ -193,6 +193,10 @@ Resource allocation and program loading In loopback mode, a BitScrambler object is created using :cpp:func:`bitscrambler_loopback_create`. If there is a BitScrambler peripheral matching the requested characteristics, this function will return a handle to it. You can then use :cpp:func:`bitscrambler_load_program` to load a program into it, then call :cpp:func:`bitscrambler_loopback_run` to transform a memory buffer using the loaded program. You can call :cpp:func:`bitscrambler_loopback_run` any number of times; it's also permissible to use :cpp:func:`bitscrambler_load_program` to change programs between calls. Finally, to free the hardware resources and clean up memory, call :cpp:func:`bitscrambler_free`. +Application Example +------------------- + +* :example:`peripherals/bitscrambler` demonstrates how to use the BitScrambler loopback mode to transform a buffer of data into a different format. API Reference ------------- diff --git a/examples/peripherals/bitscrambler/CMakeLists.txt b/examples/peripherals/bitscrambler/CMakeLists.txt index 62c7ef2272..8e78254ace 100644 --- a/examples/peripherals/bitscrambler/CMakeLists.txt +++ b/examples/peripherals/bitscrambler/CMakeLists.txt @@ -5,4 +5,8 @@ cmake_minimum_required(VERSION 3.16) include($ENV{IDF_PATH}/tools/cmake/project.cmake) + +# "Trim" the build. Include the minimal set of components, main, and anything it depends on. +idf_build_set_property(MINIMAL_BUILD ON) + project(bitscrambler_example) diff --git a/examples/peripherals/bitscrambler/README.md b/examples/peripherals/bitscrambler/README.md index 2b1363121f..617285ed85 100644 --- a/examples/peripherals/bitscrambler/README.md +++ b/examples/peripherals/bitscrambler/README.md @@ -23,6 +23,15 @@ See the Getting Started Guide for full steps to configure and use ESP-IDF to bui ## Example Output +```text +I (305) bs_example: BitScrambler example main +BitScrambler program complete. Input 40, output 40 bytes: +FF 00 00 00 00 00 00 00 +80 80 80 80 80 80 80 80 +01 02 04 08 10 20 40 80 +00 FF 00 FF 00 FF 00 FF +FF 00 FF 00 FF 00 FF 00 +``` ## Troubleshooting diff --git a/examples/peripherals/bitscrambler/main/CMakeLists.txt b/examples/peripherals/bitscrambler/main/CMakeLists.txt index e59e3e6b3f..e78d9ab257 100644 --- a/examples/peripherals/bitscrambler/main/CMakeLists.txt +++ b/examples/peripherals/bitscrambler/main/CMakeLists.txt @@ -1,6 +1,5 @@ - idf_component_register(SRCS "bitscrambler_example_main.c" - PRIV_REQUIRES "esp_driver_bitscrambler" - INCLUDE_DIRS ".") + PRIV_REQUIRES "esp_driver_bitscrambler" + INCLUDE_DIRS ".") target_bitscrambler_add_src("example.bsasm") diff --git a/examples/peripherals/bitscrambler/main/bitscrambler_example_main.c b/examples/peripherals/bitscrambler/main/bitscrambler_example_main.c index 3b4970ecb2..26457f929a 100644 --- a/examples/peripherals/bitscrambler/main/bitscrambler_example_main.c +++ b/examples/peripherals/bitscrambler/main/bitscrambler_example_main.c @@ -1,22 +1,17 @@ /* - * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: CC0-1.0 */ #include #include -#include -#include -#include -#include "esp_err.h" -#include "esp_log.h" -#include "esp_check.h" -#include -#include "driver/bitscrambler_loopback.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" +#include "esp_err.h" +#include "esp_log.h" #include "esp_heap_caps.h" +#include "driver/bitscrambler_loopback.h" //Assign a symbol to the example bitscrambler program. Note that the actual //assembly and including in the binary happens in the CMakeLists.txt file. diff --git a/examples/peripherals/bitscrambler/main/example.bsasm b/examples/peripherals/bitscrambler/main/example.bsasm index 329ce6fb21..1c718f4d20 100644 --- a/examples/peripherals/bitscrambler/main/example.bsasm +++ b/examples/peripherals/bitscrambler/main/example.bsasm @@ -1,10 +1,13 @@ +# SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD +# SPDX-License-Identifier: Unlicense OR CC0-1.0 + # Example bitscrambler program. Reads in 8 bytes and spits out 8 bytes are # the 'rotated' version of the input bytes. Specifically, output byte 0 # consists of bit 0 of input byte 0, bit 0 of input byte 1, bit 0 of input # byte 2 etc. Output byte 1 consists of bit 1 of input byte 0, bit 1 of # input byte 1, bit 1 of input byte 2, etc. -cfg trailing_bytes 64 #If we have an EOF on the input, we still +cfg trailing_bytes 8 #If we have an EOF on the input, we still #need to process the 64 bits in M0/M1 cfg prefetch true #We expect M0/M1 to be filled cfg lut_width_bits 8 #Not really applicable here diff --git a/examples/peripherals/bitscrambler/pytest_bitscrambler_loopback_example.py b/examples/peripherals/bitscrambler/pytest_bitscrambler_loopback_example.py new file mode 100644 index 0000000000..d627629f97 --- /dev/null +++ b/examples/peripherals/bitscrambler/pytest_bitscrambler_loopback_example.py @@ -0,0 +1,21 @@ +# SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD +# SPDX-License-Identifier: CC0-1.0 +import pytest +from pytest_embedded import Dut + + +@pytest.mark.esp32p4 +@pytest.mark.generic +def test_bitscrambler_loopback_example(dut: Dut) -> None: + dut.expect_exact('BitScrambler example main', timeout=5) + dut.expect_exact('BitScrambler program complete. Input 40, output 40 bytes') + + expected_lines = [ + 'FF 00 00 00 00 00 00 00', + '80 80 80 80 80 80 80 80', + '01 02 04 08 10 20 40 80', + '00 FF 00 FF 00 FF 00 FF', + 'FF 00 FF 00 FF 00 FF 00', + ] + for line in expected_lines: + dut.expect_exact(line)