Skip to content

Commit

Permalink
usb: device_next: implement usbd_class_shutdown()
Browse files Browse the repository at this point in the history
Implement marked as TODO usbd_class_shutdown().

Signed-off-by: Johann Fischer <[email protected]>
  • Loading branch information
jfischer-no authored and nashif committed May 26, 2023
1 parent 9a4ed74 commit 8a8e9e1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
4 changes: 2 additions & 2 deletions include/zephyr/usb/usbd.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ struct usbd_class_api {
/** Initialization of the class implementation */
int (*init)(struct usbd_class_node *const node);

/** Shutdown of the class implementation (TODO) */
int (*shutdown)(struct usbd_class_node *const node);
/** Shutdown of the class implementation */
void (*shutdown)(struct usbd_class_node *const node);
};

/**
Expand Down
2 changes: 2 additions & 0 deletions subsys/usb/device_next/usbd_class.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ int usbd_class_remove_all(struct usbd_contex *const uds_ctx,
while ((node = sys_slist_get(&cfg_nd->class_list))) {
c_nd = CONTAINER_OF(node, struct usbd_class_node, node);
atomic_clear_bit(&c_nd->data->state, USBD_CCTX_REGISTERED);
usbd_class_shutdown(c_nd);
LOG_DBG("Remove class node %p from configuration %u", c_nd, cfg);
}

Expand Down Expand Up @@ -361,6 +362,7 @@ int usbd_unregister_class(struct usbd_contex *const uds_ctx,
ret = usbd_class_remove(uds_ctx, c_nd, cfg);
if (ret == 0) {
atomic_clear_bit(&data->state, USBD_CCTX_REGISTERED);
usbd_class_shutdown(c_nd);
data->uds_ctx = NULL;
}

Expand Down
19 changes: 18 additions & 1 deletion subsys/usb/device_next/usbd_class_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ static inline void usbd_class_enable(struct usbd_class_node *const node)
}

/**
* @brief Class associated configuration shutdown handler
* @brief Class associated configuration disable handler
*
* @note The execution of the handler must not block.
*
Expand Down Expand Up @@ -247,5 +247,22 @@ static inline int usbd_class_init(struct usbd_class_node *const node)
return -ENOTSUP;
}

/**
* @brief Shutdown of the class implementation
*
* This is called for each instance during the shutdown phase.
*
* @note The execution of the handler must not block.
*
* @param[in] dev Pointer to device struct of the class instance
*/
static inline void usbd_class_shutdown(struct usbd_class_node *const node)
{
const struct usbd_class_api *api = node->api;

if (api->shutdown != NULL) {
api->shutdown(node);
}
}

#endif /* ZEPHYR_INCLUDE_USBD_CLASS_API_H */

0 comments on commit 8a8e9e1

Please sign in to comment.