@@ -802,13 +802,14 @@ static inline bool z_impl_device_is_ready(const struct device *dev)
802
802
803
803
/** @cond INTERNAL_HIDDEN */
804
804
805
- /* Synthesize a unique name for the device state associated with
805
+ /**
806
+ * @brief Synthesize a unique name for the device state associated with
806
807
* dev_name.
807
808
*/
808
809
#define Z_DEVICE_STATE_NAME (dev_name ) _CONCAT(__devstate_, dev_name)
809
810
810
- /*
811
- * Utility macro to define and initialize the device state.
811
+ /**
812
+ * @brief Utility macro to define and initialize the device state.
812
813
*
813
814
* @param node_id Devicetree node id of the device.
814
815
* @param dev_name Device name.
@@ -817,20 +818,31 @@ static inline bool z_impl_device_is_ready(const struct device *dev)
817
818
static struct device_state Z_DEVICE_STATE_NAME(dev_name) \
818
819
__attribute__((__section__(".z_devstate")))
819
820
820
- /* Synthesize the name of the object that holds device ordinal and
821
- * dependency data. If the object doesn't come from a devicetree
822
- * node, use dev_name.
821
+ /**
822
+ * @brief Synthesize the name of the object that holds device ordinal and
823
+ * dependency data.
824
+ *
825
+ * @param node_id Devicetree node id of the device.
826
+ * @param dev_name Device name.
823
827
*/
824
828
#define Z_DEVICE_HANDLE_NAME (node_id , dev_name ) \
825
829
_CONCAT(__devicehdl_, \
826
830
COND_CODE_1(DT_NODE_EXISTS(node_id), \
827
831
(node_id), \
828
832
(dev_name)))
829
833
834
+ /**
835
+ * @brief Expand extra handles with a comma in between.
836
+ *
837
+ * @param ... Extra handles
838
+ */
830
839
#define Z_DEVICE_EXTRA_HANDLES (...) \
831
840
FOR_EACH_NONEMPTY_TERM(IDENTITY, (,), __VA_ARGS__)
832
841
833
- /* Initial build provides a record that associates the device object
842
+ /**
843
+ * @brief Define device handles.
844
+ *
845
+ * Initial build provides a record that associates the device object
834
846
* with its devicetree ordinal, and provides the dependency ordinals.
835
847
* These are provided as weak definitions (to prevent the reference
836
848
* from being captured when the original object file is compiled), and
@@ -890,12 +902,34 @@ BUILD_ASSERT(sizeof(device_handle_t) == 2, "fix the linker scripts");
890
902
(DT_SUPPORTS_DEP_ORDS(node_id)), ()) \
891
903
}
892
904
905
+ /**
906
+ * @brief Maximum device name length.
907
+ *
908
+ * The maximum length is set so that device_get_binding() can be used from
909
+ * userspace.
910
+ */
893
911
#define Z_DEVICE_MAX_NAME_LEN 48
894
912
913
+ /**
914
+ * @brief Compile time check for device name length
915
+ *
916
+ * @param name Device name.
917
+ */
895
918
#define Z_DEVICE_NAME_CHECK (name ) \
896
919
BUILD_ASSERT(sizeof(Z_STRINGIFY(name)) <= Z_DEVICE_MAX_NAME_LEN, \
897
920
Z_STRINGIFY(DEVICE_NAME_GET(name)) " too long")
898
921
922
+ /**
923
+ * @brief Initializer for struct device.
924
+ *
925
+ * @param name_ Name of the device.
926
+ * @param pm_ Reference to struct pm_device (optional).
927
+ * @param data_ Reference to device data.
928
+ * @param config_ Reference to device config.
929
+ * @param api_ Reference to device API ops.
930
+ * @param state_ Reference to device state.
931
+ * @param handles_ Reference to device handles.
932
+ */
899
933
#define Z_DEVICE_INIT (name_ , pm_ , data_ , config_ , api_ , state_ , handles_ ) \
900
934
{ \
901
935
.name = name_, \
@@ -907,11 +941,38 @@ BUILD_ASSERT(sizeof(device_handle_t) == 2, "fix the linker scripts");
907
941
IF_ENABLED(CONFIG_PM_DEVICE, (.pm = (pm_),)) \
908
942
}
909
943
944
+ /**
945
+ * @brief Device section
946
+ *
947
+ * Each device is placed in a section with a name crafted so that it allows
948
+ * linker scripts to sort them according to the specified level/priority.
949
+ *
950
+ * @param level Initialization level
951
+ * @param prio Initialization priority
952
+ */
910
953
#define Z_DEVICE_SECTION (level , prio ) \
911
954
__attribute__((__section__(".z_device_" #level STRINGIFY(prio) "_")))
912
955
913
- /* Like DEVICE_DEFINE but takes a node_id AND a dev_name, and trailing
914
- * dependency handles that come from outside devicetree.
956
+ /**
957
+ * @brief Define a struct device
958
+ *
959
+ * This is the common macro used to define struct device objects. It can be
960
+ * used to define both Devicetree and software devices.
961
+ *
962
+ * @param node_id Devicetree node id for the device (DT_INVALID_NODE if a
963
+ * software device).
964
+ * @param dev_name Name of the defined struct device variable.
965
+ * @param drv_name Name of the device.
966
+ * @param init_fn Device init function.
967
+ * @param pm_device Reference to struct pm_device associated with the device.
968
+ * (optional).
969
+ * @param data_ptr Reference to device data.
970
+ * @param cfg_ptr Reference to device config.
971
+ * @param level Initialization level.
972
+ * @param prio Initialization priority.
973
+ * @param api_ptr Reference to device API.
974
+ * @param state_ptr Reference to device state.
975
+ * @param ... Optional dependencies, manually specified.
915
976
*/
916
977
#define Z_DEVICE_DEFINE (node_id , dev_name , drv_name , init_fn , pm_device , \
917
978
data_ptr , cfg_ptr , level , prio , api_ptr , state_ptr , \
@@ -929,16 +990,16 @@ BUILD_ASSERT(sizeof(device_handle_t) == 2, "fix the linker scripts");
929
990
Z_INIT_ENTRY_DEFINE(DEVICE_NAME_GET(dev_name), init_fn, \
930
991
(&DEVICE_NAME_GET(dev_name)), level, prio)
931
992
932
- #if CONFIG_HAS_DTS
933
- /*
934
- * Declare a device for each status "okay" devicetree node. (Disabled
935
- * nodes should not result in devices, so not predeclaring these keeps
936
- * drivers honest.)
937
- *
938
- * This is only "maybe" a device because some nodes have status "okay",
939
- * but don't have a corresponding struct device allocated. There's no way
940
- * to figure that out until after we've built the zephyr image,
941
- * though.
993
+ #if defined( CONFIG_HAS_DTS ) || defined( __DOXYGEN__ )
994
+ /**
995
+ * @brief Declare a device for each status "okay" devicetree node.
996
+ *
997
+ * @note Disabled nodes should not result in devices, so not predeclaring these
998
+ * keeps drivers honest.
999
+ *
1000
+ * This is only "maybe" a device because some nodes have status "okay", but
1001
+ * don't have a corresponding struct device allocated. There's no way to figure
1002
+ * that out until after we've built the zephyr image, though.
942
1003
*/
943
1004
#define Z_MAYBE_DEVICE_DECLARE_INTERNAL (node_id ) \
944
1005
extern const struct device DEVICE_DT_NAME_GET(node_id);
0 commit comments