@@ -811,6 +811,94 @@ static void tx_start(const struct device *dev, const uint8_t *buf, size_t len)
811811static void rx_timeout (struct k_timer * timer );
812812static void tx_timeout (struct k_timer * timer );
813813
814+ static void user_callback (const struct device * dev , struct uart_event * evt )
815+ {
816+ struct uarte_nrfx_data * data = dev -> data ;
817+
818+ if (data -> async -> user_callback ) {
819+ data -> async -> user_callback (dev , evt , data -> async -> user_data );
820+ }
821+ }
822+
823+ static void rx_buf_release (const struct device * dev , uint8_t * buf )
824+ {
825+ struct uart_event evt = {
826+ .type = UART_RX_BUF_RELEASED ,
827+ .data .rx_buf .buf = buf ,
828+ };
829+
830+ user_callback (dev , & evt );
831+ }
832+
833+ static void notify_rx_disable (const struct device * dev )
834+ {
835+ const struct uarte_nrfx_config * cfg = dev -> config ;
836+ struct uart_event evt = {
837+ .type = UART_RX_DISABLED ,
838+ };
839+
840+ if (LOW_POWER_ENABLED (cfg )) {
841+ uint32_t key = irq_lock ();
842+
843+ uarte_disable_locked (dev , UARTE_FLAG_LOW_POWER_RX );
844+ irq_unlock (key );
845+ }
846+
847+ user_callback (dev , (struct uart_event * )& evt );
848+
849+ /* runtime PM is put after the callback. In case uart is re-enabled from that
850+ * callback we avoid suspending/resuming the device.
851+ */
852+ if (IS_ENABLED (CONFIG_PM_DEVICE_RUNTIME )) {
853+ pm_device_runtime_put_async (dev , K_NO_WAIT );
854+ }
855+ }
856+
857+ static int uarte_nrfx_rx_disable (const struct device * dev )
858+ {
859+ struct uarte_nrfx_data * data = dev -> data ;
860+ struct uarte_async_rx * async_rx = & data -> async -> rx ;
861+ NRF_UARTE_Type * uarte = get_uarte_instance (dev );
862+ int key ;
863+
864+ if (async_rx -> buf == NULL ) {
865+ return - EFAULT ;
866+ }
867+
868+ k_timer_stop (& async_rx -> timer );
869+
870+ key = irq_lock ();
871+
872+ #ifdef UARTE_COUNT_BYTES_WITH_TIMER
873+ const struct uarte_nrfx_config * cfg = dev -> config ;
874+ struct uarte_async_rx_bounce * b_data = data -> async -> rx .bounce_buf_data ;
875+
876+ if (b_data ) {
877+ nrf_timer_event_clear (cfg -> timer_regs ,
878+ nrf_timer_compare_event_get (UARTE_TIMER_BUF_SWITCH_CH ));
879+ nrf_timer_event_clear (cfg -> timer_regs ,
880+ nrf_timer_compare_event_get (UARTE_TIMER_USR_CNT_CH ));
881+ nrf_timer_int_disable (cfg -> timer_regs ,
882+ nrf_timer_compare_int_get (UARTE_TIMER_BUF_SWITCH_CH ) |
883+ nrf_timer_compare_int_get (UARTE_TIMER_USR_CNT_CH ));
884+ nrf_uarte_shorts_disable (cfg -> uarte_regs , NRF_UARTE_SHORT_ENDRX_STARTRX );
885+ }
886+ #endif
887+
888+ if (async_rx -> next_buf != NULL ) {
889+ nrf_uarte_shorts_disable (uarte , NRF_UARTE_SHORT_ENDRX_STARTRX );
890+ nrf_uarte_event_clear (uarte , NRF_UARTE_EVENT_RXSTARTED );
891+ }
892+
893+ async_rx -> enabled = false;
894+ async_rx -> discard_fifo = true;
895+
896+ nrf_uarte_task_trigger (uarte , NRF_UARTE_TASK_STOPRX );
897+ irq_unlock (key );
898+
899+ return 0 ;
900+ }
901+
814902#if !defined(CONFIG_UART_NRFX_UARTE_ENHANCED_RX )
815903static void timer_handler (nrf_timer_event_t event_type , void * p_context ) { }
816904
@@ -1009,15 +1097,6 @@ static int uarte_nrfx_tx_abort(const struct device *dev)
10091097 return 0 ;
10101098}
10111099
1012- static void user_callback (const struct device * dev , struct uart_event * evt )
1013- {
1014- struct uarte_nrfx_data * data = dev -> data ;
1015-
1016- if (data -> async -> user_callback ) {
1017- data -> async -> user_callback (dev , evt , data -> async -> user_data );
1018- }
1019- }
1020-
10211100static void notify_uart_rx_rdy (const struct device * dev , size_t len )
10221101{
10231102 struct uarte_nrfx_data * data = dev -> data ;
@@ -1031,29 +1110,6 @@ static void notify_uart_rx_rdy(const struct device *dev, size_t len)
10311110 user_callback (dev , & evt );
10321111}
10331112
1034- static void rx_buf_release (const struct device * dev , uint8_t * buf )
1035- {
1036- struct uart_event evt = {
1037- .type = UART_RX_BUF_RELEASED ,
1038- .data .rx_buf .buf = buf ,
1039- };
1040-
1041- user_callback (dev , & evt );
1042- }
1043-
1044- static void notify_rx_disable (const struct device * dev )
1045- {
1046- struct uart_event evt = {
1047- .type = UART_RX_DISABLED ,
1048- };
1049-
1050- user_callback (dev , (struct uart_event * )& evt );
1051-
1052- if (IS_ENABLED (CONFIG_PM_DEVICE_RUNTIME )) {
1053- pm_device_runtime_put_async (dev , K_NO_WAIT );
1054- }
1055- }
1056-
10571113#ifdef UARTE_HAS_FRAME_TIMEOUT
10581114static uint32_t us_to_bauds (uint32_t baudrate , int32_t timeout )
10591115{
@@ -1280,35 +1336,6 @@ static int uarte_nrfx_callback_set(const struct device *dev,
12801336 return 0 ;
12811337}
12821338
1283- static int uarte_nrfx_rx_disable (const struct device * dev )
1284- {
1285- struct uarte_nrfx_data * data = dev -> data ;
1286- struct uarte_async_rx * async_rx = & data -> async -> rx ;
1287- NRF_UARTE_Type * uarte = get_uarte_instance (dev );
1288- int key ;
1289-
1290- if (async_rx -> buf == NULL ) {
1291- return - EFAULT ;
1292- }
1293-
1294- k_timer_stop (& async_rx -> timer );
1295-
1296- key = irq_lock ();
1297-
1298- if (async_rx -> next_buf != NULL ) {
1299- nrf_uarte_shorts_disable (uarte , NRF_UARTE_SHORT_ENDRX_STARTRX );
1300- nrf_uarte_event_clear (uarte , NRF_UARTE_EVENT_RXSTARTED );
1301- }
1302-
1303- async_rx -> enabled = false;
1304- async_rx -> discard_fifo = true;
1305-
1306- nrf_uarte_task_trigger (uarte , NRF_UARTE_TASK_STOPRX );
1307- irq_unlock (key );
1308-
1309- return 0 ;
1310- }
1311-
13121339static void tx_timeout (struct k_timer * timer )
13131340{
13141341 const struct device * dev = k_timer_user_data_get (timer );
0 commit comments