@@ -447,11 +447,16 @@ __subsystem struct uart_driver_api {
447
447
/**
448
448
* @brief Set event handler function.
449
449
*
450
+ * Since it is mandatory to set callback to use other asynchronous functions,
451
+ * it can be used to detect if the device supports asynchronous API. Remaining
452
+ * API does not have that detection.
453
+ *
450
454
* @param dev UART device structure.
451
455
* @param callback Event handler.
452
456
* @param user_data Data to pass to event handler function.
453
457
*
454
- * @retval -ENOTSUP If not supported.
458
+ * @retval -ENOSYS If not supported by the device.
459
+ * @retval -ENOTSUP If API not enabled.
455
460
* @retval 0 If successful, negative errno code otherwise.
456
461
*/
457
462
static inline int uart_callback_set (const struct device * dev ,
@@ -462,6 +467,10 @@ static inline int uart_callback_set(const struct device *dev,
462
467
const struct uart_driver_api * api =
463
468
(const struct uart_driver_api * )dev -> api ;
464
469
470
+ if (api -> callback_set == NULL ) {
471
+ return - ENOSYS ;
472
+ }
473
+
465
474
return api -> callback_set (dev , callback , user_data );
466
475
#else
467
476
return - ENOTSUP ;
@@ -637,6 +646,7 @@ static inline int z_impl_uart_rx_disable(const struct device *dev)
637
646
*
638
647
* @retval uart_rx_stop_reason If error during receiving occurred.
639
648
* @retval 0 Otherwise.
649
+ * @retval -ENOSYS If this function is not supported.
640
650
*/
641
651
__syscall int uart_err_check (const struct device * dev );
642
652
@@ -648,6 +658,7 @@ static inline int z_impl_uart_err_check(const struct device *dev)
648
658
if (api -> err_check == NULL ) {
649
659
return - ENOSYS ;
650
660
}
661
+
651
662
return api -> err_check (dev );
652
663
}
653
664
@@ -661,7 +672,7 @@ static inline int z_impl_uart_err_check(const struct device *dev)
661
672
* @retval 0 If a character arrived.
662
673
* @retval -1 If no character was available to read (i.e., the UART
663
674
* input buffer was empty).
664
- * @retval -ENOTSUP If the operation is not supported.
675
+ * @retval -ENOSYS If the operation is not supported.
665
676
* @retval -EBUSY If reception was enabled using uart_rx_enabled
666
677
*/
667
678
__syscall int uart_poll_in (const struct device * dev , unsigned char * p_char );
@@ -672,6 +683,10 @@ static inline int z_impl_uart_poll_in(const struct device *dev,
672
683
const struct uart_driver_api * api =
673
684
(const struct uart_driver_api * )dev -> api ;
674
685
686
+ if (api -> poll_in == NULL ) {
687
+ return - ENOSYS ;
688
+ }
689
+
675
690
return api -> poll_in (dev , p_char );
676
691
}
677
692
@@ -737,7 +752,7 @@ static inline int z_impl_uart_configure(const struct device *dev,
737
752
* @param dev UART device structure.
738
753
* @param cfg UART configuration structure.
739
754
*
740
- * @retval -ENOTSUP If driver does not support getting current configuration.
755
+ * @retval -ENOSYS If driver does not support getting current configuration.
741
756
* @retval 0 If successful, negative errno code otherwise.
742
757
*/
743
758
__syscall int uart_config_get (const struct device * dev ,
@@ -754,7 +769,6 @@ static inline int z_impl_uart_config_get(const struct device *dev,
754
769
}
755
770
756
771
return api -> config_get (dev , cfg );
757
-
758
772
}
759
773
760
774
/**
@@ -774,6 +788,8 @@ static inline int z_impl_uart_config_get(const struct device *dev,
774
788
* @param size Number of bytes to send.
775
789
*
776
790
* @return Number of bytes sent.
791
+ * @retval -ENOSYS if this function is not supported
792
+ * @retval -ENOTSUP if API is not enabled.
777
793
*/
778
794
static inline int uart_fifo_fill (const struct device * dev ,
779
795
const uint8_t * tx_data ,
@@ -783,12 +799,14 @@ static inline int uart_fifo_fill(const struct device *dev,
783
799
const struct uart_driver_api * api =
784
800
(const struct uart_driver_api * )dev -> api ;
785
801
786
- if (api -> fifo_fill ! = NULL ) {
787
- return api -> fifo_fill ( dev , tx_data , size ) ;
802
+ if (api -> fifo_fill = = NULL ) {
803
+ return - ENOSYS ;
788
804
}
805
+
806
+ return api -> fifo_fill (dev , tx_data , size );
789
807
#endif
790
808
791
- return 0 ;
809
+ return - ENOTSUP ;
792
810
}
793
811
794
812
/**
@@ -812,6 +830,8 @@ static inline int uart_fifo_fill(const struct device *dev,
812
830
* @param size Container size.
813
831
*
814
832
* @return Number of bytes read.
833
+ * @retval -ENOSYS if this function is not supported.
834
+ * @retval -ENOTSUP if API is not enabled.
815
835
*/
816
836
static inline int uart_fifo_read (const struct device * dev , uint8_t * rx_data ,
817
837
const int size )
@@ -820,12 +840,14 @@ static inline int uart_fifo_read(const struct device *dev, uint8_t *rx_data,
820
840
const struct uart_driver_api * api =
821
841
(const struct uart_driver_api * )dev -> api ;
822
842
823
- if (api -> fifo_read ! = NULL ) {
824
- return api -> fifo_read ( dev , rx_data , size ) ;
843
+ if (api -> fifo_read = = NULL ) {
844
+ return - ENOSYS ;
825
845
}
846
+
847
+ return api -> fifo_read (dev , rx_data , size );
826
848
#endif
827
849
828
- return 0 ;
850
+ return - ENOTSUP ;
829
851
}
830
852
831
853
/**
@@ -882,20 +904,24 @@ static inline void z_impl_uart_irq_tx_disable(const struct device *dev)
882
904
* @param dev UART device structure.
883
905
*
884
906
* @retval 1 If at least one char can be written to UART.
885
- * @retval 0 Otherwise.
907
+ * @retval 0 If device is not ready to write a new byte.
908
+ * @retval -ENOSYS if this function is not supported.
909
+ * @retval -ENOTSUP if API is not enabled.
886
910
*/
887
911
static inline int uart_irq_tx_ready (const struct device * dev )
888
912
{
889
913
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
890
914
const struct uart_driver_api * api =
891
915
(const struct uart_driver_api * )dev -> api ;
892
916
893
- if (api -> irq_tx_ready ! = NULL ) {
894
- return api -> irq_tx_ready ( dev ) ;
917
+ if (api -> irq_tx_ready = = NULL ) {
918
+ return - ENOSYS ;
895
919
}
920
+
921
+ return api -> irq_tx_ready (dev );
896
922
#endif
897
923
898
- return 0 ;
924
+ return - ENOTSUP ;
899
925
}
900
926
901
927
/**
@@ -955,8 +981,9 @@ static inline void z_impl_uart_irq_rx_disable(const struct device *dev)
955
981
* @param dev UART device structure.
956
982
*
957
983
* @retval 1 If nothing remains to be transmitted.
958
- * @retval 0 Otherwise.
959
- * @retval -ENOTSUP if this function is not supported
984
+ * @retval 0 If transmission is not completed.
985
+ * @retval -ENOSYS if this function is not supported.
986
+ * @retval -ENOTSUP if API is not enabled.
960
987
*/
961
988
static inline int uart_irq_tx_complete (const struct device * dev )
962
989
{
@@ -990,8 +1017,9 @@ static inline int uart_irq_tx_complete(const struct device *dev)
990
1017
* @param dev UART device structure.
991
1018
*
992
1019
* @retval 1 If a received char is ready.
993
- * @retval 0 Otherwise.
994
- * @retval -ENOTSUP if this function is not supported
1020
+ * @retval 0 If a received char is not ready.
1021
+ * @retval -ENOSYS if this function is not supported.
1022
+ * @retval -ENOTSUP if API is not enabled.
995
1023
*/
996
1024
static inline int uart_irq_rx_ready (const struct device * dev )
997
1025
{
@@ -1005,7 +1033,7 @@ static inline int uart_irq_rx_ready(const struct device *dev)
1005
1033
return api -> irq_rx_ready (dev );
1006
1034
#endif
1007
1035
1008
- return 0 ;
1036
+ return - ENOTSUP ;
1009
1037
}
1010
1038
/**
1011
1039
* @brief Enable error interrupt.
@@ -1056,7 +1084,9 @@ static inline void z_impl_uart_irq_err_disable(const struct device *dev)
1056
1084
* @param dev UART device structure.
1057
1085
*
1058
1086
* @retval 1 If an IRQ is pending.
1059
- * @retval 0 Otherwise.
1087
+ * @retval 0 If an IRQ is not pending.
1088
+ * @retval -ENOSYS if this function is not supported.
1089
+ * @retval -ENOTSUP if API is not enabled.
1060
1090
*/
1061
1091
__syscall int uart_irq_is_pending (const struct device * dev );
1062
1092
@@ -1071,7 +1101,7 @@ static inline int z_impl_uart_irq_is_pending(const struct device *dev)
1071
1101
}
1072
1102
return api -> irq_is_pending (dev );
1073
1103
#endif
1074
- return 0 ;
1104
+ return - ENOTSUP ;
1075
1105
}
1076
1106
1077
1107
/**
@@ -1095,7 +1125,9 @@ static inline int z_impl_uart_irq_is_pending(const struct device *dev)
1095
1125
*
1096
1126
* @param dev UART device structure.
1097
1127
*
1098
- * @retval 1 Always.
1128
+ * @retval -ENOSYS if this function is not supported.
1129
+ * @retval -ENOTSUP if API is not enabled.
1130
+ * @retval 1 On success.
1099
1131
*/
1100
1132
__syscall int uart_irq_update (const struct device * dev );
1101
1133
@@ -1110,7 +1142,7 @@ static inline int z_impl_uart_irq_update(const struct device *dev)
1110
1142
}
1111
1143
return api -> irq_update (dev );
1112
1144
#endif
1113
- return 0 ;
1145
+ return - ENOTSUP ;
1114
1146
}
1115
1147
1116
1148
/**
@@ -1166,7 +1198,9 @@ static inline void uart_irq_callback_set(const struct device *dev,
1166
1198
* @param val Value to set to the line control.
1167
1199
*
1168
1200
* @retval 0 If successful.
1169
- * @retval failed Otherwise.
1201
+ * @retval -ENOSYS if this function is not supported.
1202
+ * @retval -ENOTSUP if API is not enabled.
1203
+ * @retval negative value if failed.
1170
1204
*/
1171
1205
__syscall int uart_line_ctrl_set (const struct device * dev ,
1172
1206
uint32_t ctrl , uint32_t val );
@@ -1195,7 +1229,9 @@ static inline int z_impl_uart_line_ctrl_set(const struct device *dev,
1195
1229
* @param val Pointer to variable where to store the line control value.
1196
1230
*
1197
1231
* @retval 0 If successful.
1198
- * @retval failed Otherwise.
1232
+ * @retval -ENOSYS if this function is not supported.
1233
+ * @retval -ENOTSUP if API is not enabled.
1234
+ * @retval negative value if failed.
1199
1235
*/
1200
1236
__syscall int uart_line_ctrl_get (const struct device * dev , uint32_t ctrl ,
1201
1237
uint32_t * val );
@@ -1227,7 +1263,9 @@ static inline int z_impl_uart_line_ctrl_get(const struct device *dev,
1227
1263
* @param p Parameter to the command.
1228
1264
*
1229
1265
* @retval 0 If successful.
1230
- * @retval failed Otherwise.
1266
+ * @retval -ENOSYS if this function is not supported.
1267
+ * @retval -ENOTSUP if API is not enabled.
1268
+ * @retval negative value if failed.
1231
1269
*/
1232
1270
__syscall int uart_drv_cmd (const struct device * dev , uint32_t cmd , uint32_t p );
1233
1271
0 commit comments