@@ -168,13 +168,13 @@ static int rx_enable(void)
168168
169169 buf = buf_alloc ();
170170 if (!buf ) {
171- LOG_DBG ("Failed to allocate RX buffer" );
171+ LOG_ERR ("Failed to allocate RX buffer" );
172172 return - ENOMEM ;
173173 }
174174
175175 ret = uart_rx_enable (uart_dev , buf -> buf , sizeof (buf -> buf ), UART_RX_TIMEOUT_US );
176- if (ret ) {
177- LOG_WRN ("uart_rx_enable failed: %d" , ret );
176+ if (ret && ret != - EBUSY ) {
177+ LOG_ERR ("uart_rx_enable failed: %d" , ret );
178178 buf_unref (buf -> buf );
179179 return ret ;
180180 }
@@ -208,7 +208,10 @@ static int rx_disable(void)
208208 }
209209
210210 /* Wait until RX is actually disabled. */
211- k_sem_take (& uart_disabled_sem , K_MSEC (100 ));
211+ err = k_sem_take (& uart_disabled_sem , K_MSEC (100 ));
212+ if (err ) {
213+ LOG_ERR ("UART RX disable timeout: %d" , err );
214+ }
212215 atomic_clear_bit (& uart_state , SM_AT_CLIENT_RX_ENABLED_BIT );
213216
214217 return 0 ;
@@ -451,9 +454,6 @@ static void reschedule_disable(void)
451454 if (dtr_config .active && dtr_config .automatic ) {
452455 /* Restart the inactivity timer. */
453456 k_work_reschedule (& dtr_uart_disable_work , dtr_config .inactivity );
454- } else {
455- /* Stop the inactivity timer. */
456- k_work_cancel_delayable (& dtr_uart_disable_work );
457457 }
458458}
459459
@@ -913,21 +913,24 @@ int sm_at_client_send_data(const uint8_t *const data, size_t datalen)
913913 return tx_write (data , datalen , true);
914914}
915915
916- void sm_at_client_configure_dtr_uart ( bool automatic , k_timeout_t inactivity )
916+ void sm_at_client_automatic_dtr_uart ( k_timeout_t inactivity )
917917{
918918 if (!initialized ) {
919919 LOG_ERR ("AT client not initialized" );
920920 return ;
921921 }
922922
923- dtr_config .automatic = automatic ;
923+ dtr_config .automatic = true ;
924924 dtr_config .inactivity = inactivity ;
925925
926- if (dtr_config . automatic && !dtr_config .active && !ring_buf_is_empty (& tx_buf )) {
927- /* If automatic DTR UART is enabled and there is data to send, enable DTR UART . */
926+ if (!dtr_config .active && !ring_buf_is_empty (& tx_buf )) {
927+ /* Automatic mode enabled with pending TX data: trigger enable. */
928928 k_work_submit (& dtr_uart_enable_work );
929- } else {
930- reschedule_disable ();
929+ }
930+
931+ if (dtr_config .active ) {
932+ /* Restart the inactivity timer. */
933+ k_work_reschedule (& dtr_uart_disable_work , dtr_config .inactivity );
931934 }
932935}
933936
@@ -938,7 +941,8 @@ void sm_at_client_disable_dtr_uart(void)
938941 return ;
939942 }
940943
941- sm_at_client_configure_dtr_uart (false, K_NO_WAIT );
944+ dtr_config .automatic = false;
945+ k_work_cancel (& dtr_uart_enable_work );
942946 k_work_reschedule (& dtr_uart_disable_work , K_NO_WAIT );
943947}
944948
@@ -949,7 +953,8 @@ void sm_at_client_enable_dtr_uart(void)
949953 return ;
950954 }
951955
952- sm_at_client_configure_dtr_uart (false, K_NO_WAIT );
956+ dtr_config .automatic = false;
957+ k_work_cancel_delayable (& dtr_uart_disable_work );
953958 k_work_submit (& dtr_uart_enable_work );
954959}
955960
@@ -993,7 +998,7 @@ int sm_at_client_shell_smsh_dtr_uart_auto(const struct shell *shell, size_t argc
993998 return - EINVAL ;
994999 }
9951000
996- sm_at_client_configure_dtr_uart (true, K_MSEC (timeout ));
1001+ sm_at_client_automatic_dtr_uart ( K_MSEC (timeout ));
9971002
9981003 shell_print (shell , "Automatic DTR UART. Inactivity timeout %u ms" , timeout );
9991004
0 commit comments