@@ -757,6 +757,78 @@ static void tx_start(const struct device *dev, const uint8_t *buf, size_t len)
757757static void rx_timeout (struct k_timer * timer );
758758static void tx_timeout (struct k_timer * timer );
759759
760+ static void user_callback (const struct device * dev , struct uart_event * evt )
761+ {
762+ struct uarte_nrfx_data * data = dev -> data ;
763+
764+ if (data -> async -> user_callback ) {
765+ data -> async -> user_callback (dev , evt , data -> async -> user_data );
766+ }
767+ }
768+
769+ static void rx_buf_release (const struct device * dev , uint8_t * buf )
770+ {
771+ struct uart_event evt = {
772+ .type = UART_RX_BUF_RELEASED ,
773+ .data .rx_buf .buf = buf ,
774+ };
775+
776+ user_callback (dev , & evt );
777+ }
778+
779+ static void notify_rx_disable (const struct device * dev )
780+ {
781+ const struct uarte_nrfx_config * cfg = dev -> config ;
782+ struct uart_event evt = {
783+ .type = UART_RX_DISABLED ,
784+ };
785+
786+ if (LOW_POWER_ENABLED (cfg )) {
787+ uint32_t key = irq_lock ();
788+
789+ uarte_disable_locked (dev , UARTE_FLAG_LOW_POWER_RX );
790+ irq_unlock (key );
791+ }
792+
793+ user_callback (dev , (struct uart_event * )& evt );
794+
795+ /* runtime PM is put after the callback. In case uart is re-enabled from that
796+ * callback we avoid suspending/resuming the device.
797+ */
798+ if (IS_ENABLED (CONFIG_PM_DEVICE_RUNTIME )) {
799+ pm_device_runtime_put_async (dev , K_NO_WAIT );
800+ }
801+ }
802+
803+ static int uarte_nrfx_rx_disable (const struct device * dev )
804+ {
805+ struct uarte_nrfx_data * data = dev -> data ;
806+ struct uarte_async_rx * async_rx = & data -> async -> rx ;
807+ NRF_UARTE_Type * uarte = get_uarte_instance (dev );
808+ int key ;
809+
810+ if (async_rx -> buf == NULL ) {
811+ return - EFAULT ;
812+ }
813+
814+ k_timer_stop (& async_rx -> timer );
815+
816+ key = irq_lock ();
817+
818+ if (async_rx -> next_buf != NULL ) {
819+ nrf_uarte_shorts_disable (uarte , NRF_UARTE_SHORT_ENDRX_STARTRX );
820+ nrf_uarte_event_clear (uarte , NRF_UARTE_EVENT_RXSTARTED );
821+ }
822+
823+ async_rx -> enabled = false;
824+ async_rx -> discard_fifo = true;
825+
826+ nrf_uarte_task_trigger (uarte , NRF_UARTE_TASK_STOPRX );
827+ irq_unlock (key );
828+
829+ return 0 ;
830+ }
831+
760832#if !defined(CONFIG_UART_NRFX_UARTE_ENHANCED_RX )
761833static void timer_handler (nrf_timer_event_t event_type , void * p_context ) { }
762834
@@ -941,15 +1013,6 @@ static int uarte_nrfx_tx_abort(const struct device *dev)
9411013return 0 ;
9421014}
9431015
944- static void user_callback (const struct device * dev , struct uart_event * evt )
945- {
946- struct uarte_nrfx_data * data = dev -> data ;
947-
948- if (data -> async -> user_callback ) {
949- data -> async -> user_callback (dev , evt , data -> async -> user_data );
950- }
951- }
952-
9531016static void notify_uart_rx_rdy (const struct device * dev , size_t len )
9541017{
9551018struct uarte_nrfx_data * data = dev -> data ;
@@ -963,29 +1026,6 @@ static void notify_uart_rx_rdy(const struct device *dev, size_t len)
9631026user_callback (dev , & evt );
9641027}
9651028
966- static void rx_buf_release (const struct device * dev , uint8_t * buf )
967- {
968- struct uart_event evt = {
969- .type = UART_RX_BUF_RELEASED ,
970- .data .rx_buf .buf = buf ,
971- };
972-
973- user_callback (dev , & evt );
974- }
975-
976- static void notify_rx_disable (const struct device * dev )
977- {
978- struct uart_event evt = {
979- .type = UART_RX_DISABLED ,
980- };
981-
982- user_callback (dev , (struct uart_event * )& evt );
983-
984- if (IS_ENABLED (CONFIG_PM_DEVICE_RUNTIME )) {
985- pm_device_runtime_put_async (dev , K_NO_WAIT );
986- }
987- }
988-
9891029#ifdef UARTE_HAS_FRAME_TIMEOUT
9901030static uint32_t us_to_bauds (uint32_t baudrate , int32_t timeout )
9911031{
@@ -1198,35 +1238,6 @@ static int uarte_nrfx_callback_set(const struct device *dev,
11981238return 0 ;
11991239}
12001240
1201- static int uarte_nrfx_rx_disable (const struct device * dev )
1202- {
1203- struct uarte_nrfx_data * data = dev -> data ;
1204- struct uarte_async_rx * async_rx = & data -> async -> rx ;
1205- NRF_UARTE_Type * uarte = get_uarte_instance (dev );
1206- int key ;
1207-
1208- if (async_rx -> buf == NULL ) {
1209- return - EFAULT ;
1210- }
1211-
1212- k_timer_stop (& async_rx -> timer );
1213-
1214- key = irq_lock ();
1215-
1216- if (async_rx -> next_buf != NULL ) {
1217- nrf_uarte_shorts_disable (uarte , NRF_UARTE_SHORT_ENDRX_STARTRX );
1218- nrf_uarte_event_clear (uarte , NRF_UARTE_EVENT_RXSTARTED );
1219- }
1220-
1221- async_rx -> enabled = false;
1222- async_rx -> discard_fifo = true;
1223-
1224- nrf_uarte_task_trigger (uarte , NRF_UARTE_TASK_STOPRX );
1225- irq_unlock (key );
1226-
1227- return 0 ;
1228- }
1229-
12301241static void tx_timeout (struct k_timer * timer )
12311242{
12321243const struct device * dev = k_timer_user_data_get (timer );
0 commit comments