Lines Matching +full:tx +full:- +full:dummy

4  * SPDX-License-Identifier: Apache-2.0
18 #define UART_DUMMY_NODE DT_NODELABEL(dummy)
24 * Leave one byte left in tx to avoid filling it completely which will block the UART
25 * tx ready IRQ event.
27 #define SAMPLE_DATA_SIZE MIN(EMUL_UART_RX_FIFO_SIZE, EMUL_UART_TX_FIFO_SIZE) - 1
69 uart_emul_flush_rx_data(fixture->dev); in uart_emul_device_before()
70 uart_emul_flush_tx_data(fixture->dev); in uart_emul_device_before()
72 uart_err_check(fixture->dev); in uart_emul_device_before()
74 memset(fixture->rx_content, 0, sizeof(fixture->rx_content)); in uart_emul_device_before()
77 uart_irq_tx_disable(fixture->dev); in uart_emul_device_before()
78 uart_irq_rx_disable(fixture->dev); in uart_emul_device_before()
80 k_sem_reset(&fixture->tx_done_sem); in uart_emul_device_before()
81 k_sem_reset(&fixture->rx_done_sem); in uart_emul_device_before()
83 fixture->tx_remaining = SAMPLE_DATA_SIZE; in uart_emul_device_before()
84 fixture->rx_remaining = SAMPLE_DATA_SIZE; in uart_emul_device_before()
88 uart_tx_abort(fixture->dev); in uart_emul_device_before()
89 uart_rx_disable(fixture->dev); in uart_emul_device_before()
91 k_event_set(&fixture->async_events, 0); in uart_emul_device_before()
102 uart_poll_out(fixture->dev, i); in ZTEST_F()
105 len = uart_emul_get_tx_data(fixture->dev, NULL, UINT32_MAX); in ZTEST_F()
106 zassert_equal(len, 0, "TX buffer should be empty"); in ZTEST_F()
109 ret = uart_poll_in(fixture->dev, &byte); in ZTEST_F()
114 ret = uart_poll_in(fixture->dev, &byte); in ZTEST_F()
115 zassert_equal(ret, -1, "RX buffer should be empty"); in ZTEST_F()
124 if (fixture->tx_remaining) { in uart_emul_device_isr_handle_tx_ready()
125 sample_data_it = sizeof(fixture->sample_data) - fixture->tx_remaining; in uart_emul_device_isr_handle_tx_ready()
126 ret = uart_fifo_fill(fixture->dev, &fixture->sample_data[sample_data_it], in uart_emul_device_isr_handle_tx_ready()
127 fixture->tx_remaining); in uart_emul_device_isr_handle_tx_ready()
128 fixture->tx_remaining -= (size_t)ret; in uart_emul_device_isr_handle_tx_ready()
131 if (fixture->tx_remaining == 0) { in uart_emul_device_isr_handle_tx_ready()
132 uart_irq_tx_disable(fixture->dev); in uart_emul_device_isr_handle_tx_ready()
133 k_sem_give(&fixture->tx_done_sem); in uart_emul_device_isr_handle_tx_ready()
142 if (fixture->rx_remaining) { in uart_emul_device_isr_handle_rx_ready()
143 rx_content_it = sizeof(fixture->rx_content) - fixture->rx_remaining; in uart_emul_device_isr_handle_rx_ready()
144 ret = uart_fifo_read(fixture->dev, &fixture->rx_content[rx_content_it], in uart_emul_device_isr_handle_rx_ready()
145 fixture->rx_remaining); in uart_emul_device_isr_handle_rx_ready()
146 fixture->rx_remaining -= (size_t)ret; in uart_emul_device_isr_handle_rx_ready()
149 if (fixture->rx_remaining == 0) { in uart_emul_device_isr_handle_rx_ready()
150 k_sem_give(&fixture->rx_done_sem); in uart_emul_device_isr_handle_rx_ready()
159 if (uart_irq_tx_ready(fixture->dev)) { in uart_emul_device_isr()
162 if (uart_irq_rx_ready(fixture->dev)) { in uart_emul_device_isr()
173 uart_irq_callback_user_data_set(fixture->dev, uart_emul_device_isr, fixture); in ZTEST_F()
175 uart_irq_rx_enable(fixture->dev); in ZTEST_F()
176 /* enabling the tx irq will call the callback, if set */ in ZTEST_F()
177 uart_irq_tx_enable(fixture->dev); in ZTEST_F()
180 zassert_ok(k_sem_take(&fixture->tx_done_sem, K_SECONDS(1)), in ZTEST_F()
181 "Timeout waiting for UART TX ISR"); in ZTEST_F()
183 tx_len = uart_emul_get_tx_data(fixture->dev, NULL, SAMPLE_DATA_SIZE); in ZTEST_F()
184 zassert_equal(tx_len, 0, "TX buffer should be empty"); in ZTEST_F()
186 zassert_ok(k_sem_take(&fixture->rx_done_sem, K_SECONDS(1)), in ZTEST_F()
188 zassert_mem_equal(fixture->rx_content, fixture->sample_data, SAMPLE_DATA_SIZE); in ZTEST_F()
191 rc = uart_poll_in(fixture->dev, &fixture->rx_content[0]); in ZTEST_F()
192 zassert_equal(rc, -1, "RX buffer should be empty"); in ZTEST_F()
194 uart_irq_rx_disable(fixture->dev); in ZTEST_F()
204 k_event_post(&fixture->async_events, ((uint32_t)1 << evt->type)); in uart_emul_callback()
206 switch (evt->type) { in uart_emul_callback()
208 zassert_equal(evt->data.tx.len, sizeof(fixture->sample_data)); in uart_emul_callback()
209 zassert_equal(evt->data.tx.buf, fixture->sample_data); in uart_emul_callback()
212 zassert_equal(evt->data.rx.len, sizeof(fixture->sample_data)); in uart_emul_callback()
213 zassert_mem_equal(&evt->data.rx.buf[evt->data.rx.offset], fixture->sample_data, in uart_emul_callback()
214 sizeof(fixture->sample_data)); in uart_emul_callback()
217 zassert_equal(evt->data.rx_buf.buf, fixture->rx_content); in uart_emul_callback()
230 return k_event_wait(&fixture->async_events, ((uint32_t)1 << event), false, K_SECONDS(1)) != in uart_emul_device_wait_for_event()
238 uart_emul_set_release_buffer_on_timeout(fixture->dev, true); in ZTEST_F()
240 zassert_ok(uart_callback_set(fixture->dev, uart_emul_callback, fixture)); in ZTEST_F()
241 zassert_ok(uart_tx(fixture->dev, fixture->sample_data, sizeof(fixture->sample_data), in ZTEST_F()
243 zassert_ok(uart_rx_enable(fixture->dev, fixture->rx_content, sizeof(fixture->rx_content), in ZTEST_F()
250 tx_len = uart_emul_get_tx_data(fixture->dev, NULL, SAMPLE_DATA_SIZE); in ZTEST_F()
251 zassert_equal(tx_len, 0, "TX buffer should be empty"); in ZTEST_F()
257 zassert_mem_equal(fixture->rx_content, fixture->sample_data, SAMPLE_DATA_SIZE); in ZTEST_F()
269 /* Our dummy device echoes all data received */
276 zassert_equal(target->bus_type, EMUL_BUS_TYPE_UART, "UART bus required"); in uart_dummy_emul_tx_ready()