@@ -811,6 +811,94 @@ static void tx_start(const struct device *dev, const uint8_t *buf, size_t len)
811
811
static void rx_timeout (struct k_timer * timer );
812
812
static void tx_timeout (struct k_timer * timer );
813
813
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
+
814
902
#if !defined(CONFIG_UART_NRFX_UARTE_ENHANCED_RX )
815
903
static void timer_handler (nrf_timer_event_t event_type , void * p_context ) { }
816
904
@@ -1009,15 +1097,6 @@ static int uarte_nrfx_tx_abort(const struct device *dev)
1009
1097
return 0 ;
1010
1098
}
1011
1099
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
-
1021
1100
static void notify_uart_rx_rdy (const struct device * dev , size_t len )
1022
1101
{
1023
1102
struct uarte_nrfx_data * data = dev -> data ;
@@ -1031,29 +1110,6 @@ static void notify_uart_rx_rdy(const struct device *dev, size_t len)
1031
1110
user_callback (dev , & evt );
1032
1111
}
1033
1112
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
-
1057
1113
#ifdef UARTE_HAS_FRAME_TIMEOUT
1058
1114
static uint32_t us_to_bauds (uint32_t baudrate , int32_t timeout )
1059
1115
{
@@ -1280,35 +1336,6 @@ static int uarte_nrfx_callback_set(const struct device *dev,
1280
1336
return 0 ;
1281
1337
}
1282
1338
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
-
1312
1339
static void tx_timeout (struct k_timer * timer )
1313
1340
{
1314
1341
const struct device * dev = k_timer_user_data_get (timer );
0 commit comments