Skip to content

Commit 4dc46c5

Browse files
committed
can: Provide new device instantiation macro
Again removing the prio parameter. Signed-off-by: Tomasz Bursztyka <[email protected]>
1 parent fa57ff1 commit 4dc46c5

File tree

1 file changed

+38
-0
lines changed
  • include/zephyr/drivers

1 file changed

+38
-0
lines changed

include/zephyr/drivers/can.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,31 @@ struct can_device_state {
773773
pm, data, config, level, prio, api, \
774774
&(Z_DEVICE_STATE_NAME(Z_DEVICE_DT_DEV_ID(node_id)).devstate), \
775775
__VA_ARGS__)
776+
/**
777+
* @brief Like DEVICE_INSTANCE() with CAN device specifics.
778+
*
779+
* @details Defines a device which implements the CAN API. May generate a custom
780+
* device_state container struct and init_fn wrapper when needed depending on
781+
* @kconfig{CONFIG_CAN_STATS}.
782+
*
783+
* @param node_id The devicetree node identifier.
784+
* @param init_fn Name of the init function of the driver.
785+
* @param pm PM device resources reference (NULL if device does not use PM).
786+
* @param data Pointer to the device's private data.
787+
* @param config The address to the structure containing the configuration
788+
* information for this instance of the driver.
789+
* @param level The initialization level. See SYS_INIT() for
790+
* details.
791+
* @param api Provides an initial pointer to the API function struct
792+
* used by the driver. Can be NULL.
793+
*/
794+
#define CAN_DEVICE_INSTANCE(node_id, init_fn, pm, data, config, level, api) \
795+
Z_CAN_DEVICE_STATE_DEFINE(Z_DEVICE_DT_DEV_ID(node_id)); \
796+
Z_CAN_INIT_FN(Z_DEVICE_DT_DEV_ID(node_id), init_fn) \
797+
DEVICE_INSTANCE_EXTERNAL_STATE(node_id, init_fn, pm, data, \
798+
config, level, api, \
799+
&(Z_DEVICE_STATE_NAME( \
800+
Z_DEVICE_DT_DEV_ID(node_id)).devstate))
776801

777802
#else /* CONFIG_CAN_STATS */
778803

@@ -791,6 +816,9 @@ struct can_device_state {
791816
DEVICE_DT_DEFINE(node_id, init_fn, pm, data, config, level, \
792817
prio, api, __VA_ARGS__)
793818

819+
#define CAN_DEVICE_INSTANCE(node_id, init_fn, pm, data, config, level, api) \
820+
DEVICE_INSTANCE(node_id, init_fn, pm, data, config, level, api)
821+
794822
#endif /* CONFIG_CAN_STATS */
795823

796824
/**
@@ -803,6 +831,16 @@ struct can_device_state {
803831
#define CAN_DEVICE_DT_INST_DEFINE(inst, ...) \
804832
CAN_DEVICE_DT_DEFINE(DT_DRV_INST(inst), __VA_ARGS__)
805833

834+
/**
835+
* @brief Like CAN_DEVICE_INSTANCE() for an instance of a DT_DRV_COMPAT compatible
836+
*
837+
* @param inst Instance number. This is replaced by <tt>DT_DRV_COMPAT(inst)</tt>
838+
* in the call to CAN_DEVICE_INSTANCE().
839+
* @param ... Other parameters as expected by CAN_DEVICE_INSTANCE().
840+
*/
841+
#define CAN_DEVICE_INSTANCE_FROM_DT_INST(inst, ...) \
842+
CAN_DEVICE_INSTANCE(DT_DRV_INST(inst), __VA_ARGS__)
843+
806844
/**
807845
* @name CAN controller configuration
808846
*

0 commit comments

Comments
 (0)