Skip to content

Commit 8ddd429

Browse files
gmarullcarlescufi
authored andcommitted
device: add documentation for some internal helpers
Add or extend documentation for some internal device helpers. Signed-off-by: Gerard Marull-Paretas <[email protected]>
1 parent ba81ec2 commit 8ddd429

File tree

1 file changed

+80
-19
lines changed

1 file changed

+80
-19
lines changed

include/zephyr/device.h

Lines changed: 80 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -802,13 +802,14 @@ static inline bool z_impl_device_is_ready(const struct device *dev)
802802

803803
/** @cond INTERNAL_HIDDEN */
804804

805-
/* Synthesize a unique name for the device state associated with
805+
/**
806+
* @brief Synthesize a unique name for the device state associated with
806807
* dev_name.
807808
*/
808809
#define Z_DEVICE_STATE_NAME(dev_name) _CONCAT(__devstate_, dev_name)
809810

810-
/*
811-
* Utility macro to define and initialize the device state.
811+
/**
812+
* @brief Utility macro to define and initialize the device state.
812813
*
813814
* @param node_id Devicetree node id of the device.
814815
* @param dev_name Device name.
@@ -817,20 +818,31 @@ static inline bool z_impl_device_is_ready(const struct device *dev)
817818
static struct device_state Z_DEVICE_STATE_NAME(dev_name) \
818819
__attribute__((__section__(".z_devstate")))
819820

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.
823827
*/
824828
#define Z_DEVICE_HANDLE_NAME(node_id, dev_name) \
825829
_CONCAT(__devicehdl_, \
826830
COND_CODE_1(DT_NODE_EXISTS(node_id), \
827831
(node_id), \
828832
(dev_name)))
829833

834+
/**
835+
* @brief Expand extra handles with a comma in between.
836+
*
837+
* @param ... Extra handles
838+
*/
830839
#define Z_DEVICE_EXTRA_HANDLES(...) \
831840
FOR_EACH_NONEMPTY_TERM(IDENTITY, (,), __VA_ARGS__)
832841

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
834846
* with its devicetree ordinal, and provides the dependency ordinals.
835847
* These are provided as weak definitions (to prevent the reference
836848
* 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");
890902
(DT_SUPPORTS_DEP_ORDS(node_id)), ()) \
891903
}
892904

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+
*/
893911
#define Z_DEVICE_MAX_NAME_LEN 48
894912

913+
/**
914+
* @brief Compile time check for device name length
915+
*
916+
* @param name Device name.
917+
*/
895918
#define Z_DEVICE_NAME_CHECK(name) \
896919
BUILD_ASSERT(sizeof(Z_STRINGIFY(name)) <= Z_DEVICE_MAX_NAME_LEN, \
897920
Z_STRINGIFY(DEVICE_NAME_GET(name)) " too long")
898921

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+
*/
899933
#define Z_DEVICE_INIT(name_, pm_, data_, config_, api_, state_, handles_) \
900934
{ \
901935
.name = name_, \
@@ -907,11 +941,38 @@ BUILD_ASSERT(sizeof(device_handle_t) == 2, "fix the linker scripts");
907941
IF_ENABLED(CONFIG_PM_DEVICE, (.pm = (pm_),)) \
908942
}
909943

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+
*/
910953
#define Z_DEVICE_SECTION(level, prio) \
911954
__attribute__((__section__(".z_device_" #level STRINGIFY(prio) "_")))
912955

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.
915976
*/
916977
#define Z_DEVICE_DEFINE(node_id, dev_name, drv_name, init_fn, pm_device, \
917978
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");
929990
Z_INIT_ENTRY_DEFINE(DEVICE_NAME_GET(dev_name), init_fn, \
930991
(&DEVICE_NAME_GET(dev_name)), level, prio)
931992

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.
9421003
*/
9431004
#define Z_MAYBE_DEVICE_DECLARE_INTERNAL(node_id) \
9441005
extern const struct device DEVICE_DT_NAME_GET(node_id);

0 commit comments

Comments
 (0)