@@ -103,6 +103,104 @@ void test_single_read(void)
103103 zassert_equal (tx_aborted_count , 0 , "TX aborted triggered" );
104104}
105105
106+ void test_multiple_rx_enable_setup (void )
107+ {
108+ tx_aborted_count = 0 ;
109+
110+ /* Reuse the callback from the single_read test case, as this test case
111+ * does not need anything extra in this regard.
112+ */
113+ uart_callback_set (uart_dev ,
114+ test_single_read_callback ,
115+ (void * )& tx_aborted_count );
116+
117+ k_sem_reset (& rx_rdy );
118+ k_sem_reset (& rx_buf_released );
119+ k_sem_reset (& rx_disabled );
120+ k_sem_reset (& tx_done );
121+ }
122+
123+ void test_multiple_rx_enable (void )
124+ {
125+ /* Check also if sending from read only memory (e.g. flash) works. */
126+ static const uint8_t tx_buf [] = "test" ;
127+ uint8_t rx_buf [sizeof (tx_buf )] = {0 };
128+ int ret ;
129+
130+ /* Enable RX without a timeout. */
131+ ret = uart_rx_enable (uart_dev , rx_buf , sizeof (rx_buf ), SYS_FOREVER_US );
132+ zassert_equal (ret , 0 , "uart_rx_enable failed" );
133+ zassert_equal (k_sem_take (& rx_rdy , K_MSEC (100 )), - EAGAIN ,
134+ "RX_RDY not expected at this point" );
135+ zassert_equal (k_sem_take (& rx_disabled , K_MSEC (100 )), - EAGAIN ,
136+ "RX_DISABLED not expected at this point" );
137+
138+ /* Disable RX before any data has been received. */
139+ ret = uart_rx_disable (uart_dev );
140+ zassert_equal (ret , 0 , "uart_rx_disable failed" );
141+ zassert_equal (k_sem_take (& rx_rdy , K_MSEC (100 )), - EAGAIN ,
142+ "RX_RDY not expected at this point" );
143+ zassert_equal (k_sem_take (& rx_buf_released , K_MSEC (100 )), 0 ,
144+ "RX_BUF_RELEASED timeout" );
145+ zassert_equal (k_sem_take (& rx_disabled , K_MSEC (100 )), 0 ,
146+ "RX_DISABLED timeout" );
147+
148+ k_sem_reset (& rx_buf_released );
149+ k_sem_reset (& rx_disabled );
150+
151+ /* Check that RX can be reenabled after "manual" disabling. */
152+ ret = uart_rx_enable (uart_dev , rx_buf , sizeof (rx_buf ),
153+ 50 * USEC_PER_MSEC );
154+ zassert_equal (ret , 0 , "uart_rx_enable failed" );
155+ zassert_equal (k_sem_take (& rx_rdy , K_MSEC (100 )), - EAGAIN ,
156+ "RX_RDY not expected at this point" );
157+
158+ /* Send enough data to completely fill RX buffer, so that RX ends. */
159+ ret = uart_tx (uart_dev , tx_buf , sizeof (tx_buf ), 100 * USEC_PER_MSEC );
160+ zassert_equal (ret , 0 , "uart_tx failed" );
161+ zassert_equal (k_sem_take (& tx_done , K_MSEC (100 )), 0 , "TX_DONE timeout" );
162+ zassert_equal (k_sem_take (& rx_rdy , K_MSEC (100 )), 0 , "RX_RDY timeout" );
163+ zassert_equal (k_sem_take (& rx_rdy , K_MSEC (100 )), - EAGAIN ,
164+ "Extra RX_RDY received" );
165+ zassert_equal (k_sem_take (& rx_buf_released , K_MSEC (100 )), 0 ,
166+ "RX_BUF_RELEASED timeout" );
167+ zassert_equal (k_sem_take (& rx_disabled , K_MSEC (100 )), 0 ,
168+ "RX_DISABLED timeout" );
169+ zassert_equal (tx_aborted_count , 0 , "Unexpected TX abort" );
170+
171+ zassert_equal (memcmp (tx_buf , rx_buf , sizeof (tx_buf )), 0 ,
172+ "Buffers not equal" );
173+
174+ k_sem_reset (& rx_rdy );
175+ k_sem_reset (& rx_buf_released );
176+ k_sem_reset (& rx_disabled );
177+ k_sem_reset (& tx_done );
178+ memset (rx_buf , 0 , sizeof (rx_buf ));
179+
180+ /* Check that RX can be reenabled after automatic disabling. */
181+ ret = uart_rx_enable (uart_dev , rx_buf , sizeof (rx_buf ),
182+ 50 * USEC_PER_MSEC );
183+ zassert_equal (ret , 0 , "uart_rx_enable failed" );
184+ zassert_equal (k_sem_take (& rx_rdy , K_MSEC (100 )), - EAGAIN ,
185+ "RX_RDY not expected at this point" );
186+
187+ /* Fill RX buffer again to confirm that RX still works properly. */
188+ ret = uart_tx (uart_dev , tx_buf , sizeof (tx_buf ), 100 * USEC_PER_MSEC );
189+ zassert_equal (ret , 0 , "uart_tx failed" );
190+ zassert_equal (k_sem_take (& tx_done , K_MSEC (100 )), 0 , "TX_DONE timeout" );
191+ zassert_equal (k_sem_take (& rx_rdy , K_MSEC (100 )), 0 , "RX_RDY timeout" );
192+ zassert_equal (k_sem_take (& rx_rdy , K_MSEC (100 )), - EAGAIN ,
193+ "Extra RX_RDY received" );
194+ zassert_equal (k_sem_take (& rx_buf_released , K_MSEC (100 )), 0 ,
195+ "RX_BUF_RELEASED timeout" );
196+ zassert_equal (k_sem_take (& rx_disabled , K_MSEC (100 )), 0 ,
197+ "RX_DISABLED timeout" );
198+ zassert_equal (tx_aborted_count , 0 , "Unexpected TX abort" );
199+
200+ zassert_equal (memcmp (tx_buf , rx_buf , sizeof (tx_buf )), 0 ,
201+ "Buffers not equal" );
202+ }
203+
106204ZTEST_BMEM uint8_t chained_read_buf0 [10 ];
107205ZTEST_BMEM uint8_t chained_read_buf1 [20 ];
108206ZTEST_BMEM uint8_t chained_read_buf2 [30 ];
0 commit comments