@@ -811,6 +811,78 @@ 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+ if (async_rx -> next_buf != NULL ) {
873+ nrf_uarte_shorts_disable (uarte , NRF_UARTE_SHORT_ENDRX_STARTRX );
874+ nrf_uarte_event_clear (uarte , NRF_UARTE_EVENT_RXSTARTED );
875+ }
876+
877+ async_rx -> enabled = false;
878+ async_rx -> discard_fifo = true;
879+
880+ nrf_uarte_task_trigger (uarte , NRF_UARTE_TASK_STOPRX );
881+ irq_unlock (key );
882+
883+ return 0 ;
884+ }
885+
814886#if !defined(CONFIG_UART_NRFX_UARTE_ENHANCED_RX )
815887static void timer_handler (nrf_timer_event_t event_type , void * p_context ) { }
816888
@@ -1009,15 +1081,6 @@ static int uarte_nrfx_tx_abort(const struct device *dev)
10091081 return 0 ;
10101082}
10111083
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-
10211084static void notify_uart_rx_rdy (const struct device * dev , size_t len )
10221085{
10231086 struct uarte_nrfx_data * data = dev -> data ;
@@ -1031,29 +1094,6 @@ static void notify_uart_rx_rdy(const struct device *dev, size_t len)
10311094 user_callback (dev , & evt );
10321095}
10331096
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-
10571097#ifdef UARTE_HAS_FRAME_TIMEOUT
10581098static uint32_t us_to_bauds (uint32_t baudrate , int32_t timeout )
10591099{
@@ -1280,35 +1320,6 @@ static int uarte_nrfx_callback_set(const struct device *dev,
12801320 return 0 ;
12811321}
12821322
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-
13121323static void tx_timeout (struct k_timer * timer )
13131324{
13141325 const struct device * dev = k_timer_user_data_get (timer );
0 commit comments