Skip to content

Commit d939670

Browse files
committed
test(parlio_tx): add parlio_tx_bs different input output sizes test
Closes #16122
1 parent 570f9d3 commit d939670

File tree

4 files changed

+208
-4
lines changed

4 files changed

+208
-4
lines changed

components/esp_driver_parlio/test_apps/parlio/main/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,6 @@ idf_component_register(SRCS ${srcs}
2525
if(CONFIG_SOC_BITSCRAMBLER_SUPPORTED)
2626
target_bitscrambler_add_src("test_parlio_tx_LSB_to_MSB.bsasm")
2727
target_bitscrambler_add_src("test_parlio_tx_multiply.bsasm")
28+
target_bitscrambler_add_src("test_parlio_tx_in8_out32.bsasm")
29+
target_bitscrambler_add_src("test_parlio_tx_in32_out8.bsasm")
2830
endif()

components/esp_driver_parlio/test_apps/parlio/main/test_parlio_bitscrambler.c

Lines changed: 171 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,21 @@
2121

2222
BITSCRAMBLER_PROGRAM(bitscrambler_program_test_tx_LSB_to_MSB, "test_parlio_tx_LSB_to_MSB");
2323
BITSCRAMBLER_PROGRAM(bitscrambler_program_test_tx_multiply, "test_parlio_tx_multiply");
24+
BITSCRAMBLER_PROGRAM(bitscrambler_program_test_tx_in8_out32, "test_parlio_tx_in8_out32");
25+
BITSCRAMBLER_PROGRAM(bitscrambler_program_test_tx_in32_out8, "test_parlio_tx_in32_out8");
26+
27+
typedef struct {
28+
TaskHandle_t task;
29+
size_t recv_bytes;
30+
} test_parlio_bitscrambler_rx_ctx_t;
2431

2532
TEST_PARLIO_CALLBACK_ATTR
2633
static bool test_parlio_rx_done_callback(parlio_rx_unit_handle_t rx_unit, const parlio_rx_event_data_t *edata, void *user_ctx)
2734
{
2835
BaseType_t high_task_wakeup = pdFALSE;
29-
TaskHandle_t task = (TaskHandle_t)user_ctx;
30-
vTaskNotifyGiveFromISR(task, &high_task_wakeup);
36+
test_parlio_bitscrambler_rx_ctx_t *ctx = (test_parlio_bitscrambler_rx_ctx_t *)user_ctx;
37+
ctx->recv_bytes = edata->recv_bytes;
38+
vTaskNotifyGiveFromISR(ctx->task, &high_task_wakeup);
3139
return high_task_wakeup == pdTRUE;
3240
}
3341

@@ -105,10 +113,13 @@ static void test_parlio_bitscrambler(void)
105113
};
106114
TEST_ESP_OK(parlio_new_rx_level_delimiter(&lvl_deli_cfg, &deli));
107115
printf("register receive_done event callback\r\n");
116+
test_parlio_bitscrambler_rx_ctx_t rx_ctx = {
117+
.task = xTaskGetCurrentTaskHandle(),
118+
};
108119
parlio_rx_event_callbacks_t rx_cbs = {
109120
.on_receive_done = test_parlio_rx_done_callback,
110121
};
111-
TEST_ESP_OK(parlio_rx_unit_register_event_callbacks(rx_unit, &rx_cbs, xTaskGetCurrentTaskHandle()));
122+
TEST_ESP_OK(parlio_rx_unit_register_event_callbacks(rx_unit, &rx_cbs, &rx_ctx));
112123

113124
parlio_receive_config_t recv_config = {
114125
.delimiter = deli,
@@ -121,11 +132,12 @@ static void test_parlio_bitscrambler(void)
121132
// Rx in MSB mode
122133
printf("enable parlio and transmit\r\n");
123134
TEST_ESP_OK(parlio_tx_unit_enable(tx_unit));
124-
TEST_ESP_OK(parlio_rx_unit_enable(rx_unit, 1));
135+
TEST_ESP_OK(parlio_rx_unit_enable(rx_unit, true));
125136
TEST_ESP_OK(parlio_rx_unit_receive(rx_unit, rx_payload, TEST_PAYLOAD_SIZE, &recv_config));
126137
TEST_ESP_OK(parlio_tx_unit_transmit(tx_unit, tx_payload, TEST_PAYLOAD_SIZE * sizeof(uint8_t) * 8, &transmit_config));
127138

128139
TEST_ASSERT_NOT_EQUAL(0, ulTaskNotifyTake(pdTRUE, pdMS_TO_TICKS(1000)));
140+
TEST_ASSERT_EQUAL(TEST_PAYLOAD_SIZE, rx_ctx.recv_bytes);
129141

130142
for (int i = 0; i < TEST_PAYLOAD_SIZE; i++) {
131143
printf("%.3d ", (rx_payload[i]));
@@ -148,6 +160,7 @@ static void test_parlio_bitscrambler(void)
148160
TEST_ESP_OK(parlio_tx_unit_transmit(tx_unit, tx_payload, TEST_PAYLOAD_SIZE * sizeof(uint8_t) * 8, &transmit_config));
149161

150162
TEST_ASSERT_NOT_EQUAL(0, ulTaskNotifyTake(pdTRUE, pdMS_TO_TICKS(1000)));
163+
TEST_ASSERT_EQUAL(TEST_PAYLOAD_SIZE, rx_ctx.recv_bytes);
151164

152165
for (int i = 0; i < TEST_PAYLOAD_SIZE; i++) {
153166
printf("%.3d ", (rx_payload[i]));
@@ -166,6 +179,7 @@ static void test_parlio_bitscrambler(void)
166179
TEST_ESP_OK(parlio_tx_unit_transmit(tx_unit, tx_payload, TEST_PAYLOAD_SIZE * sizeof(uint8_t) * 8, &transmit_config));
167180

168181
TEST_ASSERT_NOT_EQUAL(0, ulTaskNotifyTake(pdTRUE, pdMS_TO_TICKS(1000)));
182+
TEST_ASSERT_EQUAL(TEST_PAYLOAD_SIZE, rx_ctx.recv_bytes);
169183

170184
for (int i = 0; i < TEST_PAYLOAD_SIZE; i++) {
171185
printf("%.3d ", (rx_payload[i]));
@@ -187,3 +201,156 @@ TEST_CASE("parlio_tx_bitscrambler_test", "[parlio_bitscrambler]")
187201
{
188202
test_parlio_bitscrambler();
189203
}
204+
205+
#if SOC_PARLIO_TX_SUPPORT_EOF_FROM_DMA
206+
static void test_parlio_bitscrambler_different_input_output_sizes(void)
207+
{
208+
parlio_tx_unit_handle_t tx_unit = NULL;
209+
parlio_tx_unit_config_t tx_config = {
210+
.clk_src = PARLIO_CLK_SRC_DEFAULT,
211+
.data_width = 4,
212+
.clk_in_gpio_num = -1, // use internal clock source
213+
.valid_gpio_num = TEST_VALID_GPIO,
214+
.clk_out_gpio_num = TEST_CLK_GPIO,
215+
.data_gpio_nums = {
216+
TEST_DATA0_GPIO,
217+
TEST_DATA1_GPIO,
218+
TEST_DATA2_GPIO,
219+
TEST_DATA3_GPIO,
220+
},
221+
.output_clk_freq_hz = 1 * 1000 * 1000,
222+
.trans_queue_depth = 8,
223+
.max_transfer_size = 256,
224+
.bit_pack_order = PARLIO_BIT_PACK_ORDER_LSB,
225+
.sample_edge = PARLIO_SAMPLE_EDGE_POS,
226+
};
227+
228+
parlio_rx_unit_handle_t rx_unit = NULL;
229+
parlio_rx_unit_config_t rx_config = {
230+
.trans_queue_depth = 10,
231+
.max_recv_size = 1024,
232+
.data_width = 4,
233+
.clk_src = PARLIO_CLK_SRC_DEFAULT,
234+
.ext_clk_freq_hz = 0,
235+
.clk_in_gpio_num = -1,
236+
.exp_clk_freq_hz = 1 * 1000 * 1000,
237+
.clk_out_gpio_num = -1,
238+
.valid_gpio_num = TEST_VALID_GPIO,
239+
.data_gpio_nums = {
240+
TEST_DATA0_GPIO,
241+
TEST_DATA1_GPIO,
242+
TEST_DATA2_GPIO,
243+
TEST_DATA3_GPIO,
244+
},
245+
.flags = {
246+
.clk_gate_en = false,
247+
}
248+
};
249+
250+
printf("install parlio unit\r\n");
251+
TEST_ESP_OK(parlio_new_tx_unit(&tx_config, &tx_unit));
252+
TEST_ESP_OK(parlio_new_rx_unit(&rx_config, &rx_unit));
253+
254+
printf("decorate tx unit with bitscrambler\r\n");
255+
TEST_ESP_OK(parlio_tx_unit_decorate_bitscrambler(tx_unit));
256+
257+
parlio_transmit_config_t transmit_config = {
258+
.idle_value = 0x00,
259+
.bitscrambler_program = bitscrambler_program_test_tx_in32_out8,
260+
};
261+
262+
parlio_rx_delimiter_handle_t deli = NULL;
263+
parlio_rx_level_delimiter_config_t lvl_deli_cfg = {
264+
.valid_sig_line_id = PARLIO_RX_UNIT_MAX_DATA_WIDTH - 1,
265+
.sample_edge = PARLIO_SAMPLE_EDGE_POS,
266+
.bit_pack_order = PARLIO_BIT_PACK_ORDER_LSB,
267+
.eof_data_len = TEST_PAYLOAD_SIZE,
268+
.timeout_ticks = 0,
269+
.flags = {
270+
.active_low_en = 0,
271+
},
272+
};
273+
TEST_ESP_OK(parlio_new_rx_level_delimiter(&lvl_deli_cfg, &deli));
274+
printf("register receive_done event callback\r\n");
275+
test_parlio_bitscrambler_rx_ctx_t rx_ctx = {
276+
.task = xTaskGetCurrentTaskHandle(),
277+
};
278+
parlio_rx_event_callbacks_t rx_cbs = {
279+
.on_receive_done = test_parlio_rx_done_callback,
280+
};
281+
TEST_ESP_OK(parlio_rx_unit_register_event_callbacks(rx_unit, &rx_cbs, &rx_ctx));
282+
283+
parlio_receive_config_t recv_config = {
284+
.delimiter = deli,
285+
.flags.partial_rx_en = false,
286+
};
287+
288+
uint8_t tx_payload[TEST_PAYLOAD_SIZE * 4] = {0};
289+
for (int i = 0; i < TEST_PAYLOAD_SIZE * 4; i++) {
290+
tx_payload[i] = i;
291+
}
292+
293+
__attribute__((aligned(TEST_PAYLOAD_SIZE))) uint8_t rx_payload[TEST_PAYLOAD_SIZE] = {0};
294+
TEST_ESP_OK(parlio_tx_unit_enable(tx_unit));
295+
TEST_ESP_OK(parlio_rx_unit_enable(rx_unit, true));
296+
297+
// test input size is larger than output size
298+
TEST_ESP_OK(parlio_rx_unit_receive(rx_unit, rx_payload, TEST_PAYLOAD_SIZE, &recv_config));
299+
TEST_ESP_OK(parlio_tx_unit_transmit(tx_unit, tx_payload, 4 * TEST_PAYLOAD_SIZE * sizeof(uint8_t) * 8, &transmit_config));
300+
301+
TEST_ASSERT_NOT_EQUAL(0, ulTaskNotifyTake(pdTRUE, pdMS_TO_TICKS(1000)));
302+
TEST_ASSERT_EQUAL(TEST_PAYLOAD_SIZE, rx_ctx.recv_bytes);
303+
304+
for (int i = 0; i < TEST_PAYLOAD_SIZE; i++) {
305+
printf("%.3d ", (rx_payload[i]));
306+
TEST_ASSERT_EQUAL(tx_payload[i * 4 + 3], rx_payload[i]);
307+
if ((i + 1) % 16 == 0) {
308+
printf("\n");
309+
}
310+
}
311+
printf("\n");
312+
313+
// test input size is smaller than output size
314+
transmit_config.bitscrambler_program = bitscrambler_program_test_tx_in8_out32;
315+
316+
TEST_ESP_OK(parlio_rx_unit_receive(rx_unit, rx_payload, TEST_PAYLOAD_SIZE, &recv_config));
317+
TEST_ESP_OK(parlio_tx_unit_transmit(tx_unit, tx_payload, (TEST_PAYLOAD_SIZE / 4) * sizeof(uint8_t) * 8, &transmit_config));
318+
319+
TEST_ASSERT_NOT_EQUAL(0, ulTaskNotifyTake(pdTRUE, pdMS_TO_TICKS(1000)));
320+
TEST_ASSERT_EQUAL(TEST_PAYLOAD_SIZE, rx_ctx.recv_bytes);
321+
322+
for (int i = 0; i < TEST_PAYLOAD_SIZE / 4; i++) {
323+
uint32_t *test_value = (uint32_t *)&rx_payload[i * 4];
324+
printf("0x%lx ", *test_value);
325+
switch (i % 4) {
326+
case 0:
327+
TEST_ASSERT_EQUAL(0x11111, *test_value);
328+
break;
329+
case 1:
330+
TEST_ASSERT_EQUAL(0x22222, *test_value);
331+
break;
332+
case 2:
333+
TEST_ASSERT_EQUAL(0x33333, *test_value);
334+
break;
335+
case 3:
336+
TEST_ASSERT_EQUAL(0x00000, *test_value);
337+
break;
338+
}
339+
if ((i + 1) % 4 == 0) {
340+
printf("\n");
341+
}
342+
}
343+
344+
TEST_ESP_OK(parlio_tx_unit_disable(tx_unit));
345+
TEST_ESP_OK(parlio_tx_unit_undecorate_bitscrambler(tx_unit));
346+
TEST_ESP_OK(parlio_del_tx_unit(tx_unit));
347+
TEST_ESP_OK(parlio_rx_unit_disable(rx_unit));
348+
TEST_ESP_OK(parlio_del_rx_delimiter(deli));
349+
TEST_ESP_OK(parlio_del_rx_unit(rx_unit));
350+
}
351+
352+
TEST_CASE("parlio_tx_bitscrambler_different_input_output_sizes_test", "[parlio_bitscrambler]")
353+
{
354+
test_parlio_bitscrambler_different_input_output_sizes();
355+
}
356+
#endif // SOC_PARLIO_TX_SUPPORT_EOF_FROM_DMA
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
2+
# SPDX-License-Identifier: Unlicense OR CC0-1.0
3+
4+
5+
cfg prefetch true # enable data prefetch
6+
cfg eof_on upstream # set EOF on upstream
7+
cfg trailing_bytes 9 # due to prefetch is enable, upstream is 8 bytes ahead of downstream
8+
9+
loop:
10+
set 0..7 24..31,
11+
12+
write 8,
13+
read 32,
14+
jmp loop
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
2+
# SPDX-License-Identifier: Unlicense OR CC0-1.0
3+
4+
cfg prefetch false # disable data prefetch
5+
cfg eof_on upstream # set EOF on upstream
6+
cfg trailing_bytes 9
7+
cfg lut_width_bits 32
8+
9+
# Define contents that stored in the lookup table
10+
lut 0x00011111 # index 0
11+
lut 0x00022222 # index 1
12+
lut 0x00033333 # index 2
13+
lut 0x00000000 # index 3
14+
15+
set 16..18 L # init the LUT index: 0 (0b000)
16+
17+
loop:
18+
read 8,
19+
set 31..0 L31..L0,
20+
write 32,
21+
jmp loop

0 commit comments

Comments
 (0)