fix(bitscrambler): example timeout in the bsasm

also added example pytest
This commit is contained in:
morris
2025-01-09 18:44:50 +08:00
parent 97d09e6427
commit 8de8558841
7 changed files with 48 additions and 13 deletions

View File

@@ -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
-------------

View File

@@ -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)

View File

@@ -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

View File

@@ -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")

View File

@@ -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 <stdio.h>
#include <string.h>
#include <sys/unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include "esp_err.h"
#include "esp_log.h"
#include "esp_check.h"
#include <stdio.h>
#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.

View File

@@ -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

View File

@@ -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)